@classmethod<EOL><INDENT>def read_msigdb_xml(cls, path, entrez2gene, species=None):  <DEDENT>
<EOL>assert isinstance(path, (str, _oldstr))<EOL>assert isinstance(entrez2gene, (dict, OrderedDict))<EOL>assert species is None or isinstance(species, (str, _oldstr))<EOL>logger.debug('<STR_LIT>', path)<EOL>logger.debug('<STR_LIT>', str(type(entrez2gene)))<EOL>i = [<NUM_LIT:0>]<EOL>gene_sets = []<EOL>total_gs = [<NUM_LIT:0>]<EOL>total_genes = [<NUM_LIT:0>]<EOL>species_excl = [<NUM_LIT:0>]<EOL>unknown_entrezid = [<NUM_LIT:0>]<EOL>src = '<STR_LIT>'<EOL>def handle_item(pth, item):<EOL><INDENT>total_gs[<NUM_LIT:0>] += <NUM_LIT:1><EOL>data = pth[<NUM_LIT:1>][<NUM_LIT:1>]<EOL>spec = data['<STR_LIT>']<EOL>if species is not None and spec != species:<EOL><INDENT>species_excl[<NUM_LIT:0>] += <NUM_LIT:1><EOL>return True<EOL><DEDENT>id_ = data['<STR_LIT>']<EOL>name = data['<STR_LIT>']<EOL>coll = data['<STR_LIT>']<EOL>desc = data['<STR_LIT>']<EOL>entrez = data['<STR_LIT>'].split('<STR_LIT:U+002C>')<EOL>genes = []<EOL>for e in entrez:<EOL><INDENT>total_genes[<NUM_LIT:0>] += <NUM_LIT:1><EOL>try:<EOL><INDENT>genes.append(entrez2gene[e])<EOL><DEDENT>except KeyError:<EOL><INDENT>unknown_entrezid[<NUM_LIT:0>] += <NUM_LIT:1><EOL><DEDENT><DEDENT>if not genes:<EOL><INDENT>logger.warning('<STR_LIT>',<EOL>name, id_)<EOL>return True<EOL><DEDENT>gs = GeneSet(id_, name, genes, source=src,<EOL>collection=coll, description=desc)<EOL>gene_sets.append(gs)<EOL>i[<NUM_LIT:0>] += <NUM_LIT:1><EOL>return True<EOL><DEDENT>with io.open(path, '<STR_LIT:rb>') as fh:<EOL><INDENT>xmltodict.parse(fh.read(), encoding='<STR_LIT>', item_depth=<NUM_LIT:2>,<EOL>item_callback=handle_item)<EOL><DEDENT>if species_excl[<NUM_LIT:0>] > <NUM_LIT:0>:<EOL><INDENT>kept = total_gs[<NUM_LIT:0>] - species_excl[<NUM_LIT:0>]<EOL>perc = <NUM_LIT:100> * (kept / float(total_gs[<NUM_LIT:0>]))<EOL>logger.info('<STR_LIT>'<EOL>'<STR_LIT>', kept, total_gs[<NUM_LIT:0>], perc)<EOL><DEDENT>if unknown_entrezid[<NUM_LIT:0>] > <NUM_LIT:0>:<EOL><INDENT>unkn = unknown_entrezid[<NUM_LIT:0>]<EOL>perc = <NUM_LIT:100> * (unkn / float(total_genes[<NUM_LIT:0>]))<EOL>logger.warning('<STR_LIT>' +<EOL>'<STR_LIT>', unkn, total_genes[<NUM_LIT:0>], perc)<EOL><DEDENT>logger.info('<STR_LIT>',<EOL>total_gs[<NUM_LIT:0>], len(gene_sets))<EOL>return cls(gene_sets)<EOL>
Read the complete MSigDB database from an XML file.

        The XML file can be downloaded from here:
        http://software.broadinstitute.org/gsea/msigdb/download_file.jsp?filePath=/resources/msigdb/5.0/msigdb_v5.0.xml

        Parameters
        ----------
        path: str
            The path name of the XML file.
        entrez2gene: dict or OrderedDict (str: str)
            A dictionary mapping Entrez Gene IDs to gene symbols (names).
        species: str, optional
            A species name (e.g., "Homo_sapiens"). Only gene sets for that
            species will be retained. (None)

        Returns
        -------
        GeneSetCollection
            The gene set database containing the MSigDB gene sets.