This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Gene co-expression heatmap

Hello,

I am trying to plot a gene coexpression matrix from my scRNAseq data and plot the features with the highest correlation.

My approach:

#Coexp gene matrix from Seurat (CD8 is my Seurat object)

mat <- cor(t(as.matrix(CD8@assays$RNA@data[VariableFeatures(CD8)[1:500],])),method
= "spearman") #correlation matrix of the 500 most variable genes

ht <- Heatmap(mat, name = "Spearman correlation",
        column_names_gp = grid::gpar(fontsize = 0),
        row_names_gp = grid::gpar(fontsize = 0),
        heatmap_legend_param = list(legend_direction = "horizontal")) draw(ht, heatmap_legend_side = "bottom")

enter image description here

#Extract genes with highest correlation

mat_corr <- mat  diag(mat_corr) <- 0 #give 0 to the diagonal   
q <-quantile(mat_corr, probs = .99) #calculate the 99th percentile of the remainder  
mat2 <-mat_corr %>%   as.data.frame() %>%   mutate(Res = ifelse(rowSums(mat_corr >= q) > 0, "Yes", "No")) #add column with Yes/No for corr higher than q  
mat2 <- mat2 %>% filter(Res == "Yes") #filter out those < q  
mat2 <- mat2 %>% filter(!str_detect(rownames(mat2), "^RP[SL]")) #filter out uninteresting genes  
rownames(mat2) #check genes with highest corr

Then I was thinking to use rowAnnotation to plot them onto the Heatmap. Is this approach correct?

Thanks
Francesco

scrnaseq

0 answers

No answers yet.

Log in to answer this question.