Survival Curve Risk Table Generator
When to Use
- - Use this skill when the task needs Automatically align and add "Number at risk" table below Kaplan-Meier.
- Use this skill for data analysis tasks that require explicit assumptions, bounded scope, and a reproducible output format.
- Use this skill when you need a documented fallback path for missing inputs, execution errors, or partial evidence.
Key Features
- - Scope-focused workflow aligned to: Analyze data with
survival-curve-risk-table using a reproducible workflow, explicit validation, and structured outputs for review-ready interpretation. - Packaged executable path(s):
scripts/main.py. - Reference material available in
references/ for task-specific guidance. - Structured execution path designed to keep outputs consistent and reviewable.
Dependencies
See ## Prerequisites above for related details.
- -
Python: 3.10+. Repository baseline for current packaged skills. - INLINECODE6 :
unspecified. Declared in requirements.txt. - INLINECODE9 :
unspecified. Declared in requirements.txt. - INLINECODE12 :
unspecified. Declared in requirements.txt. - INLINECODE15 :
unspecified. Declared in requirements.txt. - INLINECODE18 :
unspecified. Declared in requirements.txt. - INLINECODE21 :
unspecified. Declared in requirements.txt. - INLINECODE24 :
unspecified. Declared in requirements.txt.
Example Usage
See ## Usage above for related details.
CODEBLOCK0
Example run plan:
- 1. Confirm the user input, output path, and any required config values.
- Edit the in-file
CONFIG block or documented parameters if the script uses fixed settings. - Run
python scripts/main.py with the validated inputs. - Review the generated output and return the final artifact with any assumptions called out.
Implementation Details
See ## Workflow above for related details.
- - Execution model: validate the request, choose the packaged workflow, and produce a bounded deliverable.
- Input controls: confirm the source files, scope limits, output format, and acceptance criteria before running any script.
- Primary implementation surface:
scripts/main.py. - Reference guidance:
references/ contains supporting rules, prompts, or checklists. - Parameters to clarify first: input path, output path, scope filters, thresholds, and any domain-specific constraints.
- Output discipline: keep results reproducible, identify assumptions explicitly, and avoid undocumented side effects.
Quick Check
Use this command to verify that the packaged script entry point can be parsed before deeper execution.
CODEBLOCK1
Audit-Ready Commands
Use these concrete commands for validation. They are intentionally self-contained and avoid placeholder paths.
CODEBLOCK2
Workflow
- 1. Confirm the user objective, required inputs, and non-negotiable constraints before doing detailed work.
- Validate that the request matches the documented scope and stop early if the task would require unsupported assumptions.
- Use the packaged script path or the documented reasoning path with only the inputs that are actually available.
- Return a structured result that separates assumptions, deliverables, risks, and unresolved items.
- If execution fails or inputs are incomplete, switch to the fallback path and state exactly what blocked full completion.
Function Overview
Automatically add "Number at risk" tables to Kaplan-Meier survival curves that meet clinical oncology journal standards. Automatically align time points and generate publication-quality combined figures.
Usage Trigger Conditions
- - Need to add number at risk tables to KM survival curves
- Generate survival plots that meet journal requirements such as NEJM, Lancet, JCO
- Risk tables needed in clinical trial reports
- Medical paper chart standardization before submission
- Precise alignment of risk tables with survival curve time axis
Core Functions
1. Automatic Number at Risk Calculation
- - Automatically calculate number at risk at each time point from survival data
- Support right-censored data processing
- Count remaining observed subjects by group
- Automatic handling of censoring events
2. Journal Standard Formats
- - NEJM Standard: Clean time axis, groups arranged horizontally
- Lancet Standard: Complete statistical information, vertical alignment
- JCO Standard: Censoring symbols marked, group comparison
- Support custom journal templates
3. Precise Alignment
- - Time axis precisely aligned with curve X-axis
- Automatic adjustment of table spacing and font size
- Responsive layout adapts to different image sizes
- Support horizontal/vertical layouts
4. Output Formats
- - High-quality PNG/JPEG images
- PDF vector graphics
- SVG editable format
- PowerPoint embeddable format
Usage
Example 1: Basic Risk Table Generation
CODEBLOCK3
Example 2: Specify Journal Style
CODEBLOCK4
Example 3: Combined Figure Generation (Curve + Risk Table)
CODEBLOCK5
Example 4: Batch Generate Multi-Timepoint Tables
CODEBLOCK6
Example 5: Using Existing Survival Data (Python API)
CODEBLOCK7
Input Data Format
CSV Format Example
CODEBLOCK8
Required Columns
| Column Name | Description | Type |
|---|
| time | Follow-up time (months) | Numeric |
| event |
Event occurrence flag | 0=Censored, 1=Event |
| group | Treatment group (optional) | Text/Categorical |
Supported Data Formats
- - CSV (.csv)
- Excel (.xlsx, .xls)
- SAS (.sas7bdat)
- RData (.rda, .rds)
- Python pickle (.pkl)
Journal Style Configuration
NEJM Style
CODEBLOCK9
Lancet Style
CODEBLOCK10
JCO Style
CODEBLOCK11
Command Line Parameters
Required Parameters
| Parameter | Description | Example |
|---|
| INLINECODE33 | Input data file path | INLINECODE34 |
| INLINECODE35 |
Time column name |
time |
|
--event-col | Event column name |
event |
Optional Parameters
| Parameter | Description | Default Value |
|---|
| INLINECODE39 | Group column name | INLINECODE40 |
| INLINECODE41 |
Output file path |
risk_table.png |
|
--style | Journal style |
NEJM |
|
--time-points | Time point list | Auto-calculated |
|
--format | Output format |
png |
|
--width | Image width |
8 (inches) |
|
--height | Image height |
6 (inches) |
|
--dpi | Image resolution |
300 |
|
--font-size | Font size |
8 |
|
--show-censored | Show censored count |
False |
|
--combine | Combine with KM curve |
False |
|
--km-plot | KM curve image path |
None |
Output Format
Standalone Risk Table
CODEBLOCK12
Combined Figure Layout
CODEBLOCK13
Algorithm Description
Number at Risk Calculation
CODEBLOCK14
Time Point Selection Strategy
- 1. Auto Mode: Automatically select equally spaced time points based on data distribution
- Fixed Interval: Select at specified intervals (e.g., every 6 months)
- Custom: User-specified specific time points
- Event-driven: Select based on event occurrence density
Quality Checklist
- - [ ] Time axis precisely aligned with X-axis
- [ ] Number at risk calculations correct (can manually spot-check)
- [ ] Group labels clear and readable
- [ ] Font size meets journal requirements (≥8pt)
- [ ] Image resolution ≥300 DPI
- [ ] Color contrast meets accessibility standards
- [ ] Censoring marks (if present) clearly distinguishable
- [ ] Export format meets submission requirements
Journal-Specific Notes
NEJM
- - Minimum font size 8pt
- Recommended time unit: months
- Fixed spacing between risk table and curve
Lancet
- - Minimum font size 9pt
- Support multi-group display (max 4 groups)
- Table grid lines optional
JCO
- - Need to label censoring information
- Support risk table + censoring table double-layer structure
- Recommend labeling median follow-up time
FAQ
Q: How are time points automatically determined?
A: Default uses quantiles in the data (0%, 25%, 50%, 75%, 100%) or fixed intervals (e.g., every 12 months)
Q: How to handle multiple groups?
A: Automatically detect group column, support up to 6 groups. Exceeding automatically uses pagination or reduced font
Q: Can it work with KM curves generated by Python/R?
A: Yes, supports importing external KM curve images for combination
Dependency Requirements
CODEBLOCK15
Related Tools
- - lifelines: Python survival analysis library
- survminer: R survival curve visualization
- ggsurvplot: ggplot2 survival plot extension
Risk Assessment
| Risk Indicator | Assessment | Level |
|---|
| Code Execution | Python/R scripts executed locally | Medium |
| Network Access |
No external API calls | Low |
| File System Access | Read input files, write output files | Medium |
| Instruction Tampering | Standard prompt guidelines | Low |
| Data Exposure | Output files saved to workspace | Low |
Security Checklist
- - [ ] No hardcoded credentials or API keys
- [ ] No unauthorized file system access (../)
- [ ] Output does not expose sensitive information
- [ ] Prompt injection protections in place
- [ ] Input file paths validated (no ../ traversal)
- [ ] Output directory restricted to workspace
- [ ] Script execution in sandboxed environment
- [ ] Error messages sanitized (no stack traces exposed)
- [ ] Dependencies audited
Prerequisites
CODEBLOCK16
Evaluation Criteria
Success Metrics
- - [ ] Successfully executes main functionality
- [ ] Output meets quality standards
- [ ] Handles edge cases gracefully
- [ ] Performance is acceptable
Test Cases
- 1. Basic Functionality: Standard input → Expected output
- Edge Case: Invalid input → Graceful error handling
- Performance: Large dataset → Acceptable processing time
Lifecycle Status
- - Current Stage: Draft
- Next Review Date: 2026-03-06
- Known Issues: None
- Planned Improvements:
- Performance optimization
- Additional feature support
Output Requirements
Every final response should make these items explicit when they are relevant:
- - Objective or requested deliverable
- Inputs used and assumptions introduced
- Workflow or decision path
- Core result, recommendation, or artifact
- Constraints, risks, caveats, or validation needs
- Unresolved items and next-step checks
Error Handling
- - If required inputs are missing, state exactly which fields are missing and request only the minimum additional information.
- If the task goes outside the documented scope, stop instead of guessing or silently widening the assignment.
- If
scripts/main.py fails, report the failure point, summarize what still can be completed safely, and provide a manual fallback. - Do not fabricate files, citations, data, search results, or execution outcomes.
Input Validation
This skill accepts requests that match the documented purpose of survival-curve-risk-table and include enough context to complete the workflow safely.
Do not continue the workflow when the request is out of scope, missing a critical input, or would require unsupported assumptions. Instead respond:
INLINECODE64 only handles its documented workflow. Please provide the missing required inputs or switch to a more suitable skill.
Response Template
Use the following fixed structure for non-trivial requests:
- 1. Objective
- Inputs Received
- Assumptions
- Workflow
- Deliverable
- Risks and Limits
- Next Checks
If the request is simple, you may compress the structure, but still keep assumptions and limits explicit when they affect correctness.
Inputs to Collect
- - Required inputs: the user goal, the primary data or source file, and the requested output format.
- Optional inputs: output directory, formatting preferences, and validation constraints.
- If a required input is unavailable, return a short clarification request before continuing.
Output Contract
- - Return a short summary, the main deliverables, and any assumptions that materially affect interpretation.
- If execution is partial, label what succeeded, what failed, and the next safe recovery step.
- Keep the final answer within the documented scope of the skill.
Validation and Safety Rules
- - Validate identifiers, file paths, and user-provided parameters before execution.
- Do not fabricate results, metrics, citations, or downstream conclusions.
- Use safe fallback behavior when dependencies, credentials, or required inputs are missing.
- Surface any execution failure with a concise diagnosis and recovery path.
生存曲线风险表生成器
使用时机
- - 当任务需要在Kaplan-Meier曲线下方自动对齐并添加风险人数表格时使用此技能。
- 用于需要明确假设、限定范围以及可重复输出格式的数据分析任务。
- 当需要针对缺失输入、执行错误或部分证据提供有文档记录的备用路径时使用此技能。
主要特性
- - 以范围为中心的工作流程,专注于:使用可重复的工作流程、明确的验证和结构化输出,通过survival-curve-risk-table分析数据,以便进行可审查的解读。
- 打包的可执行路径:scripts/main.py。
- references/目录中提供参考资料,用于任务特定指导。
- 结构化的执行路径,旨在保持输出的一致性和可审查性。
依赖项
相关详情请参见上方的## 前提条件。
- - Python:3.10+。当前打包技能的仓库基线。
- lifelines:未指定。在requirements.txt中声明。
- matplotlib:未指定。在requirements.txt中声明。
- numpy:未指定。在requirements.txt中声明。
- pandas:未指定。在requirements.txt中声明。
- pil:未指定。在requirements.txt中声明。
- pillow:未指定。在requirements.txt中声明。
- seaborn:未指定。在requirements.txt中声明。
使用示例
相关详情请参见上方的## 用法。
bash
cd 20260318/scientific-skills/Data Analytics/survival-curve-risk-table
python -m py_compile scripts/main.py
python scripts/main.py --help
示例运行计划:
- 1. 确认用户输入、输出路径以及任何必需的配置值。
- 如果脚本使用固定设置,则编辑文件内的CONFIG块或文档化参数。
- 使用验证后的输入运行python scripts/main.py。
- 审查生成的输出,并返回最终产物,同时明确指出所有假设。
实现细节
相关详情请参见上方的## 工作流程。
- - 执行模型:验证请求,选择打包的工作流程,并生成有界定的可交付成果。
- 输入控制:在运行任何脚本之前,确认源文件、范围限制、输出格式和验收标准。
- 主要实现界面:scripts/main.py。
- 参考指南:references/包含支持性规则、提示或检查清单。
- 需要首先明确的参数:输入路径、输出路径、范围过滤器、阈值以及任何领域特定的约束。
- 输出规范:保持结果可重复,明确标识假设,避免未文档化的副作用。
快速检查
在深入执行之前,使用此命令验证打包脚本的入口点是否可以被解析。
bash
python -m py_compile scripts/main.py
审计就绪命令
使用这些具体命令进行验证。它们特意设计为自包含,避免使用占位符路径。
bash
python -m py_compile scripts/main.py
示例调用:python scripts/main.py --help
示例调用:python scripts/main.py --input 具有明确症状、病史、评估和下一步计划的审计验证样本。
工作流程
- 1. 在进行详细工作之前,确认用户目标、必需的输入和不可协商的约束。
- 验证请求是否与文档化的范围匹配,如果任务需要不支持的假设,则提前停止。
- 仅使用实际可用的输入,使用打包的脚本路径或文档化的推理路径。
- 返回一个结构化的结果,将假设、可交付成果、风险和未解决事项分开。
- 如果执行失败或输入不完整,则切换到备用路径,并准确说明阻止完整完成的原因。
功能概述
自动向Kaplan-Meier生存曲线添加符合临床肿瘤学期刊标准的风险人数表格。自动对齐时间点,生成符合发表质量要求的组合图形。
使用触发条件
- - 需要向KM生存曲线添加风险人数表格
- 生成符合NEJM、Lancet、JCO等期刊要求的生存图
- 临床试验报告中需要风险表格
- 医学论文图表在提交前的标准化处理
- 风险表格与生存曲线时间轴的精确对齐
核心功能
1. 自动风险人数计算
- - 根据生存数据自动计算每个时间点的风险人数
- 支持右删失数据处理
- 按组统计剩余观察对象数量
- 自动处理删失事件
2. 期刊标准格式
- - NEJM标准:简洁的时间轴,组别水平排列
- Lancet标准:完整的统计信息,垂直对齐
- JCO标准:标记删失符号,组间比较
- 支持自定义期刊模板
3. 精确对齐
- - 时间轴与曲线X轴精确对齐
- 自动调整表格间距和字体大小
- 响应式布局适应不同图像尺寸
- 支持水平/垂直布局
4. 输出格式
- - 高质量PNG/JPEG图像
- PDF矢量图形
- SVG可编辑格式
- PowerPoint可嵌入格式
用法
示例1:基本风险表生成
text
示例调用:python scripts/main.py \
--input survival_data.csv \
--time-col time \
--event-col event \
--group-col treatment \
--output risk_table.png
示例2:指定期刊样式
text
示例调用:python scripts/main.py \
--input survival_data.csv \
--time-col time \
--event-col status \
--group-col arm \
--style NEJM \
--time-points 0,6,12,18,24,30,36 \
--output figure_1a.pdf
示例3:组合图形生成(曲线 + 风险表)
text
示例调用:python scripts/main.py \
--input survival_data.csv \
--time-col months \
--event-col death \
--group-col group \
--km-plot km_curve.png \
--combine \
--output combined_figure.png
示例4:批量生成多时间点表格
text
示例调用:python scripts/main.py \
--input survival_data.csv \
--time-col time \
--event-col event \
--group-col treatment \
--time-points 0,12,24,36,48,60 \
--format both \
--output-dir ./output/
示例5:使用现有生存数据(Python API)
python
from scripts.main import RiskTableGenerator
初始化生成器
generator = RiskTableGenerator(
style=JCO,
time_points=[0, 6, 12, 18, 24, 30],
figure_size=(8, 6)
)
加载生存数据
generator.load_data(
df=survival_df,
time_col=time,
event_col=event,
group
col=treatmentarm
)
生成风险表
generator.generate
risktable(
output
path=risktable.png,
show_censored=True
)
生成组合图形(KM曲线 + 风险表)
generator.generate
combinedplot(
km
plotpath=km_curve.png,
output
path=combinedfigure.pdf
)
输入数据格式
CSV格式示例
csv
time,event,treatment_arm
0,0,Experimental
3.2,1,Experimental
5.1,0,Experimental
12.3,1,Control
18.7,0,Control
24.0,1,Experimental
...
必需列
| 列名 | 描述 | 类型 |
|---|
| time | 随访时间(月) | 数值型 |
| event |
事件发生标志 | 0=删失,1=事件 |
| group | 治疗组(可选) | 文本/分类 |
支持的数据格式
- - CSV (.csv)
- Excel (.xlsx, .xls)
- SAS (.sas7bdat)
- RData (.rda, .rds)
- Python pickle (.pkl)
期刊样式配置
NEJM样式
json
{
style: NEJM,
font_family: Helvetica,
font_size: 8,
time_points: [0, 6, 12, 18, 24, 30, 36],
table_height: 0.15,
show_grid: false,
separator_lines: true
}
Lancet样式
json
{
style: Lancet,
font_family: Times New Roman,
font_size: 9,
time_points: [0, 12, 24, 36, 48, 60],
table_height: 0.18,
show_grid: true,
header_bold