Question: Specific gene labeling in a heatmap
0
gravatar for clizama
5 weeks ago by
clizama0
clizama0 wrote:

I'm using pheatmap to make a Heatmap. I was wondering if exist any way using pheatmap in R to add only the name of specific genes in the heatmap. Without do it manually.

Thanks Carlos

rna-seq • 140 views
ADD COMMENTlink modified 5 weeks ago • written 5 weeks ago by clizama0

You can set the names that are not of interest to you to empty vectors (I think).

Apart from that, the ComplexHeatmap package seems to allow you to do just that without a hack like the one I suggested. You can transfer your pheatmap command into ComplexHeatmap universe following these code details.

ADD REPLYlink written 5 weeks ago by Friederike6.0k

I tried. ComplexHeatmap

library(ComplexHeatmap) I used the test examples just to see how it work. Then I run: pheatmap(test) I got these error: Error in pheatmap(test) : could not find function "pheatmap"

any guest I can imagine has to be something simple o fix.

ADD REPLYlink written 5 weeks ago by clizama0

Don't worry I fixed, thanks

ADD REPLYlink written 5 weeks ago by clizama0

Thanks guys I will try both option.

ADD REPLYlink written 5 weeks ago by clizama0

do report back what ended up working for you so that this post may be as useful as possible for future users

ADD REPLYlink written 4 weeks ago by Friederike6.0k

Finally, I took the suggestion from papyrus and your suggestion with ComplexHeatmap, The Script looks like that and work really good for me.

data <- read.csv("/root/heatmap.csv", header = TRUE, stringsAsFactors=F) data_mat <- data %>% column_to_rownames("Gene") %>% # turn the geneid column into rownames as.matrix() head(data_mat)

my_colors = c("blue", "black", "yellow") my_colors = colorRampPalette(my_colors)(50) colMeta_df <- data.frame(Treatment = c(rep("D", 1), rep("A", 4), rep("B", 3), rep("C", 3)), stringsAsFactors = F, row.names = colnames(data_mat))

genelist <- c("geneA", "geneX") labels <- rownames(data_mat) labels[!labels %in% genelist] <- "" pheatmap(mt, labels_row = labels)

ComplexHeatmap(data_mat,

                          scale = "row",
                          color = my_colors,
                           border_color = NA,
                         fontsize_row = 8,
                         fontsize_col = 12,       
                         cluster_rows = TRUE,
                         clustering_distance_rows = "euclidean",
                        clustering_method = "complete",
                       cluster_cols = FALSE,
                       labels_row = labels, 
                      labels_col = NULL,
                     cellwidth = 14,
                    cellheight = 0.25,
                    main="Gene Expression")
ADD REPLYlink modified 4 weeks ago • written 4 weeks ago by clizama0
1
gravatar for Papyrus
5 weeks ago by
Papyrus360
Papyrus360 wrote:

For the pheatmap package that behaviour is controlled by the labels_row or labels_col arguments. These labels are by default the rownames and colnames of your matrix. To only show specific names, set the rest to empty characters "". For example:

You have this matrix, where the rows are genes:

mt <- matrix(1:9,3,3)
colnames(mt) <- c("a","b","c")
rownames(mt) <- c("a","b","c")
pheatmap(mt)

You only want to represent genes "a" and "c":

# Your list of genes
    genelist <- c("a","c") 
# Labels to plot
    labels <- rownames(mt) 
# Set the rest of genes to ""
    labels[!labels %in% genelist] <- "" 
    pheatmap(mt, labels_row = labels)
ADD COMMENTlink modified 5 weeks ago • written 5 weeks ago by Papyrus360
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: 655 users visited in the last hour