This is a test version of Biostars. For the public version, visit https://www.biostars.org.
filtering genes by pearson correlation

Hi biostars,

I did a pearson correlation to my data (expression matrix), and I keep only the correlation >0.8 . How can I obtain the sub expression matrix of only these highly correlated genes. Thank you

data<-t(matrix)
cor = cor(data, use="pairwise.complete.obs", method="pearson")
cor<-cor[abs(cor)>0.8]
correlation rna-seq r

1 answer

Extract the indices of the genes of interest with which() and the arr.ind option, e.g.

idx <- which(abs(cor)>0.8, arr.ind = TRUE)
correlated.genes <- data[idx, ]

Thank you Jean-Karim, I do this :

#cor is symmetric, so we can keep only the half of the pairs of indices
idx<-which( (abs(cor) > 0.8) & (upper.tri(cor)), arr.ind=TRUE)
correlated.genes <- matrix[idx, ]

Then I have to remove the duplicated genes from 'correlated.genes' ?

This was just to give you quick pointer. What I think you want is to get unique indices. Something like:

idx <- which( (abs(cor) > 0.8) & (upper.tri(cor)), arr.ind=TRUE)
idx <- unique(c(idx[, 1],idx[, 2])
correlated.genes <- matrix[idx, ]

Thank you Jean-karim

Log in to answer this question.