4

I'm using the CLUSTERGRAM object from the Bioinformatics Toolbox (ver 3.7). MATLAB version R2011a.

I'd like to get permutation vectors for row and columns for clustergram, as I can do with dendrogram function:

x = magic(10);
>> [~,~,permrows] = dendrogram(linkage(x,'average','euc'))
permrows =
     9    10     6     7     8     1     2     4     5     3
>> [~,~,permcols] = dendrogram(linkage(x','average','euc'))
permcols =
     6     7     8     9     2     1     3     4     5    10

I found that the clustering is not the same from clustergram and dendrogram, most probably due to optimal leaf ordering calculation (I don't want to disable it).

For example, for clustergram from:

clustergram(x)

('average' and 'eucledian' are default methods for clustergram)

the vectors (as on the figure attached) should be:

permrows = [1 2 4 5 3 10 9 6 7 8];
permcols = [1 2 8 9 6 7 10 5 4 3];

clustergram example

So, how to get those vectors programmatically? Anybody well familiar with this object?

Do anyone can suggest a good alternative? I know I can create a similar figure combining imagesc and dendrogram functions, but leaf ordering is much better (optimal) in clustergram, than in dendrogram.

yuk
  • 19,098
  • 13
  • 68
  • 99
  • Won't you get the information from `get(cgo,'ColumnLabels')` and `get(cgo,'RowLabels')`? – Jonas Jun 13 '12 at 20:35
  • @Jonas: I actually use other labels, but your solution can be a workaround. Not to set the labels temporary, then get the vectors, and reset labels. Logically I thought that `get(cgo,'RowLabels')` would return the labels in the original order, but I didn't test. It appears that `set` and `get` work differently, so `set(cgo,'RowLabels',get(cgo,'RowLabels'))` will give you wrong result. Anyway, please post it as an answer. – yuk Jun 14 '12 at 14:54

1 Answers1

4

From looking at the documentation, I guess that get(gco,'ColumnLabels') and get(gco,'RowLabels'), where gco is the clustergram object, should give you the reordered labels. Note that the corresponding set-methods take in the labels in original order and internally reorders them.

Consequently, if you have used custom labels (set(gco,'RowLabels',originalLabels))

[~,permrows] = ismember(get(gco,'RowLabels'),originalLabels)

should return the row permutation.

Jonas
  • 74,690
  • 10
  • 137
  • 177
  • This is even easier than I thought. One correction: `originalLabels` should go as 2nd argument, since I need vectors to reproduce the clustergram from the original data. Thanks a lot! – yuk Jun 14 '12 at 19:42
  • @yuk: ok, edited (btw: you'd have the privilege to edit as well) – Jonas Jun 14 '12 at 22:33