Skip to main content

Context-aware confidence estimation for targeted proteomics.

Project description

Context: Confidence Estimation for Targeted Proteomics

Overview

Context produces PSM- and peptide-level q-values and PEPs for targeted mass-spec assays. Because the reference panel is usually too small to train a discriminant directly, Context trains the discriminant on the background PSMs from the same run (a large, statistically well-behaved background) and transfers the learned linear discriminant to score the reference panel. Two engines are supported, each paired with its own confidence-estimation back-end:

  • percolator (default) — Percolator trains the discriminant, and pyIsoPEP (q2pep) then computes FDR + q-values from TDC scores and fits an I-spline q -> PEP, separately at the PSM and peptide levels.
  • mprophet — a Python re-implementation of the mProphet-based rescoring and statistical validation components built into EncyclopeDIA for PRM. q-values are Benjamini–Hochberg-adjusted p-values from a Gaussian decoy null, and PEPs are Storey's local FDR (qvalue::lfdr, KDE on logit-p-values, π₀ floored at 0.05), exactly as EncyclopeDIA reports them. pyIsoPEP is not used on this pathway.

Context is distributed as both a container image (Podman-, Docker- and Apptainer-compatible) and a Python package exposing the same CLI.


Installation

PyPI

pip install context-ms

Context is a Python package. The mprophet engine has no external dependency beyond NumPy/pandas. The percolator engine prefers a local percolator executable on PATH and falls back to a container image via Podman or Docker (set with --container-cmd, default podman):

  • Percolator container: ghcr.io/percolator/percolator:master

Container image

podman pull ghcr.io/shannon225/context:main
# or
apptainer build context.sif docker://ghcr.io/shannon225/context:main

Input & output

Input: two Percolator-compatible tsv files for background and reference PSMs/peptides. They must share an identical header (same columns, same order).

Output: for context run --background BG --reference REF --prefix P --outdir results/ --engine E:

results/
  weights/P.weights.txt           # trained weights
  P.rescored_features.tsv         # reference features rescored with the trained weights
  P.psm.reference.txt             # PSM-level reference targets
  P.peptide.reference.txt         # peptide-level reference targets

Weights file format:

  • percolator: Percolator's native --weights output (3 lines per CV bin).
  • mprophet: a two-column TSV with feature and weight, plus a final __bias__ row carrying the LDA constant.

Each output path can be overridden individually via --weights-out, --rescored-out, --psm-out, --peptide-out. Values may be plain file names (written inside --outdir, or inside --outdir/weights for the weights file) or absolute paths.


Command-line reference

context run -h
flag default description
--background FILE required background feature TSV used to train the engine
--reference FILE required reference panel feature TSV
--prefix STR required output prefix for results files
--outdir DIR results output directory
--engine NAME percolator percolator or mprophet
--seed INT 1 seed; passed to Percolator or to mprophet's RNG
--container-cmd CMD podman container runtime fallback (podman or docker)
--input-profile NAME encyclopedia mprophet-only; feature-column selection profile (auto, pin, encyclopedia)
--seed-coefficients NAME_OR_PATH encyclopedia mprophet-only; built-in name (encyclopedia, none) or path to a JSON file mapping feature names to seed-model coefficients
--weights-out FILE <prefix>.weights.txt weights output file name (or path); relative paths land under <outdir>/weights
--rescored-out FILE <prefix>.rescored_features.tsv rescored-features output file name (or path); relative paths land under <outdir>
--psm-out FILE <prefix>.psm.reference.txt PSM-level output file name (or path); relative paths land under <outdir>
--peptide-out FILE <prefix>.peptide.reference.txt peptide-level output file name (or path); relative paths land under <outdir>

Input profiles (mprophet only)

  • auto — if any column starts with var_ or main_var_, keep only those (OpenSWATH/pyprophet convention); otherwise fall back to encyclopedia.
  • pin — keep every column the pin convention exposes as a feature.
  • encyclopedia — drop the metadata columns EncyclopeDIA's MProphetFeatureReader excludes by name (pepLength, charge1..4, precursorMass, RTinMin, midTime, numberOfMatchingPeaksAboveThreshold, primary, TD).

--input-profile has no effect on the percolator engine.

Seed coefficients (mprophet only)

A JSON dictionary mapping feature column names to starting linear coefficients for the seed LDA. Names that don't appear in the input contribute 0; if all entries drop out, the seed model is disabled and inner iter 0 falls back to ranking by the single best feature. Pass none to disable the seed model unconditionally.

Confidence estimation

The two engines use different back-ends for q-values and PEPs:

  • percolator — Percolator trains the discriminant, then pyIsoPEP computes q-values (from TDC counts) and PEPs (from an I-spline fit to q(score)). Called separately for the PSM-level and the peptide-level tables.

  • mprophet — EncyclopeDIA's method throughout, at both the PSM level and (after per-sequence deduplication, highest score wins) the peptide level:

    • fit a Gaussian N(µ_d, σ_d) to the decoy scores;
    • p = 1 - Φ((score - µ_d) / σ_d) for both targets and decoys;
    • q = Benjamini–Hochberg-adjusted p-values;
    • PEP = Storey qvalue::lfdr (KDE on the logit-transformed p-values, Silverman bandwidth, monotone non-decreasing in p), with π₀ floored at 0.05.

    The same routine is used inside the mProphet training loop for the "passing targets" selection at each inner iteration and for the held-out evaluation that picks between the trained LDA and the seed model.


Examples

cd example

PyPI

# Percolator (default)
context run \
  --background background.tsv \
  --reference    reference.tsv \
  --prefix    run01 \
  --outdir    results_run01

# mProphet
context run \
  --background background.tsv \
  --reference    reference.tsv \
  --prefix    run01 \
  --outdir    results_run01 \
  --engine    mprophet

Container image

# Podman
podman run --rm -v "$PWD:/work" -w /work \
  ghcr.io/shannon225/context:main \
  run --background background.tsv --reference reference.tsv \
      --prefix run01 --outdir results_run01 --engine mprophet

# Apptainer
apptainer run --bind "$PWD:/work" --pwd /work context.sif \
  run --background background.tsv --reference reference.tsv \
      --prefix run01 --outdir results_run01

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

context_ms-0.1.3.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

context_ms-0.1.3-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file context_ms-0.1.3.tar.gz.

File metadata

  • Download URL: context_ms-0.1.3.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for context_ms-0.1.3.tar.gz
Algorithm Hash digest
SHA256 daf09cd69327181e224a28e0a40ac8e1c3777d68a4fbe214e5e7f369a2066c0f
MD5 45acc2f8ccb37fe1e7a6163fbb9cbef7
BLAKE2b-256 aeec013c69c2afe325af10b8d35eae700c16e3664d5fb5bb9c576707134fa0ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for context_ms-0.1.3.tar.gz:

Publisher: PyPIpublish.yaml on shannon225/Context

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file context_ms-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: context_ms-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for context_ms-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 db4309c40cadc57104d455841f043dcae04c636d40ccb720d29954d3b1f2d4ef
MD5 f049a954176d1506f4c9ef517b70fcbf
BLAKE2b-256 6e0d3ced63893150dbb099d1375274da2ef565890a7abfa0c5131f2de0e39432

See more details on using hashes here.

Provenance

The following attestation bundles were made for context_ms-0.1.3-py3-none-any.whl:

Publisher: PyPIpublish.yaml on shannon225/Context

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page