Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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!

  • #2
    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.

    Comment


    • #3
      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.

      Comment


      • #4
        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.

        Comment

        Latest Articles

        Collapse

        • seqadmin
          Essential Discoveries and Tools in Epitranscriptomics
          by seqadmin




          The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist...
          Yesterday, 07:01 AM
        • seqadmin
          Current Approaches to Protein Sequencing
          by seqadmin


          Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
          04-04-2024, 04:25 PM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by seqadmin, 04-11-2024, 12:08 PM
        0 responses
        57 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-10-2024, 10:19 PM
        0 responses
        53 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-10-2024, 09:21 AM
        0 responses
        45 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-04-2024, 09:00 AM
        0 responses
        55 views
        0 likes
        Last Post seqadmin  
        Working...
        X