STRING-GSEA is a Python toolkit to submit gene set enrichment analyses (GSEA) and over-representation analyses (ORA) to the STRING-DB API, poll for completion, and fetch/export results (tables, graphs, links) with minimal boilerplate.
- Features
- Installation
- Command-Line Interface
- Batch Workflow
- Architecture
- Development
- Docker
- Interactive Notebooks
- TODO
- License
- Injected GSEA and ORA gateways behind typed
RunGSEAandRunORAuse cases - Validated YAML and JSON boundaries that preserve the established persisted formats
- Automatic polling of STRING-DB until results are ready with configurable timeouts
- Multiple input formats support for both RNK files and XLSX files with differential expression data
- ORA analysis with custom background gene sets via
string_ora_run - Concrete filesystem writers for rank files, result TSVs, enrichment graphs, links, JSON, and Excel reports
- Quarto report generation with interactive visualizations and parameterized templates
- Snakemake batch workflow for processing multiple datasets with a single command
- Ordered species resolvers using FASTA evidence first and injected STRING identifier lookup second
- Configurable parameters for FDR thresholds, enrichment direction, and API settings
- Python 3.13 or higher
- UV package manager (recommended) or pip
- Quarto (for report generation)
- R with
protseaRpackage (for Quarto reports)
git clone https://github.com/prolfqua/stringdbpy.git
cd stringdbpy
# Install in editable mode with UV
uv pip install -e .
# Or with pip
pip install -e .Create a configuration file:
string_gsea_write_configThis creates $HOME/.config/string_gsea/config.toml containing:
api_key: Your STRING-DB API keyfdr: False discovery rate threshold (default: 0.25)caller_identity: Unique identifier for API callsge_enrichment_rank_direction: Direction for enrichment ranking (1 or -1)
Verify installation:
string_gsea_run --help
string_ora_run --help
string_gsea_workflow --helpThe package provides four command-line tools:
string_gsea_write_config# Run analysis with XLSX input (default: pep_2_no_imputed)
string_gsea_run "path/to/data.zip" "workunit_id" "output_directory"
# Specify analysis type
string_gsea_run "path/to/data.zip" "workunit_id" "output_directory" --which "pep_1"
# Override FDR threshold
string_gsea_run "path/to/data.zip" "workunit_id" "output_directory" --fdr 0.05
# Run with RNK files (set --which none)
string_gsea_run "path/to/data.zip" "workunit_id" "output_directory" --which noneParameters:
zip_path: Path to input ZIP file containing rank dataworkunit_id: Unique identifier for this analysis runout_dir: Output directory (default: current directory)--which: Analysis type (default:pep_2_no_imputed). Valid:pep_1,pep_1_no_imputed,pep_2,pep_2_no_imputed, ornonefor RNK input--fdr: FDR threshold (overrides value from config.toml)
# Run ORA with significant genes, background, and FASTA for species detection
string_ora_run "significant.txt" "background.txt" "proteome.fasta" \
--out-dir "./results" --workunit-id "ORA001"Input files:
significant.txt: One protein/gene ID per line (significant genes)background.txt: One protein/gene ID per line (all tested genes)proteome.fasta: FASTA file with OX= fields for species detection
The ORA enrichment_results.json format is defined by the packaged
enrichment_results.schema.json JSON Schema.
See Batch Workflow below.
After running string_gsea_run:
output_directory/
├── WU_{workunit_id}_GSEA/
│ ├── {analysis_name}/
│ │ ├── {contrast_name}_results.tsv
│ │ ├── {contrast_name}_results.png
│ │ ├── links.txt
│ │ └── *.rnk
│ ├── gsea_session.yml
│ ├── WU_{workunit_id}_string_gsea_results_long.xlsx
│ ├── WU_{workunit_id}_string_gsea_results_pivoted.xlsx
│ └── WU_{workunit_id}_string_gsea_results_merged.xlsx
└── WU_{workunit_id}_GSEA.zip
The ZIP is created only when requested directly or by the packaging workflow.
The string_gsea_workflow command runs GSEA, renders Quarto reports, and packages results via Snakemake. It takes the same core arguments as string_gsea_run.
# Run a single dataset
string_gsea_workflow "path/to/data.zip" "workunit_id" "./output"
# With options
string_gsea_workflow "path/to/data.zip" "workunit_id" "./output" --which pep_1 --fdr 0.1 --cores 4
# Dry-run
string_gsea_workflow "path/to/data.zip" "workunit_id" "./output" --dry-run
# Generate config
string_gsea_workflow configParameters:
zip_path: Path to input ZIP fileworkunit_id: Unique identifier for this analysis runout_dir: Output directory (default: current directory)--which: Analysis type (default:pep_2_no_imputed, ornonefor RNK input)--fdr: FDR threshold (overrides config.toml)--cores: Number of Snakemake cores (default: 1)--dry-run: Show what would be done without executing
The root CLI modules are composition roots. They construct the requests adapters, rank-source strategies, species resolvers, template locators, and use cases. The feature packages gsea, ora, taxonomy, and workflow do not import one another; root modules are the only cross-feature composition points.
External boundaries are explicit and typed:
GSEAGateway,ORAGateway,SpeciesResolver, andApiKeyProviderare consumer-owned capabilities.RequestsStringDBandRequestsApiKeyProviderare concrete adapters.- XLSX and RNK archives are handled by injected
RankSourceimplementations. - Analysis policies compose
RankFilterimplementations instead of returning operation names. - Installed R-package and workspace templates are handled by ordered
TemplateLocatorimplementations.
See the architecture guide for dependency rules and extension points.
Synchronize and run every merge-blocking check:
make sync
make checkmake check verifies the uv lock, Ruff formatting/lint, Import Linter contracts, strict Pyright over production and tests, deptry, deterministic pytest with at least 90% branch coverage, and isolated sdist/wheel installation. Live STRING-DB workflow tests remain separately marked through make test-smoke and make test-integration.
# Single-platform (current architecture)
docker buildx build -f docker/Dockerfile -t string-gsea:local --load .
# Multi-arch
docker buildx build -f docker/Dockerfile -t string-gsea:local --platform linux/amd64,linux/arm64 .The recommended way to run the container is via docker/string_gsea_docker.sh. It handles image pulling, --init for signal handling, --user so output files are owned by you, and mounts $(pwd) as /work. Prefers Podman if available, falls back to Docker.
# First time: generate config.toml (mounts ~/.config/string_gsea writable)
./docker/string_gsea_docker.sh config
# Run the pipeline
./docker/string_gsea_docker.sh data/input.zip WU123 ./output --cores 4
# Dry-run
./docker/string_gsea_docker.sh data/input.zip WU123 ./output --dry-run
# Pin a specific image version
./docker/string_gsea_docker.sh --image-version 0.1.0 -- data/input.zip WU123 ./output --cores 4# Generate config (first time only)
docker run --rm -it --init \
--user "$(id -u):$(id -g)" \
-v ~/.config/string_gsea:/root/.config/string_gsea \
-v "$(pwd):/work" -w /work \
string-gsea:local config
# Run pipeline (current directory mounted as /work)
docker run --rm -it --init \
--user "$(id -u):$(id -g)" \
-v "$(pwd):/work" -w /work \
-v ~/.config/string_gsea:/root/.config/string_gsea:ro \
string-gsea:local data/input.zip WU123 ./output --cores 4STRING-GSEA includes interactive Marimo notebooks for exploratory analysis.
# Install notebook dependencies
uv pip install -e ".[notebooks]"
# Launch notebooks
marimo run docs/marimo_notebooks/getting_started.py
marimo run docs/marimo_notebooks/gsea_exploration.py
# Edit notebooks
marimo edit docs/marimo_notebooks/gsea_exploration.pyAvailable notebooks:
getting_started.py-- Introduction to STRING-GSEA and Marimo basicsgsea_exploration.py-- Interactive explorer for GSEA results with filtering and visualization
For detailed instructions, see the Marimo Quick Start.
- Integration with bfabric
- R Integration: Create R functions to convert STRING-DB GSEA results to ClusterProfiler R objects for seamless integration with the R bioinformatics ecosystem
- scverse integration: Improve interoperability with scverse (e.g. decoupler)
- Interactive Visualizations: Port static visualizations from matplotlib/seaborn to Altair for enhanced interactivity in HTML reports
- Documentation: Expand documentation with more examples and tutorials
Distributed under the MIT License.
The shared JSON codec and STRING report templates now live in the standalone protseaR package. In a development workspace, place protseaR beside stringdbpy and run make install there before rendering reports. make docker-build-local supplies ../protseaR as Docker's named protseaR build context; override PROTSEA_CONTEXT to use another checkout or a pinned Git URL. The publish workflow uses the standalone repository, so publish it before triggering a STRING image build.