Pseudotime Trajectory Visualization
Visualize single-cell developmental trajectories showing cellular differentiation processes using pseudotime analysis.
When to Use
- - Use this skill when the task needs Visualize single-cell developmental trajectories showing cellular differentiation processes using pseudotime analysis.
- 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
pseudotime-trajectory-viz 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
- - Python 3.9+
- INLINECODE3 - Single-cell analysis framework
- INLINECODE4 - RNA velocity analysis
- INLINECODE5 - Trajectory inference and pseudotime
- INLINECODE6 - Dimensionality reduction and clustering
- INLINECODE7 - Plotting
- INLINECODE8 - Statistical visualization
- INLINECODE9 ,
numpy - Data manipulation - INLINECODE11 - Single-cell data structure
Optional:
- -
slingshot (R) via rpy2 - Alternative trajectory method
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
- - Infer developmental trajectories from single-cell RNA-seq data
- Calculate pseudotime values representing cellular differentiation progress
- Visualize trajectory trees and lineage branching
- Overlay gene expression dynamics along pseudotime
- Identify lineage-specific marker genes
- Generate publication-ready trajectory plots
Technical Difficulty
High - Requires understanding of single-cell analysis, dimensionality reduction, trajectory inference algorithms, and Python visualization libraries.
Usage
CODEBLOCK3
Parameters
| Parameter | Type | Default | Description |
|---|
| INLINECODE20 | path | required | Input AnnData (.h5ad) file path |
| INLINECODE21 |
path | ./trajectory_output | Output directory for results |
|
--embedding | enum | umap | Embedding for visualization:
umap,
tsne,
pca,
diffmap |
|
--method | enum | diffusion | Trajectory inference:
diffusion,
slingshot,
paga,
palantir |
|
--start-cell | string | auto | Root cell ID or cluster name for trajectory origin |
|
--start-cell-type | string | - | Cell type annotation to use as starting point |
|
--n-lineages | int | auto | Number of expected lineage branches |
|
--cluster-key | string | leiden | AnnData obs key for cell clusters |
|
--cell-type-key | string | cell_type | AnnData obs key for cell type annotations |
|
--genes | string | - | Comma-separated gene names to plot along pseudotime |
|
--plot-genes | flag | false | Generate gene expression heatmaps along trajectories |
|
--plot-branch | flag | true | Show lineage branch probabilities |
|
--format | enum | png | Output format:
png,
pdf,
svg |
|
--dpi | int | 300 | Figure resolution |
|
--n-pcs | int | 30 | Number of principal components for analysis |
|
--n-neighbors | int | 15 | Number of neighbors for graph construction |
|
--diffmap-components | int | 5 | Number of diffusion components to compute |
Input Format
Required AnnData (.h5ad) structure:
CODEBLOCK4
Output Files
CODEBLOCK5
Output Format Example
analysis_report.json
CODEBLOCK6
pseudotime_values.csv
CODEBLOCK7
Implementation Notes
- 1. Preprocessing: Assumes input data is already normalized and log-transformed
- Root Detection: If start cell not specified, uses cell cycle or marker gene expression to infer progenitors
- Diffusion Pseudotime: Default method using diffusion maps for robust trajectory inference
- Palantir: Used for soft lineage assignments and fate probability estimation
- Memory: Large datasets (>50k cells) may require 16GB+ RAM
Methods
Diffusion Pseudotime (DPT)
- - Uses diffusion maps to capture non-linear cell relationships
- Robust to noise and dataset size
- Good for complex branching trajectories
Slingshot
- - Principal curve-based approach
- Simultaneous inference of multiple lineages
- Requires R installation with rpy2 bridge
PAGA (Partition-based Graph Abstraction)
- - Connects clusters based on transcriptome similarity
- Provides coarse-grained trajectory overview
- Fast and scalable
Palantir
- - Diffusion-based fate probability estimation
- Soft lineage assignments
- Best for fate bias analysis
Limitations
- - Requires high-quality single-cell data with good cell type coverage
- Assumes differentiation is the main source of variation
- May not capture rare transitional states with few cells
- Circular or cyclic processes not well represented by linear pseudotime
- RNA velocity requires spliced/unspliced counts in AnnData layers
Safety & Best Practices
- - Validate trajectories with known marker genes and biological knowledge
- Multiple methods recommended for critical analyses
- Batch effects should be corrected before trajectory inference
- Cell cycle effects may confound differentiation trajectories
- Do not overinterpret precise pseudotime values as absolute time
Example Workflow
CODEBLOCK8
References
- - Haghverdi et al. (2016) - Diffusion pseudotime
- Street et al. (2018) - Slingshot
- Wolf et al. (2019) - PAGA
- Setty et al. (2019) - Palantir
- La Manno et al. (2018) - RNA velocity
Version
- - Created: 2026-02-06
- Status: Functional
- Version: 1.0.0
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
CODEBLOCK9
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 pseudotime-trajectory-viz 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:
INLINECODE50 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.
伪时间轨迹可视化
使用伪时间分析可视化展示细胞分化过程的单细胞发育轨迹。
使用场景
- - 当任务需要使用伪时间分析可视化展示细胞分化过程的单细胞发育轨迹时使用此技能。
- 用于需要明确假设、有限范围和可重复输出格式的数据分析任务。
- 当需要针对缺失输入、执行错误或部分证据提供有文档记录的备用路径时使用此技能。
主要特性
- - 以范围为中心的工作流程,遵循:使用可重复工作流程、明确验证和结构化输出进行pseudotime-trajectory-viz数据分析,以便进行可审查的解读。
- 打包的可执行路径:scripts/main.py。
- references/目录中提供参考资料,用于任务特定指导。
- 结构化执行路径,旨在保持输出一致且可审查。
依赖项
- - Python 3.9+
- scanpy>=1.9.0 - 单细胞分析框架
- scvelo>=0.2.5 - RNA速率分析
- palantir - 轨迹推断和伪时间
- scikit-learn - 降维和聚类
- matplotlib>=3.5.0 - 绘图
- seaborn - 统计可视化
- pandas, numpy - 数据处理
- anndata - 单细胞数据结构
可选:
- - 通过rpy2使用slingshot (R) - 替代轨迹方法
使用示例
详见上方## 使用部分。
bash
cd 20260318/scientific-skills/Data Analytics/pseudotime-trajectory-viz
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 带有明确症状、病史、评估和下一步计划的审计验证样本。 --format json
工作流程
- 1. 在进行详细工作之前,确认用户目标、必需输入和不可协商的约束条件。
- 验证请求是否与文档化范围匹配,如果任务需要不支持的假设,则提前停止。
- 仅使用实际可用的输入,使用打包脚本路径或文档化的推理路径。
- 返回结构化结果,区分假设、可交付成果、风险和未解决事项。
- 如果执行失败或输入不完整,切换到备用路径并明确说明阻止完整完成的原因。
功能
- - 从单细胞RNA-seq数据推断发育轨迹
- 计算代表细胞分化进程的伪时间值
- 可视化轨迹树和谱系分支
- 沿伪时间叠加基因表达动态
- 识别谱系特异性标记基因
- 生成可发表的轨迹图
技术难度
高 - 需要理解单细胞分析、降维、轨迹推断算法和Python可视化库。
使用
text
从AnnData文件进行基本轨迹分析
python scripts/main.py --input data.h5ad --output ./results
指定起始细胞和谱系推断方法
python scripts/main.py --input data.h5ad --start-cell stem
cellcluster --method diffusion --output ./results
可视化沿轨迹的特定基因表达
python scripts/main.py --input data.h5ad --genes SOX2,OCT4,NANOG --plot-genes --output ./results
使用自定义参数进行全面分析
python scripts/main.py --input data.h5ad \
--embedding umap \
--method slingshot \
--start-cell-type progenitor \
--n-lineages 3 \
--genes MARKER1,MARKER2,MARKER3 \
--output ./results \
--format pdf
参数
| 参数 | 类型 | 默认值 | 描述 |
|---|
| --input | 路径 | 必需 | 输入AnnData (.h5ad)文件路径 |
| --output |
路径 | ./trajectory_output | 结果输出目录 |
| --embedding | 枚举 | umap | 可视化嵌入:umap, tsne, pca, diffmap |
| --method | 枚举 | diffusion | 轨迹推断:diffusion, slingshot, paga, palantir |
| --start-cell | 字符串 | auto | 轨迹起源的根细胞ID或簇名称 |
| --start-cell-type | 字符串 | - | 用作起点的细胞类型注释 |
| --n-lineages | 整数 | auto | 预期的谱系分支数量 |
| --cluster-key | 字符串 | leiden | 细胞簇的AnnData obs键 |
| --cell-type-key | 字符串 | cell_type | 细胞类型注释的AnnData obs键 |
| --genes | 字符串 | - | 沿伪时间绘制的逗号分隔基因名称 |
| --plot-genes | 标志 | false | 生成沿轨迹的基因表达热图 |
| --plot-branch | 标志 | true | 显示谱系分支概率 |
| --format | 枚举 | png | 输出格式:png, pdf, svg |
| --dpi | 整数 | 300 | 图形分辨率 |
| --n-pcs | 整数 | 30 | 分析的主成分数量 |
| --n-neighbors | 整数 | 15 | 图构建的邻居数量 |
| --diffmap-components | 整数 | 5 | 计算的扩散成分数量 |
输入格式
必需的AnnData (.h5ad)结构:
AnnData对象,nobs × nvars = ncells × ngenes
obs: leiden, cell_type # 簇和细胞类型注释
var: highly_variable # 高变基因标记
obsm: Xumap, Xpca # 预计算嵌入(可选)
layers: spliced, unspliced # 用于RNA速率(可选)
输出文件
output_directory/
├── trajectory_plot.{format} # 主要轨迹可视化
├── pseudotime_distribution.{format} # 伪时间值分布
├── lineage_tree.{format} # 分支谱系结构
├── geneexpressionheatmap.{format} # 基因动态热图(如果使用--plot-genes)
├── gene_trends/
│ ├── {genename}trend.{format} # 单个基因表达趋势
│ └── ...
├── pseudotime_values.csv # 细胞级伪时间值
├── lineage_assignments.csv # 细胞谱系分配
└── analysis_report.json # 分析参数和统计信息
输出格式示例
analysis_report.json
json
{
analysis_date: 2026-02-06T06:00:00,
method: diffusion,
n_cells: 5000,
n_lineages: 3,
root
cell: cell1234,
pseudotime_range: [0.0, 1.0],
lineages: {
lineage_1: {
cell_count: 1500,
terminal
state: maturetype_A,
mean_pseudotime: 0.75
},
lineage_2: {
cell_count: 1200,
terminal
state: maturetype_B,
mean_pseudotime: 0.68
}
}
}
pseudotime_values.csv
csv
cell
id,cluster,celltype,pseudotime,lineage,branch