SEQanswers

Go Back   SEQanswers > Bioinformatics > Bioinformatics



Similar Threads
Thread Thread Starter Forum Replies Last Post
extract dendrogram information from heatmap generated by heatmap.2 crazyhottommy Bioinformatics 6 11-24-2014 09:45 AM
what's wrong with heatmap.2, heatmap turns to blue after finishing plotting crazyhottommy Bioinformatics 3 08-20-2013 11:02 AM
k- means clustering of chipseq peak data wrt to TSS honey Bioinformatics 5 06-21-2012 02:12 PM
first read in a pair means F3 or R3? yhong General 1 08-24-2011 09:10 AM
what does it means Moodi Genomic Resequencing 2 01-24-2011 04:55 PM

Reply
 
Thread Tools
Old 09-09-2013, 08:39 AM   #1
crazyhottommy
Senior Member
 
Location: Gainesville

Join Date: Apr 2012
Posts: 140
Default K-means clustering and heatmap

Hi everyone,

I was plotting a ChIP-seq data using the pheatmap, see code below:

km<- kmeans(m1,2) # determin how many cluster you want, I specify 2 here

m.kmeans<- cbind(m1, km$cluster) # combine the cluster with the matrix

dim(m.kmeans)
# [1] 903 602
# the last column is 602
o<- order(m.kmeans[,602]) # order the last column

m.kmeans<- m.kmeans[o,] # order the matrix according to the order of the last column

pheatmap( m.kmeans[,1:601], cluster_rows = F, cluster_cols = F, col= hmcols, breaks = bk, legend=FALSE, show_rownames=FALSE, show_colnames=FALSE)

It works fine for me, I clustered the data to two groups by specifying K=2, the problem is that group 1 sometimes shows up in the upper part of the heatmap, sometimes it shows up in the bottom part of the figure if I plot it several times.

I think it has to do with the assignment of the group number, say, the first group is assigned to 1, the other is assigned to 2. However, next time if you plot the same data, the first group assigned to 2, the other is assigned to 1. R randomly assigns the number to the groups.

How can control this?

Thank you every much!
crazyhottommy is offline   Reply With Quote
Old 09-09-2013, 09:56 AM   #2
JackieBadger
Senior Member
 
Location: Halifax, Nova Scotia

Join Date: Mar 2009
Posts: 380
Default

I have had the same issues using k-means clustering and discriminate analysis of principle components (DAPC) package. While I can't answer your question, the package has a help mailing list that may be able to provide a solution.
JackieBadger is offline   Reply With Quote
Old 09-10-2013, 04:13 AM   #3
jmw86069
Member
 
Location: RTP, NC, USA

Join Date: Jun 2009
Posts: 28
Default

Easiest fix is to call set.seed(123); before you run k-means, and/or before you run pheatmap. Depends upon which step(s) you want to be reproducible. If it is just the order on the heatmap itself, where you're not re-running k-means, you can also precompute the row dendrogram and send it to pheatmap. Doing it that way may be better for you in the long run since it gives you more control over how the clustering is scored and linked. I recommend hcluster() from the amap package, it is much faster than default hclust, as fast as other competing hclust replacements, but also offers scoring by a few types of correlation.
jmw86069 is offline   Reply With Quote
Old 02-04-2014, 09:12 PM   #4
scyxr
Junior Member
 
Location: iowa

Join Date: Sep 2012
Posts: 2
Default

The same issue for me all the time. How can we assign each cluster number such as cluster 1 ,cluster 2 into the heat map. Hopefully someones knowing about this could give us the help.
Thx.
scyxr is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 01:18 PM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO