Skip to content

STRING Database Science Skill and CLI Tool

Science Skill and command-line interface (CLI) for interacting with the STRING Database API v12.0. This skill enables AI agents and human researchers to query protein-protein interaction (PPI) networks, retrieve functional enrichment annotations (Gene Ontology, KEGG, Reactome), analyze cross-species homology, generate network visualizations, and perform genome-wide ranked gene set enrichment analysis (Values/Ranks GSEA).


Project Overview

The STRING (Search Tool for the Retrieval of Interacting Genes/Proteins) database is a comprehensive repository of known and predicted protein-protein interactions covering physical interactions and functional associations across thousands of organisms.

Biomedical PPI and Functional Enrichment Workflow

This repository provides:

  • skills/string_database/SKILL.md: Complete skill specification for AI agent harnesses using progressive disclosure.
  • skills/string_database/scripts/string_cli.py: A robust Python CLI built with inline PEP 723 script metadata, strict 1 QPS rate-limiting via polite-http, structured logging, output redirection to protect context windows, and diagnostic error reporting.
  • skills/string_database/scripts/dashboard_builder.py: A standalone HTML dashboard builder that renders the CLI's output files plus live UniProt / AlphaFold / RCSB lookups.
  • skills/string_database/references/: Domain reference manuals covering identifier mapping, network topologies, statistical enrichment models, values/ranks GSEA, and Bayesian score calibrations.
  • sample_data/: Fully synthetic, PHI-free sample datasets for testing mapping, pathway enrichment, and continuous expression ranking.
  • tests/: Offline unit tests plus live integration tests that run against the real APIs.

Data provenance guarantee

Every number, node, edge, pathway, domain and 3D coordinate this skill reports comes from one of:

  1. a live STRING API v12.0 response,
  2. a live UniProt / AlphaFold / RCSB PDB lookup, or
  3. a file the user supplied.

There are no built-in gene tables, no recorded API responses, and no synthesized structures. When a value cannot be resolved (for example, a protein with no AlphaFold model) the dashboard shows an explicit empty state instead of a placeholder. This is enforced by tests/test_no_fabricated_data.py, which fails the build if fabricated data or mocking is reintroduced.


Project Structure

string-database-visualize-skill/
├── .gitignore
├── .licenses/
│   └── string_database_LICENSE.txt
├── LICENSE
├── Makefile                       # make test / test-live / lint / regenerate-results
├── README.md
├── assets/
│   └── workflow_overview.png
├── conftest.py                    # puts the skill scripts + test harness on sys.path
├── pyproject.toml                 # dependency, pytest and ruff configuration
├── requirements.txt               # pip/venv equivalent of the PEP 723 metadata
├── results/                       # regenerate with `make regenerate-results`
│   ├── dashboard.html
│   ├── enrichment.tsv
│   ├── mapped_genes.tsv
│   ├── network_edges.tsv
│   └── ppi_enrichment.tsv
├── sample_data/
│   ├── synthetic_cancer_genes.txt
│   ├── synthetic_mapping_queries.txt
│   └── synthetic_ranked_expression.tsv
├── skills/
│   └── string_database/
│       ├── SKILL.md
│       ├── references/
│       │   ├── enrichment.md
│       │   ├── interactions.md
│       │   ├── mapping.md
│       │   ├── scores_and_metrics.md
│       │   └── valuesranks.md
│       └── scripts/
│           ├── dashboard_builder.py
│           └── string_cli.py
└── tests/
    ├── __init__.py
    ├── harness.py                 # real-CLI runner + live-service gating
    ├── test_cli_parsing.py
    ├── test_dashboard.py
    ├── test_enrichment_filtering.py
    ├── test_live_smoke.py
    ├── test_no_fabricated_data.py
    ├── test_species_lookup.py
    └── test_valuesranks_validation.py

Prerequisites and Installation

The CLI requires Python 3.10+. The recommended runner is uv, which resolves the dependencies declared in the script's PEP 723 header automatically.

Option A: uv (recommended)

uv --version   # verify installation

If uv is not installed:

# Linux / macOS
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Run any command with uv run skills/string_database/scripts/string_cli.py <subcommand>; dependencies are cached in an isolated environment.

Option B: plain virtualenv + pip

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt          # or: pip install -e ".[dev]"
python skills/string_database/scripts/string_cli.py species --query mouse

Network endpoints used

Host Used by Purpose
string-db.org all query subcommands PPI networks, enrichment, homology, images, GSEA
rest.uniprot.org dashboard accession, sequence length and domain features
alphafold.ebi.ac.uk dashboard predicted 3D backbone coordinates
files.rcsb.org dashboard experimental PDB coordinates (fallback)

Use dashboard --no-fetch-structures to build a dashboard with zero outbound calls beyond the STRING data you already downloaded.

Configuration

Variable Purpose Default
STRING_API_KEY API key for the Values/Ranks workflow (alternative to --api_key, keeps keys out of shell history and process listings) unset
STRING_CLI_LOG_LEVEL Default log verbosity (DEBUG/INFO/WARNING/ERROR) INFO
RUN_LIVE_TESTS Set to 0 to skip all live tests 1
RUN_LIVE_VALUESRANKS Set to 0 to skip the slow async GSEA job test when STRING's queue is backed up 1
KEEP_TEST_OUTPUT Set to 1 to keep live test output files for debugging unset

No credentials are ever hardcoded in the repository.

Logging, stdout and exit codes

  • stdout carries only consumable result lines (summaries, Saved ... to: <path>), so output can be parsed or piped.
  • stderr carries structured log records: 2026-01-01 12:00:00,000 ERROR string_cli: .... Control verbosity with --log-level (placed before the subcommand) or STRING_CLI_LOG_LEVEL.
  • Exit codes: 0 success, 1 runtime/API/filesystem failure, 2 usage error (missing inputs or credentials).
uv run skills/string_database/scripts/string_cli.py --log-level DEBUG map -i TP53 -s 9606 -o results/tp53.tsv

Licensing and Terms of Use

  • Project Code and Skill: This project, its CLI tool (string_cli.py), test suite, and skill definitions are licensed under the Apache License, Version 2.0.
  • STRING Database Access and Data: Non-commercial and academic use of the STRING database is freely permitted under the Creative Commons Attribution 4.0 (CC-BY 4.0) license.
  • Commercial entities must obtain a commercial license from the STRING consortium.
  • Access terms: https://string-db.org/cgi/access
  • The CLI automatically verifies and logs license compliance in .licenses/string_database_LICENSE.txt.

Non-Technical User Guide

This guide is for researchers, bioinformaticians, and non-programmers interacting with an AI assistant equipped with this skill. You do not need to write code or execute terminal commands manually.

How It Works

When you ask biological questions involving gene lists, protein interactions, or pathway enrichment, the AI assistant automatically uses this skill to:

  1. Verify the organism and resolve your gene names to canonical identifiers.
  2. Query the STRING database for interaction networks, confidence scores, and enriched pathways.
  3. Save structured data files and generate an interactive visual dashboard for your browser or preview pane.

What Data Files You Can Provide

1. Simple Gene List

A plain text file containing gene symbols or protein IDs (one per line).

Example (my_genes.txt):

TP53
MDM2
CDKN1A
RB1
E2F1
ATM
CHEK2
BRCA1
PTEN
PIK3CA

2. Ranked Expression Table

A two-column tab-separated table containing gene symbols in column 1 and numerical rank metrics (such as log2 fold-change, signed p-values, or t-statistics) in column 2.

Example (ranked_expression.tsv):

TP53	9.45
CDKN1A	8.12
MDM2	7.80
ATM	6.23
MYC	-3.50
BCL2	-4.70

Example Prompts for Common Research Scenarios

Scenario 1: Identifying Interaction Partners for a Target Protein

"Find the top 10 highest-confidence interaction partners for human TP53 using STRING. Summarize what cellular roles each partner plays."

Scenario 2: Pathway Enrichment for a Differentially Expressed Gene Set

