1.读入文件
library(DESeq2)
rm(list=ls())
#读入文件并修改行列名
countdata <- read.table("./hhh/hhh_WT_matrix.out", header=TRUE, row.names=1) #导入数据
head(countdata)
image.png
colnames(countdata) <- c("hhh-1","hhh-2","hhh-3","WT_1","WT_2","WT_3") # 修改列名,
head(countdata)
image.png
2.构建分组信息
condition <- factor(c("hhh","hhh","hhh","WT","WT","WT")) # 赋值因子,即变量
sample_Data <- data.frame(sampleID=colnames(countdata), condition)
#设置因子,并确定顺序(一般突变体在后,这样最终结果是Mutant/WT)
sample_Data$condition=factor(sample_Data$condition,c("WT","hhh")) #设置分组顺序,最终差异结果是后面/前面,
sample_Data
image.png
3.构建DESeq2中的dds对象
dds<- DESeqDataSetFromMatrix(countData = countdata, colData =sample_Data, design = ~condition)
#4.差异分析
dds<-DESeq(dds)
5.获得各组的size factors
sizefactor<-sizeFactors(dds)
image.png
6.获得比较组
resultsNames(dds)#list the coefficients,获得比较组
image.png
7.提取差异结果 name根据前面resultsNames(dds)获得。
res<-results(dds,name="condition_hhh_vs_WT")
head(res)
image.png
8.合并前面的Raw reads counts
final_data=merge(as.data.frame(res),countdata,by="row.names",sort=FALSE)
head(final_data)
image.png
9.写入文件
write.table(final_data,"HAG704VSWT.out2.txt",sep="\t",quote=F,col.names = NA)
网友评论