CtrlK
BlogDocsLog inGet started
Tessl Logo

pseudotime-trajectory-viz

Visualize single-cell developmental trajectories (pseudotime) to show how cells differentiate from stem cells to mature cells. Includes trajectory inference, pseudotime calculation, and publication-ready visualizations.

Install with Tessl CLI

npx tessl i github:aipoch/medical-research-skills --skill pseudotime-trajectory-viz
What are skills?

72

Does it follow best practices?

Validation for skill structure

SKILL.md
Review
Evals

Pseudotime Trajectory Visualization

Visualize single-cell developmental trajectories showing cellular differentiation processes using pseudotime analysis.

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

# Basic trajectory analysis from AnnData file
python scripts/main.py --input data.h5ad --output ./results

# Specify starting cells and lineage inference method
python scripts/main.py --input data.h5ad --start-cell stem_cell_cluster --method diffusion --output ./results

# Visualize specific gene expression along trajectories
python scripts/main.py --input data.h5ad --genes SOX2,OCT4,NANOG --plot-genes --output ./results

# Full analysis with custom parameters
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

Parameters

ParameterTypeDefaultDescription
--inputpathrequiredInput AnnData (.h5ad) file path
--outputpath./trajectory_outputOutput directory for results
--embeddingenumumapEmbedding for visualization: umap, tsne, pca, diffmap
--methodenumdiffusionTrajectory inference: diffusion, slingshot, paga, palantir
--start-cellstringautoRoot cell ID or cluster name for trajectory origin
--start-cell-typestring-Cell type annotation to use as starting point
--n-lineagesintautoNumber of expected lineage branches
--cluster-keystringleidenAnnData obs key for cell clusters
--cell-type-keystringcell_typeAnnData obs key for cell type annotations
--genesstring-Comma-separated gene names to plot along pseudotime
--plot-genesflagfalseGenerate gene expression heatmaps along trajectories
--plot-branchflagtrueShow lineage branch probabilities
--formatenumpngOutput format: png, pdf, svg
--dpiint300Figure resolution
--n-pcsint30Number of principal components for analysis
--n-neighborsint15Number of neighbors for graph construction
--diffmap-componentsint5Number of diffusion components to compute

Input Format

Required AnnData (.h5ad) structure:

AnnData object with n_obs × n_vars = n_cells × n_genes
    obs: 'leiden', 'cell_type'  # Cluster and cell type annotations
    var: 'highly_variable'       # Highly variable gene marker
    obsm: 'X_umap', 'X_pca'      # Pre-computed embeddings (optional)
    layers: 'spliced', 'unspliced'  # For RNA velocity (optional)

Output Files

output_directory/
├── trajectory_plot.{format}          # Main trajectory visualization
├── pseudotime_distribution.{format}  # Pseudotime value distribution
├── lineage_tree.{format}             # Branching lineage structure
├── gene_expression_heatmap.{format}  # Gene dynamics heatmap (if --plot-genes)
├── gene_trends/
│   ├── {gene_name}_trend.{format}    # Individual gene expression trends
│   └── ...
├── pseudotime_values.csv             # Cell-level pseudotime values
├── lineage_assignments.csv           # Cell lineage assignments
└── analysis_report.json              # Analysis parameters and statistics

Output Format Example

analysis_report.json

{
  "analysis_date": "2026-02-06T06:00:00",
  "method": "diffusion",
  "n_cells": 5000,
  "n_lineages": 3,
  "root_cell": "cell_1234",
  "pseudotime_range": [0.0, 1.0],
  "lineages": {
    "lineage_1": {
      "cell_count": 1500,
      "terminal_state": "mature_type_A",
      "mean_pseudotime": 0.75
    },
    "lineage_2": {
      "cell_count": 1200,
      "terminal_state": "mature_type_B",
      "mean_pseudotime": 0.68
    }
  }
}

pseudotime_values.csv

cell_id,cluster,cell_type,pseudotime,lineage,branch_probability
cell_001,0,progenitor,0.05,lineage_1,0.95
cell_002,1,intermediate,0.42,lineage_1,0.88
...

Dependencies

  • Python 3.9+
  • scanpy>=1.9.0 - Single-cell analysis framework
  • scvelo>=0.2.5 - RNA velocity analysis
  • palantir - Trajectory inference and pseudotime
  • scikit-learn - Dimensionality reduction and clustering
  • matplotlib>=3.5.0 - Plotting
  • seaborn - Statistical visualization
  • pandas, numpy - Data manipulation
  • anndata - Single-cell data structure

Optional:

  • slingshot (R) via rpy2 - Alternative trajectory method

Implementation Notes

  1. Preprocessing: Assumes input data is already normalized and log-transformed
  2. Root Detection: If start cell not specified, uses cell cycle or marker gene expression to infer progenitors
  3. Diffusion Pseudotime: Default method using diffusion maps for robust trajectory inference
  4. Palantir: Used for soft lineage assignments and fate probability estimation
  5. 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

# Preprocess data with scanpy (before using this tool)
import scanpy as sc

adata = sc.read_h5ad('raw_data.h5ad')
sc.pp.normalize_total(adata)
sc.pp.log1p(adata)
sc.pp.highly_variable_genes(adata, n_top_genes=2000)
sc.pp.scale(adata)
sc.tl.pca(adata)
sc.pp.neighbors(adata)
sc.tl.umap(adata)
sc.tl.leiden(adata)
adata.write('data.h5ad')

# Then run this skill
# python scripts/main.py --input data.h5ad --start-cell-type progenitor

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 IndicatorAssessmentLevel
Code ExecutionPython/R scripts executed locallyMedium
Network AccessNo external API callsLow
File System AccessRead input files, write output filesMedium
Instruction TamperingStandard prompt guidelinesLow
Data ExposureOutput files saved to workspaceLow

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

# Python dependencies
pip install -r requirements.txt

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
  2. Edge Case: Invalid input → Graceful error handling
  3. 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
Repository
aipoch/medical-research-skills
Last updated
Created

Is this your skill?

If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.