整理表格做相关分析
mR=read.csv('mRNAre.csv',header = T)
row.names(mR)=mR[,1]
mR=mR[,-1]
colnames(mR)=c('V1','V2','V3','C1','C2','C3')
mR1=as.matrix(mR)
tmR=t(mR1)
tmR=as.data.frame(tmR)
#lncRNA表格整理
lnR=read.csv('lncRNAre.csv',header = T)
row.names(lnR)=lnR[,1]
lnR=lnR[,-1]
colnames(lnR)=c('V1','V2','V3','C1','C2','C3')
lnR1=as.matrix(lnR)
tlnR=t(lnR1)
tlnR=as.data.frame(tlnR)
##相关
library(pheatmap)
cor_matrix <- cor(tlncR,tmR)
cor=cor_matrix[]
pheatmap(cor_matrix)
write.table(cor_matrix,file='cor.csv',sep = ",")
矩阵边长便于分析
n*n矩阵变长
ut <- upper.tri(data)
edge<-data.frame(row = rownames(data)[row(data)[ut]],column = colnames(data)[col(data)[ut]], cor =(data)[ut] )
write.csv(edge,"lnc_mRNA_edge.csv")
n*X矩阵
data=read.csv("cor.csv",header = T)
ut <- upper.tri(data,diag=FALSE)
downt<-lower.tri(data,diag = TRUE)
edge1<-data.frame(row = rownames(data)[row(data)[ut]],column = colnames(data)[col(data)[ut]], cor =(data)[ut])
edge2<-data.frame(row = rownames(data)[row(data)[downt]],column = colnames(data)[col(data)[downt]], cor =(data)[downt])
c=rbind(edge1,edge2)
write.csv(c,"lncRNA_mRNA_edge.csv")
网友评论