R语言进行GEO数据挖掘与分析(四)基因的差异性分析-R语言进行GEO数据挖掘与分析(四)基因的差异性分析
热门回复:
- 低调的大朝:课程的相关代码(三):
#上调基因和下调基因
tempOutput$g=ifelse(tempOutput$P.Value>0.01,'stable', #if 判断:如果这一基因的P.Value>0.01,则为stable基因
ifelse( tempOutput$logFC >1.5,'up', #接上句else 否则:接下来开始判断那些P.Value<0.01的基因,再if 判断:如果logFC >1.5,则为up(上调)基因
ifelse( tempOutput$logFC < -1.5,'down','stable') )#接上句else 否则:接下来开始判断那些logFC <1.5 的基因,再if 判断:如果logFC <1.5,则为down(下调)基因,否则为stable基因
)
table(tempOutput$g)
save(dat1,group_list1,tempOutput,file = 'tempOutput.Rdata')
如果觉得对您有所帮助,请您动动您发财的小指头“三连”,谢谢!
- 低调的大朝:课程的相关代码(二):
#差异分析走标准的limma流程
library(limma)
#创建一个分组的矩阵
design=model.matrix(~0+factor(group_list1))#创建一个分组的矩阵
colnames(design)=levels(factor(group_list1))
rownames(design)=colnames(dat1)
head(design)
#创建差异比较矩阵
contrast.matrix<-makeContrasts(paste0(unique(group_list1),collapse = "-"),levels = design)
contrast.matrix ##这个矩阵声明,我们要Tumor组和Non_Tumor组进行差异分析比较
#第一步lmFit,#lmFit为每个基因给定一系列的阵列来拟合线性模型
fit<-lmFit(dat1,design)
#第二步eBayes,#eBayes给出了一个微阵列线性模型拟合,通过经验贝叶斯调整标准误差到一个共同的值来计算修正后的t统计量、修正后的f统计量和微分表达式的对数概率。
fit2<-contrasts.fit(fit, contrast.matrix)
fit2<-eBayes(fit2)
#第三步topTable,#topTable从线性模型拟合中提取出排名靠前的基因表。
options(digits = 4) #设置全局的数字有效位数为4
#topTable(fit2,coef=2,adjust='BH')
tempOutput<-topTable(fit2,coef=1,n=Inf)
tempOutput<-na.omit(tempOutput)#移除NA值
head(tempOutput)
tempOutput【"CCL5",】
- Lover3913:走标准的limma流程的时候,运行fit<-lmFit(dat1,design)的时候我的电脑出现了这样错误
Error in rowMeans(y$exprs, na.rm = TRUE) : 'x'必需为数值
[辣眼睛]啊要怎么解决呢
- 低调的大朝:课程的相关代码(一):
###基因的差异性分析
rm(list = ls()) ## 魔幻操作,一键清空~
options(stringsAsFactors = F)
load(file = 'Expreset1.Rdata')
dat1【1:4,1:4】#每次都要检测数据
table(group_list1) #table函数,查看group_list1中的分组个数
boxplot(dat1【2,】~group_list1) #第一个基因以group_list分组画箱线图
t.test(dat1【2,】~group_list1) #第一个基因做t检验
bp=function(g){ #自定义一个函数bp,函数为{}里的内容
library(ggpubr)
df=data.frame(gene=g,stage=group_list1)
p <- ggboxplot(df, x = "stage", y = "gene",
color = "stage", palette = "jco",
add = "jitter")
# Add p-value
p + stat_compare_means()
}
bp(dat1【1,】) ## 调用上面定义好的函数,避免同样的绘图代码重复多次敲。
- 情人眼中:奔溃 视频里面讲解一下 你第三节课是怎么回事 好不好