Mercurial > repos > tduigou > get_sbml_model
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 13:6bcd8f09158d | 14:7a57f54c130f |
|---|---|
| 1 from argparse import ArgumentParser | 1 from argparse import ArgumentParser |
| 2 from libsbml import readSBMLFromFile | 2 from libsbml import readSBMLFromFile |
| 3 from taxonid import get_taxonid | 3 from requests import RequestException, get as r_get |
| 4 from requests import get as r_get | |
| 5 | 4 |
| 6 | 5 |
| 7 def get_biomass_rxn(sbml_doc): | 6 def get_biomass_rxn(sbml_doc): |
| 8 """ | 7 """ |
| 9 Returns the biomass reaction of the model | 8 Returns the biomass reaction of the model |
| 60 data = response.json() | 59 data = response.json() |
| 61 organism = data.get("organism") | 60 organism = data.get("organism") |
| 62 return organism | 61 return organism |
| 63 except Exception as e: | 62 except Exception as e: |
| 64 print(f"Error querying BiGG: {e}") | 63 print(f"Error querying BiGG: {e}") |
| 65 return None | 64 return -1 |
| 66 | 65 |
| 67 def get_taxon_id(input_name): | 66 |
| 67 def get_taxonid(organism_name: str) -> str: | |
| 68 """Query NCBI Taxonomy for a given organism name and return its Taxon ID.""" | |
| 69 url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi" | |
| 70 params = { | |
| 71 "db": "taxonomy", | |
| 72 "term": organism_name, | |
| 73 "retmode": "json" | |
| 74 } | |
| 75 try: | |
| 76 response = r_get(url, params=params, timeout=10) | |
| 77 response.raise_for_status() | |
| 78 data = response.json() | |
| 79 ids = data.get("esearchresult", {}).get("idlist", []) | |
| 80 return ids[0] if ids else -1 | |
| 81 except RequestException as e: | |
| 82 print(f"Error querying NCBI for '{organism_name}': {e}") | |
| 83 return -1 | |
| 84 | |
| 85 | |
| 86 def get_taxon_id(input_name: str) -> str: | |
| 68 """Try BiGG model name first, then NCBI directly.""" | 87 """Try BiGG model name first, then NCBI directly.""" |
| 69 print(f"Trying input: {input_name}") | 88 print(f"Trying input: {input_name}") |
| 70 | 89 |
| 71 # Try resolving as a BiGG model | 90 # Try resolving as a BiGG model |
| 72 organism = get_organism_from_bigg_model(input_name) | 91 organism = get_organism_from_bigg_model(input_name) |
| 73 if organism: | 92 if organism: |
| 74 print(f"Model '{input_name}' maps to organism: {organism}") | 93 print(f"Model '{input_name}' maps to organism: {organism}") |
| 75 taxon_id = get_taxonid(organism) | 94 taxon_id = get_taxonid(organism) |
