Seuratpreparing

From pwwang/immunopipe · View interactive version

Seuratpreparing is an AI agent skill from the GitHub repository pwwang/immunopipe. Load, prepare, and apply quality control (QC) to single-cell RNA-seq data using Seurat. Performs data loading, QC filtering, normalization, and multi-sample integration. This is a core preprocessing process that prepares Seurat objects for downstream clustering and analysis.

How to use this skill

Skill file

SeuratPreparing Process Configuration

Purpose

Load, prepare, and apply quality control (QC) to single-cell RNA-seq data using Seurat. Performs data loading, QC filtering, normalization, and multi-sample integration. This is a core preprocessing process that prepares Seurat objects for downstream clustering and analysis.

When to Use

Data Requirements

Dependencies

Configuration Structure

Process Enablement

[SeuratPreparing]
cache = true  # Enable caching to speed up re-runs

Input Specification

[SeuratPreparing.in]
# metafile is required unless LoadingRNAFromSeurat is used
metafile = ["path/to/sample_info.txt"]

metafile format (tab-delimited):

Environment Variables

[SeuratPreparing.envs]
# Core processing parameters
ncores = 1                           # Parallelization cores
mutaters = {}                          # Add custom metadata columns
min_cells = 0                           # Minimum cells per gene (CreateSeuratObject)
min_features = 0                         # Minimum features per cell (CreateSeuratObject)

# Quality control
cell_qc = ""                           # Cell filtering expression (R syntax)
gene_qc = { min_cells = 0 }            # Gene filtering options

# QC plots generation
qc_plots = {}                           # Visualization configuration

# Normalization method selection
use_sct = false                         # Use SCTransform instead of NormalizeData pipeline
no_integration = false                    # Skip sample integration

# Doublet detection
doublet_detector = "none"                # Options: none, DoubletFinder, scDblFinder

# Caching
cache = "/tmp"                          # Cache intermediate results

External References

Seurat Normalization Functions

Standard Workflow (use_sct = false):

  1. NormalizeData - Log-normalization of UMI counts

```toml

[SeuratPreparing.envs.NormalizeData]

normalization-method = "LogNormalize" # Options: LogNormalize, CLR, RC

scale-factor = 10000 # Normalization scaling factor

margin = 1 # Normalize across features (1) or cells (2)

verbose = true

```

  1. FindVariableFeatures - Identify highly variable genes

```toml

[SeuratPreparing.envs.FindVariableFeatures]

selection-method = "vst" # Options: vst, mean.var.plot, disp

nfeatures = 2000 # Number of variable features to select

verbose = true

```

  1. ScaleData - Center and scale gene expression

```toml

[SeuratPreparing.envs.ScaleData]

vars.to.regress = [] # Variables to regress out (e.g., ["percent.mt"])

model.use = "linear" # Regression model

verbose = true

```

  1. RunPCA - Principal component analysis

```toml

[SeuratPreparing.envs.RunPCA]

npcs = 50 # Number of principal components

verbose = true

rev.pca = false # Reverse PCA direction

weight.by.var = true # Weight by variance

```

SCTransform Workflow (use_sct = true):

  1. SCTransform - Variance-stabilizing transformation (replaces standard pipeline)

```toml

[SeuratPreparing.envs.SCTransform]

assay = "RNA" # Input assay

new.assay.name = "SCT" # Output assay name

return-only-var-genes = true # Keep only variable genes

min_cells = 3 # Minimum cells per gene (hidden param)

variable.features.n = 3000 # Number of variable features

variable.features.rv.th = 1.3 # Residual variance threshold

vars.to.regress = [] # Variables to regress out

do.correct.umi = true # Correct for UMI counts

ncells = 5000 # Subsample for model fitting

do.scale = false # Scale after transformation

do.center = true # Center after transformation

clip.range = [-10, 10] # Clip residual values

vst.flavor = "v2" # VST algorithm version

conserve.memory = false # Memory-efficient mode

seed.use = 1448145 # Random seed

verbose = true

```

Integration Methods

IntegrateLayers - Multi-sample batch correction

[SeuratPreparing.envs.IntegrateLayers]
method = "harmony"                      # Integration method
orig.reduction = "pca"                  # Base reduction for correction
assay = null                             # Assay to integrate (auto-detected)
features = null                           # Features for integration
layers = null                             # Layers to integrate
scale.layer = "scale.data"                 # Scaled layer name

Doublet Detection

DoubletFinder - Simulation-based doublet detection

[SeuratPreparing.envs.DoubletFinder]
PCs = 10                                 # Number of PCs to use
doublets = 0.075                          # Expected doublet rate (7.5%)
pN = 0.25                                  # Doublet simulation proportion (25%)
ncores = 1                                  # Cores for paramSweep (null = use envs.ncores)
pK = 0.005                                 # Expected doublet rate parameter
reduction = "pca"                           # Reduction to use

