读取文件就可以进行差异表达基因分析,替换文件名和分组名
需要注意:
1. 读取的count文件应该是整数矩阵

2. 分组文件格式

3. 应当注意分组文件列应该与count文件的行顺序一致
#每次开始之前必做的获取工作目录及更改工作目录,找文件一定要与文件名一模一样,带文件类型后缀
#之后就是读取count矩阵和分组文件
getwd()
genecounts<-read.csv("D:/R/R-4.4.2/working/rnaseq/genecounts.csv",row.names = 1)
head(genecounts)
dim(genecounts)
groups<-read.csv("rnaseq/groups.csv",stringsAsFactors = T)
groups
colnames(genecounts) == groups$id
#加载DESeq2包,对数据整体进行了差异表达分析
library(DESeq2)
dds <- DESeqDataSetFromMatrix(countData=genecounts,
colData=groups,
design=~dex)
dds <- DESeq(dds)
res <- results(dds)
head(res)
class(res)
res_1<-data.frame(res)
class(res_1)
head(res_1)
library(dplyr)
res_1 %>%
mutate(group = case_when(
log2FoldChange >= 2 & padj <= 0.05 ~ "UP",
log2FoldChange <= -2 & padj <= 0.05 ~ "DOWN",
TRUE ~ "NOT_CHANGE"
)) -> res_2
table(res_2$group)
#导出结果表
write.csv(res_2,file="rnaseq/diff_expr_result.csv",
quote = F)


1302

被折叠的 条评论
为什么被折叠?



