Using row order of one heatmap for a new heatmap
0
1
Entering edit mode
5.4 years ago
Anand Rao ▴ 640

I've generated a heatmap from my 1st input file containing a ( 315 row * 48 column ) grid of 0s and 1s, plus column and row names - please see after downloading file1)

I need to use order of row names from this x, y clustered heatmap to constrain how I make my next plots, which need to be:

A. barplots for these 3 single column files - A, B, C, and

B. another heatmap a different input file with a ( 315 row * 100 column) grid of 0s and 1s, with same row and column names as for the first heatmap.

I tried replicating the instructions at these other BioStars posts - post1 and post2, in order to extract row order from one heatmap and apply it to another, but without success.

Please note that I am using heatmap from base R, rather than pheatmap or Pheatmap (should I switch over?). I hope to convert these plots, using as.grob(plot), to "grobs", and then combine then into a plot_grid-based series of sub-panels.

The 3 specific questions I seek help for are:

1. How do I FIX the improper extraction of my ordered row list from the heatmap object ?

2. How should I modify my other input files (add rownames, delete column header etc) BEFORE they can be used in the final step?

3. What should be my R syntax for using heatmap clustered row order + new input files = ordered bar plots & ordered (new) heatmap

Thank you!

This is what I've tried thus far, without success:

HMM_Binaries = read.table("HMM_binary",header=TRUE,sep="\t")
HBM=data.matrix(HMM_Binaries, rownames.force = NA)

HBM_hm = heatmap(HBM, labRow = FALSE, col=c("firebrick1", "forestgreen"))

HBM_hm_row.order = HBM_hm$rowInd
HBM_hm_row.list = as.list(HBM_hm$rowInd)

> head(HBM_hm_row.order)
[1] 192 292 121 163 258 260

> head(HBM_hm_row.list)
[[1]]
[1] 192

[[2]]
[1] 292

[[3]]
[1] 121

[[4]]
[1] 163

[[5]]
[1] 258

[[6]]
[1] 260

> nrow(HBM_hm_row.order)
NULL
> nrow(HBM_hm_row.list)
NULL
> typeof(HBM_hm_row.order)
[1] "integer"
> typeof(HBM_hm_row.list)
[1] "list"

> Lengths_Reordered = Lengths[names(HBM_hm_row.order)]
> Lengths_Relisted = Lengths[names(HBM_hm_row.list)]
> nrow(Lengths_Reordered)
[1] 315
> nrow(Lengths_Relisted)
[1] 315
> typeof(Lengths_Reordered)
[1] "list"
> typeof(Lengths_Relisted)
[1] "list"
> head(Lengths_Reordered)
data frame with 0 columns and 6 rows
> head(Lengths_Relisted)
data frame with 0 columns and 6 rows
Heatmap R row reorder plot • 2.8k views
ADD COMMENT
0
Entering edit mode

Anand,

Please use github gists to show us plain text data. Clicking links and then downloading files takes way too much time. If possible, check out reprex so you can produce a reproducible example for us.

On the subject of heatmaps, you should really check out ComplexHeatmap. It will solve all your problems as it exposes APIs for almost everything and the developer is super responsive.

ADD REPLY
0
Entering edit mode

Thanks for your suggestion, Ram.

I am installing ComplexHeatmap and its dependencies currently.

Looks like ComplexHeatmap output be converted to a grob, based on a post here

ADD REPLY
0
Entering edit mode

No, you won't need grobs. There are functions like row_order that will get you the row order. Please skim through the manual - it covers a lot of options.

ADD REPLY

Login before adding your answer.

Traffic: 1677 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