Systems Biology
RNA-seq data analysis
III. Quantification &
Differential expression
April 19, 2022
Bioinformatics & Genomics Lab
Department of Life Science
Hanyang University
Sang-Ho Yoon
Bioinformatics & Genomics, the BIG lab.
RNA-seq analytic pipeline
Bioinformatics & Genomics, the BIG lab.
3
Gene/isoform quantification
- Two different levels of expression in RNA-seq analysis
- Gene-level quantification; assign all reads to a gene ignoring isoforms
🡪 FeatureCounts, htseq-count, etc.
- Transcript/isoform-level quantification; assign reads to individual RNA transcripts
🡪 RSEM, BitSeq, Cufflinks, etc.
uses probabilistic models
Bioinformatics & Genomics, the BIG lab.
4
Gene/isoform quantification
Gene-level quantification
- Gene locus is a union structure of its isoforms
- Directly count all reads aligned to exons of a gene 🡪 simple task w/ some issues
Isoform-level quantification
- Isoforms often share multiple exonic structures with each other
- Reads should be assigned to one of isoforms 🡪 probabilistic models
Incomplete annotation
MAPQ or randomly assign
Nascent transcript
Read strandedness
Bioinformatics & Genomics, the BIG lab.
5
Gene/isoform quantification
Quantification metrics
- The number of assigned reads are proxy of expression level
- Read counts of a gene/transcript are influenced by numerous factors
*Overall sequencing depth (total mapped reads)
*length of genes/transcripts
expression should be normalized with total mapped reads
and length of gene / transcript
Bioinformatics & Genomics, the BIG lab.
6
Gene/isoform quantification
Quantification metrics
- RPKM (Reads Per Kilobase of exons per Million mapped reads) for single-end
- FPKM (Fragments Per Kilobase of exons per Million mapped reads) for paired-end
1. Count the total reads in a sample and divide by 1,000,000
🡪 “per million” scaling factor
2. Divide the read counts by the “per million” scaling factor
🡪 Reads per Million (RPM); counts normalized by sequencing depth
3. Divide RPM by the length of a gene in kilobases
🡪 RPKM (1 RPKM ~ 1 copy in a cell)
*The sum of RPKM-/FPKM-normalized reads in each sample is different
- Inter-sample quantile normalization should be performed to compare expressions
Bioinformatics & Genomics, the BIG lab.
7
Gene/isoform quantification
Quantification metrics
- TPM (Transcripts Per kilobase per Million mapped reads)
- Based on the observation that approx. 1 million transcripts are found in a cell
- TPM calculates relative expression values comparable across different samples
1. Divide the read counts by the length of each transcript in kilobases
🡪 RPK, reads per kilobase
2. Count all RPK values in a sample and divide by 1,000,000
🡪 “per million” scaling factor
3. Divide RPK values by the “per million” scaling factor
🡪 TPM
Pop-up quiz:
Fill in these values to get an extra point ☺
Bioinformatics & Genomics, the BIG lab.
8
RNA-seq data analysis: Gene-level quantification
Connect VPN and open your Shell
호스트: 166.104.118.161
포트 번호: 22
User: biguser
Password: biglab2428
1.
2.
3.
4.
P
Bioinformatics & Genomics, the BIG lab.
9
Connect biglab1 and navigate into your working space
P
$ ssh biglab1
$ cd systems_biology_2022/YOUR_DIRECTORY
$ mkdir session_07
$ cd session_07
mkdir A = make directory named A
cd A = enter the directory A
RNA-seq data analysis: Gene-level quantification
Bioinformatics & Genomics, the BIG lab.
10
P
RNA-seq data analysis: Gene-level quantification
ex) featureCounts -a genes.gtf -p -o output.txt input.bam
(reference or assembled GTF)
(output)
(input)
(-p: Input is paired-end reads. Count fragments rather than reads)
Bioinformatics & Genomics, the BIG lab.
11
P
RNA-seq data analysis: Gene-level quantification
ln –s ~/systems_biology_2022/TA/__human_transcriptome__/gencode.v34.gtf
ln –s ~/systems_biology_2022/TA/session_7/Naive_CD8_T_cells_rep1/star/Naive_CD8_T_cells_rep1_1_Aligned.sortedByCoord.out.bam
Bioinformatics & Genomics, the BIG lab.
12
P
mkdir 7_featureCounts
cd 7_featureCounts
featureCounts -p -a ../gencode.v34.gtf \
-o Naive_CD8_T_cells_rep1.txt \
../Naive_CD8_T_cells_rep1_1_Aligned.sortedByCoord.out.bam
RNA-seq data analysis: Gene-level quantification
Bioinformatics & Genomics, the BIG lab.
13
P
RNA-seq data analysis: Gene-level quantification
Bioinformatics & Genomics, the BIG lab.
14
P
RNA-seq data analysis: Gene-level quantification
less Naive_CD8_T_cells_rep1.txt.summary
Reads mapped to genes
Bioinformatics & Genomics, the BIG lab.
15
P
RNA-seq data analysis: Gene-level quantification
less Naive_CD8_T_cells_rep1.txt
Gene ID
Chr.
(2 exons)
Start
(2 exons)
End
(2 exons)
strand
Gene length
Read counts
We want to collect this values for every genes in this file
Bioinformatics & Genomics, the BIG lab.
16
P
RNA-seq data analysis: Gene-level quantification
ln –s ~/systems_biology_2022/TA/session_7/Naive_CD8_T_cells_rep2/star/Naive_CD8_T_cells_rep2_1_Aligned.sortedByCoord.out.bam
ln –s ~/systems_biology_2022/TA/session_7/Naive_CD8_T_cells_rep3/star/Naive_CD8_T_cells_rep3_1_Aligned.sortedByCoord.out.bam
ln –s ~/systems_biology_2022/TA/session_7/Switched_memory_B_cells_rep1/star/Switched_memory_B_cells_rep1_1_Aligned.sortedByCoord.out.bam
ln –s ~/systems_biology_2022/TA/session_7/Switched_memory_B_cells_rep2/star/Switched_memory_B_cells_rep2_1_Aligned.sortedByCoord.out.bam
ln –s ~/systems_biology_2022/TA/session_7/Switched_memory_B_cells_rep3/star/Switched_memory_B_cells_rep3_1_Aligned.sortedByCoord.out.bam
Bioinformatics & Genomics, the BIG lab.
17
P
#replicate2
featureCounts -p -a ../gencode.v34.gtf \
-o Naive_CD8_T_cells_rep2.txt \
../Naive_CD8_T_cells_rep2_1_Aligned.sortedByCoord.out.bam
#replicate3
featureCounts -p -a ../gencode.v34.gtf \
-o Naive_CD8_T_cells_rep3.txt \
../Naive_CD8_T_cells_rep3_1_Aligned.sortedByCoord.out.bam
RNA-seq data analysis: Gene-level quantification
Bioinformatics & Genomics, the BIG lab.
18
P
#replicate1
featureCounts -p -a ../gencode.v34.gtf \
-o Switched_memory_B_cells_rep1.txt \
../Switched_memory_B_cells_rep1_1_Aligned.sortedByCoord.out.bam
#replicate2
featureCounts -p -a ../gencode.v34.gtf \
-o Switched_memory_B_cells_rep2.txt \
../Switched_memory_B_cells_rep2_1_Aligned.sortedByCoord.out.bam
#replicate3
featureCounts -p -a ../gencode.v34.gtf \
-o Switched_memory_B_cells_rep3.txt \
../Switched_memory_B_cells_rep3_1_Aligned.sortedByCoord.out.bam
RNA-seq data analysis: Gene-level quantification
Bioinformatics & Genomics, the BIG lab.
19
P
RNA-seq data analysis: Gene-level quantification
cd ..
cp /home/biguser/systems_biology_2022/TA/src/1.readcount.featureCounts.py .
An in-house python script summarizing read counts
Bioinformatics & Genomics, the BIG lab.
20
P
RNA-seq data analysis: Gene-level quantification
python 1.readcount.featureCounts.py \
7_featureCounts/Naive_CD8_T_cells_rep1.txt,7_featureCounts/Naive_CD8_T_cells_rep2.txt,7_featureCounts/Naive_CD8_T_cells_rep3.txt,Switched_memory_B_cells_rep1.txt,Switched_memory_B_cells_rep2.txt,Switched_memory_B_cells_rep3.txt \
immune_cells.txt
Comma-separated input
Bioinformatics & Genomics, the BIG lab.
21
P
RNA-seq data analysis: Gene-level quantification
cp /home/biguser/systems_biology_2022/TA/src/2.add_gene_name.py .
Gene ID > Name dictionary
Exclude “turned-off” genes
Bioinformatics & Genomics, the BIG lab.
22
P
RNA-seq data analysis: Gene-level quantification
python 2.add_gene_name.py immune_cells.txt immune_cells.symbols.txt
input
output
Gene name & ID
Bioinformatics & Genomics, the BIG lab.
RNA-seq analytic pipeline
Bioinformatics & Genomics, the BIG lab.
24
Differential Expression Analysis
DE analysis
- Statistical analysis to discover quantitative changes in gene expression levels
- Different experimental groups have distinct gene expression landscape
e.g., diseased vs. healthy blood, vaccinated vs. unvaccinated, etc.
- DE analysis tries to identify genes expressed at different levels between groups
*statistically
- Differentially expressed gene (DEG) analysis
🡪 DESeq2, EdgeR, etc.
- Differentially expressed transcript (DET) analysis
🡪 Bitseq, Cuffdiff, etc.
1) Normalization of sequencing libraries
2) Statistical test
Bioinformatics & Genomics, the BIG lab.
25
Differential Expression Analysis
1) Normalization of sequencing libraries
- However, these values violate statistical assumptions in DEG analysis tools
- FPKM/TPM describes expression of genes in general
FPKM/TPM handle this issue
🡪 read count values should be normalized with a different approach
Within condition variance
between condition variance
Condition A
Condition B
Bioinformatics & Genomics, the BIG lab.
26
DEG analysis using DESeq2
1) Normalization of sequencing libraries
An outlier
Averaged expression of Gene C = (33+55+200)/3 = 96
Averaged expression of Gene C = e4.3 = 73.7
*Log-transformed data is insensitive to outliers
These average values are called
“Geometric averages”
Bioinformatics & Genomics, the BIG lab.
27
DEG analysis using DESeq2
1) Normalization of sequencing libraries
Un-expressed genes are removed
Exclude infinity values
Step4. Subtract the average log value from the log(counts)
-1.7
-1.7
-1.7
-4.3
-4.3
-4.3
-1.0
0.1
0.8
-0.8
-0.3
1.0
Step5. Calculate median values for each sample
-0.9
-0.1
0.9
Step6. Convert them into “normal numbers”
e-0.9 = 0.4
e-0.1 = 0.9
e0.9 = 2.5
Final scaling factors
*NOTE: median also mitigates outliers
Bioinformatics & Genomics, the BIG lab.
28
DEG analysis using DESeq2
1) Normalization of sequencing libraries
Step6. Convert them into “normal numbers”
e-0.9 = 0.4
e-0.1 = 0.9
e0.9 = 2.5
Final scaling factors
/0.4
/0.9
/2.5
/0.4
/0.9
/2.5
/0.4
/0.9
/2.5
Bioinformatics & Genomics, the BIG lab.
29
DEG analysis using DESeq2
2) Statistical test
- Shrinkage for dispersion estimates is performed to denoise
Shrunken variances
Condition A
Condition B
Within condition variance
between condition variance
- Data fitting using a generalized linear model
Shrink dispersion for each gene
Bioinformatics & Genomics, the BIG lab.
30
DEG analysis using DESeq2
2) Statistical test
- RNA-seq follows negative binomial distribution (overdispersion problem)
Microarray data follows Poisson distribution;
mean = variance
In RNA-seq, variance is much higher than mean
- DESeq2 uses a negative binomial (NB) model to fit the observed read counts
- Calculate P-values for log2 fold changes using Wald test
- Multiple testing correction using Benjamini-Hochberg procedure
Bioinformatics & Genomics, the BIG lab.
31
P
RNA-seq data analysis: DEG analysis using DESeq2
Read count table
Label table
Sample Group
Sample1 cond1
Sample2 cond1
Sample3 cond2
Sample4 cond2
Sample1 Sample2 Sample3 Sample4
Gene1 1 5 7 4
Gene2 0 3 0 0
*Should be in same order
Bioinformatics & Genomics, the BIG lab.
32
P
RNA-seq data analysis: DEG analysis using DESeq2
Or you can make using Excel
cp /home/biguser/systems_biology_2022/TA/src/3.mklabel_DESeq2.py .
Bioinformatics & Genomics, the BIG lab.
33
P
RNA-seq data analysis: DEG analysis using DESeq2
python 3.mklabel_DESeq2.py immune_cells.symbols.txt
ll
Bioinformatics & Genomics, the BIG lab.
34
P
RNA-seq data analysis: DEG analysis using DESeq2
Rscript DESeq2.R <count table> <label table> <outprefix> \
<group of interest> <background group>
labelTable.txt
Group of interest
Background group
Rscript DESeq2.R readCountTable.txt labelTable.txt output cond1 cond2
Sample Group
Sample1 cond1
Sample2 cond1
Sample3 cond2
Sample4 cond2
/home/biguser/systems_biology_2022/TA/src/DESeq2.R
Bioinformatics & Genomics, the BIG lab.
35
P
RNA-seq data analysis: DEG analysis using DESeq2
cp /home/biguser/systems_biology_2022/TA/src/DESeq2.R .
1. Read tables
2. Run DESeq2
3. Draw MA plot
4. Write DEG stats
Bioinformatics & Genomics, the BIG lab.
36
P
RNA-seq data analysis: DEG analysis using DESeq2
Rscript DESeq2.R immune_cells.symbols.txt \
immune_cells.symbols.label.txt \
immune_cells_deseq2.txt \
Naive_CD8_T_cells \
Switched_memory_B_cells
ex)
Rscript DESeq2.R <count table> <label table> <outprefix> \
<group of interest> <background group>
- Run this command line to perform DESeq2 analysis
Bioinformatics & Genomics, the BIG lab.
37
P
RNA-seq data analysis: DEG analysis using DESeq2
immune_cells_deseq2.txt
Mean expression of all samples
Standard error
Wald statistic
Nominal
p-value
BH adjusted p-value
Multiple testing correction
T cell-specific genes
B cell-specific genes
...
Bioinformatics & Genomics, the BIG lab.
38
P
RNA-seq data analysis: DEG analysis using DESeq2
immune_cells_deseq2.pdf
MA-plot:�log fold change (M) on Y-axis�mean expression (A) on X-axis
Bioinformatics & Genomics, the BIG lab.
39
Homework
- From the results we have produced today
1) Summarize each step and explain briefly
2) Command lines & your working directory (use “pwd” command)
3) Screenshot of expression table (top n lines)
4) Screenshot of the final DESeq2 result table and MA plot
5) Select one marker gene for each cell type and briefly summarize its functions
e.g., CD8B: T cell surface marker, its function is ~
IGHA2: immunoglobulin heavy chain usu. expressed in plasma cells ~
ssh biglab1