Mercurial > repos > tduigou > get_sbml_model
comparison get_infos.py @ 2:fa893f77dc22 draft
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
author | tduigou |
---|---|
date | Mon, 24 Apr 2023 14:49:53 +0000 |
parents | ceffb29b60c9 |
children | 1482291aaa5c |
comparison
equal
deleted
inserted
replaced
1:ceffb29b60c9 | 2:fa893f77dc22 |
---|---|
1 from argparse import ArgumentParser | 1 from argparse import ArgumentParser |
2 from libsbml import ( | 2 from libsbml import ( |
3 readSBMLFromFile | 3 readSBMLFromFile |
4 ) | 4 ) |
5 from requests import get as r_get | |
5 | 6 |
6 | 7 |
7 def entry_point(): | 8 def entry_point(): |
8 parser = ArgumentParser('Returns cell informations') | 9 parser = ArgumentParser('Returns cell informations') |
9 parser.add_argument( | 10 parser.add_argument( |
18 ) | 19 ) |
19 parser.add_argument( | 20 parser.add_argument( |
20 '--biomass', | 21 '--biomass', |
21 type=str, | 22 type=str, |
22 help='Path to store biomass reaction ID' | 23 help='Path to store biomass reaction ID' |
24 ) | |
25 parser.add_argument( | |
26 '--hostid', | |
27 type=str, | |
28 help='Extended name of the host organism' | |
29 ) | |
30 parser.add_argument( | |
31 '--taxid', | |
32 type=str, | |
33 help='Path to store host taxonomy ID' | |
23 ) | 34 ) |
24 params = parser.parse_args() | 35 params = parser.parse_args() |
25 | 36 |
26 sbml_doc = readSBMLFromFile(params.infile) | 37 sbml_doc = readSBMLFromFile(params.infile) |
27 | 38 |
38 f.write('#ID\n') | 49 f.write('#ID\n') |
39 for rxn in reactions: | 50 for rxn in reactions: |
40 if 'biomass' in rxn.getId().lower(): | 51 if 'biomass' in rxn.getId().lower(): |
41 f.write(f'{rxn.getId()}\n') | 52 f.write(f'{rxn.getId()}\n') |
42 | 53 |
54 if params.taxid: | |
55 # Extended Name | |
56 server = 'http://bigg.ucsd.edu/api/v2/models/' | |
57 ext = params.hostid | |
58 r = r_get(server+ext, headers={ "Content-Type" : "application/json"}) | |
59 if not r.ok: | |
60 print(f"Warning: unable to retrieve host name for id {params.hostid}") | |
61 else: | |
62 try: | |
63 hostname = r.json()["organism"] | |
64 except KeyError: | |
65 print(f"*** Error: unable to retrieve host name for id {params.hostid}") | |
66 return -1 | |
67 # TAXON ID | |
68 server = 'https://rest.ensembl.org' | |
69 ext = f'/taxonomy/id/{hostname}?' | |
70 r = r_get(server+ext, headers={ "Content-Type" : "application/json"}) | |
71 if not r.ok: | |
72 print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}") | |
73 else: | |
74 try: | |
75 taxid = r.json()["parent"]["id"] | |
76 except KeyError: | |
77 print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}") | |
78 with open(params.taxid, 'w') as f: | |
79 f.write('#ID\n') | |
80 f.write(f'{taxid}\n') | |
81 | |
82 | |
43 if __name__ == "__main__": | 83 if __name__ == "__main__": |
44 entry_point() | 84 entry_point() |