scDblFinder - Machine learning-based doublet detection

[SeuratPreparing.envs.scDblFinder]
dbr = 0.075                               # Expected doublet rate (7.5%)
ncores = 1                                  # Cores for scDblFinder (null = use envs.ncores)
dbr.per1k = 0.8                            # Doublets per 1000 cells
verbose = true

Configuration Examples

Minimal Configuration (Single Sample, No Integration)

[SeuratPreparing]
[SeuratPreparing.in]
metafile = ["sample_info.txt"]

[SeuratPreparing.envs]
cell_qc = "nFeature_RNA > 200 & percent.mt < 5"
gene_qc = { min_cells = 3 }

Standard SCTransform with Harmony Integration

[SeuratPreparing]
[SeuratPreparing.in]
metafile = ["sample_info.txt"]

[SeuratPreparing.envs]
ncores = 4
use_sct = true

# QC filtering
cell_qc = "nFeature_RNA > 200 & percent.mt < 5"
gene_qc = { min_cells = 3 }

# SCTransform parameters
[SeuratPreparing.envs.SCTransform]
vars.to.regress = ["percent.mt", "percent.ribo"]
variable.features.n = 3000

# Harmony integration
[SeuratPreparing.envs.IntegrateLayers]
method = "harmony"

Multi-sample RPCA Integration

[SeuratPreparing]
[SeuratPreparing.in]
metafile = ["sample_info.txt"]

[SeuratPreparing.envs]
use_sct = false
ncores = 8

# Standard normalization workflow
[SeuratPreparing.envs.NormalizeData]
normalization-method = "LogNormalize"
scale-factor = 10000

[SeuratPreparing.envs.FindVariableFeatures]
selection-method = "vst"
nfeatures = 3000

[SeuratPreparing.envs.ScaleData]
vars.to.regress = ["percent.mt", "S.Score", "G2M.Score"]

# RPCA integration (faster, conservative)
[SeuratPreparing.envs.IntegrateLayers]
method = "rpca"
orig.reduction = "pca"

With DoubletFinder

[SeuratPreparing]
[SeuratPreparing.in]
metafile = ["sample_info.txt"]

[SeuratPreparing.envs]
use_sct = true
doublet_detector = "DoubletFinder"

[SeuratPreparing.envs.DoubletFinder]
PCs = 30
doublets = 0.05
pN = 0.25
ncores = 4

With scDblFinder

[SeuratPreparing]
[SeuratPreparing.in]
metafile = ["sample_info.txt"]

[SeuratPreparing.envs]
use_sct = true
doublet_detector = "scDblFinder"

[SeuratPreparing.envs.scDblFinder]
dbr = 0.05
ncores = 4

Per-Sample Cell QC

[SeuratPreparing.envs]
cell_qc = { DEFAULT = "nFeature_RNA > 200 & percent.mt < 5",
              Sample1 = "nFeature_RNA > 300 & percent.mt < 10",
              Sample2 = "nFeature_RNA > 150 & percent.mt < 5" }

Custom QC Plots

[SeuratPreparing.envs.qc_plots]
# Violin plots for QC metrics
[SeuratPreparing.envs.qc_plots."QC Violin Plots"]
kind = "cell"
plot_type = "violin"
devpars = { res = 100, height = 600, width = 1200 }

# Scatter plots
[SeuratPreparing.envs.qc_plots."QC Scatter Plots"]
kind = "cell"
plot_type = "scatter"
devpars = { res = 100, height = 800, width = 1200 }

# Gene expression distribution
[SeuratPreparing.envs.qc_plots."Gene Expression Distribution"]
kind = "gene"
plot_type = "histogram"
devpars = { res = 100, height = 1200, width = 1200 }

Common Patterns

Pattern 1: Single Sample (No Integration)

# Use when analyzing one sample or already batch-corrected data
[SeuratPreparing]
[SeuratPreparing.in]
metafile = ["single_sample_info.txt"]

[SeuratPreparing.envs]
no_integration = true  # Skip integration step
use_sct = true
cell_qc = "nFeature_RNA > 200 & percent.mt < 5"
gene_qc = { min_cells = 3 }

Pattern 2: Multiple Samples with Harmony Integration

# Use for multi-batch data with complex batch structures
[SeuratPreparing]
[SeuratPreparing.in]
metafile = ["multi_sample_info.txt"]

[SeuratPreparing.envs]
use_sct = true
ncores = 8

# Cell QC
cell_qc = "nFeature_RNA > 200 & nCount_RNA > 500 & percent.mt < 10"
gene_qc = { min_cells = 3, excludes = ["MALAT1", "MT-ND3"] }

