使用工具
fastp(質控), hisat2(比對), samtools(sam文件轉bam文件), featureCounts(count計數), DESeq2(差異分析)
環境配置
使用conda配置環境, 安裝fastp, hisat2, samtools, subread。featureCounts整合在subread中。DESeq2為R包。使用DESeq2進行差異分析前的流程都在linux環境下進行,DESeq2在R環境下運行。
分析流程
- 拿到數據后首先需要對數據進行質控,這里使用fastp。這篇文章介紹的比較清楚:[鏈接1]。
- 使用hisat2進行序列比對,輸入文件為測序數據fastq(gz)文件,輸出文件為sam文件,額外需要基因組索引文件,需要到hisat2官網[鏈接2]下載。
hisat2 -p 8 -x ref/grch38/genome -1 sample_1.fq.gz -2 sample_2.fq.gz -S sample.sam --summary-file sample.hisat2.summary
# -p: 線程數
# -x: 基因組索引前綴。所下的基因組索引為多個文件,索引前綴到genome為止。
# -1/-2: fastq輸入文件。當輸入為單端測序時使用-U 指定輸入。單端或雙端的輸入都可使用逗號分隔輸入多個樣本,或使用多次-1 -2 / -U 指定多個輸入。e.g.: -U sample1.fq.gz,sample2.fq.gz -U sample3.fq.gz
# -S: 輸出sam文件路徑。
# --summary-file: 生成summary文件。
- 轉換成bam文件
sam文件為通用的比對數據存儲格式,記錄了reads的比對信息,其內容為純文本,因此大小通常十分大。為解決這個問題,sam文件的壓縮格式bam文件被設計了出來,使文件大小被大大壓縮。這里通過samtools進行bam文件轉換:
samtools sort -@ 8 -o sample.bam smaple.sam
# sort: 進行排序
# -@: 線程數
# -o: 輸出bam文件
# 最后一項為輸入文件
- 使用featureCounts進行計數,需要基因組注釋文件,可在gencode網站下載[鏈接3]。
featureCounts -p -T 8 -a ref/annotation.gtf.gz -o featurecounts.out sample1.bam sample2.bam ...
# -p: 此參數雙端測序時使用
# -T: 線程數
# -a: 基因組注釋文件
# -o: 輸出文件
# 最后為bam文件,可指定多個輸入
- 使用DESeq2進行差異分析
差異分析在R環境中進行。
1) 構建dds對象
dds <- DESeqDataSetFromMatrix(countData, colData, design, tidy = False, ignoreRank = False)
# countData: 非負整數count矩陣,count數據從第一列開始,列名為樣本名,行名可指定為gene id。
# colData: 行名為countData的列名且至少1列的DataFrame,每一列為樣本分組信息和其他批次信息。
# design: 指定colData中的分組變量,e.g.: design = ~batch+type (batch和type均為colData的列名)。DESeq2將默認使用最后一個分組變量進行差異分析。
# tidy: 邏輯變量,countData第一列是否為行名。
# ignoreRank: use of this argument is reserved for DEXSeq developers only. Users will immediately encounter an error upon trying to estimate dispersion using a design with a model matrix which is not full rank.
Note: countData列名和colData行名必須相同。
2) 差異分析---differential experssion analysis
dds_deseq <- DESeq(dds)
這一步將經過3步分析:
1. estimation of size factors
2. estimation of dispersion
3. Negative Binomial GLM fitting and Wald statistics
3) 提取結果
res <- results(dds_deseq, contrast = c("type","treatment","untreatment"))
# contrast: 3個元素的向量,第一個元素: colData中的分組列名,第二個元素: 計算log2FC時的分子項,第三個元素: 計算log2FC時的分母項。
res <- res[order(res$padj),]
# 根據padj排序
summary(res)
# 查看summary
?
4) DEseq標準化數據
除了進行差異分析外,有時我們還需要直接得到標準化的表達矩陣,現有的標準化方法有CPM、TPM、RPKM/FPKM、TMM、DESeq標準化等。這篇文章[鏈接4]詳細介紹了各標準化的適用范圍以及DESeq標準化的計算方法。
代碼:
#創建dds對象
dds <- DESeqDataSetFromMatrix(countData, colData, design)
#計算量化因子
dds_SF <- estimateSizeFactors(dds)
#進行標準化
normalized_counts <- counts(dds_SF, normalized=TRUE)
另外DESeq提供了其他兩種標準方法VST和rlog,但目前對這兩種標準化方法的理解還不夠深入。
兩種方法的差異及如何選擇:
For genes with high counts, both the VST and the rlog will give similar result to the ordinary log2 transformation of normalized counts. For genes with lower counts, however, the values are shrunken towards a middle value. The VST or rlog-transformed data then become approximately homoskedastic (more flat trend in the meanSdPlot), and can be used directly for computing distances between samples, making PCA plots, or as input to downstream methods which perform best with homoskedastic data.
Which transformation to choose?
The VST is much faster to compute and is less sensitive to high count outliers than the rlog. The rlog tends to work well on small datasets (n < 30), potentially outperforming the VST when there is a wide range of sequencing depth across samples (an order of magnitude difference). We therefore recommend the VST for medium-to-large datasets (n > 30).
具體介紹見這里[鏈接5]
兩種轉換方法可分別用vst和rlog函數實現:
vsd <- vst(dds, blind=FALSE)
rld <- rlog(dds, blind=FALSE)