RNA-seq下游分析之PCA画图

RNA-seq下游分析之 PCA图_欧阳火火的博客-CSDN博客

rm(list=ls())

mydata <- read.table("C:/Users/gao/Desktop/all.id.txt",header =TRUE,quote='\t',skip = 1)

smpleNames <- c('mesc_1','mesc_1','mesc_2','mesc_2','mesc_3','mesc_3','mesc_4','mesc_4','mesc_5','mesc_5','mesc_6','mesc_6','mesc_7','mesc_7','mesc_8','mesc_8')

names(mydata)[7:22] <- smpleNames

head(mydata)

countmatrix <- as.matrix(mydata[7:22])

rownames(countmatrix) <- mydata$Geneid

head(countmatrix)

save(countmatrix,file="expr.Rdata")

table2 <- data.frame(name = c('mesc_1','mesc_1','mesc_2','mesc_2','mesc_3','mesc_3','mesc_4','mesc_4','mesc_5','mesc_5','mesc_6','mesc_6','mesc_7','mesc_7','mesc_8','mesc_8'),condition = c('A','A','A','A','A','A','A','A','B','B','B','B','B','B','B','B'))

dds2 <- DESeqDataSetFromMatrix(countmatrix,colData=table2,design =~condition) 

dds2 <- dds[rowSums(counts(dds2)) > 1,]

head(dds2)

rld1<- rlog(dds2)

plotPCA(rld1, intgroup=c( "name","condition"))

library(ggplot2)

data1 <- plotPCA(rld1, intgroup=c("condition","name"), returnData=TRUE) 

percentVar1 <- round(100 * attr(data1, "percentVar"))

p1<- ggplot(data1, aes(PC1, PC2, color=name)) +

  geom_point(size=3) +

  xlab(paste0("PC1: ",percentVar[1],"% variance")) +

  ylab(paste0("PC2: ",percentVar[2],"% variance"))

p1


你可能感兴趣的:(RNA-seq下游分析之PCA画图)