Source: https://github.com/aipoch/medical-research-skills
When to Use
- You need to retrieve and combine biological data from multiple databases (e.g., UniProt + KEGG + GO) in one Python workflow.
- You need cross-database identifier mapping (e.g., UniProt ↔ KEGG, KEGG compound ↔ ChEMBL) as part of downstream analysis.
- You want to programmatically explore pathways and networks (e.g., KEGG pathway parsing, exporting interactions to SIF).
- You need service-agnostic access across many providers (REST and SOAP/WSDL) without writing custom clients per service.
- You are building integrated bioinformatics pipelines (protein → sequence → BLAST → pathways → interactions) that span multiple resources.
Key Features
- Unified API for ~40+ bioinformatics services (single Python package, consistent patterns).
- Transparent protocol handling (REST and SOAP/WSDL).
- Protein-centric workflows via UniProt (search, retrieve, ID mapping).
- Pathway discovery and parsing via KEGG (KGML parsing, relations extraction, SIF export).
- Compound lookup and cross-referencing (e.g., KEGG compounds + UniChem mapping to ChEMBL).
- Sequence analysis integrations (e.g., NCBI BLAST asynchronous jobs).
- Ontology and annotation queries (e.g., QuickGO).
- Protein–protein interaction queries via PSICQUIC-compatible services.
Dependencies
python >= 3.9
bioservices (install via pip/uv; version depends on your environment)
Optional (commonly used alongside returned formats):
pandas >= 1.5 (TSV/tabular outputs)
beautifulsoup4 >= 4.11 (XML parsing)
lxml >= 4.9 (faster XML parsing)
networkx >= 2.8 (network analysis of interactions)
biopython >= 1.81 (sequence handling for FASTA outputs)
Example Usage
A single runnable script that demonstrates a cross-service workflow:
- UniProt search + FASTA retrieval
- UniProt → KEGG ID mapping
- KEGG pathway lookup and KGML relation extraction
- QuickGO annotation query
- PSICQUIC interaction query
- KEGG compound lookup + UniChem mapping to ChEMBL
"""
Run:
uv pip install bioservices pandas
python bioservices_example.py
Notes:
- Some services may rate-limit or be temporarily unavailable.
- NCBI BLAST requires an email; this example does not run BLAST to stay lightweight.
"""
from bioservices import UniProt, KEGG, QuickGO, PSICQUIC, UniChem
def main():
# --- UniProt: search + retrieve ---
u = UniProt(verbose=False)
# Search by entry name (example: ZAP70 human)
tab = u.search("ZAP70_HUMAN", frmt="tab", columns="id,entry name,genes,organism")
print("UniProt search (tab):")
print(tab.splitlines()[0:3], "\n") # show header + first rows
uniprot_ac = "P43403" # ZAP70_HUMAN accession
fasta = u.retrieve(uniprot_ac, "fasta")
print("UniProt FASTA header:")
print(fasta.splitlines()[0], "\n")
# --- UniProt: identifier mapping (UniProt -> KEGG) ---
mapping = u.mapping(fr="UniProtKB_AC-ID", to="KEGG", query=uniprot_ac)
print("UniProt -> KEGG mapping:")
print(mapping, "\n")
# --- KEGG: pathway discovery + parsing ---
k = KEGG(verbose=False)
k.organism = "hsa"
# Example gene: ZAP70 is KEGG gene hsa:7535
pathways = k.get_pathway_by_gene("7535", "hsa")
print("KEGG pathways containing hsa:7535:")
print(pathways, "\n")
pathway_id = "hsa04660" # T cell receptor signaling pathway (example)
kgml_relations = k.parse_kgml_pathway(pathway_id).get("relations", [])
print(f"KEGG KGML relations count for {pathway_id}: {len(kgml_relations)}\n")
# Export to SIF (useful for network tools)
sif = k.pathway2sif(pathway_id)
print(f"KEGG SIF preview for {pathway_id}:")
print("\n".join(sif.splitlines()[:5]), "\n")
# --- QuickGO: GO annotations for a UniProt protein ---
g = QuickGO(verbose=False)
ann = g.Annotation(protein=uniprot_ac, format="tsv")
print("QuickGO annotation TSV header:")
print(ann.splitlines()[0], "\n")
# --- PSICQUIC: interaction query (database name may vary by availability) ---
p = PSICQUIC(verbose=False)
# Example query: ZAP70 interactions in human
# Choose a database that is active in your environment; "intact" is commonly available.
interactions = p.query("intact", "ZAP70 AND species:9606")
print("PSICQUIC query result preview:")
print("\n".join(interactions.splitlines()[:3]), "\n")
# --- Compound workflow: KEGG compound -> UniChem -> ChEMBL ---
# Example: Geldanamycin
cpd_hits = k.find("compound", "Geldanamycin")
print("KEGG compound find('Geldanamycin'):")
print(cpd_hits, "\n")
# If you already know the KEGG compound ID:
kegg_compound_id = "C11222"
uc = UniChem(verbose=False)
chembl_id = uc.get_compound_id_from_kegg(kegg_compound_id)
print(f"UniChem KEGG {kegg_compound_id} -> ChEMBL:")
print(chembl_id, "\n")
if __name__ == "__main__":
main()
Implementation Details
- Service objects: Each remote resource is exposed as a Python class (e.g.,
UniProt, KEGG, QuickGO, PSICQUIC, NCBIblast). You instantiate a client and call methods that wrap the underlying endpoints.
- Protocols: BioServices abstracts REST and SOAP/WSDL services behind similar method calls; returned payloads may be text (TSV), XML, JSON-like dicts, or FASTA.
- Common parameters
verbose: toggles HTTP/request logging (verbose=False is recommended for scripts).
TIMEOUT: per-service timeout control (useful for slow networks or large responses).
- Service-specific parameters (examples):
- UniProt:
search(query, frmt=..., columns=...), retrieve(accession, format), mapping(fr=..., to=..., query=...)
- KEGG:
find(db, query), get(entry_id), parse(raw), parse_kgml_pathway(pathway_id), pathway2sif(pathway_id)
- NCBI BLAST: asynchronous job model (
run(...) → getStatus(jobid) → getResult(jobid, ...))
- Data handling guidance
- TSV/tabular outputs: load into
pandas.read_csv(io.StringIO(text), sep="\t")
- XML outputs: parse with
BeautifulSoup or lxml
- Network exports (SIF): import into NetworkX/Cytoscape-compatible tooling
- Operational considerations
- Many endpoints are rate-limited; implement retries/backoff for production pipelines.
- Some services require contact information (e.g., NCBI BLAST email) and may enforce usage policies.
- Availability varies by provider; design workflows to degrade gracefully (try/except, fallbacks).
1---2name: bioservices3description: Unified Python access to 40+ bioinformatics web services; use when you need to query multiple databases (e.g., UniProt/KEGG/ChEMBL/Reactome) with one consistent API in a single workflow, especially for cross-database analysis and identifier mapping.4license: MIT5---6> **Source**: [https://github.com/aipoch/medical-research-skills](https://github.com/aipoch/medical-research-skills)78## When to Use910- You need to **retrieve and combine biological data from multiple databases** (e.g., UniProt + KEGG + GO) in one Python workflow.11- You need **cross-database identifier mapping** (e.g., UniProt ↔ KEGG, KEGG compound ↔ ChEMBL) as part of downstream analysis.12- You want to **programmatically explore pathways and networks** (e.g., KEGG pathway parsing, exporting interactions to SIF).13- You need **service-agnostic access** across many providers (REST and SOAP/WSDL) without writing custom clients per service.14- You are building **integrated bioinformatics pipelines** (protein → sequence → BLAST → pathways → interactions) that span multiple resources.1516## Key Features1718- **Unified API** for ~40+ bioinformatics services (single Python package, consistent patterns).19- **Transparent protocol handling** (REST and SOAP/WSDL).20- **Protein-centric workflows** via UniProt (search, retrieve, ID mapping).21- **Pathway discovery and parsing** via KEGG (KGML parsing, relations extraction, SIF export).22- **Compound lookup and cross-referencing** (e.g., KEGG compounds + UniChem mapping to ChEMBL).23- **Sequence analysis integrations** (e.g., NCBI BLAST asynchronous jobs).24- **Ontology and annotation queries** (e.g., QuickGO).25- **Protein–protein interaction queries** via PSICQUIC-compatible services.2627## Dependencies2829- `python >= 3.9`30- `bioservices` (install via pip/uv; version depends on your environment)3132Optional (commonly used alongside returned formats):33- `pandas >= 1.5` (TSV/tabular outputs)34- `beautifulsoup4 >= 4.11` (XML parsing)35- `lxml >= 4.9` (faster XML parsing)36- `networkx >= 2.8` (network analysis of interactions)37- `biopython >= 1.81` (sequence handling for FASTA outputs)3839## Example Usage4041A single runnable script that demonstrates a cross-service workflow:421) UniProt search + FASTA retrieval 432) UniProt → KEGG ID mapping 443) KEGG pathway lookup and KGML relation extraction 454) QuickGO annotation query 465) PSICQUIC interaction query 476) KEGG compound lookup + UniChem mapping to ChEMBL4849```python50"""51Run:52 uv pip install bioservices pandas53 python bioservices_example.py5455Notes:56- Some services may rate-limit or be temporarily unavailable.57- NCBI BLAST requires an email; this example does not run BLAST to stay lightweight.58"""5960from bioservices import UniProt, KEGG, QuickGO, PSICQUIC, UniChem616263def main():64 # --- UniProt: search + retrieve ---65 u = UniProt(verbose=False)6667 # Search by entry name (example: ZAP70 human)68 tab = u.search("ZAP70_HUMAN", frmt="tab", columns="id,entry name,genes,organism")69 print("UniProt search (tab):")70 print(tab.splitlines()[0:3], "\n") # show header + first rows7172 uniprot_ac = "P43403" # ZAP70_HUMAN accession73 fasta = u.retrieve(uniprot_ac, "fasta")74 print("UniProt FASTA header:")75 print(fasta.splitlines()[0], "\n")7677 # --- UniProt: identifier mapping (UniProt -> KEGG) ---78 mapping = u.mapping(fr="UniProtKB_AC-ID", to="KEGG", query=uniprot_ac)79 print("UniProt -> KEGG mapping:")80 print(mapping, "\n")8182 # --- KEGG: pathway discovery + parsing ---83 k = KEGG(verbose=False)84 k.organism = "hsa"8586 # Example gene: ZAP70 is KEGG gene hsa:753587 pathways = k.get_pathway_by_gene("7535", "hsa")88 print("KEGG pathways containing hsa:7535:")89 print(pathways, "\n")9091 pathway_id = "hsa04660" # T cell receptor signaling pathway (example)92 kgml_relations = k.parse_kgml_pathway(pathway_id).get("relations", [])93 print(f"KEGG KGML relations count for {pathway_id}: {len(kgml_relations)}\n")9495 # Export to SIF (useful for network tools)96 sif = k.pathway2sif(pathway_id)97 print(f"KEGG SIF preview for {pathway_id}:")98 print("\n".join(sif.splitlines()[:5]), "\n")99100 # --- QuickGO: GO annotations for a UniProt protein ---101 g = QuickGO(verbose=False)102 ann = g.Annotation(protein=uniprot_ac, format="tsv")103 print("QuickGO annotation TSV header:")104 print(ann.splitlines()[0], "\n")105106 # --- PSICQUIC: interaction query (database name may vary by availability) ---107 p = PSICQUIC(verbose=False)108 # Example query: ZAP70 interactions in human109 # Choose a database that is active in your environment; "intact" is commonly available.110 interactions = p.query("intact", "ZAP70 AND species:9606")111 print("PSICQUIC query result preview:")112 print("\n".join(interactions.splitlines()[:3]), "\n")113114 # --- Compound workflow: KEGG compound -> UniChem -> ChEMBL ---115 # Example: Geldanamycin116 cpd_hits = k.find("compound", "Geldanamycin")117 print("KEGG compound find('Geldanamycin'):")118 print(cpd_hits, "\n")119120 # If you already know the KEGG compound ID:121 kegg_compound_id = "C11222"122 uc = UniChem(verbose=False)123 chembl_id = uc.get_compound_id_from_kegg(kegg_compound_id)124 print(f"UniChem KEGG {kegg_compound_id} -> ChEMBL:")125 print(chembl_id, "\n")126127128if __name__ == "__main__":129 main()130```131132## Implementation Details133134- **Service objects**: Each remote resource is exposed as a Python class (e.g., `UniProt`, `KEGG`, `QuickGO`, `PSICQUIC`, `NCBIblast`). You instantiate a client and call methods that wrap the underlying endpoints.135- **Protocols**: BioServices abstracts **REST** and **SOAP/WSDL** services behind similar method calls; returned payloads may be text (TSV), XML, JSON-like dicts, or FASTA.136- **Common parameters**137 - `verbose`: toggles HTTP/request logging (`verbose=False` is recommended for scripts).138 - `TIMEOUT`: per-service timeout control (useful for slow networks or large responses).139 - Service-specific parameters (examples):140 - UniProt: `search(query, frmt=..., columns=...)`, `retrieve(accession, format)`, `mapping(fr=..., to=..., query=...)`141 - KEGG: `find(db, query)`, `get(entry_id)`, `parse(raw)`, `parse_kgml_pathway(pathway_id)`, `pathway2sif(pathway_id)`142 - NCBI BLAST: asynchronous job model (`run(...)` → `getStatus(jobid)` → `getResult(jobid, ...)`)143- **Data handling guidance**144 - TSV/tabular outputs: load into `pandas.read_csv(io.StringIO(text), sep="\t")`145 - XML outputs: parse with `BeautifulSoup` or `lxml`146 - Network exports (SIF): import into NetworkX/Cytoscape-compatible tooling147- **Operational considerations**148 - Many endpoints are **rate-limited**; implement retries/backoff for production pipelines.149 - Some services require **contact information** (e.g., NCBI BLAST email) and may enforce usage policies.150 - Availability varies by provider; design workflows to degrade gracefully (try/except, fallbacks).