Question: Ordering of rowVar in drawing Heatmap
0
gravatar for dazhudou1122
14 months ago by
dazhudou112280
dazhudou112280 wrote:

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

heatmap rna-seq R • 433 views
ADD COMMENTlink modified 14 months ago • written 14 months ago by dazhudou112280
1

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

ADD REPLYlink written 14 months ago by ATpoint39k

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

ADD REPLYlink written 14 months ago by dazhudou112280

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 REPLYlink written 14 months ago by RamRS30k

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

ADD REPLYlink written 14 months ago by zx87549.6k

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

ADD REPLYlink written 14 months ago by dazhudou112280

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 REPLYlink modified 14 months ago by RamRS30k • written 14 months ago by asalimih30

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 REPLYlink written 14 months ago by dazhudou112280

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 REPLYlink written 14 months ago by asalimih30

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 REPLYlink written 14 months ago by dazhudou112280

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 REPLYlink written 14 months ago by RamRS30k

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 REPLYlink written 14 months ago by Fabio Marroni2.6k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 840 users visited in the last hour