Search
Question: heatmap.2() get matrix after hierarchical clustering
5
gravatar for Guest User
5.1 years ago by
Guest User12k
Guest User12k 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.
ADD COMMENTlink modified 5.1 years ago by Thomas Girke1.6k • written 5.1 years ago by Guest User12k
8
gravatar for Thomas Girke
5.1 years ago by
Thomas Girke1.6k
United States
Thomas Girke1.6k 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 COMMENTlink written 5.1 years ago by Thomas Girke1.6k
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 REPLYlink written 5.1 years ago by Kasoji, Manjula NIH/NCI [C]120
0
gravatar for James W. MacDonald
5.1 years ago by
United States
James W. MacDonald45k wrote:
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 COMMENTlink written 5.1 years ago by James W. MacDonald45k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 111 users visited in the last hour