Ordering of rowVar in drawing Heatmap
0
0
Entering edit mode
4.8 years ago
dazhudou1122 ▴ 140

Dear Biostars community,

I am trying to draw a Heatmap with specific genes from RNA seq results. I want to order the genes by row variations so that the up-regulated genes are on top while the down-regulated genes are at the bottom (B6 is the control group, B6+WY is the treatment group). I used the codes below for Heatmap drawing but the sorting seems to fail as the orders are quite random. Up-regulated genes are mixed with down-regulated ones. Can anyone help me fix it? I would really appreciate it! Code:

library("genefilter")
library(pheatmap)

topVarGenes <- order(rowVars(assay(rld)), decreasing = TRUE)
mat  <- assay(rld)[ topVarGenes, ]
mat  <- mat - rowMeans(mat)

selectGene <- c("Txnrd1","Cat","Gsr","Gsta3","Gstm1","Gstp1","Gstt2","Mgst1","Nqo1","Prdx1","Sod1","Prdx6","Ftl1","Gdf15","Slc11a1","Slc25a37","Slc40a1","Slc48a1","Hmox1","Fos","Prkcg","Abcc1","Aox1","Dnajb13","Gclc","Gclm","Abhd3","Csf2ra","Pla2g7","Plb1","Pla2g2e","Tnf","Plcb4","Nfkbie","Nfkb2","Rsad2","Maff","Herpud1","Acta2","Hp","Cp","Sod3")

dataSub <- mat[rownames(mat) %in% selectGene, ]
anno <- as.data.frame(colData(rld))

png("redox.png", 1500, 3000, pointsize=25)
pheatmap(dataSub, annotation_col = anno, cluster_rows=FALSE, cluster_cols=FALSE, fontsize=24)
dev.off()

enter image description here

RNA-Seq heatmap R • 2.1k views
ADD COMMENT
1
Entering edit mode

Use ComplexHeatmap and refer to its awesome documentation. https://jokergoo.github.io/ComplexHeatmap-reference/book/

ADD REPLY
0
Entering edit mode

Is there a way to do it using pHeatmap? That way I can keep my previous heat map drown using this software.

ADD REPLY
0
Entering edit mode

There probably is, but ComplexHeatmap has the modularity that no other piece of heatmap software does. It will make your life a lot easier.

ADD REPLY
0
Entering edit mode

See: How to add images to a Biostars post and edit your post with images.

ADD REPLY
0
Entering edit mode

Thank you! I have updated the post. I copied the wrong link before.

ADD REPLY
0
Entering edit mode

You mean the order of genes be the same as in "selectGene'? then just change

dataSub <- mat[rownames(mat) %in% selectGene, ]

to

dataSub <- mat[selectGene[selectGene %in% rownames(mat)], ]
ADD REPLY
0
Entering edit mode

Thanks for the reply. No I meant that I would like to plots the genes in the selectGene then sort them according their log2FoldChange so up-regulated genes are on top while the down-regulated genes are at the bottom.

ADD REPLY
0
Entering edit mode

So first you must perform a differential expression analysis using a tool like limma or DESeq2,... then extract log2FCs from the result. after that you can sort 'selectGene' based on logFC numbers.

ADD REPLY
0
Entering edit mode

I did a DE analysis with DESeq2. Can you show me how to extract log2FCs and sort based on these numbers. If will be great if you can provide some sample codes. Thank you!

ADD REPLY
0
Entering edit mode

Did you look the resultsNames() of the DESeq2 result dataset? Check out the results() function to extract a result, and look at the column names of such a result dataset.

ADD REPLY
0
Entering edit mode

Try something like dataSub <- dataSub[order(dataSub$L2FC),] (assuming L2FC is the log2fold change column).

As an alternative, you might just let the algorithm cluster them for you by using pheatmap(dataSub, annotation_col = anno, cluster_rows=TRUE, cluster_cols=FALSE, fontsize=24)

ADD REPLY

Login before adding your answer.

Traffic: 1742 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6