cola Report for GDS4238

Date: 2019-12-25 21:20:11 CET, cola version: 1.3.2


Summary

All available functions which can be applied to this res_list object:

res_list
#> A 'ConsensusPartitionList' object with 24 methods.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows are extracted by 'SD, CV, MAD, ATC' methods.
#>   Subgroups are detected by 'hclust, kmeans, skmeans, pam, mclust, NMF' method.
#>   Number of partitions are tried for k = 2, 3, 4, 5, 6.
#>   Performed in total 30000 partitions by row resampling.
#> 
#> Following methods can be applied to this 'ConsensusPartitionList' object:
#>  [1] "cola_report"           "collect_classes"       "collect_plots"         "collect_stats"        
#>  [5] "colnames"              "functional_enrichment" "get_anno_col"          "get_anno"             
#>  [9] "get_classes"           "get_matrix"            "get_membership"        "get_stats"            
#> [13] "is_best_k"             "is_stable_k"           "ncol"                  "nrow"                 
#> [17] "rownames"              "show"                  "suggest_best_k"        "test_to_known_factors"
#> [21] "top_rows_heatmap"      "top_rows_overlap"     
#> 
#> You can get result for a single method by, e.g. object["SD", "hclust"] or object["SD:hclust"]
#> or a subset of methods by object[c("SD", "CV")], c("hclust", "kmeans")]

The call of run_all_consensus_partition_methods() was:

#> run_all_consensus_partition_methods(data = mat, mc.cores = 4, anno = anno)

Dimension of the input matrix:

mat = get_matrix(res_list)
dim(mat)
#> [1] 21163   169

Density distribution

The density distribution for each sample is visualized as in one column in the following heatmap. The clustering is based on the distance which is the Kolmogorov-Smirnov statistic between two distributions.

library(ComplexHeatmap)
densityHeatmap(mat, top_annotation = HeatmapAnnotation(df = get_anno(res_list), 
    col = get_anno_col(res_list)), ylab = "value", cluster_columns = TRUE, show_column_names = FALSE,
    mc.cores = 4)

plot of chunk density-heatmap

Suggest the best k

Folowing table shows the best k (number of partitions) for each combination of top-value methods and partition methods. Clicking on the method name in the table goes to the section for a single combination of methods.

The cola vignette explains the definition of the metrics used for determining the best number of partitions.

suggest_best_k(res_list)
The best k 1-PAC Mean silhouette Concordance Optional k
SD:NMF 2 1.000 0.969 0.988 **
MAD:kmeans 2 1.000 0.996 0.998 **
ATC:kmeans 2 1.000 1.000 1.000 **
ATC:pam 2 1.000 0.997 0.998 **
ATC:mclust 3 1.000 0.973 0.986 ** 2
ATC:skmeans 4 0.964 0.934 0.963 ** 2,3
MAD:NMF 3 0.958 0.947 0.977 ** 2
MAD:skmeans 6 0.955 0.912 0.920 ** 2,3,4,5
ATC:NMF 3 0.953 0.936 0.971 ** 2
SD:skmeans 6 0.949 0.882 0.898 * 2,5
CV:skmeans 6 0.941 0.916 0.924 * 2,5
SD:pam 5 0.928 0.887 0.953 * 2,4
CV:NMF 3 0.921 0.916 0.965 * 2
MAD:pam 5 0.919 0.846 0.938 * 2
CV:pam 5 0.918 0.899 0.955 * 2,3,4
MAD:hclust 3 0.910 0.887 0.961 * 2
ATC:hclust 6 0.900 0.879 0.912 * 2,3,4
MAD:mclust 2 0.896 0.966 0.984
SD:hclust 5 0.764 0.837 0.889
CV:mclust 3 0.740 0.872 0.919
CV:hclust 4 0.715 0.708 0.836
SD:mclust 2 0.673 0.912 0.939
SD:kmeans 2 0.548 0.947 0.939
CV:kmeans 2 0.511 0.914 0.903

**: 1-PAC > 0.95, *: 1-PAC > 0.9

CDF of consensus matrices

Cumulative distribution function curves of consensus matrix for all methods.

collect_plots(res_list, fun = plot_ecdf)

plot of chunk collect-plots

Consensus heatmap

Consensus heatmaps for all methods. (What is a consensus heatmap?)

collect_plots(res_list, k = 2, fun = consensus_heatmap, mc.cores = 4)

plot of chunk tab-collect-consensus-heatmap-1

Membership heatmap

Membership heatmaps for all methods. (What is a membership heatmap?)

collect_plots(res_list, k = 2, fun = membership_heatmap, mc.cores = 4)

plot of chunk tab-collect-membership-heatmap-1

Signature heatmap

Signature heatmaps for all methods. (What is a signature heatmap?)

Note in following heatmaps, rows are scaled.

collect_plots(res_list, k = 2, fun = get_signatures, mc.cores = 4)

plot of chunk tab-collect-get-signatures-1

Statistics table

The statistics used for measuring the stability of consensus partitioning. (How are they defined?)

get_stats(res_list, k = 2)
#>             k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> SD:NMF      2 1.000           0.969       0.988          0.487 0.514   0.514
#> CV:NMF      2 1.000           0.965       0.982          0.485 0.512   0.512
#> MAD:NMF     2 1.000           0.982       0.993          0.479 0.524   0.524
#> ATC:NMF     2 1.000           0.998       0.999          0.474 0.527   0.527
#> SD:skmeans  2 1.000           0.977       0.990          0.488 0.512   0.512
#> CV:skmeans  2 1.000           0.971       0.989          0.485 0.512   0.512
#> MAD:skmeans 2 1.000           0.984       0.993          0.482 0.521   0.521
#> ATC:skmeans 2 1.000           1.000       1.000          0.474 0.527   0.527
#> SD:mclust   2 0.673           0.912       0.939          0.478 0.501   0.501
#> CV:mclust   2 0.434           0.796       0.897          0.486 0.499   0.499
#> MAD:mclust  2 0.896           0.966       0.984          0.477 0.530   0.530
#> ATC:mclust  2 1.000           0.976       0.988          0.501 0.497   0.497
#> SD:kmeans   2 0.548           0.947       0.939          0.456 0.527   0.527
#> CV:kmeans   2 0.511           0.914       0.903          0.442 0.527   0.527
#> MAD:kmeans  2 1.000           0.996       0.998          0.475 0.527   0.527
#> ATC:kmeans  2 1.000           1.000       1.000          0.471 0.530   0.530
#> SD:pam      2 0.936           0.909       0.965          0.496 0.502   0.502
#> CV:pam      2 0.998           0.961       0.983          0.501 0.500   0.500
#> MAD:pam     2 0.922           0.930       0.969          0.477 0.530   0.530
#> ATC:pam     2 1.000           0.997       0.998          0.474 0.527   0.527
#> SD:hclust   2 0.837           0.858       0.948          0.199 0.799   0.799
#> CV:hclust   2 0.837           0.878       0.952          0.184 0.878   0.878
#> MAD:hclust  2 0.905           0.901       0.964          0.447 0.563   0.563
#> ATC:hclust  2 1.000           0.976       0.989          0.431 0.576   0.576

Following heatmap plots the partition for each combination of methods and the lightness correspond to the silhouette scores for samples in each method. On top the consensus subgroup is inferred from all methods by taking the mean silhouette scores as weight.

collect_stats(res_list, k = 2)

plot of chunk tab-collect-stats-from-consensus-partition-list-1

Partition from all methods

Collect partitions from all methods:

collect_classes(res_list, k = 2)

plot of chunk tab-collect-classes-from-consensus-partition-list-1

Top rows overlap

Overlap of top rows from different top-row methods:

top_rows_overlap(res_list, top_n = 1000, method = "euler")

plot of chunk tab-top-rows-overlap-by-euler-1

Also visualize the correspondance of rankings between different top-row methods:

top_rows_overlap(res_list, top_n = 1000, method = "correspondance")

plot of chunk tab-top-rows-overlap-by-correspondance-1

Heatmaps of the top rows:

top_rows_heatmap(res_list, top_n = 1000)

plot of chunk tab-top-rows-heatmap-1

Test to known annotations

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res_list, k = 2)
#>               n agent(p) dose(p)  time(p) k
#> SD:NMF      167    0.860  0.9988 3.81e-27 2
#> CV:NMF      167    0.860  0.9988 3.81e-27 2
#> MAD:NMF     168    0.866  0.9999 1.39e-28 2
#> ATC:NMF     169    0.907  1.0000 1.43e-29 2
#> SD:skmeans  169    0.863  0.9992 4.57e-27 2
#> CV:skmeans  165    0.861  0.9998 1.74e-27 2
#> MAD:skmeans 169    0.832  0.9999 3.84e-28 2
#> ATC:skmeans 169    0.907  1.0000 1.43e-29 2
#> SD:mclust   166    0.997  0.9971 4.95e-27 2
#> CV:mclust   152    0.845  0.9698 8.25e-25 2
#> MAD:mclust  168    0.903  0.9989 2.34e-29 2
#> ATC:mclust  168    0.986  0.9756 1.43e-27 2
#> SD:kmeans   168    0.901  1.0000 2.29e-29 2
#> CV:kmeans   167    0.891  1.0000 3.65e-29 2
#> MAD:kmeans  169    0.907  1.0000 1.43e-29 2
#> ATC:kmeans  169    0.891  0.9925 1.01e-28 2
#> SD:pam      160    0.578  0.9280 7.77e-24 2
#> CV:pam      168    0.523  0.9108 4.51e-23 2
#> MAD:pam     165    0.890  0.9912 6.56e-28 2
#> ATC:pam     169    0.907  1.0000 1.43e-29 2
#> SD:hclust   154    0.025  0.0408 1.49e-09 2
#> CV:hclust   154    0.025  0.0408 1.49e-09 2
#> MAD:hclust  157    0.759  0.9919 5.29e-27 2
#> ATC:hclust  167    0.627  0.9420 7.59e-25 2

Results for each method


SD:hclust

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["SD", "hclust"]
# you can also extract it by
# res = res_list["SD:hclust"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'SD' method.
#>   Subgroups are detected by 'hclust' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 5.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk SD-hclust-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk SD-hclust-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.837           0.858       0.948         0.1994 0.799   0.799
#> 3 3 0.378           0.771       0.835         1.6748 0.558   0.478
#> 4 4 0.713           0.752       0.838         0.2572 0.822   0.618
#> 5 5 0.764           0.837       0.889         0.0844 0.949   0.832
#> 6 6 0.862           0.836       0.902         0.0568 0.953   0.828

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 5

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     1  0.0000      0.959 1.000 0.000
#> GSM528682     1  0.0000      0.959 1.000 0.000
#> GSM528683     1  0.0000      0.959 1.000 0.000
#> GSM528684     1  0.0000      0.959 1.000 0.000
#> GSM528687     1  0.0000      0.959 1.000 0.000
#> GSM528688     1  0.0000      0.959 1.000 0.000
#> GSM528685     1  0.0000      0.959 1.000 0.000
#> GSM528686     1  0.0000      0.959 1.000 0.000
#> GSM528693     1  0.5408      0.796 0.876 0.124
#> GSM528694     1  0.5408      0.796 0.876 0.124
#> GSM528695     1  0.5737      0.776 0.864 0.136
#> GSM528696     1  0.5737      0.776 0.864 0.136
#> GSM528697     1  0.9933     -0.208 0.548 0.452
#> GSM528698     1  0.9933     -0.208 0.548 0.452
#> GSM528699     1  1.0000     -0.364 0.504 0.496
#> GSM528700     1  1.0000     -0.364 0.504 0.496
#> GSM528689     2  1.0000      0.352 0.496 0.504
#> GSM528690     2  1.0000      0.352 0.496 0.504
#> GSM528691     2  1.0000      0.352 0.496 0.504
#> GSM528692     2  1.0000      0.352 0.496 0.504
#> GSM528779     1  0.0000      0.959 1.000 0.000
#> GSM528780     1  0.0000      0.959 1.000 0.000
#> GSM528782     1  0.0000      0.959 1.000 0.000
#> GSM528781     1  0.0000      0.959 1.000 0.000
#> GSM528785     1  0.0000      0.959 1.000 0.000
#> GSM528786     1  0.0000      0.959 1.000 0.000
#> GSM528787     1  0.0000      0.959 1.000 0.000
#> GSM528788     1  0.0938      0.953 0.988 0.012
#> GSM528783     1  0.2423      0.925 0.960 0.040
#> GSM528784     2  0.1633      0.753 0.024 0.976
#> GSM528759     1  0.0938      0.953 0.988 0.012
#> GSM528760     1  0.0938      0.953 0.988 0.012
#> GSM528761     1  0.0000      0.959 1.000 0.000
#> GSM528762     1  0.0000      0.959 1.000 0.000
#> GSM528765     1  0.0000      0.959 1.000 0.000
#> GSM528766     1  0.0000      0.959 1.000 0.000
#> GSM528763     1  0.0000      0.959 1.000 0.000
#> GSM528764     1  0.0000      0.959 1.000 0.000
#> GSM528771     1  0.0000      0.959 1.000 0.000
#> GSM528772     1  0.0000      0.959 1.000 0.000
#> GSM528773     1  0.0000      0.959 1.000 0.000
#> GSM528774     1  0.0000      0.959 1.000 0.000
#> GSM528775     1  0.0000      0.959 1.000 0.000
#> GSM528776     1  0.0938      0.953 0.988 0.012
#> GSM528777     1  0.0938      0.953 0.988 0.012
#> GSM528778     1  0.0938      0.953 0.988 0.012
#> GSM528767     2  0.1633      0.753 0.024 0.976
#> GSM528768     2  0.1633      0.753 0.024 0.976
#> GSM528769     2  0.1633      0.753 0.024 0.976
#> GSM528770     2  0.1633      0.753 0.024 0.976
#> GSM528671     1  0.0000      0.959 1.000 0.000
#> GSM528672     1  0.0000      0.959 1.000 0.000
#> GSM528674     1  0.0000      0.959 1.000 0.000
#> GSM528673     1  0.0000      0.959 1.000 0.000
#> GSM528677     1  0.0000      0.959 1.000 0.000
#> GSM528678     1  0.0000      0.959 1.000 0.000
#> GSM528679     1  0.0938      0.953 0.988 0.012
#> GSM528680     1  0.9896     -0.161 0.560 0.440
#> GSM528675     2  0.0000      0.751 0.000 1.000
#> GSM528676     2  0.0000      0.751 0.000 1.000
#> GSM528651     1  0.0000      0.959 1.000 0.000
#> GSM528652     1  0.0000      0.959 1.000 0.000
#> GSM528653     1  0.0000      0.959 1.000 0.000
#> GSM528654     1  0.0000      0.959 1.000 0.000
#> GSM528657     1  0.0000      0.959 1.000 0.000
#> GSM528658     1  0.0000      0.959 1.000 0.000
#> GSM528655     1  0.0000      0.959 1.000 0.000
#> GSM528656     1  0.0000      0.959 1.000 0.000
#> GSM528663     1  0.0000      0.959 1.000 0.000
#> GSM528664     1  0.0000      0.959 1.000 0.000
#> GSM528665     1  0.0000      0.959 1.000 0.000
#> GSM528666     1  0.0000      0.959 1.000 0.000
#> GSM528667     1  0.0938      0.953 0.988 0.012
#> GSM528668     1  0.0938      0.953 0.988 0.012
#> GSM528669     1  0.0938      0.953 0.988 0.012
#> GSM528670     1  0.0938      0.953 0.988 0.012
#> GSM528659     2  0.0000      0.751 0.000 1.000
#> GSM528660     2  0.0000      0.751 0.000 1.000
#> GSM528661     2  0.0000      0.751 0.000 1.000
#> GSM528662     2  0.0000      0.751 0.000 1.000
#> GSM528701     1  0.0000      0.959 1.000 0.000
#> GSM528702     1  0.0000      0.959 1.000 0.000
#> GSM528703     1  0.0000      0.959 1.000 0.000
#> GSM528704     1  0.0000      0.959 1.000 0.000
#> GSM528707     1  0.0000      0.959 1.000 0.000
#> GSM528708     1  0.0000      0.959 1.000 0.000
#> GSM528705     1  0.0000      0.959 1.000 0.000
#> GSM528706     1  0.0000      0.959 1.000 0.000
#> GSM528713     1  0.0000      0.959 1.000 0.000
#> GSM528714     1  0.0000      0.959 1.000 0.000
#> GSM528715     1  0.0000      0.959 1.000 0.000
#> GSM528716     1  0.0000      0.959 1.000 0.000
#> GSM528717     1  0.5737      0.785 0.864 0.136
#> GSM528718     1  0.5737      0.785 0.864 0.136
#> GSM528719     1  1.0000     -0.364 0.504 0.496
#> GSM528720     1  1.0000     -0.364 0.504 0.496
#> GSM528709     2  1.0000      0.352 0.496 0.504
#> GSM528710     2  1.0000      0.352 0.496 0.504
#> GSM528711     2  1.0000      0.352 0.496 0.504
#> GSM528712     2  1.0000      0.352 0.496 0.504
#> GSM528721     1  0.0000      0.959 1.000 0.000
#> GSM528722     1  0.0000      0.959 1.000 0.000
#> GSM528723     1  0.0000      0.959 1.000 0.000
#> GSM528724     1  0.0000      0.959 1.000 0.000
#> GSM528727     1  0.0000      0.959 1.000 0.000
#> GSM528728     1  0.0000      0.959 1.000 0.000
#> GSM528725     1  0.0000      0.959 1.000 0.000
#> GSM528726     1  0.0000      0.959 1.000 0.000
#> GSM528733     1  0.0000      0.959 1.000 0.000
#> GSM528734     1  0.0000      0.959 1.000 0.000
#> GSM528735     1  0.0938      0.953 0.988 0.012
#> GSM528736     1  0.0938      0.953 0.988 0.012
#> GSM528737     1  0.0938      0.953 0.988 0.012
#> GSM528738     1  0.0938      0.953 0.988 0.012
#> GSM528729     1  0.0938      0.953 0.988 0.012
#> GSM528730     1  0.0938      0.953 0.988 0.012
#> GSM528731     1  0.0938      0.953 0.988 0.012
#> GSM528732     1  0.0938      0.953 0.988 0.012
#> GSM528739     1  0.0000      0.959 1.000 0.000
#> GSM528740     1  0.0000      0.959 1.000 0.000
#> GSM528741     1  0.0000      0.959 1.000 0.000
#> GSM528742     1  0.0000      0.959 1.000 0.000
#> GSM528745     1  0.0000      0.959 1.000 0.000
#> GSM528746     1  0.0000      0.959 1.000 0.000
#> GSM528743     1  0.0000      0.959 1.000 0.000
#> GSM528744     1  0.0000      0.959 1.000 0.000
#> GSM528751     1  0.0000      0.959 1.000 0.000
#> GSM528752     1  0.0000      0.959 1.000 0.000
#> GSM528753     1  0.0000      0.959 1.000 0.000
#> GSM528754     1  0.0000      0.959 1.000 0.000
#> GSM528755     1  0.0376      0.957 0.996 0.004
#> GSM528756     1  0.0376      0.957 0.996 0.004
#> GSM528757     1  0.0938      0.953 0.988 0.012
#> GSM528758     1  0.0938      0.953 0.988 0.012
#> GSM528747     1  0.0938      0.953 0.988 0.012
#> GSM528748     1  0.0938      0.953 0.988 0.012
#> GSM528749     1  0.0938      0.953 0.988 0.012
#> GSM528750     1  0.0938      0.953 0.988 0.012
#> GSM528640     1  0.0000      0.959 1.000 0.000
#> GSM528641     1  0.0000      0.959 1.000 0.000
#> GSM528643     1  0.0000      0.959 1.000 0.000
#> GSM528644     1  0.0938      0.953 0.988 0.012
#> GSM528642     1  0.0938      0.953 0.988 0.012
#> GSM528620     1  0.0000      0.959 1.000 0.000
#> GSM528621     1  0.0000      0.959 1.000 0.000
#> GSM528623     1  0.0000      0.959 1.000 0.000
#> GSM528624     1  0.0938      0.953 0.988 0.012
#> GSM528622     1  0.0938      0.953 0.988 0.012
#> GSM528625     1  0.0000      0.959 1.000 0.000
#> GSM528626     1  0.0000      0.959 1.000 0.000
#> GSM528628     1  0.0000      0.959 1.000 0.000
#> GSM528629     1  0.0938      0.953 0.988 0.012
#> GSM528627     1  0.0938      0.953 0.988 0.012
#> GSM528630     1  0.0000      0.959 1.000 0.000
#> GSM528631     1  0.0000      0.959 1.000 0.000
#> GSM528632     1  0.0000      0.959 1.000 0.000
#> GSM528633     1  0.0000      0.959 1.000 0.000
#> GSM528636     1  0.0000      0.959 1.000 0.000
#> GSM528637     1  0.0000      0.959 1.000 0.000
#> GSM528638     1  0.0938      0.953 0.988 0.012
#> GSM528639     1  0.0938      0.953 0.988 0.012
#> GSM528634     1  0.0938      0.953 0.988 0.012
#> GSM528635     1  0.0938      0.953 0.988 0.012
#> GSM528645     1  0.0000      0.959 1.000 0.000
#> GSM528646     1  0.0000      0.959 1.000 0.000
#> GSM528647     1  0.0000      0.959 1.000 0.000
#> GSM528648     1  0.0938      0.953 0.988 0.012
#> GSM528649     1  0.0938      0.953 0.988 0.012
#> GSM528650     1  0.0938      0.953 0.988 0.012

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-SD-hclust-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-SD-hclust-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-SD-hclust-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-SD-hclust-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk SD-hclust-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-SD-hclust-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk SD-hclust-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>             n agent(p) dose(p)  time(p) k
#> SD:hclust 154 0.024981 0.04080 1.49e-09 2
#> SD:hclust 150 0.044756 0.08137 3.21e-31 3
#> SD:hclust 142 0.101854 0.14131 7.18e-45 4
#> SD:hclust 157 0.000129 0.00212 9.14e-47 5
#> SD:hclust 155 0.000444 0.00476 5.47e-73 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


SD:kmeans

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["SD", "kmeans"]
# you can also extract it by
# res = res_list["SD:kmeans"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'SD' method.
#>   Subgroups are detected by 'kmeans' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 2.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk SD-kmeans-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk SD-kmeans-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.548           0.947       0.939         0.4559 0.527   0.527
#> 3 3 0.779           0.742       0.865         0.4025 0.842   0.701
#> 4 4 0.697           0.724       0.784         0.1137 0.883   0.697
#> 5 5 0.814           0.905       0.891         0.0734 0.920   0.728
#> 6 6 0.859           0.843       0.855         0.0432 0.995   0.978

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 2

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2   0.000      1.000 0.000 1.000
#> GSM528682     2   0.000      1.000 0.000 1.000
#> GSM528683     2   0.000      1.000 0.000 1.000
#> GSM528684     2   0.000      1.000 0.000 1.000
#> GSM528687     2   0.000      1.000 0.000 1.000
#> GSM528688     2   0.000      1.000 0.000 1.000
#> GSM528685     2   0.000      1.000 0.000 1.000
#> GSM528686     2   0.000      1.000 0.000 1.000
#> GSM528693     1   0.541      0.944 0.876 0.124
#> GSM528694     1   0.541      0.944 0.876 0.124
#> GSM528695     1   0.184      0.907 0.972 0.028
#> GSM528696     1   0.184      0.907 0.972 0.028
#> GSM528697     1   0.000      0.895 1.000 0.000
#> GSM528698     1   0.000      0.895 1.000 0.000
#> GSM528699     1   0.000      0.895 1.000 0.000
#> GSM528700     1   0.000      0.895 1.000 0.000
#> GSM528689     1   0.000      0.895 1.000 0.000
#> GSM528690     1   0.000      0.895 1.000 0.000
#> GSM528691     1   0.000      0.895 1.000 0.000
#> GSM528692     1   0.000      0.895 1.000 0.000
#> GSM528779     2   0.000      1.000 0.000 1.000
#> GSM528780     2   0.000      1.000 0.000 1.000
#> GSM528782     2   0.000      1.000 0.000 1.000
#> GSM528781     2   0.000      1.000 0.000 1.000
#> GSM528785     1   0.839      0.785 0.732 0.268
#> GSM528786     1   0.541      0.944 0.876 0.124
#> GSM528787     1   0.541      0.944 0.876 0.124
#> GSM528788     1   0.541      0.944 0.876 0.124
#> GSM528783     1   0.311      0.920 0.944 0.056
#> GSM528784     1   0.000      0.895 1.000 0.000
#> GSM528759     1   0.541      0.944 0.876 0.124
#> GSM528760     1   0.541      0.944 0.876 0.124
#> GSM528761     2   0.000      1.000 0.000 1.000
#> GSM528762     2   0.000      1.000 0.000 1.000
#> GSM528765     2   0.000      1.000 0.000 1.000
#> GSM528766     2   0.000      1.000 0.000 1.000
#> GSM528763     2   0.000      1.000 0.000 1.000
#> GSM528764     2   0.000      1.000 0.000 1.000
#> GSM528771     1   0.827      0.796 0.740 0.260
#> GSM528772     1   0.808      0.813 0.752 0.248
#> GSM528773     1   0.541      0.944 0.876 0.124
#> GSM528774     1   0.541      0.944 0.876 0.124
#> GSM528775     1   0.541      0.944 0.876 0.124
#> GSM528776     1   0.482      0.938 0.896 0.104
#> GSM528777     1   0.430      0.932 0.912 0.088
#> GSM528778     1   0.430      0.932 0.912 0.088
#> GSM528767     1   0.000      0.895 1.000 0.000
#> GSM528768     1   0.000      0.895 1.000 0.000
#> GSM528769     1   0.000      0.895 1.000 0.000
#> GSM528770     1   0.000      0.895 1.000 0.000
#> GSM528671     2   0.000      1.000 0.000 1.000
#> GSM528672     2   0.000      1.000 0.000 1.000
#> GSM528674     2   0.000      1.000 0.000 1.000
#> GSM528673     2   0.000      1.000 0.000 1.000
#> GSM528677     1   0.541      0.944 0.876 0.124
#> GSM528678     1   0.541      0.944 0.876 0.124
#> GSM528679     1   0.358      0.924 0.932 0.068
#> GSM528680     1   0.000      0.895 1.000 0.000
#> GSM528675     1   0.000      0.895 1.000 0.000
#> GSM528676     1   0.000      0.895 1.000 0.000
#> GSM528651     2   0.000      1.000 0.000 1.000
#> GSM528652     2   0.000      1.000 0.000 1.000
#> GSM528653     2   0.000      1.000 0.000 1.000
#> GSM528654     2   0.000      1.000 0.000 1.000
#> GSM528657     2   0.000      1.000 0.000 1.000
#> GSM528658     2   0.000      1.000 0.000 1.000
#> GSM528655     2   0.000      1.000 0.000 1.000
#> GSM528656     2   0.000      1.000 0.000 1.000
#> GSM528663     1   0.929      0.656 0.656 0.344
#> GSM528664     1   0.995      0.381 0.540 0.460
#> GSM528665     1   0.541      0.944 0.876 0.124
#> GSM528666     1   0.541      0.944 0.876 0.124
#> GSM528667     1   0.541      0.944 0.876 0.124
#> GSM528668     1   0.541      0.944 0.876 0.124
#> GSM528669     1   0.541      0.944 0.876 0.124
#> GSM528670     1   0.541      0.944 0.876 0.124
#> GSM528659     1   0.000      0.895 1.000 0.000
#> GSM528660     1   0.000      0.895 1.000 0.000
#> GSM528661     1   0.000      0.895 1.000 0.000
#> GSM528662     1   0.000      0.895 1.000 0.000
#> GSM528701     2   0.000      1.000 0.000 1.000
#> GSM528702     2   0.000      1.000 0.000 1.000
#> GSM528703     2   0.000      1.000 0.000 1.000
#> GSM528704     2   0.000      1.000 0.000 1.000
#> GSM528707     2   0.000      1.000 0.000 1.000
#> GSM528708     2   0.000      1.000 0.000 1.000
#> GSM528705     2   0.000      1.000 0.000 1.000
#> GSM528706     2   0.000      1.000 0.000 1.000
#> GSM528713     1   0.541      0.944 0.876 0.124
#> GSM528714     1   0.541      0.944 0.876 0.124
#> GSM528715     1   0.541      0.944 0.876 0.124
#> GSM528716     1   0.541      0.944 0.876 0.124
#> GSM528717     1   0.000      0.895 1.000 0.000
#> GSM528718     1   0.000      0.895 1.000 0.000
#> GSM528719     1   0.000      0.895 1.000 0.000
#> GSM528720     1   0.000      0.895 1.000 0.000
#> GSM528709     1   0.000      0.895 1.000 0.000
#> GSM528710     1   0.000      0.895 1.000 0.000
#> GSM528711     1   0.000      0.895 1.000 0.000
#> GSM528712     1   0.000      0.895 1.000 0.000
#> GSM528721     2   0.000      1.000 0.000 1.000
#> GSM528722     2   0.000      1.000 0.000 1.000
#> GSM528723     2   0.000      1.000 0.000 1.000
#> GSM528724     2   0.000      1.000 0.000 1.000
#> GSM528727     2   0.000      1.000 0.000 1.000
#> GSM528728     2   0.000      1.000 0.000 1.000
#> GSM528725     2   0.000      1.000 0.000 1.000
#> GSM528726     2   0.000      1.000 0.000 1.000
#> GSM528733     1   0.541      0.944 0.876 0.124
#> GSM528734     1   0.541      0.944 0.876 0.124
#> GSM528735     1   0.541      0.944 0.876 0.124
#> GSM528736     1   0.541      0.944 0.876 0.124
#> GSM528737     1   0.541      0.944 0.876 0.124
#> GSM528738     1   0.541      0.944 0.876 0.124
#> GSM528729     1   0.541      0.944 0.876 0.124
#> GSM528730     1   0.541      0.944 0.876 0.124
#> GSM528731     1   0.541      0.944 0.876 0.124
#> GSM528732     1   0.541      0.944 0.876 0.124
#> GSM528739     2   0.000      1.000 0.000 1.000
#> GSM528740     2   0.000      1.000 0.000 1.000
#> GSM528741     2   0.000      1.000 0.000 1.000
#> GSM528742     2   0.000      1.000 0.000 1.000
#> GSM528745     2   0.000      1.000 0.000 1.000
#> GSM528746     2   0.000      1.000 0.000 1.000
#> GSM528743     2   0.000      1.000 0.000 1.000
#> GSM528744     2   0.000      1.000 0.000 1.000
#> GSM528751     1   0.808      0.813 0.752 0.248
#> GSM528752     1   0.802      0.818 0.756 0.244
#> GSM528753     1   0.541      0.944 0.876 0.124
#> GSM528754     1   0.541      0.944 0.876 0.124
#> GSM528755     1   0.541      0.944 0.876 0.124
#> GSM528756     1   0.541      0.944 0.876 0.124
#> GSM528757     1   0.541      0.944 0.876 0.124
#> GSM528758     1   0.541      0.944 0.876 0.124
#> GSM528747     1   0.541      0.944 0.876 0.124
#> GSM528748     1   0.541      0.944 0.876 0.124
#> GSM528749     1   0.541      0.944 0.876 0.124
#> GSM528750     1   0.541      0.944 0.876 0.124
#> GSM528640     2   0.000      1.000 0.000 1.000
#> GSM528641     2   0.000      1.000 0.000 1.000
#> GSM528643     1   0.541      0.944 0.876 0.124
#> GSM528644     1   0.541      0.944 0.876 0.124
#> GSM528642     1   0.541      0.944 0.876 0.124
#> GSM528620     2   0.000      1.000 0.000 1.000
#> GSM528621     2   0.000      1.000 0.000 1.000
#> GSM528623     1   0.541      0.944 0.876 0.124
#> GSM528624     1   0.541      0.944 0.876 0.124
#> GSM528622     1   0.541      0.944 0.876 0.124
#> GSM528625     2   0.000      1.000 0.000 1.000
#> GSM528626     2   0.000      1.000 0.000 1.000
#> GSM528628     1   0.541      0.944 0.876 0.124
#> GSM528629     1   0.541      0.944 0.876 0.124
#> GSM528627     1   0.541      0.944 0.876 0.124
#> GSM528630     2   0.000      1.000 0.000 1.000
#> GSM528631     2   0.000      1.000 0.000 1.000
#> GSM528632     2   0.000      1.000 0.000 1.000
#> GSM528633     2   0.000      1.000 0.000 1.000
#> GSM528636     1   0.541      0.944 0.876 0.124
#> GSM528637     1   0.541      0.944 0.876 0.124
#> GSM528638     1   0.541      0.944 0.876 0.124
#> GSM528639     1   0.541      0.944 0.876 0.124
#> GSM528634     1   0.541      0.944 0.876 0.124
#> GSM528635     1   0.541      0.944 0.876 0.124
#> GSM528645     1   0.541      0.944 0.876 0.124
#> GSM528646     1   0.541      0.944 0.876 0.124
#> GSM528647     1   0.541      0.944 0.876 0.124
#> GSM528648     1   0.541      0.944 0.876 0.124
#> GSM528649     1   0.541      0.944 0.876 0.124
#> GSM528650     1   0.541      0.944 0.876 0.124

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-SD-kmeans-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-SD-kmeans-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)
#> Error in mat[ceiling(1:nr/h_ratio), ceiling(1:nc/w_ratio), drop = FALSE]: subscript out of bounds

plot of chunk tab-SD-kmeans-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)
#> Error in mat[ceiling(1:nr/h_ratio), ceiling(1:nc/w_ratio), drop = FALSE]: subscript out of bounds

plot of chunk tab-SD-kmeans-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk SD-kmeans-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-SD-kmeans-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk SD-kmeans-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>             n agent(p)  dose(p)  time(p) k
#> SD:kmeans 168  0.90117 0.999961 2.29e-29 2
#> SD:kmeans 161  0.00872 0.001702 4.50e-33 3
#> SD:kmeans 141  0.00435 0.000542 1.21e-40 4
#> SD:kmeans 167  0.02873 0.013444 3.09e-73 5
#> SD:kmeans 168  0.02563 0.012512 9.35e-74 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


SD:skmeans*

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["SD", "skmeans"]
# you can also extract it by
# res = res_list["SD:skmeans"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'SD' method.
#>   Subgroups are detected by 'skmeans' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 6.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk SD-skmeans-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk SD-skmeans-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           0.977       0.990         0.4878 0.512   0.512
#> 3 3 0.835           0.927       0.953         0.3569 0.785   0.595
#> 4 4 0.795           0.880       0.895         0.1031 0.897   0.707
#> 5 5 0.997           0.961       0.978         0.0720 0.923   0.725
#> 6 6 0.949           0.882       0.898         0.0292 0.972   0.875

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 6
#> attr(,"optional")
#> [1] 2 5

