setwd('/media/shen/bdaca657-45dc-4eb7-a8de-667de599fcbd/jjc/2019-1-18-all-df2')
library("DESeq2")
directory <-'/media/shen/bdaca657-45dc-4eb7-a8de-667de599fcbd/jjc/2019-1-18-all-df2'
directory
sampleFiles <- grep("raw",list.files(directory),value=TRUE)
sampleFiles
sampleCondition <- c("con","con","KO","KO","con","con","KO","KO","con","con","KO","KO")
sampleCondition
samplecelltype<- c("Pac","Pac","Pac","Pac","RS","RS","RS","RS","EF","EF","EF","EF")
sampleTable <- data.frame(sampleName = sampleFiles,fileName = sampleFiles,condition = sampleCondition,celltype= samplecelltype)
sampleTable
dds <- DESeqDataSetFromHTSeqCount(sampleTable = sampleTable,directory = directory,design= ~ condition)
dds
dds <- dds [ rowSums(counts(dds)) > 1, ]
#PCA#
rld<-rlog(dds
plotPCA(rld)
pcaData <- plotPCA(rld, intgroup=c("condition","celltype"), returnData=TRUE)
percentVar <- round(100 * attr(pcaData, "percentVar"))
ggplot(pcaData, aes(PC1, PC2, color=celltype, shape=condition)) +
geom_point(size=3) +
xlab(paste0("PC1: ",percentVar[1],"% variance")) +
ylab(paste0("PC2: ",percentVar[2],"% variance")) +
coord_fixed()+scale_shape_manual(values = c("con"="\23","KO"="\2"))
##在每一个点上添加样本名称##
library(ggplot2)
p <- plotPCA(rld)
p <- p + geom_text(aes_string(x = "PC1", y = "PC2", label = "name"), color = "black",size = 4)
##name可单独赋值 比如 name = c("PN1","","","","","","","","","","","PN1","","PN1","PN1","PN1","PN1","","","")###
print(p)