2019-01-17

作者: 一路向前_莫问前程_前程似锦 | 来源:发表于2019-01-17 22:20 被阅读12次
    ## 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")
    

    相关文章

      网友评论

        本文标题:2019-01-17

        本文链接:https://www.haomeiwen.com/subject/eriwdqtx.html