There is also optional best \(k\) = 2 5 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2   0.000      0.985 0.000 1.000
#> GSM528682     2   0.000      0.985 0.000 1.000
#> GSM528683     2   0.000      0.985 0.000 1.000
#> GSM528684     2   0.000      0.985 0.000 1.000
#> GSM528687     2   0.000      0.985 0.000 1.000
#> GSM528688     2   0.000      0.985 0.000 1.000
#> GSM528685     2   0.000      0.985 0.000 1.000
#> GSM528686     2   0.000      0.985 0.000 1.000
#> GSM528693     1   0.000      0.992 1.000 0.000
#> GSM528694     1   0.000      0.992 1.000 0.000
#> GSM528695     1   0.000      0.992 1.000 0.000
#> GSM528696     1   0.000      0.992 1.000 0.000
#> GSM528697     1   0.000      0.992 1.000 0.000
#> GSM528698     1   0.000      0.992 1.000 0.000
#> GSM528699     1   0.000      0.992 1.000 0.000
#> GSM528700     1   0.000      0.992 1.000 0.000
#> GSM528689     1   0.000      0.992 1.000 0.000
#> GSM528690     1   0.000      0.992 1.000 0.000
#> GSM528691     1   0.000      0.992 1.000 0.000
#> GSM528692     1   0.000      0.992 1.000 0.000
#> GSM528779     2   0.000      0.985 0.000 1.000
#> GSM528780     2   0.000      0.985 0.000 1.000
#> GSM528782     2   0.000      0.985 0.000 1.000
#> GSM528781     2   0.000      0.985 0.000 1.000
#> GSM528785     2   0.795      0.691 0.240 0.760
#> GSM528786     1   0.000      0.992 1.000 0.000
#> GSM528787     1   0.000      0.992 1.000 0.000
#> GSM528788     1   0.000      0.992 1.000 0.000
#> GSM528783     1   0.000      0.992 1.000 0.000
#> GSM528784     1   0.000      0.992 1.000 0.000
#> GSM528759     1   0.000      0.992 1.000 0.000
#> GSM528760     1   0.000      0.992 1.000 0.000
#> GSM528761     2   0.000      0.985 0.000 1.000
#> GSM528762     2   0.000      0.985 0.000 1.000
#> GSM528765     2   0.000      0.985 0.000 1.000
#> GSM528766     2   0.000      0.985 0.000 1.000
#> GSM528763     2   0.000      0.985 0.000 1.000
#> GSM528764     2   0.000      0.985 0.000 1.000
#> GSM528771     2   0.753      0.729 0.216 0.784
#> GSM528772     2   0.795      0.691 0.240 0.760
#> GSM528773     1   0.000      0.992 1.000 0.000
#> GSM528774     1   0.000      0.992 1.000 0.000
#> GSM528775     1   0.000      0.992 1.000 0.000
#> GSM528776     1   0.000      0.992 1.000 0.000
#> GSM528777     1   0.000      0.992 1.000 0.000
#> GSM528778     1   0.000      0.992 1.000 0.000
#> GSM528767     1   0.000      0.992 1.000 0.000
#> GSM528768     1   0.000      0.992 1.000 0.000
#> GSM528769     1   0.000      0.992 1.000 0.000
#> GSM528770     1   0.000      0.992 1.000 0.000
#> GSM528671     2   0.000      0.985 0.000 1.000
#> GSM528672     2   0.000      0.985 0.000 1.000
#> GSM528674     2   0.000      0.985 0.000 1.000
#> GSM528673     2   0.000      0.985 0.000 1.000
#> GSM528677     1   0.689      0.775 0.816 0.184
#> GSM528678     1   0.000      0.992 1.000 0.000
#> GSM528679     1   0.000      0.992 1.000 0.000
#> GSM528680     1   0.000      0.992 1.000 0.000
#> GSM528675     1   0.000      0.992 1.000 0.000
#> GSM528676     1   0.000      0.992 1.000 0.000
#> GSM528651     2   0.000      0.985 0.000 1.000
#> GSM528652     2   0.000      0.985 0.000 1.000
#> GSM528653     2   0.000      0.985 0.000 1.000
#> GSM528654     2   0.000      0.985 0.000 1.000
#> GSM528657     2   0.000      0.985 0.000 1.000
#> GSM528658     2   0.000      0.985 0.000 1.000
#> GSM528655     2   0.000      0.985 0.000 1.000
#> GSM528656     2   0.000      0.985 0.000 1.000
#> GSM528663     2   0.000      0.985 0.000 1.000
#> GSM528664     2   0.000      0.985 0.000 1.000
#> GSM528665     1   0.000      0.992 1.000 0.000
#> GSM528666     1   0.000      0.992 1.000 0.000
#> GSM528667     1   0.000      0.992 1.000 0.000
#> GSM528668     1   0.000      0.992 1.000 0.000
#> GSM528669     1   0.000      0.992 1.000 0.000
#> GSM528670     1   0.000      0.992 1.000 0.000
#> GSM528659     1   0.000      0.992 1.000 0.000
#> GSM528660     1   0.000      0.992 1.000 0.000
#> GSM528661     1   0.000      0.992 1.000 0.000
#> GSM528662     1   0.000      0.992 1.000 0.000
#> GSM528701     2   0.000      0.985 0.000 1.000
#> GSM528702     2   0.000      0.985 0.000 1.000
#> GSM528703     2   0.000      0.985 0.000 1.000
#> GSM528704     2   0.000      0.985 0.000 1.000
#> GSM528707     2   0.000      0.985 0.000 1.000
#> GSM528708     2   0.000      0.985 0.000 1.000
#> GSM528705     2   0.000      0.985 0.000 1.000
#> GSM528706     2   0.000      0.985 0.000 1.000
#> GSM528713     1   0.653      0.798 0.832 0.168
#> GSM528714     1   0.671      0.786 0.824 0.176
#> GSM528715     1   0.000      0.992 1.000 0.000
#> GSM528716     1   0.000      0.992 1.000 0.000
#> GSM528717     1   0.000      0.992 1.000 0.000
#> GSM528718     1   0.000      0.992 1.000 0.000
#> GSM528719     1   0.000      0.992 1.000 0.000
#> GSM528720     1   0.000      0.992 1.000 0.000
#> GSM528709     1   0.000      0.992 1.000 0.000
#> GSM528710     1   0.000      0.992 1.000 0.000
#> GSM528711     1   0.000      0.992 1.000 0.000
#> GSM528712     1   0.000      0.992 1.000 0.000
#> GSM528721     2   0.000      0.985 0.000 1.000
#> GSM528722     2   0.000      0.985 0.000 1.000
#> GSM528723     2   0.000      0.985 0.000 1.000
#> GSM528724     2   0.000      0.985 0.000 1.000
#> GSM528727     2   0.000      0.985 0.000 1.000
#> GSM528728     2   0.000      0.985 0.000 1.000
#> GSM528725     2   0.000      0.985 0.000 1.000
#> GSM528726     2   0.000      0.985 0.000 1.000
#> GSM528733     1   0.000      0.992 1.000 0.000
#> GSM528734     1   0.000      0.992 1.000 0.000
#> GSM528735     1   0.000      0.992 1.000 0.000
#> GSM528736     1   0.000      0.992 1.000 0.000
#> GSM528737     1   0.000      0.992 1.000 0.000
#> GSM528738     1   0.000      0.992 1.000 0.000
#> GSM528729     1   0.000      0.992 1.000 0.000
#> GSM528730     1   0.000      0.992 1.000 0.000
#> GSM528731     1   0.000      0.992 1.000 0.000
#> GSM528732     1   0.000      0.992 1.000 0.000
#> GSM528739     2   0.000      0.985 0.000 1.000
#> GSM528740     2   0.000      0.985 0.000 1.000
#> GSM528741     2   0.000      0.985 0.000 1.000
#> GSM528742     2   0.000      0.985 0.000 1.000
#> GSM528745     2   0.000      0.985 0.000 1.000
#> GSM528746     2   0.000      0.985 0.000 1.000
#> GSM528743     2   0.000      0.985 0.000 1.000
#> GSM528744     2   0.000      0.985 0.000 1.000
#> GSM528751     2   0.866      0.604 0.288 0.712
#> GSM528752     1   0.795      0.684 0.760 0.240
#> GSM528753     1   0.000      0.992 1.000 0.000
#> GSM528754     1   0.000      0.992 1.000 0.000
#> GSM528755     1   0.000      0.992 1.000 0.000
#> GSM528756     1   0.000      0.992 1.000 0.000
#> GSM528757     1   0.000      0.992 1.000 0.000
#> GSM528758     1   0.000      0.992 1.000 0.000
#> GSM528747     1   0.000      0.992 1.000 0.000
#> GSM528748     1   0.000      0.992 1.000 0.000
#> GSM528749     1   0.000      0.992 1.000 0.000
#> GSM528750     1   0.000      0.992 1.000 0.000
#> GSM528640     2   0.000      0.985 0.000 1.000
#> GSM528641     2   0.000      0.985 0.000 1.000
#> GSM528643     1   0.000      0.992 1.000 0.000
#> GSM528644     1   0.000      0.992 1.000 0.000
#> GSM528642     1   0.000      0.992 1.000 0.000
#> GSM528620     2   0.000      0.985 0.000 1.000
#> GSM528621     2   0.000      0.985 0.000 1.000
#> GSM528623     1   0.000      0.992 1.000 0.000
#> GSM528624     1   0.000      0.992 1.000 0.000
#> GSM528622     1   0.000      0.992 1.000 0.000
#> GSM528625     2   0.000      0.985 0.000 1.000
#> GSM528626     2   0.000      0.985 0.000 1.000
#> GSM528628     1   0.000      0.992 1.000 0.000
#> GSM528629     1   0.000      0.992 1.000 0.000
#> GSM528627     1   0.000      0.992 1.000 0.000
#> GSM528630     2   0.000      0.985 0.000 1.000
#> GSM528631     2   0.000      0.985 0.000 1.000
#> GSM528632     2   0.000      0.985 0.000 1.000
#> GSM528633     2   0.000      0.985 0.000 1.000
#> GSM528636     1   0.000      0.992 1.000 0.000
#> GSM528637     1   0.000      0.992 1.000 0.000
#> GSM528638     1   0.000      0.992 1.000 0.000
#> GSM528639     1   0.000      0.992 1.000 0.000
#> GSM528634     1   0.000      0.992 1.000 0.000
#> GSM528635     1   0.000      0.992 1.000 0.000
#> GSM528645     1   0.000      0.992 1.000 0.000
#> GSM528646     1   0.000      0.992 1.000 0.000
#> GSM528647     1   0.000      0.992 1.000 0.000
#> GSM528648     1   0.000      0.992 1.000 0.000
#> GSM528649     1   0.000      0.992 1.000 0.000
#> GSM528650     1   0.000      0.992 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-SD-skmeans-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-SD-skmeans-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-SD-skmeans-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-SD-skmeans-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk SD-skmeans-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-SD-skmeans-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk SD-skmeans-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>              n agent(p) dose(p)  time(p) k
#> SD:skmeans 169 0.862532 0.99917 4.57e-27 2
#> SD:skmeans 169 0.450467 0.97873 1.40e-51 3
#> SD:skmeans 169 0.000677 0.00395 7.82e-53 4
#> SD:skmeans 168 0.006087 0.00749 4.13e-70 5
#> SD:skmeans 161 0.007267 0.00934 5.37e-95 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


SD:pam*

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["SD", "pam"]
# you can also extract it by
# res = res_list["SD:pam"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'SD' method.
#>   Subgroups are detected by 'pam' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 5.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk SD-pam-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk SD-pam-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.936           0.909       0.965          0.496 0.502   0.502
#> 3 3 0.808           0.876       0.934          0.227 0.850   0.714
#> 4 4 0.905           0.855       0.935          0.149 0.787   0.531
#> 5 5 0.928           0.887       0.953          0.097 0.909   0.708
#> 6 6 0.838           0.734       0.843          0.067 0.906   0.625

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 5
#> attr(,"optional")
#> [1] 2 4

There is also optional best \(k\) = 2 4 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2  0.0000     0.9498 0.000 1.000
#> GSM528682     2  0.0000     0.9498 0.000 1.000
#> GSM528683     2  0.0000     0.9498 0.000 1.000
#> GSM528684     2  0.0000     0.9498 0.000 1.000
#> GSM528687     2  0.0000     0.9498 0.000 1.000
#> GSM528688     2  0.0000     0.9498 0.000 1.000
#> GSM528685     2  0.1184     0.9401 0.016 0.984
#> GSM528686     2  0.1843     0.9323 0.028 0.972
#> GSM528693     1  0.0000     0.9738 1.000 0.000
#> GSM528694     1  0.0000     0.9738 1.000 0.000
#> GSM528695     1  0.0000     0.9738 1.000 0.000
#> GSM528696     1  0.0000     0.9738 1.000 0.000
#> GSM528697     1  0.0000     0.9738 1.000 0.000
#> GSM528698     1  0.0000     0.9738 1.000 0.000
#> GSM528699     2  1.0000     0.0674 0.496 0.504
#> GSM528700     1  0.0000     0.9738 1.000 0.000
#> GSM528689     1  0.0000     0.9738 1.000 0.000
#> GSM528690     1  0.1633     0.9526 0.976 0.024
#> GSM528691     1  0.0000     0.9738 1.000 0.000
#> GSM528692     1  0.0000     0.9738 1.000 0.000
#> GSM528779     2  0.0000     0.9498 0.000 1.000
#> GSM528780     2  0.0000     0.9498 0.000 1.000
#> GSM528782     2  0.0000     0.9498 0.000 1.000
#> GSM528781     2  0.0000     0.9498 0.000 1.000
#> GSM528785     1  0.4161     0.8895 0.916 0.084
#> GSM528786     1  0.0000     0.9738 1.000 0.000
#> GSM528787     1  0.0000     0.9738 1.000 0.000
#> GSM528788     1  0.9909     0.1708 0.556 0.444
#> GSM528783     1  0.0000     0.9738 1.000 0.000
#> GSM528784     1  0.0000     0.9738 1.000 0.000
#> GSM528759     1  0.0000     0.9738 1.000 0.000
#> GSM528760     1  0.0000     0.9738 1.000 0.000
#> GSM528761     2  0.0000     0.9498 0.000 1.000
#> GSM528762     2  0.0000     0.9498 0.000 1.000
#> GSM528765     2  0.0000     0.9498 0.000 1.000
#> GSM528766     2  0.0000     0.9498 0.000 1.000
#> GSM528763     2  0.0000     0.9498 0.000 1.000
#> GSM528764     2  0.0672     0.9452 0.008 0.992
#> GSM528771     1  0.0000     0.9738 1.000 0.000
#> GSM528772     1  0.0000     0.9738 1.000 0.000
#> GSM528773     1  0.0000     0.9738 1.000 0.000
#> GSM528774     1  0.0000     0.9738 1.000 0.000
#> GSM528775     1  0.0000     0.9738 1.000 0.000
#> GSM528776     1  0.0000     0.9738 1.000 0.000
#> GSM528777     2  0.9998     0.0324 0.492 0.508
#> GSM528778     1  0.9686     0.3217 0.604 0.396
#> GSM528767     1  0.0000     0.9738 1.000 0.000
#> GSM528768     1  0.0000     0.9738 1.000 0.000
#> GSM528769     1  0.0000     0.9738 1.000 0.000
#> GSM528770     1  0.0000     0.9738 1.000 0.000
#> GSM528671     2  0.0000     0.9498 0.000 1.000
#> GSM528672     2  0.0000     0.9498 0.000 1.000
#> GSM528674     2  0.0000     0.9498 0.000 1.000
#> GSM528673     2  0.1414     0.9374 0.020 0.980
#> GSM528677     1  0.0000     0.9738 1.000 0.000
#> GSM528678     1  0.0000     0.9738 1.000 0.000
#> GSM528679     1  0.0000     0.9738 1.000 0.000
#> GSM528680     1  0.0000     0.9738 1.000 0.000
#> GSM528675     1  0.0000     0.9738 1.000 0.000
#> GSM528676     1  0.0000     0.9738 1.000 0.000
#> GSM528651     2  0.0000     0.9498 0.000 1.000
#> GSM528652     2  0.0000     0.9498 0.000 1.000
#> GSM528653     2  0.0000     0.9498 0.000 1.000
#> GSM528654     2  0.0000     0.9498 0.000 1.000
#> GSM528657     2  0.0000     0.9498 0.000 1.000
#> GSM528658     2  0.0000     0.9498 0.000 1.000
#> GSM528655     2  0.1633     0.9347 0.024 0.976
#> GSM528656     2  0.0000     0.9498 0.000 1.000
#> GSM528663     1  0.9998    -0.0455 0.508 0.492
#> GSM528664     2  0.7674     0.7120 0.224 0.776
#> GSM528665     1  0.0000     0.9738 1.000 0.000
#> GSM528666     1  0.0000     0.9738 1.000 0.000
#> GSM528667     1  0.0000     0.9738 1.000 0.000
#> GSM528668     1  0.0000     0.9738 1.000 0.000
#> GSM528669     2  0.9998     0.0324 0.492 0.508
#> GSM528670     1  0.2423     0.9360 0.960 0.040
#> GSM528659     1  0.1184     0.9599 0.984 0.016
#> GSM528660     1  0.0376     0.9705 0.996 0.004
#> GSM528661     1  0.0000     0.9738 1.000 0.000
#> GSM528662     1  0.0000     0.9738 1.000 0.000
#> GSM528701     2  0.0000     0.9498 0.000 1.000
#> GSM528702     2  0.0000     0.9498 0.000 1.000
#> GSM528703     2  0.0000     0.9498 0.000 1.000
#> GSM528704     2  0.0000     0.9498 0.000 1.000
#> GSM528707     2  0.0000     0.9498 0.000 1.000
#> GSM528708     2  0.0000     0.9498 0.000 1.000
#> GSM528705     2  0.0000     0.9498 0.000 1.000
#> GSM528706     2  0.0000     0.9498 0.000 1.000
#> GSM528713     1  0.0000     0.9738 1.000 0.000
#> GSM528714     1  0.0000     0.9738 1.000 0.000
#> GSM528715     1  0.0000     0.9738 1.000 0.000
#> GSM528716     1  0.0000     0.9738 1.000 0.000
#> GSM528717     1  0.0000     0.9738 1.000 0.000
#> GSM528718     1  0.0000     0.9738 1.000 0.000
#> GSM528719     1  0.0000     0.9738 1.000 0.000
#> GSM528720     1  0.0000     0.9738 1.000 0.000
#> GSM528709     1  0.0000     0.9738 1.000 0.000
#> GSM528710     1  0.1184     0.9599 0.984 0.016
#> GSM528711     1  0.0000     0.9738 1.000 0.000
#> GSM528712     1  0.0000     0.9738 1.000 0.000
#> GSM528721     2  0.0000     0.9498 0.000 1.000
#> GSM528722     2  0.0000     0.9498 0.000 1.000
#> GSM528723     2  0.0000     0.9498 0.000 1.000
#> GSM528724     2  0.0000     0.9498 0.000 1.000
#> GSM528727     2  0.0000     0.9498 0.000 1.000
#> GSM528728     2  0.0000     0.9498 0.000 1.000
#> GSM528725     2  0.0000     0.9498 0.000 1.000
#> GSM528726     2  0.0000     0.9498 0.000 1.000
#> GSM528733     1  0.0000     0.9738 1.000 0.000
#> GSM528734     1  0.0000     0.9738 1.000 0.000
#> GSM528735     1  0.0000     0.9738 1.000 0.000
#> GSM528736     1  0.0000     0.9738 1.000 0.000
#> GSM528737     1  0.0000     0.9738 1.000 0.000
#> GSM528738     1  0.0000     0.9738 1.000 0.000
#> GSM528729     1  0.9710     0.3119 0.600 0.400
#> GSM528730     1  0.6712     0.7685 0.824 0.176
#> GSM528731     1  0.0672     0.9670 0.992 0.008
#> GSM528732     1  0.0000     0.9738 1.000 0.000
#> GSM528739     2  0.0000     0.9498 0.000 1.000
#> GSM528740     2  0.0000     0.9498 0.000 1.000
#> GSM528741     2  0.0000     0.9498 0.000 1.000
#> GSM528742     2  0.0000     0.9498 0.000 1.000
#> GSM528745     2  0.0000     0.9498 0.000 1.000
#> GSM528746     2  0.0000     0.9498 0.000 1.000
#> GSM528743     2  0.0000     0.9498 0.000 1.000
#> GSM528744     2  0.0000     0.9498 0.000 1.000
#> GSM528751     1  0.0000     0.9738 1.000 0.000
#> GSM528752     1  0.0000     0.9738 1.000 0.000
#> GSM528753     1  0.0000     0.9738 1.000 0.000
#> GSM528754     1  0.0000     0.9738 1.000 0.000
#> GSM528755     1  0.0000     0.9738 1.000 0.000
#> GSM528756     1  0.0000     0.9738 1.000 0.000
#> GSM528757     2  0.0672     0.9454 0.008 0.992
#> GSM528758     2  0.1414     0.9379 0.020 0.980
#> GSM528747     1  0.6048     0.8094 0.852 0.148
#> GSM528748     2  0.8144     0.6688 0.252 0.748
#> GSM528749     1  0.0000     0.9738 1.000 0.000
#> GSM528750     1  0.0376     0.9705 0.996 0.004
#> GSM528640     2  0.0000     0.9498 0.000 1.000
#> GSM528641     2  0.1414     0.9384 0.020 0.980
#> GSM528643     1  0.0000     0.9738 1.000 0.000
#> GSM528644     2  0.4298     0.8781 0.088 0.912
#> GSM528642     1  0.0000     0.9738 1.000 0.000
#> GSM528620     2  0.0000     0.9498 0.000 1.000
#> GSM528621     2  0.4298     0.8780 0.088 0.912
#> GSM528623     1  0.0000     0.9738 1.000 0.000
#> GSM528624     2  0.9998     0.0324 0.492 0.508
#> GSM528622     1  0.0000     0.9738 1.000 0.000
#> GSM528625     2  0.0000     0.9498 0.000 1.000
#> GSM528626     2  0.0938     0.9431 0.012 0.988
#> GSM528628     1  0.0000     0.9738 1.000 0.000
#> GSM528629     2  0.9608     0.4038 0.384 0.616
#> GSM528627     1  0.0000     0.9738 1.000 0.000
#> GSM528630     2  0.0000     0.9498 0.000 1.000
#> GSM528631     2  0.0000     0.9498 0.000 1.000
#> GSM528632     2  0.1633     0.9346 0.024 0.976
#> GSM528633     2  0.3879     0.8890 0.076 0.924
#> GSM528636     1  0.0000     0.9738 1.000 0.000
#> GSM528637     1  0.0000     0.9738 1.000 0.000
#> GSM528638     2  0.1843     0.9323 0.028 0.972
#> GSM528639     2  0.8955     0.5632 0.312 0.688
#> GSM528634     1  0.0000     0.9738 1.000 0.000
#> GSM528635     1  0.0000     0.9738 1.000 0.000
#> GSM528645     1  0.0000     0.9738 1.000 0.000
#> GSM528646     1  0.0000     0.9738 1.000 0.000
#> GSM528647     1  0.0000     0.9738 1.000 0.000
#> GSM528648     1  0.0000     0.9738 1.000 0.000
#> GSM528649     1  0.0000     0.9738 1.000 0.000
#> GSM528650     1  0.0000     0.9738 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-SD-pam-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-SD-pam-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-SD-pam-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-SD-pam-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk SD-pam-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-SD-pam-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk SD-pam-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>          n agent(p) dose(p)  time(p) k
#> SD:pam 160 0.577858  0.9280 7.77e-24 2
#> SD:pam 161 0.000728  0.0121 3.02e-29 3
#> SD:pam 156 0.009309  0.1075 1.90e-44 4
#> SD:pam 159 0.028560  0.0894 3.09e-63 5
#> SD:pam 139 0.012382  0.1861 5.05e-76 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


SD:mclust

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["SD", "mclust"]
# you can also extract it by
# res = res_list["SD:mclust"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'SD' method.
#>   Subgroups are detected by 'mclust' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 2.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk SD-mclust-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk SD-mclust-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.673           0.912       0.939         0.4775 0.501   0.501
#> 3 3 0.726           0.832       0.893         0.3187 0.802   0.628
#> 4 4 0.706           0.756       0.864         0.1227 0.902   0.740
#> 5 5 0.680           0.679       0.809         0.0961 0.881   0.615
#> 6 6 0.708           0.681       0.802         0.0446 0.942   0.734

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 2

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2  0.0000      0.945 0.000 1.000
#> GSM528682     2  0.0000      0.945 0.000 1.000
#> GSM528683     2  0.0000      0.945 0.000 1.000
#> GSM528684     2  0.0000      0.945 0.000 1.000
#> GSM528687     2  0.0000      0.945 0.000 1.000
#> GSM528688     2  0.0000      0.945 0.000 1.000
#> GSM528685     2  0.2043      0.922 0.032 0.968
#> GSM528686     2  0.2043      0.922 0.032 0.968
#> GSM528693     1  0.3584      0.944 0.932 0.068
#> GSM528694     1  0.3584      0.944 0.932 0.068
#> GSM528695     1  0.1414      0.922 0.980 0.020
#> GSM528696     1  0.1414      0.922 0.980 0.020
#> GSM528697     1  0.0000      0.924 1.000 0.000
#> GSM528698     1  0.0000      0.924 1.000 0.000
#> GSM528699     1  0.0000      0.924 1.000 0.000
#> GSM528700     1  0.0000      0.924 1.000 0.000
#> GSM528689     1  0.0000      0.924 1.000 0.000
#> GSM528690     1  0.0000      0.924 1.000 0.000
#> GSM528691     1  0.0000      0.924 1.000 0.000
#> GSM528692     1  0.0000      0.924 1.000 0.000
#> GSM528779     2  0.0000      0.945 0.000 1.000
#> GSM528780     2  0.0000      0.945 0.000 1.000
#> GSM528782     2  0.0000      0.945 0.000 1.000
#> GSM528781     2  0.0000      0.945 0.000 1.000
#> GSM528785     2  0.7745      0.714 0.228 0.772
#> GSM528786     1  0.4562      0.941 0.904 0.096
#> GSM528787     1  0.4161      0.944 0.916 0.084
#> GSM528788     1  0.5629      0.921 0.868 0.132
#> GSM528783     1  0.0000      0.924 1.000 0.000
#> GSM528784     1  0.0000      0.924 1.000 0.000
#> GSM528759     1  0.4562      0.940 0.904 0.096
#> GSM528760     1  0.3879      0.944 0.924 0.076
#> GSM528761     2  0.0000      0.945 0.000 1.000
#> GSM528762     2  0.0000      0.945 0.000 1.000
#> GSM528765     2  0.0000      0.945 0.000 1.000
#> GSM528766     2  0.0000      0.945 0.000 1.000
#> GSM528763     2  0.0000      0.945 0.000 1.000
#> GSM528764     2  0.0376      0.943 0.004 0.996
#> GSM528771     2  0.7745      0.714 0.228 0.772
#> GSM528772     2  0.7745      0.714 0.228 0.772
#> GSM528773     1  0.4562      0.941 0.904 0.096
#> GSM528774     1  0.4562      0.941 0.904 0.096
#> GSM528775     1  0.4298      0.943 0.912 0.088
#> GSM528776     1  0.4431      0.942 0.908 0.092
#> GSM528777     1  0.3274      0.943 0.940 0.060
#> GSM528778     1  0.3114      0.942 0.944 0.056
#> GSM528767     1  0.0000      0.924 1.000 0.000
#> GSM528768     1  0.0000      0.924 1.000 0.000
#> GSM528769     1  0.0000      0.924 1.000 0.000
#> GSM528770     1  0.0000      0.924 1.000 0.000
#> GSM528671     2  0.0000      0.945 0.000 1.000
#> GSM528672     2  0.0000      0.945 0.000 1.000
#> GSM528674     2  0.0000      0.945 0.000 1.000
#> GSM528673     2  0.0376      0.943 0.004 0.996
#> GSM528677     2  0.7745      0.714 0.228 0.772
#> GSM528678     1  0.4562      0.941 0.904 0.096
#> GSM528679     1  0.3584      0.944 0.932 0.068
#> GSM528680     1  0.0000      0.924 1.000 0.000
#> GSM528675     1  0.0000      0.924 1.000 0.000
#> GSM528676     1  0.0000      0.924 1.000 0.000
#> GSM528651     2  0.0000      0.945 0.000 1.000
#> GSM528652     2  0.0000      0.945 0.000 1.000
#> GSM528653     2  0.0000      0.945 0.000 1.000
#> GSM528654     2  0.0000      0.945 0.000 1.000
#> GSM528657     2  0.0000      0.945 0.000 1.000
#> GSM528658     2  0.0000      0.945 0.000 1.000
#> GSM528655     2  0.0376      0.943 0.004 0.996
#> GSM528656     2  0.0376      0.943 0.004 0.996
#> GSM528663     2  0.7745      0.714 0.228 0.772
#> GSM528664     2  0.7745      0.714 0.228 0.772
#> GSM528665     1  0.4562      0.941 0.904 0.096
#> GSM528666     1  0.4562      0.941 0.904 0.096
#> GSM528667     1  0.5178      0.931 0.884 0.116
#> GSM528668     1  0.5178      0.931 0.884 0.116
#> GSM528669     1  0.3584      0.944 0.932 0.068
#> GSM528670     1  0.3584      0.944 0.932 0.068
#> GSM528659     1  0.0000      0.924 1.000 0.000
#> GSM528660     1  0.0000      0.924 1.000 0.000
#> GSM528661     1  0.0000      0.924 1.000 0.000
#> GSM528662     1  0.0000      0.924 1.000 0.000
#> GSM528701     2  0.0000      0.945 0.000 1.000
#> GSM528702     2  0.0000      0.945 0.000 1.000
#> GSM528703     2  0.0000      0.945 0.000 1.000
#> GSM528704     2  0.0000      0.945 0.000 1.000
#> GSM528707     2  0.0000      0.945 0.000 1.000
#> GSM528708     2  0.0000      0.945 0.000 1.000
#> GSM528705     2  0.0000      0.945 0.000 1.000
#> GSM528706     2  0.0000      0.945 0.000 1.000
#> GSM528713     2  0.9710      0.316 0.400 0.600
#> GSM528714     2  0.7745      0.714 0.228 0.772
#> GSM528715     1  0.4690      0.940 0.900 0.100
#> GSM528716     1  0.4690      0.940 0.900 0.100
#> GSM528717     1  0.3584      0.944 0.932 0.068
#> GSM528718     1  0.3584      0.944 0.932 0.068
#> GSM528719     1  0.0000      0.924 1.000 0.000
#> GSM528720     1  0.0000      0.924 1.000 0.000
#> GSM528709     1  0.0000      0.924 1.000 0.000
#> GSM528710     1  0.0000      0.924 1.000 0.000
#> GSM528711     1  0.0000      0.924 1.000 0.000
#> GSM528712     1  0.0000      0.924 1.000 0.000
#> GSM528721     2  0.0000      0.945 0.000 1.000
#> GSM528722     2  0.0000      0.945 0.000 1.000
#> GSM528723     2  0.0000      0.945 0.000 1.000
#> GSM528724     2  0.0000      0.945 0.000 1.000
#> GSM528727     2  0.0000      0.945 0.000 1.000
#> GSM528728     2  0.0000      0.945 0.000 1.000
#> GSM528725     2  0.0000      0.945 0.000 1.000
#> GSM528726     2  0.0000      0.945 0.000 1.000
#> GSM528733     1  0.4562      0.941 0.904 0.096
#> GSM528734     1  0.4562      0.941 0.904 0.096
#> GSM528735     1  0.4161      0.944 0.916 0.084
#> GSM528736     1  0.4022      0.944 0.920 0.080
#> GSM528737     1  0.5178      0.931 0.884 0.116
#> GSM528738     1  0.5178      0.931 0.884 0.116
#> GSM528729     1  0.5946      0.912 0.856 0.144
#> GSM528730     1  0.5946      0.912 0.856 0.144
#> GSM528731     1  0.5946      0.912 0.856 0.144
#> GSM528732     1  0.5946      0.912 0.856 0.144
#> GSM528739     2  0.0000      0.945 0.000 1.000
#> GSM528740     2  0.0000      0.945 0.000 1.000
#> GSM528741     2  0.0000      0.945 0.000 1.000
#> GSM528742     2  0.0000      0.945 0.000 1.000
#> GSM528745     2  0.0000      0.945 0.000 1.000
#> GSM528746     2  0.0000      0.945 0.000 1.000
#> GSM528743     2  0.0000      0.945 0.000 1.000
#> GSM528744     2  0.0000      0.945 0.000 1.000
#> GSM528751     2  0.7745      0.714 0.228 0.772
#> GSM528752     2  0.8267      0.660 0.260 0.740
#> GSM528753     1  0.4562      0.941 0.904 0.096
#> GSM528754     1  0.4562      0.941 0.904 0.096
#> GSM528755     1  0.3733      0.944 0.928 0.072
#> GSM528756     1  0.3584      0.944 0.932 0.068
#> GSM528757     1  0.5946      0.912 0.856 0.144
#> GSM528758     1  0.5946      0.912 0.856 0.144
#> GSM528747     1  0.5946      0.912 0.856 0.144
#> GSM528748     1  0.5946      0.912 0.856 0.144
#> GSM528749     1  0.5178      0.931 0.884 0.116
#> GSM528750     1  0.5946      0.912 0.856 0.144
#> GSM528640     2  0.0000      0.945 0.000 1.000
#> GSM528641     2  0.0376      0.943 0.004 0.996
#> GSM528643     1  0.4562      0.941 0.904 0.096
#> GSM528644     1  0.5946      0.912 0.856 0.144
#> GSM528642     1  0.5629      0.920 0.868 0.132
#> GSM528620     2  0.0000      0.945 0.000 1.000
#> GSM528621     2  0.6887      0.765 0.184 0.816
#> GSM528623     1  0.4562      0.941 0.904 0.096
#> GSM528624     1  0.5946      0.912 0.856 0.144
#> GSM528622     1  0.5946      0.912 0.856 0.144
#> GSM528625     2  0.0000      0.945 0.000 1.000
#> GSM528626     2  0.0376      0.943 0.004 0.996
#> GSM528628     1  0.4562      0.941 0.904 0.096
#> GSM528629     1  0.5946      0.912 0.856 0.144
#> GSM528627     1  0.5629      0.921 0.868 0.132
#> GSM528630     2  0.0000      0.945 0.000 1.000
#> GSM528631     2  0.0000      0.945 0.000 1.000
#> GSM528632     2  0.0376      0.943 0.004 0.996
#> GSM528633     2  0.0376      0.943 0.004 0.996
#> GSM528636     1  0.4562      0.941 0.904 0.096
#> GSM528637     1  0.4562      0.941 0.904 0.096
#> GSM528638     1  0.5946      0.912 0.856 0.144
#> GSM528639     1  0.5946      0.912 0.856 0.144
#> GSM528634     1  0.4815      0.937 0.896 0.104
#> GSM528635     1  0.5629      0.921 0.868 0.132
#> GSM528645     2  0.9248      0.493 0.340 0.660
#> GSM528646     2  0.9460      0.430 0.364 0.636
#> GSM528647     2  0.8207      0.670 0.256 0.744
#> GSM528648     1  0.4562      0.940 0.904 0.096
#> GSM528649     1  0.4022      0.944 0.920 0.080
#> GSM528650     1  0.4562      0.940 0.904 0.096

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-SD-mclust-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-SD-mclust-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-SD-mclust-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-SD-mclust-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk SD-mclust-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-SD-mclust-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk SD-mclust-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>             n agent(p)  dose(p)  time(p) k
#> SD:mclust 166 0.996738 0.997146 4.95e-27 2
#> SD:mclust 157 0.000834 0.000385 2.54e-29 3
#> SD:mclust 148 0.008301 0.002895 8.30e-49 4
#> SD:mclust 125 0.002360 0.000322 9.63e-53 5
#> SD:mclust 135 0.006786 0.000571 2.65e-57 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


