This is a test version of Biostars. For the public version, visit https://www.biostars.org.
RNAseq TPM heatmap

Hi

I have a count matrix (TPM) for my samples. My samples are as follows :

wt0hr wt6hr wt24hr kd0hr kd6hr kd24hr

I have a TPM matrix with geneids as rows and the columns as the 6 samples above. I am using follwoing R code to generate the heatmap: cols <- c("","wt0","wt6","wt24","kd0", "kd6","kd24") dat <- read.csv("TPM.csv", row.names = 1,stringsAsFactors = FALSE, col.names = cols, header = TRUE)

counts_filtered_df <- dat[apply(dat, MARGIN = 1, FUN = function(x) sd(x) != 0),]

z.mat <- t(scale(t(counts_filtered_df), scale=TRUE, center=TRUE))

heatmap.2(z.mat, dendrogram="both", scale="none", trace="none")

Can anyone suggest me if this is the correct way to generate the heatmaps from TPM .

Tanya

rna-seq heatmap2

what makes you think that this was not the correct way?

You don't really need to scale the matrix manually as heatmap.2 can do that for you (by choosing a different value than scale = "none") and my personal preference is to look at the unscaled values, too.

1 answer

If you are going to scale manually outside of the heatmap.2 function, be sure to also set your own breaks:

require(RColorBrewer)
myCol <- colorRampPalette(c("dodgerblue", "black", "yellow"))(100)
myBreaks <- seq(-3, 3, length.out=101)

require("gplots")

heat.scaled <- t(scale(t(heat)))

heatmap.2(heat.scaled, col=myCol, breaks=myBreaks, scale="none", ...)

However, as Friederike says, heatmap.2 will automatically scale your data with scale="row", thus de-necessitating the manual scaling to Z-scores as you have done with z.mat <- t(scale(t(counts_filtered_df), scale=TRUE, center=TRUE))

At the end of the day, your statistical tests will have been performed on the unscaled TPM data, and thus the scaling to Z-scores (or logging or something else) is purely for visualisation purposes.

Log in to answer this question.