I am doing a gene-gene pairwise correlation, I get a plot and I do see positive and negative correlation
My code:
library(corrplot)
library(Hmisc)
gen = read.csv('NEW_RBP/CORPLOT/TF_NORMAL_NEW_40.txt',row.names = 1)
head(gen)
dim(gen)
gendat <- t(gen)
#gendat <- gen
head(gendat)
dim(gendat)
macolor = colorRampPalette(c("navyblue", "white", "red"))(100)
cor_5 <- rcorr(as.matrix(gendat))
M <- cor_5$r
p_mat <- cor_5$P
row_names <- rownames(M)
pdf("TF_NORMAL_NEW_40_gene.pdf",20,15,paper = "a4r")
corrplot(M, method = "color",is.corr = FALSE,
tl.srt = 45,diag = TRUE,tl.pos='n'
,order = "hclust",hclust.method = c("complete"),tl.cex = 3,number.cex=1.5)
dev.off()
How do I extract those gene pairs? One way what I have read and done is:
library(dplyr)
flat_cor_mat <- function(cor_r, cor_p){
#This function provides a simple formatting of a correlation matrix
#into a table with 4 columns containing :
# Column 1 : row names (variable 1 for the correlation test)
# Column 2 : column names (variable 2 for the correlation test)
# Column 3 : the correlation coefficients
# Column 4 : the p-values of the correlations
library(tidyr)
library(tibble)
cor_r <- rownames_to_column(as.data.frame(cor_r), var = "row")
cor_r <- gather(cor_r, column, cor, -1)
cor_p <- rownames_to_column(as.data.frame(cor_p), var = "row")
cor_p <- gather(cor_p, column, p, -1)
cor_p_matrix <- left_join(cor_r, cor_p, by = c("row", "column"))
cor_p_matrix
}
#cor_3 <- rcorr(as.matrix(gendat))
my_cor_matrix <- flat_cor_mat(cor_5$r, cor_5$P)
head(my_cor_matrix)
dim(my_cor_matrix)
Delete.na <- function(DF, n=0) {
DF[rowSums(is.na(DF)) <= n,]
}
TF_NORMAL_CORR = Delete.na(my_cor_matrix)
dim(RBP_DISEASE_40_CORR)
TF_NORMAL_HIGH = TF_NORMAL_CORR[ TF_NORMAL_CORR$cor > 0.9 & RBP_DISEASE_40_CORR$p < 0.00000001, ]
TF_NORMAL_LOW = TF_NORMAL_CORR[TF_NORMAL_CORR$cor < -0.9 & TF_NORMAL_CORR$p < 0.00000001, ]
Now even if I do that sort of high cut-off filtering I still get considerably high number of correlation pairs like few thousands if positive correlation is considered.
So few of my issues which I would like to get input or help
- How do I extract the cluster of regions with positive correlation or negative correlation ?
- If I found certain gene pair/pairs how do I label them ? should I make a vector or map or any other way like if say more than 0.8 correlation I would like to put a label on those regions only
- Considering label the gene order is important to be considered, what I have read and found is this how to find the order of the label
tempCor <- cor(gendat) tempCor <- data.frame(tempCor) dim(tempCor) names(tempCor) <- c(1:741) out <- corrplot(t(tempCor),method = "color",is.corr = FALSE, tl.srt = 45,diag = TRUE,tl.pos='n' ,order = "hclust",hclust.method = c("complete"),tl.cex = 3,number.cex=1.5) dimnames(out)
Now with all these how can I extract those patches of high and low correlation pairs and add selected label or highlight them and add label
I m not sure if all these can be done with corrplot! like adding selected label if yes i would be really glad to use that..
My data file data used
"In which groups are you interested in? In the upper left region and the bottom right square? In which format do you want it ? A list for each group? BTW, how many samples do you have? If it is so high, or they are mostly similar or there are few samples."
Its symmetric so would it matter if i use upper left or bottom right? I guess anyone would do good.
Format - a list for each group if i understand if there is one gene with many positive correlation then that would be considered as group?is that you are saying ?
I have 16 samples in this case but here I using gene-gene. I'm bit curious with a naive question: Is it possible to do gene to sample correlation or if i know what genes are positively or negatively correlated can I trace back without have to plot another heatmap of found genes which are positively or negatively correlated to see their expression in sample ?
I have given the data file it might help you better with my context..