SD:NMF**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["SD", "NMF"]
# you can also extract it by
# res = res_list["SD:NMF"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'SD' method.
#>   Subgroups are detected by 'NMF' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 2.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk SD-NMF-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk SD-NMF-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           0.969       0.988         0.4871 0.514   0.514
#> 3 3 0.832           0.844       0.938         0.3345 0.786   0.604
#> 4 4 0.786           0.810       0.897         0.1178 0.862   0.637
#> 5 5 0.815           0.804       0.890         0.0653 0.919   0.716
#> 6 6 0.861           0.814       0.895         0.0371 0.933   0.722

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 2

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2   0.000     0.9879 0.000 1.000
#> GSM528682     2   0.000     0.9879 0.000 1.000
#> GSM528683     2   0.000     0.9879 0.000 1.000
#> GSM528684     2   0.000     0.9879 0.000 1.000
#> GSM528687     2   0.000     0.9879 0.000 1.000
#> GSM528688     2   0.000     0.9879 0.000 1.000
#> GSM528685     2   0.000     0.9879 0.000 1.000
#> GSM528686     2   0.000     0.9879 0.000 1.000
#> GSM528693     1   0.000     0.9867 1.000 0.000
#> GSM528694     1   0.000     0.9867 1.000 0.000
#> GSM528695     1   0.000     0.9867 1.000 0.000
#> GSM528696     1   0.000     0.9867 1.000 0.000
#> GSM528697     1   0.000     0.9867 1.000 0.000
#> GSM528698     1   0.000     0.9867 1.000 0.000
#> GSM528699     1   0.000     0.9867 1.000 0.000
#> GSM528700     1   0.000     0.9867 1.000 0.000
#> GSM528689     1   0.000     0.9867 1.000 0.000
#> GSM528690     1   0.000     0.9867 1.000 0.000
#> GSM528691     1   0.000     0.9867 1.000 0.000
#> GSM528692     1   0.000     0.9867 1.000 0.000
#> GSM528779     2   0.000     0.9879 0.000 1.000
#> GSM528780     2   0.000     0.9879 0.000 1.000
#> GSM528782     2   0.000     0.9879 0.000 1.000
#> GSM528781     2   0.000     0.9879 0.000 1.000
#> GSM528785     2   0.775     0.7000 0.228 0.772
#> GSM528786     1   0.000     0.9867 1.000 0.000
#> GSM528787     1   0.000     0.9867 1.000 0.000
#> GSM528788     1   0.000     0.9867 1.000 0.000
#> GSM528783     1   0.000     0.9867 1.000 0.000
#> GSM528784     1   0.000     0.9867 1.000 0.000
#> GSM528759     1   0.000     0.9867 1.000 0.000
#> GSM528760     1   0.000     0.9867 1.000 0.000
#> GSM528761     2   0.000     0.9879 0.000 1.000
#> GSM528762     2   0.000     0.9879 0.000 1.000
#> GSM528765     2   0.000     0.9879 0.000 1.000
#> GSM528766     2   0.000     0.9879 0.000 1.000
#> GSM528763     2   0.000     0.9879 0.000 1.000
#> GSM528764     2   0.000     0.9879 0.000 1.000
#> GSM528771     2   0.625     0.8091 0.156 0.844
#> GSM528772     2   0.981     0.2648 0.420 0.580
#> GSM528773     1   0.000     0.9867 1.000 0.000
#> GSM528774     1   0.000     0.9867 1.000 0.000
#> GSM528775     1   0.000     0.9867 1.000 0.000
#> GSM528776     1   0.000     0.9867 1.000 0.000
#> GSM528777     1   0.000     0.9867 1.000 0.000
#> GSM528778     1   0.000     0.9867 1.000 0.000
#> GSM528767     1   0.000     0.9867 1.000 0.000
#> GSM528768     1   0.000     0.9867 1.000 0.000
#> GSM528769     1   0.000     0.9867 1.000 0.000
#> GSM528770     1   0.000     0.9867 1.000 0.000
#> GSM528671     2   0.000     0.9879 0.000 1.000
#> GSM528672     2   0.000     0.9879 0.000 1.000
#> GSM528674     2   0.000     0.9879 0.000 1.000
#> GSM528673     2   0.000     0.9879 0.000 1.000
#> GSM528677     1   0.697     0.7673 0.812 0.188
#> GSM528678     1   0.000     0.9867 1.000 0.000
#> GSM528679     1   0.000     0.9867 1.000 0.000
#> GSM528680     1   0.000     0.9867 1.000 0.000
#> GSM528675     1   0.000     0.9867 1.000 0.000
#> GSM528676     1   0.000     0.9867 1.000 0.000
#> GSM528651     2   0.000     0.9879 0.000 1.000
#> GSM528652     2   0.000     0.9879 0.000 1.000
#> GSM528653     2   0.000     0.9879 0.000 1.000
#> GSM528654     2   0.000     0.9879 0.000 1.000
#> GSM528657     2   0.000     0.9879 0.000 1.000
#> GSM528658     2   0.000     0.9879 0.000 1.000
#> GSM528655     2   0.000     0.9879 0.000 1.000
#> GSM528656     2   0.000     0.9879 0.000 1.000
#> GSM528663     2   0.000     0.9879 0.000 1.000
#> GSM528664     2   0.000     0.9879 0.000 1.000
#> GSM528665     1   0.000     0.9867 1.000 0.000
#> GSM528666     1   0.000     0.9867 1.000 0.000
#> GSM528667     1   0.000     0.9867 1.000 0.000
#> GSM528668     1   0.000     0.9867 1.000 0.000
#> GSM528669     1   0.000     0.9867 1.000 0.000
#> GSM528670     1   0.000     0.9867 1.000 0.000
#> GSM528659     1   0.000     0.9867 1.000 0.000
#> GSM528660     1   0.000     0.9867 1.000 0.000
#> GSM528661     1   0.000     0.9867 1.000 0.000
#> GSM528662     1   0.000     0.9867 1.000 0.000
#> GSM528701     2   0.000     0.9879 0.000 1.000
#> GSM528702     2   0.000     0.9879 0.000 1.000
#> GSM528703     2   0.000     0.9879 0.000 1.000
#> GSM528704     2   0.000     0.9879 0.000 1.000
#> GSM528707     2   0.000     0.9879 0.000 1.000
#> GSM528708     2   0.000     0.9879 0.000 1.000
#> GSM528705     2   0.000     0.9879 0.000 1.000
#> GSM528706     2   0.000     0.9879 0.000 1.000
#> GSM528713     1   0.697     0.7673 0.812 0.188
#> GSM528714     1   0.625     0.8117 0.844 0.156
#> GSM528715     1   0.000     0.9867 1.000 0.000
#> GSM528716     1   0.000     0.9867 1.000 0.000
#> GSM528717     1   0.000     0.9867 1.000 0.000
#> GSM528718     1   0.000     0.9867 1.000 0.000
#> GSM528719     1   0.000     0.9867 1.000 0.000
#> GSM528720     1   0.000     0.9867 1.000 0.000
#> GSM528709     1   0.000     0.9867 1.000 0.000
#> GSM528710     1   0.000     0.9867 1.000 0.000
#> GSM528711     1   0.000     0.9867 1.000 0.000
#> GSM528712     1   0.000     0.9867 1.000 0.000
#> GSM528721     2   0.000     0.9879 0.000 1.000
#> GSM528722     2   0.000     0.9879 0.000 1.000
#> GSM528723     2   0.000     0.9879 0.000 1.000
#> GSM528724     2   0.000     0.9879 0.000 1.000
#> GSM528727     2   0.000     0.9879 0.000 1.000
#> GSM528728     2   0.000     0.9879 0.000 1.000
#> GSM528725     2   0.000     0.9879 0.000 1.000
#> GSM528726     2   0.000     0.9879 0.000 1.000
#> GSM528733     1   0.000     0.9867 1.000 0.000
#> GSM528734     1   0.000     0.9867 1.000 0.000
#> GSM528735     1   0.000     0.9867 1.000 0.000
#> GSM528736     1   0.000     0.9867 1.000 0.000
#> GSM528737     1   0.000     0.9867 1.000 0.000
#> GSM528738     1   0.000     0.9867 1.000 0.000
#> GSM528729     1   0.000     0.9867 1.000 0.000
#> GSM528730     1   0.000     0.9867 1.000 0.000
#> GSM528731     1   0.000     0.9867 1.000 0.000
#> GSM528732     1   0.000     0.9867 1.000 0.000
#> GSM528739     2   0.000     0.9879 0.000 1.000
#> GSM528740     2   0.000     0.9879 0.000 1.000
#> GSM528741     2   0.000     0.9879 0.000 1.000
#> GSM528742     2   0.000     0.9879 0.000 1.000
#> GSM528745     2   0.000     0.9879 0.000 1.000
#> GSM528746     2   0.000     0.9879 0.000 1.000
#> GSM528743     2   0.000     0.9879 0.000 1.000
#> GSM528744     2   0.000     0.9879 0.000 1.000
#> GSM528751     1   1.000     0.0128 0.504 0.496
#> GSM528752     1   0.833     0.6426 0.736 0.264
#> GSM528753     1   0.000     0.9867 1.000 0.000
#> GSM528754     1   0.000     0.9867 1.000 0.000
#> GSM528755     1   0.000     0.9867 1.000 0.000
#> GSM528756     1   0.000     0.9867 1.000 0.000
#> GSM528757     1   0.000     0.9867 1.000 0.000
#> GSM528758     1   0.000     0.9867 1.000 0.000
#> GSM528747     1   0.000     0.9867 1.000 0.000
#> GSM528748     1   0.000     0.9867 1.000 0.000
#> GSM528749     1   0.000     0.9867 1.000 0.000
#> GSM528750     1   0.000     0.9867 1.000 0.000
#> GSM528640     2   0.000     0.9879 0.000 1.000
#> GSM528641     2   0.000     0.9879 0.000 1.000
#> GSM528643     1   0.000     0.9867 1.000 0.000
#> GSM528644     1   0.000     0.9867 1.000 0.000
#> GSM528642     1   0.000     0.9867 1.000 0.000
#> GSM528620     2   0.000     0.9879 0.000 1.000
#> GSM528621     2   0.000     0.9879 0.000 1.000
#> GSM528623     1   0.000     0.9867 1.000 0.000
#> GSM528624     1   0.000     0.9867 1.000 0.000
#> GSM528622     1   0.000     0.9867 1.000 0.000
#> GSM528625     2   0.000     0.9879 0.000 1.000
#> GSM528626     2   0.000     0.9879 0.000 1.000
#> GSM528628     1   0.000     0.9867 1.000 0.000
#> GSM528629     1   0.000     0.9867 1.000 0.000
#> GSM528627     1   0.000     0.9867 1.000 0.000
#> GSM528630     2   0.000     0.9879 0.000 1.000
#> GSM528631     2   0.000     0.9879 0.000 1.000
#> GSM528632     2   0.000     0.9879 0.000 1.000
#> GSM528633     2   0.000     0.9879 0.000 1.000
#> GSM528636     1   0.000     0.9867 1.000 0.000
#> GSM528637     1   0.000     0.9867 1.000 0.000
#> GSM528638     1   0.000     0.9867 1.000 0.000
#> GSM528639     1   0.000     0.9867 1.000 0.000
#> GSM528634     1   0.000     0.9867 1.000 0.000
#> GSM528635     1   0.000     0.9867 1.000 0.000
#> GSM528645     1   0.000     0.9867 1.000 0.000
#> GSM528646     1   0.000     0.9867 1.000 0.000
#> GSM528647     1   0.000     0.9867 1.000 0.000
#> GSM528648     1   0.000     0.9867 1.000 0.000
#> GSM528649     1   0.000     0.9867 1.000 0.000
#> GSM528650     1   0.000     0.9867 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-SD-NMF-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-SD-NMF-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-SD-NMF-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-SD-NMF-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk SD-NMF-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-SD-NMF-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk SD-NMF-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>          n agent(p) dose(p)  time(p) k
#> SD:NMF 167  0.85955 0.99881 3.81e-27 2
#> SD:NMF 153  0.01043 0.00367 5.55e-36 3
#> SD:NMF 155  0.00477 0.00682 2.43e-44 4
#> SD:NMF 156  0.06507 0.00689 8.68e-68 5
#> SD:NMF 153  0.00486 0.00817 4.93e-63 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


CV:hclust

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["CV", "hclust"]
# you can also extract it by
# res = res_list["CV:hclust"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'CV' method.
#>   Subgroups are detected by 'hclust' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 4.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk CV-hclust-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk CV-hclust-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.837           0.878       0.952         0.1836 0.878   0.878
#> 3 3 0.374           0.646       0.765         1.8914 0.576   0.517
#> 4 4 0.715           0.708       0.836         0.1909 0.871   0.725
#> 5 5 0.769           0.835       0.877         0.1384 0.851   0.613
#> 6 6 0.790           0.821       0.887         0.0326 0.998   0.992

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 4

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     1   0.000      0.949 1.000 0.000
#> GSM528682     1   0.000      0.949 1.000 0.000
#> GSM528683     1   0.000      0.949 1.000 0.000
#> GSM528684     1   0.000      0.949 1.000 0.000
#> GSM528687     1   0.000      0.949 1.000 0.000
#> GSM528688     1   0.000      0.949 1.000 0.000
#> GSM528685     1   0.000      0.949 1.000 0.000
#> GSM528686     1   0.000      0.949 1.000 0.000
#> GSM528693     1   0.358      0.886 0.932 0.068
#> GSM528694     1   0.358      0.886 0.932 0.068
#> GSM528695     1   0.634      0.779 0.840 0.160
#> GSM528696     1   0.634      0.779 0.840 0.160
#> GSM528697     1   0.958      0.391 0.620 0.380
#> GSM528698     1   0.958      0.391 0.620 0.380
#> GSM528699     1   0.992      0.216 0.552 0.448
#> GSM528700     1   0.992      0.216 0.552 0.448
#> GSM528689     1   0.994      0.191 0.544 0.456
#> GSM528690     1   0.994      0.191 0.544 0.456
#> GSM528691     1   0.994      0.191 0.544 0.456
#> GSM528692     1   0.994      0.191 0.544 0.456
#> GSM528779     1   0.000      0.949 1.000 0.000
#> GSM528780     1   0.000      0.949 1.000 0.000
#> GSM528782     1   0.000      0.949 1.000 0.000
#> GSM528781     1   0.000      0.949 1.000 0.000
#> GSM528785     1   0.000      0.949 1.000 0.000
#> GSM528786     1   0.000      0.949 1.000 0.000
#> GSM528787     1   0.000      0.949 1.000 0.000
#> GSM528788     1   0.000      0.949 1.000 0.000
#> GSM528783     1   0.343      0.890 0.936 0.064
#> GSM528784     2   0.625      0.882 0.156 0.844
#> GSM528759     1   0.000      0.949 1.000 0.000
#> GSM528760     1   0.000      0.949 1.000 0.000
#> GSM528761     1   0.000      0.949 1.000 0.000
#> GSM528762     1   0.000      0.949 1.000 0.000
#> GSM528765     1   0.000      0.949 1.000 0.000
#> GSM528766     1   0.000      0.949 1.000 0.000
#> GSM528763     1   0.000      0.949 1.000 0.000
#> GSM528764     1   0.000      0.949 1.000 0.000
#> GSM528771     1   0.000      0.949 1.000 0.000
#> GSM528772     1   0.000      0.949 1.000 0.000
#> GSM528773     1   0.000      0.949 1.000 0.000
#> GSM528774     1   0.000      0.949 1.000 0.000
#> GSM528775     1   0.000      0.949 1.000 0.000
#> GSM528776     1   0.000      0.949 1.000 0.000
#> GSM528777     1   0.000      0.949 1.000 0.000
#> GSM528778     1   0.000      0.949 1.000 0.000
#> GSM528767     2   0.625      0.882 0.156 0.844
#> GSM528768     2   0.625      0.882 0.156 0.844
#> GSM528769     2   0.625      0.882 0.156 0.844
#> GSM528770     2   0.625      0.882 0.156 0.844
#> GSM528671     1   0.000      0.949 1.000 0.000
#> GSM528672     1   0.000      0.949 1.000 0.000
#> GSM528674     1   0.000      0.949 1.000 0.000
#> GSM528673     1   0.000      0.949 1.000 0.000
#> GSM528677     1   0.000      0.949 1.000 0.000
#> GSM528678     1   0.000      0.949 1.000 0.000
#> GSM528679     1   0.000      0.949 1.000 0.000
#> GSM528680     1   0.983      0.281 0.576 0.424
#> GSM528675     2   0.000      0.916 0.000 1.000
#> GSM528676     2   0.000      0.916 0.000 1.000
#> GSM528651     1   0.000      0.949 1.000 0.000
#> GSM528652     1   0.000      0.949 1.000 0.000
#> GSM528653     1   0.000      0.949 1.000 0.000
#> GSM528654     1   0.000      0.949 1.000 0.000
#> GSM528657     1   0.000      0.949 1.000 0.000
#> GSM528658     1   0.000      0.949 1.000 0.000
#> GSM528655     1   0.000      0.949 1.000 0.000
#> GSM528656     1   0.000      0.949 1.000 0.000
#> GSM528663     1   0.000      0.949 1.000 0.000
#> GSM528664     1   0.000      0.949 1.000 0.000
#> GSM528665     1   0.000      0.949 1.000 0.000
#> GSM528666     1   0.000      0.949 1.000 0.000
#> GSM528667     1   0.000      0.949 1.000 0.000
#> GSM528668     1   0.000      0.949 1.000 0.000
#> GSM528669     1   0.000      0.949 1.000 0.000
#> GSM528670     1   0.000      0.949 1.000 0.000
#> GSM528659     2   0.000      0.916 0.000 1.000
#> GSM528660     2   0.000      0.916 0.000 1.000
#> GSM528661     2   0.000      0.916 0.000 1.000
#> GSM528662     2   0.000      0.916 0.000 1.000
#> GSM528701     1   0.000      0.949 1.000 0.000
#> GSM528702     1   0.000      0.949 1.000 0.000
#> GSM528703     1   0.000      0.949 1.000 0.000
#> GSM528704     1   0.000      0.949 1.000 0.000
#> GSM528707     1   0.000      0.949 1.000 0.000
#> GSM528708     1   0.000      0.949 1.000 0.000
#> GSM528705     1   0.000      0.949 1.000 0.000
#> GSM528706     1   0.000      0.949 1.000 0.000
#> GSM528713     1   0.000      0.949 1.000 0.000
#> GSM528714     1   0.000      0.949 1.000 0.000
#> GSM528715     1   0.000      0.949 1.000 0.000
#> GSM528716     1   0.000      0.949 1.000 0.000
#> GSM528717     1   0.358      0.886 0.932 0.068
#> GSM528718     1   0.358      0.886 0.932 0.068
#> GSM528719     1   0.992      0.216 0.552 0.448
#> GSM528720     1   0.992      0.216 0.552 0.448
#> GSM528709     1   0.994      0.191 0.544 0.456
#> GSM528710     1   0.994      0.191 0.544 0.456
#> GSM528711     1   0.994      0.191 0.544 0.456
#> GSM528712     1   0.994      0.191 0.544 0.456
#> GSM528721     1   0.000      0.949 1.000 0.000
#> GSM528722     1   0.000      0.949 1.000 0.000
#> GSM528723     1   0.000      0.949 1.000 0.000
#> GSM528724     1   0.000      0.949 1.000 0.000
#> GSM528727     1   0.000      0.949 1.000 0.000
#> GSM528728     1   0.000      0.949 1.000 0.000
#> GSM528725     1   0.000      0.949 1.000 0.000
#> GSM528726     1   0.000      0.949 1.000 0.000
#> GSM528733     1   0.000      0.949 1.000 0.000
#> GSM528734     1   0.000      0.949 1.000 0.000
#> GSM528735     1   0.000      0.949 1.000 0.000
#> GSM528736     1   0.000      0.949 1.000 0.000
#> GSM528737     1   0.000      0.949 1.000 0.000
#> GSM528738     1   0.000      0.949 1.000 0.000
#> GSM528729     1   0.000      0.949 1.000 0.000
#> GSM528730     1   0.000      0.949 1.000 0.000
#> GSM528731     1   0.000      0.949 1.000 0.000
#> GSM528732     1   0.000      0.949 1.000 0.000
#> GSM528739     1   0.000      0.949 1.000 0.000
#> GSM528740     1   0.000      0.949 1.000 0.000
#> GSM528741     1   0.000      0.949 1.000 0.000
#> GSM528742     1   0.000      0.949 1.000 0.000
#> GSM528745     1   0.000      0.949 1.000 0.000
#> GSM528746     1   0.000      0.949 1.000 0.000
#> GSM528743     1   0.000      0.949 1.000 0.000
#> GSM528744     1   0.000      0.949 1.000 0.000
#> GSM528751     1   0.000      0.949 1.000 0.000
#> GSM528752     1   0.000      0.949 1.000 0.000
#> GSM528753     1   0.000      0.949 1.000 0.000
#> GSM528754     1   0.000      0.949 1.000 0.000
#> GSM528755     1   0.000      0.949 1.000 0.000
#> GSM528756     1   0.000      0.949 1.000 0.000
#> GSM528757     1   0.000      0.949 1.000 0.000
#> GSM528758     1   0.000      0.949 1.000 0.000
#> GSM528747     1   0.000      0.949 1.000 0.000
#> GSM528748     1   0.000      0.949 1.000 0.000
#> GSM528749     1   0.000      0.949 1.000 0.000
#> GSM528750     1   0.000      0.949 1.000 0.000
#> GSM528640     1   0.000      0.949 1.000 0.000
#> GSM528641     1   0.000      0.949 1.000 0.000
#> GSM528643     1   0.000      0.949 1.000 0.000
#> GSM528644     1   0.000      0.949 1.000 0.000
#> GSM528642     1   0.000      0.949 1.000 0.000
#> GSM528620     1   0.000      0.949 1.000 0.000
#> GSM528621     1   0.000      0.949 1.000 0.000
#> GSM528623     1   0.000      0.949 1.000 0.000
#> GSM528624     1   0.000      0.949 1.000 0.000
#> GSM528622     1   0.000      0.949 1.000 0.000
#> GSM528625     1   0.000      0.949 1.000 0.000
#> GSM528626     1   0.000      0.949 1.000 0.000
#> GSM528628     1   0.000      0.949 1.000 0.000
#> GSM528629     1   0.000      0.949 1.000 0.000
#> GSM528627     1   0.000      0.949 1.000 0.000
#> GSM528630     1   0.000      0.949 1.000 0.000
#> GSM528631     1   0.000      0.949 1.000 0.000
#> GSM528632     1   0.000      0.949 1.000 0.000
#> GSM528633     1   0.000      0.949 1.000 0.000
#> GSM528636     1   0.000      0.949 1.000 0.000
#> GSM528637     1   0.000      0.949 1.000 0.000
#> GSM528638     1   0.000      0.949 1.000 0.000
#> GSM528639     1   0.000      0.949 1.000 0.000
#> GSM528634     1   0.000      0.949 1.000 0.000
#> GSM528635     1   0.000      0.949 1.000 0.000
#> GSM528645     1   0.000      0.949 1.000 0.000
#> GSM528646     1   0.000      0.949 1.000 0.000
#> GSM528647     1   0.000      0.949 1.000 0.000
#> GSM528648     1   0.000      0.949 1.000 0.000
#> GSM528649     1   0.000      0.949 1.000 0.000
#> GSM528650     1   0.000      0.949 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-CV-hclust-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-CV-hclust-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-CV-hclust-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-CV-hclust-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk CV-hclust-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-CV-hclust-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk CV-hclust-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>             n agent(p)  dose(p)  time(p) k
#> CV:hclust 154 2.50e-02 4.08e-02 1.49e-09 2
#> CV:hclust 117 1.15e-02 1.44e-02 5.97e-23 3
#> CV:hclust 155 1.63e-06 3.84e-05 1.20e-31 4
#> CV:hclust 153 1.35e-04 2.90e-03 2.68e-45 5
#> CV:hclust 153 1.08e-06 2.22e-02 4.52e-41 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


CV:kmeans

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["CV", "kmeans"]
# you can also extract it by
# res = res_list["CV:kmeans"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'CV' method.
#>   Subgroups are detected by 'kmeans' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 2.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk CV-kmeans-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk CV-kmeans-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.511           0.914       0.903         0.4419 0.527   0.527
#> 3 3 0.711           0.882       0.883         0.4110 0.852   0.718
#> 4 4 0.714           0.551       0.743         0.1353 0.878   0.685
#> 5 5 0.767           0.888       0.881         0.0693 0.864   0.569
#> 6 6 0.868           0.848       0.848         0.0495 1.000   1.000

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 2

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2  0.7376      1.000 0.208 0.792
#> GSM528682     2  0.7376      1.000 0.208 0.792
#> GSM528683     2  0.7376      1.000 0.208 0.792
#> GSM528684     2  0.7376      1.000 0.208 0.792
#> GSM528687     2  0.7376      1.000 0.208 0.792
#> GSM528688     2  0.7376      1.000 0.208 0.792
#> GSM528685     2  0.7376      1.000 0.208 0.792
#> GSM528686     2  0.7376      1.000 0.208 0.792
#> GSM528693     1  0.0000      0.907 1.000 0.000
#> GSM528694     1  0.0000      0.907 1.000 0.000
#> GSM528695     1  0.6712      0.834 0.824 0.176
#> GSM528696     1  0.6712      0.834 0.824 0.176
#> GSM528697     1  0.7376      0.820 0.792 0.208
#> GSM528698     1  0.7376      0.820 0.792 0.208
#> GSM528699     1  0.7376      0.820 0.792 0.208
#> GSM528700     1  0.7376      0.820 0.792 0.208
#> GSM528689     1  0.7376      0.820 0.792 0.208
#> GSM528690     1  0.7376      0.820 0.792 0.208
#> GSM528691     1  0.7376      0.820 0.792 0.208
#> GSM528692     1  0.7376      0.820 0.792 0.208
#> GSM528779     2  0.7376      1.000 0.208 0.792
#> GSM528780     2  0.7376      1.000 0.208 0.792
#> GSM528782     2  0.7376      1.000 0.208 0.792
#> GSM528781     2  0.7376      1.000 0.208 0.792
#> GSM528785     1  0.5519      0.749 0.872 0.128
#> GSM528786     1  0.0000      0.907 1.000 0.000
#> GSM528787     1  0.0000      0.907 1.000 0.000
#> GSM528788     1  0.0000      0.907 1.000 0.000
#> GSM528783     1  0.5737      0.852 0.864 0.136
#> GSM528784     1  0.7376      0.820 0.792 0.208
#> GSM528759     1  0.0000      0.907 1.000 0.000
#> GSM528760     1  0.0000      0.907 1.000 0.000
#> GSM528761     2  0.7376      1.000 0.208 0.792
#> GSM528762     2  0.7376      1.000 0.208 0.792
#> GSM528765     2  0.7376      1.000 0.208 0.792
#> GSM528766     2  0.7376      1.000 0.208 0.792
#> GSM528763     2  0.7376      1.000 0.208 0.792
#> GSM528764     2  0.7376      1.000 0.208 0.792
#> GSM528771     1  0.5059      0.774 0.888 0.112
#> GSM528772     1  0.4022      0.820 0.920 0.080
#> GSM528773     1  0.0000      0.907 1.000 0.000
#> GSM528774     1  0.0000      0.907 1.000 0.000
#> GSM528775     1  0.0000      0.907 1.000 0.000
#> GSM528776     1  0.2423      0.893 0.960 0.040
#> GSM528777     1  0.2778      0.890 0.952 0.048
#> GSM528778     1  0.2778      0.890 0.952 0.048
#> GSM528767     1  0.7376      0.820 0.792 0.208
#> GSM528768     1  0.7376      0.820 0.792 0.208
#> GSM528769     1  0.7376      0.820 0.792 0.208
#> GSM528770     1  0.7376      0.820 0.792 0.208
#> GSM528671     2  0.7376      1.000 0.208 0.792
#> GSM528672     2  0.7376      1.000 0.208 0.792
#> GSM528674     2  0.7376      1.000 0.208 0.792
#> GSM528673     2  0.7376      1.000 0.208 0.792
#> GSM528677     1  0.0000      0.907 1.000 0.000
#> GSM528678     1  0.0000      0.907 1.000 0.000
#> GSM528679     1  0.3879      0.878 0.924 0.076
#> GSM528680     1  0.7376      0.820 0.792 0.208
#> GSM528675     1  0.7376      0.820 0.792 0.208
#> GSM528676     1  0.7376      0.820 0.792 0.208
#> GSM528651     2  0.7376      1.000 0.208 0.792
#> GSM528652     2  0.7376      1.000 0.208 0.792
#> GSM528653     2  0.7376      1.000 0.208 0.792
#> GSM528654     2  0.7376      1.000 0.208 0.792
#> GSM528657     2  0.7376      1.000 0.208 0.792
#> GSM528658     2  0.7376      1.000 0.208 0.792
#> GSM528655     2  0.7376      1.000 0.208 0.792
#> GSM528656     2  0.7376      1.000 0.208 0.792
#> GSM528663     1  0.8327      0.459 0.736 0.264
#> GSM528664     1  0.9909     -0.234 0.556 0.444
#> GSM528665     1  0.0000      0.907 1.000 0.000
#> GSM528666     1  0.0000      0.907 1.000 0.000
#> GSM528667     1  0.0000      0.907 1.000 0.000
#> GSM528668     1  0.0000      0.907 1.000 0.000
#> GSM528669     1  0.0938      0.903 0.988 0.012
#> GSM528670     1  0.0672      0.904 0.992 0.008
#> GSM528659     1  0.7376      0.820 0.792 0.208
#> GSM528660     1  0.7376      0.820 0.792 0.208
#> GSM528661     1  0.7376      0.820 0.792 0.208
#> GSM528662     1  0.7376      0.820 0.792 0.208
#> GSM528701     2  0.7376      1.000 0.208 0.792
#> GSM528702     2  0.7376      1.000 0.208 0.792
#> GSM528703     2  0.7376      1.000 0.208 0.792
#> GSM528704     2  0.7376      1.000 0.208 0.792
#> GSM528707     2  0.7376      1.000 0.208 0.792
#> GSM528708     2  0.7376      1.000 0.208 0.792
#> GSM528705     2  0.7376      1.000 0.208 0.792
#> GSM528706     2  0.7376      1.000 0.208 0.792
#> GSM528713     1  0.0000      0.907 1.000 0.000
#> GSM528714     1  0.0000      0.907 1.000 0.000
#> GSM528715     1  0.0000      0.907 1.000 0.000
#> GSM528716     1  0.0000      0.907 1.000 0.000
#> GSM528717     1  0.7376      0.820 0.792 0.208
#> GSM528718     1  0.7376      0.820 0.792 0.208
#> GSM528719     1  0.7376      0.820 0.792 0.208
#> GSM528720     1  0.7376      0.820 0.792 0.208
#> GSM528709     1  0.7376      0.820 0.792 0.208
#> GSM528710     1  0.7376      0.820 0.792 0.208
#> GSM528711     1  0.7376      0.820 0.792 0.208
#> GSM528712     1  0.7376      0.820 0.792 0.208
#> GSM528721     2  0.7376      1.000 0.208 0.792
#> GSM528722     2  0.7376      1.000 0.208 0.792
#> GSM528723     2  0.7376      1.000 0.208 0.792
#> GSM528724     2  0.7376      1.000 0.208 0.792
#> GSM528727     2  0.7376      1.000 0.208 0.792
#> GSM528728     2  0.7376      1.000 0.208 0.792
#> GSM528725     2  0.7376      1.000 0.208 0.792
#> GSM528726     2  0.7376      1.000 0.208 0.792
#> GSM528733     1  0.0000      0.907 1.000 0.000
#> GSM528734     1  0.0000      0.907 1.000 0.000
#> GSM528735     1  0.0000      0.907 1.000 0.000
#> GSM528736     1  0.0000      0.907 1.000 0.000
#> GSM528737     1  0.0000      0.907 1.000 0.000
#> GSM528738     1  0.0000      0.907 1.000 0.000
#> GSM528729     1  0.0000      0.907 1.000 0.000
#> GSM528730     1  0.0000      0.907 1.000 0.000
#> GSM528731     1  0.0000      0.907 1.000 0.000
#> GSM528732     1  0.0000      0.907 1.000 0.000
#> GSM528739     2  0.7376      1.000 0.208 0.792
#> GSM528740     2  0.7376      1.000 0.208 0.792
#> GSM528741     2  0.7376      1.000 0.208 0.792
#> GSM528742     2  0.7376      1.000 0.208 0.792
#> GSM528745     2  0.7376      1.000 0.208 0.792
#> GSM528746     2  0.7376      1.000 0.208 0.792
#> GSM528743     2  0.7376      1.000 0.208 0.792
#> GSM528744     2  0.7376      1.000 0.208 0.792
#> GSM528751     1  0.4022      0.820 0.920 0.080
#> GSM528752     1  0.2778      0.858 0.952 0.048
#> GSM528753     1  0.0000      0.907 1.000 0.000
#> GSM528754     1  0.0000      0.907 1.000 0.000
#> GSM528755     1  0.0000      0.907 1.000 0.000
#> GSM528756     1  0.0000      0.907 1.000 0.000
#> GSM528757     1  0.0000      0.907 1.000 0.000
#> GSM528758     1  0.0000      0.907 1.000 0.000
#> GSM528747     1  0.0000      0.907 1.000 0.000
#> GSM528748     1  0.0000      0.907 1.000 0.000
#> GSM528749     1  0.0000      0.907 1.000 0.000
#> GSM528750     1  0.0000      0.907 1.000 0.000
#> GSM528640     2  0.7376      1.000 0.208 0.792
#> GSM528641     2  0.7376      1.000 0.208 0.792
#> GSM528643     1  0.0000      0.907 1.000 0.000
#> GSM528644     1  0.0000      0.907 1.000 0.000
#> GSM528642     1  0.0000      0.907 1.000 0.000
#> GSM528620     2  0.7376      1.000 0.208 0.792
#> GSM528621     2  0.7376      1.000 0.208 0.792
#> GSM528623     1  0.0000      0.907 1.000 0.000
#> GSM528624     1  0.0000      0.907 1.000 0.000
#> GSM528622     1  0.0000      0.907 1.000 0.000
#> GSM528625     2  0.7376      1.000 0.208 0.792
#> GSM528626     2  0.7376      1.000 0.208 0.792
#> GSM528628     1  0.0000      0.907 1.000 0.000
#> GSM528629     1  0.0000      0.907 1.000 0.000
#> GSM528627     1  0.0000      0.907 1.000 0.000
#> GSM528630     2  0.7376      1.000 0.208 0.792
#> GSM528631     2  0.7376      1.000 0.208 0.792
#> GSM528632     2  0.7376      1.000 0.208 0.792
#> GSM528633     2  0.7376      1.000 0.208 0.792
#> GSM528636     1  0.0000      0.907 1.000 0.000
#> GSM528637     1  0.0000      0.907 1.000 0.000
#> GSM528638     1  0.0000      0.907 1.000 0.000
#> GSM528639     1  0.0000      0.907 1.000 0.000
#> GSM528634     1  0.0000      0.907 1.000 0.000
#> GSM528635     1  0.0000      0.907 1.000 0.000
#> GSM528645     1  0.0000      0.907 1.000 0.000
#> GSM528646     1  0.0000      0.907 1.000 0.000
#> GSM528647     1  0.0000      0.907 1.000 0.000
#> GSM528648     1  0.0000      0.907 1.000 0.000
#> GSM528649     1  0.0000      0.907 1.000 0.000
#> GSM528650     1  0.0000      0.907 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-CV-kmeans-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-CV-kmeans-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-CV-kmeans-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-CV-kmeans-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk CV-kmeans-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-CV-kmeans-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk CV-kmeans-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>             n agent(p) dose(p)  time(p) k
#> CV:kmeans 167   0.8905  1.0000 3.65e-29 2
#> CV:kmeans 167   0.0125  0.0029 4.32e-35 3
#> CV:kmeans  79   0.0555  0.0181 2.20e-14 4
#> CV:kmeans 167   0.0287  0.0134 3.09e-73 5
#> CV:kmeans 168   0.0256  0.0125 9.35e-74 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


CV:skmeans*

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["CV", "skmeans"]
# you can also extract it by
# res = res_list["CV:skmeans"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'CV' method.
#>   Subgroups are detected by 'skmeans' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 6.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk CV-skmeans-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk CV-skmeans-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           0.971       0.989         0.4855 0.512   0.512
#> 3 3 0.804           0.901       0.940         0.3628 0.785   0.595
#> 4 4 0.819           0.847       0.890         0.1004 0.906   0.732
#> 5 5 0.956           0.951       0.976         0.0732 0.909   0.685
#> 6 6 0.941           0.916       0.924         0.0296 0.970   0.867

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 6
#> attr(,"optional")
#> [1] 2 5

