heatmap.2() get matrix after hierarchical clustering
2
5
Entering edit mode
Guest User ★ 12k
@guest-user-4897
Last seen 6.6 years ago
Hi, Is there an easy way to obtain the matrix after the heatmap.2() function performs clustering. I'm plotting a matrix of fold change values with 359 genes. The names of the genes are not visible on the heatmap since there are so many. I want to view this matrix after the clustering is performed since the order of the genes from the input matrix is rearranged. Any input will be appreciated. Thanks! -- output of sessionInfo(): N/A -- Sent via the guest posting facility at bioconductor.org.
Clustering Clustering • 26k views
ADD COMMENT
9
Entering edit mode
Thomas Girke ★ 1.7k
@thomas-girke-993
Last seen 8 weeks ago
United States
Try: ## Some input sample matrix y <- matrix(rnorm(50), 10, 5, dimnames=list(paste("g", 1:10, sep=""), paste("t", 1:5, sep=""))) ## Run heatmap.2 on this matrix library(gplots) test <- heatmap.2(y) y[rev(test$rowInd), test$colInd] Now try to understand why y[rev(test$rowInd), test$colInd] does the trick of returning the row names/labels in the proper order, which is just some basic R syntax of accessing a list-like object and then using an index for sorting. Another way of doing this is to separate the clustering with hclust from the heatmap plotting, where you want to learn how to access the hclust object as you need. For instance: ## Row clustering (adjust here distance/linkage methods to what you need!) hr <- hclust(as.dist(1-cor(t(y), method="pearson")), method="complete") ## Column clustering (adjust here distance/linkage methods to what you need!) hc <- hclust(as.dist(1-cor(y, method="spearman")), method="complete") ## Plot heatmap heatmap.2(y, Rowv=as.dendrogram(hr), Colv=as.dendrogram(hc), scale="row", density.info="none", trace="none") ## Return matrix with row/column sorting as in heatmap y[rev(hr$labels[hr$order]), hc$labels[hc$order]] Thomas On Tue, Oct 16, 2012 at 02:32:35PM +0000, Guest [guest] wrote: > > Hi, > > Is there an easy way to obtain the matrix after the heatmap.2() function performs clustering. I'm plotting a matrix of fold change values with 359 genes. The names of the genes are not visible on the heatmap since there are so many. I want to view this matrix after the clustering is performed since the order of the genes from the input matrix is rearranged. > > Any input will be appreciated. > > Thanks! > > -- output of sessionInfo(): > > N/A > > -- > Sent via the guest posting facility at bioconductor.org. > > _______________________________________________ > Bioconductor mailing list > Bioconductor at r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
ADD COMMENT
0
Entering edit mode
Hey, that's a pretty neat trick! I was going to use the reorder() function and re-order my input matrix based on the values returned by rowInd, but I think is may be more straightforward. Thank you Thomas and Jim! On 10/16/12 11:42AM, "Thomas Girke" <thomas.girke at="" ucr.edu=""> wrote: >Try: > >## Some input sample matrix >y <- matrix(rnorm(50), 10, 5, dimnames=list(paste("g", 1:10, sep=""), >paste("t", 1:5, sep=""))) > >## Run heatmap.2 on this matrix >library(gplots) >test <- heatmap.2(y) >y[rev(test$rowInd), test$colInd] > >Now try to understand why y[rev(test$rowInd), test$colInd] does the >trick of returning the row names/labels in the proper order, which is >just some basic R syntax of accessing a list-like object and then >using an index for sorting. > >Another way of doing this is to separate the clustering with hclust from >the >heatmap plotting, where you want to learn how to access the hclust object >as >you need. > >For instance: > >## Row clustering (adjust here distance/linkage methods to what you need!) >hr <- hclust(as.dist(1-cor(t(y), method="pearson")), method="complete") > >## Column clustering (adjust here distance/linkage methods to what you >need!) >hc <- hclust(as.dist(1-cor(y, method="spearman")), method="complete") > >## Plot heatmap >heatmap.2(y, Rowv=as.dendrogram(hr), Colv=as.dendrogram(hc), scale="row", >density.info="none", trace="none") > >## Return matrix with row/column sorting as in heatmap >y[rev(hr$labels[hr$order]), hc$labels[hc$order]] > > >Thomas > >On Tue, Oct 16, 2012 at 02:32:35PM +0000, Guest [guest] wrote: >> >> Hi, >> >> Is there an easy way to obtain the matrix after the heatmap.2() >>function performs clustering. I'm plotting a matrix of fold change >>values with 359 genes. The names of the genes are not visible on the >>heatmap since there are so many. I want to view this matrix after the >>clustering is performed since the order of the genes from the input >>matrix is rearranged. >> >> Any input will be appreciated. >> >> Thanks! >> >> -- output of sessionInfo(): >> >> N/A >> >> -- >> Sent via the guest posting facility at bioconductor.org. >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at r-project.org >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: >>http://news.gmane.org/gmane.science.biology.informatics.conductor
ADD REPLY
0
Entering edit mode
@james-w-macdonald-5106
Last seen 7 hours ago
United States
Hi Whomever, On 10/16/2012 10:32 AM, Guest [guest] wrote: > Hi, > > Is there an easy way to obtain the matrix after the heatmap.2() function performs clustering. I'm plotting a matrix of fold change values with 359 genes. The names of the genes are not visible on the heatmap since there are so many. I want to view this matrix after the clustering is performed since the order of the genes from the input matrix is rearranged. > > Any input will be appreciated. From ?heatmap.2: Value: Invisibly, a list with components rowInd: row index permutation vector as returned by order.dendrogram . colInd: column index permutation vector. So if you assign the output of heatmap.2 you can get what you want. Best, Jim > > Thanks! > > -- output of sessionInfo(): > > N/A > > -- > Sent via the guest posting facility at bioconductor.org. > > _______________________________________________ > Bioconductor mailing list > Bioconductor at r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor -- James W. MacDonald, M.S. Biostatistician University of Washington Environmental and Occupational Health Sciences 4225 Roosevelt Way NE, # 100 Seattle WA 98105-6099
ADD COMMENT
0
Entering edit mode

Thanks James I appreciate your time.

ADD REPLY

Login before adding your answer.

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