scientific-skills/Data Analysis/biopython/SKILL.md
A comprehensive toolbox for computational molecular biology; use it when you need programmatic sequence/structure parsing, batch bioinformatics pipelines, or automated NCBI/BLAST workflows.
npx skillsauth add aipoch/medical-research-skills biopythonInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill when you need to:
Bio.Entrez, respecting rate limits.Note: For quick one-off queries, tools like gget may be more convenient; for multi-service API aggregation, bioservices may be a better fit.
Bio.Seq, Bio.SeqRecord, Bio.SeqUtils (GC fraction, molecular weight, translation, etc.).Bio.SeqIO, Bio.AlignIO for FASTA/FASTQ/GenBank and alignment formats.Bio.Entrez for esearch, efetch, elink, and structured parsing via Entrez.read.Bio.Blast.NCBIWWW for remote BLAST and Bio.Blast.NCBIXML for XML parsing.Bio.PDB for PDB/mmCIF parsing, hierarchy traversal, and geometry calculations.Bio.Phylo and Bio.Phylo.TreeConstruction for tree I/O, distances, and construction.Reference guides (if present in this repository) can be consulted for deeper module-specific patterns:
references/sequence_io.mdreferences/alignment.mdreferences/databases.mdreferences/blast.mdreferences/structure.mdreferences/phylogenetics.mdreferences/advanced.mdbiopython==1.85numpy>=1.20 (required by Biopython)Install:
python -m pip install "biopython==1.85" "numpy>=1.20"
A complete, runnable example that:
Create example_biopython_pipeline.py:
from __future__ import annotations
import os
import time
from typing import Optional
from Bio import Entrez, SeqIO
from Bio.SeqUtils import gc_fraction
# Optional BLAST (remote). Comment out if you do not want network calls.
from Bio.Blast import NCBIWWW, NCBIXML
def configure_entrez() -> None:
"""
NCBI requires an email. An API key increases rate limits.
Set these via environment variables to avoid hardcoding secrets.
"""
email = os.environ.get("NCBI_EMAIL")
if not email:
raise RuntimeError("Set NCBI_EMAIL env var (required by NCBI). Example: export NCBI_EMAIL='[email protected]'")
Entrez.email = email
api_key = os.environ.get("NCBI_API_KEY")
if api_key:
Entrez.api_key = api_key
def read_first_fasta_record(path: str):
with open(path, "r", encoding="utf-8") as handle:
return next(SeqIO.parse(handle, "fasta"))
def blast_top_accession(sequence: str, program: str = "blastn", database: str = "nt") -> Optional[str]:
"""
Remote BLAST can be slow and rate-limited. For large-scale BLAST, prefer local BLAST+.
"""
result_handle = NCBIWWW.qblast(program, database, sequence)
blast_record = NCBIXML.read(result_handle)
if not blast_record.alignments:
return None
# Many BLAST titles include multiple identifiers; accession is usually available directly.
return blast_record.alignments[0].accession
def fetch_fasta_by_accession(accession: str) -> str:
with Entrez.efetch(db="nucleotide", id=accession, rettype="fasta", retmode="text") as handle:
return handle.read()
def main() -> None:
configure_entrez()
record = read_first_fasta_record("input.fasta")
seq = record.seq
print(f"ID: {record.id}")
print(f"Length: {len(seq)}")
print(f"GC fraction: {gc_fraction(seq):.2%}")
# Be polite to NCBI services in batch workflows.
time.sleep(0.34)
top_acc = blast_top_accession(str(seq))
if not top_acc:
print("No BLAST hits found.")
return
print(f"Top BLAST accession: {top_acc}")
time.sleep(0.34)
fasta_text = fetch_fasta_by_accession(top_acc)
print("Top hit FASTA:")
print(fasta_text)
if __name__ == "__main__":
main()
Run:
export NCBI_EMAIL="[email protected]"
# export NCBI_API_KEY="your_ncbi_api_key" # optional
python example_biopython_pipeline.py
Provide an input.fasta in the same directory, e.g.:
>demo
ATCGATCGATCGATCGATCG
SeqIO.parse) to avoid loading entire files into memory. Use SeqIO.read only when exactly one record is expected.Entrez.email (NCBI requirement).Entrez.api_key to increase request limits.time.sleep(0.34) as a conservative baseline) and implement retries for transient HTTP failures.NCBIWWW.qblast(...) is convenient but can be slow and is not ideal for high-throughput workloads.NCBIXML.read(...) (single record) or NCBIXML.parse(...) (multiple records).alignment.hsps.Bio.SeqUtils.gc_fraction(seq) for GC fraction (returns 0–1).seq.translate(table=...) with the correct genetic code table for reproducibility.Bio.PDB.PDBParser(QUIET=True) to suppress warnings when appropriate.tools
Generates complete conventional oncology bulk-transcriptome biomarker and hub-gene research designs from a user-provided cancer type and study direction. Always use this skill whenever a user wants to design, plan, or build a tumor bioinformatics study centered on differential expression, prognostic filtering or risk modeling, PPI-based hub-gene prioritization, diagnostic/prognostic evaluation, clinical association, immune infiltration context, methylation context, and optional tissue or cell validation. Covers five study patterns (signature-first prognostic workflow, hub-gene-first biomarker workflow, hybrid signature-to-hub workflow, immune-context biomarker workflow, translational validation workflow) and always outputs four workload configs (Lite / Standard / Advanced / Publication+) with recommended primary plan, step-by-step workflow, figure plan, validation strategy, minimal executable version, publication upgrade path...
development
Generates complete conventional non-oncology bioinformatics research designs from a user-provided disease context, process-related gene family or biological theme, and validation direction. Use when a study centers on multi-dataset bulk transcriptome integration, DEG analysis, process-gene intersection, enrichment analysis, GSEA, PPI hub-gene prioritization, TF/miRNA regulatory networks, ROC-based biomarker evaluation, and immune infiltration analysis. Covers five study patterns (process-DEG discovery, enrichment/GSEA interpretation, hub-gene prioritization, regulatory-network and immune interpretation, multi-layer public validation) and always outputs Lite / Standard / Advanced / Publication+ with a recommended primary plan, stepwise workflow, figure plan, validation hierarchy, minimal executable version, publication upgrade path, and strictly verified literature retrieval.
tools
Plans confounder control, variable adjustment logic, and bias mitigation strategies at the protocol stage for clinical, epidemiologic, translational, observational, and biomarker studies. Always use this skill when a user needs to identify major confounders, decide which variables should or should not be adjusted for, compare matching/stratification/weighting approaches, anticipate selection or measurement bias, or pressure-test a study design before execution. Focus on bias sensing, causal structure awareness, variable-role classification, and critical design review rather than generic statistical advice.
testing
Generates complete comparative network-toxicology research designs from a user-provided exposure pair, shared toxic phenotype, and validation direction. Use when a study centers on two related exposures under one outcome and needs target collection, shared-vs-specific target decomposition, enrichment, PPI hub prioritization, docking, optional transcriptomic cross-checks, and conservative mechanistic synthesis. Covers five study patterns and always outputs Lite / Standard / Advanced / Publication+ with a recommended primary plan, stepwise workflow, figure plan, validation hierarchy, minimal executable version, publication upgrade path, and strictly verified literature retrieval.