#九象限分析#
数据准备
相关性分析的r值与p值
#导入每组差异分组检测到的基因和代谢相关性分析的p值和r值#
r <- read.csv("r.csv",header = T,row.names = 1)
metaGeneCor.p <- read.csv("metaGeneCor.p.csv",header = T,row.names = 1)
#转换数据类型为matrix#
r <- as.matrix(r)
metaGeneCor.p <- as.matrix(metaGeneCor.p)
#构建一个226793行4列的matrix#
#226793为基因与代谢物的乘积#
x <- matrix(NA,ncol = 4,nrow = 226793)
#构建一个循环,使相关性分析中的基因与代谢物填入这个变量中#
for(i in 1:1253){
j <- 1
while(j<182)
{ x[(i-1)*181+j,1] <- row.names(r)[i]
x[(i-1)*181+j,2] <- colnames(r)[j]
j <- j+1
}
}
#将相关性分析的r值和p值提取出来#
for(i in 1:dim(x)[1]){
x[i,3] <- r[x[i,1],x[i,2]]
x[i,4] <- metaGeneCor.p[x[i,1],x[i,2]]
}
colnames(x) <- c("gene","meta","PCC","PCCP")
#导入基因与代谢物的差异倍数数据#
meta <- read.csv("181FC.csv",header = T)
colnames(meta) <- c("meta","m-Log2FC")
meta <- as.matrix(meta)
gene <- read.csv("1253FC.csv",header = T)
colnames(gene) <- c("gene","g-Log2FC")
gene <- as.matrix(gene)
#将差异倍数数据与相关性数据x合并成一个数据#
jiuxiangxian <- merge(x,gene,by="gene")
jiuxiangxian <- merge(jiuxiangxian,meta,by="meta")
#筛选相关性绝对值大于0.8,p值小于0.05#
jiuxiangxian[,3] <- as.numeric(jiuxiangxian[,3])
jiuxiangxian[,4] <- as.numeric(jiuxiangxian[,4])
jiuxiangxian[,5] <- as.numeric(jiuxiangxian[,5])
jiuxiangxian[,6] <- as.numeric(jiuxiangxian[,6])
jxx <- jiuxiangxian[which(abs(jiuxiangxian$PCC)>0.8),]
jxx <- jxx[which(jxx$PCCP<0.05),]
#按九象限对数据分类#
#jxx增加一列#
ninequadrants <- NA
jxx <- cbind(jxx[,1:6],ninequadrants)
#去除LogFC值为NA的行,即第5、6列为NA的行#
jxx <- jxx[complete.cases(jxx[,5:6]),]
#九象限位置填充#
for(i in 1:dim(jxx)[1]){
if((jxx[i,5]<=-1)&&(jxx[i,6]>=1))
{jxx[i,7] <- 1}
else if(((jxx[i,5]<1)&&(-1<jxx[i,5]))&&(jxx[i,6]>=1))
{jxx[i,7] <- 2}
else if((jxx[i,5]>=1)&&(jxx[i,6]>=1))
{jxx[i,7] <- 3}
else if((jxx[i,5]<=-1)&&((jxx[i,6]<1)&&(-1<jxx[i,6])))
{jxx[i,7] <- 4}
else if(((jxx[i,5]<1)&&(-1<jxx[i,5]))&&((jxx[i,6]<1)&&(-1<jxx[i,6])))
{jxx[i,7] <- 5}
else if((jxx[i,5]>=1)&&((jxx[i,6]<1)&&(-1<jxx[i,6])))
{jxx[i,7] <- 6}
else if((jxx[i,5]<=-1)&&(jxx[i,6]<=-1))
{jxx[i,7] <- 7}
else if(((jxx[i,5]<1)&&(-1<jxx[i,5]))&&(jxx[i,6]<=-1))
{jxx[i,7] <- 8}
else if((jxx[i,5]>=1)&&(jxx[i,6]<=-1))
{jxx[i,7] <- 9}
}
可视化
https://blog.csdn.net/ziixiaoshenwang/article/details/115297657