[英]Confidence intervals in PCA by group with prcomp
我正在進行 RNA-seq 分析,我對哪些基因驅動基因表達的組織特異性變異感興趣。 PCAs 在 RNA-seq 分析中很常見,但大多數軟件包(例如 DESeq2)僅將其用於 2D plot。 因此,我使用了 prcomp 和 fviz_pca_ind 來生成我的 2D plot,這樣我可以在之后進行更進一步的分析。 但是,由於輸入數據結構,我似乎無法將我的分組信息(即組織)包含在我的 prcomp object 中,因此無法對我的樣本進行顏色編碼或在我的組周圍生成置信區間。
套餐:
library(ggplot2)
library(factoextra)
library(Deseq2)
我從 DESeq2 object 的方差穩定轉換開始(抱歉,這是多長時間......):
即使是子集,數據集也太大了-這是一個鏈接(希望這是可以接受的) https://drive.google.com/file/d/1Gtw5GUCAyBVr3MI6CpgsF4n81KZuq8WI/view?usp=sharing
還有我的 PCA 代碼(這實際上只是 DESeq2 中的 function)
####################################################################################################
# Principle component analysis - PRComp
####################################################################################################
# set number of genes to include in PCA
ntop = 500
# calculate the variance for each gene
rv <- rowVars(assay(vst))
# select the ntop genes by variance
select <- order(rv, decreasing=TRUE)[seq_len(min(ntop, length(rv)))]
# perform a PCA on the data in assay(x) for the selected genes
tissue_pca <- prcomp(t(assay(vst)[select,]))
還有我的可視化代碼:
# Visualize samples on PC1 and PC2
fviz_pca_ind(tissue_pca,
# col.var = ,
palette = cbPalette,
ellipse.type = "confidence",
repel = TRUE,
mean = FALSE)
產生這個:
正如您將在 prcomp object 中看到的,沒有分組信息。 關於如何 1) 將此信息包含在 prcomp object 或 2) 將此信息合並到圖形代碼中的任何想法?fa
您的 dput 似乎有點大,但這是一個可重復的示例 - 只需添加habillage
和 colors,您對 go 就很好了。
suppressPackageStartupMessages(invisible(
lapply(c("DESeq2", "factoextra"),
require, character.only = TRUE)))
set.seed(123)
dds <- makeExampleDESeqDataSet(n=5e3, betaSD=.8)
dds$group <- gl(4,3, labels = paste0("Group_", LETTERS[1:4]))
counts(dds)[, 1:3] <- as.integer(counts(dds)[, 1:3] *
stats::runif(1.5e4, 0.8, 1.2))
vst <- vst(dds)
ntop = 500
rv <- rowVars(assay(vst))
select <- order(rv, decreasing=TRUE)[seq_len(min(ntop, length(rv)))]
tissue_pca <- prcomp(t(assay(vst)[select,]))
fviz_pca_ind(tissue_pca,
habillage = vst$group,
palette = c("blue", "red", "cyan", "magenta"),
ellipse.type = "confidence",
repel = TRUE,
mean = FALSE)
由reprex package (v0.3.0) 創建於 2020 年 8 月 5 日
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.