"I have a list of 15 upregulated genes in my experiment: TP53, MDM2, CDKN1A, RB1, E2F1, ATM, CHEK2, BRCA1, PTEN, PIK3CA, AKT1, MTOR, EGFR, KRAS, BRAF. Run KEGG and Reactome pathway enrichment on these genes in human (Taxon ID 9606), and report any pathways with FDR < 0.01."

Scenario 3: Generating an Interactive Network Dashboard

"Analyze the interaction network for the attached file my_genes.txt in human. Generate an interactive dashboard with the network graph and pathway table so I can explore the results."

Scenario 4: Cross-Species Ortholog Comparison

"Map the human proteins TP53 and MDM2 to their mouse orthologs (Taxon ID 10090), and check if their interaction score is conserved."

Scenario 5: Cutoff-Free Genome-Wide GSEA

"Run a Values/Ranks gene set enrichment analysis on my ranked differential expression file ranked_expression.tsv for human. Identify the biological processes most enriched at the positive and negative ends of the ranking."


Command-Line Reference (string_cli.py)

Run any command using uv run skills/string_database/scripts/string_cli.py <subcommand> [options].

Supplying identifiers. --identifiers / -i accepts space- or comma-separated names, and @path/to/file reads them from a file. A file supplies one identifier per line; blank lines and # comments are skipped, only the first tab-delimited field of each line is used, and a leading STRING TSV header row is dropped. A STRING result table can therefore be chained straight into the next command:

uv run skills/string_database/scripts/string_cli.py map -i @sample_data/synthetic_cancer_genes.txt -s 9606 --limit_to_best -o results/mapped_genes.tsv
uv run skills/string_database/scripts/string_cli.py network -i @results/mapped_genes.tsv -s 9606 -o results/network_edges.tsv

1. Species Resolution (species)

Resolve common names or scientific names to NCBI Taxonomy IDs, or view the built-in top 20 model organisms table.

# Search for an organism
uv run skills/string_database/scripts/string_cli.py species --query "mouse"

# View table of common model organisms
uv run skills/string_database/scripts/string_cli.py species

2. Identifier Mapping (map)

Map gene symbols, UniProt accessions, or Ensembl IDs to canonical STRING identifiers (stringId).

uv run skills/string_database/scripts/string_cli.py map \
  --identifiers TP53 MDM2 CDKN1A \
  --species 9606 \
  --limit_to_best \
  --output results/mapped_genes.tsv

3. Interaction Networks (network)

Extract interaction edges between query proteins with confidence score filtering.

uv run skills/string_database/scripts/string_cli.py network \
  --identifiers TP53 MDM2 CDKN1A RB1 \
  --species 9606 \
  --required_score 700 \
  --summary \
  --output results/network_edges.tsv

4. Interaction Partners (partners)

Retrieve top interaction partners for seed proteins.

uv run skills/string_database/scripts/string_cli.py partners \
  --identifiers 9606.ENSP00000269305 \
  --species 9606 \
  --limit 15 \
  --required_score 700 \
  --output results/tp53_partners.tsv

5. PPI Network Enrichment (ppi-enrichment)

Calculate whether the query proteins have significantly more interactions than expected by chance.

uv run skills/string_database/scripts/string_cli.py ppi-enrichment \
  --identifiers TP53 MDM2 CDKN1A RB1 ATM \
  --species 9606 \
  --output results/ppi_enrichment.tsv

6. Functional Enrichment (enrichment)

Perform over-representation analysis against Gene Ontology, KEGG, Reactome, and protein domain databases. Results are filtered by category/FDR, sorted by ascending FDR, and truncated by --limit.

uv run skills/string_database/scripts/string_cli.py enrichment \
  --identifiers @sample_data/synthetic_cancer_genes.txt \
  --species 9606 \
  --category KEGG \
  --fdr 0.05 \
  --summary \
  --output results/enrichment.tsv

7. Functional Terms Search (functional-terms)

Search for functional annotations, disease associations, or Gene Ontology terms matching a text keyword.

