diff get_infos.py @ 9:6a2871e89352 draft default tip

planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 537d7fefe58984b8f7ca66010153a2fdc35ddf4b
author tduigou
date Wed, 14 Feb 2024 15:25:38 +0000
parents 768ed7cc0978
children
line wrap: on
line diff
--- a/get_infos.py	Fri Sep 29 09:03:09 2023 +0000
+++ b/get_infos.py	Wed Feb 14 15:25:38 2024 +0000
@@ -2,7 +2,7 @@
 from libsbml import (
     readSBMLFromFile
 )
-from requests import get as r_get
+from taxonid import get_taxonid
 
 
 def get_biomass_rxn(sbml_doc):
@@ -39,51 +39,6 @@
     return None
 
 
-def get_taxon_id(hostid):
-    '''
-    Returns the taxonomy ID of the host organism
-    
-    Parameters
-    ----------
-    hostid: str
-        Extended name of the host organism
-        
-    Returns
-    -------
-    taxid: str
-        Taxonomy ID of the host organism
-    '''
-    taxid = get_taxon_id(hostid)
-    hostname = ''
-    # Extended Name
-    server = 'http://bigg.ucsd.edu/api/v2/models/'
-    ext = hostid
-    r = r_get(server+ext, headers={ "Content-Type" : "application/json"})
-    if not r.ok:
-        print(f"Warning: unable to retrieve host name for id {hostid}")
-    else:
-        try:
-            hostname = r.json()["organism"]
-        except KeyError:
-            print(f"Warning: unable to retrieve host name for id {hostid}")
-    if not hostname:
-        taxid = ''
-    else:
-        # TAXON ID
-        server = 'https://rest.ensembl.org'
-        ext = f'/taxonomy/id/{hostname}?'
-        r = r_get(server+ext, headers={ "Content-Type" : "application/json"})
-        if not r.ok:
-            print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}")
-        else:
-            try:
-                taxid = r.json()["id"]
-            except KeyError:
-                print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}")
-                taxid = ''
-    return taxid
-
-
 def args():
     parser = ArgumentParser('Returns cell informations')
     parser.add_argument(
@@ -113,9 +68,9 @@
         help='ID of biomass reaction'
     )
     parser.add_argument(
-        '--hostid',
+        '--hostname',
         type=str,
-        help='Extended name of the host organism'
+        help='Name of the host organism'
     )
     parser.add_argument(
         '--taxid',
@@ -126,6 +81,55 @@
     return params
 
 
+def get_taxon_id(hostid: str, bigg: bool):
+    '''
+    Returns the taxonomy ID of the host organism
+    
+    Parameters
+    ----------
+    hostid: str
+        Extended name of the host organism or host ID if from BiGG
+    bigg: bool
+        True if the model is from BiGG
+        
+    Returns
+    -------
+    taxid: str
+        Taxonomy ID of the host organism
+    '''
+    if not bigg:
+        return get_taxonid(hostid)
+
+    hostname = ''
+    # Extended Name
+    server = 'http://bigg.ucsd.edu/api/v2/models/'
+    ext = hostid
+    r = r_get(server+ext, headers={ "Content-Type" : "application/json"})
+    if not r.ok:
+        print(f"Warning: unable to retrieve host name for id {hostid}")
+    else:
+        try:
+            hostname = r.json()["organism"]
+        except KeyError:
+            print(f"Warning: unable to retrieve host name for id {hostid}")
+    if not hostname:
+        taxid = ''
+    else:
+        # TAXON ID
+        server = 'https://rest.ensembl.org'
+        ext = f'/taxonomy/id/{hostname}?'
+        r = r_get(server+ext, headers={ "Content-Type" : "application/json"})
+        if not r.ok:
+            print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}")
+        else:
+            try:
+                taxid = r.json()["id"]
+            except KeyError:
+                print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}")
+                taxid = ''
+    return taxid
+
+
 def entry_point():
 
     params = args()
@@ -161,12 +165,7 @@
     else:
         print(f'Biomass reaction ID: {biomass_id}')
 
-    # Model from BiGG
-    if params.bigg:
-        taxid = get_taxon_id(params.hostid)
-    # Model from user
-    else:
-        taxid = params.hostid
+    taxid = get_taxon_id(params.hostname, params.bigg)
 
     if params.taxid:
         with open(params.taxid, 'w') as f: