diff get_infos.py @ 7:8dc4d3964ab5 draft

planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
author tduigou
date Mon, 04 Sep 2023 14:19:43 +0000
parents 1482291aaa5c
children 768ed7cc0978
line wrap: on
line diff
--- a/get_infos.py	Mon Aug 28 14:24:48 2023 +0000
+++ b/get_infos.py	Mon Sep 04 14:19:43 2023 +0000
@@ -12,6 +12,12 @@
         type=str,
         help='SBML input file (xml)'
     )
+    # argument to tag file from BiGG
+    parser.add_argument(
+        '--bigg',
+        action='store_true',
+        help='Tag file from BiGG'
+    )
     parser.add_argument(
         '--comp',
         type=str,
@@ -52,33 +58,41 @@
                     f.write(f'{rxn.getId()}\n')
 
     if params.taxid:
-        # Extended Name
-        server = 'http://bigg.ucsd.edu/api/v2/models/'
-        ext = params.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 {params.hostid}")
-        else:
-            try:
-                hostname = r.json()["organism"]
-            except KeyError:
-                print(f"Warning: unable to retrieve host name for id {params.hostid}")
-                hostname = ''
-        if not hostname:
-            taxid = ''
-        else:
-            # TAXON ID
-            server = 'https://rest.ensembl.org'
-            ext = f'/taxonomy/id/{hostname}?'
+        hostname = ''
+
+        # Model from BiGG
+        if params.bigg:
+            # Extended Name
+            server = 'http://bigg.ucsd.edu/api/v2/models/'
+            ext = params.hostid
             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}")
+                print(f"Warning: unable to retrieve host name for id {params.hostid}")
             else:
                 try:
-                    taxid = r.json()["id"]
+                    hostname = r.json()["organism"]
                 except KeyError:
+                    print(f"Warning: unable to retrieve host name for id {params.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}")
-                    taxid = ''
+                else:
+                    try:
+                        taxid = r.json()["id"]
+                    except KeyError:
+                        print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}")
+                        taxid = ''
+
+        # Model from user
+        else:
+            taxid = params.hostid
+
         with open(params.taxid, 'w') as f:
             f.write('#ID\n')
             f.write(f'{taxid}\n')