Skip to main content

Download and align RNA Seq files

This tutorial shows you how to download and align RNA Seq data from GEO using the Nextflow pipelines. All you need to have is a installation on conda/mamba.
Author

Maximilian Heeg

Published

September 9, 2026

Create a nextflow conda environment

If you already have a working conda installation, you can create a new environment with the following command: mamba create -n nextflow nextflow -c bioconda. Note that if you are using conda instead of the much faster mamba package manager, you need to repace mamba with conda. To activate the environment run conda activate nextflow.

Downlod the RNA Seq data: fastq files

Nextflow provides a pipeline that automatically download the data from GEO: https://nf-co.re/fetchngs. In this example, we will download files from GSE198874. On the bottom of that page, you can see a link SRA Run Selector. Click on that. On the next page click on Accession List to download the file. Save it! Next, on you computer (I use TSCC), create a directory for you project. e.g. mkdir MY_EXCITING_PROJECT && cd MY_EXCITING_PROJECT. Within that, create a folder where we download the fastq files. E.g. mkdir 01_download_fastq. To run nextflow on the TSCC, we need to create a config file to tell the programm which queues to use. Eg home-yeo or condo. Create a file using vim called nextflow.config with the following content:

process {
    executor = 'pbs'
    queue = 'home-yeo'
}
singularity.cacheDir = '/home/mheeg/scratch/nextflow/singularity'

The singularity.cacheDir is optional.

Let’s start the pipeline and download the files:

# activate the conda environment
conda activate nextflow

# start the pipeline
nextflow  run nf-core/fetchngs\
    --input  01_download_fastq/SRR_Acc_List.txt\
    --outdir 01_download_fastq\
    -profile singularity

Depending on the number of samples and the internet speed, this might take a while.

Align the samples using the nextflow pipeline

Using the fastq files, we can run the rnaseq pipeline to align the samples. Let’s create a new subfolder for that anaylsis: mkdir 02_RNA-Seq. Within that folder, we need to create a samplesheet. Luckily, we can start by copying a template from the fetchngs pipeline that we ran above: cp 01_download_fastq/samplesheet/samplesheet.csv 02_RNA-Seq/ Use your favorite editor (vim, what else?) to modify the file: It needs four columns: sample, fastq_1, fastq_2, and strandedness. After editing it, mine looked as follows:

sample,fastq_1,fastq_2,strandedness
ARKO 1,01_download_fastq/fastq/SRX14493513_SRR18358797_1.fastq.gz,01_download_fastq/fastq/SRX14493513_SRR18358797_2.fastq.gz,auto
ARKO 2,01_download_fastq/fastq/SRX14493514_SRR18358796_1.fastq.gz,01_download_fastq/fastq/SRX14493514_SRR18358796_2.fastq.gz,auto
ARKO 3,01_download_fastq/fastq/SRX14493515_SRR18358795_1.fastq.gz,01_download_fastq/fastq/SRX14493515_SRR18358795_2.fastq.gz,auto
NTC 1,01_download_fastq/fastq/SRX14493516_SRR18358794_1.fastq.gz,01_download_fastq/fastq/SRX14493516_SRR18358794_2.fastq.gz,auto
NTC 2,01_download_fastq/fastq/SRX14493517_SRR18358793_1.fastq.gz,01_download_fastq/fastq/SRX14493517_SRR18358793_2.fastq.gz,auto
NTC 3,01_download_fastq/fastq/SRX14493518_SRR18358792_1.fastq.gz,01_download_fastq/fastq/SRX14493518_SRR18358792_2.fastq.gz,auto

Next, we can run the pipeline. This performs QC, trimming and alignment. Make sure that you have the nextflow conda environment still activated.

nextflow run nf-core/rnaseq \
    --input 02_RNA-Seq/samplesheet.csv\
    --genome GRCm38\
    -profile singularity\
    --igenomes_base /home/mheeg/projects/igenomes/\
    --outdir 02_RNA-Seq -resume

The --igenomes_base is optional, but it is a lot faster if you don’t need to download the genome every time. Once this is done, we can import the counts into DESeq2.

Basic analysis in DESeq2

Importing the data into R is quite easy. One of the outputs of the pipeline is an rds file with the counts data. The file can be found in the follwoing location: ./02_RNA-Seq/star_salmon/salmon.merged.gene_counts.rds. For the analysis, you don’t need to use the supercomputer anymore. Any laptop should be fast enough. So copy that file to your computer. We can then import that, make some minor adjustments and finally run DESeq2.

#| message: false
#| warning: false
suppressPackageStartupMessages({
  library(ggplot2)
  library(DESeq2)
})

# Set a custom theme for the plots, not requiered, but it looks better
theme_max <- function(base_size = 12, base_family="Avenir Next"){ 
    theme_bw(base_size = base_size, base_family = base_family) %+replace%    #replace elements we want to change
    theme(
      panel.grid = element_blank(), 
      strip.background = element_rect(fill = "#EEEEEE", colour = NA)
    )
}
theme_set(theme_max())

# Setup the dds object
# Import the summarized Experiment
gse <- readRDS("salmon.merged.gene_counts.rds")
# Lets remove the replicate from the sample name
# we will use this for the desgin in DESeq2
gse$condition <- sub("_.*", "",gse$names)
gse$replicate <- sub(".*_", "",gse$names)
# Some 'count' have small rounding errors (eg 10.0001)
# We need to convert that to integers for DESeq2
assay(gse, 'counts') <- as.matrix(round(assay(gse, 'counts')))
# Create the DESeq2 dataset.
dds <- DESeqDataSet(gse, ~condition)

dds <- DESeq(dds)

PCA plots

#| fig-cap: PCA plots of the dataset
#| label: fig-pca-lots
#| fig-subcap: 
#|     - colored by condition
#|     - colored by replicate
#| layout-ncol: 2
#| message: false
vsd <- vst(dds, blind = FALSE)
plotPCA(vsd, intgroup="condition") + theme_max()
plotPCA(vsd, intgroup="replicate") + theme_max()

DE-genes

#| label: tbl-de-genes
#| tbl-cap: "DE genes"

res <- results(dds, saveCols = "gene_name")
knitr::kable(head(res[order(res$padj),], 20))

Read Introduction to DESeq2 for more information about RNA Seq analysis.