There is also optional best \(k\) = 2 5 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2   0.000      0.976 0.000 1.000
#> GSM528682     2   0.000      0.976 0.000 1.000
#> GSM528683     2   0.000      0.976 0.000 1.000
#> GSM528684     2   0.000      0.976 0.000 1.000
#> GSM528687     2   0.000      0.976 0.000 1.000
#> GSM528688     2   0.000      0.976 0.000 1.000
#> GSM528685     2   0.000      0.976 0.000 1.000
#> GSM528686     2   0.000      0.976 0.000 1.000
#> GSM528693     1   0.000      0.997 1.000 0.000
#> GSM528694     1   0.000      0.997 1.000 0.000
#> GSM528695     1   0.000      0.997 1.000 0.000
#> GSM528696     1   0.000      0.997 1.000 0.000
#> GSM528697     1   0.000      0.997 1.000 0.000
#> GSM528698     1   0.000      0.997 1.000 0.000
#> GSM528699     1   0.000      0.997 1.000 0.000
#> GSM528700     1   0.000      0.997 1.000 0.000
#> GSM528689     1   0.000      0.997 1.000 0.000
#> GSM528690     1   0.000      0.997 1.000 0.000
#> GSM528691     1   0.000      0.997 1.000 0.000
#> GSM528692     1   0.000      0.997 1.000 0.000
#> GSM528779     2   0.000      0.976 0.000 1.000
#> GSM528780     2   0.000      0.976 0.000 1.000
#> GSM528782     2   0.000      0.976 0.000 1.000
#> GSM528781     2   0.000      0.976 0.000 1.000
#> GSM528785     2   0.943      0.452 0.360 0.640
#> GSM528786     1   0.000      0.997 1.000 0.000
#> GSM528787     1   0.000      0.997 1.000 0.000
#> GSM528788     1   0.000      0.997 1.000 0.000
#> GSM528783     1   0.000      0.997 1.000 0.000
#> GSM528784     1   0.000      0.997 1.000 0.000
#> GSM528759     1   0.000      0.997 1.000 0.000
#> GSM528760     1   0.000      0.997 1.000 0.000
#> GSM528761     2   0.000      0.976 0.000 1.000
#> GSM528762     2   0.000      0.976 0.000 1.000
#> GSM528765     2   0.000      0.976 0.000 1.000
#> GSM528766     2   0.000      0.976 0.000 1.000
#> GSM528763     2   0.000      0.976 0.000 1.000
#> GSM528764     2   0.000      0.976 0.000 1.000
#> GSM528771     2   0.943      0.452 0.360 0.640
#> GSM528772     2   0.993      0.201 0.452 0.548
#> GSM528773     1   0.000      0.997 1.000 0.000
#> GSM528774     1   0.000      0.997 1.000 0.000
#> GSM528775     1   0.000      0.997 1.000 0.000
#> GSM528776     1   0.000      0.997 1.000 0.000
#> GSM528777     1   0.000      0.997 1.000 0.000
#> GSM528778     1   0.000      0.997 1.000 0.000
#> GSM528767     1   0.000      0.997 1.000 0.000
#> GSM528768     1   0.000      0.997 1.000 0.000
#> GSM528769     1   0.000      0.997 1.000 0.000
#> GSM528770     1   0.000      0.997 1.000 0.000
#> GSM528671     2   0.000      0.976 0.000 1.000
#> GSM528672     2   0.000      0.976 0.000 1.000
#> GSM528674     2   0.000      0.976 0.000 1.000
#> GSM528673     2   0.000      0.976 0.000 1.000
#> GSM528677     1   0.184      0.969 0.972 0.028
#> GSM528678     1   0.000      0.997 1.000 0.000
#> GSM528679     1   0.000      0.997 1.000 0.000
#> GSM528680     1   0.000      0.997 1.000 0.000
#> GSM528675     1   0.000      0.997 1.000 0.000
#> GSM528676     1   0.000      0.997 1.000 0.000
#> GSM528651     2   0.000      0.976 0.000 1.000
#> GSM528652     2   0.000      0.976 0.000 1.000
#> GSM528653     2   0.000      0.976 0.000 1.000
#> GSM528654     2   0.000      0.976 0.000 1.000
#> GSM528657     2   0.000      0.976 0.000 1.000
#> GSM528658     2   0.000      0.976 0.000 1.000
#> GSM528655     2   0.000      0.976 0.000 1.000
#> GSM528656     2   0.000      0.976 0.000 1.000
#> GSM528663     2   0.000      0.976 0.000 1.000
#> GSM528664     2   0.000      0.976 0.000 1.000
#> GSM528665     1   0.000      0.997 1.000 0.000
#> GSM528666     1   0.000      0.997 1.000 0.000
#> GSM528667     1   0.000      0.997 1.000 0.000
#> GSM528668     1   0.000      0.997 1.000 0.000
#> GSM528669     1   0.000      0.997 1.000 0.000
#> GSM528670     1   0.000      0.997 1.000 0.000
#> GSM528659     1   0.000      0.997 1.000 0.000
#> GSM528660     1   0.000      0.997 1.000 0.000
#> GSM528661     1   0.000      0.997 1.000 0.000
#> GSM528662     1   0.000      0.997 1.000 0.000
#> GSM528701     2   0.000      0.976 0.000 1.000
#> GSM528702     2   0.000      0.976 0.000 1.000
#> GSM528703     2   0.000      0.976 0.000 1.000
#> GSM528704     2   0.000      0.976 0.000 1.000
#> GSM528707     2   0.000      0.976 0.000 1.000
#> GSM528708     2   0.000      0.976 0.000 1.000
#> GSM528705     2   0.000      0.976 0.000 1.000
#> GSM528706     2   0.000      0.976 0.000 1.000
#> GSM528713     1   0.141      0.977 0.980 0.020
#> GSM528714     1   0.163      0.973 0.976 0.024
#> GSM528715     1   0.000      0.997 1.000 0.000
#> GSM528716     1   0.000      0.997 1.000 0.000
#> GSM528717     1   0.000      0.997 1.000 0.000
#> GSM528718     1   0.000      0.997 1.000 0.000
#> GSM528719     1   0.000      0.997 1.000 0.000
#> GSM528720     1   0.000      0.997 1.000 0.000
#> GSM528709     1   0.000      0.997 1.000 0.000
#> GSM528710     1   0.000      0.997 1.000 0.000
#> GSM528711     1   0.000      0.997 1.000 0.000
#> GSM528712     1   0.000      0.997 1.000 0.000
#> GSM528721     2   0.000      0.976 0.000 1.000
#> GSM528722     2   0.000      0.976 0.000 1.000
#> GSM528723     2   0.000      0.976 0.000 1.000
#> GSM528724     2   0.000      0.976 0.000 1.000
#> GSM528727     2   0.000      0.976 0.000 1.000
#> GSM528728     2   0.000      0.976 0.000 1.000
#> GSM528725     2   0.000      0.976 0.000 1.000
#> GSM528726     2   0.000      0.976 0.000 1.000
#> GSM528733     1   0.000      0.997 1.000 0.000
#> GSM528734     1   0.000      0.997 1.000 0.000
#> GSM528735     1   0.000      0.997 1.000 0.000
#> GSM528736     1   0.000      0.997 1.000 0.000
#> GSM528737     1   0.000      0.997 1.000 0.000
#> GSM528738     1   0.000      0.997 1.000 0.000
#> GSM528729     1   0.000      0.997 1.000 0.000
#> GSM528730     1   0.000      0.997 1.000 0.000
#> GSM528731     1   0.000      0.997 1.000 0.000
#> GSM528732     1   0.000      0.997 1.000 0.000
#> GSM528739     2   0.000      0.976 0.000 1.000
#> GSM528740     2   0.000      0.976 0.000 1.000
#> GSM528741     2   0.000      0.976 0.000 1.000
#> GSM528742     2   0.000      0.976 0.000 1.000
#> GSM528745     2   0.000      0.976 0.000 1.000
#> GSM528746     2   0.000      0.976 0.000 1.000
#> GSM528743     2   0.000      0.976 0.000 1.000
#> GSM528744     2   0.000      0.976 0.000 1.000
#> GSM528751     2   0.994      0.189 0.456 0.544
#> GSM528752     1   0.745      0.722 0.788 0.212
#> GSM528753     1   0.000      0.997 1.000 0.000
#> GSM528754     1   0.000      0.997 1.000 0.000
#> GSM528755     1   0.000      0.997 1.000 0.000
#> GSM528756     1   0.000      0.997 1.000 0.000
#> GSM528757     1   0.000      0.997 1.000 0.000
#> GSM528758     1   0.000      0.997 1.000 0.000
#> GSM528747     1   0.000      0.997 1.000 0.000
#> GSM528748     1   0.000      0.997 1.000 0.000
#> GSM528749     1   0.000      0.997 1.000 0.000
#> GSM528750     1   0.000      0.997 1.000 0.000
#> GSM528640     2   0.000      0.976 0.000 1.000
#> GSM528641     2   0.000      0.976 0.000 1.000
#> GSM528643     1   0.000      0.997 1.000 0.000
#> GSM528644     1   0.000      0.997 1.000 0.000
#> GSM528642     1   0.000      0.997 1.000 0.000
#> GSM528620     2   0.000      0.976 0.000 1.000
#> GSM528621     2   0.000      0.976 0.000 1.000
#> GSM528623     1   0.000      0.997 1.000 0.000
#> GSM528624     1   0.000      0.997 1.000 0.000
#> GSM528622     1   0.000      0.997 1.000 0.000
#> GSM528625     2   0.000      0.976 0.000 1.000
#> GSM528626     2   0.000      0.976 0.000 1.000
#> GSM528628     1   0.000      0.997 1.000 0.000
#> GSM528629     1   0.000      0.997 1.000 0.000
#> GSM528627     1   0.000      0.997 1.000 0.000
#> GSM528630     2   0.000      0.976 0.000 1.000
#> GSM528631     2   0.000      0.976 0.000 1.000
#> GSM528632     2   0.000      0.976 0.000 1.000
#> GSM528633     2   0.000      0.976 0.000 1.000
#> GSM528636     1   0.000      0.997 1.000 0.000
#> GSM528637     1   0.000      0.997 1.000 0.000
#> GSM528638     1   0.000      0.997 1.000 0.000
#> GSM528639     1   0.000      0.997 1.000 0.000
#> GSM528634     1   0.000      0.997 1.000 0.000
#> GSM528635     1   0.000      0.997 1.000 0.000
#> GSM528645     1   0.000      0.997 1.000 0.000
#> GSM528646     1   0.000      0.997 1.000 0.000
#> GSM528647     1   0.000      0.997 1.000 0.000
#> GSM528648     1   0.000      0.997 1.000 0.000
#> GSM528649     1   0.000      0.997 1.000 0.000
#> GSM528650     1   0.000      0.997 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-CV-skmeans-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-CV-skmeans-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-CV-skmeans-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-CV-skmeans-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk CV-skmeans-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-CV-skmeans-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk CV-skmeans-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>              n agent(p) dose(p)  time(p) k
#> CV:skmeans 165  0.86112 0.99980 1.74e-27 2
#> CV:skmeans 168  0.43376 0.98472 2.35e-52 3
#> CV:skmeans 165  0.00153 0.00527 4.77e-53 4
#> CV:skmeans 166  0.01727 0.00715 2.85e-70 5
#> CV:skmeans 167  0.00243 0.00679 5.64e-88 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


CV:pam*

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["CV", "pam"]
# you can also extract it by
# res = res_list["CV:pam"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'CV' method.
#>   Subgroups are detected by 'pam' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 5.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk CV-pam-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk CV-pam-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.998           0.961       0.983         0.5005 0.500   0.500
#> 3 3 1.000           0.965       0.986         0.2064 0.896   0.793
#> 4 4 0.937           0.921       0.965         0.1580 0.809   0.572
#> 5 5 0.918           0.899       0.955         0.0832 0.907   0.715
#> 6 6 0.832           0.767       0.865         0.0467 0.969   0.880

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 5
#> attr(,"optional")
#> [1] 2 3 4

There is also optional best \(k\) = 2 3 4 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2  0.0000      0.983 0.000 1.000
#> GSM528682     2  0.0000      0.983 0.000 1.000
#> GSM528683     2  0.0000      0.983 0.000 1.000
#> GSM528684     2  0.0000      0.983 0.000 1.000
#> GSM528687     2  0.0000      0.983 0.000 1.000
#> GSM528688     2  0.0000      0.983 0.000 1.000
#> GSM528685     2  0.0000      0.983 0.000 1.000
#> GSM528686     2  0.0000      0.983 0.000 1.000
#> GSM528693     1  0.0000      0.981 1.000 0.000
#> GSM528694     1  0.0000      0.981 1.000 0.000
#> GSM528695     1  0.0000      0.981 1.000 0.000
#> GSM528696     1  0.0000      0.981 1.000 0.000
#> GSM528697     1  0.0000      0.981 1.000 0.000
#> GSM528698     1  0.0000      0.981 1.000 0.000
#> GSM528699     1  0.8267      0.657 0.740 0.260
#> GSM528700     1  0.0000      0.981 1.000 0.000
#> GSM528689     1  0.0000      0.981 1.000 0.000
#> GSM528690     1  0.7528      0.726 0.784 0.216
#> GSM528691     1  0.0000      0.981 1.000 0.000
#> GSM528692     1  0.0000      0.981 1.000 0.000
#> GSM528779     2  0.0000      0.983 0.000 1.000
#> GSM528780     2  0.0000      0.983 0.000 1.000
#> GSM528782     2  0.0000      0.983 0.000 1.000
#> GSM528781     2  0.0000      0.983 0.000 1.000
#> GSM528785     1  0.7219      0.752 0.800 0.200
#> GSM528786     1  0.0000      0.981 1.000 0.000
#> GSM528787     1  0.0000      0.981 1.000 0.000
#> GSM528788     2  0.3274      0.931 0.060 0.940
#> GSM528783     1  0.0000      0.981 1.000 0.000
#> GSM528784     1  0.0000      0.981 1.000 0.000
#> GSM528759     1  0.0000      0.981 1.000 0.000
#> GSM528760     1  0.0000      0.981 1.000 0.000
#> GSM528761     2  0.0000      0.983 0.000 1.000
#> GSM528762     2  0.0000      0.983 0.000 1.000
#> GSM528765     2  0.0000      0.983 0.000 1.000
#> GSM528766     2  0.0000      0.983 0.000 1.000
#> GSM528763     2  0.0000      0.983 0.000 1.000
#> GSM528764     2  0.0000      0.983 0.000 1.000
#> GSM528771     1  0.0000      0.981 1.000 0.000
#> GSM528772     1  0.0000      0.981 1.000 0.000
#> GSM528773     1  0.0000      0.981 1.000 0.000
#> GSM528774     1  0.0000      0.981 1.000 0.000
#> GSM528775     1  0.0000      0.981 1.000 0.000
#> GSM528776     1  0.0000      0.981 1.000 0.000
#> GSM528777     2  0.3431      0.927 0.064 0.936
#> GSM528778     2  0.8713      0.594 0.292 0.708
#> GSM528767     1  0.0000      0.981 1.000 0.000
#> GSM528768     1  0.0000      0.981 1.000 0.000
#> GSM528769     1  0.0000      0.981 1.000 0.000
#> GSM528770     1  0.0000      0.981 1.000 0.000
#> GSM528671     2  0.0000      0.983 0.000 1.000
#> GSM528672     2  0.0000      0.983 0.000 1.000
#> GSM528674     2  0.0000      0.983 0.000 1.000
#> GSM528673     2  0.0000      0.983 0.000 1.000
#> GSM528677     1  0.0000      0.981 1.000 0.000
#> GSM528678     1  0.0000      0.981 1.000 0.000
#> GSM528679     1  0.0000      0.981 1.000 0.000
#> GSM528680     1  0.0000      0.981 1.000 0.000
#> GSM528675     1  0.0000      0.981 1.000 0.000
#> GSM528676     1  0.0000      0.981 1.000 0.000
#> GSM528651     2  0.0000      0.983 0.000 1.000
#> GSM528652     2  0.0000      0.983 0.000 1.000
#> GSM528653     2  0.0000      0.983 0.000 1.000
#> GSM528654     2  0.0000      0.983 0.000 1.000
#> GSM528657     2  0.0000      0.983 0.000 1.000
#> GSM528658     2  0.0000      0.983 0.000 1.000
#> GSM528655     2  0.0000      0.983 0.000 1.000
#> GSM528656     2  0.0000      0.983 0.000 1.000
#> GSM528663     1  0.3274      0.925 0.940 0.060
#> GSM528664     2  0.0376      0.981 0.004 0.996
#> GSM528665     1  0.0000      0.981 1.000 0.000
#> GSM528666     1  0.0000      0.981 1.000 0.000
#> GSM528667     1  0.0000      0.981 1.000 0.000
#> GSM528668     1  0.0000      0.981 1.000 0.000
#> GSM528669     2  0.3431      0.927 0.064 0.936
#> GSM528670     1  0.0672      0.974 0.992 0.008
#> GSM528659     1  0.4562      0.886 0.904 0.096
#> GSM528660     1  0.0000      0.981 1.000 0.000
#> GSM528661     1  0.0000      0.981 1.000 0.000
#> GSM528662     1  0.0000      0.981 1.000 0.000
#> GSM528701     2  0.0000      0.983 0.000 1.000
#> GSM528702     2  0.0000      0.983 0.000 1.000
#> GSM528703     2  0.0000      0.983 0.000 1.000
#> GSM528704     2  0.0000      0.983 0.000 1.000
#> GSM528707     2  0.0000      0.983 0.000 1.000
#> GSM528708     2  0.0000      0.983 0.000 1.000
#> GSM528705     2  0.0000      0.983 0.000 1.000
#> GSM528706     2  0.0000      0.983 0.000 1.000
#> GSM528713     1  0.0000      0.981 1.000 0.000
#> GSM528714     1  0.0000      0.981 1.000 0.000
#> GSM528715     1  0.0000      0.981 1.000 0.000
#> GSM528716     1  0.0000      0.981 1.000 0.000
#> GSM528717     1  0.0000      0.981 1.000 0.000
#> GSM528718     1  0.0000      0.981 1.000 0.000
#> GSM528719     1  0.0000      0.981 1.000 0.000
#> GSM528720     1  0.0000      0.981 1.000 0.000
#> GSM528709     1  0.0000      0.981 1.000 0.000
#> GSM528710     1  0.0376      0.978 0.996 0.004
#> GSM528711     1  0.0000      0.981 1.000 0.000
#> GSM528712     1  0.0000      0.981 1.000 0.000
#> GSM528721     2  0.0000      0.983 0.000 1.000
#> GSM528722     2  0.0000      0.983 0.000 1.000
#> GSM528723     2  0.0000      0.983 0.000 1.000
#> GSM528724     2  0.0000      0.983 0.000 1.000
#> GSM528727     2  0.0000      0.983 0.000 1.000
#> GSM528728     2  0.0000      0.983 0.000 1.000
#> GSM528725     2  0.0000      0.983 0.000 1.000
#> GSM528726     2  0.0000      0.983 0.000 1.000
#> GSM528733     1  0.0000      0.981 1.000 0.000
#> GSM528734     1  0.0000      0.981 1.000 0.000
#> GSM528735     1  0.0000      0.981 1.000 0.000
#> GSM528736     1  0.0000      0.981 1.000 0.000
#> GSM528737     1  0.0000      0.981 1.000 0.000
#> GSM528738     1  0.0000      0.981 1.000 0.000
#> GSM528729     2  0.3431      0.927 0.064 0.936
#> GSM528730     2  0.7815      0.707 0.232 0.768
#> GSM528731     1  0.7219      0.752 0.800 0.200
#> GSM528732     1  0.0000      0.981 1.000 0.000
#> GSM528739     2  0.0000      0.983 0.000 1.000
#> GSM528740     2  0.0000      0.983 0.000 1.000
#> GSM528741     2  0.0000      0.983 0.000 1.000
#> GSM528742     2  0.0000      0.983 0.000 1.000
#> GSM528745     2  0.0000      0.983 0.000 1.000
#> GSM528746     2  0.0000      0.983 0.000 1.000
#> GSM528743     2  0.0000      0.983 0.000 1.000
#> GSM528744     2  0.0000      0.983 0.000 1.000
#> GSM528751     1  0.0000      0.981 1.000 0.000
#> GSM528752     1  0.0000      0.981 1.000 0.000
#> GSM528753     1  0.0000      0.981 1.000 0.000
#> GSM528754     1  0.0000      0.981 1.000 0.000
#> GSM528755     1  0.0000      0.981 1.000 0.000
#> GSM528756     1  0.0000      0.981 1.000 0.000
#> GSM528757     2  0.0000      0.983 0.000 1.000
#> GSM528758     2  0.0000      0.983 0.000 1.000
#> GSM528747     1  0.7299      0.752 0.796 0.204
#> GSM528748     2  0.0376      0.981 0.004 0.996
#> GSM528749     1  0.0000      0.981 1.000 0.000
#> GSM528750     1  0.0000      0.981 1.000 0.000
#> GSM528640     2  0.0000      0.983 0.000 1.000
#> GSM528641     2  0.0000      0.983 0.000 1.000
#> GSM528643     1  0.0000      0.981 1.000 0.000
#> GSM528644     2  0.0376      0.981 0.004 0.996
#> GSM528642     1  0.0000      0.981 1.000 0.000
#> GSM528620     2  0.0000      0.983 0.000 1.000
#> GSM528621     2  0.3879      0.913 0.076 0.924
#> GSM528623     1  0.0000      0.981 1.000 0.000
#> GSM528624     2  0.3431      0.927 0.064 0.936
#> GSM528622     1  0.0000      0.981 1.000 0.000
#> GSM528625     2  0.0000      0.983 0.000 1.000
#> GSM528626     2  0.0000      0.983 0.000 1.000
#> GSM528628     1  0.0000      0.981 1.000 0.000
#> GSM528629     1  0.9710      0.350 0.600 0.400
#> GSM528627     1  0.0000      0.981 1.000 0.000
#> GSM528630     2  0.0000      0.983 0.000 1.000
#> GSM528631     2  0.0000      0.983 0.000 1.000
#> GSM528632     2  0.0376      0.981 0.004 0.996
#> GSM528633     2  0.0376      0.981 0.004 0.996
#> GSM528636     1  0.0000      0.981 1.000 0.000
#> GSM528637     1  0.0000      0.981 1.000 0.000
#> GSM528638     2  0.0672      0.977 0.008 0.992
#> GSM528639     2  0.8955      0.544 0.312 0.688
#> GSM528634     1  0.0000      0.981 1.000 0.000
#> GSM528635     1  0.0000      0.981 1.000 0.000
#> GSM528645     1  0.0000      0.981 1.000 0.000
#> GSM528646     1  0.0000      0.981 1.000 0.000
#> GSM528647     1  0.0000      0.981 1.000 0.000
#> GSM528648     1  0.0000      0.981 1.000 0.000
#> GSM528649     1  0.0000      0.981 1.000 0.000
#> GSM528650     1  0.0000      0.981 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-CV-pam-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-CV-pam-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)
#> Error in mat[ceiling(1:nr/h_ratio), ceiling(1:nc/w_ratio), drop = FALSE]: subscript out of bounds

plot of chunk tab-CV-pam-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)
#> Error in mat[ceiling(1:nr/h_ratio), ceiling(1:nc/w_ratio), drop = FALSE]: subscript out of bounds

plot of chunk tab-CV-pam-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk CV-pam-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-CV-pam-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk CV-pam-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>          n agent(p) dose(p)  time(p) k
#> CV:pam 168 0.522904 0.91081 4.51e-23 2
#> CV:pam 168 0.000389 0.00994 7.96e-27 3
#> CV:pam 165 0.005162 0.04442 2.47e-48 4
#> CV:pam 159 0.014721 0.20333 1.38e-71 5
#> CV:pam 144 0.051547 0.15297 3.25e-73 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


CV:mclust

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["CV", "mclust"]
# you can also extract it by
# res = res_list["CV:mclust"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'CV' method.
#>   Subgroups are detected by 'mclust' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk CV-mclust-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk CV-mclust-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.434           0.796       0.897         0.4862 0.499   0.499
#> 3 3 0.740           0.872       0.919         0.3135 0.756   0.558
#> 4 4 0.693           0.735       0.847         0.1078 0.915   0.770
#> 5 5 0.658           0.648       0.790         0.0899 0.918   0.719
#> 6 6 0.682           0.627       0.741         0.0438 0.961   0.821

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2  0.0000      0.930 0.000 1.000
#> GSM528682     2  0.0000      0.930 0.000 1.000
#> GSM528683     2  0.0000      0.930 0.000 1.000
#> GSM528684     2  0.0000      0.930 0.000 1.000
#> GSM528687     2  0.0000      0.930 0.000 1.000
#> GSM528688     2  0.0000      0.930 0.000 1.000
#> GSM528685     2  0.3274      0.879 0.060 0.940
#> GSM528686     2  0.3274      0.879 0.060 0.940
#> GSM528693     1  0.2423      0.837 0.960 0.040
#> GSM528694     1  0.2236      0.837 0.964 0.036
#> GSM528695     1  0.5842      0.778 0.860 0.140
#> GSM528696     1  0.5842      0.778 0.860 0.140
#> GSM528697     1  0.0000      0.835 1.000 0.000
#> GSM528698     1  0.0000      0.835 1.000 0.000
#> GSM528699     1  0.0000      0.835 1.000 0.000
#> GSM528700     1  0.0000      0.835 1.000 0.000
#> GSM528689     1  0.0000      0.835 1.000 0.000
#> GSM528690     1  0.0000      0.835 1.000 0.000
#> GSM528691     1  0.0000      0.835 1.000 0.000
#> GSM528692     1  0.0000      0.835 1.000 0.000
#> GSM528779     2  0.0000      0.930 0.000 1.000
#> GSM528780     2  0.0000      0.930 0.000 1.000
#> GSM528782     2  0.0000      0.930 0.000 1.000
#> GSM528781     2  0.0000      0.930 0.000 1.000
#> GSM528785     2  0.7674      0.685 0.224 0.776
#> GSM528786     1  0.6801      0.779 0.820 0.180
#> GSM528787     1  0.4939      0.820 0.892 0.108
#> GSM528788     1  0.9552      0.510 0.624 0.376
#> GSM528783     1  0.0000      0.835 1.000 0.000
#> GSM528784     1  0.0000      0.835 1.000 0.000
#> GSM528759     1  0.4022      0.830 0.920 0.080
#> GSM528760     1  0.2948      0.836 0.948 0.052
#> GSM528761     2  0.0000      0.930 0.000 1.000
#> GSM528762     2  0.0000      0.930 0.000 1.000
#> GSM528765     2  0.0000      0.930 0.000 1.000
#> GSM528766     2  0.0000      0.930 0.000 1.000
#> GSM528763     2  0.0000      0.930 0.000 1.000
#> GSM528764     2  0.0672      0.925 0.008 0.992
#> GSM528771     2  0.7453      0.704 0.212 0.788
#> GSM528772     2  0.7528      0.698 0.216 0.784
#> GSM528773     1  0.6801      0.779 0.820 0.180
#> GSM528774     1  0.6801      0.779 0.820 0.180
#> GSM528775     1  0.6623      0.780 0.828 0.172
#> GSM528776     1  0.7602      0.737 0.780 0.220
#> GSM528777     1  0.1414      0.837 0.980 0.020
#> GSM528778     1  0.1184      0.837 0.984 0.016
#> GSM528767     1  0.0000      0.835 1.000 0.000
#> GSM528768     1  0.0000      0.835 1.000 0.000
#> GSM528769     1  0.0000      0.835 1.000 0.000
#> GSM528770     1  0.0000      0.835 1.000 0.000
#> GSM528671     2  0.0000      0.930 0.000 1.000
#> GSM528672     2  0.0000      0.930 0.000 1.000
#> GSM528674     2  0.0000      0.930 0.000 1.000
#> GSM528673     2  0.0672      0.925 0.008 0.992
#> GSM528677     2  0.7602      0.692 0.220 0.780
#> GSM528678     1  0.6623      0.785 0.828 0.172
#> GSM528679     1  0.7815      0.723 0.768 0.232
#> GSM528680     1  0.0000      0.835 1.000 0.000
#> GSM528675     1  0.0000      0.835 1.000 0.000
#> GSM528676     1  0.0000      0.835 1.000 0.000
#> GSM528651     2  0.0000      0.930 0.000 1.000
#> GSM528652     2  0.0000      0.930 0.000 1.000
#> GSM528653     2  0.0000      0.930 0.000 1.000
#> GSM528654     2  0.0000      0.930 0.000 1.000
#> GSM528657     2  0.0000      0.930 0.000 1.000
#> GSM528658     2  0.0000      0.930 0.000 1.000
#> GSM528655     2  0.0672      0.925 0.008 0.992
#> GSM528656     2  0.0672      0.925 0.008 0.992
#> GSM528663     2  0.7376      0.709 0.208 0.792
#> GSM528664     2  0.7376      0.709 0.208 0.792
#> GSM528665     1  0.6801      0.779 0.820 0.180
#> GSM528666     1  0.6801      0.779 0.820 0.180
#> GSM528667     1  0.5737      0.807 0.864 0.136
#> GSM528668     1  0.5737      0.807 0.864 0.136
#> GSM528669     1  0.2043      0.838 0.968 0.032
#> GSM528670     1  0.2043      0.838 0.968 0.032
#> GSM528659     1  0.0000      0.835 1.000 0.000
#> GSM528660     1  0.0000      0.835 1.000 0.000
#> GSM528661     1  0.0000      0.835 1.000 0.000
#> GSM528662     1  0.0000      0.835 1.000 0.000
#> GSM528701     2  0.0000      0.930 0.000 1.000
#> GSM528702     2  0.0000      0.930 0.000 1.000
#> GSM528703     2  0.0000      0.930 0.000 1.000
#> GSM528704     2  0.0000      0.930 0.000 1.000
#> GSM528707     2  0.0000      0.930 0.000 1.000
#> GSM528708     2  0.0000      0.930 0.000 1.000
#> GSM528705     2  0.0000      0.930 0.000 1.000
#> GSM528706     2  0.0000      0.930 0.000 1.000
#> GSM528713     2  0.9000      0.499 0.316 0.684
#> GSM528714     2  0.7453      0.704 0.212 0.788
#> GSM528715     1  0.6887      0.778 0.816 0.184
#> GSM528716     1  0.6973      0.775 0.812 0.188
#> GSM528717     1  0.1843      0.838 0.972 0.028
#> GSM528718     1  0.2043      0.838 0.968 0.032
#> GSM528719     1  0.0000      0.835 1.000 0.000
#> GSM528720     1  0.0000      0.835 1.000 0.000
#> GSM528709     1  0.0000      0.835 1.000 0.000
#> GSM528710     1  0.0000      0.835 1.000 0.000
#> GSM528711     1  0.0000      0.835 1.000 0.000
#> GSM528712     1  0.0000      0.835 1.000 0.000
#> GSM528721     2  0.0000      0.930 0.000 1.000
#> GSM528722     2  0.0000      0.930 0.000 1.000
#> GSM528723     2  0.0000      0.930 0.000 1.000
#> GSM528724     2  0.0000      0.930 0.000 1.000
#> GSM528727     2  0.0000      0.930 0.000 1.000
#> GSM528728     2  0.0000      0.930 0.000 1.000
#> GSM528725     2  0.0000      0.930 0.000 1.000
#> GSM528726     2  0.0000      0.930 0.000 1.000
#> GSM528733     1  0.6801      0.779 0.820 0.180
#> GSM528734     1  0.6801      0.779 0.820 0.180
#> GSM528735     1  0.2423      0.837 0.960 0.040
#> GSM528736     1  0.2423      0.837 0.960 0.040
#> GSM528737     1  0.6801      0.776 0.820 0.180
#> GSM528738     1  0.5059      0.818 0.888 0.112
#> GSM528729     1  0.9815      0.422 0.580 0.420
#> GSM528730     1  0.9815      0.422 0.580 0.420
#> GSM528731     1  0.8909      0.628 0.692 0.308
#> GSM528732     1  0.9815      0.422 0.580 0.420
#> GSM528739     2  0.0000      0.930 0.000 1.000
#> GSM528740     2  0.0000      0.930 0.000 1.000
#> GSM528741     2  0.0000      0.930 0.000 1.000
#> GSM528742     2  0.0000      0.930 0.000 1.000
#> GSM528745     2  0.0000      0.930 0.000 1.000
#> GSM528746     2  0.0000      0.930 0.000 1.000
#> GSM528743     2  0.0000      0.930 0.000 1.000
#> GSM528744     2  0.0000      0.930 0.000 1.000
#> GSM528751     2  0.7745      0.679 0.228 0.772
#> GSM528752     2  0.7950      0.658 0.240 0.760
#> GSM528753     1  0.6801      0.779 0.820 0.180
#> GSM528754     1  0.6801      0.779 0.820 0.180
#> GSM528755     1  0.4815      0.823 0.896 0.104
#> GSM528756     1  0.2423      0.837 0.960 0.040
#> GSM528757     1  0.9815      0.422 0.580 0.420
#> GSM528758     1  0.9815      0.422 0.580 0.420
#> GSM528747     1  0.7602      0.740 0.780 0.220
#> GSM528748     2  0.9815      0.166 0.420 0.580
#> GSM528749     1  0.8955      0.626 0.688 0.312
#> GSM528750     1  0.9795      0.431 0.584 0.416
#> GSM528640     2  0.0000      0.930 0.000 1.000
#> GSM528641     2  0.0672      0.925 0.008 0.992
#> GSM528643     1  0.6801      0.779 0.820 0.180
#> GSM528644     2  0.9710      0.242 0.400 0.600
#> GSM528642     1  0.9963      0.354 0.536 0.464
#> GSM528620     2  0.0000      0.930 0.000 1.000
#> GSM528621     2  0.3733      0.864 0.072 0.928
#> GSM528623     1  0.6801      0.779 0.820 0.180
#> GSM528624     1  0.9815      0.422 0.580 0.420
#> GSM528622     1  0.9608      0.500 0.616 0.384
#> GSM528625     2  0.0000      0.930 0.000 1.000
#> GSM528626     2  0.0672      0.925 0.008 0.992
#> GSM528628     1  0.6801      0.779 0.820 0.180
#> GSM528629     1  0.9815      0.422 0.580 0.420
#> GSM528627     1  0.9286      0.575 0.656 0.344
#> GSM528630     2  0.0000      0.930 0.000 1.000
#> GSM528631     2  0.0000      0.930 0.000 1.000
#> GSM528632     2  0.0672      0.925 0.008 0.992
#> GSM528633     2  0.0672      0.925 0.008 0.992
#> GSM528636     1  0.6801      0.779 0.820 0.180
#> GSM528637     1  0.6801      0.779 0.820 0.180
#> GSM528638     1  0.9815      0.422 0.580 0.420
#> GSM528639     1  0.9815      0.422 0.580 0.420
#> GSM528634     1  0.7883      0.724 0.764 0.236
#> GSM528635     1  0.8813      0.644 0.700 0.300
#> GSM528645     2  0.9427      0.349 0.360 0.640
#> GSM528646     2  0.9522      0.314 0.372 0.628
#> GSM528647     2  0.9491      0.335 0.368 0.632
#> GSM528648     1  0.9209      0.581 0.664 0.336
#> GSM528649     1  0.7219      0.756 0.800 0.200
#> GSM528650     1  0.5059      0.820 0.888 0.112

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-CV-mclust-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-CV-mclust-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-CV-mclust-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-CV-mclust-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk CV-mclust-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-CV-mclust-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk CV-mclust-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>             n agent(p)  dose(p)  time(p) k
#> CV:mclust 152 8.45e-01 9.70e-01 8.25e-25 2
#> CV:mclust 165 2.14e-05 6.60e-06 1.06e-29 3
#> CV:mclust 142 7.48e-03 1.74e-03 8.79e-48 4
#> CV:mclust 136 1.93e-03 9.03e-04 1.68e-48 5
#> CV:mclust 127 3.12e-03 2.73e-04 1.68e-50 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


CV:NMF*

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["CV", "NMF"]
# you can also extract it by
# res = res_list["CV:NMF"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'CV' method.
#>   Subgroups are detected by 'NMF' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk CV-NMF-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk CV-NMF-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           0.965       0.982         0.4848 0.512   0.512
#> 3 3 0.921           0.916       0.965         0.3240 0.796   0.622
#> 4 4 0.840           0.811       0.910         0.1289 0.868   0.655
#> 5 5 0.807           0.789       0.884         0.0667 0.921   0.725
#> 6 6 0.830           0.785       0.877         0.0366 0.922   0.687

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3
#> attr(,"optional")
#> [1] 2

