Entering edit mode
5.4 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()
Use ComplexHeatmap and refer to its awesome documentation. https://jokergoo.github.io/ComplexHeatmap-reference/book/
Is there a way to do it using pHeatmap? That way I can keep my previous heat map drown using this software.
There probably is, but ComplexHeatmap has the modularity that no other piece of heatmap software does. It will make your life a lot easier.
See: How to add images to a Biostars post and edit your post with images.
Thank you! I have updated the post. I copied the wrong link before.
You mean the order of genes be the same as in "selectGene'? then just change
to
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.
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.
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!
Did you look the
resultsNames()
of the DESeq2 result dataset? Check out theresults()
function to extract a result, and look at the column names of such a result dataset.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)