## calculate correlation of multiple genes and multiple LncRNAs
lnc_Gene_Correlation<-function(difLncProfile,GeneExprofile,cutoff_cor=0.6,cutoff_p=0.01){
## define variables
lnc<-c()
gene<-c()
corelation<-c()
p<-c()
k<-1
## use a for circulation to calculate all correlations of lncRNAs and mRNA
for(i in 1:dim(difLncProfile)[1]){
gene[k:(k+dim(GeneExprofile)[1]-1)]<-rownames(GeneExprofile)
lnc[k:(k+dim(GeneExprofile)[1]-1)]<-rep(rownames(difLncProfile[i,]),dim(GeneExprofile)[1])
corelation[k:(k+dim(GeneExprofile)[1]-1)]<-apply(GeneExprofile,1,function(x){cor(as.numeric(difLncProfile[i,]),as.numeric(x))})
p[k:(k+dim(GeneExprofile)[1]-1)]<-apply(GeneExprofile,1,function(x){cor.test(as.numeric(difLncProfile[i,]),as.numeric(x))$p.value})
k<-k+dim(GeneExprofile)[1]
}
## combine the variables to a table
lncGeneCor<-data.frame(lnc,gene,corelation,p)
## filter the correlations
lncGeneCor1<-lncGeneCor[which(abs(lncGeneCor[["corelation"]])>=cutoff_cor & lncGeneCor[["p"]]<cutoff_p),]
return(lncGeneCor1)
}
## read files
read.table("GeneExprofile.txt")->GeneExprofile
read.table("DifLncProfile.txt")->DifLncProfile
## set cutoff
cutoff_cor=0.6
cutoff_p=0.01
## function call to calculate all correlations of lncRNAs and mRNA
LncGeneCor<-lnc_Gene_Correlation(DifLncProfile,GeneExprofile)
## write files
write.table(LncGeneCor,"LncGeneCorResult.txt",row.names=F,sep="\t",quote=F)
## show some result
head(LncGeneCor)
## to get neighbor genes of one lncRNAs
lncRNA2="ENSG00000034063"
neighborGenes<-LncGeneCor[which(LncGeneCor[,1]==lncRNA2),2]
write.table(neighborGenes,"neighborGenes.txt",row.names=F,col.names=F,quote=F,sep="\t")
共表达
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- Day 14 第二周复盘 (2019.01.17~2019.01.23) 2019.01.23 今天是第二周的复盘...
- 《聊斋志异》 考城隍 我姐夫的祖父,名叫宋焘,是本县的廪生。有一天,他生病卧床,见一个小官吏,...