Screpcombiningexpression

From pwwang/immunopipe · View interactive version

Screpcombiningexpression is an AI agent skill from the GitHub repository pwwang/immunopipe. Combine scTCR/BCR repertoire data with scRNA-seq expression data using `scRepertoire::combineExpression()`. This process integrates immune receptor information (CDR3 sequences, V(D)J genes, clonotypes) into a Seurat object's metadata, enabling clonotype-aware gene expression analysis.

How to use this skill

Skill file

ScRepCombiningExpression Process Configuration

Purpose

Combine scTCR/BCR repertoire data with scRNA-seq expression data using scRepertoire::combineExpression(). This process integrates immune receptor information (CDR3 sequences, V(D)J genes, clonotypes) into a Seurat object's metadata, enabling clonotype-aware gene expression analysis.

When to Use

Configuration Structure

Process Enablement

[ScRepCombiningExpression]
cache = true

Input Specification

[ScRepCombiningExpression.in]
# Required inputs
screpfile = ["ScRepLoading"]      # scRepertoire object from ScRepLoading
srtobj = ["SeuratClustering"]     # Seurat object with RNA data

Note: Barcodes in srtobj must match barcodes in screpfile. Ensure both datasets were generated from the same cell calling run.

Environment Variables

[ScRepCombiningExpression.envs]
# Clonotype definition
cloneCall = "aa"  # How to define a clonotype (default: aa)

# Chain selection
chain = "both"    # Which TCR/BCR chains to use (default: both)

# Frequency calculation
group_by = "Sample"  # Group for frequency/proportion calculation (default: Sample)
proportion = true    # Use proportion (true) or total frequency (false) (default: true)

# Filtering options
filterNA = false   # Remove cells without TCR/BCR data (default: false)

# Clone size bins
cloneSize = {Rare = 0.0001, Small = 0.001, Medium = 0.01, Large = 0.1, Hyperexpanded = 1}

# Label customization
addLabel = false   # Add label to frequency header (default: false)
Environment Variables Explained

cloneCall: Defines clonotype grouping strategy

chain: Which receptor chains to include

group_by: Column for frequency calculation

proportion:

filterNA:

cloneSize: Bins for categorizing clone sizes

addLabel: Useful when running multiple configurations with different group_by or cloneCall settings.

Configuration Examples

Minimal Configuration

[ScRepCombiningExpression]
[ScRepCombiningExpression.in]
screpfile = ["ScRepLoading"]
srtobj = ["SeuratClustering"]

Use when: Default CDR3aa clonotype definition is sufficient.

Standard TCR Integration

[ScRepCombiningExpression]
[ScRepCombiningExpression.in]
screpfile = ["ScRepLoading"]
srtobj = ["SeuratClustering"]
[ScRepCombiningExpression.envs]
# Use CDR3 amino acid for clonotype definition
cloneCall = "aa"
# Include both TRA and TRB chains
chain = "both"
# Calculate frequency per sample
group_by = "Sample"
# Use proportional frequency
proportion = true

Use when: Analyzing TCR data with standard parameters.

BCR Heavy+Light Chain Integration

[ScRepCombiningExpression]
[ScRepCombiningExpression.in]
screpfile = ["ScRepLoading"]
srtobj = ["SeuratClustering"]
[ScRepCombiningExpression.envs]
# BCR data - analyze both heavy and light chains
chain = "both"
# Use V gene + CDR3aa for specific clonotype definition
cloneCall = "aa"
# Calculate frequency per sample
group_by = "Sample"

Use when: Analyzing paired IGH + IGL/IGK BCR data.

Clonotype by RNA Cluster

[ScRepCombiningExpression]
[ScRepCombiningExpression.in]
screpfile = ["ScRepLoading"]
srtobj = ["SeuratClustering"]
[ScRepCombiningExpression.envs]
# Calculate clonotype frequency within each RNA cluster
group_by = "seurat_clusters"
# Use absolute counts instead of proportions
proportion = false

Use when: Need to track which RNA clusters contain expanded clones.

Remove Non-Productive Cells

[ScRepCombiningExpression]
[ScRepCombiningExpression.in]
screpfile = ["ScRepLoading"]
srtobj = ["SeuratClustering"]
[ScRepCombiningExpression.envs]
# Remove cells without productive V(D)J rearrangements
filterNA = true

Use when: Analysis should only include cells with receptor data.

Gene-Based Clonotype Definition

