Mercurial > repos > tduigou > get_sbml_model
diff get_infos.py @ 2:52649039cf3f draft
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit d1f5bac36c249e0767ed0bb968a1f4b5843256e3
| author | tduigou |
|---|---|
| date | Mon, 24 Apr 2023 14:41:39 +0000 |
| parents | e276119e73c8 |
| children | 4c773948a490 |
line wrap: on
line diff
--- a/get_infos.py Mon Apr 24 13:26:25 2023 +0000 +++ b/get_infos.py Mon Apr 24 14:41:39 2023 +0000 @@ -2,6 +2,7 @@ from libsbml import ( readSBMLFromFile ) +from requests import get as r_get def entry_point(): @@ -21,6 +22,16 @@ type=str, help='Path to store biomass reaction ID' ) + parser.add_argument( + '--hostid', + type=str, + help='Extended name of the host organism' + ) + parser.add_argument( + '--taxid', + type=str, + help='Path to store host taxonomy ID' + ) params = parser.parse_args() sbml_doc = readSBMLFromFile(params.infile) @@ -40,5 +51,34 @@ if 'biomass' in rxn.getId().lower(): 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"*** Error: unable to retrieve host name for id {params.hostid}") + return -1 + # 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()["parent"]["id"] + except KeyError: + print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}") + with open(params.taxid, 'w') as f: + f.write('#ID\n') + f.write(f'{taxid}\n') + + if __name__ == "__main__": entry_point() \ No newline at end of file
