1

I have a heatmap made from over 1200 samples using ComplexHeatmap. I noticed an interesting expression pattern in the first sub-branch of the main 2 branches of the column dendrogram (circled in the image linked below). Is there any way to extract those sample IDs? I know how to use column_order() to rearrange my dataframe but that doesn't tell me where the cutoff for that specific branch is.

Branch of interest from my heatmap

I can't share the exact data I'm using but here is a (much smaller) example from a publicly available dataset:

            MB.0362   MB.0346   MB.0386   MB.0574   MB.0503   MB.0641   MB.0201   MB.0218   MB.0316   MB.0189   MB.0891   MB.0658   MB.0899   MB.0605   MB.0258   MB.0506   MB.0420   MB.0223   MB.0445   MB.0199
SLC9A1    10.014262  9.348527  8.811785  8.952057  9.294008  9.074486  9.073483  8.917497  9.206067  9.583312  9.255846  8.648056  8.971370  9.487947  8.871051  9.595639  9.197777  9.393822 10.152384  9.568540
GNG5       8.852986  8.578356  8.381930  8.862339  8.991660  8.396527  8.033163  8.600396  8.839458  8.348755  8.398942  9.038147  8.173396  8.683117 10.052359  7.990176  8.367180  8.726214  8.717414  8.767201
TAF15     10.166590  8.954535  9.688830 10.627204 11.113856 10.497890 10.196994 10.143833 10.200014 10.280406 10.035374 10.103472 10.039609 10.329979 10.752679  9.949489 10.020149 10.472094 10.298979  9.987892
HIPK2      7.655179  7.033683  7.375785  7.108554  7.489580  7.335830  7.302815  6.839674  7.986762  7.517980  8.058493  7.138536  7.404821  7.033944  7.974238  7.274671  7.766441  8.057382  9.084636  6.692346
SHMT2      9.918027 12.369679  9.547593  9.624116  9.253191  9.642811 10.943321 10.377846 10.317363  9.641000  9.453476 10.620086  9.652899  9.151635  9.622799 10.276871 10.046446  9.412688  9.149661  9.289657
RPL35     10.887942 11.258645 11.589094 11.221420 11.082407 11.214193 11.021294 11.468842 11.360617 11.655555 11.474745 12.002109 11.617621 11.768203 11.511261 10.923588 11.019755 10.894383 11.694444 11.406323
TM2D1      8.606975  7.947867  8.237843  8.729167  8.591014  8.797988  9.450876  9.312002  9.268968  9.149995  9.415797  9.294075  8.880117  9.256000  9.290991  9.092648  9.606783  9.082684  9.648657  9.233755
PDIA6      8.507808  9.090804  7.841400  8.352159  8.739558  8.181130  9.515963  8.081951  9.308254  8.676159  7.908640  8.535718  8.424852  7.984671  7.771104  8.702274  8.604027  8.184711  8.747111  8.268900
RPS24      7.313840  8.931837  9.343814  8.656425  7.784744  7.632077  8.335490  7.915826  8.405816  7.415337  7.359698  8.289743  8.040539  7.518757  7.860967  7.715894  7.751548  7.230542  7.557848  6.666697
C14orf102  9.530002  9.424313  9.139450  8.729495  8.869929  9.171725  8.706918  9.387788  8.295372  8.602474  9.036995  8.725990  9.303004  9.298385  8.510322  8.553584  9.260028  8.438634  8.738240  8.721516
GLT8D2     8.276766  6.762350  8.725306  8.263818  8.372672  9.388836  8.967529  8.888135  6.975133  8.998073  8.771314  7.781078  8.506116  8.624120  6.888547  7.515468  8.691047  8.005198  7.839425  8.349178
EFCAB4A   10.027106 10.607895  8.417696  9.074081  9.477721  8.892575  9.144772 11.690308  9.051305  9.602089 10.582232  9.188076  8.648211  9.529172  9.412860  8.654041  8.537899  9.711596  8.973382  9.928549
ECI2       8.188227  7.932798  7.749042  8.405749  8.255581  8.103899  6.893893  9.723858  7.382778  9.409714  9.580753  8.855057  9.728697  8.987784  8.574284  8.771357  7.748056  8.307684  8.272652  9.564966
PLXNB2     9.634034 10.088377  9.072433  9.818408  9.378441  9.388272  9.900784  9.309009  9.884819  9.400739  9.414565  8.727501  9.870917  8.877603  9.515299  9.251402  9.782487  9.771257  9.768631  9.391262
ANTXR2     7.675268  7.302808  8.154243  7.498313  7.982752  8.675433  8.598871  7.899966  7.712419  8.596722  8.343792  8.048416  8.234922  8.111262  7.994355  7.733463  8.494510  7.878913  7.510128  7.695356
TMEM59    11.957371 11.840038 11.601336 11.812162 12.162400 11.974395 12.974287 11.140323 11.660696 11.710925 12.138851 11.537590 11.412840 12.034548 12.291991 11.769580 11.254918 12.979612 11.890414 12.285631
DOCK2      8.457012  7.436265  8.573070  7.881306  8.272164  8.981460  8.318510  8.001394  9.444604  8.853754  8.379051  9.209957  8.604442  8.495951  8.132622  8.267956  8.619183  8.477045  8.310149  8.604218
LARGE      7.725950  8.802281  7.700536  8.459797  8.982957  8.622956  7.809481 10.520597  7.531150  8.091029  7.975678  6.773807  7.808668  8.316455  7.933935  7.084101  7.702452  8.209997  9.356626  8.051576
KRT8      11.343993 10.989258  9.656656 11.031466 11.379990  9.788035 10.194469 12.548176  9.357603 10.213369 10.285941  8.720888 10.740695 10.624580 10.413525 11.019989  8.597315  9.627852 11.738518 10.275624
CREB3L2    9.245806  9.510992  9.289734  9.332547  9.068660 10.020441 10.214738  9.088670 10.306787  9.386496 10.065021 10.409406  9.392956  9.239798  8.938254  9.193017 10.797863  9.724634  9.787840  9.347403

