基于log2(CPM)画3DPCA的R语言代码
时间: 2024-03-04 20:49:33 浏览: 167
code7uj_2DPCA_matlab_
以下是基于log2(CPM)画3DPCA的R语言代码:
```
# 加载所需的库
library(DESeq2)
library(plotly)
# 读取数据
counts <- read.table("counts.txt", header=TRUE, row.names=1, check.names=FALSE)
colData <- read.table("colData.txt", header=TRUE, row.names=1, check.names=FALSE)
dds <- DESeqDataSetFromMatrix(countData=counts, colData=colData, design=~group)
dds <- DESeq(dds)
# 计算CPM
cpm <- counts(dds, normalized=TRUE) / colSums(counts(dds)) * 1e6
# 取对数并进行3DPCA
cpm.log <- log2(cpm + 1)
pca <- prcomp(cpm.log, scale=TRUE)
pc1 <- pca$x[,1]
pc2 <- pca$x[,2]
pc3 <- pca$x[,3]
# 绘制3DPCA图
plot_ly(x=pc1, y=pc2, z=pc3, color=colData$group, type="scatter3d", mode="markers")
```
阅读全文