[ScRepCombiningExpression]
[ScRepCombiningExpression.in]
screpfile = ["ScRepLoading"]
srtobj = ["SeuratClustering"]
[ScRepCombiningExpression.envs]
# Group by V(D)JC gene usage only
cloneCall = "gene"

Use when: Interested in V gene bias rather than CDR3 specificity.

Common Patterns

Pattern 1: Simple TCR Addition (Default)

[ScRepCombiningExpression]
[ScRepCombiningExpression.in]
screpfile = ["ScRepLoading"]
srtobj = ["SeuratClustering"]

Best for: Initial exploratory analysis with default CDR3aa clonotypes.

Pattern 2: TCR Beta Chain Only

[ScRepCombiningExpression.envs]
# Analyze only TRB chain
chain = "TRB"

Best for: TRB-focused analyses when TRA data is noisy or unavailable.

Pattern 3: BCR with Custom Clone Bins

[ScRepCombiningExpression.envs]
chain = "both"
cloneCall = "aa"
# Custom bins for BCR clonal expansion
cloneSize = {Single = 1, Small = 3, Medium = 10, Large = 50, Hyperexpanded = 500}

Best for: BCR analysis where expansion patterns differ from TCR.

Pattern 4: Frequency by Condition

[ScRepCombiningExpression.envs]
# Calculate frequency per experimental condition
group_by = "Diagnosis"
# Use absolute counts
proportion = false

Best for: Comparing clonal expansion across treatment groups.

Pattern 5: Strict Clonotype Definition

[ScRepCombiningExpression.envs]
# Most specific: V(D)JC gene + CDR3 nucleotide
cloneCall = "strict"

Best for: High-resolution clonotype analysis where gene + CDR3 matter.

Metadata Added to Seurat Object

After running ScRepCombiningExpression, the Seurat object's metadata will include:

Core Columns (from scRepertoire)

Custom Column (immunopipe-specific)

Chain-Specific Columns (when applicable)

Dependencies

Upstream Processes

Downstream Processes

Data Flow

ScRepLoading (TCR/BCR data)
         ↓
SeuratClustering (RNA clusters)
         ↓
ScRepCombiningExpression (integrate)
         ↓
CDR3Clustering / TESSA / ClonalStats

Validation Rules

Barcode Matching

Clonotype Definition Constraints

Chain Selection Rules

Troubleshooting

Issue: No metadata columns added

Possible causes:

  1. Barcode mismatch between RNA and TCR/BCR data
  2. All cells filtered out (low QC or missing V(D)J data)
  3. Empty TCR/BCR input file

Diagnosis:

# Check barcode overlap
length(intersect(Cells(srtobj), rownames(screpfile)))

Solution: Ensure both datasets come from same cell calling run, or manually filter to common barcodes.

Issue: Many cells with `VDJ_Presence = FALSE`

Possible causes:

  1. Low sequencing depth for V(D)J library
  2. Stringent V(D)J calling filters
  3. Non-T/B cells in dataset (e.g., myeloid cells)

Solution:

Issue: Empty `CTaa` column

Possible causes:

  1. Wrong chain selected (e.g., chain = "TRB" for alpha-only T cells)
  2. Paired chain data but single-chain selection
  3. Non-productive rearrangements filtered out

Solution:

Issue: Clonotype frequency doesn't sum to 1

Possible causes:

  1. group_by includes cells without V(D)J data
  2. proportion = false (using counts, not proportions)
  3. Multiple samples with different cell counts

Solution:

Issue: All clones in "Rare" category

Possible causes:

  1. cloneSize thresholds too high for data
  2. Low clonal expansion in dataset
  3. proportion = false with absolute counts

Solution:

Best Practices

Data Preparation

  1. Run same cell calling for RNA and V(D)J libraries
  2. Apply consistent QC filters before integration
  3. Verify sample matching between RNA and TCR/BCR metadata

Parameter Selection

  1. Use cloneCall = "aa" for most analyses (default)
  2. Use chain = "both" for paired receptor data
  3. Set group_by = "Sample" for frequency calculations (default)
  4. Keep filterNA = false to distinguish productive vs non-productive cells

Validation

  1. Check barcode overlap before running: sum(rownames(srtobj) %in% rownames(screpfile))
  2. Verify VDJ_Presence distribution: table(srtobj$VDJ_Presence)
  3. Inspect clone size distribution: table(srtobj$cloneSize)
  4. Check clonotype counts: length(unique(srtobj$CTaa))

External References

scRepertoire Documentation

Clonotype Definition

Chain Pairing

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.