uv run skills/string_database/scripts/string_cli.py functional-terms \
  --term_text "DNA repair" \
  --species 9606 \
  --limit 20 \
  --output results/dna_repair_terms.tsv

8. Protein Functional Annotation (functional-annotation)

Retrieve functional descriptions and domain summaries for a set of proteins.

uv run skills/string_database/scripts/string_cli.py functional-annotation \
  --identifiers TP53 MDM2 \
  --species 9606 \
  --output results/annotations.tsv

9. Cross-Species Homology (homology / homology-best)

Map orthologous proteins between species.

uv run skills/string_database/scripts/string_cli.py homology-best \
  --identifiers TP53 MDM2 \
  --species 9606 \
  --species_b 10090 \
  --output results/human_mouse_orthologs.tsv

10. Network Visualization (image)

Generate high-resolution PNG or vector SVG network diagrams.

uv run skills/string_database/scripts/string_cli.py image \
  --identifiers TP53 MDM2 CDKN1A RB1 \
  --species 9606 \
  --format svg \
  --network_flavor confidence \
  --output results/network.svg

11. Ranked Dataset GSEA (valuesranks Workflow)

Perform cutoff-free gene set enrichment on a continuously ranked dataset (e.g. differential expression log2FC or signed p-value). Polling retries transient network failures against the --timeout budget.

# 1. Fetch anonymous API key
uv run skills/string_database/scripts/string_cli.py valuesranks-key \
  --output results/key.json

# 2. Submit ranked dataset (key may also come from $STRING_API_KEY)
export STRING_API_KEY="<API_KEY>"
uv run skills/string_database/scripts/string_cli.py valuesranks-submit \
  --input_file sample_data/synthetic_ranked_expression.tsv \
  --species 9606 \
  --output results/job.json

# 3. Poll and download final results
uv run skills/string_database/scripts/string_cli.py valuesranks-status \
  --job_id "<JOB_ID>" \
  --wait \
  --timeout 300 \
  --output results/ranked_enrichment.tsv

Important

The valuesranks-key response carries a note saying the key activates "within 30 minutes"; in practice it is often usable immediately. If a submit returns {"status": "error"} the CLI logs STRING's message and exits 1 - wait and retry rather than minting another key. Reuse a stored key via STRING_API_KEY.

The three subcommands wrap json/get_api_key, json/valuesranks_enrichment_submit and json/valuesranks_enrichment_status. There is no separate results endpoint: on status == "success" the CLI follows the absolute download_url returned in the status record. Add --rank_direction {-1,0,1} to restrict testing to one tail of the ranking. See valuesranks.md for the full output schema.

12. Interactive HTML Dashboard (dashboard)

Generate a self-contained, responsive HTML dashboard for agent harnesses with HTML / iframe preview panes. Requires at least one input file; missing files are a hard error (exit code 1) rather than a silently empty dashboard.

Features included in the dashboard:

  • Light and dark theme toggle with icon-only button (Sun / Moon SVG icons).
  • Real-time physics simulation with drag-and-drop nodes, zooming, panning, anti-overlap constraints, and live minimum confidence score slider.
  • Metric summary cards (mapped proteins count, observed/expected edges, average node degree, PPI p-value) read directly from the PPI enrichment file.
  • Functional enrichment explorer with search filtering, category dropdown (KEGG, Reactome, GO Process, etc.), FDR significance bars, and CSV export.
  • Protein details inspector modal with a 3D viewer that renders real AlphaFold or RCSB PDB coordinates, states which database each structure came from, and shows an explicit "no structure available" state when nothing can be retrieved.
  • Domain architecture track built from UniProt feature annotations for the queried proteins (any organism, not a fixed gene list).
uv run skills/string_database/scripts/string_cli.py dashboard \
  --title "Synthetic Cancer Gene Network & Pathway Analysis" \
  --map_file results/mapped_genes.tsv \
  --network_file results/network_edges.tsv \
  --ppi_file results/ppi_enrichment.tsv \
  --enrichment_file results/enrichment.tsv \
  --output results/dashboard.html