# SCTransform with regression
[SeuratPreparing.envs.SCTransform]
vars.to.regress = ["percent.mt", "percent.ribo", "S.Score", "G2M.Score"]
variable.features.n = 3000

# Harmony integration
[SeuratPreparing.envs.IntegrateLayers]
method = "harmony"

Pattern 3: Batch Correction with RPCA (Large Datasets)

# Use for large datasets (>100k cells) or same-platform multi-batch
[SeuratPreparing]
[SeuratPreparing.in]
metafile = ["large_dataset_info.txt"]

[SeuratPreparing.envs]
use_sct = false  # RPCA works better with standard workflow
ncores = 16

# Standard workflow
[SeuratPreparing.envs.NormalizeData]
normalization-method = "LogNormalize"
scale-factor = 10000

[SeuratPreparing.envs.FindVariableFeatures]
selection-method = "vst"
nfeatures = 3000

[SeuratPreparing.envs.ScaleData]
vars.to.regress = ["percent.mt", "percent.ribo"]

[SeuratPreparing.envs.RunPCA]
npcs = 100

# RPCA integration (faster for large data)
[SeuratPreparing.envs.IntegrateLayers]
method = "rpca"
orig.reduction = "pca"

Pattern 4: Doublet Detection + Integration

# Use for datasets with high doublet rates (>5%)
[SeuratPreparing]
[SeuratPreparing.in]
metafile = ["high_doublet_info.txt"]

[SeuratPreparing.envs]
use_sct = true
doublet_detector = "scDblFinder"  # or "DoubletFinder"

[SeuratPreparing.envs.scDblFinder]
dbr = 0.08  # Higher expected doublet rate
ncores = 4

[SeuratPreparing.envs.SCTransform]
vars.to.regress = ["percent.mt", "percent.ribo"]

[SeuratPreparing.envs.IntegrateLayers]
method = "harmony"

Pattern 5: Keep All Genes (Not Just Variable Genes)

# Use when you need to analyze non-variable genes later
[SeuratPreparing]
[SeuratPreparing.in]
metafile = ["sample_info.txt"]

[SeuratPreparing.envs]
use_sct = true

[SeuratPreparing.envs.SCTransform]
min_cells = 0                    # Don't filter by expression
return-only-var-genes = false   # Keep all genes in RNA assay

Dependencies

Upstream Processes

Downstream Processes

Assay Output

Validation Rules

Required Parameters

Normalization Method Constraints

Integration Method Constraints

Doublet Detection Constraints

Cache Configuration

Troubleshooting

Issue: Too many cells filtered by QC

Symptoms: Low cell count after SeuratPreparing

Solutions:

Issue: Integration overcorrects biological variation

Symptoms: Clusters mix distinct cell types after integration

Solutions:

Issue: High doublet rate detected (>15%)

Symptoms: More doublets than expected

Solutions:

Issue: SCTransform returns too few genes

Symptoms: Low number of genes in SCT assay

Solutions:

Issue: Memory errors during processing

Symptoms: Process killed or out-of-memory errors

Solutions:

Issue: Slow processing for large datasets

Symptoms: Process takes >24 hours

Solutions:

Issue: Batch effects remain after integration

Symptoms: Cells cluster by sample rather than cell type

Solutions:

Issue: Seurat v5 compatibility errors

Symptoms: Assay layer errors, deprecated function warnings

Solutions:

Quick Reference

Default Parameter Values

ncores = 1
min_cells = 0
min_features = 0
cell_qc = ""
gene_qc = { min_cells = 0 }
use_sct = false
no_integration = false
doublet_detector = "none"
cache = "/tmp"

# NormalizeData
normalization-method = "LogNormalize"
scale-factor = 10000

# FindVariableFeatures
selection-method = "vst"
nfeatures = 2000

# SCTransform
variable.features.n = 3000
variable.features.rv.th = 1.3
min_cells = 3
return-only-var-genes = true

# IntegrateLayers
method = "harmony"

# DoubletFinder
PCs = 10
doublets = 0.075
pN = 0.25

# scDblFinder
dbr = 0.075

QC Metric Keys (Available in cell_qc expressions)

Integration Method Selection Guide

| Situation | Recommended Method | Reason |

|-----------|-------------------|---------|

| Strong biological differences | CCA | Captures shared biology despite expression shifts |

| Same platform, large data | RPCA | Faster, conservative, less overcorrection |

| Complex batch structure | Harmony | Handles multiple batch variables |

| Very large datasets (>200k) | RPCA or scVI | Scales well computationally |

| Cross-modality integration | CCA or FastMNN | Designed for different data types |

| Preliminary analysis | Harmony | Fast, good default performance |

Seurat Assay Information After Processing

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.