How to Build a Bulk RNA-seq Analysis Pipeline for Your Own Data
By the end of this guide you will have a reproducible pipeline that turns paired-end FASTQ files into three artifacts: a gene-level count matrix, a variance-stabilized expression matrix suitable for clustering and machine learning, and a ranked table of genes that change across your timepoints. You need the raw FASTQ files and the library prep details from the sequencing provider, a machine with at least 32 GB of RAM and roughly 200 GB of free disk, and working knowledge of the shell and R. Everything below assumes human data and a mamba or conda environment. If you are working with a single person’s blood sampled repeatedly, the statistics section matters more than the alignment section, so read it carefully.
1. Establish what your library contains
Before running any tool, get four facts from the sequencing provider: read length and pairing, library selection chemistry, strandedness, and target depth. These four determine every downstream choice, and guessing them is the most common source of silently wrong results.
Library selection is the one that changes biology. Poly-A selection captures polyadenylated mRNA and gives you the cleanest protein-coding signal per read. Ribosomal RNA depletion (Ribo-Zero, RiboCop) retains non-polyadenylated transcripts including many long non-coding RNAs and pre-mRNA, at the cost of spending reads on intronic sequence. For degraded input or for anything where non-coding transcripts matter, rRNA depletion is the better protocol.
Whole blood adds a specific problem. Hemoglobin transcripts from residual reticulocytes can consume a very large fraction of reads, leaving too few for the rest of the transcriptome. Globin depletion during prep, or PAXgene-style stabilization followed by globin block, is the standard remedy. If your provider did not deplete globin, check the fraction of reads mapping to HBB, HBA1, and HBA2 before drawing any conclusions about low-expressed genes.
Strandedness you can infer rather than trust. Run Salmon with -l A and read the lib_format_counts.json it writes. Most modern kits are reverse-stranded (ISR in Salmon notation, --rna-strandness RF in HISAT2 notation).
2. Set up the environment and references
Pin your tool versions now. Transcript quantification results shift between versions, and a longitudinal profile is only comparable to itself if the pipeline is stable across runs.
mamba create -n rnaseq -c conda-forge -c bioconda \
fastp=0.23.4 fastqc=0.12.1 multiqc=1.21 \
salmon=1.10.3 star=2.7.11b samtools=1.19 \
subread=2.0.6 qualimap=2.3
mamba activate rnaseq
For references, use GENCODE and keep the annotation version in the output path. We use the primary assembly plus the matching comprehensive annotation.
wget https://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_45/GRCh38.primary_assembly.genome.fa.gz
wget https://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_45/gencode.v45.transcripts.fa.gz
wget https://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_45/gencode.v45.primary_assembly.annotation.gtf.gz
Build a decoy-aware Salmon index. The decoys are the genome sequence itself, which lets Salmon discard reads that look transcriptomic but come from unannotated genomic regions. Skipping this step inflates counts for genes with pseudogene or intronic near-matches.
grep '^>' <(gunzip -c GRCh38.primary_assembly.genome.fa.gz) \
| cut -d ' ' -f 1 | sed 's/>//g' > decoys.txt
cat gencode.v45.transcripts.fa.gz GRCh38.primary_assembly.genome.fa.gz > gentrome.fa.gz
salmon index -t gentrome.fa.gz -d decoys.txt -p 16 \
-i salmon_idx_gencode45 --gencode -k 31
The --gencode flag strips the pipe-delimited GENCODE headers down to the transcript ID, which saves you a string-parsing step later. Index building takes roughly 20 to 40 minutes and about 16 GB of RAM.
3. Quality control and trimming
Run FastQC on the raw files first so you have a record of the input, then trim. We use fastp because it does adapter detection, quality trimming, and reporting in one pass and it is fast enough to be unremarkable.
fastp \
-i sample_R1.fastq.gz -I sample_R2.fastq.gz \
-o trim_R1.fastq.gz -O trim_R2.fastq.gz \
--detect_adapter_for_pe \
--cut_front --cut_tail --cut_mean_quality 20 \
--length_required 36 \
--thread 8 \
--json sample.fastp.json --html sample.fastp.html
Be conservative with trimming. Aggressive quality trimming shortens reads and biases quantification of short transcripts. Adapter removal and a minimum length filter are enough for most libraries.
Three numbers in the report deserve attention. Duplication rate above roughly 50% in a poly-A library usually means low input complexity rather than a bug. Per-base GC that diverges sharply between R1 and R2 suggests a prep problem. A large drop in reads after --length_required means the insert size was shorter than the read length, and you are sequencing through into adapter.
Aggregate everything with MultiQC once all samples are processed: multiqc . -o qc_report. Reviewing samples side by side is the only reliable way to spot an outlier run, and structured QC of this kind is the step that most pipeline write-ups treat too lightly 1.
4. Quantify with Salmon
For gene-level expression, selective alignment with Salmon is our default. It is roughly an order of magnitude faster than genome alignment, it handles multi-mapping reads probabilistically rather than discarding them, and with a decoy-aware index its gene-level accuracy is comparable to STAR plus featureCounts. Alignment-free and alignment-based routes are both standard practice and the choice mostly comes down to what else you need from the data 2.
salmon quant \
-i salmon_idx_gencode45 -l A \
-1 trim_R1.fastq.gz -2 trim_R2.fastq.gz \
-p 16 -o quant/sample01 \
--seqBias --gcBias --posBias \
--numGibbsSamples 20 \
--validateMappings
--gcBias corrects fragment-level GC content bias and matters for any comparison across library preps done on different days. --numGibbsSamples 20 writes posterior samples that let downstream tools account for quantification uncertainty, which is useful when a gene has few uniquely assignable reads.
Check quant/sample01/logs/salmon_quant.log for the mapping rate. For human poly-A data, expect 75 to 90%. Below 60%, suspect contamination, the wrong organism reference, or heavy rRNA carryover.
Use STAR instead when you need the alignments themselves: splice junction discovery, variant calling from RNA, fusion detection, or coverage plots. In that case align to the genome and count with featureCounts, matching -s 2 to a reverse-stranded library.
STAR --genomeDir star_idx --readFilesIn trim_R1.fastq.gz trim_R2.fastq.gz \
--readFilesCommand zcat --runThreadN 16 \
--outSAMtype BAM SortedByCoordinate \
--quantMode GeneCounts --outFileNamePrefix bam/sample01.
featureCounts -p --countReadPairs -T 8 -s 2 \
-a gencode.v45.primary_assembly.annotation.gtf \
-o counts.txt bam/*.bam
STAR needs about 32 GB of RAM for a human index. If you only have 16 GB, use Salmon or HISAT2.
5. Build the gene-level matrix in R
Salmon writes transcript-level estimates. Summarize them to genes with tximport, which also computes an average transcript length offset per gene per sample. That offset corrects for isoform switching that would otherwise look like a change in gene expression.
library(tximport); library(AnnotationDbi)
library(org.Hs.eg.db); library(readr)
files <- file.path("quant", samples$id, "quant.sf")
names(files) <- samples$id
# tx2gene: two columns, transcript ID -> gene ID, from the GENCODE GTF
txi <- tximport(files, type = "salmon", tx2gene = tx2gene,
countsFromAbundance = "lengthScaledTPM")
We use countsFromAbundance = "lengthScaledTPM" because it produces counts that are already length-corrected, which makes them safe to hand to tools that do not accept an offset matrix. If you are going straight into DESeq2, "no" plus DESeqDataSetFromTximport is equally correct and slightly more principled, since DESeq2 then uses the length offsets directly.
Filter before modeling. Genes with near-zero counts across all samples add nothing but multiple-testing burden.
library(edgeR)
keep <- filterByExpr(txi$counts, group = samples$condition)
table(keep) # expect ~14,000-18,000 genes retained for whole blood
6. Normalize and look at the structure
Normalization and exploration come before hypothesis testing, and skipping them is how people end up reporting batch effects as biology. Use a variance-stabilizing transform for anything involving distances: PCA, correlation heatmaps, clustering, or feature input to a model.
library(DESeq2)
dds <- DESeqDataSetFromTximport(txi, colData = samples, design = ~ timepoint)
dds <- dds[keep, ]
vsd <- vst(dds, blind = TRUE)
plotPCA(vsd, intgroup = c("timepoint", "batch"))
Read the PCA. If PC1 separates your samples by sequencing run rather than by timepoint, you have a batch effect that must go into the design matrix. If one sample sits far from the rest, check its RNA integrity number and its 5’-to-3’ coverage uniformity with qualimap rnaseq. Degraded RNA shows a clear 3’ bias and will distort every comparison that includes it.
For a longitudinal single-person profile, also compute sample-to-sample Spearman correlation on the vst matrix. Blood transcriptomes from the same person weeks apart typically correlate above 0.95. A value well below that points to a technical problem or to a genuine acute perturbation such as infection, and distinguishing those two is a question for a clinician rather than for the pipeline.
7. Test for differences across timepoints
This is where single-person data departs from the textbook. Standard differential expression assumes biological replicates within each group so that the model can estimate gene-wise dispersion. With one sample per timepoint you have no replication, and no software can conjure it.
There are two defensible options. The first is to treat repeated sampling during a stable baseline period as your replicate set, then test later timepoints against that baseline.
dds$period <- factor(ifelse(dds$timepoint %in% c("t0","t1","t2"),
"baseline", "later"))
design(dds) <- ~ period
dds <- DESeq(dds)
res <- results(dds, contrast = c("period","later","baseline"),
alpha = 0.05, lfcThreshold = log2(1.5))
res <- lfcShrink(dds, coef = "period_later_vs_baseline",
type = "apeglm", res = res)
Setting lfcThreshold inside results() tests against a fold-change floor rather than against zero. That is stricter and more useful than filtering by fold change after the fact.
The second option applies when you truly have one sample per condition. Fit an edgeR model with a fixed biological coefficient of variation instead of an estimated one. The edgeR user guide suggests a BCV around 0.4 for human samples from different individuals, and a much smaller value for technical replicates of the same sample.
y <- DGEList(counts = round(txi$counts))
y <- calcNormFactors(y)
bcv <- 0.4
et <- exactTest(y, pair = c("t0","t5"), dispersion = bcv^2)
topTags(et, n = 30)
Treat the output as a ranked list for exploration. It is not a set of significance claims. The p-values are conditional on a dispersion you assumed.
On method choice more broadly: DESeq2 and edgeR behave similarly on well-powered designs, while limma-voom is faster and better calibrated as sample counts grow into the dozens. Comparative reviews of differential expression methods find that the choice matters most at small sample sizes and with unusual count distributions 3. For fewer than ten samples we use DESeq2 with apeglm shrinkage, because shrunken effect sizes are far more stable for ranking.
8. Move to pathways and cell composition
Single-gene results from one person are noisy. Aggregating to gene sets is the step that makes the data interpretable, because coordinated shifts across a pathway are much harder to produce by chance than one gene crossing a threshold.
Rank all genes by the Wald statistic and run fgsea against Hallmark and Reactome sets.
library(fgsea); library(msigdbr)
stats <- res$stat; names(stats) <- rownames(res)
stats <- sort(stats[is.finite(stats)])
h <- msigdbr(species = "Homo sapiens", category = "H")
pathways <- split(h$gene_symbol, h$gs_name)
fg <- fgseaMultilevel(pathways, stats, minSize = 15, maxSize = 500)
fg[order(fg$padj), c("pathway","NES","padj","size")][1:20, ]
For whole blood, a large share of transcriptome variation reflects shifting cell proportions rather than per-cell regulation. Deconvolution estimates those proportions from bulk expression, and running it lets you tell the two apart. CIBERSORTx with the LM22 signature matrix and quanTIseq are the usual choices. Integrated protocols such as RIMA combine quantification, immune cell deconvolution, and repertoire inference in one workflow. That is a sensible model to copy even if you assemble the parts yourself 4.
If you want a single environment that spans bulk and single-cell analysis in Python, consider OmicVerse. It packages preprocessing, differential expression, and pathway enrichment behind a consistent API 5. For an interactive R route with a Shiny front end that you can hand to a collaborator, bulkAnalyseR covers exploration and network inference without writing much code 6.
Downstream machine learning on expression features is possible and increasingly common, though published applications are mostly trained on large cohorts rather than on repeated samples from one person 7. Be skeptical of any model applied to your data that was not validated on a longitudinal design.
9. Make the outputs durable
Write four files per run and keep them alongside a manifest recording tool versions, reference release, and command lines. This is what makes a profile comparable to itself a year later, and it is what an analysis agent needs in order to do anything useful without re-deriving your choices.
write_tsv(as.data.frame(assay(vsd)) |> rownames_to_column("gene_id"),
"out/expression_vst.tsv.gz")
write_tsv(as.data.frame(counts(dds)) |> rownames_to_column("gene_id"),
"out/counts_gene.tsv.gz")
write_tsv(as.data.frame(res) |> rownames_to_column("gene_id"),
"out/de_results.tsv.gz")
saveRDS(dds, "out/dds.rds")
Use Nextflow or Snakemake to wrap steps 3 through 5 once the pipeline stabilizes. nf-core/rnaseq is a well-tested implementation if you would rather not maintain your own, and automated pipelines of this kind exist precisely because the manual version drifts 8. Published step-by-step protocols cover the same ground with more hand-holding if you want a second reference implementation to compare against 9.
Common problems
Low mapping rate with high-quality reads usually means the index and the data disagree. Check that you built the index from the same GENCODE release you are annotating with, and that you did not mix a transcriptome-only index with genome-aligned expectations.
Strandedness set wrong cuts your effective counts roughly in half and skews antisense genes badly. Salmon’s -l A avoids this. If you use featureCounts, verify -s against the lib_format_counts.json from a test Salmon run rather than against the kit documentation alone.
A PCA dominated by batch is the most frequent real failure. Add batch to the design formula when the design allows it. If batch is perfectly confounded with the biological variable, the experiment cannot answer the question and no correction will fix that.
Globin or rRNA dominance shows up as a small number of genes taking most of the counts. Compute the fraction of counts in the top 10 genes. Above 40% in whole blood, treat all low-expression results as unreliable.
Duplicate gene symbols break joins silently. Key everything on Ensembl gene IDs with the version suffix stripped, and map to symbols only for display.
Finally, resist reading clinical meaning into a single differential expression table. Expression is dynamic and responds to sleep, exercise, recent infection, and time of day. Repeated sampling under comparable conditions is what separates a real signal from a Tuesday. Any result that seems to bear on your health belongs in a conversation with a physician who can order the appropriate confirmatory testing.
Footnotes
-
Amarinder Singh Thind, Isha Monga, Prasoon Kumar Thakur, et al. Demystifying emerging bulk RNA-Seq applications: the application and utility of bioinformatic methodology. Briefings in Bioinformatics, 2021. https://doi.org/10.1093/bib/bbab259 ↩
-
Jorge A. Tzec‐Interián, Daianna González‐Padilla, Elsa B. Góngora‐Castillo. Bioinformatics perspectives on transcriptomics: A comprehensive review of bulk and single‐cell RNA sequencing analyses. Quantitative Biology, 2025. https://doi.org/10.1002/qub2.78 ↩
-
Maryam Kalantari-Dehaghi, Neda Ghohabi-Esfahani, Modjtaba Emadi-Baygi. From bulk RNA sequencing to spatial transcriptomics: a comparative review of differential gene expression analysis methods. Human Genomics, 2025. https://doi.org/10.1186/s40246-025-00884-w ↩
-
Lin Yang, Jin Wang, Jennifer Altreuter, et al. Tutorial: integrative computational analysis of bulk RNA-sequencing data to characterize tumor immunity using RIMA. Nature Protocols, 2023. https://doi.org/10.1038/s41596-023-00841-8 ↩
-
Zehua Zeng, Yuqing Ma, Lei Hu, et al. OmicVerse: a framework for bridging and deepening insights across bulk and single-cell sequencing. Nature Communications, 2024. https://doi.org/10.1038/s41467-024-50194-3 ↩
-
Ilias Moutsopoulos, Eleanor C Williams, Irina I Mohorianu. bulkAnalyseR: an accessible, interactive pipeline for analysing and sharing bulk multi-modal sequencing data. Briefings in Bioinformatics, 2022. https://doi.org/10.1093/bib/bbac591 ↩
-
Elena A. Pudova, Vladislav S. Pavlov, Zulfiya G. Guvatova, et al. Machine Learning Models for Cancer Research: A Narrative Review of Bulk RNA-Seq Applications. International Journal of Molecular Sciences, 2025. https://doi.org/10.3390/ijms262412081 ↩
-
Josh Loecker, Brandt Bessell, Bhanwar Lal Puniya, et al. AutoRNAseq: Automated Bulk RNA-seq Analysis Pipeline. 2026. https://doi.org/10.64898/2026.04.21.719844 ↩
-
Abdullah Al Mohit, Niher Ranjan Das, Arushi Jain, et al. Streamline Protocol for Bulk‐RNA Sequencing: From Data Extraction to Expression Analysis. Current Protocols, 2026. https://doi.org/10.1002/cpz1.70304 ↩
Pothos builds longitudinal molecular profiles of individuals: whole-genome sequencing, single-cell RNA sequencing, and plasma proteomics, delivered as a detailed report, every data file, and stored cells. Build your profile.