AGENT SKILL

bulkrna-survival

Load when comparing bulk expression strata against clinical time-to-event data with Kaplan-Meier and log-rank tests. R survival also fits Cox HR; Python reports a descriptive events/person-time ratio. Skip missing clinical outcomes.

使用场景后端与接口
License 许可
Apache-2.0
最近更新
2026-10-08
Stars
★ 161
Forks
27

01 前言 Front Matter

name
bulkrna-survival
tags
[ "bulkrna", "survival", "Kaplan-Meier", "Cox", "hazard-ratio", "clinical" ]
trigger
survival, Kaplan-Meier, Cox, prognosis, hazard ratio, overall survival, clinical outcome
description
Load when comparing bulk expression strata against clinical time-to-event data with Kaplan-Meier and log-rank tests. R survival also fits Cox HR; Python reports a descriptive events/person-time ratio. Skip missing clinical outcomes.

02 资源文件 8

03 SKILL.md 正文

bulkrna-survival

When to use

Load when comparing bulk expression strata against clinical time-to-event data with Kaplan-Meier and log-rank tests. R survival also fits Cox HR; Python reports a descriptive events/person-time ratio. Skip missing clinical outcomes.

Use from a step

from skills._sdk.notebook import load_skill, write_output
library = load_skill("bulkrna-survival")
result = library.analyze(data, clinical=clinical, backend="python")
write_output(result, "tables/result.csv")
write_output(library.curve_figure(result, gene="G"), "figures/result.png")

Read expression and metadata with read_input before calling the library. examples/example_step.py constructs a small synthetic dataset and checks its results through the step runner and fresh-kernel replay.

API

<!-- api:begin generated from _api.py; regenerate with run.py api <skill dir> --write -->

analyze(data: pd.DataFrame, *, clinical: pd.DataFrame, genes: list[str] | None=None, cutoff_method: str='median', backend: str='auto') -> pd.DataFrame

Return gene-wise survival comparisons without modifying expression.

:param data: Nonnegative feature-by-sample expression. :param clinical: Clinical table with unique sample, nonnegative time and binary event columns. :param genes: Genes to test; None uses every row. Missing genes raise. :param cutoff_method: CLI default median; optimal scans cuts with unadjusted p-values. :param backend: auto prefers R survival with Cox HR, as the CLI did; python uses an events/person-time ratio. :returns: Per-gene table with diagnostics and KM points attached in attrs. :raises ValueError: Identifiers, clinical values, requested genes or comparison groups are invalid. :raises ImportError: Explicit R backend lacks survival or Matrix. :raises RuntimeError: The requested R method fails or returns incomplete results.

run_info(data: pd.DataFrame, *, keep: bool=True) -> dict

Return actual backend, HR estimator and summary.

:param data: Result from analyze. :param keep: Keep diagnostics by default; the CLI passes False. :returns: Diagnostics dictionary. :raises ValueError: The table has no analysis diagnostics.

km_table(data: pd.DataFrame) -> pd.DataFrame

Return the fitted Kaplan-Meier points for both expression strata.

:param data: Result from analyze. :returns: New table with gene, group, time and survival columns. :raises ValueError: The result lacks stored curves.

curve_figure(data: pd.DataFrame, *, gene: str)

Plot the stored Kaplan-Meier curves for one analyzed gene.

:param data: Result from analyze. :param gene: Exact gene identifier in the result. :returns: Matplotlib Figure. :raises ValueError: No curve exists for the requested gene.

<!-- api:end -->

Methods and parameters

The function library returns DataFrames and Figures. The CLI loads the same library and owns reports and file writes. R runs in a temporary directory using Matrix Market, feature/sample identifiers and metadata. No R intermediate is a permanent CLI output.

Gotchas

  • analyze(backend="auto") prefers R survival, which fits Cox PH hazard ratios. Its Python fallback uses a descriptive events/person-time ratio. run_info()["hazard_estimator"] distinguishes them.
  • analyze raises for missing genes or insufficient high/low groups; it does not silently deliver a subset of the requested genes.
  • analyze(cutoff_method="optimal") scans cutoffs and reports unadjusted p-values. Treat the selected-cutoff test as exploratory.
  • km_table exposes both KM curves. Median survival is None when a curve never reaches 0.5; no extrapolated median is invented.
  • run_info()["dropped_expression_samples"] reports samples excluded by the expression/clinical intersection. Clinical IDs must be unique.

Inputs and outputs

Feature-by-sample expression CSV and a clinical CSV containing unique sample, nonnegative time and binary event.

CLI outputs:

  • tables/survival_results.csv
  • figures/km_<gene>.png per successful gene
  • figures/forest_plot.png when at least two genes succeed
  • report.md, result.json
  • reproducibility/commands.sh

CLI

python skills/bulkrna/bulkrna-survival/bulkrna_survival.py --demo --output /tmp/bulkrna_survival_demo

Run the script with --help for real-input arguments.

See also

  • references/parameters.md
  • references/methodology.md
  • references/output_contract.md

Dependencies

matplotlib, numpy, pandas, scipy, survival, Matrix

04 同仓库更多 Skills

TianGzlab
TianGzlab/OmicsClaw

demo-skill

A fixture skill for the skill environment tests. Use it for nothing else.

Skill与智能体开发
★ 161
TianGzlab
TianGzlab/OmicsClaw

fake-domains

Test fixture for the golden deployment in tests/entry. Load never; it has no script.

★ 161
TianGzlab
TianGzlab/OmicsClaw

replace-me-skill

Load when copying this directory to bootstrap a new OmicsClaw skill. Skip when an existing skill already covers the request.

Skill与智能体开发
★ 161
TianGzlab
TianGzlab/OmicsClaw

spatial-velocity

Load when estimating RNA velocity on a spatial AnnData with `layers["spliced"]` + `layers["unspliced"]` via scVelo (stochastic / deterministic / dynamical) or veloVI (deep generative). Skip when input lacks the spliced/unspliced layers (must be quantified upstream by velocyto / kb-python / STARsolo); non-spatial scRNA velocity (use sc-velocity).

★ 161
TianGzlab
TianGzlab/OmicsClaw

spatial-trajectory

Load when inferring pseudotime / lineage trajectories on a preprocessed spatial AnnData via DPT (default — diffusion pseudotime), CellRank (terminal-state + fate-probability), or Palantir (waypoint branch probabilities). Skip when the data has spliced/unspliced layers and you want velocity-driven dynamics (use spatial-velocity); non-spatial scRNA pseudotime (use sc-pseudotime).

★ 161
TianGzlab
TianGzlab/OmicsClaw

spatial-statistics

Load when running spatial autocorrelation / hotspot / co-occurrence / neighbourhood-enrichment / Ripley K stats on a clustered spatial AnnData via squidpy. Skip when ranking spatially variable genes (use spatial-genes); tissue domain detection (use spatial-domains).

★ 161