There is also optional best \(k\) = 2 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2  0.0000     0.9814 0.000 1.000
#> GSM528682     2  0.0000     0.9814 0.000 1.000
#> GSM528683     2  0.0000     0.9814 0.000 1.000
#> GSM528684     2  0.0000     0.9814 0.000 1.000
#> GSM528687     2  0.0000     0.9814 0.000 1.000
#> GSM528688     2  0.0000     0.9814 0.000 1.000
#> GSM528685     2  0.0000     0.9814 0.000 1.000
#> GSM528686     2  0.0000     0.9814 0.000 1.000
#> GSM528693     1  0.1184     0.9854 0.984 0.016
#> GSM528694     1  0.1184     0.9854 0.984 0.016
#> GSM528695     1  0.0000     0.9807 1.000 0.000
#> GSM528696     1  0.0000     0.9807 1.000 0.000
#> GSM528697     1  0.0000     0.9807 1.000 0.000
#> GSM528698     1  0.0000     0.9807 1.000 0.000
#> GSM528699     1  0.0000     0.9807 1.000 0.000
#> GSM528700     1  0.0000     0.9807 1.000 0.000
#> GSM528689     1  0.0000     0.9807 1.000 0.000
#> GSM528690     1  0.0000     0.9807 1.000 0.000
#> GSM528691     1  0.0000     0.9807 1.000 0.000
#> GSM528692     1  0.0000     0.9807 1.000 0.000
#> GSM528779     2  0.0000     0.9814 0.000 1.000
#> GSM528780     2  0.0000     0.9814 0.000 1.000
#> GSM528782     2  0.0000     0.9814 0.000 1.000
#> GSM528781     2  0.0000     0.9814 0.000 1.000
#> GSM528785     2  0.6712     0.7769 0.176 0.824
#> GSM528786     1  0.1184     0.9854 0.984 0.016
#> GSM528787     1  0.1184     0.9854 0.984 0.016
#> GSM528788     1  0.1184     0.9854 0.984 0.016
#> GSM528783     1  0.0000     0.9807 1.000 0.000
#> GSM528784     1  0.0000     0.9807 1.000 0.000
#> GSM528759     1  0.1184     0.9854 0.984 0.016
#> GSM528760     1  0.1184     0.9854 0.984 0.016
#> GSM528761     2  0.0000     0.9814 0.000 1.000
#> GSM528762     2  0.0000     0.9814 0.000 1.000
#> GSM528765     2  0.0000     0.9814 0.000 1.000
#> GSM528766     2  0.0000     0.9814 0.000 1.000
#> GSM528763     2  0.0000     0.9814 0.000 1.000
#> GSM528764     2  0.0000     0.9814 0.000 1.000
#> GSM528771     2  0.6048     0.8159 0.148 0.852
#> GSM528772     2  0.9850     0.2350 0.428 0.572
#> GSM528773     1  0.1184     0.9854 0.984 0.016
#> GSM528774     1  0.1184     0.9854 0.984 0.016
#> GSM528775     1  0.1184     0.9854 0.984 0.016
#> GSM528776     1  0.1184     0.9854 0.984 0.016
#> GSM528777     1  0.0000     0.9807 1.000 0.000
#> GSM528778     1  0.0000     0.9807 1.000 0.000
#> GSM528767     1  0.0000     0.9807 1.000 0.000
#> GSM528768     1  0.0000     0.9807 1.000 0.000
#> GSM528769     1  0.0000     0.9807 1.000 0.000
#> GSM528770     1  0.0000     0.9807 1.000 0.000
#> GSM528671     2  0.0000     0.9814 0.000 1.000
#> GSM528672     2  0.0000     0.9814 0.000 1.000
#> GSM528674     2  0.0000     0.9814 0.000 1.000
#> GSM528673     2  0.0000     0.9814 0.000 1.000
#> GSM528677     1  0.7219     0.7662 0.800 0.200
#> GSM528678     1  0.1184     0.9854 0.984 0.016
#> GSM528679     1  0.0000     0.9807 1.000 0.000
#> GSM528680     1  0.0000     0.9807 1.000 0.000
#> GSM528675     1  0.0000     0.9807 1.000 0.000
#> GSM528676     1  0.0000     0.9807 1.000 0.000
#> GSM528651     2  0.0000     0.9814 0.000 1.000
#> GSM528652     2  0.0000     0.9814 0.000 1.000
#> GSM528653     2  0.0000     0.9814 0.000 1.000
#> GSM528654     2  0.0000     0.9814 0.000 1.000
#> GSM528657     2  0.0000     0.9814 0.000 1.000
#> GSM528658     2  0.0000     0.9814 0.000 1.000
#> GSM528655     2  0.0000     0.9814 0.000 1.000
#> GSM528656     2  0.0000     0.9814 0.000 1.000
#> GSM528663     2  0.0672     0.9740 0.008 0.992
#> GSM528664     2  0.0000     0.9814 0.000 1.000
#> GSM528665     1  0.1184     0.9854 0.984 0.016
#> GSM528666     1  0.1184     0.9854 0.984 0.016
#> GSM528667     1  0.1184     0.9854 0.984 0.016
#> GSM528668     1  0.1184     0.9854 0.984 0.016
#> GSM528669     1  0.1184     0.9854 0.984 0.016
#> GSM528670     1  0.1184     0.9854 0.984 0.016
#> GSM528659     1  0.0000     0.9807 1.000 0.000
#> GSM528660     1  0.0000     0.9807 1.000 0.000
#> GSM528661     1  0.0000     0.9807 1.000 0.000
#> GSM528662     1  0.0000     0.9807 1.000 0.000
#> GSM528701     2  0.0000     0.9814 0.000 1.000
#> GSM528702     2  0.0000     0.9814 0.000 1.000
#> GSM528703     2  0.0000     0.9814 0.000 1.000
#> GSM528704     2  0.0000     0.9814 0.000 1.000
#> GSM528707     2  0.0000     0.9814 0.000 1.000
#> GSM528708     2  0.0000     0.9814 0.000 1.000
#> GSM528705     2  0.0000     0.9814 0.000 1.000
#> GSM528706     2  0.0000     0.9814 0.000 1.000
#> GSM528713     1  0.7219     0.7662 0.800 0.200
#> GSM528714     1  0.6973     0.7840 0.812 0.188
#> GSM528715     1  0.1184     0.9854 0.984 0.016
#> GSM528716     1  0.1184     0.9854 0.984 0.016
#> GSM528717     1  0.0000     0.9807 1.000 0.000
#> GSM528718     1  0.0000     0.9807 1.000 0.000
#> GSM528719     1  0.0000     0.9807 1.000 0.000
#> GSM528720     1  0.0000     0.9807 1.000 0.000
#> GSM528709     1  0.0000     0.9807 1.000 0.000
#> GSM528710     1  0.0000     0.9807 1.000 0.000
#> GSM528711     1  0.0000     0.9807 1.000 0.000
#> GSM528712     1  0.0000     0.9807 1.000 0.000
#> GSM528721     2  0.0000     0.9814 0.000 1.000
#> GSM528722     2  0.0000     0.9814 0.000 1.000
#> GSM528723     2  0.0000     0.9814 0.000 1.000
#> GSM528724     2  0.0000     0.9814 0.000 1.000
#> GSM528727     2  0.0000     0.9814 0.000 1.000
#> GSM528728     2  0.0000     0.9814 0.000 1.000
#> GSM528725     2  0.0000     0.9814 0.000 1.000
#> GSM528726     2  0.0000     0.9814 0.000 1.000
#> GSM528733     1  0.1184     0.9854 0.984 0.016
#> GSM528734     1  0.1184     0.9854 0.984 0.016
#> GSM528735     1  0.1184     0.9854 0.984 0.016
#> GSM528736     1  0.1184     0.9854 0.984 0.016
#> GSM528737     1  0.1184     0.9854 0.984 0.016
#> GSM528738     1  0.1184     0.9854 0.984 0.016
#> GSM528729     1  0.1184     0.9854 0.984 0.016
#> GSM528730     1  0.1184     0.9854 0.984 0.016
#> GSM528731     1  0.1184     0.9854 0.984 0.016
#> GSM528732     1  0.1184     0.9854 0.984 0.016
#> GSM528739     2  0.0000     0.9814 0.000 1.000
#> GSM528740     2  0.0000     0.9814 0.000 1.000
#> GSM528741     2  0.0000     0.9814 0.000 1.000
#> GSM528742     2  0.0000     0.9814 0.000 1.000
#> GSM528745     2  0.0000     0.9814 0.000 1.000
#> GSM528746     2  0.0000     0.9814 0.000 1.000
#> GSM528743     2  0.0000     0.9814 0.000 1.000
#> GSM528744     2  0.0000     0.9814 0.000 1.000
#> GSM528751     2  0.9983     0.0681 0.476 0.524
#> GSM528752     1  0.8661     0.6133 0.712 0.288
#> GSM528753     1  0.1184     0.9854 0.984 0.016
#> GSM528754     1  0.1184     0.9854 0.984 0.016
#> GSM528755     1  0.1184     0.9854 0.984 0.016
#> GSM528756     1  0.1184     0.9854 0.984 0.016
#> GSM528757     1  0.1414     0.9824 0.980 0.020
#> GSM528758     1  0.1184     0.9854 0.984 0.016
#> GSM528747     1  0.1184     0.9854 0.984 0.016
#> GSM528748     1  0.1184     0.9854 0.984 0.016
#> GSM528749     1  0.1184     0.9854 0.984 0.016
#> GSM528750     1  0.1184     0.9854 0.984 0.016
#> GSM528640     2  0.0000     0.9814 0.000 1.000
#> GSM528641     2  0.0000     0.9814 0.000 1.000
#> GSM528643     1  0.1184     0.9854 0.984 0.016
#> GSM528644     1  0.1184     0.9854 0.984 0.016
#> GSM528642     1  0.1184     0.9854 0.984 0.016
#> GSM528620     2  0.0000     0.9814 0.000 1.000
#> GSM528621     2  0.0000     0.9814 0.000 1.000
#> GSM528623     1  0.1184     0.9854 0.984 0.016
#> GSM528624     1  0.1184     0.9854 0.984 0.016
#> GSM528622     1  0.1184     0.9854 0.984 0.016
#> GSM528625     2  0.0000     0.9814 0.000 1.000
#> GSM528626     2  0.0000     0.9814 0.000 1.000
#> GSM528628     1  0.1184     0.9854 0.984 0.016
#> GSM528629     1  0.1184     0.9854 0.984 0.016
#> GSM528627     1  0.1184     0.9854 0.984 0.016
#> GSM528630     2  0.0000     0.9814 0.000 1.000
#> GSM528631     2  0.0000     0.9814 0.000 1.000
#> GSM528632     2  0.0000     0.9814 0.000 1.000
#> GSM528633     2  0.0000     0.9814 0.000 1.000
#> GSM528636     1  0.1184     0.9854 0.984 0.016
#> GSM528637     1  0.1184     0.9854 0.984 0.016
#> GSM528638     1  0.1184     0.9854 0.984 0.016
#> GSM528639     1  0.1184     0.9854 0.984 0.016
#> GSM528634     1  0.1184     0.9854 0.984 0.016
#> GSM528635     1  0.1184     0.9854 0.984 0.016
#> GSM528645     1  0.1184     0.9854 0.984 0.016
#> GSM528646     1  0.1184     0.9854 0.984 0.016
#> GSM528647     1  0.1184     0.9854 0.984 0.016
#> GSM528648     1  0.1184     0.9854 0.984 0.016
#> GSM528649     1  0.1184     0.9854 0.984 0.016
#> GSM528650     1  0.1184     0.9854 0.984 0.016

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-CV-NMF-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-CV-NMF-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-CV-NMF-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-CV-NMF-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk CV-NMF-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-CV-NMF-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk CV-NMF-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>          n agent(p) dose(p)  time(p) k
#> CV:NMF 167  0.85955 0.99881 3.81e-27 2
#> CV:NMF 162  0.00640 0.00114 4.41e-35 3
#> CV:NMF 151  0.01861 0.01267 8.31e-43 4
#> CV:NMF 155  0.09875 0.00526 1.15e-72 5
#> CV:NMF 149  0.00514 0.01197 5.89e-63 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


MAD:hclust*

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["MAD", "hclust"]
# you can also extract it by
# res = res_list["MAD:hclust"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'MAD' method.
#>   Subgroups are detected by 'hclust' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk MAD-hclust-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk MAD-hclust-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.905           0.901       0.964         0.4475 0.563   0.563
#> 3 3 0.910           0.887       0.961         0.1740 0.919   0.857
#> 4 4 0.893           0.863       0.943         0.3326 0.812   0.610
#> 5 5 0.837           0.859       0.913         0.0546 0.963   0.874
#> 6 6 0.852           0.829       0.914         0.0568 0.948   0.797

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3
#> attr(,"optional")
#> [1] 2

There is also optional best \(k\) = 2 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2  0.0000    0.96898 0.000 1.000
#> GSM528682     2  0.0000    0.96898 0.000 1.000
#> GSM528683     2  0.0000    0.96898 0.000 1.000
#> GSM528684     2  0.0000    0.96898 0.000 1.000
#> GSM528687     2  0.0000    0.96898 0.000 1.000
#> GSM528688     2  0.0000    0.96898 0.000 1.000
#> GSM528685     1  0.9993    0.07663 0.516 0.484
#> GSM528686     1  0.9993    0.07663 0.516 0.484
#> GSM528693     1  0.0376    0.95407 0.996 0.004
#> GSM528694     1  0.0376    0.95407 0.996 0.004
#> GSM528695     1  0.0000    0.95696 1.000 0.000
#> GSM528696     1  0.0000    0.95696 1.000 0.000
#> GSM528697     1  0.0000    0.95696 1.000 0.000
#> GSM528698     1  0.0000    0.95696 1.000 0.000
#> GSM528699     1  0.0000    0.95696 1.000 0.000
#> GSM528700     1  0.0000    0.95696 1.000 0.000
#> GSM528689     1  0.0000    0.95696 1.000 0.000
#> GSM528690     1  0.0000    0.95696 1.000 0.000
#> GSM528691     1  0.0000    0.95696 1.000 0.000
#> GSM528692     1  0.0000    0.95696 1.000 0.000
#> GSM528779     2  0.1633    0.95168 0.024 0.976
#> GSM528780     2  0.0000    0.96898 0.000 1.000
#> GSM528782     2  0.0000    0.96898 0.000 1.000
#> GSM528781     2  0.5842    0.83252 0.140 0.860
#> GSM528785     1  0.0376    0.95407 0.996 0.004
#> GSM528786     1  0.0000    0.95696 1.000 0.000
#> GSM528787     1  0.0000    0.95696 1.000 0.000
#> GSM528788     1  0.0000    0.95696 1.000 0.000
#> GSM528783     1  0.0000    0.95696 1.000 0.000
#> GSM528784     1  0.0000    0.95696 1.000 0.000
#> GSM528759     1  0.0000    0.95696 1.000 0.000
#> GSM528760     1  0.0000    0.95696 1.000 0.000
#> GSM528761     2  0.0000    0.96898 0.000 1.000
#> GSM528762     2  0.0000    0.96898 0.000 1.000
#> GSM528765     2  0.0000    0.96898 0.000 1.000
#> GSM528766     2  0.0000    0.96898 0.000 1.000
#> GSM528763     2  0.9427    0.41059 0.360 0.640
#> GSM528764     2  0.9998   -0.00906 0.492 0.508
#> GSM528771     1  0.0376    0.95407 0.996 0.004
#> GSM528772     1  0.0376    0.95407 0.996 0.004
#> GSM528773     1  0.0000    0.95696 1.000 0.000
#> GSM528774     1  0.0000    0.95696 1.000 0.000
#> GSM528775     1  0.0000    0.95696 1.000 0.000
#> GSM528776     1  0.0000    0.95696 1.000 0.000
#> GSM528777     1  0.0000    0.95696 1.000 0.000
#> GSM528778     1  0.0000    0.95696 1.000 0.000
#> GSM528767     1  0.0000    0.95696 1.000 0.000
#> GSM528768     1  0.0000    0.95696 1.000 0.000
#> GSM528769     1  0.0000    0.95696 1.000 0.000
#> GSM528770     1  0.0000    0.95696 1.000 0.000
#> GSM528671     2  0.2778    0.93231 0.048 0.952
#> GSM528672     2  0.0000    0.96898 0.000 1.000
#> GSM528674     2  0.0000    0.96898 0.000 1.000
#> GSM528673     1  0.9993    0.07663 0.516 0.484
#> GSM528677     1  0.0376    0.95407 0.996 0.004
#> GSM528678     1  0.0000    0.95696 1.000 0.000
#> GSM528679     1  0.0000    0.95696 1.000 0.000
#> GSM528680     1  0.0000    0.95696 1.000 0.000
#> GSM528675     1  0.0000    0.95696 1.000 0.000
#> GSM528676     1  0.0000    0.95696 1.000 0.000
#> GSM528651     2  0.2778    0.93231 0.048 0.952
#> GSM528652     2  0.2778    0.93231 0.048 0.952
#> GSM528653     2  0.0000    0.96898 0.000 1.000
#> GSM528654     2  0.0000    0.96898 0.000 1.000
#> GSM528657     2  0.0000    0.96898 0.000 1.000
#> GSM528658     2  0.0000    0.96898 0.000 1.000
#> GSM528655     1  0.9993    0.07663 0.516 0.484
#> GSM528656     1  0.9993    0.07663 0.516 0.484
#> GSM528663     1  0.0376    0.95407 0.996 0.004
#> GSM528664     1  0.0376    0.95407 0.996 0.004
#> GSM528665     1  0.0000    0.95696 1.000 0.000
#> GSM528666     1  0.0000    0.95696 1.000 0.000
#> GSM528667     1  0.0000    0.95696 1.000 0.000
#> GSM528668     1  0.0000    0.95696 1.000 0.000
#> GSM528669     1  0.0000    0.95696 1.000 0.000
#> GSM528670     1  0.0000    0.95696 1.000 0.000
#> GSM528659     1  0.0000    0.95696 1.000 0.000
#> GSM528660     1  0.0000    0.95696 1.000 0.000
#> GSM528661     1  0.0000    0.95696 1.000 0.000
#> GSM528662     1  0.0000    0.95696 1.000 0.000
#> GSM528701     2  0.0000    0.96898 0.000 1.000
#> GSM528702     2  0.0000    0.96898 0.000 1.000
#> GSM528703     2  0.0000    0.96898 0.000 1.000
#> GSM528704     2  0.0000    0.96898 0.000 1.000
#> GSM528707     2  0.0000    0.96898 0.000 1.000
#> GSM528708     2  0.0000    0.96898 0.000 1.000
#> GSM528705     2  0.0000    0.96898 0.000 1.000
#> GSM528706     2  0.0000    0.96898 0.000 1.000
#> GSM528713     1  0.0376    0.95407 0.996 0.004
#> GSM528714     1  0.0376    0.95407 0.996 0.004
#> GSM528715     1  0.0000    0.95696 1.000 0.000
#> GSM528716     1  0.0000    0.95696 1.000 0.000
#> GSM528717     1  0.0000    0.95696 1.000 0.000
#> GSM528718     1  0.0000    0.95696 1.000 0.000
#> GSM528719     1  0.0000    0.95696 1.000 0.000
#> GSM528720     1  0.0000    0.95696 1.000 0.000
#> GSM528709     1  0.0000    0.95696 1.000 0.000
#> GSM528710     1  0.0000    0.95696 1.000 0.000
#> GSM528711     1  0.0000    0.95696 1.000 0.000
#> GSM528712     1  0.0000    0.95696 1.000 0.000
#> GSM528721     2  0.0000    0.96898 0.000 1.000
#> GSM528722     2  0.0000    0.96898 0.000 1.000
#> GSM528723     2  0.0000    0.96898 0.000 1.000
#> GSM528724     2  0.0000    0.96898 0.000 1.000
#> GSM528727     2  0.0000    0.96898 0.000 1.000
#> GSM528728     2  0.0000    0.96898 0.000 1.000
#> GSM528725     2  0.0000    0.96898 0.000 1.000
#> GSM528726     2  0.0000    0.96898 0.000 1.000
#> GSM528733     1  0.0000    0.95696 1.000 0.000
#> GSM528734     1  0.0000    0.95696 1.000 0.000
#> GSM528735     1  0.0000    0.95696 1.000 0.000
#> GSM528736     1  0.0000    0.95696 1.000 0.000
#> GSM528737     1  0.0000    0.95696 1.000 0.000
#> GSM528738     1  0.0000    0.95696 1.000 0.000
#> GSM528729     1  0.0000    0.95696 1.000 0.000
#> GSM528730     1  0.0000    0.95696 1.000 0.000
#> GSM528731     1  0.0000    0.95696 1.000 0.000
#> GSM528732     1  0.0000    0.95696 1.000 0.000
#> GSM528739     2  0.0000    0.96898 0.000 1.000
#> GSM528740     2  0.0000    0.96898 0.000 1.000
#> GSM528741     2  0.0000    0.96898 0.000 1.000
#> GSM528742     2  0.0000    0.96898 0.000 1.000
#> GSM528745     2  0.4690    0.87991 0.100 0.900
#> GSM528746     2  0.0000    0.96898 0.000 1.000
#> GSM528743     2  0.4939    0.87127 0.108 0.892
#> GSM528744     2  0.1414    0.95487 0.020 0.980
#> GSM528751     1  0.0376    0.95407 0.996 0.004
#> GSM528752     1  0.0376    0.95407 0.996 0.004
#> GSM528753     1  0.0000    0.95696 1.000 0.000
#> GSM528754     1  0.0000    0.95696 1.000 0.000
#> GSM528755     1  0.0000    0.95696 1.000 0.000
#> GSM528756     1  0.0000    0.95696 1.000 0.000
#> GSM528757     1  0.0000    0.95696 1.000 0.000
#> GSM528758     1  0.0000    0.95696 1.000 0.000
#> GSM528747     1  0.0000    0.95696 1.000 0.000
#> GSM528748     1  0.0000    0.95696 1.000 0.000
#> GSM528749     1  0.0000    0.95696 1.000 0.000
#> GSM528750     1  0.0000    0.95696 1.000 0.000
#> GSM528640     2  0.0000    0.96898 0.000 1.000
#> GSM528641     1  0.9993    0.07663 0.516 0.484
#> GSM528643     1  0.0000    0.95696 1.000 0.000
#> GSM528644     1  0.0000    0.95696 1.000 0.000
#> GSM528642     1  0.0000    0.95696 1.000 0.000
#> GSM528620     2  0.0000    0.96898 0.000 1.000
#> GSM528621     1  0.9754    0.31151 0.592 0.408
#> GSM528623     1  0.0000    0.95696 1.000 0.000
#> GSM528624     1  0.0000    0.95696 1.000 0.000
#> GSM528622     1  0.0000    0.95696 1.000 0.000
#> GSM528625     2  0.0000    0.96898 0.000 1.000
#> GSM528626     1  0.9795    0.28960 0.584 0.416
#> GSM528628     1  0.0000    0.95696 1.000 0.000
#> GSM528629     1  0.0000    0.95696 1.000 0.000
#> GSM528627     1  0.0000    0.95696 1.000 0.000
#> GSM528630     2  0.0000    0.96898 0.000 1.000
#> GSM528631     2  0.6048    0.82204 0.148 0.852
#> GSM528632     1  0.9754    0.31151 0.592 0.408
#> GSM528633     1  0.9754    0.31151 0.592 0.408
#> GSM528636     1  0.0000    0.95696 1.000 0.000
#> GSM528637     1  0.0000    0.95696 1.000 0.000
#> GSM528638     1  0.0000    0.95696 1.000 0.000
#> GSM528639     1  0.0000    0.95696 1.000 0.000
#> GSM528634     1  0.0000    0.95696 1.000 0.000
#> GSM528635     1  0.0000    0.95696 1.000 0.000
#> GSM528645     1  0.0000    0.95696 1.000 0.000
#> GSM528646     1  0.0000    0.95696 1.000 0.000
#> GSM528647     1  0.0000    0.95696 1.000 0.000
#> GSM528648     1  0.0000    0.95696 1.000 0.000
#> GSM528649     1  0.0000    0.95696 1.000 0.000
#> GSM528650     1  0.0000    0.95696 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-MAD-hclust-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-MAD-hclust-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-MAD-hclust-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-MAD-hclust-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk MAD-hclust-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-MAD-hclust-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk MAD-hclust-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>              n agent(p) dose(p)  time(p) k
#> MAD:hclust 157   0.7587  0.9919 5.29e-27 2
#> MAD:hclust 157   0.0628  0.2789 1.48e-29 3
#> MAD:hclust 155   0.2622  0.5946 1.32e-50 4
#> MAD:hclust 159   0.3195  0.5840 3.15e-71 5
#> MAD:hclust 155   0.0081  0.0291 6.66e-70 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


MAD:kmeans**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["MAD", "kmeans"]
# you can also extract it by
# res = res_list["MAD:kmeans"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'MAD' method.
#>   Subgroups are detected by 'kmeans' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 2.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk MAD-kmeans-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk MAD-kmeans-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           0.996       0.998         0.4747 0.527   0.527
#> 3 3 0.667           0.817       0.893         0.3571 0.796   0.618
#> 4 4 0.732           0.797       0.830         0.1026 0.913   0.759
#> 5 5 0.762           0.869       0.844         0.0678 0.903   0.685
#> 6 6 0.794           0.838       0.840         0.0499 1.000   1.000

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 2

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2   0.000      1.000 0.000 1.000
#> GSM528682     2   0.000      1.000 0.000 1.000
#> GSM528683     2   0.000      1.000 0.000 1.000
#> GSM528684     2   0.000      1.000 0.000 1.000
#> GSM528687     2   0.000      1.000 0.000 1.000
#> GSM528688     2   0.000      1.000 0.000 1.000
#> GSM528685     2   0.000      1.000 0.000 1.000
#> GSM528686     2   0.000      1.000 0.000 1.000
#> GSM528693     1   0.000      0.997 1.000 0.000
#> GSM528694     1   0.000      0.997 1.000 0.000
#> GSM528695     1   0.000      0.997 1.000 0.000
#> GSM528696     1   0.000      0.997 1.000 0.000
#> GSM528697     1   0.000      0.997 1.000 0.000
#> GSM528698     1   0.000      0.997 1.000 0.000
#> GSM528699     1   0.000      0.997 1.000 0.000
#> GSM528700     1   0.000      0.997 1.000 0.000
#> GSM528689     1   0.000      0.997 1.000 0.000
#> GSM528690     1   0.000      0.997 1.000 0.000
#> GSM528691     1   0.000      0.997 1.000 0.000
#> GSM528692     1   0.000      0.997 1.000 0.000
#> GSM528779     2   0.000      1.000 0.000 1.000
#> GSM528780     2   0.000      1.000 0.000 1.000
#> GSM528782     2   0.000      1.000 0.000 1.000
#> GSM528781     2   0.000      1.000 0.000 1.000
#> GSM528785     1   0.000      0.997 1.000 0.000
#> GSM528786     1   0.000      0.997 1.000 0.000
#> GSM528787     1   0.000      0.997 1.000 0.000
#> GSM528788     1   0.000      0.997 1.000 0.000
#> GSM528783     1   0.000      0.997 1.000 0.000
#> GSM528784     1   0.000      0.997 1.000 0.000
#> GSM528759     1   0.000      0.997 1.000 0.000
#> GSM528760     1   0.000      0.997 1.000 0.000
#> GSM528761     2   0.000      1.000 0.000 1.000
#> GSM528762     2   0.000      1.000 0.000 1.000
#> GSM528765     2   0.000      1.000 0.000 1.000
#> GSM528766     2   0.000      1.000 0.000 1.000
#> GSM528763     2   0.000      1.000 0.000 1.000
#> GSM528764     2   0.000      1.000 0.000 1.000
#> GSM528771     1   0.000      0.997 1.000 0.000
#> GSM528772     1   0.000      0.997 1.000 0.000
#> GSM528773     1   0.000      0.997 1.000 0.000
#> GSM528774     1   0.000      0.997 1.000 0.000
#> GSM528775     1   0.000      0.997 1.000 0.000
#> GSM528776     1   0.000      0.997 1.000 0.000
#> GSM528777     1   0.000      0.997 1.000 0.000
#> GSM528778     1   0.000      0.997 1.000 0.000
#> GSM528767     1   0.000      0.997 1.000 0.000
#> GSM528768     1   0.000      0.997 1.000 0.000
#> GSM528769     1   0.000      0.997 1.000 0.000
#> GSM528770     1   0.000      0.997 1.000 0.000
#> GSM528671     2   0.000      1.000 0.000 1.000
#> GSM528672     2   0.000      1.000 0.000 1.000
#> GSM528674     2   0.000      1.000 0.000 1.000
#> GSM528673     2   0.000      1.000 0.000 1.000
#> GSM528677     1   0.000      0.997 1.000 0.000
#> GSM528678     1   0.000      0.997 1.000 0.000
#> GSM528679     1   0.000      0.997 1.000 0.000
#> GSM528680     1   0.000      0.997 1.000 0.000
#> GSM528675     1   0.000      0.997 1.000 0.000
#> GSM528676     1   0.000      0.997 1.000 0.000
#> GSM528651     2   0.000      1.000 0.000 1.000
#> GSM528652     2   0.000      1.000 0.000 1.000
#> GSM528653     2   0.000      1.000 0.000 1.000
#> GSM528654     2   0.000      1.000 0.000 1.000
#> GSM528657     2   0.000      1.000 0.000 1.000
#> GSM528658     2   0.000      1.000 0.000 1.000
#> GSM528655     2   0.000      1.000 0.000 1.000
#> GSM528656     2   0.000      1.000 0.000 1.000
#> GSM528663     1   0.494      0.879 0.892 0.108
#> GSM528664     1   0.722      0.752 0.800 0.200
#> GSM528665     1   0.000      0.997 1.000 0.000
#> GSM528666     1   0.000      0.997 1.000 0.000
#> GSM528667     1   0.000      0.997 1.000 0.000
#> GSM528668     1   0.000      0.997 1.000 0.000
#> GSM528669     1   0.000      0.997 1.000 0.000
#> GSM528670     1   0.000      0.997 1.000 0.000
#> GSM528659     1   0.000      0.997 1.000 0.000
#> GSM528660     1   0.000      0.997 1.000 0.000
#> GSM528661     1   0.000      0.997 1.000 0.000
#> GSM528662     1   0.000      0.997 1.000 0.000
#> GSM528701     2   0.000      1.000 0.000 1.000
#> GSM528702     2   0.000      1.000 0.000 1.000
#> GSM528703     2   0.000      1.000 0.000 1.000
#> GSM528704     2   0.000      1.000 0.000 1.000
#> GSM528707     2   0.000      1.000 0.000 1.000
#> GSM528708     2   0.000      1.000 0.000 1.000
#> GSM528705     2   0.000      1.000 0.000 1.000
#> GSM528706     2   0.000      1.000 0.000 1.000
#> GSM528713     1   0.000      0.997 1.000 0.000
#> GSM528714     1   0.000      0.997 1.000 0.000
#> GSM528715     1   0.000      0.997 1.000 0.000
#> GSM528716     1   0.000      0.997 1.000 0.000
#> GSM528717     1   0.000      0.997 1.000 0.000
#> GSM528718     1   0.000      0.997 1.000 0.000
#> GSM528719     1   0.000      0.997 1.000 0.000
#> GSM528720     1   0.000      0.997 1.000 0.000
#> GSM528709     1   0.000      0.997 1.000 0.000
#> GSM528710     1   0.000      0.997 1.000 0.000
#> GSM528711     1   0.000      0.997 1.000 0.000
#> GSM528712     1   0.000      0.997 1.000 0.000
#> GSM528721     2   0.000      1.000 0.000 1.000
#> GSM528722     2   0.000      1.000 0.000 1.000
#> GSM528723     2   0.000      1.000 0.000 1.000
#> GSM528724     2   0.000      1.000 0.000 1.000
#> GSM528727     2   0.000      1.000 0.000 1.000
#> GSM528728     2   0.000      1.000 0.000 1.000
#> GSM528725     2   0.000      1.000 0.000 1.000
#> GSM528726     2   0.000      1.000 0.000 1.000
#> GSM528733     1   0.000      0.997 1.000 0.000
#> GSM528734     1   0.000      0.997 1.000 0.000
#> GSM528735     1   0.000      0.997 1.000 0.000
#> GSM528736     1   0.000      0.997 1.000 0.000
#> GSM528737     1   0.000      0.997 1.000 0.000
#> GSM528738     1   0.000      0.997 1.000 0.000
#> GSM528729     1   0.000      0.997 1.000 0.000
#> GSM528730     1   0.000      0.997 1.000 0.000
#> GSM528731     1   0.000      0.997 1.000 0.000
#> GSM528732     1   0.000      0.997 1.000 0.000
#> GSM528739     2   0.000      1.000 0.000 1.000
#> GSM528740     2   0.000      1.000 0.000 1.000
#> GSM528741     2   0.000      1.000 0.000 1.000
#> GSM528742     2   0.000      1.000 0.000 1.000
#> GSM528745     2   0.000      1.000 0.000 1.000
#> GSM528746     2   0.000      1.000 0.000 1.000
#> GSM528743     2   0.000      1.000 0.000 1.000
#> GSM528744     2   0.000      1.000 0.000 1.000
#> GSM528751     1   0.000      0.997 1.000 0.000
#> GSM528752     1   0.000      0.997 1.000 0.000
#> GSM528753     1   0.000      0.997 1.000 0.000
#> GSM528754     1   0.000      0.997 1.000 0.000
#> GSM528755     1   0.000      0.997 1.000 0.000
#> GSM528756     1   0.000      0.997 1.000 0.000
#> GSM528757     1   0.000      0.997 1.000 0.000
#> GSM528758     1   0.000      0.997 1.000 0.000
#> GSM528747     1   0.000      0.997 1.000 0.000
#> GSM528748     1   0.000      0.997 1.000 0.000
#> GSM528749     1   0.000      0.997 1.000 0.000
#> GSM528750     1   0.000      0.997 1.000 0.000
#> GSM528640     2   0.000      1.000 0.000 1.000
#> GSM528641     2   0.000      1.000 0.000 1.000
#> GSM528643     1   0.000      0.997 1.000 0.000
#> GSM528644     1   0.000      0.997 1.000 0.000
#> GSM528642     1   0.000      0.997 1.000 0.000
#> GSM528620     2   0.000      1.000 0.000 1.000
#> GSM528621     2   0.141      0.979 0.020 0.980
#> GSM528623     1   0.000      0.997 1.000 0.000
#> GSM528624     1   0.000      0.997 1.000 0.000
#> GSM528622     1   0.000      0.997 1.000 0.000
#> GSM528625     2   0.000      1.000 0.000 1.000
#> GSM528626     2   0.000      1.000 0.000 1.000
#> GSM528628     1   0.000      0.997 1.000 0.000
#> GSM528629     1   0.000      0.997 1.000 0.000
#> GSM528627     1   0.000      0.997 1.000 0.000
#> GSM528630     2   0.000      1.000 0.000 1.000
#> GSM528631     2   0.000      1.000 0.000 1.000
#> GSM528632     2   0.000      1.000 0.000 1.000
#> GSM528633     2   0.000      1.000 0.000 1.000
#> GSM528636     1   0.000      0.997 1.000 0.000
#> GSM528637     1   0.000      0.997 1.000 0.000
#> GSM528638     1   0.000      0.997 1.000 0.000
#> GSM528639     1   0.000      0.997 1.000 0.000
#> GSM528634     1   0.000      0.997 1.000 0.000
#> GSM528635     1   0.000      0.997 1.000 0.000
#> GSM528645     1   0.000      0.997 1.000 0.000
#> GSM528646     1   0.000      0.997 1.000 0.000
#> GSM528647     1   0.000      0.997 1.000 0.000
#> GSM528648     1   0.000      0.997 1.000 0.000
#> GSM528649     1   0.000      0.997 1.000 0.000
#> GSM528650     1   0.000      0.997 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-MAD-kmeans-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-MAD-kmeans-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-MAD-kmeans-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-MAD-kmeans-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk MAD-kmeans-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-MAD-kmeans-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk MAD-kmeans-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>              n agent(p) dose(p)  time(p) k
#> MAD:kmeans 169   0.9069 0.99995 1.43e-29 2
#> MAD:kmeans 154   0.4257 0.99486 1.03e-48 3
#> MAD:kmeans 163   0.8924 0.99148 4.01e-73 4
#> MAD:kmeans 168   0.0293 0.00946 4.90e-75 5
#> MAD:kmeans 169   0.0288 0.01145 9.45e-75 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


MAD:skmeans**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["MAD", "skmeans"]
# you can also extract it by
# res = res_list["MAD:skmeans"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'MAD' method.
#>   Subgroups are detected by 'skmeans' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 6.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk MAD-skmeans-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk MAD-skmeans-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           0.984       0.993         0.4820 0.521   0.521
#> 3 3 1.000           0.985       0.992         0.3767 0.796   0.615
#> 4 4 0.935           0.926       0.962         0.0745 0.881   0.679
#> 5 5 0.990           0.963       0.981         0.0956 0.923   0.736
#> 6 6 0.955           0.912       0.920         0.0285 0.971   0.871

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 6
#> attr(,"optional")
#> [1] 2 3 4 5

