前两天我向大家推了16s做差异分析的两个包(没有看的请点击下面链接):
差异做出来了如何展示,也是一个值得思考的问题,所以今天我们就尝试一下热图,看看效果:
#首先安装这个包
#source("http://bioconductor.org/biocLite.R")
#biocLite("edgeR")
#install.packages("rlang")
#install.packages("vegan")
library("gplots")
library("RColorBrewer")
library(edgeR)
library("ggplot2")
library("vegan")
setwd("E:/Shared_Folder/HG_usearch_HG")
#读入mapping文件
design =read.table("map_lxdjhg.txt", header=T, row.names= 1,sep="\t")
#读取OTU表,这里我选择的是整个otu表格,但是一般没有必要全部做差异的啊,相对丰度高的做做就可以了
otu_table =read.delim("otu_table.txt", row.names= 1,sep="\t",header=T,check.names=F)
#本步骤采用otu。table基于抽平后的qiime文件,去掉第一行,和第二行首行的#符号,即可导入成功。
#过滤数据并排序
idx =rownames(design) %in% colnames(otu_table)
sub_design =design[idx,]
count =otu_table[, rownames(sub_design)]
#转换原始数据为百分比,
norm =t(t(count)/colSums(count,na=T)) * 100 # normalization to total 100
# create DGE list
d = DGEList(counts=count,group=sub_design$SampleType)#count是一个数据框,$samples是第二个数据框
d =calcNormFactors(d)
#生成实验设计矩阵
design.mat =model.matrix(~ 0 + d$samples$group)
colnames(design.mat)=levels(design$SampleType)
colnames(design.mat)
d2 =estimateGLMCommonDisp(d, design.mat)
d2 =estimateGLMTagwiseDisp(d2, design.ma