The rows are genes and the columns are samples. Here is the code I used to create the heatmap:

library(tidyverse)
library(ComplexHeatmap)
library(circlize)

metabric<-read.table("source_data/metabric.csv", sep=",", header=1, row.names=1)
metabric_subset<-metabric[1:20, 1:20]

medianCtr<-function(x){
  annAll <- dimnames(x)
  medians <- apply(x,1,median,na.rm=T)
  x <- t(scale(t(x),center=medians,scale=F))
  dimnames(x) <- annAll
  return(x)
}

metabric_subset.medctr<-as.data.frame(medianCtr(metabric_subset))
metabric_subset.medctr<-as.matrix(metabric_subset.medctr)

col_fun<-colorRamp2(c(-2,0,2), colorRampPalette(c("dodgerblue","white","red2"))(3))

clustering_func = function(x) fastcluster::hclust(dist(x))

ht = Heatmap(metabric_subset.medctr, 
             name = "Expression",
             col=col_fun,
             cluster_rows=clustering_func,
             cluster_columns=clustering_func,
             border=TRUE,
             show_column_names=FALSE,
             show_row_names=FALSE,
             width = unit(20, "cm"),
             column_title= "METABRIC",
)
ht = draw(ht)
order_of_cols<-column_order(ht)

lapply(order_of_cols, function(x) length(x))

metabric_reordered<-metabric_subset.medctr[, order_of_cols]

You can see at the bottom that I'm able to rearrange my matrix by the order of the columns in the dendrogram. This is fine for this example because there are only 20 rows and it's easy to see where the clusters are. However, in my actual heatmap, there are over 1200 samples so I can't tell where the cutoff for the cluster I have circled is.

mfeldbauer
  • 132
  • 1
  • 9
  • Welcome to StackOverflow. Please provide a [minimal reproducible dataset](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and the codes you have tried. This will help us help you with your question. – Adam Quek Jun 01 '22 at 07:47
  • @AdamQuek is it possible to wrap the heatmap inside a function ? – PesKchan Jul 06 '22 at 07:26
  • @PesKchan I have done that before but how will that help here? – mfeldbauer Jul 06 '22 at 17:09
  • @mfeldbauer actually I have made a question regarding that ..if you could help ...please have a look https://stackoverflow.com/questions/72887166/complexheatmap-with-multiple-files-plotting it would be really helpful – PesKchan Jul 06 '22 at 17:30

0 Answers0