There is also optional best \(k\) = 2 3 4 5 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2   0.000      1.000 0.000 1.000
#> GSM528682     2   0.000      1.000 0.000 1.000
#> GSM528683     2   0.000      1.000 0.000 1.000
#> GSM528684     2   0.000      1.000 0.000 1.000
#> GSM528687     2   0.000      1.000 0.000 1.000
#> GSM528688     2   0.000      1.000 0.000 1.000
#> GSM528685     2   0.000      1.000 0.000 1.000
#> GSM528686     2   0.000      1.000 0.000 1.000
#> GSM528693     1   0.000      0.989 1.000 0.000
#> GSM528694     1   0.000      0.989 1.000 0.000
#> GSM528695     1   0.000      0.989 1.000 0.000
#> GSM528696     1   0.000      0.989 1.000 0.000
#> GSM528697     1   0.000      0.989 1.000 0.000
#> GSM528698     1   0.000      0.989 1.000 0.000
#> GSM528699     1   0.000      0.989 1.000 0.000
#> GSM528700     1   0.000      0.989 1.000 0.000
#> GSM528689     1   0.000      0.989 1.000 0.000
#> GSM528690     1   0.000      0.989 1.000 0.000
#> GSM528691     1   0.000      0.989 1.000 0.000
#> GSM528692     1   0.000      0.989 1.000 0.000
#> GSM528779     2   0.000      1.000 0.000 1.000
#> GSM528780     2   0.000      1.000 0.000 1.000
#> GSM528782     2   0.000      1.000 0.000 1.000
#> GSM528781     2   0.000      1.000 0.000 1.000
#> GSM528785     1   0.891      0.570 0.692 0.308
#> GSM528786     1   0.000      0.989 1.000 0.000
#> GSM528787     1   0.000      0.989 1.000 0.000
#> GSM528788     1   0.000      0.989 1.000 0.000
#> GSM528783     1   0.000      0.989 1.000 0.000
#> GSM528784     1   0.000      0.989 1.000 0.000
#> GSM528759     1   0.000      0.989 1.000 0.000
#> GSM528760     1   0.000      0.989 1.000 0.000
#> GSM528761     2   0.000      1.000 0.000 1.000
#> GSM528762     2   0.000      1.000 0.000 1.000
#> GSM528765     2   0.000      1.000 0.000 1.000
#> GSM528766     2   0.000      1.000 0.000 1.000
#> GSM528763     2   0.000      1.000 0.000 1.000
#> GSM528764     2   0.000      1.000 0.000 1.000
#> GSM528771     1   0.891      0.570 0.692 0.308
#> GSM528772     1   0.753      0.732 0.784 0.216
#> GSM528773     1   0.000      0.989 1.000 0.000
#> GSM528774     1   0.000      0.989 1.000 0.000
#> GSM528775     1   0.000      0.989 1.000 0.000
#> GSM528776     1   0.000      0.989 1.000 0.000
#> GSM528777     1   0.000      0.989 1.000 0.000
#> GSM528778     1   0.000      0.989 1.000 0.000
#> GSM528767     1   0.000      0.989 1.000 0.000
#> GSM528768     1   0.000      0.989 1.000 0.000
#> GSM528769     1   0.000      0.989 1.000 0.000
#> GSM528770     1   0.000      0.989 1.000 0.000
#> GSM528671     2   0.000      1.000 0.000 1.000
#> GSM528672     2   0.000      1.000 0.000 1.000
#> GSM528674     2   0.000      1.000 0.000 1.000
#> GSM528673     2   0.000      1.000 0.000 1.000
#> GSM528677     1   0.000      0.989 1.000 0.000
#> GSM528678     1   0.000      0.989 1.000 0.000
#> GSM528679     1   0.000      0.989 1.000 0.000
#> GSM528680     1   0.000      0.989 1.000 0.000
#> GSM528675     1   0.000      0.989 1.000 0.000
#> GSM528676     1   0.000      0.989 1.000 0.000
#> GSM528651     2   0.000      1.000 0.000 1.000
#> GSM528652     2   0.000      1.000 0.000 1.000
#> GSM528653     2   0.000      1.000 0.000 1.000
#> GSM528654     2   0.000      1.000 0.000 1.000
#> GSM528657     2   0.000      1.000 0.000 1.000
#> GSM528658     2   0.000      1.000 0.000 1.000
#> GSM528655     2   0.000      1.000 0.000 1.000
#> GSM528656     2   0.000      1.000 0.000 1.000
#> GSM528663     2   0.000      1.000 0.000 1.000
#> GSM528664     2   0.000      1.000 0.000 1.000
#> GSM528665     1   0.000      0.989 1.000 0.000
#> GSM528666     1   0.000      0.989 1.000 0.000
#> GSM528667     1   0.000      0.989 1.000 0.000
#> GSM528668     1   0.000      0.989 1.000 0.000
#> GSM528669     1   0.000      0.989 1.000 0.000
#> GSM528670     1   0.000      0.989 1.000 0.000
#> GSM528659     1   0.000      0.989 1.000 0.000
#> GSM528660     1   0.000      0.989 1.000 0.000
#> GSM528661     1   0.000      0.989 1.000 0.000
#> GSM528662     1   0.000      0.989 1.000 0.000
#> GSM528701     2   0.000      1.000 0.000 1.000
#> GSM528702     2   0.000      1.000 0.000 1.000
#> GSM528703     2   0.000      1.000 0.000 1.000
#> GSM528704     2   0.000      1.000 0.000 1.000
#> GSM528707     2   0.000      1.000 0.000 1.000
#> GSM528708     2   0.000      1.000 0.000 1.000
#> GSM528705     2   0.000      1.000 0.000 1.000
#> GSM528706     2   0.000      1.000 0.000 1.000
#> GSM528713     1   0.000      0.989 1.000 0.000
#> GSM528714     1   0.000      0.989 1.000 0.000
#> GSM528715     1   0.000      0.989 1.000 0.000
#> GSM528716     1   0.000      0.989 1.000 0.000
#> GSM528717     1   0.000      0.989 1.000 0.000
#> GSM528718     1   0.000      0.989 1.000 0.000
#> GSM528719     1   0.000      0.989 1.000 0.000
#> GSM528720     1   0.000      0.989 1.000 0.000
#> GSM528709     1   0.000      0.989 1.000 0.000
#> GSM528710     1   0.000      0.989 1.000 0.000
#> GSM528711     1   0.000      0.989 1.000 0.000
#> GSM528712     1   0.000      0.989 1.000 0.000
#> GSM528721     2   0.000      1.000 0.000 1.000
#> GSM528722     2   0.000      1.000 0.000 1.000
#> GSM528723     2   0.000      1.000 0.000 1.000
#> GSM528724     2   0.000      1.000 0.000 1.000
#> GSM528727     2   0.000      1.000 0.000 1.000
#> GSM528728     2   0.000      1.000 0.000 1.000
#> GSM528725     2   0.000      1.000 0.000 1.000
#> GSM528726     2   0.000      1.000 0.000 1.000
#> GSM528733     1   0.000      0.989 1.000 0.000
#> GSM528734     1   0.000      0.989 1.000 0.000
#> GSM528735     1   0.000      0.989 1.000 0.000
#> GSM528736     1   0.000      0.989 1.000 0.000
#> GSM528737     1   0.000      0.989 1.000 0.000
#> GSM528738     1   0.000      0.989 1.000 0.000
#> GSM528729     1   0.000      0.989 1.000 0.000
#> GSM528730     1   0.000      0.989 1.000 0.000
#> GSM528731     1   0.000      0.989 1.000 0.000
#> GSM528732     1   0.000      0.989 1.000 0.000
#> GSM528739     2   0.000      1.000 0.000 1.000
#> GSM528740     2   0.000      1.000 0.000 1.000
#> GSM528741     2   0.000      1.000 0.000 1.000
#> GSM528742     2   0.000      1.000 0.000 1.000
#> GSM528745     2   0.000      1.000 0.000 1.000
#> GSM528746     2   0.000      1.000 0.000 1.000
#> GSM528743     2   0.000      1.000 0.000 1.000
#> GSM528744     2   0.000      1.000 0.000 1.000
#> GSM528751     1   0.730      0.750 0.796 0.204
#> GSM528752     1   0.518      0.867 0.884 0.116
#> GSM528753     1   0.000      0.989 1.000 0.000
#> GSM528754     1   0.000      0.989 1.000 0.000
#> GSM528755     1   0.000      0.989 1.000 0.000
#> GSM528756     1   0.000      0.989 1.000 0.000
#> GSM528757     1   0.000      0.989 1.000 0.000
#> GSM528758     1   0.000      0.989 1.000 0.000
#> GSM528747     1   0.000      0.989 1.000 0.000
#> GSM528748     1   0.000      0.989 1.000 0.000
#> GSM528749     1   0.000      0.989 1.000 0.000
#> GSM528750     1   0.000      0.989 1.000 0.000
#> GSM528640     2   0.000      1.000 0.000 1.000
#> GSM528641     2   0.000      1.000 0.000 1.000
#> GSM528643     1   0.000      0.989 1.000 0.000
#> GSM528644     1   0.000      0.989 1.000 0.000
#> GSM528642     1   0.000      0.989 1.000 0.000
#> GSM528620     2   0.000      1.000 0.000 1.000
#> GSM528621     2   0.000      1.000 0.000 1.000
#> GSM528623     1   0.000      0.989 1.000 0.000
#> GSM528624     1   0.000      0.989 1.000 0.000
#> GSM528622     1   0.000      0.989 1.000 0.000
#> GSM528625     2   0.000      1.000 0.000 1.000
#> GSM528626     2   0.000      1.000 0.000 1.000
#> GSM528628     1   0.000      0.989 1.000 0.000
#> GSM528629     1   0.000      0.989 1.000 0.000
#> GSM528627     1   0.000      0.989 1.000 0.000
#> GSM528630     2   0.000      1.000 0.000 1.000
#> GSM528631     2   0.000      1.000 0.000 1.000
#> GSM528632     2   0.000      1.000 0.000 1.000
#> GSM528633     2   0.000      1.000 0.000 1.000
#> GSM528636     1   0.000      0.989 1.000 0.000
#> GSM528637     1   0.000      0.989 1.000 0.000
#> GSM528638     1   0.000      0.989 1.000 0.000
#> GSM528639     1   0.000      0.989 1.000 0.000
#> GSM528634     1   0.000      0.989 1.000 0.000
#> GSM528635     1   0.000      0.989 1.000 0.000
#> GSM528645     1   0.000      0.989 1.000 0.000
#> GSM528646     1   0.000      0.989 1.000 0.000
#> GSM528647     1   0.000      0.989 1.000 0.000
#> GSM528648     1   0.000      0.989 1.000 0.000
#> GSM528649     1   0.000      0.989 1.000 0.000
#> GSM528650     1   0.000      0.989 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-MAD-skmeans-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-MAD-skmeans-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-MAD-skmeans-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-MAD-skmeans-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk MAD-skmeans-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-MAD-skmeans-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk MAD-skmeans-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>               n agent(p) dose(p)  time(p) k
#> MAD:skmeans 169  0.83181 0.99988 3.84e-28 2
#> MAD:skmeans 168  0.43376 0.98472 2.35e-52 3
#> MAD:skmeans 165  0.14993 0.95086 1.65e-69 4
#> MAD:skmeans 167  0.00608 0.00700 7.01e-71 5
#> MAD:skmeans 167  0.00190 0.00542 5.56e-88 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


MAD:pam*

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["MAD", "pam"]
# you can also extract it by
# res = res_list["MAD:pam"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'MAD' method.
#>   Subgroups are detected by 'pam' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 5.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk MAD-pam-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk MAD-pam-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.922           0.930       0.969         0.4767 0.530   0.530
#> 3 3 0.843           0.924       0.953         0.3805 0.799   0.624
#> 4 4 0.858           0.895       0.928         0.1074 0.931   0.795
#> 5 5 0.919           0.846       0.938         0.0549 0.882   0.622
#> 6 6 0.829           0.607       0.816         0.0631 0.922   0.692

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 5
#> attr(,"optional")
#> [1] 2

There is also optional best \(k\) = 2 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2  0.0000     0.9805 0.000 1.000
#> GSM528682     2  0.0000     0.9805 0.000 1.000
#> GSM528683     2  0.0000     0.9805 0.000 1.000
#> GSM528684     2  0.0000     0.9805 0.000 1.000
#> GSM528687     2  0.0000     0.9805 0.000 1.000
#> GSM528688     2  0.0000     0.9805 0.000 1.000
#> GSM528685     2  0.0000     0.9805 0.000 1.000
#> GSM528686     2  0.4298     0.8988 0.088 0.912
#> GSM528693     1  0.0000     0.9601 1.000 0.000
#> GSM528694     1  0.0000     0.9601 1.000 0.000
#> GSM528695     1  0.0000     0.9601 1.000 0.000
#> GSM528696     1  0.0000     0.9601 1.000 0.000
#> GSM528697     1  0.0000     0.9601 1.000 0.000
#> GSM528698     1  0.0000     0.9601 1.000 0.000
#> GSM528699     1  0.3879     0.9032 0.924 0.076
#> GSM528700     1  0.0000     0.9601 1.000 0.000
#> GSM528689     1  0.0000     0.9601 1.000 0.000
#> GSM528690     1  0.3584     0.9090 0.932 0.068
#> GSM528691     1  0.0000     0.9601 1.000 0.000
#> GSM528692     1  0.0000     0.9601 1.000 0.000
#> GSM528779     2  0.0000     0.9805 0.000 1.000
#> GSM528780     2  0.0000     0.9805 0.000 1.000
#> GSM528782     2  0.0000     0.9805 0.000 1.000
#> GSM528781     2  0.0000     0.9805 0.000 1.000
#> GSM528785     1  0.0672     0.9556 0.992 0.008
#> GSM528786     1  0.0000     0.9601 1.000 0.000
#> GSM528787     1  0.0000     0.9601 1.000 0.000
#> GSM528788     1  0.7056     0.7694 0.808 0.192
#> GSM528783     1  0.0000     0.9601 1.000 0.000
#> GSM528784     1  0.0000     0.9601 1.000 0.000
#> GSM528759     1  0.0000     0.9601 1.000 0.000
#> GSM528760     1  0.0000     0.9601 1.000 0.000
#> GSM528761     2  0.0000     0.9805 0.000 1.000
#> GSM528762     2  0.0000     0.9805 0.000 1.000
#> GSM528765     2  0.0000     0.9805 0.000 1.000
#> GSM528766     2  0.0000     0.9805 0.000 1.000
#> GSM528763     2  0.0000     0.9805 0.000 1.000
#> GSM528764     2  0.4939     0.8753 0.108 0.892
#> GSM528771     1  0.0672     0.9556 0.992 0.008
#> GSM528772     1  0.0672     0.9556 0.992 0.008
#> GSM528773     1  0.0000     0.9601 1.000 0.000
#> GSM528774     1  0.0000     0.9601 1.000 0.000
#> GSM528775     1  0.0000     0.9601 1.000 0.000
#> GSM528776     1  0.0000     0.9601 1.000 0.000
#> GSM528777     1  0.9552     0.4342 0.624 0.376
#> GSM528778     1  0.7219     0.7600 0.800 0.200
#> GSM528767     1  0.0000     0.9601 1.000 0.000
#> GSM528768     1  0.0000     0.9601 1.000 0.000
#> GSM528769     1  0.0000     0.9601 1.000 0.000
#> GSM528770     1  0.0000     0.9601 1.000 0.000
#> GSM528671     2  0.0000     0.9805 0.000 1.000
#> GSM528672     2  0.0000     0.9805 0.000 1.000
#> GSM528674     2  0.0000     0.9805 0.000 1.000
#> GSM528673     2  0.4161     0.9032 0.084 0.916
#> GSM528677     1  0.0672     0.9556 0.992 0.008
#> GSM528678     1  0.0000     0.9601 1.000 0.000
#> GSM528679     1  0.0000     0.9601 1.000 0.000
#> GSM528680     1  0.0000     0.9601 1.000 0.000
#> GSM528675     1  0.0000     0.9601 1.000 0.000
#> GSM528676     1  0.0000     0.9601 1.000 0.000
#> GSM528651     2  0.0000     0.9805 0.000 1.000
#> GSM528652     2  0.0000     0.9805 0.000 1.000
#> GSM528653     2  0.0000     0.9805 0.000 1.000
#> GSM528654     2  0.0000     0.9805 0.000 1.000
#> GSM528657     2  0.0000     0.9805 0.000 1.000
#> GSM528658     2  0.0000     0.9805 0.000 1.000
#> GSM528655     2  0.4161     0.9032 0.084 0.916
#> GSM528656     2  0.0000     0.9805 0.000 1.000
#> GSM528663     1  0.3431     0.9129 0.936 0.064
#> GSM528664     1  0.3879     0.9026 0.924 0.076
#> GSM528665     1  0.0000     0.9601 1.000 0.000
#> GSM528666     1  0.0000     0.9601 1.000 0.000
#> GSM528667     1  0.0000     0.9601 1.000 0.000
#> GSM528668     1  0.0000     0.9601 1.000 0.000
#> GSM528669     1  0.9993     0.1028 0.516 0.484
#> GSM528670     1  0.0000     0.9601 1.000 0.000
#> GSM528659     1  0.3274     0.9159 0.940 0.060
#> GSM528660     1  0.2043     0.9384 0.968 0.032
#> GSM528661     1  0.0000     0.9601 1.000 0.000
#> GSM528662     1  0.0000     0.9601 1.000 0.000
#> GSM528701     2  0.0000     0.9805 0.000 1.000
#> GSM528702     2  0.0000     0.9805 0.000 1.000
#> GSM528703     2  0.0000     0.9805 0.000 1.000
#> GSM528704     2  0.0000     0.9805 0.000 1.000
#> GSM528707     2  0.0000     0.9805 0.000 1.000
#> GSM528708     2  0.0000     0.9805 0.000 1.000
#> GSM528705     2  0.0000     0.9805 0.000 1.000
#> GSM528706     2  0.0000     0.9805 0.000 1.000
#> GSM528713     1  0.0376     0.9579 0.996 0.004
#> GSM528714     1  0.0672     0.9556 0.992 0.008
#> GSM528715     1  0.0000     0.9601 1.000 0.000
#> GSM528716     1  0.0000     0.9601 1.000 0.000
#> GSM528717     1  0.0000     0.9601 1.000 0.000
#> GSM528718     1  0.0000     0.9601 1.000 0.000
#> GSM528719     1  0.0000     0.9601 1.000 0.000
#> GSM528720     1  0.0000     0.9601 1.000 0.000
#> GSM528709     1  0.0000     0.9601 1.000 0.000
#> GSM528710     1  0.3274     0.9159 0.940 0.060
#> GSM528711     1  0.0000     0.9601 1.000 0.000
#> GSM528712     1  0.0000     0.9601 1.000 0.000
#> GSM528721     2  0.0000     0.9805 0.000 1.000
#> GSM528722     2  0.0000     0.9805 0.000 1.000
#> GSM528723     2  0.0000     0.9805 0.000 1.000
#> GSM528724     2  0.0000     0.9805 0.000 1.000
#> GSM528727     2  0.0000     0.9805 0.000 1.000
#> GSM528728     2  0.0000     0.9805 0.000 1.000
#> GSM528725     2  0.0000     0.9805 0.000 1.000
#> GSM528726     2  0.0000     0.9805 0.000 1.000
#> GSM528733     1  0.0000     0.9601 1.000 0.000
#> GSM528734     1  0.0000     0.9601 1.000 0.000
#> GSM528735     1  0.0000     0.9601 1.000 0.000
#> GSM528736     1  0.0000     0.9601 1.000 0.000
#> GSM528737     1  0.0000     0.9601 1.000 0.000
#> GSM528738     1  0.0000     0.9601 1.000 0.000
#> GSM528729     1  0.5059     0.8660 0.888 0.112
#> GSM528730     1  0.6343     0.8118 0.840 0.160
#> GSM528731     1  0.0000     0.9601 1.000 0.000
#> GSM528732     1  0.0000     0.9601 1.000 0.000
#> GSM528739     2  0.0000     0.9805 0.000 1.000
#> GSM528740     2  0.0000     0.9805 0.000 1.000
#> GSM528741     2  0.0000     0.9805 0.000 1.000
#> GSM528742     2  0.0000     0.9805 0.000 1.000
#> GSM528745     2  0.0000     0.9805 0.000 1.000
#> GSM528746     2  0.0000     0.9805 0.000 1.000
#> GSM528743     2  0.0000     0.9805 0.000 1.000
#> GSM528744     2  0.0000     0.9805 0.000 1.000
#> GSM528751     1  0.0672     0.9556 0.992 0.008
#> GSM528752     1  0.0672     0.9556 0.992 0.008
#> GSM528753     1  0.0000     0.9601 1.000 0.000
#> GSM528754     1  0.0000     0.9601 1.000 0.000
#> GSM528755     1  0.0000     0.9601 1.000 0.000
#> GSM528756     1  0.0000     0.9601 1.000 0.000
#> GSM528757     1  1.0000     0.0612 0.500 0.500
#> GSM528758     1  0.8144     0.6865 0.748 0.252
#> GSM528747     1  0.0000     0.9601 1.000 0.000
#> GSM528748     1  0.3431     0.9128 0.936 0.064
#> GSM528749     1  0.0000     0.9601 1.000 0.000
#> GSM528750     1  0.0000     0.9601 1.000 0.000
#> GSM528640     2  0.0000     0.9805 0.000 1.000
#> GSM528641     2  0.4161     0.9032 0.084 0.916
#> GSM528643     1  0.0000     0.9601 1.000 0.000
#> GSM528644     1  0.7745     0.7215 0.772 0.228
#> GSM528642     1  0.0000     0.9601 1.000 0.000
#> GSM528620     2  0.0000     0.9805 0.000 1.000
#> GSM528621     1  0.8763     0.6140 0.704 0.296
#> GSM528623     1  0.0000     0.9601 1.000 0.000
#> GSM528624     1  0.9044     0.5602 0.680 0.320
#> GSM528622     1  0.0000     0.9601 1.000 0.000
#> GSM528625     2  0.0000     0.9805 0.000 1.000
#> GSM528626     2  0.4161     0.9032 0.084 0.916
#> GSM528628     1  0.0000     0.9601 1.000 0.000
#> GSM528629     1  0.3114     0.9189 0.944 0.056
#> GSM528627     1  0.0000     0.9601 1.000 0.000
#> GSM528630     2  0.0000     0.9805 0.000 1.000
#> GSM528631     2  0.0000     0.9805 0.000 1.000
#> GSM528632     2  0.9732     0.2818 0.404 0.596
#> GSM528633     2  0.7056     0.7585 0.192 0.808
#> GSM528636     1  0.0000     0.9601 1.000 0.000
#> GSM528637     1  0.0000     0.9601 1.000 0.000
#> GSM528638     1  0.8661     0.6275 0.712 0.288
#> GSM528639     1  0.2423     0.9319 0.960 0.040
#> GSM528634     1  0.0000     0.9601 1.000 0.000
#> GSM528635     1  0.0000     0.9601 1.000 0.000
#> GSM528645     1  0.0000     0.9601 1.000 0.000
#> GSM528646     1  0.0000     0.9601 1.000 0.000
#> GSM528647     1  0.0000     0.9601 1.000 0.000
#> GSM528648     1  0.0000     0.9601 1.000 0.000
#> GSM528649     1  0.0000     0.9601 1.000 0.000
#> GSM528650     1  0.0000     0.9601 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-MAD-pam-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-MAD-pam-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-MAD-pam-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-MAD-pam-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk MAD-pam-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-MAD-pam-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk MAD-pam-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>           n agent(p) dose(p)  time(p) k
#> MAD:pam 165  0.89030  0.9912 6.56e-28 2
#> MAD:pam 165  0.37577  0.9991 3.99e-41 3
#> MAD:pam 168  0.50446  0.9028 5.13e-60 4
#> MAD:pam 154  0.00496  0.0776 1.00e-67 5
#> MAD:pam 119  0.00186  0.0480 4.75e-35 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


MAD:mclust

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["MAD", "mclust"]
# you can also extract it by
# res = res_list["MAD:mclust"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'MAD' method.
#>   Subgroups are detected by 'mclust' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 2.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk MAD-mclust-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk MAD-mclust-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.896           0.966       0.984         0.4766 0.530   0.530
#> 3 3 0.671           0.865       0.911         0.2840 0.879   0.771
#> 4 4 0.720           0.786       0.878         0.1149 0.927   0.822
#> 5 5 0.685           0.703       0.796         0.0928 0.923   0.779
#> 6 6 0.713           0.595       0.800         0.0599 0.898   0.654

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 2

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2  0.0000      0.999 0.000 1.000
#> GSM528682     2  0.0000      0.999 0.000 1.000
#> GSM528683     2  0.0000      0.999 0.000 1.000
#> GSM528684     2  0.0000      0.999 0.000 1.000
#> GSM528687     2  0.0000      0.999 0.000 1.000
#> GSM528688     2  0.0000      0.999 0.000 1.000
#> GSM528685     2  0.0376      0.996 0.004 0.996
#> GSM528686     2  0.0376      0.996 0.004 0.996
#> GSM528693     1  0.6623      0.812 0.828 0.172
#> GSM528694     1  0.6623      0.812 0.828 0.172
#> GSM528695     1  0.0376      0.972 0.996 0.004
#> GSM528696     1  0.0376      0.972 0.996 0.004
#> GSM528697     1  0.0000      0.974 1.000 0.000
#> GSM528698     1  0.0000      0.974 1.000 0.000
#> GSM528699     1  0.0000      0.974 1.000 0.000
#> GSM528700     1  0.0000      0.974 1.000 0.000
#> GSM528689     1  0.0000      0.974 1.000 0.000
#> GSM528690     1  0.0000      0.974 1.000 0.000
#> GSM528691     1  0.0000      0.974 1.000 0.000
#> GSM528692     1  0.0000      0.974 1.000 0.000
#> GSM528779     2  0.0000      0.999 0.000 1.000
#> GSM528780     2  0.0000      0.999 0.000 1.000
#> GSM528782     2  0.0000      0.999 0.000 1.000
#> GSM528781     2  0.0000      0.999 0.000 1.000
#> GSM528785     1  0.6623      0.812 0.828 0.172
#> GSM528786     1  0.0376      0.972 0.996 0.004
#> GSM528787     1  0.0000      0.974 1.000 0.000
#> GSM528788     1  0.0000      0.974 1.000 0.000
#> GSM528783     1  0.0000      0.974 1.000 0.000
#> GSM528784     1  0.0000      0.974 1.000 0.000
#> GSM528759     1  0.0000      0.974 1.000 0.000
#> GSM528760     1  0.0000      0.974 1.000 0.000
#> GSM528761     2  0.0000      0.999 0.000 1.000
#> GSM528762     2  0.0000      0.999 0.000 1.000
#> GSM528765     2  0.0000      0.999 0.000 1.000
#> GSM528766     2  0.0000      0.999 0.000 1.000
#> GSM528763     2  0.0376      0.996 0.004 0.996
#> GSM528764     2  0.0376      0.996 0.004 0.996
#> GSM528771     1  0.6623      0.812 0.828 0.172
#> GSM528772     1  0.6623      0.812 0.828 0.172
#> GSM528773     1  0.0376      0.972 0.996 0.004
#> GSM528774     1  0.0376      0.972 0.996 0.004
#> GSM528775     1  0.0000      0.974 1.000 0.000
#> GSM528776     1  0.0000      0.974 1.000 0.000
#> GSM528777     1  0.0000      0.974 1.000 0.000
#> GSM528778     1  0.0000      0.974 1.000 0.000
#> GSM528767     1  0.0000      0.974 1.000 0.000
#> GSM528768     1  0.0000      0.974 1.000 0.000
#> GSM528769     1  0.0000      0.974 1.000 0.000
#> GSM528770     1  0.0000      0.974 1.000 0.000
#> GSM528671     2  0.0000      0.999 0.000 1.000
#> GSM528672     2  0.0000      0.999 0.000 1.000
#> GSM528674     2  0.0000      0.999 0.000 1.000
#> GSM528673     2  0.0376      0.996 0.004 0.996
#> GSM528677     1  0.6623      0.812 0.828 0.172
#> GSM528678     1  0.0376      0.972 0.996 0.004
#> GSM528679     1  0.0000      0.974 1.000 0.000
#> GSM528680     1  0.0000      0.974 1.000 0.000
#> GSM528675     1  0.0000      0.974 1.000 0.000
#> GSM528676     1  0.0000      0.974 1.000 0.000
#> GSM528651     2  0.0000      0.999 0.000 1.000
#> GSM528652     2  0.0000      0.999 0.000 1.000
#> GSM528653     2  0.0000      0.999 0.000 1.000
#> GSM528654     2  0.0000      0.999 0.000 1.000
#> GSM528657     2  0.0000      0.999 0.000 1.000
#> GSM528658     2  0.0000      0.999 0.000 1.000
#> GSM528655     2  0.0376      0.996 0.004 0.996
#> GSM528656     2  0.0376      0.996 0.004 0.996
#> GSM528663     1  0.8327      0.678 0.736 0.264
#> GSM528664     1  0.8327      0.678 0.736 0.264
#> GSM528665     1  0.0376      0.972 0.996 0.004
#> GSM528666     1  0.0376      0.972 0.996 0.004
#> GSM528667     1  0.0000      0.974 1.000 0.000
#> GSM528668     1  0.0000      0.974 1.000 0.000
#> GSM528669     1  0.0000      0.974 1.000 0.000
#> GSM528670     1  0.0000      0.974 1.000 0.000
#> GSM528659     1  0.0000      0.974 1.000 0.000
#> GSM528660     1  0.0000      0.974 1.000 0.000
#> GSM528661     1  0.0000      0.974 1.000 0.000
#> GSM528662     1  0.0000      0.974 1.000 0.000
#> GSM528701     2  0.0000      0.999 0.000 1.000
#> GSM528702     2  0.0000      0.999 0.000 1.000
#> GSM528703     2  0.0000      0.999 0.000 1.000
#> GSM528704     2  0.0000      0.999 0.000 1.000
#> GSM528707     2  0.0000      0.999 0.000 1.000
#> GSM528708     2  0.0000      0.999 0.000 1.000
#> GSM528705     2  0.0000      0.999 0.000 1.000
#> GSM528706     2  0.0000      0.999 0.000 1.000
#> GSM528713     1  0.6623      0.812 0.828 0.172
#> GSM528714     1  0.6712      0.807 0.824 0.176
#> GSM528715     1  0.0376      0.972 0.996 0.004
#> GSM528716     1  0.0376      0.972 0.996 0.004
#> GSM528717     1  0.0000      0.974 1.000 0.000
#> GSM528718     1  0.0000      0.974 1.000 0.000
#> GSM528719     1  0.0000      0.974 1.000 0.000
#> GSM528720     1  0.0000      0.974 1.000 0.000
#> GSM528709     1  0.0000      0.974 1.000 0.000
#> GSM528710     1  0.0000      0.974 1.000 0.000
#> GSM528711     1  0.0000      0.974 1.000 0.000
#> GSM528712     1  0.0000      0.974 1.000 0.000
#> GSM528721     2  0.0000      0.999 0.000 1.000
#> GSM528722     2  0.0000      0.999 0.000 1.000
#> GSM528723     2  0.0000      0.999 0.000 1.000
#> GSM528724     2  0.0000      0.999 0.000 1.000
#> GSM528727     2  0.0000      0.999 0.000 1.000
#> GSM528728     2  0.0000      0.999 0.000 1.000
#> GSM528725     2  0.0000      0.999 0.000 1.000
#> GSM528726     2  0.0000      0.999 0.000 1.000
#> GSM528733     1  0.0376      0.972 0.996 0.004
#> GSM528734     1  0.0376      0.972 0.996 0.004
#> GSM528735     1  0.0000      0.974 1.000 0.000
#> GSM528736     1  0.0000      0.974 1.000 0.000
#> GSM528737     1  0.0000      0.974 1.000 0.000
#> GSM528738     1  0.0000      0.974 1.000 0.000
#> GSM528729     1  0.0000      0.974 1.000 0.000
#> GSM528730     1  0.0000      0.974 1.000 0.000
#> GSM528731     1  0.0000      0.974 1.000 0.000
#> GSM528732     1  0.0000      0.974 1.000 0.000
#> GSM528739     2  0.0000      0.999 0.000 1.000
#> GSM528740     2  0.0000      0.999 0.000 1.000
#> GSM528741     2  0.0000      0.999 0.000 1.000
#> GSM528742     2  0.0000      0.999 0.000 1.000
#> GSM528745     2  0.0000      0.999 0.000 1.000
#> GSM528746     2  0.0000      0.999 0.000 1.000
#> GSM528743     2  0.0000      0.999 0.000 1.000
#> GSM528744     2  0.0000      0.999 0.000 1.000
#> GSM528751     1  0.6623      0.812 0.828 0.172
#> GSM528752     1  0.6623      0.812 0.828 0.172
#> GSM528753     1  0.0376      0.972 0.996 0.004
#> GSM528754     1  0.0376      0.972 0.996 0.004
#> GSM528755     1  0.0000      0.974 1.000 0.000
#> GSM528756     1  0.0000      0.974 1.000 0.000
#> GSM528757     1  0.0000      0.974 1.000 0.000
#> GSM528758     1  0.0000      0.974 1.000 0.000
#> GSM528747     1  0.0000      0.974 1.000 0.000
#> GSM528748     1  0.0000      0.974 1.000 0.000
#> GSM528749     1  0.0000      0.974 1.000 0.000
#> GSM528750     1  0.0000      0.974 1.000 0.000
#> GSM528640     2  0.0000      0.999 0.000 1.000
#> GSM528641     2  0.0376      0.996 0.004 0.996
#> GSM528643     1  0.0376      0.972 0.996 0.004
#> GSM528644     1  0.0000      0.974 1.000 0.000
#> GSM528642     1  0.0000      0.974 1.000 0.000
#> GSM528620     2  0.0000      0.999 0.000 1.000
#> GSM528621     1  0.9661      0.412 0.608 0.392
#> GSM528623     1  0.0376      0.972 0.996 0.004
#> GSM528624     1  0.0000      0.974 1.000 0.000
#> GSM528622     1  0.0000      0.974 1.000 0.000
#> GSM528625     2  0.0000      0.999 0.000 1.000
#> GSM528626     2  0.0376      0.996 0.004 0.996
#> GSM528628     1  0.0376      0.972 0.996 0.004
#> GSM528629     1  0.0000      0.974 1.000 0.000
#> GSM528627     1  0.0000      0.974 1.000 0.000
#> GSM528630     2  0.0000      0.999 0.000 1.000
#> GSM528631     2  0.0000      0.999 0.000 1.000
#> GSM528632     2  0.0376      0.996 0.004 0.996
#> GSM528633     2  0.0376      0.996 0.004 0.996
#> GSM528636     1  0.0376      0.972 0.996 0.004
#> GSM528637     1  0.0376      0.972 0.996 0.004
#> GSM528638     1  0.0000      0.974 1.000 0.000
#> GSM528639     1  0.0000      0.974 1.000 0.000
#> GSM528634     1  0.0000      0.974 1.000 0.000
#> GSM528635     1  0.0000      0.974 1.000 0.000
#> GSM528645     1  0.0376      0.972 0.996 0.004
#> GSM528646     1  0.0376      0.972 0.996 0.004
#> GSM528647     1  0.0376      0.972 0.996 0.004
#> GSM528648     1  0.0000      0.974 1.000 0.000
#> GSM528649     1  0.0000      0.974 1.000 0.000
#> GSM528650     1  0.0000      0.974 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-MAD-mclust-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-MAD-mclust-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)
#> Error in mat[ceiling(1:nr/h_ratio), ceiling(1:nc/w_ratio), drop = FALSE]: subscript out of bounds

plot of chunk tab-MAD-mclust-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)
#> Error in mat[ceiling(1:nr/h_ratio), ceiling(1:nc/w_ratio), drop = FALSE]: subscript out of bounds

plot of chunk tab-MAD-mclust-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk MAD-mclust-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-MAD-mclust-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk MAD-mclust-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>              n agent(p) dose(p)  time(p) k
#> MAD:mclust 168    0.903   0.999 2.34e-29 2
#> MAD:mclust 169    0.973   0.992 3.35e-52 3
#> MAD:mclust 156    0.983   0.963 1.00e-72 4
#> MAD:mclust 156    0.871   0.806 1.84e-78 5
#> MAD:mclust 133    0.455   0.413 2.96e-69 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


MAD:NMF**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["MAD", "NMF"]
# you can also extract it by
# res = res_list["MAD:NMF"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'MAD' method.
#>   Subgroups are detected by 'NMF' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk MAD-NMF-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk MAD-NMF-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           0.982       0.993         0.4789 0.524   0.524
#> 3 3 0.958           0.947       0.977         0.3975 0.765   0.568
#> 4 4 0.724           0.638       0.795         0.0896 0.899   0.709
#> 5 5 0.794           0.801       0.885         0.0615 0.876   0.592
#> 6 6 0.870           0.826       0.911         0.0369 0.922   0.684

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3
#> attr(,"optional")
#> [1] 2

There is also optional best \(k\) = 2 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2   0.000      0.997 0.000 1.000
#> GSM528682     2   0.000      0.997 0.000 1.000
#> GSM528683     2   0.000      0.997 0.000 1.000
#> GSM528684     2   0.000      0.997 0.000 1.000
#> GSM528687     2   0.000      0.997 0.000 1.000
#> GSM528688     2   0.000      0.997 0.000 1.000
#> GSM528685     2   0.000      0.997 0.000 1.000
#> GSM528686     2   0.000      0.997 0.000 1.000
#> GSM528693     1   0.000      0.990 1.000 0.000
#> GSM528694     1   0.000      0.990 1.000 0.000
#> GSM528695     1   0.000      0.990 1.000 0.000
#> GSM528696     1   0.000      0.990 1.000 0.000
#> GSM528697     1   0.000      0.990 1.000 0.000
#> GSM528698     1   0.000      0.990 1.000 0.000
#> GSM528699     1   0.000      0.990 1.000 0.000
#> GSM528700     1   0.000      0.990 1.000 0.000
#> GSM528689     1   0.000      0.990 1.000 0.000
#> GSM528690     1   0.000      0.990 1.000 0.000
#> GSM528691     1   0.000      0.990 1.000 0.000
#> GSM528692     1   0.000      0.990 1.000 0.000
#> GSM528779     2   0.000      0.997 0.000 1.000
#> GSM528780     2   0.000      0.997 0.000 1.000
#> GSM528782     2   0.000      0.997 0.000 1.000
#> GSM528781     2   0.000      0.997 0.000 1.000
#> GSM528785     1   0.788      0.695 0.764 0.236
#> GSM528786     1   0.000      0.990 1.000 0.000
#> GSM528787     1   0.000      0.990 1.000 0.000
#> GSM528788     1   0.000      0.990 1.000 0.000
#> GSM528783     1   0.000      0.990 1.000 0.000
#> GSM528784     1   0.000      0.990 1.000 0.000
#> GSM528759     1   0.000      0.990 1.000 0.000
#> GSM528760     1   0.000      0.990 1.000 0.000
#> GSM528761     2   0.000      0.997 0.000 1.000
#> GSM528762     2   0.000      0.997 0.000 1.000
#> GSM528765     2   0.000      0.997 0.000 1.000
#> GSM528766     2   0.000      0.997 0.000 1.000
#> GSM528763     2   0.000      0.997 0.000 1.000
#> GSM528764     2   0.000      0.997 0.000 1.000
#> GSM528771     1   0.738      0.740 0.792 0.208
#> GSM528772     1   0.482      0.881 0.896 0.104
#> GSM528773     1   0.000      0.990 1.000 0.000
#> GSM528774     1   0.000      0.990 1.000 0.000
#> GSM528775     1   0.000      0.990 1.000 0.000
#> GSM528776     1   0.000      0.990 1.000 0.000
#> GSM528777     1   0.000      0.990 1.000 0.000
#> GSM528778     1   0.000      0.990 1.000 0.000
#> GSM528767     1   0.000      0.990 1.000 0.000
#> GSM528768     1   0.000      0.990 1.000 0.000
#> GSM528769     1   0.000      0.990 1.000 0.000
#> GSM528770     1   0.000      0.990 1.000 0.000
#> GSM528671     2   0.000      0.997 0.000 1.000
#> GSM528672     2   0.000      0.997 0.000 1.000
#> GSM528674     2   0.000      0.997 0.000 1.000
#> GSM528673     2   0.000      0.997 0.000 1.000
#> GSM528677     1   0.000      0.990 1.000 0.000
#> GSM528678     1   0.000      0.990 1.000 0.000
#> GSM528679     1   0.000      0.990 1.000 0.000
#> GSM528680     1   0.000      0.990 1.000 0.000
#> GSM528675     1   0.000      0.990 1.000 0.000
#> GSM528676     1   0.000      0.990 1.000 0.000
#> GSM528651     2   0.000      0.997 0.000 1.000
#> GSM528652     2   0.000      0.997 0.000 1.000
#> GSM528653     2   0.000      0.997 0.000 1.000
#> GSM528654     2   0.000      0.997 0.000 1.000
#> GSM528657     2   0.000      0.997 0.000 1.000
#> GSM528658     2   0.000      0.997 0.000 1.000
#> GSM528655     2   0.000      0.997 0.000 1.000
#> GSM528656     2   0.000      0.997 0.000 1.000
#> GSM528663     1   0.997      0.132 0.532 0.468
#> GSM528664     2   0.653      0.794 0.168 0.832
#> GSM528665     1   0.000      0.990 1.000 0.000
#> GSM528666     1   0.000      0.990 1.000 0.000
#> GSM528667     1   0.000      0.990 1.000 0.000
#> GSM528668     1   0.000      0.990 1.000 0.000
#> GSM528669     1   0.000      0.990 1.000 0.000
#> GSM528670     1   0.000      0.990 1.000 0.000
#> GSM528659     1   0.000      0.990 1.000 0.000
#> GSM528660     1   0.000      0.990 1.000 0.000
#> GSM528661     1   0.000      0.990 1.000 0.000
#> GSM528662     1   0.000      0.990 1.000 0.000
#> GSM528701     2   0.000      0.997 0.000 1.000
#> GSM528702     2   0.000      0.997 0.000 1.000
#> GSM528703     2   0.000      0.997 0.000 1.000
#> GSM528704     2   0.000      0.997 0.000 1.000
#> GSM528707     2   0.000      0.997 0.000 1.000
#> GSM528708     2   0.000      0.997 0.000 1.000
#> GSM528705     2   0.000      0.997 0.000 1.000
#> GSM528706     2   0.000      0.997 0.000 1.000
#> GSM528713     1   0.000      0.990 1.000 0.000
#> GSM528714     1   0.000      0.990 1.000 0.000
#> GSM528715     1   0.000      0.990 1.000 0.000
#> GSM528716     1   0.000      0.990 1.000 0.000
#> GSM528717     1   0.000      0.990 1.000 0.000
#> GSM528718     1   0.000      0.990 1.000 0.000
#> GSM528719     1   0.000      0.990 1.000 0.000
#> GSM528720     1   0.000      0.990 1.000 0.000
#> GSM528709     1   0.000      0.990 1.000 0.000
#> GSM528710     1   0.000      0.990 1.000 0.000
#> GSM528711     1   0.000      0.990 1.000 0.000
#> GSM528712     1   0.000      0.990 1.000 0.000
#> GSM528721     2   0.000      0.997 0.000 1.000
#> GSM528722     2   0.000      0.997 0.000 1.000
#> GSM528723     2   0.000      0.997 0.000 1.000
#> GSM528724     2   0.000      0.997 0.000 1.000
#> GSM528727     2   0.000      0.997 0.000 1.000
#> GSM528728     2   0.000      0.997 0.000 1.000
#> GSM528725     2   0.000      0.997 0.000 1.000
#> GSM528726     2   0.000      0.997 0.000 1.000
#> GSM528733     1   0.000      0.990 1.000 0.000
#> GSM528734     1   0.000      0.990 1.000 0.000
#> GSM528735     1   0.000      0.990 1.000 0.000
#> GSM528736     1   0.000      0.990 1.000 0.000
#> GSM528737     1   0.000      0.990 1.000 0.000
#> GSM528738     1   0.000      0.990 1.000 0.000
#> GSM528729     1   0.000      0.990 1.000 0.000
#> GSM528730     1   0.000      0.990 1.000 0.000
#> GSM528731     1   0.000      0.990 1.000 0.000
#> GSM528732     1   0.000      0.990 1.000 0.000
#> GSM528739     2   0.000      0.997 0.000 1.000
#> GSM528740     2   0.000      0.997 0.000 1.000
#> GSM528741     2   0.000      0.997 0.000 1.000
#> GSM528742     2   0.000      0.997 0.000 1.000
#> GSM528745     2   0.000      0.997 0.000 1.000
#> GSM528746     2   0.000      0.997 0.000 1.000
#> GSM528743     2   0.000      0.997 0.000 1.000
#> GSM528744     2   0.000      0.997 0.000 1.000
#> GSM528751     1   0.311      0.934 0.944 0.056
#> GSM528752     1   0.000      0.990 1.000 0.000
#> GSM528753     1   0.000      0.990 1.000 0.000
#> GSM528754     1   0.000      0.990 1.000 0.000
#> GSM528755     1   0.000      0.990 1.000 0.000
#> GSM528756     1   0.000      0.990 1.000 0.000
#> GSM528757     1   0.000      0.990 1.000 0.000
#> GSM528758     1   0.000      0.990 1.000 0.000
#> GSM528747     1   0.000      0.990 1.000 0.000
#> GSM528748     1   0.000      0.990 1.000 0.000
#> GSM528749     1   0.000      0.990 1.000 0.000
#> GSM528750     1   0.000      0.990 1.000 0.000
#> GSM528640     2   0.000      0.997 0.000 1.000
#> GSM528641     2   0.000      0.997 0.000 1.000
#> GSM528643     1   0.000      0.990 1.000 0.000
#> GSM528644     1   0.000      0.990 1.000 0.000
#> GSM528642     1   0.000      0.990 1.000 0.000
#> GSM528620     2   0.000      0.997 0.000 1.000
#> GSM528621     2   0.000      0.997 0.000 1.000
#> GSM528623     1   0.000      0.990 1.000 0.000
#> GSM528624     1   0.000      0.990 1.000 0.000
#> GSM528622     1   0.000      0.990 1.000 0.000
#> GSM528625     2   0.000      0.997 0.000 1.000
#> GSM528626     2   0.000      0.997 0.000 1.000
#> GSM528628     1   0.000      0.990 1.000 0.000
#> GSM528629     1   0.000      0.990 1.000 0.000
#> GSM528627     1   0.000      0.990 1.000 0.000
#> GSM528630     2   0.000      0.997 0.000 1.000
#> GSM528631     2   0.000      0.997 0.000 1.000
#> GSM528632     2   0.000      0.997 0.000 1.000
#> GSM528633     2   0.000      0.997 0.000 1.000
#> GSM528636     1   0.000      0.990 1.000 0.000
#> GSM528637     1   0.000      0.990 1.000 0.000
#> GSM528638     1   0.000      0.990 1.000 0.000
#> GSM528639     1   0.000      0.990 1.000 0.000
#> GSM528634     1   0.000      0.990 1.000 0.000
#> GSM528635     1   0.000      0.990 1.000 0.000
#> GSM528645     1   0.000      0.990 1.000 0.000
#> GSM528646     1   0.000      0.990 1.000 0.000
#> GSM528647     1   0.000      0.990 1.000 0.000
#> GSM528648     1   0.000      0.990 1.000 0.000
#> GSM528649     1   0.000      0.990 1.000 0.000
#> GSM528650     1   0.000      0.990 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-MAD-NMF-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-MAD-NMF-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)
#> Error in mat[ceiling(1:nr/h_ratio), ceiling(1:nc/w_ratio), drop = FALSE]: subscript out of bounds

