RNASEQ分析入门笔记10-差异分析与绘制热图(命令集合) 发表于 2018-10-05 | 分类于 编程语言 | | 热度 °C 一、差异分析1234567891011121314151617181920212223242526272829setwd("E:/R/My Analysis/") # 设置工作目录getwd() # 查看当前工作目录dir() # 查看工作目录下的文件library(DESeq2) # 载入DESeq2data <- read.delim("clipboard",header=T,row.names=1) # 从剪贴板载入要分析的数据countData <- datacondition <- factor(c("S","S","R","R")) # 定义condition,根据具体情况作相应改变colData <- data.frame(row.names=colnames(countData),condition)condition # 查看conditioncolData # 查看colData是否与预期一致dds <- DESeqDataSetFromMatrix(countData,DataFrame(condition),design= ~ condition) # 构建dds矩阵head(dds) # 查看dds矩阵的前端dds2 <- DESeq(dds) # 对dds矩阵进行Normalizeres <- results(dds2) # 使用results()函数获取结果,并赋值给ressummary(res) # 查看res矩阵的总结信息table(res$padj<0.05) # 取padj小于0.05的数据,作为第一个checkpointres <- res[order(res$padj),] # 按照padj的大小将res重新排列diff <- subset(res,padj < 0.05 & (log2FoldChange >1 | log2FoldChange < -1)) # 获取padj小于0.05,表达倍数取以2为对数后绝对值大于1的差异表达基因nrow(diff) # 查看行数,作为第二个checkpointresdata <- merge(as.data.frame(diff),as.data.frame(counts(dds,normalize=FALSE)),by="row.names",sort=FALSE) # 合并文件write.csv(resdata,file="diff_SR.csv") # 结果输出为.CSV文件 二、绘制热图12345data <- read.delim("clipboard",header=T,row.names=1) # 从剪贴板载入数据col_anno=data.frame(PT=c("S","S","S","S","S","S","S","S","S","S","S","S","R","R","R","R","R","R","R","R","R","R","R"),row.names=colnames(data)) # 定义分组信息,具体情况具体设置,本例是对列进行分组,前12列为S,后11列为Rpheatmap(data,scale="row",annotation_col=col_anno,color=colorRampPalette(c("navy","white","firebrick3"))(50)) # 绘制热图 本文作者:括囊无誉 本文链接: RNASEQ/RNASEQ 差异分析与绘制热图/ 版权声明: 本博客所有文章均为原创作品,转载请注明出处! ------ 本文结束 ------ 坚持原创文章分享,您的支持将鼓励我继续创作! Donate WeChat Pay