annotate get_infos.py @ 14:7a57f54c130f draft default tip

planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
author tduigou
date Mon, 27 Oct 2025 06:26:27 +0000
parents 6bcd8f09158d
children
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
14
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
3 from requests import RequestException, get as r_get
1
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
4
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
5
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
6 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
7 """
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
8 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
9
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
10 Parameters
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
11 ----------
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
12 sbml_doc: libsbml.SBMLDocument
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
13 SBML model
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
14
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
15 Returns
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
16 -------
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
17 biomass_rxn: libsbml.Reaction
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
18 Biomass reaction
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
19 """
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
20 reactions = sbml_doc.getModel().getListOfReactions()
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
21 # 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
22 for rxn in reactions:
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
23 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
24 return rxn
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
25 # 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
26 # AND not in reactants
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
27 for rxn in reactions:
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
28 in_reactants = False
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
29 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
30 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
31 in_reactants = True
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
32 break
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
33 if not in_reactants:
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
34 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
35 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
36 return rxn
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
37 return None
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
38
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 def args():
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
41 parser = ArgumentParser("Returns cell informations")
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
42 parser.add_argument("infile", type=str, help="SBML input file (xml)")
13
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
43 parser.add_argument("--biomassid", type=str, help="ID of biomass reaction")
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
44 parser.add_argument("--taxonid", type=str, help="Taxonomy ID")
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
45 parser.add_argument("--standalone", action="store_true", help="Standalone mode, e.g. do not retrieve taxonomy ID on Internet (true if --taxonid is provided)")
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
46 parser.add_argument("--compartments-outfile", type=str, help="Path to store cell compartments")
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
47 parser.add_argument("--biomassid-outfile", type=str, help="Path to store biomass reaction ID")
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
48 parser.add_argument("--taxonid-outfile", 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}")
14
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
64 return -1
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
65
9
6a2871e89352 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 537d7fefe58984b8f7ca66010153a2fdc35ddf4b
tduigou
parents: 8
diff changeset
66
14
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
67 def get_taxonid(organism_name: str) -> str:
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
68 """Query NCBI Taxonomy for a given organism name and return its Taxon ID."""
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
69 url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi"
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
70 params = {
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
71 "db": "taxonomy",
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
72 "term": organism_name,
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
73 "retmode": "json"
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
74 }
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
75 try:
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
76 response = r_get(url, params=params, timeout=10)
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
77 response.raise_for_status()
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
78 data = response.json()
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
79 ids = data.get("esearchresult", {}).get("idlist", [])
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
80 return ids[0] if ids else -1
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
81 except RequestException as e:
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
82 print(f"Error querying NCBI for '{organism_name}': {e}")
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
83 return -1
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
84
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
85
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
86 def get_taxon_id(input_name: str) -> str:
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
87 """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
88 print(f"Trying input: {input_name}")
14
7a57f54c130f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit dda8b49daae051df39f4a58d5c0d81fbc393cdf4
tduigou
parents: 13
diff changeset
89
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
90 # 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
91 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
92 if organism:
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
93 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
94 taxon_id = get_taxonid(organism)
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
95 if taxon_id:
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
96 return taxon_id
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
97
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
98 # 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
99 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
100 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
101
6a2871e89352 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 537d7fefe58984b8f7ca66010153a2fdc35ddf4b
tduigou
parents: 8
diff changeset
102
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
103 def entry_point():
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
104 params = args()
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
105
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
106 # test if the file exists
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
107 with open(params.infile):
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
108 pass
1
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
109
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
110 sbml_doc = readSBMLFromFile(params.infile)
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
111
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
112 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
113 comp_str = ""
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
114 for comp in compartments:
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
115 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
116 print("Compartments:")
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
117 for comp in compartments:
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
118 print(f"{comp.getId()}\t{comp.getName()}".replace("\n", " | "))
13
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
119 if params.compartments_outfile:
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
120 with open(params.compartments_outfile, "w") as f:
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
121 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
122 f.write(comp_str)
1
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
123
13
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
124 if params.biomassid:
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
125 biomass_rxn = sbml_doc.getModel().getReaction(params.biomassid)
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
126 else:
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
127 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
128 if not biomass_rxn:
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
129 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
130 biomass_id = ""
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
131 else:
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
132 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
133 print(f"Biomass reaction ID: {biomass_id}")
13
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
134 if params.biomassid_outfile:
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
135 with open(params.biomassid_outfile, "w") as f:
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
136 f.write("#ID\n")
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
137 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
138
13
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
139 if params.taxonid:
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
140 taxid = params.taxonid
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
141 elif params.standalone:
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
142 taxid = -1
8
768ed7cc0978 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
143 else:
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
144 model_id = sbml_doc.getModel().getId()
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
145 if model_id:
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
146 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
147 if taxid == -1:
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
148 # Try with model name
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
149 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
150 if model_name:
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
151 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
152 print(f"Taxonomy ID: {taxid}")
1
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
153
13
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
154 if params.taxonid_outfile:
6bcd8f09158d planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents: 12
diff changeset
155 with open(params.taxonid_outfile, "w") as f:
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
156 f.write("#ID\n")
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
157 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
158
fa893f77dc22 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents: 1
diff changeset
159
1
ceffb29b60c9 planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff changeset
160 if __name__ == "__main__":
10
dc1167469d62 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents: 9
diff changeset
161 entry_point()