Use of various distance measures and clustering methods in heatmap creation
2
0
Entering edit mode
svlachavas ▴ 800
@svlachavas-7225
Last seen 20 days ago
Germany/Heidelberg/German Cancer Resear…

Dear Bioconductor Community,

i would like to ask a specific and simple question about defining specific arguments than the default in the heatmap.2 function of the gplots R package. In detail, if i want to use as a distance measure the pearson correlation distance and as clustering method the average for clustering both my rows(genes) and columns(samples), should i proceed like this ? :

eset # my expression set

corr.dist = function(x) as.dist(1-cor(t(x)))
avg = function(x) hclust(x, method="average")

heatmap.2(exprs(eset), distfun=corr.dist, hclustfun=avg, col=greenred(75), scale="none"....)

1
Entering edit mode
svlachavas ▴ 800
@svlachavas-7225
Last seen 20 days ago
Germany/Heidelberg/German Cancer Resear…

Dear Keith,

thank you for your answer-on the other hand, because i posted the question to get as much feedback i can-the function cor(x) computes the correlation on the columns on the matrix-object x-thats why i used the function transpose.

i noticed that if you want to use different cluster methodologies for row and colums respectively, for instanse for a matrix named y:

hr <- hclust(as.dist(1-cor(t(y), method="pearson")), method="complete") # Clusters rows by Pearson correlation as distance method.
hc <- hclust(as.dist(1-cor(y, method="spearman")), method="complete") # Colums by spearman

and then heatmap(y, Rowv=as.dendrogram(hr), Colv=as.dendrogram(hc))  or heatmap.2

So, i want to confirm that the code is fine for both perspectives

Best,

Efstathios

0
Entering edit mode
Keith Hughitt ▴ 170
@keith-hughitt-6740
Last seen 6 months ago
United States

Hi svlachavas,

I haven't tried passing a custom function to hclustfun before, but from a quick glance at the code it looks like it should work fine. To use Pearson correlation instead of euclidian distance, I would just pass in the correlation matrix directly:

heatmap.2(cor(exprs(eset)), ...)

HTH,

Keith