annotate get_infos.py @ 12:1aadcfdae10b draft

planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
author tduigou
date Tue, 01 Apr 2025 10:00:10 +0000
parents 062f51695ae0
children 6bcd8f09158d
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
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
2 from libsbml import readSBMLFromFile
9
6a2871e89352 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 537d7fefe58984b8f7ca66010153a2fdc35ddf4b
tduigou
parents: 8
diff changeset
3 from taxonid import get_taxonid
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
4 from requests import get as r_get
1
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
5
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
6
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
7 def get_biomass_rxn(sbml_doc):
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
8 """
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
9 Returns the biomass reaction of the model
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
10
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
11 Parameters
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
12 ----------
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
13 sbml_doc: libsbml.SBMLDocument
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
14 SBML model
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
15
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
16 Returns
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
17 -------
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
18 biomass_rxn: libsbml.Reaction
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
19 Biomass reaction
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
20 """
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
21 reactions = sbml_doc.getModel().getListOfReactions()
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
22 # Search for 'biomass' keyword in reaction name
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
23 for rxn in reactions:
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
24 if "biomass" in rxn.getName().lower():
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
25 return rxn
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
26 # Search for 'biomass' keyword in products
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
27 # AND not in reactants
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
28 for rxn in reactions:
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
29 in_reactants = False
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
30 for reac in rxn.getListOfReactants():
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
31 if "biomass" in reac.getSpecies().lower():
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
32 in_reactants = True
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
33 break
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
34 if not in_reactants:
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
35 for prod in rxn.getListOfProducts():
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
36 if "biomass" in prod.getSpecies().lower():
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
37 return rxn
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
38 return None
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
39
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
40
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
41 def args():
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
42 parser = ArgumentParser("Returns cell informations")
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
43 parser.add_argument("infile", type=str, help="SBML input file (xml)")
12
1aadcfdae10b planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 11
diff changeset
44 parser.add_argument("--hostname-or-id", type=str, help="Hostname or model ID")
1aadcfdae10b planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 11
diff changeset
45 parser.add_argument("--comp", type=str, help="Path to store cell compartments")
1aadcfdae10b planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 11
diff changeset
46 parser.add_argument("--biomass", type=str, help="Path to store biomass reaction ID")
1aadcfdae10b planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 11
diff changeset
47 parser.add_argument("--biomass-id", type=str, help="ID of biomass reaction")
1aadcfdae10b planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 11
diff changeset
48 parser.add_argument("--taxid", type=str, help="Path to store host taxonomy ID")
1
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
49 params = parser.parse_args()
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
50 return params
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
51
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
52
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
53 def get_organism_from_bigg_model(model_id):
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
54 """Try to retrieve organism info from BiGG Models for a given model ID."""
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
55 url = f"http://bigg.ucsd.edu/api/v2/models/{model_id}"
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
56 try:
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
57 response = r_get(url)
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
58 if response.status_code == 200:
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
59 data = response.json()
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
60 organism = data.get("organism")
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
61 return organism
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
62 except Exception as e:
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
63 print(f"Error querying BiGG: {e}")
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
64 return None
9
6a2871e89352 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 537d7fefe58984b8f7ca66010153a2fdc35ddf4b
tduigou
parents: 8
diff changeset
65
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
66 def get_taxon_id(input_name):
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
67 """Try BiGG model name first, then NCBI directly."""
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
68 print(f"Trying input: {input_name}")
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
69
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
70 # Try resolving as a BiGG model
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
71 organism = get_organism_from_bigg_model(input_name)
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
72 if organism:
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
73 print(f"Model '{input_name}' maps to organism: {organism}")
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
74 taxon_id = get_taxonid(organism)
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
75 if taxon_id:
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
76 return taxon_id
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
77
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
78 # If not a model, try directly as an organism name
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
79 print(f"Trying NCBI search with input: {input_name}")
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
80 return get_taxonid(input_name)
9
6a2871e89352 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 537d7fefe58984b8f7ca66010153a2fdc35ddf4b
tduigou
parents: 8
diff changeset
81
6a2871e89352 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 537d7fefe58984b8f7ca66010153a2fdc35ddf4b
tduigou
parents: 8
diff changeset
82
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
83 def entry_point():
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
84 params = args()
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
85
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
86 # test if the file exists
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
87 with open(params.infile):
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
88 pass
1
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
89
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
90 sbml_doc = readSBMLFromFile(params.infile)
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
91
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
92 compartments = sbml_doc.getModel().getListOfCompartments()
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
93 comp_str = ""
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
94 for comp in compartments:
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
95 comp_str += f"{comp.getId()}\t{comp.getName()}\n"
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
96 print("Compartments:")
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
97 for comp in compartments:
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
98 print(f"{comp.getId()}\t{comp.getName()}".replace("\n", " | "))
12
1aadcfdae10b planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 11
diff changeset
99 if params.comp:
1aadcfdae10b planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 11
diff changeset
100 with open(params.comp, "w") as f:
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
101 f.write("#ID\tNAME\n")
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
102 f.write(comp_str)
1
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
103
12
1aadcfdae10b planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 11
diff changeset
104 if params.biomass_id:
1aadcfdae10b planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 11
diff changeset
105 biomass_rxn = sbml_doc.getModel().getReaction(params.biomass_id)
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
106 else:
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
107 biomass_rxn = get_biomass_rxn(sbml_doc)
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
108 if not biomass_rxn:
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
109 print("Warning: unable to retrieve biomass reaction")
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
110 biomass_id = ""
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
111 else:
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
112 biomass_id = biomass_rxn.getId()
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
113 print(f"Biomass reaction ID: {biomass_id}")
12
1aadcfdae10b planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 11
diff changeset
114 if params.biomass:
1aadcfdae10b planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 11
diff changeset
115 with open(params.biomass, "w") as f:
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
116 f.write("#ID\n")
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
117 f.write(f"{biomass_id}\n")
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
118
12
1aadcfdae10b planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 11
diff changeset
119 if params.hostname_or_id:
1aadcfdae10b planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 11
diff changeset
120 taxid = get_taxon_id(params.hostname_or_id)
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
121 else:
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
122 model_id = sbml_doc.getModel().getId()
12
1aadcfdae10b planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 11
diff changeset
123 taxid = -1
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
124 if model_id:
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
125 taxid = get_taxon_id(sbml_doc.getModel().getId())
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
126 if taxid == -1:
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
127 # Try with model name
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
128 model_name = sbml_doc.getModel().getName()
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
129 if model_name:
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
130 taxid = get_taxon_id(sbml_doc.getModel().getName())
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
131 print(f"Taxonomy ID: {taxid}")
1
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
132
12
1aadcfdae10b planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 11
diff changeset
133 if params.taxid:
1aadcfdae10b planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 11
diff changeset
134 with open(params.taxid, "w") as f:
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
135 f.write("#ID\n")
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
136 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
137
fa893f77dc22 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents: 1
diff changeset
138
1
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
139 if __name__ == "__main__":
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
140 entry_point()