annotate get_infos.py @ 5:80c32f0cb716 draft

planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 1e01b679611d980f87089184e7d8a538b96d68c7
author tduigou
date Tue, 30 May 2023 21:03:04 +0000
parents 1482291aaa5c
children 8dc4d3964ab5
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 )
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:
4
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
65 print(f"Warning: unable to retrieve host name for id {params.hostid}")
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
66 hostname = ''
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
67 if not hostname:
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
68 taxid = ''
2
fa893f77dc22 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents: 1
diff changeset
69 else:
4
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
70 # TAXON ID
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
71 server = 'https://rest.ensembl.org'
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
72 ext = f'/taxonomy/id/{hostname}?'
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
73 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
74 if not r.ok:
2
fa893f77dc22 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents: 1
diff changeset
75 print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}")
4
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
76 else:
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
77 try:
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
78 taxid = r.json()["id"]
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
79 except KeyError:
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
80 print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}")
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
81 taxid = ''
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
82 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
83 f.write('#ID\n')
1482291aaa5c planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
84 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
85
fa893f77dc22 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents: 1
diff changeset
86
1
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
87 if __name__ == "__main__":
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
88 entry_point()