Tcga Survival Analysis
by Kang-chen
Perform survival analysis on TCGA cancer data using cBioPortal API and lifelines. Use when user wants to analyze gene expression and survival outcomes, create Kaplan-Meier curves, run Cox proportional hazards models, or study specific genes (like TP53, KRAS, EGFR) in cancer cohorts (LUAD, LUSC, BRCA, etc.). Triggers on keywords like "TCGA", "survival analysis", "Kaplan-Meier", "hazard ratio", or cancer type abbreviations.
Skill Details
Repository Files
3 files in this skill directory
name: tcga-survival-analysis description: Perform survival analysis on TCGA cancer data using cBioPortal API and lifelines. Use when user wants to analyze gene expression and survival outcomes, create Kaplan-Meier curves, run Cox proportional hazards models, or study specific genes (like TP53, KRAS, EGFR) in cancer cohorts (LUAD, LUSC, BRCA, etc.). Triggers on keywords like "TCGA", "survival analysis", "Kaplan-Meier", "hazard ratio", or cancer type abbreviations.
TCGA Survival Analysis
Perform survival analysis on TCGA data using cBioPortal API + lifelines.
Step 1: Environment Check
Before starting the analysis, verify that required dependencies are available:
# Check required packages
python -c "import pandas, numpy, matplotlib, requests, lifelines; print('All dependencies OK')"
Dependency check strategy (by priority):
- Check the currently activated environment (or user-specified environment)
- Missing packages → Install with
uv pip installfirst - If uv unavailable → Use
pip install - If installation fails or conflicts → Only then create a new conda environment
Required dependencies:
- pandas
- numpy
- matplotlib
- requests
- lifelines
To install missing packages:
# Prefer uv (faster)
uv pip install lifelines
# Or use pip
pip install lifelines
Step 2: Quick Start
import pandas as pd
import requests
from lifelines import KaplanMeierFitter
from lifelines.statistics import logrank_test
# cBioPortal API
CBIOPORTAL_API = "https://www.cbioportal.org/api"
study_id = "luad_tcga_pan_can_atlas_2018" # LUAD Pan-Cancer Atlas
# Fetch EGFR expression data
# ... (see workflow.md for details)
# Perform Kaplan-Meier analysis
kmf = KaplanMeierFitter()
kmf.fit(time, event, label='Gene High')
kmf.plot_survival_function()
Workflow
See workflow.md for detailed workflow, including:
- Environment check - Verify dependencies, install as needed
- Data download - Fetch expression and clinical data from cBioPortal
- Data processing - Merge expression and survival data
- Survival analysis - Kaplan-Meier analysis and Log-rank test
- Visualization - Survival curves and expression distribution plots
Key Functions
| Module | Function |
|---|---|
requests |
cBioPortal API data retrieval |
lifelines |
Kaplan-Meier and Cox regression |
pandas |
Data processing and merging |
Supported Cancer Types
Common cBioPortal TCGA study IDs:
luad_tcga_pan_can_atlas_2018- Lung Adenocarcinoma (LUAD)lusc_tcga_pan_can_atlas_2018- Lung Squamous Cell Carcinoma (LUSC)brca_tcga_pan_can_atlas_2018- Breast Cancer (BRCA)coadread_tcga_pan_can_atlas_2018- Colorectal Cancer
Troubleshooting
- Network issues: cBioPortal API requires stable network connection
- Gene names: Use Entrez Gene ID (e.g., EGFR = 1956)
- Survival data: Check if OS_MONTHS and OS_STATUS columns exist
Related Skills
Xlsx
Comprehensive spreadsheet creation, editing, and analysis with support for formulas, formatting, data analysis, and visualization. When Claude needs to work with spreadsheets (.xlsx, .xlsm, .csv, .tsv, etc) for: (1) Creating new spreadsheets with formulas and formatting, (2) Reading or analyzing data, (3) Modify existing spreadsheets while preserving formulas, (4) Data analysis and visualization in spreadsheets, or (5) Recalculating formulas
Clickhouse Io
ClickHouse database patterns, query optimization, analytics, and data engineering best practices for high-performance analytical workloads.
Clickhouse Io
ClickHouse database patterns, query optimization, analytics, and data engineering best practices for high-performance analytical workloads.
Analyzing Financial Statements
This skill calculates key financial ratios and metrics from financial statement data for investment analysis
Data Storytelling
Transform data into compelling narratives using visualization, context, and persuasive structure. Use when presenting analytics to stakeholders, creating data reports, or building executive presentations.
Kpi Dashboard Design
Design effective KPI dashboards with metrics selection, visualization best practices, and real-time monitoring patterns. Use when building business dashboards, selecting metrics, or designing data visualization layouts.
Dbt Transformation Patterns
Master dbt (data build tool) for analytics engineering with model organization, testing, documentation, and incremental strategies. Use when building data transformations, creating data models, or implementing analytics engineering best practices.
Sql Optimization Patterns
Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries. Use when debugging slow queries, designing database schemas, or optimizing application performance.
Anndata
This skill should be used when working with annotated data matrices in Python, particularly for single-cell genomics analysis, managing experimental measurements with metadata, or handling large-scale biological datasets. Use when tasks involve AnnData objects, h5ad files, single-cell RNA-seq data, or integration with scanpy/scverse tools.
Xlsx
Spreadsheet toolkit (.xlsx/.csv). Create/edit with formulas/formatting, analyze data, visualization, recalculate formulas, for spreadsheet processing and analysis.
