Repository: churchmanlab/genewalk

Issue:
ENSEMBL IDs
Hi, a quick question: Is it possible to support also ENSEMBL IDs as input?

Discussion:

Patch:
diff --git a/README.md b/README.md
index 2b734e3..ae5d980 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,7 @@ GeneWalk always requires as input a text file containing a list with genes of in
 relevant to the biological context. For example, differentially expressed genes
 from a sequencing experiment that compares an experimental versus control condition.
 GeneWalk supports gene list files containing HGNC human gene symbols,
-HGNC IDs, or MGI mouse gene IDs. Each line in the file contains a gene identifier of
+HGNC IDs, Ensembl IDs, or MGI mouse gene IDs. Each line in the file contains a gene identifier of
 one of these types.
 
 ### GeneWalk command line interface
@@ -63,10 +63,10 @@ required arguments:
   --genes GENES         Path to a text file with a list of differentially
                         expressed genes. Thetype of gene identifiers used in
                         the text file are provided in the id_type argument.
-  --id_type {hgnc_symbol,hgnc_id,mgi_id}
+  --id_type {hgnc_symbol,hgnc_id,ensembl_id,mgi_id}
                         The type of gene IDs provided in the text file in the
                         genes argument. Possible values are: hgnc_symbol,
-                        hgnc_id, and mgi_id.
+                        hgnc_id, ensembl_id, and mgi_id.
 
 optional arguments:
   --stage {all,node_vectors,null_distribution,statistics}
diff --git a/genewalk/cli.py b/genewalk/cli.py
index e1ebb80..42b41b5 100644
--- a/genewalk/cli.py
+++ b/genewalk/cli.py
@@ -65,8 +65,9 @@ def main():
     parser.add_argument('--id_type',
                         help='The type of gene IDs provided in the text file '
                              'in the genes argument. Possible values are: '
-                             'hgnc_symbol, hgnc_id, and mgi_id.',
-                        choices=['hgnc_symbol', 'hgnc_id', 'mgi_id'],
+                             'hgnc_symbol, hgnc_id, ensembl_id, and mgi_id.',
+                        choices=['hgnc_symbol', 'hgnc_id',
+                                 'ensembl_id', 'mgi_id'],
                         required=True)
     parser.add_argument('--stage', default='all',
                         help='The stage of processing to run. Default: '
diff --git a/genewalk/gene_lists.py b/genewalk/gene_lists.py
index c42235b..9737914 100644
--- a/genewalk/gene_lists.py
+++ b/genewalk/gene_lists.py
@@ -17,7 +17,7 @@ def read_gene_list(fname, id_type):
         file corresponds to a single gene.
     id_type : str
         The type of identifier contained in each line of the gene list file.
-        Possible values are: hgnc_symbol, hgnc_id, mgi_id.
+        Possible values are: hgnc_symbol, hgnc_id, ensembl_id, mgi_id.
 
     Returns
     -------
@@ -38,6 +38,8 @@ def read_gene_list(fname, id_type):
         return map_hgnc_symbols(unique_lines)
     elif id_type == 'hgnc_id':
         return map_hgnc_ids(unique_lines)
+    elif id_type == 'ensembl_id':
+        return map_ensembl_ids(unique_lines)
     elif id_type == 'mgi_id':
         return map_mgi_ids(unique_lines)
     else:
@@ -115,3 +117,31 @@ def map_mgi_ids(mgi_ids):
         ref['UP'] = uniprot_id
         refs.append(ref)
     return refs
+
+
+def map_ensembl_ids(ensembl_ids):
+    """Return references based on a list of Ensembl IDs."""
+    refs = []
+    for ensembl_id in ensembl_ids:
+        ref = {'HGNC_SYMBOL': None, 'HGNC': None, 'UP': None,
+               'ENSEMBL': ensembl_id}
+        hgnc_id = hgnc_client.get_hgnc_from_ensembl(ensembl_id)
+        if not hgnc_id:
+            logger.warning('Could not get HGNC ID for ENSEMBL ID %s' %
+                           ensembl_id)
+            continue
+        ref['HGNC'] = hgnc_id
+        hgnc_name = hgnc_client.get_hgnc_name(hgnc_id)
+        if not hgnc_name:
+            logger.warning('Could not get HGNC name for ID %s' %
+                           hgnc_id)
+            continue
+        ref['HGNC_SYMBOL'] = hgnc_name
+        uniprot_id = hgnc_client.get_uniprot_id(hgnc_id)
+        if not uniprot_id:
+            logger.warning('Could not get UniProt ID for HGNC ID %s' %
+                           hgnc_id)
+            continue
+        ref['UP'] = uniprot_id
+        refs.append(ref)
+    return refs
diff --git a/setup.py b/setup.py
index f913a4b..dfb4d59 100755
--- a/setup.py
+++ b/setup.py
@@ -9,7 +9,7 @@ with open(path.join(here, 'README.md'), encoding='utf-8') as f:
 
 def main():
     install_list = ['numpy', 'pandas', 'networkx>=2.1', 'gensim', 'goatools',
-                    'indra', 'scipy>=1.3.0']
+                    'indra>=1.14.1', 'scipy>=1.3.0']
 
     setup(name='genewalk',
           version='1.1.0',


Test patch:
diff --git a/genewalk/tests/test_gene_lists.py b/genewalk/tests/test_gene_lists.py
index 9715a4c..ac9fd42 100644
--- a/genewalk/tests/test_gene_lists.py
+++ b/genewalk/tests/test_gene_lists.py
@@ -22,3 +22,8 @@ def test_map_lists():
     assert refs[0]['HGNC'] == '6817', refs
     assert refs[0]['HGNC_SYMBOL'] == 'MAL', refs
     assert refs[0]['UP'] == 'P21145', refs
+
+    refs = map_ensembl_ids(['ENSG00000157764'])
+    assert refs[0]['HGNC'] == '1097', refs
+    assert refs[0]['UP'] == 'P15056', refs
+    assert refs[0]['HGNC_SYMBOL'] == 'BRAF', refs