Mercurial > repos > tduigou > get_sbml_model
annotate 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 |
rev | line source |
---|---|
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
1 from argparse import ArgumentParser |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
2 from libsbml import ( |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
3 readSBMLFromFile |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
4 ) |
2
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
5 from requests import get as r_get |
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
6 |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
7 |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
8 def entry_point(): |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
9 parser = ArgumentParser('Returns cell informations') |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
10 parser.add_argument( |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
11 'infile', |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
12 type=str, |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
13 help='SBML input file (xml)' |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
14 ) |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
15 parser.add_argument( |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
16 '--comp', |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
17 type=str, |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
18 help='Path to store cell compartments' |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
19 ) |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
20 parser.add_argument( |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
21 '--biomass', |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
22 type=str, |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
23 help='Path to store biomass reaction ID' |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
24 ) |
2
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
25 parser.add_argument( |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
26 '--hostid', |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
27 type=str, |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
28 help='Extended name of the host organism' |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
29 ) |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
30 parser.add_argument( |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
31 '--taxid', |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
32 type=str, |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
33 help='Path to store host taxonomy ID' |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
34 ) |
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
35 params = parser.parse_args() |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
36 |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
37 sbml_doc = readSBMLFromFile(params.infile) |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
38 |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
39 if params.comp: |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
40 compartments = sbml_doc.getModel().getListOfCompartments() |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
41 with open(params.comp, 'w') as f: |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
42 f.write('#ID\tNAME\n') |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
43 for comp in compartments: |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
44 f.write(f'{comp.getId()}\t{comp.getName()}\n') |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
45 |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
46 if params.biomass: |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
47 reactions = sbml_doc.getModel().getListOfReactions() |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
48 with open(params.biomass, 'w') as f: |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
49 f.write('#ID\n') |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
50 for rxn in reactions: |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
51 if 'biomass' in rxn.getId().lower(): |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
52 f.write(f'{rxn.getId()}\n') |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
53 |
2
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
54 if params.taxid: |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
55 # Extended Name |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
56 server = 'http://bigg.ucsd.edu/api/v2/models/' |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
57 ext = params.hostid |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
58 r = r_get(server+ext, headers={ "Content-Type" : "application/json"}) |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
59 if not r.ok: |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
60 print(f"Warning: unable to retrieve host name for id {params.hostid}") |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
61 else: |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
62 try: |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
63 hostname = r.json()["organism"] |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
64 except KeyError: |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
65 print(f"*** Error: unable to retrieve host name for id {params.hostid}") |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
66 return -1 |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
67 # TAXON ID |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
68 server = 'https://rest.ensembl.org' |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
69 ext = f'/taxonomy/id/{hostname}?' |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
70 r = r_get(server+ext, headers={ "Content-Type" : "application/json"}) |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
71 if not r.ok: |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
72 print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}") |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
73 else: |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
74 try: |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
75 taxid = r.json()["parent"]["id"] |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
76 except KeyError: |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
77 print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}") |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
78 with open(params.taxid, 'w') as f: |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
79 f.write('#ID\n') |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
80 f.write(f'{taxid}\n') |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
81 |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
82 |
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
83 if __name__ == "__main__": |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
84 entry_point() |