annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 )
7
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
15 # argument to tag file from BiGG
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
16 parser.add_argument(
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
17 '--bigg',
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
18 action='store_true',
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
19 help='Tag file from BiGG'
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
20 )
1
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
21 parser.add_argument(
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
22 '--comp',
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
23 type=str,
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
24 help='Path to store cell compartments'
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
25 )
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
26 parser.add_argument(
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
27 '--biomass',
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
28 type=str,
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
29 help='Path to store biomass reaction ID'
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
30 )
2
fa893f77dc22 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents: 1
diff changeset
31 parser.add_argument(
fa893f77dc22 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents: 1
diff changeset
32 '--hostid',
fa893f77dc22 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents: 1
diff changeset
33 type=str,
fa893f77dc22 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents: 1
diff changeset
34 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
35 )
fa893f77dc22 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents: 1
diff changeset
36 parser.add_argument(
fa893f77dc22 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents: 1
diff changeset
37 '--taxid',
fa893f77dc22 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents: 1
diff changeset
38 type=str,
fa893f77dc22 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents: 1
diff changeset
39 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
40 )
1
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
41 params = parser.parse_args()
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
42
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
43 sbml_doc = readSBMLFromFile(params.infile)
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
44
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
45 if params.comp:
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
46 compartments = sbml_doc.getModel().getListOfCompartments()
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
47 with open(params.comp, 'w') as f:
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
48 f.write('#ID\tNAME\n')
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
49 for comp in compartments:
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
50 f.write(f'{comp.getId()}\t{comp.getName()}\n')
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
51
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
52 if params.biomass:
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
53 reactions = sbml_doc.getModel().getListOfReactions()
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
54 with open(params.biomass, 'w') as f:
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
55 f.write('#ID\n')
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
56 for rxn in reactions:
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
57 if 'biomass' in rxn.getId().lower():
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
58 f.write(f'{rxn.getId()}\n')
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
59
2
fa893f77dc22 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents: 1
diff changeset
60 if params.taxid:
7
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
61 hostname = ''
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
62
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
63 # Model from BiGG
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
64 if params.bigg:
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
65 # Extended Name
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
66 server = 'http://bigg.ucsd.edu/api/v2/models/'
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
67 ext = params.hostid
4
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
68 r = r_get(server+ext, headers={ "Content-Type" : "application/json"})
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
69 if not r.ok:
7
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
70 print(f"Warning: unable to retrieve host name for id {params.hostid}")
4
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
71 else:
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
72 try:
7
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
73 hostname = r.json()["organism"]
4
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
74 except KeyError:
7
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
75 print(f"Warning: unable to retrieve host name for id {params.hostid}")
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
76 if not hostname:
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
77 taxid = ''
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
78 else:
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
79 # TAXON ID
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
80 server = 'https://rest.ensembl.org'
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
81 ext = f'/taxonomy/id/{hostname}?'
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
82 r = r_get(server+ext, headers={ "Content-Type" : "application/json"})
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
83 if not r.ok:
4
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
84 print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}")
7
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
85 else:
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
86 try:
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
87 taxid = r.json()["id"]
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
88 except KeyError:
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
89 print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}")
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
90 taxid = ''
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
91
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
92 # Model from user
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
93 else:
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
94 taxid = params.hostid
8dc4d3964ab5 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents: 4
diff changeset
95
4
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
96 with open(params.taxid, 'w') as f:
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
97 f.write('#ID\n')
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
98 f.write(f'{taxid}\n')
2
fa893f77dc22 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents: 1
diff changeset
99
fa893f77dc22 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents: 1
diff changeset
100
1
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
101 if __name__ == "__main__":
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
102 entry_point()