plot of chunk tab-MAD-NMF-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)
#> Error in mat[ceiling(1:nr/h_ratio), ceiling(1:nc/w_ratio), drop = FALSE]: subscript out of bounds

plot of chunk tab-MAD-NMF-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk MAD-NMF-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-MAD-NMF-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk MAD-NMF-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>           n agent(p) dose(p)  time(p) k
#> MAD:NMF 168   0.8663  0.9999 1.39e-28 2
#> MAD:NMF 166   0.2478  0.5294 1.09e-43 3
#> MAD:NMF 127   0.2398  0.4095 1.35e-39 4
#> MAD:NMF 158   0.0967  0.0122 2.11e-67 5
#> MAD:NMF 159   0.0473  0.1225 8.23e-66 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


ATC:hclust*

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["ATC", "hclust"]
# you can also extract it by
# res = res_list["ATC:hclust"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'ATC' method.
#>   Subgroups are detected by 'hclust' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 6.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk ATC-hclust-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk ATC-hclust-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           0.976       0.989         0.4306 0.576   0.576
#> 3 3 0.989           0.969       0.979         0.5226 0.765   0.592
#> 4 4 0.911           0.906       0.951         0.0814 0.957   0.874
#> 5 5 0.893           0.834       0.868         0.0397 0.962   0.871
#> 6 6 0.900           0.879       0.912         0.0386 0.986   0.948

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 6
#> attr(,"optional")
#> [1] 2 3 4

There is also optional best \(k\) = 2 3 4 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2  0.0000      0.997 0.000 1.000
#> GSM528682     2  0.0000      0.997 0.000 1.000
#> GSM528683     2  0.0000      0.997 0.000 1.000
#> GSM528684     2  0.0000      0.997 0.000 1.000
#> GSM528687     2  0.0000      0.997 0.000 1.000
#> GSM528688     2  0.0000      0.997 0.000 1.000
#> GSM528685     1  0.4431      0.902 0.908 0.092
#> GSM528686     1  0.4431      0.902 0.908 0.092
#> GSM528693     1  0.0000      0.986 1.000 0.000
#> GSM528694     1  0.0000      0.986 1.000 0.000
#> GSM528695     1  0.0000      0.986 1.000 0.000
#> GSM528696     1  0.0000      0.986 1.000 0.000
#> GSM528697     1  0.0000      0.986 1.000 0.000
#> GSM528698     1  0.0000      0.986 1.000 0.000
#> GSM528699     1  0.0000      0.986 1.000 0.000
#> GSM528700     1  0.0000      0.986 1.000 0.000
#> GSM528689     1  0.0000      0.986 1.000 0.000
#> GSM528690     1  0.0000      0.986 1.000 0.000
#> GSM528691     1  0.0000      0.986 1.000 0.000
#> GSM528692     1  0.0000      0.986 1.000 0.000
#> GSM528779     2  0.0000      0.997 0.000 1.000
#> GSM528780     2  0.0000      0.997 0.000 1.000
#> GSM528782     2  0.0000      0.997 0.000 1.000
#> GSM528781     2  0.6343      0.804 0.160 0.840
#> GSM528785     1  0.0000      0.986 1.000 0.000
#> GSM528786     1  0.0000      0.986 1.000 0.000
#> GSM528787     1  0.0000      0.986 1.000 0.000
#> GSM528788     1  0.0000      0.986 1.000 0.000
#> GSM528783     1  0.0000      0.986 1.000 0.000
#> GSM528784     1  0.0000      0.986 1.000 0.000
#> GSM528759     1  0.0000      0.986 1.000 0.000
#> GSM528760     1  0.0000      0.986 1.000 0.000
#> GSM528761     2  0.0000      0.997 0.000 1.000
#> GSM528762     2  0.0000      0.997 0.000 1.000
#> GSM528765     2  0.0000      0.997 0.000 1.000
#> GSM528766     2  0.0000      0.997 0.000 1.000
#> GSM528763     1  0.9358      0.483 0.648 0.352
#> GSM528764     1  0.4431      0.902 0.908 0.092
#> GSM528771     1  0.0000      0.986 1.000 0.000
#> GSM528772     1  0.0000      0.986 1.000 0.000
#> GSM528773     1  0.0000      0.986 1.000 0.000
#> GSM528774     1  0.0000      0.986 1.000 0.000
#> GSM528775     1  0.0000      0.986 1.000 0.000
#> GSM528776     1  0.0000      0.986 1.000 0.000
#> GSM528777     1  0.0000      0.986 1.000 0.000
#> GSM528778     1  0.0000      0.986 1.000 0.000
#> GSM528767     1  0.0000      0.986 1.000 0.000
#> GSM528768     1  0.0000      0.986 1.000 0.000
#> GSM528769     1  0.0000      0.986 1.000 0.000
#> GSM528770     1  0.0000      0.986 1.000 0.000
#> GSM528671     2  0.0000      0.997 0.000 1.000
#> GSM528672     2  0.0000      0.997 0.000 1.000
#> GSM528674     2  0.0000      0.997 0.000 1.000
#> GSM528673     1  0.4431      0.902 0.908 0.092
#> GSM528677     1  0.0000      0.986 1.000 0.000
#> GSM528678     1  0.0000      0.986 1.000 0.000
#> GSM528679     1  0.0000      0.986 1.000 0.000
#> GSM528680     1  0.0000      0.986 1.000 0.000
#> GSM528675     1  0.0000      0.986 1.000 0.000
#> GSM528676     1  0.0000      0.986 1.000 0.000
#> GSM528651     2  0.0000      0.997 0.000 1.000
#> GSM528652     2  0.0000      0.997 0.000 1.000
#> GSM528653     2  0.0000      0.997 0.000 1.000
#> GSM528654     2  0.0000      0.997 0.000 1.000
#> GSM528657     2  0.0000      0.997 0.000 1.000
#> GSM528658     2  0.0000      0.997 0.000 1.000
#> GSM528655     1  0.4431      0.902 0.908 0.092
#> GSM528656     1  0.4431      0.902 0.908 0.092
#> GSM528663     1  0.0000      0.986 1.000 0.000
#> GSM528664     1  0.0000      0.986 1.000 0.000
#> GSM528665     1  0.0000      0.986 1.000 0.000
#> GSM528666     1  0.0000      0.986 1.000 0.000
#> GSM528667     1  0.0000      0.986 1.000 0.000
#> GSM528668     1  0.0000      0.986 1.000 0.000
#> GSM528669     1  0.0000      0.986 1.000 0.000
#> GSM528670     1  0.0000      0.986 1.000 0.000
#> GSM528659     1  0.0000      0.986 1.000 0.000
#> GSM528660     1  0.0000      0.986 1.000 0.000
#> GSM528661     1  0.0000      0.986 1.000 0.000
#> GSM528662     1  0.0000      0.986 1.000 0.000
#> GSM528701     2  0.0000      0.997 0.000 1.000
#> GSM528702     2  0.0000      0.997 0.000 1.000
#> GSM528703     2  0.0000      0.997 0.000 1.000
#> GSM528704     2  0.0000      0.997 0.000 1.000
#> GSM528707     2  0.0000      0.997 0.000 1.000
#> GSM528708     2  0.0000      0.997 0.000 1.000
#> GSM528705     2  0.0000      0.997 0.000 1.000
#> GSM528706     2  0.0000      0.997 0.000 1.000
#> GSM528713     1  0.0000      0.986 1.000 0.000
#> GSM528714     1  0.0000      0.986 1.000 0.000
#> GSM528715     1  0.0000      0.986 1.000 0.000
#> GSM528716     1  0.0000      0.986 1.000 0.000
#> GSM528717     1  0.0000      0.986 1.000 0.000
#> GSM528718     1  0.0000      0.986 1.000 0.000
#> GSM528719     1  0.0000      0.986 1.000 0.000
#> GSM528720     1  0.0000      0.986 1.000 0.000
#> GSM528709     1  0.0000      0.986 1.000 0.000
#> GSM528710     1  0.0000      0.986 1.000 0.000
#> GSM528711     1  0.0000      0.986 1.000 0.000
#> GSM528712     1  0.0000      0.986 1.000 0.000
#> GSM528721     2  0.0000      0.997 0.000 1.000
#> GSM528722     2  0.0000      0.997 0.000 1.000
#> GSM528723     2  0.0000      0.997 0.000 1.000
#> GSM528724     2  0.0000      0.997 0.000 1.000
#> GSM528727     2  0.0000      0.997 0.000 1.000
#> GSM528728     2  0.0000      0.997 0.000 1.000
#> GSM528725     2  0.0000      0.997 0.000 1.000
#> GSM528726     2  0.0000      0.997 0.000 1.000
#> GSM528733     1  0.0000      0.986 1.000 0.000
#> GSM528734     1  0.0000      0.986 1.000 0.000
#> GSM528735     1  0.0000      0.986 1.000 0.000
#> GSM528736     1  0.0000      0.986 1.000 0.000
#> GSM528737     1  0.0000      0.986 1.000 0.000
#> GSM528738     1  0.0000      0.986 1.000 0.000
#> GSM528729     1  0.0000      0.986 1.000 0.000
#> GSM528730     1  0.0000      0.986 1.000 0.000
#> GSM528731     1  0.0000      0.986 1.000 0.000
#> GSM528732     1  0.0000      0.986 1.000 0.000
#> GSM528739     2  0.0000      0.997 0.000 1.000
#> GSM528740     2  0.0000      0.997 0.000 1.000
#> GSM528741     2  0.0000      0.997 0.000 1.000
#> GSM528742     2  0.0000      0.997 0.000 1.000
#> GSM528745     1  0.9661      0.385 0.608 0.392
#> GSM528746     2  0.0000      0.997 0.000 1.000
#> GSM528743     2  0.0000      0.997 0.000 1.000
#> GSM528744     2  0.0000      0.997 0.000 1.000
#> GSM528751     1  0.0000      0.986 1.000 0.000
#> GSM528752     1  0.0000      0.986 1.000 0.000
#> GSM528753     1  0.0000      0.986 1.000 0.000
#> GSM528754     1  0.0000      0.986 1.000 0.000
#> GSM528755     1  0.0000      0.986 1.000 0.000
#> GSM528756     1  0.0000      0.986 1.000 0.000
#> GSM528757     1  0.0000      0.986 1.000 0.000
#> GSM528758     1  0.0000      0.986 1.000 0.000
#> GSM528747     1  0.0000      0.986 1.000 0.000
#> GSM528748     1  0.0000      0.986 1.000 0.000
#> GSM528749     1  0.0000      0.986 1.000 0.000
#> GSM528750     1  0.0000      0.986 1.000 0.000
#> GSM528640     2  0.0000      0.997 0.000 1.000
#> GSM528641     1  0.4431      0.902 0.908 0.092
#> GSM528643     1  0.0000      0.986 1.000 0.000
#> GSM528644     1  0.0000      0.986 1.000 0.000
#> GSM528642     1  0.0000      0.986 1.000 0.000
#> GSM528620     2  0.0000      0.997 0.000 1.000
#> GSM528621     1  0.0376      0.982 0.996 0.004
#> GSM528623     1  0.0000      0.986 1.000 0.000
#> GSM528624     1  0.0000      0.986 1.000 0.000
#> GSM528622     1  0.0000      0.986 1.000 0.000
#> GSM528625     2  0.0000      0.997 0.000 1.000
#> GSM528626     1  0.4431      0.902 0.908 0.092
#> GSM528628     1  0.0000      0.986 1.000 0.000
#> GSM528629     1  0.0000      0.986 1.000 0.000
#> GSM528627     1  0.0000      0.986 1.000 0.000
#> GSM528630     2  0.0000      0.997 0.000 1.000
#> GSM528631     2  0.0000      0.997 0.000 1.000
#> GSM528632     1  0.4431      0.902 0.908 0.092
#> GSM528633     1  0.4431      0.902 0.908 0.092
#> GSM528636     1  0.0000      0.986 1.000 0.000
#> GSM528637     1  0.0000      0.986 1.000 0.000
#> GSM528638     1  0.0000      0.986 1.000 0.000
#> GSM528639     1  0.0000      0.986 1.000 0.000
#> GSM528634     1  0.0000      0.986 1.000 0.000
#> GSM528635     1  0.0000      0.986 1.000 0.000
#> GSM528645     1  0.0000      0.986 1.000 0.000
#> GSM528646     1  0.0000      0.986 1.000 0.000
#> GSM528647     1  0.0000      0.986 1.000 0.000
#> GSM528648     1  0.0000      0.986 1.000 0.000
#> GSM528649     1  0.0000      0.986 1.000 0.000
#> GSM528650     1  0.0000      0.986 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-ATC-hclust-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-ATC-hclust-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-ATC-hclust-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-ATC-hclust-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk ATC-hclust-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-ATC-hclust-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk ATC-hclust-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>              n agent(p) dose(p)  time(p) k
#> ATC:hclust 167   0.6267   0.942 7.59e-25 2
#> ATC:hclust 168   0.9275   0.991 4.45e-49 3
#> ATC:hclust 163   0.2796   0.608 5.96e-48 4
#> ATC:hclust 159   0.2858   0.786 1.56e-67 5
#> ATC:hclust 163   0.0307   0.933 3.98e-66 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


ATC:kmeans**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["ATC", "kmeans"]
# you can also extract it by
# res = res_list["ATC:kmeans"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'ATC' method.
#>   Subgroups are detected by 'kmeans' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 2.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk ATC-kmeans-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk ATC-kmeans-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           1.000       1.000         0.4709 0.530   0.530
#> 3 3 0.778           0.909       0.931         0.3694 0.796   0.622
#> 4 4 0.716           0.657       0.755         0.1124 0.943   0.843
#> 5 5 0.686           0.557       0.691         0.0697 0.818   0.489
#> 6 6 0.715           0.684       0.757         0.0447 0.891   0.572

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 2

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette p1 p2
#> GSM528681     2       0          1  0  1
#> GSM528682     2       0          1  0  1
#> GSM528683     2       0          1  0  1
#> GSM528684     2       0          1  0  1
#> GSM528687     2       0          1  0  1
#> GSM528688     2       0          1  0  1
#> GSM528685     2       0          1  0  1
#> GSM528686     2       0          1  0  1
#> GSM528693     1       0          1  1  0
#> GSM528694     1       0          1  1  0
#> GSM528695     1       0          1  1  0
#> GSM528696     1       0          1  1  0
#> GSM528697     1       0          1  1  0
#> GSM528698     1       0          1  1  0
#> GSM528699     1       0          1  1  0
#> GSM528700     1       0          1  1  0
#> GSM528689     1       0          1  1  0
#> GSM528690     1       0          1  1  0
#> GSM528691     1       0          1  1  0
#> GSM528692     1       0          1  1  0
#> GSM528779     2       0          1  0  1
#> GSM528780     2       0          1  0  1
#> GSM528782     2       0          1  0  1
#> GSM528781     2       0          1  0  1
#> GSM528785     1       0          1  1  0
#> GSM528786     1       0          1  1  0
#> GSM528787     1       0          1  1  0
#> GSM528788     1       0          1  1  0
#> GSM528783     1       0          1  1  0
#> GSM528784     1       0          1  1  0
#> GSM528759     1       0          1  1  0
#> GSM528760     1       0          1  1  0
#> GSM528761     2       0          1  0  1
#> GSM528762     2       0          1  0  1
#> GSM528765     2       0          1  0  1
#> GSM528766     2       0          1  0  1
#> GSM528763     2       0          1  0  1
#> GSM528764     2       0          1  0  1
#> GSM528771     1       0          1  1  0
#> GSM528772     1       0          1  1  0
#> GSM528773     1       0          1  1  0
#> GSM528774     1       0          1  1  0
#> GSM528775     1       0          1  1  0
#> GSM528776     1       0          1  1  0
#> GSM528777     1       0          1  1  0
#> GSM528778     1       0          1  1  0
#> GSM528767     1       0          1  1  0
#> GSM528768     1       0          1  1  0
#> GSM528769     1       0          1  1  0
#> GSM528770     1       0          1  1  0
#> GSM528671     2       0          1  0  1
#> GSM528672     2       0          1  0  1
#> GSM528674     2       0          1  0  1
#> GSM528673     2       0          1  0  1
#> GSM528677     1       0          1  1  0
#> GSM528678     1       0          1  1  0
#> GSM528679     1       0          1  1  0
#> GSM528680     1       0          1  1  0
#> GSM528675     1       0          1  1  0
#> GSM528676     1       0          1  1  0
#> GSM528651     2       0          1  0  1
#> GSM528652     2       0          1  0  1
#> GSM528653     2       0          1  0  1
#> GSM528654     2       0          1  0  1
#> GSM528657     2       0          1  0  1
#> GSM528658     2       0          1  0  1
#> GSM528655     2       0          1  0  1
#> GSM528656     2       0          1  0  1
#> GSM528663     1       0          1  1  0
#> GSM528664     1       0          1  1  0
#> GSM528665     1       0          1  1  0
#> GSM528666     1       0          1  1  0
#> GSM528667     1       0          1  1  0
#> GSM528668     1       0          1  1  0
#> GSM528669     1       0          1  1  0
#> GSM528670     1       0          1  1  0
#> GSM528659     1       0          1  1  0
#> GSM528660     1       0          1  1  0
#> GSM528661     1       0          1  1  0
#> GSM528662     1       0          1  1  0
#> GSM528701     2       0          1  0  1
#> GSM528702     2       0          1  0  1
#> GSM528703     2       0          1  0  1
#> GSM528704     2       0          1  0  1
#> GSM528707     2       0          1  0  1
#> GSM528708     2       0          1  0  1
#> GSM528705     2       0          1  0  1
#> GSM528706     2       0          1  0  1
#> GSM528713     1       0          1  1  0
#> GSM528714     1       0          1  1  0
#> GSM528715     1       0          1  1  0
#> GSM528716     1       0          1  1  0
#> GSM528717     1       0          1  1  0
#> GSM528718     1       0          1  1  0
#> GSM528719     1       0          1  1  0
#> GSM528720     1       0          1  1  0
#> GSM528709     1       0          1  1  0
#> GSM528710     1       0          1  1  0
#> GSM528711     1       0          1  1  0
#> GSM528712     1       0          1  1  0
#> GSM528721     2       0          1  0  1
#> GSM528722     2       0          1  0  1
#> GSM528723     2       0          1  0  1
#> GSM528724     2       0          1  0  1
#> GSM528727     2       0          1  0  1
#> GSM528728     2       0          1  0  1
#> GSM528725     2       0          1  0  1
#> GSM528726     2       0          1  0  1
#> GSM528733     1       0          1  1  0
#> GSM528734     1       0          1  1  0
#> GSM528735     1       0          1  1  0
#> GSM528736     1       0          1  1  0
#> GSM528737     1       0          1  1  0
#> GSM528738     1       0          1  1  0
#> GSM528729     1       0          1  1  0
#> GSM528730     1       0          1  1  0
#> GSM528731     1       0          1  1  0
#> GSM528732     1       0          1  1  0
#> GSM528739     2       0          1  0  1
#> GSM528740     2       0          1  0  1
#> GSM528741     2       0          1  0  1
#> GSM528742     2       0          1  0  1
#> GSM528745     2       0          1  0  1
#> GSM528746     2       0          1  0  1
#> GSM528743     2       0          1  0  1
#> GSM528744     2       0          1  0  1
#> GSM528751     1       0          1  1  0
#> GSM528752     1       0          1  1  0
#> GSM528753     1       0          1  1  0
#> GSM528754     1       0          1  1  0
#> GSM528755     1       0          1  1  0
#> GSM528756     1       0          1  1  0
#> GSM528757     1       0          1  1  0
#> GSM528758     1       0          1  1  0
#> GSM528747     1       0          1  1  0
#> GSM528748     1       0          1  1  0
#> GSM528749     1       0          1  1  0
#> GSM528750     1       0          1  1  0
#> GSM528640     2       0          1  0  1
#> GSM528641     2       0          1  0  1
#> GSM528643     1       0          1  1  0
#> GSM528644     1       0          1  1  0
#> GSM528642     1       0          1  1  0
#> GSM528620     2       0          1  0  1
#> GSM528621     1       0          1  1  0
#> GSM528623     1       0          1  1  0
#> GSM528624     1       0          1  1  0
#> GSM528622     1       0          1  1  0
#> GSM528625     2       0          1  0  1
#> GSM528626     2       0          1  0  1
#> GSM528628     1       0          1  1  0
#> GSM528629     1       0          1  1  0
#> GSM528627     1       0          1  1  0
#> GSM528630     2       0          1  0  1
#> GSM528631     2       0          1  0  1
#> GSM528632     2       0          1  0  1
#> GSM528633     2       0          1  0  1
#> GSM528636     1       0          1  1  0
#> GSM528637     1       0          1  1  0
#> GSM528638     1       0          1  1  0
#> GSM528639     1       0          1  1  0
#> GSM528634     1       0          1  1  0
#> GSM528635     1       0          1  1  0
#> GSM528645     1       0          1  1  0
#> GSM528646     1       0          1  1  0
#> GSM528647     1       0          1  1  0
#> GSM528648     1       0          1  1  0
#> GSM528649     1       0          1  1  0
#> GSM528650     1       0          1  1  0

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-ATC-kmeans-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-ATC-kmeans-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-ATC-kmeans-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-ATC-kmeans-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk ATC-kmeans-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-ATC-kmeans-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk ATC-kmeans-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>              n agent(p) dose(p)  time(p) k
#> ATC:kmeans 169   0.8908  0.9925 1.01e-28 2
#> ATC:kmeans 163   0.9603  0.9827 3.71e-47 3
#> ATC:kmeans 134   0.8575  0.8093 6.91e-54 4
#> ATC:kmeans 113   0.3907  0.7810 1.22e-43 5
#> ATC:kmeans 143   0.0169  0.0172 1.05e-76 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


ATC:skmeans**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["ATC", "skmeans"]
# you can also extract it by
# res = res_list["ATC:skmeans"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'ATC' method.
#>   Subgroups are detected by 'skmeans' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 4.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk ATC-skmeans-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk ATC-skmeans-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           1.000       1.000         0.4739 0.527   0.527
#> 3 3 0.950           0.959       0.981         0.3735 0.814   0.648
#> 4 4 0.964           0.934       0.963         0.0656 0.935   0.816
#> 5 5 0.813           0.776       0.840         0.0832 0.891   0.663
#> 6 6 0.871           0.732       0.755         0.0478 0.891   0.612

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 4
#> attr(,"optional")
#> [1] 2 3

There is also optional best \(k\) = 2 3 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette p1 p2
#> GSM528681     2       0          1  0  1
#> GSM528682     2       0          1  0  1
#> GSM528683     2       0          1  0  1
#> GSM528684     2       0          1  0  1
#> GSM528687     2       0          1  0  1
#> GSM528688     2       0          1  0  1
#> GSM528685     2       0          1  0  1
#> GSM528686     2       0          1  0  1
#> GSM528693     1       0          1  1  0
#> GSM528694     1       0          1  1  0
#> GSM528695     1       0          1  1  0
#> GSM528696     1       0          1  1  0
#> GSM528697     1       0          1  1  0
#> GSM528698     1       0          1  1  0
#> GSM528699     1       0          1  1  0
#> GSM528700     1       0          1  1  0
#> GSM528689     1       0          1  1  0
#> GSM528690     1       0          1  1  0
#> GSM528691     1       0          1  1  0
#> GSM528692     1       0          1  1  0
#> GSM528779     2       0          1  0  1
#> GSM528780     2       0          1  0  1
#> GSM528782     2       0          1  0  1
#> GSM528781     2       0          1  0  1
#> GSM528785     1       0          1  1  0
#> GSM528786     1       0          1  1  0
#> GSM528787     1       0          1  1  0
#> GSM528788     1       0          1  1  0
#> GSM528783     1       0          1  1  0
#> GSM528784     1       0          1  1  0
#> GSM528759     1       0          1  1  0
#> GSM528760     1       0          1  1  0
#> GSM528761     2       0          1  0  1
#> GSM528762     2       0          1  0  1
#> GSM528765     2       0          1  0  1
#> GSM528766     2       0          1  0  1
#> GSM528763     2       0          1  0  1
#> GSM528764     2       0          1  0  1
#> GSM528771     1       0          1  1  0
#> GSM528772     1       0          1  1  0
#> GSM528773     1       0          1  1  0
#> GSM528774     1       0          1  1  0
#> GSM528775     1       0          1  1  0
#> GSM528776     1       0          1  1  0
#> GSM528777     1       0          1  1  0
#> GSM528778     1       0          1  1  0
#> GSM528767     1       0          1  1  0
#> GSM528768     1       0          1  1  0
#> GSM528769     1       0          1  1  0
#> GSM528770     1       0          1  1  0
#> GSM528671     2       0          1  0  1
#> GSM528672     2       0          1  0  1
#> GSM528674     2       0          1  0  1
#> GSM528673     2       0          1  0  1
#> GSM528677     1       0          1  1  0
#> GSM528678     1       0          1  1  0
#> GSM528679     1       0          1  1  0
#> GSM528680     1       0          1  1  0
#> GSM528675     1       0          1  1  0
#> GSM528676     1       0          1  1  0
#> GSM528651     2       0          1  0  1
#> GSM528652     2       0          1  0  1
#> GSM528653     2       0          1  0  1
#> GSM528654     2       0          1  0  1
#> GSM528657     2       0          1  0  1
#> GSM528658     2       0          1  0  1
#> GSM528655     2       0          1  0  1
#> GSM528656     2       0          1  0  1
#> GSM528663     1       0          1  1  0
#> GSM528664     1       0          1  1  0
#> GSM528665     1       0          1  1  0
#> GSM528666     1       0          1  1  0
#> GSM528667     1       0          1  1  0
#> GSM528668     1       0          1  1  0
#> GSM528669     1       0          1  1  0
#> GSM528670     1       0          1  1  0
#> GSM528659     1       0          1  1  0
#> GSM528660     1       0          1  1  0
#> GSM528661     1       0          1  1  0
#> GSM528662     1       0          1  1  0
#> GSM528701     2       0          1  0  1
#> GSM528702     2       0          1  0  1
#> GSM528703     2       0          1  0  1
#> GSM528704     2       0          1  0  1
#> GSM528707     2       0          1  0  1
#> GSM528708     2       0          1  0  1
#> GSM528705     2       0          1  0  1
#> GSM528706     2       0          1  0  1
#> GSM528713     1       0          1  1  0
#> GSM528714     1       0          1  1  0
#> GSM528715     1       0          1  1  0
#> GSM528716     1       0          1  1  0
#> GSM528717     1       0          1  1  0
#> GSM528718     1       0          1  1  0
#> GSM528719     1       0          1  1  0
#> GSM528720     1       0          1  1  0
#> GSM528709     1       0          1  1  0
#> GSM528710     1       0          1  1  0
#> GSM528711     1       0          1  1  0
#> GSM528712     1       0          1  1  0
#> GSM528721     2       0          1  0  1
#> GSM528722     2       0          1  0  1
#> GSM528723     2       0          1  0  1
#> GSM528724     2       0          1  0  1
#> GSM528727     2       0          1  0  1
#> GSM528728     2       0          1  0  1
#> GSM528725     2       0          1  0  1
#> GSM528726     2       0          1  0  1
#> GSM528733     1       0          1  1  0
#> GSM528734     1       0          1  1  0
#> GSM528735     1       0          1  1  0
#> GSM528736     1       0          1  1  0
#> GSM528737     1       0          1  1  0
#> GSM528738     1       0          1  1  0
#> GSM528729     1       0          1  1  0
#> GSM528730     1       0          1  1  0
#> GSM528731     1       0          1  1  0
#> GSM528732     1       0          1  1  0
#> GSM528739     2       0          1  0  1
#> GSM528740     2       0          1  0  1
#> GSM528741     2       0          1  0  1
#> GSM528742     2       0          1  0  1
#> GSM528745     2       0          1  0  1
#> GSM528746     2       0          1  0  1
#> GSM528743     2       0          1  0  1
#> GSM528744     2       0          1  0  1
#> GSM528751     1       0          1  1  0
#> GSM528752     1       0          1  1  0
#> GSM528753     1       0          1  1  0
#> GSM528754     1       0          1  1  0
#> GSM528755     1       0          1  1  0
#> GSM528756     1       0          1  1  0
#> GSM528757     1       0          1  1  0
#> GSM528758     1       0          1  1  0
#> GSM528747     1       0          1  1  0
#> GSM528748     1       0          1  1  0
#> GSM528749     1       0          1  1  0
#> GSM528750     1       0          1  1  0
#> GSM528640     2       0          1  0  1
#> GSM528641     2       0          1  0  1
#> GSM528643     1       0          1  1  0
#> GSM528644     1       0          1  1  0
#> GSM528642     1       0          1  1  0
#> GSM528620     2       0          1  0  1
#> GSM528621     2       0          1  0  1
#> GSM528623     1       0          1  1  0
#> GSM528624     1       0          1  1  0
#> GSM528622     1       0          1  1  0
#> GSM528625     2       0          1  0  1
#> GSM528626     2       0          1  0  1
#> GSM528628     1       0          1  1  0
#> GSM528629     1       0          1  1  0
#> GSM528627     1       0          1  1  0
#> GSM528630     2       0          1  0  1
#> GSM528631     2       0          1  0  1
#> GSM528632     2       0          1  0  1
#> GSM528633     2       0          1  0  1
#> GSM528636     1       0          1  1  0
#> GSM528637     1       0          1  1  0
#> GSM528638     1       0          1  1  0
#> GSM528639     1       0          1  1  0
#> GSM528634     1       0          1  1  0
#> GSM528635     1       0          1  1  0
#> GSM528645     1       0          1  1  0
#> GSM528646     1       0          1  1  0
#> GSM528647     1       0          1  1  0
#> GSM528648     1       0          1  1  0
#> GSM528649     1       0          1  1  0
#> GSM528650     1       0          1  1  0

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-ATC-skmeans-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-ATC-skmeans-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-ATC-skmeans-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-ATC-skmeans-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk ATC-skmeans-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-ATC-skmeans-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk ATC-skmeans-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>               n agent(p) dose(p)  time(p) k
#> ATC:skmeans 169  0.90691   1.000 1.43e-29 2
#> ATC:skmeans 167  0.95762   1.000 1.87e-50 3
#> ATC:skmeans 167  0.82442   0.983 1.59e-71 4
#> ATC:skmeans 132  0.00783   0.017 7.76e-46 5
#> ATC:skmeans 122  0.30726   0.396 2.32e-54 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