# Deterministic, fully offline build (no UniProt/AlphaFold/RCSB calls)
uv run skills/string_database/scripts/string_cli.py dashboard \
  --map_file results/mapped_genes.tsv \
  --no-fetch-structures \
  --structure-timeout 5 \
  --output results/dashboard_offline.html

Agent Harness Integration

This skill conforms to standard Agent Skill specifications and can be used across various AI agent harnesses:

1. Workspace Configuration

  1. Place the repository in the workspace or add skills/string_database to your agent's skill search paths.
  2. The agent discovers skills/string_database/SKILL.md automatically.
  3. When answering questions about protein interactions or gene enrichment, the agent invokes string_cli.py to fetch data, inspects results safely, and presents structured answers.

2. Execution Environment

  • Ensure the agent environment has Python 3.10+ and uv (or a virtualenv with requirements.txt) to execute CLI commands and generate interactive HTML artifacts.

Synthetic Sample Datasets

All datasets in sample_data/ are 100% synthetic, containing public gene symbols and simulated numerical values. They are inputs for demos and tests - they are never substituted for API responses. They contain no protected health information (PHI):

  • sample_data/synthetic_cancer_genes.txt: 15 canonical cancer-associated gene symbols for testing mapping and over-representation analysis.
  • sample_data/synthetic_ranked_expression.tsv: 30 ranked gene entries with simulated signed scores for testing the Values/Ranks workflow.
  • sample_data/synthetic_mapping_queries.txt: Mixed symbols, UniProt accessions, and Ensembl protein IDs for testing batch normalization.

Regenerating results/

The files in results/ are build artifacts, not fixtures. Rebuild them from live STRING queries at any time:

make regenerate-results

CI runs this target so the committed dashboard is provably produced by the current code.


Testing and Verification

The suite contains no mocking libraries, no recorded API responses and no fixture payloads. Tests either exercise pure functions with inputs they generate, or run the real CLI against live services. Live tests skip automatically when the network is unavailable or RUN_LIVE_TESTS=0.

# Offline: parsers, validators, argument handling, dashboard payload construction
make test
# equivalent to:
RUN_LIVE_TESTS=0 uv run --with pytest --with polite-http pytest tests/ -v

# Full suite including live STRING / UniProt / AlphaFold integration tests
make test-live

# Static analysis (unused imports, bare excepts, bugbear rules)
make lint

# Just the asynchronous Values/Ranks GSEA job (also part of `make test-live`)
make test-valuesranks

Test Suite Components

  • tests/harness.py: Shared real-CLI runner plus live-service reachability gating.
  • tests/test_cli_parsing.py: Parser and identifier-resolver behaviour, plus offline failure paths (missing files, missing API key, stdout/stderr separation, exit codes).
  • tests/test_species_lookup.py: Search behaviour of the species subcommand and live validation that the built-in taxon IDs are accepted by STRING.
  • tests/test_enrichment_filtering.py: The skill's real filtering/sorting functions, verified both deterministically and against live STRING payloads.
  • tests/test_valuesranks_validation.py: The real ranked-TSV validator (malformed rows, comments, empty identifiers, scientific notation) and CLI exit codes.
  • tests/test_dashboard.py: PDB parsing, payload-to-source-file equivalence, live UniProt annotation for arbitrary proteins, full live dashboard build, and regressions against fabricated identifiers or synthetic structures.
  • tests/test_live_smoke.py: Live integration coverage for every subcommand, asserting schemas and that --required_score, --limit and --fdr are actually honoured. Includes the full asynchronous Values/Ranks GSEA round trip (key -> submit -> poll -> download), which checks that every protein STRING reports back was present in the submitted ranking.
  • tests/test_no_fabricated_data.py: Meta-tests banning mocking, hardcoded gene tables, procedural structures and print-style diagnostics.

License

This software and skill suite are distributed under the terms of the Apache License, Version 2.0. See the LICENSE file for the full text.

Releases

Packages

Contributors

Languages