Chapter 2 Data Preprocessing
This chapter describes the preprocessing workflows for single-cell RNA sequencing and spatial transcriptomic data. The scripts process sequencing reads into gene expression matrices, immune receptor annotations, and spatially resolved expression outputs. Additional preprocessing generates loom files for downstream RNA velocity analysis.
2.1 scRNA-seq
Single-cell preprocessing includes gene expression quantification, T-cell receptor (TCR) and B-cell receptor (BCR) reconstruction where corresponding libraries are available, and preparation of spliced and unspliced count matrices.
2.1.1 Preprocessing
Gene expression FASTQ files are processed using Cell Ranger with the human GRCh38 reference. The count pipeline performs read alignment, barcode processing, and unique molecular identifier (UMI) counting to generate gene expression matrices.
TCR and BCR libraries are processed separately using the Cell Ranger V(D)J pipeline with the human V(D)J reference to assemble receptor sequences and identify clonotypes.
#!/bin/bash
#SBATCH -p CPU # partition (queue)
#SBATCH --job-name=HEA
#SBATCH -n 40
#SBATCH -t 7-00:00 # time (D-HH:MM)
#SBATCH --array=1-4
#SBATCH -o _log/scrna.%A_%a.out # STDOUT
#SBATCH -e _log/scrna.%A_%a.err # STDERR
#SBATCH --exclude=node30
#SBATCH --mail-type=END,FAIL # notifications for job done & fail
#SBATCH --mail-user=XX # send-to address
id=`sed -n ${SLURM_ARRAY_TASK_ID}p sample.txt`
echo "${id}"
fq_path=.
index_path=refdata-gex-GRCh38-2024-A
index_vdj=refdata-cellranger-vdj-GRCh38-alts-ensembl-7.1.0
$CELLRANGER_9 count --id=${sample}_RNA \
--fastqs=${fq_path}/${sample} \
--create-bam=true \
--include-introns=false \
--sample=${sample}_RNA \
--transcriptome=${index_path}
$CELLRANGER_9 vdj --id=${sample}_TCR \
--fastqs=${fq_path}/${sample} \
--sample=${sample}_TCR \
--reference=${index_vdj}
$CELLRANGER_9 vdj --id=${sample}_BCR \
--fastqs=${fq_path}/${sample} \
--sample=${sample}_BCR \
--reference=${index_vdj} 2.1.2 RNA loom
Velocyto is used to generate loom files from the aligned BAM files, filtered cell barcodes, and gene annotations associated with the Cell Ranger reference. The barcode list restricts processing to cells retained by Cell Ranger. Transcripts are quantified as spliced, unspliced, or ambiguous, and the resulting count matrices provide inputs for downstream RNA velocity analysis.
#!/bin/bash
#SBATCH -p SVC # partition (queue)
#SBATCH --job-name=HEA
#SBATCH -n 40
#SBATCH --array=1-27
#SBATCH --exclude=node03
#SBATCH -t 7-00:00 # time (D-HH:MM)
#SBATCH -o _log/loom.%A_%a.out # STDOUT
#SBATCH -e _log/loom.%A_%a.err # STDERR
#SBATCH --mail-type=END,FAIL # notifications for job done & fail
#SBATCH --mail-user=XXX # send-to address
sample=`sed -n ${SLURM_ARRAY_TASK_ID}p sample.txt`
echo "${sample}"
gtf_file=refdata-gex-GRCh38-2024-A/genes/genes.gtf
velocyto run -b ${bam_path}/${sample}_RNA/outs/filtered_feature_bc_matrix/barcodes.tsv.gz \
-o ${out_path}/${sample} -@ 40 ${bam_path}/${sample}_RNA/outs/possorted_genome_bam.bam ${gtf_file}2.2 Spatial
Spatial preprocessing (10X visium HD) combines sequencing data with tissue images to generate gene expression outputs linked to their spatial locations.
2.2.1 Preprocessing
Visium HD data are processed using Space Ranger with the human GRCh38 reference and the specified human transcriptome probe set. The workflow incorporates sequencing FASTQ files, the microscope image, the CytAssist image, and a Loupe alignment file to associate expression measurements with tissue coordinates. Slide and capture-area identifiers specify the spatial layout. Outputs include expression matrices, spatial information, quality summary reports, and BAM files for subsequent analyses.
#!/bin/bash
#SBATCH -p training # partition (queue)
#SBATCH --job-name=HEA
#SBATCH -n 40
#SBATCH -t 7-00:00 # time (D-HH:MM)
#SBATCH -o _log/scrna.%A_%a.out # STDOUT
#SBATCH -e _log/scrna.%A_%a.err # STDERR
#SBATCH --mail-type=END,FAIL # notifications for job done & fail
#SBATCH --mail-user=809449456@qq.com # send-to address
fq_path=.
index_path=refdata-gex-GRCh38-2024-A
prob_path=Visium_Human_Transcriptome_Probe_Set_v2.1.0_GRCh38-2024-A.csv
sample=""
echo "${sample}"
$SPACERANGER_4 count --id=${sample}_STR \
--fastqs=${fq_path}/${sample} \
--transcriptome=${index_path} \
--sample=${sample}_STR \
--image=${fq_path}/${sample}/${sample}_PIC.jpg \
--slide=H1-FVV8T9P \
--area=D1 \
--probe-set=${prob_path} \
--cytaimage=${fq_path}/${sample}/${sample}_H1-FVV8T9P_D1.tif \
--loupe-alignment=${fq_path}/${sample}/${sample}_H1-FVV8T9P-D1.json \
--create-bam=true