ATC:pam**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["ATC", "pam"]
# you can also extract it by
# res = res_list["ATC:pam"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'ATC' method.
#>   Subgroups are detected by 'pam' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 2.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk ATC-pam-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk ATC-pam-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           0.997       0.998         0.4740 0.527   0.527
#> 3 3 0.748           0.719       0.837         0.3472 0.857   0.731
#> 4 4 0.799           0.779       0.879         0.1008 0.916   0.789
#> 5 5 0.737           0.756       0.816         0.0733 0.926   0.774
#> 6 6 0.806           0.689       0.821         0.0709 0.863   0.529

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 2

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2  0.0000      0.998 0.000 1.000
#> GSM528682     2  0.0000      0.998 0.000 1.000
#> GSM528683     2  0.0000      0.998 0.000 1.000
#> GSM528684     2  0.0000      0.998 0.000 1.000
#> GSM528687     2  0.0000      0.998 0.000 1.000
#> GSM528688     2  0.0000      0.998 0.000 1.000
#> GSM528685     2  0.0000      0.998 0.000 1.000
#> GSM528686     2  0.0000      0.998 0.000 1.000
#> GSM528693     1  0.0000      0.998 1.000 0.000
#> GSM528694     1  0.0000      0.998 1.000 0.000
#> GSM528695     1  0.0000      0.998 1.000 0.000
#> GSM528696     1  0.0000      0.998 1.000 0.000
#> GSM528697     1  0.0000      0.998 1.000 0.000
#> GSM528698     1  0.0000      0.998 1.000 0.000
#> GSM528699     1  0.0000      0.998 1.000 0.000
#> GSM528700     1  0.0000      0.998 1.000 0.000
#> GSM528689     1  0.0000      0.998 1.000 0.000
#> GSM528690     1  0.0000      0.998 1.000 0.000
#> GSM528691     1  0.0000      0.998 1.000 0.000
#> GSM528692     1  0.0000      0.998 1.000 0.000
#> GSM528779     2  0.0000      0.998 0.000 1.000
#> GSM528780     2  0.0000      0.998 0.000 1.000
#> GSM528782     2  0.0000      0.998 0.000 1.000
#> GSM528781     2  0.0000      0.998 0.000 1.000
#> GSM528785     1  0.0000      0.998 1.000 0.000
#> GSM528786     1  0.4022      0.914 0.920 0.080
#> GSM528787     1  0.0000      0.998 1.000 0.000
#> GSM528788     1  0.0000      0.998 1.000 0.000
#> GSM528783     1  0.0000      0.998 1.000 0.000
#> GSM528784     1  0.0000      0.998 1.000 0.000
#> GSM528759     1  0.0000      0.998 1.000 0.000
#> GSM528760     1  0.0000      0.998 1.000 0.000
#> GSM528761     2  0.0000      0.998 0.000 1.000
#> GSM528762     2  0.0000      0.998 0.000 1.000
#> GSM528765     2  0.0000      0.998 0.000 1.000
#> GSM528766     2  0.0000      0.998 0.000 1.000
#> GSM528763     2  0.0000      0.998 0.000 1.000
#> GSM528764     2  0.0000      0.998 0.000 1.000
#> GSM528771     1  0.0000      0.998 1.000 0.000
#> GSM528772     1  0.0000      0.998 1.000 0.000
#> GSM528773     1  0.0000      0.998 1.000 0.000
#> GSM528774     1  0.0000      0.998 1.000 0.000
#> GSM528775     1  0.0000      0.998 1.000 0.000
#> GSM528776     1  0.0000      0.998 1.000 0.000
#> GSM528777     1  0.0000      0.998 1.000 0.000
#> GSM528778     1  0.0000      0.998 1.000 0.000
#> GSM528767     1  0.0000      0.998 1.000 0.000
#> GSM528768     1  0.0000      0.998 1.000 0.000
#> GSM528769     1  0.0000      0.998 1.000 0.000
#> GSM528770     1  0.0000      0.998 1.000 0.000
#> GSM528671     2  0.0000      0.998 0.000 1.000
#> GSM528672     2  0.0000      0.998 0.000 1.000
#> GSM528674     2  0.0000      0.998 0.000 1.000
#> GSM528673     2  0.0000      0.998 0.000 1.000
#> GSM528677     1  0.0000      0.998 1.000 0.000
#> GSM528678     1  0.0000      0.998 1.000 0.000
#> GSM528679     1  0.0000      0.998 1.000 0.000
#> GSM528680     1  0.0000      0.998 1.000 0.000
#> GSM528675     1  0.0000      0.998 1.000 0.000
#> GSM528676     1  0.0000      0.998 1.000 0.000
#> GSM528651     2  0.0000      0.998 0.000 1.000
#> GSM528652     2  0.0000      0.998 0.000 1.000
#> GSM528653     2  0.0000      0.998 0.000 1.000
#> GSM528654     2  0.0000      0.998 0.000 1.000
#> GSM528657     2  0.0000      0.998 0.000 1.000
#> GSM528658     2  0.0000      0.998 0.000 1.000
#> GSM528655     2  0.0000      0.998 0.000 1.000
#> GSM528656     2  0.0000      0.998 0.000 1.000
#> GSM528663     1  0.0938      0.987 0.988 0.012
#> GSM528664     1  0.4022      0.914 0.920 0.080
#> GSM528665     1  0.0000      0.998 1.000 0.000
#> GSM528666     1  0.0000      0.998 1.000 0.000
#> GSM528667     1  0.0000      0.998 1.000 0.000
#> GSM528668     1  0.0000      0.998 1.000 0.000
#> GSM528669     1  0.0000      0.998 1.000 0.000
#> GSM528670     1  0.0000      0.998 1.000 0.000
#> GSM528659     1  0.0000      0.998 1.000 0.000
#> GSM528660     1  0.0000      0.998 1.000 0.000
#> GSM528661     1  0.0000      0.998 1.000 0.000
#> GSM528662     1  0.0000      0.998 1.000 0.000
#> GSM528701     2  0.0000      0.998 0.000 1.000
#> GSM528702     2  0.0000      0.998 0.000 1.000
#> GSM528703     2  0.0000      0.998 0.000 1.000
#> GSM528704     2  0.0000      0.998 0.000 1.000
#> GSM528707     2  0.0000      0.998 0.000 1.000
#> GSM528708     2  0.0000      0.998 0.000 1.000
#> GSM528705     2  0.0000      0.998 0.000 1.000
#> GSM528706     2  0.0000      0.998 0.000 1.000
#> GSM528713     1  0.0000      0.998 1.000 0.000
#> GSM528714     1  0.0000      0.998 1.000 0.000
#> GSM528715     1  0.0000      0.998 1.000 0.000
#> GSM528716     1  0.0000      0.998 1.000 0.000
#> GSM528717     1  0.0000      0.998 1.000 0.000
#> GSM528718     1  0.0000      0.998 1.000 0.000
#> GSM528719     1  0.0000      0.998 1.000 0.000
#> GSM528720     1  0.0000      0.998 1.000 0.000
#> GSM528709     1  0.0000      0.998 1.000 0.000
#> GSM528710     1  0.0000      0.998 1.000 0.000
#> GSM528711     1  0.0000      0.998 1.000 0.000
#> GSM528712     1  0.0000      0.998 1.000 0.000
#> GSM528721     2  0.0000      0.998 0.000 1.000
#> GSM528722     2  0.0000      0.998 0.000 1.000
#> GSM528723     2  0.0000      0.998 0.000 1.000
#> GSM528724     2  0.0000      0.998 0.000 1.000
#> GSM528727     2  0.0000      0.998 0.000 1.000
#> GSM528728     2  0.0000      0.998 0.000 1.000
#> GSM528725     2  0.0000      0.998 0.000 1.000
#> GSM528726     2  0.0000      0.998 0.000 1.000
#> GSM528733     1  0.0000      0.998 1.000 0.000
#> GSM528734     1  0.0000      0.998 1.000 0.000
#> GSM528735     1  0.0000      0.998 1.000 0.000
#> GSM528736     1  0.0000      0.998 1.000 0.000
#> GSM528737     1  0.0000      0.998 1.000 0.000
#> GSM528738     1  0.0000      0.998 1.000 0.000
#> GSM528729     1  0.0000      0.998 1.000 0.000
#> GSM528730     1  0.0000      0.998 1.000 0.000
#> GSM528731     1  0.0000      0.998 1.000 0.000
#> GSM528732     1  0.0000      0.998 1.000 0.000
#> GSM528739     2  0.0000      0.998 0.000 1.000
#> GSM528740     2  0.0000      0.998 0.000 1.000
#> GSM528741     2  0.0000      0.998 0.000 1.000
#> GSM528742     2  0.0000      0.998 0.000 1.000
#> GSM528745     2  0.0000      0.998 0.000 1.000
#> GSM528746     2  0.0000      0.998 0.000 1.000
#> GSM528743     2  0.0000      0.998 0.000 1.000
#> GSM528744     2  0.0000      0.998 0.000 1.000
#> GSM528751     1  0.0000      0.998 1.000 0.000
#> GSM528752     1  0.0000      0.998 1.000 0.000
#> GSM528753     1  0.0000      0.998 1.000 0.000
#> GSM528754     1  0.0000      0.998 1.000 0.000
#> GSM528755     1  0.0000      0.998 1.000 0.000
#> GSM528756     1  0.0000      0.998 1.000 0.000
#> GSM528757     1  0.0000      0.998 1.000 0.000
#> GSM528758     1  0.0000      0.998 1.000 0.000
#> GSM528747     1  0.0000      0.998 1.000 0.000
#> GSM528748     1  0.0000      0.998 1.000 0.000
#> GSM528749     1  0.0000      0.998 1.000 0.000
#> GSM528750     1  0.0000      0.998 1.000 0.000
#> GSM528640     2  0.0000      0.998 0.000 1.000
#> GSM528641     2  0.0000      0.998 0.000 1.000
#> GSM528643     1  0.0000      0.998 1.000 0.000
#> GSM528644     1  0.0000      0.998 1.000 0.000
#> GSM528642     1  0.0000      0.998 1.000 0.000
#> GSM528620     2  0.0000      0.998 0.000 1.000
#> GSM528621     2  0.4939      0.878 0.108 0.892
#> GSM528623     1  0.0000      0.998 1.000 0.000
#> GSM528624     1  0.0000      0.998 1.000 0.000
#> GSM528622     1  0.0000      0.998 1.000 0.000
#> GSM528625     2  0.0000      0.998 0.000 1.000
#> GSM528626     2  0.0000      0.998 0.000 1.000
#> GSM528628     1  0.0000      0.998 1.000 0.000
#> GSM528629     1  0.0000      0.998 1.000 0.000
#> GSM528627     1  0.0000      0.998 1.000 0.000
#> GSM528630     2  0.0000      0.998 0.000 1.000
#> GSM528631     2  0.0000      0.998 0.000 1.000
#> GSM528632     2  0.0000      0.998 0.000 1.000
#> GSM528633     2  0.0000      0.998 0.000 1.000
#> GSM528636     1  0.0000      0.998 1.000 0.000
#> GSM528637     1  0.0000      0.998 1.000 0.000
#> GSM528638     1  0.0000      0.998 1.000 0.000
#> GSM528639     1  0.0000      0.998 1.000 0.000
#> GSM528634     1  0.0000      0.998 1.000 0.000
#> GSM528635     1  0.0000      0.998 1.000 0.000
#> GSM528645     1  0.0000      0.998 1.000 0.000
#> GSM528646     1  0.0000      0.998 1.000 0.000
#> GSM528647     1  0.0000      0.998 1.000 0.000
#> GSM528648     1  0.0000      0.998 1.000 0.000
#> GSM528649     1  0.0000      0.998 1.000 0.000
#> GSM528650     1  0.0000      0.998 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-ATC-pam-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-ATC-pam-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-ATC-pam-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-ATC-pam-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk ATC-pam-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-ATC-pam-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk ATC-pam-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>           n agent(p) dose(p)  time(p) k
#> ATC:pam 169   0.9069   1.000 1.43e-29 2
#> ATC:pam 159   0.8520   0.980 8.38e-51 3
#> ATC:pam 162   0.9064   0.855 9.21e-73 4
#> ATC:pam 158   0.0632   0.154 2.35e-74 5
#> ATC:pam 139   0.0229   0.166 2.87e-65 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


ATC:mclust**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["ATC", "mclust"]
# you can also extract it by
# res = res_list["ATC:mclust"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'ATC' method.
#>   Subgroups are detected by 'mclust' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk ATC-mclust-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk ATC-mclust-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           0.976       0.988         0.5012 0.497   0.497
#> 3 3 1.000           0.973       0.986         0.1928 0.899   0.800
#> 4 4 0.856           0.894       0.933         0.1086 0.931   0.831
#> 5 5 0.761           0.847       0.880         0.1084 0.938   0.820
#> 6 6 0.839           0.806       0.905         0.0962 0.896   0.644

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3
#> attr(,"optional")
#> [1] 2

There is also optional best \(k\) = 2 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2  0.0000      0.979 0.000 1.000
#> GSM528682     2  0.0000      0.979 0.000 1.000
#> GSM528683     2  0.0000      0.979 0.000 1.000
#> GSM528684     2  0.0000      0.979 0.000 1.000
#> GSM528687     2  0.0000      0.979 0.000 1.000
#> GSM528688     2  0.0000      0.979 0.000 1.000
#> GSM528685     2  0.0376      0.977 0.004 0.996
#> GSM528686     2  0.0376      0.977 0.004 0.996
#> GSM528693     1  0.0000      0.996 1.000 0.000
#> GSM528694     1  0.0000      0.996 1.000 0.000
#> GSM528695     2  0.3274      0.947 0.060 0.940
#> GSM528696     2  0.3274      0.947 0.060 0.940
#> GSM528697     1  0.0000      0.996 1.000 0.000
#> GSM528698     1  0.0000      0.996 1.000 0.000
#> GSM528699     1  0.0000      0.996 1.000 0.000
#> GSM528700     1  0.0000      0.996 1.000 0.000
#> GSM528689     1  0.0000      0.996 1.000 0.000
#> GSM528690     1  0.0000      0.996 1.000 0.000
#> GSM528691     1  0.0000      0.996 1.000 0.000
#> GSM528692     1  0.0000      0.996 1.000 0.000
#> GSM528779     2  0.0000      0.979 0.000 1.000
#> GSM528780     2  0.0000      0.979 0.000 1.000
#> GSM528782     2  0.0000      0.979 0.000 1.000
#> GSM528781     2  0.0376      0.977 0.004 0.996
#> GSM528785     1  0.0000      0.996 1.000 0.000
#> GSM528786     2  0.3274      0.947 0.060 0.940
#> GSM528787     1  0.0000      0.996 1.000 0.000
#> GSM528788     1  0.0000      0.996 1.000 0.000
#> GSM528783     1  0.0000      0.996 1.000 0.000
#> GSM528784     1  0.0000      0.996 1.000 0.000
#> GSM528759     1  0.0000      0.996 1.000 0.000
#> GSM528760     1  0.0000      0.996 1.000 0.000
#> GSM528761     2  0.0000      0.979 0.000 1.000
#> GSM528762     2  0.0000      0.979 0.000 1.000
#> GSM528765     2  0.0000      0.979 0.000 1.000
#> GSM528766     2  0.0000      0.979 0.000 1.000
#> GSM528763     2  0.0000      0.979 0.000 1.000
#> GSM528764     2  0.0376      0.977 0.004 0.996
#> GSM528771     1  0.0000      0.996 1.000 0.000
#> GSM528772     1  0.0000      0.996 1.000 0.000
#> GSM528773     2  0.3274      0.947 0.060 0.940
#> GSM528774     2  0.3274      0.947 0.060 0.940
#> GSM528775     1  0.0000      0.996 1.000 0.000
#> GSM528776     1  0.0000      0.996 1.000 0.000
#> GSM528777     1  0.0000      0.996 1.000 0.000
#> GSM528778     1  0.0000      0.996 1.000 0.000
#> GSM528767     1  0.0000      0.996 1.000 0.000
#> GSM528768     1  0.0000      0.996 1.000 0.000
#> GSM528769     1  0.0000      0.996 1.000 0.000
#> GSM528770     1  0.0000      0.996 1.000 0.000
#> GSM528671     2  0.0000      0.979 0.000 1.000
#> GSM528672     2  0.0000      0.979 0.000 1.000
#> GSM528674     2  0.0000      0.979 0.000 1.000
#> GSM528673     2  0.0376      0.977 0.004 0.996
#> GSM528677     1  0.0000      0.996 1.000 0.000
#> GSM528678     1  0.6973      0.761 0.812 0.188
#> GSM528679     1  0.0000      0.996 1.000 0.000
#> GSM528680     1  0.0000      0.996 1.000 0.000
#> GSM528675     1  0.0000      0.996 1.000 0.000
#> GSM528676     1  0.0000      0.996 1.000 0.000
#> GSM528651     2  0.0000      0.979 0.000 1.000
#> GSM528652     2  0.0000      0.979 0.000 1.000
#> GSM528653     2  0.0000      0.979 0.000 1.000
#> GSM528654     2  0.0000      0.979 0.000 1.000
#> GSM528657     2  0.0000      0.979 0.000 1.000
#> GSM528658     2  0.0000      0.979 0.000 1.000
#> GSM528655     2  0.0376      0.977 0.004 0.996
#> GSM528656     2  0.0376      0.977 0.004 0.996
#> GSM528663     1  0.0000      0.996 1.000 0.000
#> GSM528664     1  0.0000      0.996 1.000 0.000
#> GSM528665     2  0.3274      0.947 0.060 0.940
#> GSM528666     2  0.3274      0.947 0.060 0.940
#> GSM528667     1  0.0000      0.996 1.000 0.000
#> GSM528668     1  0.0000      0.996 1.000 0.000
#> GSM528669     1  0.0000      0.996 1.000 0.000
#> GSM528670     1  0.0000      0.996 1.000 0.000
#> GSM528659     1  0.0000      0.996 1.000 0.000
#> GSM528660     1  0.0000      0.996 1.000 0.000
#> GSM528661     1  0.0000      0.996 1.000 0.000
#> GSM528662     1  0.0000      0.996 1.000 0.000
#> GSM528701     2  0.0000      0.979 0.000 1.000
#> GSM528702     2  0.0000      0.979 0.000 1.000
#> GSM528703     2  0.0000      0.979 0.000 1.000
#> GSM528704     2  0.0000      0.979 0.000 1.000
#> GSM528707     2  0.0000      0.979 0.000 1.000
#> GSM528708     2  0.0000      0.979 0.000 1.000
#> GSM528705     2  0.0000      0.979 0.000 1.000
#> GSM528706     2  0.0000      0.979 0.000 1.000
#> GSM528713     1  0.0000      0.996 1.000 0.000
#> GSM528714     1  0.0000      0.996 1.000 0.000
#> GSM528715     2  0.3274      0.947 0.060 0.940
#> GSM528716     2  0.3274      0.947 0.060 0.940
#> GSM528717     1  0.0000      0.996 1.000 0.000
#> GSM528718     1  0.0000      0.996 1.000 0.000
#> GSM528719     1  0.0000      0.996 1.000 0.000
#> GSM528720     1  0.0000      0.996 1.000 0.000
#> GSM528709     1  0.0000      0.996 1.000 0.000
#> GSM528710     1  0.0000      0.996 1.000 0.000
#> GSM528711     1  0.0000      0.996 1.000 0.000
#> GSM528712     1  0.0000      0.996 1.000 0.000
#> GSM528721     2  0.0000      0.979 0.000 1.000
#> GSM528722     2  0.0000      0.979 0.000 1.000
#> GSM528723     2  0.0000      0.979 0.000 1.000
#> GSM528724     2  0.0000      0.979 0.000 1.000
#> GSM528727     2  0.0000      0.979 0.000 1.000
#> GSM528728     2  0.0000      0.979 0.000 1.000
#> GSM528725     2  0.0000      0.979 0.000 1.000
#> GSM528726     2  0.0000      0.979 0.000 1.000
#> GSM528733     2  0.3274      0.947 0.060 0.940
#> GSM528734     2  0.3274      0.947 0.060 0.940
#> GSM528735     1  0.0000      0.996 1.000 0.000
#> GSM528736     1  0.0000      0.996 1.000 0.000
#> GSM528737     1  0.0000      0.996 1.000 0.000
#> GSM528738     1  0.0000      0.996 1.000 0.000
#> GSM528729     1  0.0000      0.996 1.000 0.000
#> GSM528730     1  0.0000      0.996 1.000 0.000
#> GSM528731     1  0.0000      0.996 1.000 0.000
#> GSM528732     1  0.0000      0.996 1.000 0.000
#> GSM528739     2  0.0000      0.979 0.000 1.000
#> GSM528740     2  0.0000      0.979 0.000 1.000
#> GSM528741     2  0.0000      0.979 0.000 1.000
#> GSM528742     2  0.0000      0.979 0.000 1.000
#> GSM528745     2  0.0000      0.979 0.000 1.000
#> GSM528746     2  0.0000      0.979 0.000 1.000
#> GSM528743     2  0.0000      0.979 0.000 1.000
#> GSM528744     2  0.0000      0.979 0.000 1.000
#> GSM528751     1  0.0000      0.996 1.000 0.000
#> GSM528752     1  0.0000      0.996 1.000 0.000
#> GSM528753     2  0.3274      0.947 0.060 0.940
#> GSM528754     2  0.3274      0.947 0.060 0.940
#> GSM528755     1  0.0000      0.996 1.000 0.000
#> GSM528756     1  0.0000      0.996 1.000 0.000
#> GSM528757     1  0.0000      0.996 1.000 0.000
#> GSM528758     1  0.0000      0.996 1.000 0.000
#> GSM528747     1  0.0000      0.996 1.000 0.000
#> GSM528748     1  0.0000      0.996 1.000 0.000
#> GSM528749     1  0.0000      0.996 1.000 0.000
#> GSM528750     1  0.0000      0.996 1.000 0.000
#> GSM528640     2  0.0000      0.979 0.000 1.000
#> GSM528641     2  0.0376      0.977 0.004 0.996
#> GSM528643     2  0.3274      0.947 0.060 0.940
#> GSM528644     1  0.0000      0.996 1.000 0.000
#> GSM528642     1  0.0000      0.996 1.000 0.000
#> GSM528620     2  0.0000      0.979 0.000 1.000
#> GSM528621     2  0.9988      0.116 0.480 0.520
#> GSM528623     2  0.3274      0.947 0.060 0.940
#> GSM528624     1  0.0000      0.996 1.000 0.000
#> GSM528622     1  0.0000      0.996 1.000 0.000
#> GSM528625     2  0.0000      0.979 0.000 1.000
#> GSM528626     2  0.0376      0.977 0.004 0.996
#> GSM528628     2  0.3274      0.947 0.060 0.940
#> GSM528629     1  0.0000      0.996 1.000 0.000
#> GSM528627     1  0.0000      0.996 1.000 0.000
#> GSM528630     2  0.0000      0.979 0.000 1.000
#> GSM528631     2  0.0376      0.977 0.004 0.996
#> GSM528632     2  0.2423      0.959 0.040 0.960
#> GSM528633     2  0.0672      0.976 0.008 0.992
#> GSM528636     2  0.3274      0.947 0.060 0.940
#> GSM528637     2  0.3274      0.947 0.060 0.940
#> GSM528638     1  0.0000      0.996 1.000 0.000
#> GSM528639     1  0.0000      0.996 1.000 0.000
#> GSM528634     1  0.0000      0.996 1.000 0.000
#> GSM528635     1  0.0000      0.996 1.000 0.000
#> GSM528645     2  0.3274      0.947 0.060 0.940
#> GSM528646     2  0.3274      0.947 0.060 0.940
#> GSM528647     1  0.5629      0.843 0.868 0.132
#> GSM528648     1  0.0000      0.996 1.000 0.000
#> GSM528649     1  0.0000      0.996 1.000 0.000
#> GSM528650     1  0.0000      0.996 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-ATC-mclust-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-ATC-mclust-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)
#> Error in mat[ceiling(1:nr/h_ratio), ceiling(1:nc/w_ratio), drop = FALSE]: subscript out of bounds

plot of chunk tab-ATC-mclust-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)
#> Error in mat[ceiling(1:nr/h_ratio), ceiling(1:nc/w_ratio), drop = FALSE]: subscript out of bounds

plot of chunk tab-ATC-mclust-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk ATC-mclust-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-ATC-mclust-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk ATC-mclust-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>              n agent(p) dose(p)  time(p) k
#> ATC:mclust 168    0.986   0.976 1.43e-27 2
#> ATC:mclust 169    0.973   0.992 3.35e-52 3
#> ATC:mclust 167    0.971   0.988 7.41e-70 4
#> ATC:mclust 166    0.610   0.539 3.89e-77 5
#> ATC:mclust 153    0.441   0.411 1.46e-73 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


ATC:NMF**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["ATC", "NMF"]
# you can also extract it by
# res = res_list["ATC:NMF"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 21163 rows and 169 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'ATC' method.
#>   Subgroups are detected by 'NMF' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk ATC-NMF-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk ATC-NMF-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           0.998       0.999         0.4743 0.527   0.527
#> 3 3 0.953           0.936       0.971         0.4080 0.775   0.584
#> 4 4 0.851           0.848       0.913         0.0875 0.898   0.711
#> 5 5 0.771           0.719       0.845         0.0614 0.909   0.690
#> 6 6 0.773           0.675       0.797         0.0307 0.958   0.823

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3
#> attr(,"optional")
#> [1] 2

There is also optional best \(k\) = 2 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM528681     2  0.0000      1.000 0.000 1.000
#> GSM528682     2  0.0000      1.000 0.000 1.000
#> GSM528683     2  0.0000      1.000 0.000 1.000
#> GSM528684     2  0.0000      1.000 0.000 1.000
#> GSM528687     2  0.0000      1.000 0.000 1.000
#> GSM528688     2  0.0000      1.000 0.000 1.000
#> GSM528685     2  0.0000      1.000 0.000 1.000
#> GSM528686     2  0.0000      1.000 0.000 1.000
#> GSM528693     1  0.0000      0.999 1.000 0.000
#> GSM528694     1  0.0000      0.999 1.000 0.000
#> GSM528695     1  0.0000      0.999 1.000 0.000
#> GSM528696     1  0.0000      0.999 1.000 0.000
#> GSM528697     1  0.0000      0.999 1.000 0.000
#> GSM528698     1  0.0000      0.999 1.000 0.000
#> GSM528699     1  0.0000      0.999 1.000 0.000
#> GSM528700     1  0.0000      0.999 1.000 0.000
#> GSM528689     1  0.0000      0.999 1.000 0.000
#> GSM528690     1  0.0000      0.999 1.000 0.000
#> GSM528691     1  0.0000      0.999 1.000 0.000
#> GSM528692     1  0.0000      0.999 1.000 0.000
#> GSM528779     2  0.0000      1.000 0.000 1.000
#> GSM528780     2  0.0000      1.000 0.000 1.000
#> GSM528782     2  0.0000      1.000 0.000 1.000
#> GSM528781     2  0.0000      1.000 0.000 1.000
#> GSM528785     1  0.0000      0.999 1.000 0.000
#> GSM528786     1  0.0000      0.999 1.000 0.000
#> GSM528787     1  0.0000      0.999 1.000 0.000
#> GSM528788     1  0.0000      0.999 1.000 0.000
#> GSM528783     1  0.0000      0.999 1.000 0.000
#> GSM528784     1  0.0000      0.999 1.000 0.000
#> GSM528759     1  0.0000      0.999 1.000 0.000
#> GSM528760     1  0.0000      0.999 1.000 0.000
#> GSM528761     2  0.0000      1.000 0.000 1.000
#> GSM528762     2  0.0000      1.000 0.000 1.000
#> GSM528765     2  0.0000      1.000 0.000 1.000
#> GSM528766     2  0.0000      1.000 0.000 1.000
#> GSM528763     2  0.0000      1.000 0.000 1.000
#> GSM528764     2  0.0000      1.000 0.000 1.000
#> GSM528771     1  0.0000      0.999 1.000 0.000
#> GSM528772     1  0.0000      0.999 1.000 0.000
#> GSM528773     1  0.0000      0.999 1.000 0.000
#> GSM528774     1  0.0000      0.999 1.000 0.000
#> GSM528775     1  0.0000      0.999 1.000 0.000
#> GSM528776     1  0.0000      0.999 1.000 0.000
#> GSM528777     1  0.0000      0.999 1.000 0.000
#> GSM528778     1  0.0000      0.999 1.000 0.000
#> GSM528767     1  0.0000      0.999 1.000 0.000
#> GSM528768     1  0.0000      0.999 1.000 0.000
#> GSM528769     1  0.0000      0.999 1.000 0.000
#> GSM528770     1  0.0000      0.999 1.000 0.000
#> GSM528671     2  0.0000      1.000 0.000 1.000
#> GSM528672     2  0.0000      1.000 0.000 1.000
#> GSM528674     2  0.0000      1.000 0.000 1.000
#> GSM528673     2  0.0000      1.000 0.000 1.000
#> GSM528677     1  0.0000      0.999 1.000 0.000
#> GSM528678     1  0.0000      0.999 1.000 0.000
#> GSM528679     1  0.0000      0.999 1.000 0.000
#> GSM528680     1  0.0000      0.999 1.000 0.000
#> GSM528675     1  0.0000      0.999 1.000 0.000
#> GSM528676     1  0.0000      0.999 1.000 0.000
#> GSM528651     2  0.0000      1.000 0.000 1.000
#> GSM528652     2  0.0000      1.000 0.000 1.000
#> GSM528653     2  0.0000      1.000 0.000 1.000
#> GSM528654     2  0.0000      1.000 0.000 1.000
#> GSM528657     2  0.0000      1.000 0.000 1.000
#> GSM528658     2  0.0000      1.000 0.000 1.000
#> GSM528655     2  0.0000      1.000 0.000 1.000
#> GSM528656     2  0.0000      1.000 0.000 1.000
#> GSM528663     1  0.0672      0.991 0.992 0.008
#> GSM528664     1  0.5178      0.869 0.884 0.116
#> GSM528665     1  0.0000      0.999 1.000 0.000
#> GSM528666     1  0.0000      0.999 1.000 0.000
#> GSM528667     1  0.0000      0.999 1.000 0.000
#> GSM528668     1  0.0000      0.999 1.000 0.000
#> GSM528669     1  0.0000      0.999 1.000 0.000
#> GSM528670     1  0.0000      0.999 1.000 0.000
#> GSM528659     1  0.0000      0.999 1.000 0.000
#> GSM528660     1  0.0000      0.999 1.000 0.000
#> GSM528661     1  0.0000      0.999 1.000 0.000
#> GSM528662     1  0.0000      0.999 1.000 0.000
#> GSM528701     2  0.0000      1.000 0.000 1.000
#> GSM528702     2  0.0000      1.000 0.000 1.000
#> GSM528703     2  0.0000      1.000 0.000 1.000
#> GSM528704     2  0.0000      1.000 0.000 1.000
#> GSM528707     2  0.0000      1.000 0.000 1.000
#> GSM528708     2  0.0000      1.000 0.000 1.000
#> GSM528705     2  0.0000      1.000 0.000 1.000
#> GSM528706     2  0.0000      1.000 0.000 1.000
#> GSM528713     1  0.0000      0.999 1.000 0.000
#> GSM528714     1  0.0000      0.999 1.000 0.000
#> GSM528715     1  0.0000      0.999 1.000 0.000
#> GSM528716     1  0.0000      0.999 1.000 0.000
#> GSM528717     1  0.0000      0.999 1.000 0.000
#> GSM528718     1  0.0000      0.999 1.000 0.000
#> GSM528719     1  0.0000      0.999 1.000 0.000
#> GSM528720     1  0.0000      0.999 1.000 0.000
#> GSM528709     1  0.0000      0.999 1.000 0.000
#> GSM528710     1  0.0000      0.999 1.000 0.000
#> GSM528711     1  0.0000      0.999 1.000 0.000
#> GSM528712     1  0.0000      0.999 1.000 0.000
#> GSM528721     2  0.0000      1.000 0.000 1.000
#> GSM528722     2  0.0000      1.000 0.000 1.000
#> GSM528723     2  0.0000      1.000 0.000 1.000
#> GSM528724     2  0.0000      1.000 0.000 1.000
#> GSM528727     2  0.0000      1.000 0.000 1.000
#> GSM528728     2  0.0000      1.000 0.000 1.000
#> GSM528725     2  0.0000      1.000 0.000 1.000
#> GSM528726     2  0.0000      1.000 0.000 1.000
#> GSM528733     1  0.0000      0.999 1.000 0.000
#> GSM528734     1  0.0000      0.999 1.000 0.000
#> GSM528735     1  0.0000      0.999 1.000 0.000
#> GSM528736     1  0.0000      0.999 1.000 0.000
#> GSM528737     1  0.0000      0.999 1.000 0.000
#> GSM528738     1  0.0000      0.999 1.000 0.000
#> GSM528729     1  0.0000      0.999 1.000 0.000
#> GSM528730     1  0.0000      0.999 1.000 0.000
#> GSM528731     1  0.0000      0.999 1.000 0.000
#> GSM528732     1  0.0000      0.999 1.000 0.000
#> GSM528739     2  0.0000      1.000 0.000 1.000
#> GSM528740     2  0.0000      1.000 0.000 1.000
#> GSM528741     2  0.0000      1.000 0.000 1.000
#> GSM528742     2  0.0000      1.000 0.000 1.000
#> GSM528745     2  0.0000      1.000 0.000 1.000
#> GSM528746     2  0.0000      1.000 0.000 1.000
#> GSM528743     2  0.0000      1.000 0.000 1.000
#> GSM528744     2  0.0000      1.000 0.000 1.000
#> GSM528751     1  0.0000      0.999 1.000 0.000
#> GSM528752     1  0.0000      0.999 1.000 0.000
#> GSM528753     1  0.0000      0.999 1.000 0.000
#> GSM528754     1  0.0000      0.999 1.000 0.000
#> GSM528755     1  0.0000      0.999 1.000 0.000
#> GSM528756     1  0.0000      0.999 1.000 0.000
#> GSM528757     1  0.0672      0.991 0.992 0.008
#> GSM528758     1  0.0000      0.999 1.000 0.000
#> GSM528747     1  0.0000      0.999 1.000 0.000
#> GSM528748     1  0.0000      0.999 1.000 0.000
#> GSM528749     1  0.0000      0.999 1.000 0.000
#> GSM528750     1  0.0000      0.999 1.000 0.000
#> GSM528640     2  0.0000      1.000 0.000 1.000
#> GSM528641     2  0.0000      1.000 0.000 1.000
#> GSM528643     1  0.0000      0.999 1.000 0.000
#> GSM528644     1  0.0000      0.999 1.000 0.000
#> GSM528642     1  0.0000      0.999 1.000 0.000
#> GSM528620     2  0.0000      1.000 0.000 1.000
#> GSM528621     2  0.0376      0.996 0.004 0.996
#> GSM528623     1  0.0000      0.999 1.000 0.000
#> GSM528624     1  0.0000      0.999 1.000 0.000
#> GSM528622     1  0.0000      0.999 1.000 0.000
#> GSM528625     2  0.0000      1.000 0.000 1.000
#> GSM528626     2  0.0000      1.000 0.000 1.000
#> GSM528628     1  0.0000      0.999 1.000 0.000
#> GSM528629     1  0.0000      0.999 1.000 0.000
#> GSM528627     1  0.0000      0.999 1.000 0.000
#> GSM528630     2  0.0000      1.000 0.000 1.000
#> GSM528631     2  0.0000      1.000 0.000 1.000
#> GSM528632     2  0.0000      1.000 0.000 1.000
#> GSM528633     2  0.0000      1.000 0.000 1.000
#> GSM528636     1  0.0000      0.999 1.000 0.000
#> GSM528637     1  0.0000      0.999 1.000 0.000
#> GSM528638     1  0.0000      0.999 1.000 0.000
#> GSM528639     1  0.0000      0.999 1.000 0.000
#> GSM528634     1  0.0000      0.999 1.000 0.000
#> GSM528635     1  0.0000      0.999 1.000 0.000
#> GSM528645     1  0.0000      0.999 1.000 0.000
#> GSM528646     1  0.0000      0.999 1.000 0.000
#> GSM528647     1  0.0000      0.999 1.000 0.000
#> GSM528648     1  0.0000      0.999 1.000 0.000
#> GSM528649     1  0.0000      0.999 1.000 0.000
#> GSM528650     1  0.0000      0.999 1.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-ATC-NMF-consensus-heatmap-1

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-ATC-NMF-membership-heatmap-1

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-ATC-NMF-get-signatures-1

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-ATC-NMF-get-signatures-no-scale-1

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk ATC-NMF-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-ATC-NMF-dimension-reduction-1

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk ATC-NMF-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>           n agent(p) dose(p)  time(p) k
#> ATC:NMF 169  0.90691 0.99995 1.43e-29 2
#> ATC:NMF 164  0.88842 0.98032 1.06e-43 3
#> ATC:NMF 156  0.55316 0.76601 4.47e-56 4
#> ATC:NMF 143  0.00653 0.00781 1.54e-52 5
#> ATC:NMF 132  0.01291 0.09192 2.49e-58 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.

Session info

sessionInfo()
#> R version 3.6.0 (2019-04-26)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: CentOS Linux 7 (Core)
#> 
#> Matrix products: default
#> BLAS:   /usr/lib64/libblas.so.3.4.2
#> LAPACK: /usr/lib64/liblapack.so.3.4.2
#> 
#> locale:
#>  [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB.UTF-8       
#>  [4] LC_COLLATE=en_GB.UTF-8     LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
#>  [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
#> [10] LC_TELEPHONE=C             LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] grid      stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] genefilter_1.66.0    ComplexHeatmap_2.3.1 markdown_1.1         knitr_1.26          
#> [5] GetoptLong_0.1.7     cola_1.3.2          
#> 
#> loaded via a namespace (and not attached):
#>  [1] circlize_0.4.8       shape_1.4.4          xfun_0.11            slam_0.1-46         
#>  [5] lattice_0.20-38      splines_3.6.0        colorspace_1.4-1     vctrs_0.2.0         
#>  [9] stats4_3.6.0         blob_1.2.0           XML_3.98-1.20        survival_2.44-1.1   
#> [13] rlang_0.4.2          pillar_1.4.2         DBI_1.0.0            BiocGenerics_0.30.0 
#> [17] bit64_0.9-7          RColorBrewer_1.1-2   matrixStats_0.55.0   stringr_1.4.0       
#> [21] GlobalOptions_0.1.1  evaluate_0.14        memoise_1.1.0        Biobase_2.44.0      
#> [25] IRanges_2.18.3       parallel_3.6.0       AnnotationDbi_1.46.1 highr_0.8           
#> [29] Rcpp_1.0.3           xtable_1.8-4         backports_1.1.5      S4Vectors_0.22.1    
#> [33] annotate_1.62.0      skmeans_0.2-11       bit_1.1-14           microbenchmark_1.4-7
#> [37] brew_1.0-6           impute_1.58.0        rjson_0.2.20         png_0.1-7           
#> [41] digest_0.6.23        stringi_1.4.3        polyclip_1.10-0      clue_0.3-57         
#> [45] tools_3.6.0          bitops_1.0-6         magrittr_1.5         eulerr_6.0.0        
#> [49] RCurl_1.95-4.12      RSQLite_2.1.4        tibble_2.1.3         cluster_2.1.0       
#> [53] crayon_1.3.4         pkgconfig_2.0.3      zeallot_0.1.0        Matrix_1.2-17       
#> [57] xml2_1.2.2           httr_1.4.1           R6_2.4.1             mclust_5.4.5        
#> [61] compiler_3.6.0