cola Report for MCF10CA_scRNAseq

Date: 2019-12-26 18:30:06 CET, cola version: 1.3.2


Summary

First the variable is renamed to res_list.

res_list = rl

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

res_list
#> A 'ConsensusPartitionList' object with 24 methods.
#>   On a matrix with 5576 rows and 160 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 = m, mc.cores = 4, anno = data.frame(cell_type = cell_type), 
#>     anno_col = list(cell_type = cell_col))

Dimension of the input matrix:

mat = get_matrix(res_list)
dim(mat)
#> [1] 5576  160

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:mclust 2 1.000 0.988 0.995 **
SD:NMF 2 1.000 0.975 0.989 **
CV:mclust 2 1.000 0.988 0.995 **
MAD:mclust 2 1.000 0.988 0.995 **
MAD:NMF 2 1.000 0.983 0.993 **
ATC:kmeans 2 1.000 0.987 0.982 **
ATC:NMF 2 1.000 0.976 0.990 **
CV:NMF 2 0.961 0.950 0.979 **
ATC:mclust 3 0.931 0.926 0.968 * 2
ATC:skmeans 4 0.927 0.895 0.958 * 2,3
SD:skmeans 2 0.886 0.924 0.967
MAD:skmeans 2 0.877 0.926 0.970
CV:skmeans 2 0.875 0.936 0.970
ATC:pam 4 0.869 0.869 0.949
SD:kmeans 2 0.861 0.900 0.958
CV:kmeans 2 0.856 0.927 0.968
MAD:kmeans 2 0.829 0.932 0.970
ATC:hclust 5 0.768 0.775 0.880
SD:hclust 3 0.379 0.743 0.852
MAD:pam 3 0.367 0.607 0.844
SD:pam 3 0.324 0.781 0.845
MAD:hclust 3 0.300 0.693 0.825
CV:hclust 2 0.222 0.648 0.824
CV:pam 3 0.192 0.462 0.705

**: 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.975       0.989          0.501 0.500   0.500
#> CV:NMF      2 0.961           0.950       0.979          0.501 0.498   0.498
#> MAD:NMF     2 1.000           0.983       0.993          0.503 0.498   0.498
#> ATC:NMF     2 1.000           0.976       0.990          0.501 0.499   0.499
#> SD:skmeans  2 0.886           0.924       0.967          0.503 0.498   0.498
#> CV:skmeans  2 0.875           0.936       0.971          0.503 0.497   0.497
#> MAD:skmeans 2 0.877           0.926       0.970          0.503 0.498   0.498
#> ATC:skmeans 2 1.000           0.983       0.992          0.503 0.498   0.498
#> SD:mclust   2 1.000           0.988       0.995          0.504 0.497   0.497
#> CV:mclust   2 1.000           0.988       0.995          0.503 0.497   0.497
#> MAD:mclust  2 1.000           0.988       0.995          0.503 0.497   0.497
#> ATC:mclust  2 0.999           0.981       0.992          0.503 0.497   0.497
#> SD:kmeans   2 0.861           0.900       0.958          0.500 0.498   0.498
#> CV:kmeans   2 0.856           0.927       0.968          0.502 0.498   0.498
#> MAD:kmeans  2 0.829           0.932       0.970          0.501 0.500   0.500
#> ATC:kmeans  2 1.000           0.987       0.982          0.491 0.498   0.498
#> SD:pam      2 0.401           0.798       0.863          0.231 0.904   0.904
#> CV:pam      2 0.314           0.721       0.863          0.291 0.771   0.771
#> MAD:pam     2 0.703           0.911       0.945          0.148 0.904   0.904
#> ATC:pam     2 0.556           0.869       0.927          0.479 0.502   0.502
#> SD:hclust   2 0.279           0.656       0.807          0.348 0.554   0.554
#> CV:hclust   2 0.222           0.648       0.824          0.462 0.497   0.497
#> MAD:hclust  2 0.204           0.459       0.770          0.298 0.718   0.718
#> ATC:hclust  2 0.424           0.654       0.828          0.277 0.916   0.916

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 = 558, 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 = 558, method = "correspondance")

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

Heatmaps of the top rows:

top_rows_heatmap(res_list, top_n = 558)

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 cell_type(p) k
#> SD:NMF      159     1.02e-26 2
#> CV:NMF      156     2.05e-28 2
#> MAD:NMF     159     2.51e-28 2
#> ATC:NMF     159     4.69e-29 2
#> SD:skmeans  158     4.65e-19 2
#> CV:skmeans  156     2.86e-21 2
#> MAD:skmeans 155     3.94e-19 2
#> ATC:skmeans 160     4.49e-20 2
#> SD:mclust   160     7.97e-29 2
#> CV:mclust   160     5.69e-31 2
#> MAD:mclust  160     3.08e-30 2
#> ATC:mclust  159     5.02e-30 2
#> SD:kmeans   155     1.04e-19 2
#> CV:kmeans   155     4.72e-21 2
#> MAD:kmeans  157     1.66e-17 2
#> ATC:kmeans  160     4.49e-20 2
#> SD:pam      160     2.38e-02 2
#> CV:pam      143     9.46e-02 2
#> MAD:pam     158     2.40e-02 2
#> ATC:pam     152     6.61e-24 2
#> SD:hclust   138     2.76e-14 2
#> CV:hclust   125     5.51e-11 2
#> MAD:hclust   99     7.49e-07 2
#> ATC:hclust  120     1.74e-01 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 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 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.279           0.656       0.807         0.3475 0.554   0.554
#> 3 3 0.379           0.743       0.852         0.3781 0.894   0.818
#> 4 4 0.482           0.700       0.761         0.2786 0.809   0.667
#> 5 5 0.471           0.531       0.679         0.0999 0.831   0.650
#> 6 6 0.508           0.443       0.686         0.0591 0.887   0.723

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
#> aberrant_ERR2585320     2  0.3584     0.8047 0.068 0.932
#> aberrant_ERR2585338     2  0.0672     0.8019 0.008 0.992
#> aberrant_ERR2585325     2  0.3584     0.8047 0.068 0.932
#> aberrant_ERR2585283     1  0.2236     0.5120 0.964 0.036
#> aberrant_ERR2585343     2  0.6438     0.7341 0.164 0.836
#> aberrant_ERR2585329     2  0.1633     0.8135 0.024 0.976
#> aberrant_ERR2585317     2  0.0938     0.8047 0.012 0.988
#> aberrant_ERR2585339     2  0.0000     0.8066 0.000 1.000
#> aberrant_ERR2585335     2  0.2236     0.8138 0.036 0.964
#> aberrant_ERR2585287     2  0.9661     0.2956 0.392 0.608
#> aberrant_ERR2585321     2  0.5629     0.7657 0.132 0.868
#> aberrant_ERR2585297     1  0.9635     0.7361 0.612 0.388
#> aberrant_ERR2585337     2  0.0000     0.8066 0.000 1.000
#> aberrant_ERR2585319     2  0.2423     0.8146 0.040 0.960
#> aberrant_ERR2585315     2  0.1414     0.8135 0.020 0.980
#> aberrant_ERR2585336     2  0.0000     0.8066 0.000 1.000
#> aberrant_ERR2585307     2  0.1633     0.8113 0.024 0.976
#> aberrant_ERR2585301     2  0.2236     0.8144 0.036 0.964
#> aberrant_ERR2585326     2  0.0672     0.8019 0.008 0.992
#> aberrant_ERR2585331     2  0.0672     0.8019 0.008 0.992
#> aberrant_ERR2585346     1  0.2236     0.5120 0.964 0.036
#> aberrant_ERR2585314     2  0.2236     0.8152 0.036 0.964
#> aberrant_ERR2585298     2  0.8207     0.4624 0.256 0.744
#> aberrant_ERR2585345     2  0.0938     0.8047 0.012 0.988
#> aberrant_ERR2585299     1  0.9754     0.7286 0.592 0.408
#> aberrant_ERR2585309     1  0.8499     0.7271 0.724 0.276
#> aberrant_ERR2585303     2  0.0938     0.8049 0.012 0.988
#> aberrant_ERR2585313     2  0.1414     0.8130 0.020 0.980
#> aberrant_ERR2585318     2  0.3274     0.8084 0.060 0.940
#> aberrant_ERR2585328     2  0.2778     0.8155 0.048 0.952
#> aberrant_ERR2585330     2  0.3431     0.8078 0.064 0.936
#> aberrant_ERR2585293     1  0.2236     0.5120 0.964 0.036
#> aberrant_ERR2585342     2  0.4298     0.7997 0.088 0.912
#> aberrant_ERR2585348     2  0.3584     0.8086 0.068 0.932
#> aberrant_ERR2585352     2  0.2603     0.8140 0.044 0.956
#> aberrant_ERR2585308     1  0.9044     0.7410 0.680 0.320
#> aberrant_ERR2585349     2  0.2043     0.8023 0.032 0.968
#> aberrant_ERR2585316     2  0.6247     0.7456 0.156 0.844
#> aberrant_ERR2585306     2  0.6887     0.7040 0.184 0.816
#> aberrant_ERR2585324     2  0.2423     0.8146 0.040 0.960
#> aberrant_ERR2585310     2  0.1633     0.8123 0.024 0.976
#> aberrant_ERR2585296     2  0.9933    -0.4104 0.452 0.548
#> aberrant_ERR2585275     1  0.2236     0.5120 0.964 0.036
#> aberrant_ERR2585311     2  0.4161     0.8011 0.084 0.916
#> aberrant_ERR2585292     1  0.2236     0.5120 0.964 0.036
#> aberrant_ERR2585282     2  0.3584     0.8064 0.068 0.932
#> aberrant_ERR2585305     2  0.3274     0.8081 0.060 0.940
#> aberrant_ERR2585278     2  0.0938     0.8110 0.012 0.988
#> aberrant_ERR2585347     2  0.5946     0.7569 0.144 0.856
#> aberrant_ERR2585332     2  0.4815     0.7847 0.104 0.896
#> aberrant_ERR2585280     2  0.4298     0.7986 0.088 0.912
#> aberrant_ERR2585304     2  0.3114     0.7939 0.056 0.944
#> aberrant_ERR2585322     2  0.0376     0.8084 0.004 0.996
#> aberrant_ERR2585279     2  0.0672     0.8019 0.008 0.992
#> aberrant_ERR2585277     2  0.0376     0.8045 0.004 0.996
#> aberrant_ERR2585295     2  0.2778     0.8157 0.048 0.952
#> aberrant_ERR2585333     2  0.4939     0.7881 0.108 0.892
#> aberrant_ERR2585285     2  0.3274     0.8094 0.060 0.940
#> aberrant_ERR2585286     2  0.0672     0.8019 0.008 0.992
#> aberrant_ERR2585294     2  0.2778     0.8143 0.048 0.952
#> aberrant_ERR2585300     2  0.6887     0.7040 0.184 0.816
#> aberrant_ERR2585334     2  0.0672     0.8019 0.008 0.992
#> aberrant_ERR2585361     2  0.3114     0.8127 0.056 0.944
#> aberrant_ERR2585372     2  0.3584     0.8052 0.068 0.932
#> round_ERR2585217        2  0.6438     0.6793 0.164 0.836
#> round_ERR2585205        1  0.9881     0.7050 0.564 0.436
#> round_ERR2585214        2  0.6973     0.6292 0.188 0.812
#> round_ERR2585202        2  0.3733     0.7823 0.072 0.928
#> aberrant_ERR2585367     2  0.3114     0.8127 0.056 0.944
#> round_ERR2585220        1  0.9977     0.6523 0.528 0.472
#> round_ERR2585238        1  0.9491     0.7420 0.632 0.368
#> aberrant_ERR2585276     2  0.3879     0.8046 0.076 0.924
#> round_ERR2585218        1  0.9815     0.7189 0.580 0.420
#> aberrant_ERR2585363     2  0.3114     0.8125 0.056 0.944
#> round_ERR2585201        2  0.8016     0.4950 0.244 0.756
#> round_ERR2585210        1  0.9815     0.7177 0.580 0.420
#> aberrant_ERR2585362     2  0.3114     0.8132 0.056 0.944
#> aberrant_ERR2585360     2  0.4161     0.8004 0.084 0.916
#> round_ERR2585209        2  0.8081     0.4815 0.248 0.752
#> round_ERR2585242        2  0.8144     0.4608 0.252 0.748
#> round_ERR2585216        1  1.0000     0.5920 0.504 0.496
#> round_ERR2585219        1  0.9977     0.6541 0.528 0.472
#> round_ERR2585237        2  0.6973     0.6304 0.188 0.812
#> round_ERR2585198        2  0.3584     0.7857 0.068 0.932
#> round_ERR2585211        1  0.9833     0.7169 0.576 0.424
#> round_ERR2585206        1  0.9850     0.7134 0.572 0.428
#> aberrant_ERR2585281     2  0.1633     0.8104 0.024 0.976
#> round_ERR2585212        1  0.9993     0.6286 0.516 0.484
#> round_ERR2585221        1  0.8955     0.7401 0.688 0.312
#> round_ERR2585243        1  0.9833     0.7178 0.576 0.424
#> round_ERR2585204        2  0.6343     0.6746 0.160 0.840
#> round_ERR2585213        2  0.4431     0.7583 0.092 0.908
#> aberrant_ERR2585373     2  0.4298     0.7981 0.088 0.912
#> aberrant_ERR2585358     2  0.5629     0.7646 0.132 0.868
#> aberrant_ERR2585365     2  0.0672     0.8102 0.008 0.992
#> aberrant_ERR2585359     2  0.6247     0.7399 0.156 0.844
#> aberrant_ERR2585370     2  0.0376     0.8045 0.004 0.996
#> round_ERR2585215        1  0.9087     0.7401 0.676 0.324
#> round_ERR2585262        2  0.6148     0.6855 0.152 0.848
#> round_ERR2585199        2  0.4022     0.7753 0.080 0.920
#> aberrant_ERR2585369     2  0.3114     0.8104 0.056 0.944
#> round_ERR2585208        1  0.9710     0.7320 0.600 0.400
#> round_ERR2585252        1  0.8081     0.7132 0.752 0.248
#> round_ERR2585236        2  0.9922    -0.4086 0.448 0.552
#> aberrant_ERR2585284     1  0.2236     0.5120 0.964 0.036
#> round_ERR2585224        1  0.7815     0.7027 0.768 0.232
#> round_ERR2585260        1  0.9933     0.6838 0.548 0.452
#> round_ERR2585229        1  0.9552     0.7400 0.624 0.376
#> aberrant_ERR2585364     1  0.6623     0.5510 0.828 0.172
#> round_ERR2585253        1  0.7815     0.7027 0.768 0.232
#> aberrant_ERR2585368     2  0.0672     0.8019 0.008 0.992
#> aberrant_ERR2585371     2  0.0672     0.8019 0.008 0.992
#> round_ERR2585239        1  0.9944     0.6793 0.544 0.456
#> round_ERR2585273        1  0.9754     0.7216 0.592 0.408
#> round_ERR2585256        2  0.8443     0.3987 0.272 0.728
#> round_ERR2585272        2  1.0000    -0.5787 0.496 0.504
#> round_ERR2585246        1  0.9129     0.7421 0.672 0.328
#> round_ERR2585261        2  0.8443     0.4107 0.272 0.728
#> round_ERR2585254        2  0.6887     0.6384 0.184 0.816
#> round_ERR2585225        2  0.7950     0.4943 0.240 0.760
#> round_ERR2585235        2  0.9393     0.0403 0.356 0.644
#> round_ERR2585271        1  0.9922     0.6910 0.552 0.448
#> round_ERR2585251        1  0.9977     0.6511 0.528 0.472
#> round_ERR2585255        2  0.7950     0.4930 0.240 0.760
#> round_ERR2585257        2  0.8081     0.4772 0.248 0.752
#> round_ERR2585226        1  0.9983     0.6445 0.524 0.476
#> round_ERR2585265        1  0.9970     0.6591 0.532 0.468
#> round_ERR2585259        2  0.9209     0.1803 0.336 0.664
#> round_ERR2585247        1  0.9286     0.7425 0.656 0.344
#> round_ERR2585241        1  0.9922     0.6905 0.552 0.448
#> round_ERR2585263        2  0.9996    -0.5551 0.488 0.512
#> round_ERR2585264        1  0.7815     0.7027 0.768 0.232
#> round_ERR2585233        2  0.8267     0.4422 0.260 0.740
#> round_ERR2585223        1  0.9954     0.6692 0.540 0.460
#> round_ERR2585234        2  0.6973     0.6268 0.188 0.812
#> round_ERR2585222        1  0.9996     0.6130 0.512 0.488
#> round_ERR2585228        1  0.9944     0.6771 0.544 0.456
#> round_ERR2585248        1  0.7815     0.7027 0.768 0.232
#> round_ERR2585240        2  0.9833    -0.3806 0.424 0.576
#> round_ERR2585270        1  0.9954     0.6706 0.540 0.460
#> round_ERR2585232        2  0.8813     0.2886 0.300 0.700
#> aberrant_ERR2585341     2  0.1414     0.8092 0.020 0.980
#> aberrant_ERR2585355     2  0.0672     0.8019 0.008 0.992
#> round_ERR2585227        1  0.9977     0.6529 0.528 0.472
#> aberrant_ERR2585351     2  0.3274     0.8116 0.060 0.940
#> round_ERR2585269        1  0.8909     0.7390 0.692 0.308
#> aberrant_ERR2585357     2  0.0376     0.8045 0.004 0.996
#> aberrant_ERR2585350     2  0.0000     0.8066 0.000 1.000
#> round_ERR2585250        2  0.9977    -0.4999 0.472 0.528
#> round_ERR2585245        1  0.7815     0.7027 0.768 0.232
#> aberrant_ERR2585353     2  0.3733     0.8082 0.072 0.928
#> round_ERR2585258        1  0.9970     0.6591 0.532 0.468
#> aberrant_ERR2585354     2  0.2778     0.8145 0.048 0.952
#> round_ERR2585249        1  0.8608     0.7313 0.716 0.284
#> round_ERR2585268        2  0.9933    -0.4224 0.452 0.548
#> aberrant_ERR2585356     2  0.6801     0.7131 0.180 0.820
#> round_ERR2585266        2  0.8207     0.4480 0.256 0.744
#> round_ERR2585231        1  0.8207     0.7181 0.744 0.256
#> round_ERR2585230        1  0.9983     0.6343 0.524 0.476
#> round_ERR2585267        1  0.8327     0.7222 0.736 0.264

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 cell_type(p) k
#> SD:hclust 138     2.76e-14 2
#> SD:hclust 143     2.08e-20 3
#> SD:hclust 131     7.71e-25 4
#> SD:hclust  97     4.22e-19 5
#> SD:hclust 107     1.55e-20 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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.861           0.900       0.958         0.4999 0.498   0.498
#> 3 3 0.588           0.677       0.845         0.2507 0.857   0.719
#> 4 4 0.649           0.667       0.809         0.1233 0.773   0.513
#> 5 5 0.686           0.733       0.815         0.0801 0.861   0.599
#> 6 6 0.723           0.628       0.758         0.0481 0.927   0.712

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
#> aberrant_ERR2585320     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585338     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585325     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585283     1  0.9129      0.550 0.672 0.328
#> aberrant_ERR2585343     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585329     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585317     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585339     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585335     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585287     2  0.2236      0.938 0.036 0.964
#> aberrant_ERR2585321     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585297     1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585337     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585319     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585315     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585336     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585307     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585301     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585326     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585331     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585346     1  0.9129      0.550 0.672 0.328
#> aberrant_ERR2585314     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585298     1  0.3114      0.898 0.944 0.056
#> aberrant_ERR2585345     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585299     1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585309     1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585303     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585313     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585318     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585328     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585330     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585293     1  0.8861      0.592 0.696 0.304
#> aberrant_ERR2585342     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585348     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585352     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585308     1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585349     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585316     2  0.1414      0.953 0.020 0.980
#> aberrant_ERR2585306     1  0.9358      0.504 0.648 0.352
#> aberrant_ERR2585324     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585310     2  0.1184      0.958 0.016 0.984
#> aberrant_ERR2585296     1  0.9977      0.108 0.528 0.472
#> aberrant_ERR2585275     1  0.9323      0.512 0.652 0.348
#> aberrant_ERR2585311     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585292     1  0.8861      0.592 0.696 0.304
#> aberrant_ERR2585282     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585305     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585278     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585347     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585332     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585280     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585304     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585322     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585279     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585277     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585295     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585333     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585285     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585286     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585294     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585300     2  0.0376      0.968 0.004 0.996
#> aberrant_ERR2585334     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585361     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585372     2  0.0000      0.971 0.000 1.000
#> round_ERR2585217        2  0.9460      0.418 0.364 0.636
#> round_ERR2585205        1  0.0000      0.936 1.000 0.000
#> round_ERR2585214        2  0.8909      0.542 0.308 0.692
#> round_ERR2585202        2  0.1414      0.954 0.020 0.980
#> aberrant_ERR2585367     2  0.0000      0.971 0.000 1.000
#> round_ERR2585220        1  0.0000      0.936 1.000 0.000
#> round_ERR2585238        1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585276     2  0.0000      0.971 0.000 1.000
#> round_ERR2585218        1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585363     2  0.0000      0.971 0.000 1.000
#> round_ERR2585201        1  0.8555      0.611 0.720 0.280
#> round_ERR2585210        1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585362     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585360     2  0.0000      0.971 0.000 1.000
#> round_ERR2585209        1  0.1414      0.923 0.980 0.020
#> round_ERR2585242        1  0.3114      0.898 0.944 0.056
#> round_ERR2585216        1  0.0000      0.936 1.000 0.000
#> round_ERR2585219        1  0.0000      0.936 1.000 0.000
#> round_ERR2585237        2  0.9170      0.491 0.332 0.668
#> round_ERR2585198        2  0.9000      0.525 0.316 0.684
#> round_ERR2585211        1  0.0000      0.936 1.000 0.000
#> round_ERR2585206        1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585281     2  0.0000      0.971 0.000 1.000
#> round_ERR2585212        1  0.0000      0.936 1.000 0.000
#> round_ERR2585221        1  0.0000      0.936 1.000 0.000
#> round_ERR2585243        1  0.0000      0.936 1.000 0.000
#> round_ERR2585204        2  0.5842      0.818 0.140 0.860
#> round_ERR2585213        2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585373     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585358     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585365     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585359     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585370     2  0.0000      0.971 0.000 1.000
#> round_ERR2585215        1  0.0000      0.936 1.000 0.000
#> round_ERR2585262        2  0.3431      0.911 0.064 0.936
#> round_ERR2585199        2  0.5946      0.813 0.144 0.856
#> aberrant_ERR2585369     2  0.0000      0.971 0.000 1.000
#> round_ERR2585208        1  0.0000      0.936 1.000 0.000
#> round_ERR2585252        1  0.0000      0.936 1.000 0.000
#> round_ERR2585236        1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585284     1  0.9209      0.537 0.664 0.336
#> round_ERR2585224        1  0.0000      0.936 1.000 0.000
#> round_ERR2585260        1  0.0000      0.936 1.000 0.000
#> round_ERR2585229        1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585364     1  0.9248      0.530 0.660 0.340
#> round_ERR2585253        1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585368     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585371     2  0.0000      0.971 0.000 1.000
#> round_ERR2585239        1  0.0000      0.936 1.000 0.000
#> round_ERR2585273        1  0.0000      0.936 1.000 0.000
#> round_ERR2585256        1  0.3114      0.898 0.944 0.056
#> round_ERR2585272        1  0.0000      0.936 1.000 0.000
#> round_ERR2585246        1  0.0000      0.936 1.000 0.000
#> round_ERR2585261        1  0.8081      0.666 0.752 0.248
#> round_ERR2585254        1  0.9983      0.096 0.524 0.476
#> round_ERR2585225        1  0.1843      0.918 0.972 0.028
#> round_ERR2585235        1  0.0000      0.936 1.000 0.000
#> round_ERR2585271        1  0.0000      0.936 1.000 0.000
#> round_ERR2585251        1  0.0000      0.936 1.000 0.000
#> round_ERR2585255        1  0.3114      0.898 0.944 0.056
#> round_ERR2585257        1  0.3114      0.898 0.944 0.056
#> round_ERR2585226        1  0.0000      0.936 1.000 0.000
#> round_ERR2585265        1  0.0000      0.936 1.000 0.000
#> round_ERR2585259        1  0.0000      0.936 1.000 0.000
#> round_ERR2585247        1  0.0000      0.936 1.000 0.000
#> round_ERR2585241        1  0.0000      0.936 1.000 0.000
#> round_ERR2585263        1  0.0000      0.936 1.000 0.000
#> round_ERR2585264        1  0.0000      0.936 1.000 0.000
#> round_ERR2585233        1  0.0000      0.936 1.000 0.000
#> round_ERR2585223        1  0.0000      0.936 1.000 0.000
#> round_ERR2585234        2  0.9608      0.366 0.384 0.616
#> round_ERR2585222        1  0.0000      0.936 1.000 0.000
#> round_ERR2585228        1  0.0000      0.936 1.000 0.000
#> round_ERR2585248        1  0.0000      0.936 1.000 0.000
#> round_ERR2585240        1  0.1633      0.921 0.976 0.024
#> round_ERR2585270        1  0.0000      0.936 1.000 0.000
#> round_ERR2585232        1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585341     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585355     2  0.0000      0.971 0.000 1.000
#> round_ERR2585227        1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585351     2  0.0000      0.971 0.000 1.000
#> round_ERR2585269        1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585357     2  0.0000      0.971 0.000 1.000
#> aberrant_ERR2585350     2  0.0000      0.971 0.000 1.000
#> round_ERR2585250        1  0.0000      0.936 1.000 0.000
#> round_ERR2585245        1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585353     2  0.0000      0.971 0.000 1.000
#> round_ERR2585258        1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585354     2  0.0000      0.971 0.000 1.000
#> round_ERR2585249        1  0.0000      0.936 1.000 0.000
#> round_ERR2585268        1  0.0000      0.936 1.000 0.000
#> aberrant_ERR2585356     2  0.0000      0.971 0.000 1.000
#> round_ERR2585266        1  0.2948      0.901 0.948 0.052
#> round_ERR2585231        1  0.0000      0.936 1.000 0.000
#> round_ERR2585230        1  0.0000      0.936 1.000 0.000
#> round_ERR2585267        1  0.0000      0.936 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-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)

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

Signature heatmaps where rows are not scaled:

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

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 cell_type(p) k
#> SD:kmeans 155     1.04e-19 2
#> SD:kmeans 141     3.28e-20 3
#> SD:kmeans 137     4.66e-24 4
#> SD:kmeans 139     1.29e-23 5
#> SD:kmeans 118     1.38e-20 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 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-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 0.886           0.924       0.967         0.5026 0.498   0.498
#> 3 3 0.825           0.860       0.941         0.3171 0.758   0.551
#> 4 4 0.837           0.846       0.929         0.1181 0.875   0.654
#> 5 5 0.744           0.684       0.822         0.0533 0.962   0.857
#> 6 6 0.681           0.634       0.763         0.0377 0.970   0.876

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
#> aberrant_ERR2585320     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585338     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585325     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585283     1  0.8955      0.578 0.688 0.312
#> aberrant_ERR2585343     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585329     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585317     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585339     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585335     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585287     2  0.2236      0.938 0.036 0.964
#> aberrant_ERR2585321     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585297     1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585337     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585319     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585315     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585336     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585307     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585301     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585326     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585331     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585346     1  0.8955      0.578 0.688 0.312
#> aberrant_ERR2585314     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585298     1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585345     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585299     1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585309     1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585303     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585313     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585318     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585328     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585330     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585293     1  0.7815      0.706 0.768 0.232
#> aberrant_ERR2585342     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585348     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585352     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585308     1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585349     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585316     2  0.2948      0.922 0.052 0.948
#> aberrant_ERR2585306     1  0.9044      0.563 0.680 0.320
#> aberrant_ERR2585324     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585310     2  0.5178      0.857 0.116 0.884
#> aberrant_ERR2585296     1  0.2948      0.914 0.948 0.052
#> aberrant_ERR2585275     1  0.9087      0.555 0.676 0.324
#> aberrant_ERR2585311     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585292     1  0.7815      0.706 0.768 0.232
#> aberrant_ERR2585282     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585305     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585278     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585347     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585332     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585280     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585304     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585322     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585279     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585277     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585295     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585333     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585285     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585286     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585294     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585300     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585334     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585361     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585372     2  0.0000      0.970 0.000 1.000
#> round_ERR2585217        2  0.9732      0.350 0.404 0.596
#> round_ERR2585205        1  0.0000      0.960 1.000 0.000
#> round_ERR2585214        2  0.8955      0.562 0.312 0.688
#> round_ERR2585202        2  0.4431      0.882 0.092 0.908
#> aberrant_ERR2585367     2  0.0000      0.970 0.000 1.000
#> round_ERR2585220        1  0.0000      0.960 1.000 0.000
#> round_ERR2585238        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585276     2  0.0000      0.970 0.000 1.000
#> round_ERR2585218        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585363     2  0.0000      0.970 0.000 1.000
#> round_ERR2585201        1  0.0376      0.956 0.996 0.004
#> round_ERR2585210        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585362     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585360     2  0.0000      0.970 0.000 1.000
#> round_ERR2585209        1  0.0000      0.960 1.000 0.000
#> round_ERR2585242        1  0.0000      0.960 1.000 0.000
#> round_ERR2585216        1  0.0000      0.960 1.000 0.000
#> round_ERR2585219        1  0.0000      0.960 1.000 0.000
#> round_ERR2585237        2  0.9129      0.530 0.328 0.672
#> round_ERR2585198        2  0.8955      0.562 0.312 0.688
#> round_ERR2585211        1  0.0000      0.960 1.000 0.000
#> round_ERR2585206        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585281     2  0.0000      0.970 0.000 1.000
#> round_ERR2585212        1  0.0000      0.960 1.000 0.000
#> round_ERR2585221        1  0.0000      0.960 1.000 0.000
#> round_ERR2585243        1  0.0000      0.960 1.000 0.000
#> round_ERR2585204        2  0.7602      0.718 0.220 0.780
#> round_ERR2585213        2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585373     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585358     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585365     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585359     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585370     2  0.0000      0.970 0.000 1.000
#> round_ERR2585215        1  0.0000      0.960 1.000 0.000
#> round_ERR2585262        2  0.8443      0.633 0.272 0.728
#> round_ERR2585199        2  0.7056      0.759 0.192 0.808
#> aberrant_ERR2585369     2  0.0000      0.970 0.000 1.000
#> round_ERR2585208        1  0.0000      0.960 1.000 0.000
#> round_ERR2585252        1  0.0000      0.960 1.000 0.000
#> round_ERR2585236        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585284     1  0.8955      0.578 0.688 0.312
#> round_ERR2585224        1  0.0000      0.960 1.000 0.000
#> round_ERR2585260        1  0.0000      0.960 1.000 0.000
#> round_ERR2585229        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585364     1  0.9000      0.571 0.684 0.316
#> round_ERR2585253        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585368     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585371     2  0.0000      0.970 0.000 1.000
#> round_ERR2585239        1  0.0000      0.960 1.000 0.000
#> round_ERR2585273        1  0.0000      0.960 1.000 0.000
#> round_ERR2585256        1  0.0000      0.960 1.000 0.000
#> round_ERR2585272        1  0.0000      0.960 1.000 0.000
#> round_ERR2585246        1  0.0000      0.960 1.000 0.000
#> round_ERR2585261        1  0.0672      0.953 0.992 0.008
#> round_ERR2585254        1  0.3584      0.898 0.932 0.068
#> round_ERR2585225        1  0.0000      0.960 1.000 0.000
#> round_ERR2585235        1  0.0000      0.960 1.000 0.000
#> round_ERR2585271        1  0.0000      0.960 1.000 0.000
#> round_ERR2585251        1  0.0000      0.960 1.000 0.000
#> round_ERR2585255        1  0.0000      0.960 1.000 0.000
#> round_ERR2585257        1  0.0000      0.960 1.000 0.000
#> round_ERR2585226        1  0.0000      0.960 1.000 0.000
#> round_ERR2585265        1  0.0000      0.960 1.000 0.000
#> round_ERR2585259        1  0.0000      0.960 1.000 0.000
#> round_ERR2585247        1  0.0000      0.960 1.000 0.000
#> round_ERR2585241        1  0.0000      0.960 1.000 0.000
#> round_ERR2585263        1  0.0000      0.960 1.000 0.000
#> round_ERR2585264        1  0.0000      0.960 1.000 0.000
#> round_ERR2585233        1  0.0000      0.960 1.000 0.000
#> round_ERR2585223        1  0.0000      0.960 1.000 0.000
#> round_ERR2585234        1  0.9754      0.282 0.592 0.408
#> round_ERR2585222        1  0.0000      0.960 1.000 0.000
#> round_ERR2585228        1  0.0000      0.960 1.000 0.000
#> round_ERR2585248        1  0.0000      0.960 1.000 0.000
#> round_ERR2585240        1  0.0000      0.960 1.000 0.000
#> round_ERR2585270        1  0.0000      0.960 1.000 0.000
#> round_ERR2585232        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585341     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585355     2  0.0000      0.970 0.000 1.000
#> round_ERR2585227        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585351     2  0.0000      0.970 0.000 1.000
#> round_ERR2585269        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585357     2  0.0000      0.970 0.000 1.000
#> aberrant_ERR2585350     2  0.0000      0.970 0.000 1.000
#> round_ERR2585250        1  0.0000      0.960 1.000 0.000
#> round_ERR2585245        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585353     2  0.0000      0.970 0.000 1.000
#> round_ERR2585258        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585354     2  0.0000      0.970 0.000 1.000
#> round_ERR2585249        1  0.0000      0.960 1.000 0.000
#> round_ERR2585268        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585356     2  0.0000      0.970 0.000 1.000
#> round_ERR2585266        1  0.0000      0.960 1.000 0.000
#> round_ERR2585231        1  0.0000      0.960 1.000 0.000
#> round_ERR2585230        1  0.0000      0.960 1.000 0.000
#> round_ERR2585267        1  0.0000      0.960 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 cell_type(p) k
#> SD:skmeans 158     4.65e-19 2
#> SD:skmeans 150     7.32e-22 3
#> SD:skmeans 148     4.34e-27 4
#> SD:skmeans 130     1.99e-22 5
#> SD:skmeans 116     2.14e-19 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 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 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.401           0.798       0.863         0.2311 0.904   0.904
#> 3 3 0.324           0.781       0.845         1.1708 0.575   0.532
#> 4 4 0.306           0.687       0.805         0.0967 0.974   0.948
#> 5 5 0.330           0.361       0.777         0.0649 0.996   0.991
#> 6 6 0.513           0.524       0.807         0.0771 0.951   0.895

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
#> aberrant_ERR2585320     1  0.8955      0.726 0.688 0.312
#> aberrant_ERR2585338     1  0.5408      0.827 0.876 0.124
#> aberrant_ERR2585325     1  0.8555      0.752 0.720 0.280
#> aberrant_ERR2585283     2  0.1184      0.906 0.016 0.984
#> aberrant_ERR2585343     1  0.9323      0.690 0.652 0.348
#> aberrant_ERR2585329     1  0.7745      0.785 0.772 0.228
#> aberrant_ERR2585317     1  0.7883      0.780 0.764 0.236
#> aberrant_ERR2585339     1  0.7299      0.799 0.796 0.204
#> aberrant_ERR2585335     1  0.8661      0.746 0.712 0.288
#> aberrant_ERR2585287     2  0.3584      0.882 0.068 0.932
#> aberrant_ERR2585321     1  0.9358      0.690 0.648 0.352
#> aberrant_ERR2585297     1  0.1184      0.839 0.984 0.016
#> aberrant_ERR2585337     1  0.7602      0.789 0.780 0.220
#> aberrant_ERR2585319     1  0.9286      0.694 0.656 0.344
#> aberrant_ERR2585315     1  0.9286      0.694 0.656 0.344
#> aberrant_ERR2585336     1  0.8016      0.776 0.756 0.244
#> aberrant_ERR2585307     1  0.5629      0.825 0.868 0.132
#> aberrant_ERR2585301     1  0.7219      0.799 0.800 0.200
#> aberrant_ERR2585326     1  0.8016      0.777 0.756 0.244
#> aberrant_ERR2585331     1  0.4298      0.833 0.912 0.088
#> aberrant_ERR2585346     2  0.5737      0.839 0.136 0.864
#> aberrant_ERR2585314     1  0.7815      0.782 0.768 0.232
#> aberrant_ERR2585298     1  0.0000      0.842 1.000 0.000
#> aberrant_ERR2585345     1  0.7815      0.782 0.768 0.232
#> aberrant_ERR2585299     1  0.1184      0.839 0.984 0.016
#> aberrant_ERR2585309     1  0.0938      0.839 0.988 0.012
#> aberrant_ERR2585303     1  0.8267      0.768 0.740 0.260
#> aberrant_ERR2585313     1  0.9209      0.703 0.664 0.336
#> aberrant_ERR2585318     1  0.9323      0.690 0.652 0.348
#> aberrant_ERR2585328     1  0.9286      0.694 0.656 0.344
#> aberrant_ERR2585330     1  0.9323      0.690 0.652 0.348
#> aberrant_ERR2585293     2  0.4298      0.889 0.088 0.912
#> aberrant_ERR2585342     1  0.9323      0.690 0.652 0.348
#> aberrant_ERR2585348     1  0.9323      0.690 0.652 0.348
#> aberrant_ERR2585352     1  0.9286      0.694 0.656 0.344
#> aberrant_ERR2585308     1  0.0938      0.839 0.988 0.012
#> aberrant_ERR2585349     1  0.5946      0.820 0.856 0.144
#> aberrant_ERR2585316     1  0.9323      0.690 0.652 0.348
#> aberrant_ERR2585306     1  0.8763      0.739 0.704 0.296
#> aberrant_ERR2585324     1  0.9286      0.694 0.656 0.344
#> aberrant_ERR2585310     1  0.0376      0.843 0.996 0.004
#> aberrant_ERR2585296     1  0.0000      0.842 1.000 0.000
#> aberrant_ERR2585275     2  0.0000      0.903 0.000 1.000
#> aberrant_ERR2585311     1  0.9323      0.690 0.652 0.348
#> aberrant_ERR2585292     2  0.4298      0.889 0.088 0.912
#> aberrant_ERR2585282     1  0.8555      0.744 0.720 0.280
#> aberrant_ERR2585305     1  0.8661      0.747 0.712 0.288
#> aberrant_ERR2585278     1  0.7528      0.795 0.784 0.216
#> aberrant_ERR2585347     1  0.9323      0.690 0.652 0.348
#> aberrant_ERR2585332     1  0.9323      0.690 0.652 0.348
#> aberrant_ERR2585280     1  0.9248      0.699 0.660 0.340
#> aberrant_ERR2585304     1  0.3274      0.838 0.940 0.060
#> aberrant_ERR2585322     1  0.7883      0.781 0.764 0.236
#> aberrant_ERR2585279     1  0.4298      0.833 0.912 0.088
#> aberrant_ERR2585277     1  0.5737      0.823 0.864 0.136
#> aberrant_ERR2585295     1  0.6343      0.817 0.840 0.160
#> aberrant_ERR2585333     1  0.9323      0.690 0.652 0.348
#> aberrant_ERR2585285     1  0.8327      0.763 0.736 0.264
#> aberrant_ERR2585286     1  0.5178      0.828 0.884 0.116
#> aberrant_ERR2585294     1  0.8608      0.750 0.716 0.284
#> aberrant_ERR2585300     1  0.9209      0.706 0.664 0.336
#> aberrant_ERR2585334     1  0.4298      0.833 0.912 0.088
#> aberrant_ERR2585361     1  0.9323      0.690 0.652 0.348
#> aberrant_ERR2585372     1  0.9323      0.690 0.652 0.348
#> round_ERR2585217        1  0.0672      0.843 0.992 0.008
#> round_ERR2585205        1  0.0938      0.839 0.988 0.012
#> round_ERR2585214        1  0.1414      0.843 0.980 0.020
#> round_ERR2585202        1  0.1414      0.843 0.980 0.020
#> aberrant_ERR2585367     1  0.8327      0.760 0.736 0.264
#> round_ERR2585220        1  0.0938      0.839 0.988 0.012
#> round_ERR2585238        1  0.0938      0.839 0.988 0.012
#> aberrant_ERR2585276     1  0.8909      0.732 0.692 0.308
#> round_ERR2585218        1  0.0938      0.839 0.988 0.012
#> aberrant_ERR2585363     1  0.8608      0.749 0.716 0.284
#> round_ERR2585201        1  0.0938      0.843 0.988 0.012
#> round_ERR2585210        1  0.0938      0.839 0.988 0.012
#> aberrant_ERR2585362     1  0.9044      0.720 0.680 0.320
#> aberrant_ERR2585360     1  0.9129      0.711 0.672 0.328
#> round_ERR2585209        1  0.0376      0.843 0.996 0.004
#> round_ERR2585242        1  0.0000      0.842 1.000 0.000
#> round_ERR2585216        1  0.0000      0.842 1.000 0.000
#> round_ERR2585219        1  0.0376      0.841 0.996 0.004
#> round_ERR2585237        1  0.1414      0.843 0.980 0.020
#> round_ERR2585198        1  0.1414      0.843 0.980 0.020
#> round_ERR2585211        1  0.0938      0.839 0.988 0.012
#> round_ERR2585206        1  0.0938      0.839 0.988 0.012
#> aberrant_ERR2585281     1  0.5629      0.825 0.868 0.132
#> round_ERR2585212        1  0.0376      0.841 0.996 0.004
#> round_ERR2585221        1  0.1184      0.839 0.984 0.016
#> round_ERR2585243        1  0.0672      0.840 0.992 0.008
#> round_ERR2585204        1  0.1414      0.843 0.980 0.020
#> round_ERR2585213        1  0.4022      0.835 0.920 0.080
#> aberrant_ERR2585373     1  0.9323      0.690 0.652 0.348
#> aberrant_ERR2585358     1  0.9323      0.690 0.652 0.348
#> aberrant_ERR2585365     1  0.8267      0.766 0.740 0.260
#> aberrant_ERR2585359     1  0.9358      0.686 0.648 0.352
#> aberrant_ERR2585370     1  0.7883      0.780 0.764 0.236
#> round_ERR2585215        1  0.0938      0.839 0.988 0.012
#> round_ERR2585262        1  0.1633      0.843 0.976 0.024
#> round_ERR2585199        1  0.1414      0.843 0.980 0.020
#> aberrant_ERR2585369     1  0.9323      0.690 0.652 0.348
#> round_ERR2585208        1  0.0938      0.839 0.988 0.012
#> round_ERR2585252        1  0.0938      0.839 0.988 0.012
#> round_ERR2585236        1  0.2423      0.837 0.960 0.040
#> aberrant_ERR2585284     2  0.0376      0.902 0.004 0.996
#> round_ERR2585224        1  0.1633      0.838 0.976 0.024
#> round_ERR2585260        1  0.0938      0.839 0.988 0.012
#> round_ERR2585229        1  0.0938      0.839 0.988 0.012
#> aberrant_ERR2585364     2  0.5629      0.779 0.132 0.868
#> round_ERR2585253        1  0.1184      0.839 0.984 0.016
#> aberrant_ERR2585368     1  0.4690      0.831 0.900 0.100
#> aberrant_ERR2585371     1  0.4431      0.832 0.908 0.092
#> round_ERR2585239        1  0.0938      0.839 0.988 0.012
#> round_ERR2585273        1  0.0938      0.839 0.988 0.012
#> round_ERR2585256        1  0.1184      0.843 0.984 0.016
#> round_ERR2585272        1  0.0376      0.841 0.996 0.004
#> round_ERR2585246        1  0.1184      0.839 0.984 0.016
#> round_ERR2585261        1  0.0000      0.842 1.000 0.000
#> round_ERR2585254        1  0.1184      0.843 0.984 0.016
#> round_ERR2585225        1  0.0000      0.842 1.000 0.000
#> round_ERR2585235        1  0.0000      0.842 1.000 0.000
#> round_ERR2585271        1  0.0938      0.839 0.988 0.012
#> round_ERR2585251        1  0.0938      0.839 0.988 0.012
#> round_ERR2585255        1  0.0938      0.843 0.988 0.012
#> round_ERR2585257        1  0.1414      0.843 0.980 0.020
#> round_ERR2585226        1  0.0000      0.842 1.000 0.000
#> round_ERR2585265        1  0.0938      0.839 0.988 0.012
#> round_ERR2585259        1  0.0672      0.840 0.992 0.008
#> round_ERR2585247        1  0.0938      0.839 0.988 0.012
#> round_ERR2585241        1  0.0938      0.839 0.988 0.012
#> round_ERR2585263        1  0.0000      0.842 1.000 0.000
#> round_ERR2585264        1  0.8081      0.506 0.752 0.248
#> round_ERR2585233        1  0.0000      0.842 1.000 0.000
#> round_ERR2585223        1  0.0938      0.839 0.988 0.012
#> round_ERR2585234        1  0.1184      0.843 0.984 0.016
#> round_ERR2585222        1  0.0672      0.840 0.992 0.008
#> round_ERR2585228        1  0.0938      0.839 0.988 0.012
#> round_ERR2585248        1  0.2603      0.822 0.956 0.044
#> round_ERR2585240        1  0.0376      0.842 0.996 0.004
#> round_ERR2585270        1  0.0938      0.839 0.988 0.012
#> round_ERR2585232        1  0.0000      0.842 1.000 0.000
#> aberrant_ERR2585341     1  0.6531      0.814 0.832 0.168
#> aberrant_ERR2585355     1  0.8144      0.773 0.748 0.252
#> round_ERR2585227        1  0.0672      0.840 0.992 0.008
#> aberrant_ERR2585351     1  0.8555      0.752 0.720 0.280
#> round_ERR2585269        1  0.0938      0.839 0.988 0.012
#> aberrant_ERR2585357     1  0.7815      0.782 0.768 0.232
#> aberrant_ERR2585350     1  0.7815      0.782 0.768 0.232
#> round_ERR2585250        1  0.0672      0.840 0.992 0.008
#> round_ERR2585245        1  0.2603      0.835 0.956 0.044
#> aberrant_ERR2585353     1  0.9323      0.690 0.652 0.348
#> round_ERR2585258        1  0.0938      0.839 0.988 0.012
#> aberrant_ERR2585354     1  0.8955      0.731 0.688 0.312
#> round_ERR2585249        1  0.1184      0.839 0.984 0.016
#> round_ERR2585268        1  0.0376      0.841 0.996 0.004
#> aberrant_ERR2585356     1  0.9427      0.689 0.640 0.360
#> round_ERR2585266        1  0.0672      0.843 0.992 0.008
#> round_ERR2585231        1  0.0938      0.839 0.988 0.012
#> round_ERR2585230        1  0.0938      0.839 0.988 0.012
#> round_ERR2585267        1  0.1414      0.840 0.980 0.020

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 cell_type(p) k
#> SD:pam 160     2.38e-02 2
#> SD:pam 153     8.80e-19 3
#> SD:pam 149     1.84e-18 4
#> SD:pam  85     1.98e-14 5
#> SD:pam 101     3.35e-15 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 1.000           0.988       0.995         0.5035 0.497   0.497
#> 3 3 0.801           0.865       0.913         0.1515 0.942   0.884
#> 4 4 0.835           0.843       0.919         0.1248 0.881   0.740
#> 5 5 0.771           0.751       0.881         0.1371 0.878   0.659
#> 6 6 0.730           0.674       0.833         0.0523 0.956   0.835

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
#> aberrant_ERR2585320     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585338     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585325     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585283     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585343     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585329     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585317     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585339     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585335     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585287     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585321     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585297     1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585337     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585319     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585315     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585336     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585307     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585301     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585326     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585331     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585346     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585314     2  0.1633      0.972 0.024 0.976
#> aberrant_ERR2585298     1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585345     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585299     1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585309     1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585303     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585313     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585318     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585328     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585330     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585293     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585342     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585348     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585352     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585308     1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585349     2  0.8499      0.614 0.276 0.724
#> aberrant_ERR2585316     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585306     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585324     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585310     1  0.2236      0.959 0.964 0.036
#> aberrant_ERR2585296     1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585275     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585311     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585292     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585282     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585305     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585278     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585347     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585332     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585280     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585304     1  0.6247      0.816 0.844 0.156
#> aberrant_ERR2585322     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585279     1  0.8661      0.598 0.712 0.288
#> aberrant_ERR2585277     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585295     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585333     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585285     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585286     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585294     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585300     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585334     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585361     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585372     2  0.0000      0.996 0.000 1.000
#> round_ERR2585217        1  0.0000      0.993 1.000 0.000
#> round_ERR2585205        1  0.0000      0.993 1.000 0.000
#> round_ERR2585214        1  0.0000      0.993 1.000 0.000
#> round_ERR2585202        1  0.0376      0.990 0.996 0.004
#> aberrant_ERR2585367     2  0.0000      0.996 0.000 1.000
#> round_ERR2585220        1  0.0000      0.993 1.000 0.000
#> round_ERR2585238        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585276     2  0.0000      0.996 0.000 1.000
#> round_ERR2585218        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585363     2  0.0000      0.996 0.000 1.000
#> round_ERR2585201        1  0.0000      0.993 1.000 0.000
#> round_ERR2585210        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585362     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585360     2  0.0000      0.996 0.000 1.000
#> round_ERR2585209        1  0.0000      0.993 1.000 0.000
#> round_ERR2585242        1  0.0000      0.993 1.000 0.000
#> round_ERR2585216        1  0.0000      0.993 1.000 0.000
#> round_ERR2585219        1  0.0000      0.993 1.000 0.000
#> round_ERR2585237        1  0.0000      0.993 1.000 0.000
#> round_ERR2585198        1  0.0000      0.993 1.000 0.000
#> round_ERR2585211        1  0.0000      0.993 1.000 0.000
#> round_ERR2585206        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585281     2  0.0000      0.996 0.000 1.000
#> round_ERR2585212        1  0.0000      0.993 1.000 0.000
#> round_ERR2585221        1  0.0000      0.993 1.000 0.000
#> round_ERR2585243        1  0.0000      0.993 1.000 0.000
#> round_ERR2585204        1  0.0000      0.993 1.000 0.000
#> round_ERR2585213        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585373     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585358     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585365     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585359     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585370     2  0.0000      0.996 0.000 1.000
#> round_ERR2585215        1  0.0000      0.993 1.000 0.000
#> round_ERR2585262        1  0.2236      0.959 0.964 0.036
#> round_ERR2585199        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585369     2  0.0000      0.996 0.000 1.000
#> round_ERR2585208        1  0.0000      0.993 1.000 0.000
#> round_ERR2585252        1  0.0000      0.993 1.000 0.000
#> round_ERR2585236        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585284     2  0.0000      0.996 0.000 1.000
#> round_ERR2585224        1  0.0000      0.993 1.000 0.000
#> round_ERR2585260        1  0.0000      0.993 1.000 0.000
#> round_ERR2585229        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585364     2  0.0000      0.996 0.000 1.000
#> round_ERR2585253        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585368     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585371     2  0.0000      0.996 0.000 1.000
#> round_ERR2585239        1  0.0000      0.993 1.000 0.000
#> round_ERR2585273        1  0.0000      0.993 1.000 0.000
#> round_ERR2585256        1  0.0000      0.993 1.000 0.000
#> round_ERR2585272        1  0.0000      0.993 1.000 0.000
#> round_ERR2585246        1  0.0000      0.993 1.000 0.000
#> round_ERR2585261        1  0.0000      0.993 1.000 0.000
#> round_ERR2585254        1  0.0000      0.993 1.000 0.000
#> round_ERR2585225        1  0.0000      0.993 1.000 0.000
#> round_ERR2585235        1  0.0000      0.993 1.000 0.000
#> round_ERR2585271        1  0.0000      0.993 1.000 0.000
#> round_ERR2585251        1  0.0000      0.993 1.000 0.000
#> round_ERR2585255        1  0.0000      0.993 1.000 0.000
#> round_ERR2585257        1  0.0000      0.993 1.000 0.000
#> round_ERR2585226        1  0.0000      0.993 1.000 0.000
#> round_ERR2585265        1  0.0000      0.993 1.000 0.000
#> round_ERR2585259        1  0.0000      0.993 1.000 0.000
#> round_ERR2585247        1  0.0000      0.993 1.000 0.000
#> round_ERR2585241        1  0.0000      0.993 1.000 0.000
#> round_ERR2585263        1  0.0000      0.993 1.000 0.000
#> round_ERR2585264        1  0.0000      0.993 1.000 0.000
#> round_ERR2585233        1  0.0000      0.993 1.000 0.000
#> round_ERR2585223        1  0.0000      0.993 1.000 0.000
#> round_ERR2585234        1  0.0000      0.993 1.000 0.000
#> round_ERR2585222        1  0.0000      0.993 1.000 0.000
#> round_ERR2585228        1  0.0000      0.993 1.000 0.000
#> round_ERR2585248        1  0.0000      0.993 1.000 0.000
#> round_ERR2585240        1  0.0000      0.993 1.000 0.000
#> round_ERR2585270        1  0.0000      0.993 1.000 0.000
#> round_ERR2585232        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585341     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585355     2  0.0000      0.996 0.000 1.000
#> round_ERR2585227        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585351     2  0.0000      0.996 0.000 1.000
#> round_ERR2585269        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585357     2  0.0000      0.996 0.000 1.000
#> aberrant_ERR2585350     2  0.0000      0.996 0.000 1.000
#> round_ERR2585250        1  0.0000      0.993 1.000 0.000
#> round_ERR2585245        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585353     2  0.0000      0.996 0.000 1.000
#> round_ERR2585258        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585354     2  0.0000      0.996 0.000 1.000
#> round_ERR2585249        1  0.0000      0.993 1.000 0.000
#> round_ERR2585268        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585356     2  0.0000      0.996 0.000 1.000
#> round_ERR2585266        1  0.0000      0.993 1.000 0.000
#> round_ERR2585231        1  0.0000      0.993 1.000 0.000
#> round_ERR2585230        1  0.0000      0.993 1.000 0.000
#> round_ERR2585267        1  0.0000      0.993 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-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 cell_type(p) k
#> SD:mclust 160     7.97e-29 2
#> SD:mclust 154     2.46e-29 3
#> SD:mclust 151     2.03e-26 4
#> SD:mclust 137     6.49e-24 5
#> SD:mclust 132     8.15e-23 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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.975       0.989         0.5008 0.500   0.500
#> 3 3 0.742           0.810       0.902         0.2748 0.813   0.643
#> 4 4 0.652           0.769       0.870         0.0619 0.961   0.894
#> 5 5 0.600           0.635       0.800         0.0715 0.957   0.881
#> 6 6 0.609           0.553       0.765         0.0555 0.915   0.748

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
#> aberrant_ERR2585320     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585338     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585325     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585283     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585343     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585329     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585317     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585339     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585335     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585287     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585321     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585297     1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585337     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585319     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585315     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585336     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585307     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585301     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585326     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585331     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585346     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585314     2  0.0672      0.981 0.008 0.992
#> aberrant_ERR2585298     1  0.0672      0.984 0.992 0.008
#> aberrant_ERR2585345     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585299     1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585309     1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585303     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585313     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585318     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585328     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585330     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585293     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585342     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585348     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585352     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585308     1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585349     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585316     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585306     2  0.3733      0.917 0.072 0.928
#> aberrant_ERR2585324     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585310     1  0.2603      0.950 0.956 0.044
#> aberrant_ERR2585296     1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585275     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585311     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585292     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585282     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585305     2  0.1414      0.970 0.020 0.980
#> aberrant_ERR2585278     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585347     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585332     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585280     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585304     2  0.0376      0.984 0.004 0.996
#> aberrant_ERR2585322     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585279     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585277     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585295     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585333     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585285     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585286     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585294     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585300     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585334     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585361     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585372     2  0.0000      0.988 0.000 1.000
#> round_ERR2585217        1  0.0000      0.990 1.000 0.000
#> round_ERR2585205        1  0.0000      0.990 1.000 0.000
#> round_ERR2585214        2  0.9815      0.274 0.420 0.580
#> round_ERR2585202        2  0.5737      0.841 0.136 0.864
#> aberrant_ERR2585367     2  0.0000      0.988 0.000 1.000
#> round_ERR2585220        1  0.0000      0.990 1.000 0.000
#> round_ERR2585238        1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585276     2  0.0000      0.988 0.000 1.000
#> round_ERR2585218        1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585363     2  0.0000      0.988 0.000 1.000
#> round_ERR2585201        1  0.0376      0.987 0.996 0.004
#> round_ERR2585210        1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585362     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585360     2  0.0000      0.988 0.000 1.000
#> round_ERR2585209        1  0.0000      0.990 1.000 0.000
#> round_ERR2585242        1  0.0376      0.987 0.996 0.004
#> round_ERR2585216        1  0.0000      0.990 1.000 0.000
#> round_ERR2585219        1  0.0000      0.990 1.000 0.000
#> round_ERR2585237        1  0.0000      0.990 1.000 0.000
#> round_ERR2585198        1  0.0376      0.987 0.996 0.004
#> round_ERR2585211        1  0.0000      0.990 1.000 0.000
#> round_ERR2585206        1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585281     2  0.0000      0.988 0.000 1.000
#> round_ERR2585212        1  0.0000      0.990 1.000 0.000
#> round_ERR2585221        1  0.0000      0.990 1.000 0.000
#> round_ERR2585243        1  0.0000      0.990 1.000 0.000
#> round_ERR2585204        2  0.8909      0.554 0.308 0.692
#> round_ERR2585213        2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585373     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585358     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585365     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585359     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585370     2  0.0000      0.988 0.000 1.000
#> round_ERR2585215        1  0.0000      0.990 1.000 0.000
#> round_ERR2585262        2  0.2778      0.942 0.048 0.952
#> round_ERR2585199        1  0.7602      0.721 0.780 0.220
#> aberrant_ERR2585369     2  0.0000      0.988 0.000 1.000
#> round_ERR2585208        1  0.0000      0.990 1.000 0.000
#> round_ERR2585252        1  0.0000      0.990 1.000 0.000
#> round_ERR2585236        1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585284     2  0.0000      0.988 0.000 1.000
#> round_ERR2585224        1  0.0000      0.990 1.000 0.000
#> round_ERR2585260        1  0.0000      0.990 1.000 0.000
#> round_ERR2585229        1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585364     2  0.0000      0.988 0.000 1.000
#> round_ERR2585253        1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585368     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585371     2  0.0000      0.988 0.000 1.000
#> round_ERR2585239        1  0.0000      0.990 1.000 0.000
#> round_ERR2585273        1  0.0000      0.990 1.000 0.000
#> round_ERR2585256        1  0.0000      0.990 1.000 0.000
#> round_ERR2585272        1  0.0000      0.990 1.000 0.000
#> round_ERR2585246        1  0.0000      0.990 1.000 0.000
#> round_ERR2585261        1  0.0000      0.990 1.000 0.000
#> round_ERR2585254        1  0.0000      0.990 1.000 0.000
#> round_ERR2585225        1  0.5408      0.859 0.876 0.124
#> round_ERR2585235        1  0.0000      0.990 1.000 0.000
#> round_ERR2585271        1  0.0000      0.990 1.000 0.000
#> round_ERR2585251        1  0.0000      0.990 1.000 0.000
#> round_ERR2585255        1  0.7883      0.696 0.764 0.236
#> round_ERR2585257        1  0.0000      0.990 1.000 0.000
#> round_ERR2585226        1  0.0000      0.990 1.000 0.000
#> round_ERR2585265        1  0.0000      0.990 1.000 0.000
#> round_ERR2585259        1  0.0000      0.990 1.000 0.000
#> round_ERR2585247        1  0.0000      0.990 1.000 0.000
#> round_ERR2585241        1  0.0000      0.990 1.000 0.000
#> round_ERR2585263        1  0.0000      0.990 1.000 0.000
#> round_ERR2585264        1  0.0000      0.990 1.000 0.000
#> round_ERR2585233        1  0.0000      0.990 1.000 0.000
#> round_ERR2585223        1  0.0000      0.990 1.000 0.000
#> round_ERR2585234        1  0.2423      0.954 0.960 0.040
#> round_ERR2585222        1  0.0000      0.990 1.000 0.000
#> round_ERR2585228        1  0.0000      0.990 1.000 0.000
#> round_ERR2585248        1  0.0000      0.990 1.000 0.000
#> round_ERR2585240        1  0.0000      0.990 1.000 0.000
#> round_ERR2585270        1  0.0000      0.990 1.000 0.000
#> round_ERR2585232        1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585341     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585355     2  0.0000      0.988 0.000 1.000
#> round_ERR2585227        1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585351     2  0.0000      0.988 0.000 1.000
#> round_ERR2585269        1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585357     2  0.0000      0.988 0.000 1.000
#> aberrant_ERR2585350     2  0.0000      0.988 0.000 1.000
#> round_ERR2585250        1  0.0000      0.990 1.000 0.000
#> round_ERR2585245        1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585353     2  0.0000      0.988 0.000 1.000
#> round_ERR2585258        1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585354     2  0.0000      0.988 0.000 1.000
#> round_ERR2585249        1  0.0000      0.990 1.000 0.000
#> round_ERR2585268        1  0.0000      0.990 1.000 0.000
#> aberrant_ERR2585356     2  0.0000      0.988 0.000 1.000
#> round_ERR2585266        1  0.1184      0.977 0.984 0.016
#> round_ERR2585231        1  0.0000      0.990 1.000 0.000
#> round_ERR2585230        1  0.0000      0.990 1.000 0.000
#> round_ERR2585267        1  0.0000      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-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 cell_type(p) k
#> SD:NMF 159     1.02e-26 2
#> SD:NMF 146     1.88e-22 3
#> SD:NMF 147     3.76e-21 4
#> SD:NMF 129     2.91e-19 5
#> SD:NMF 114     2.48e-14 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 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-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.222           0.648       0.824         0.4617 0.497   0.497
#> 3 3 0.342           0.639       0.782         0.3493 0.794   0.606
#> 4 4 0.523           0.632       0.760         0.1291 0.933   0.806
#> 5 5 0.597           0.558       0.718         0.0732 0.927   0.754
#> 6 6 0.602           0.527       0.721         0.0330 0.951   0.813

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
#> aberrant_ERR2585320     2  0.8443     0.6849 0.272 0.728
#> aberrant_ERR2585338     2  0.1843     0.7434 0.028 0.972
#> aberrant_ERR2585325     2  0.8443     0.6849 0.272 0.728
#> aberrant_ERR2585283     1  0.5059     0.7679 0.888 0.112
#> aberrant_ERR2585343     1  0.9732     0.2421 0.596 0.404
#> aberrant_ERR2585329     2  0.2603     0.7459 0.044 0.956
#> aberrant_ERR2585317     2  0.3584     0.7505 0.068 0.932
#> aberrant_ERR2585339     2  0.0672     0.7337 0.008 0.992
#> aberrant_ERR2585335     2  0.7815     0.7095 0.232 0.768
#> aberrant_ERR2585287     1  0.9044     0.4826 0.680 0.320
#> aberrant_ERR2585321     1  0.9970    -0.0307 0.532 0.468
#> aberrant_ERR2585297     1  0.0938     0.8148 0.988 0.012
#> aberrant_ERR2585337     2  0.2603     0.7466 0.044 0.956
#> aberrant_ERR2585319     2  0.7219     0.7305 0.200 0.800
#> aberrant_ERR2585315     2  0.2603     0.7460 0.044 0.956
#> aberrant_ERR2585336     2  0.2423     0.7450 0.040 0.960
#> aberrant_ERR2585307     2  0.2423     0.7473 0.040 0.960
#> aberrant_ERR2585301     2  0.9850     0.4006 0.428 0.572
#> aberrant_ERR2585326     2  0.0938     0.7362 0.012 0.988
#> aberrant_ERR2585331     2  0.0000     0.7299 0.000 1.000
#> aberrant_ERR2585346     1  0.4815     0.7748 0.896 0.104
#> aberrant_ERR2585314     2  0.5737     0.7498 0.136 0.864
#> aberrant_ERR2585298     2  0.9686     0.4747 0.396 0.604
#> aberrant_ERR2585345     2  0.4161     0.7522 0.084 0.916
#> aberrant_ERR2585299     1  0.1184     0.8169 0.984 0.016
#> aberrant_ERR2585309     1  0.0000     0.8117 1.000 0.000
#> aberrant_ERR2585303     2  0.4815     0.7470 0.104 0.896
#> aberrant_ERR2585313     2  0.1633     0.7409 0.024 0.976
#> aberrant_ERR2585318     2  0.9552     0.5333 0.376 0.624
#> aberrant_ERR2585328     1  0.9427     0.3836 0.640 0.360
#> aberrant_ERR2585330     2  0.7376     0.7266 0.208 0.792
#> aberrant_ERR2585293     1  0.5059     0.7679 0.888 0.112
#> aberrant_ERR2585342     1  0.9850     0.1534 0.572 0.428
#> aberrant_ERR2585348     2  0.9209     0.5918 0.336 0.664
#> aberrant_ERR2585352     2  0.6712     0.7391 0.176 0.824
#> aberrant_ERR2585308     1  0.0376     0.8136 0.996 0.004
#> aberrant_ERR2585349     2  0.0938     0.7369 0.012 0.988
#> aberrant_ERR2585316     1  0.8861     0.5053 0.696 0.304
#> aberrant_ERR2585306     1  0.9044     0.4754 0.680 0.320
#> aberrant_ERR2585324     2  0.7219     0.7305 0.200 0.800
#> aberrant_ERR2585310     2  0.7602     0.7252 0.220 0.780
#> aberrant_ERR2585296     1  0.8813     0.5061 0.700 0.300
#> aberrant_ERR2585275     1  0.6887     0.7025 0.816 0.184
#> aberrant_ERR2585311     1  0.9909     0.0779 0.556 0.444
#> aberrant_ERR2585292     1  0.5059     0.7679 0.888 0.112
#> aberrant_ERR2585282     1  0.9977    -0.0783 0.528 0.472
#> aberrant_ERR2585305     1  0.9988    -0.0861 0.520 0.480
#> aberrant_ERR2585278     2  0.7299     0.7280 0.204 0.796
#> aberrant_ERR2585347     1  0.8713     0.5292 0.708 0.292
#> aberrant_ERR2585332     1  0.9393     0.3894 0.644 0.356
#> aberrant_ERR2585280     2  0.8661     0.6677 0.288 0.712
#> aberrant_ERR2585304     2  0.7815     0.6915 0.232 0.768
#> aberrant_ERR2585322     2  0.3733     0.7538 0.072 0.928
#> aberrant_ERR2585279     2  0.0000     0.7299 0.000 1.000
#> aberrant_ERR2585277     2  0.0376     0.7319 0.004 0.996
#> aberrant_ERR2585295     2  0.9661     0.4772 0.392 0.608
#> aberrant_ERR2585333     1  0.9977    -0.0653 0.528 0.472
#> aberrant_ERR2585285     2  0.8909     0.6366 0.308 0.692
#> aberrant_ERR2585286     2  0.1414     0.7375 0.020 0.980
#> aberrant_ERR2585294     2  0.9775     0.4280 0.412 0.588
#> aberrant_ERR2585300     1  0.9710     0.2546 0.600 0.400
#> aberrant_ERR2585334     2  0.0000     0.7299 0.000 1.000
#> aberrant_ERR2585361     2  0.6801     0.7396 0.180 0.820
#> aberrant_ERR2585372     2  0.9580     0.5223 0.380 0.620
#> round_ERR2585217        2  0.7815     0.6865 0.232 0.768
#> round_ERR2585205        1  0.1414     0.8178 0.980 0.020
#> round_ERR2585214        2  0.9044     0.5982 0.320 0.680
#> round_ERR2585202        2  0.8327     0.6724 0.264 0.736
#> aberrant_ERR2585367     2  0.7299     0.7257 0.204 0.796
#> round_ERR2585220        1  0.3879     0.8050 0.924 0.076
#> round_ERR2585238        1  0.0938     0.8161 0.988 0.012
#> aberrant_ERR2585276     2  0.9983     0.2564 0.476 0.524
#> round_ERR2585218        1  0.1184     0.8172 0.984 0.016
#> aberrant_ERR2585363     2  0.4431     0.7502 0.092 0.908
#> round_ERR2585201        2  0.9661     0.4834 0.392 0.608
#> round_ERR2585210        1  0.0000     0.8117 1.000 0.000
#> aberrant_ERR2585362     2  0.9977     0.2869 0.472 0.528
#> aberrant_ERR2585360     2  0.9944     0.3193 0.456 0.544
#> round_ERR2585209        1  0.9635     0.2706 0.612 0.388
#> round_ERR2585242        2  0.9775     0.4423 0.412 0.588
#> round_ERR2585216        1  0.5946     0.7560 0.856 0.144
#> round_ERR2585219        1  0.2043     0.8180 0.968 0.032
#> round_ERR2585237        2  0.9815     0.4345 0.420 0.580
#> round_ERR2585198        2  0.7674     0.6927 0.224 0.776
#> round_ERR2585211        1  0.1184     0.8168 0.984 0.016
#> round_ERR2585206        1  0.0672     0.8153 0.992 0.008
#> aberrant_ERR2585281     2  0.4298     0.7485 0.088 0.912
#> round_ERR2585212        1  0.3584     0.8087 0.932 0.068
#> round_ERR2585221        1  0.0376     0.8139 0.996 0.004
#> round_ERR2585243        1  0.0938     0.8165 0.988 0.012
#> round_ERR2585204        2  0.5294     0.7360 0.120 0.880
#> round_ERR2585213        2  0.2948     0.7446 0.052 0.948
#> aberrant_ERR2585373     2  0.9944     0.3210 0.456 0.544
#> aberrant_ERR2585358     1  0.9686     0.2702 0.604 0.396
#> aberrant_ERR2585365     2  0.6343     0.7463 0.160 0.840
#> aberrant_ERR2585359     1  0.9044     0.4727 0.680 0.320
#> aberrant_ERR2585370     2  0.0000     0.7299 0.000 1.000
#> round_ERR2585215        1  0.0000     0.8117 1.000 0.000
#> round_ERR2585262        2  0.9580     0.5164 0.380 0.620
#> round_ERR2585199        2  0.6801     0.7102 0.180 0.820
#> aberrant_ERR2585369     2  0.9580     0.5184 0.380 0.620
#> round_ERR2585208        1  0.0938     0.8160 0.988 0.012
#> round_ERR2585252        1  0.0376     0.8139 0.996 0.004
#> round_ERR2585236        1  0.4431     0.7973 0.908 0.092
#> aberrant_ERR2585284     1  0.4815     0.7748 0.896 0.104
#> round_ERR2585224        1  0.0000     0.8117 1.000 0.000
#> round_ERR2585260        1  0.2778     0.8141 0.952 0.048
#> round_ERR2585229        1  0.1184     0.8172 0.984 0.016
#> aberrant_ERR2585364     1  0.6438     0.7222 0.836 0.164
#> round_ERR2585253        1  0.0000     0.8117 1.000 0.000
#> aberrant_ERR2585368     2  0.0000     0.7299 0.000 1.000
#> aberrant_ERR2585371     2  0.0000     0.7299 0.000 1.000
#> round_ERR2585239        1  0.2043     0.8176 0.968 0.032
#> round_ERR2585273        1  0.0672     0.8156 0.992 0.008
#> round_ERR2585256        1  0.8267     0.6067 0.740 0.260
#> round_ERR2585272        1  0.5842     0.7611 0.860 0.140
#> round_ERR2585246        1  0.0376     0.8136 0.996 0.004
#> round_ERR2585261        2  0.9833     0.4198 0.424 0.576
#> round_ERR2585254        2  0.9552     0.5575 0.376 0.624
#> round_ERR2585225        2  0.9754     0.4541 0.408 0.592
#> round_ERR2585235        1  0.6801     0.7079 0.820 0.180
#> round_ERR2585271        1  0.2236     0.8170 0.964 0.036
#> round_ERR2585251        1  0.4022     0.8032 0.920 0.080
#> round_ERR2585255        2  0.9754     0.4521 0.408 0.592
#> round_ERR2585257        2  0.9909     0.3695 0.444 0.556
#> round_ERR2585226        1  0.4161     0.8007 0.916 0.084
#> round_ERR2585265        1  0.3274     0.8118 0.940 0.060
#> round_ERR2585259        1  0.7139     0.6895 0.804 0.196
#> round_ERR2585247        1  0.0672     0.8153 0.992 0.008
#> round_ERR2585241        1  0.1414     0.8177 0.980 0.020
#> round_ERR2585263        1  0.6343     0.7458 0.840 0.160
#> round_ERR2585264        1  0.0000     0.8117 1.000 0.000
#> round_ERR2585233        2  0.9815     0.4268 0.420 0.580
#> round_ERR2585223        1  0.3114     0.8117 0.944 0.056
#> round_ERR2585234        2  0.8608     0.6450 0.284 0.716
#> round_ERR2585222        1  0.1843     0.8174 0.972 0.028
#> round_ERR2585228        1  0.1414     0.8176 0.980 0.020
#> round_ERR2585248        1  0.0000     0.8117 1.000 0.000
#> round_ERR2585240        1  0.9522     0.3355 0.628 0.372
#> round_ERR2585270        1  0.2948     0.8135 0.948 0.052
#> round_ERR2585232        1  0.8713     0.5344 0.708 0.292
#> aberrant_ERR2585341     2  0.6531     0.7407 0.168 0.832
#> aberrant_ERR2585355     2  0.0938     0.7371 0.012 0.988
#> round_ERR2585227        1  0.3431     0.8074 0.936 0.064
#> aberrant_ERR2585351     2  0.9323     0.5774 0.348 0.652
#> round_ERR2585269        1  0.0000     0.8117 1.000 0.000
#> aberrant_ERR2585357     2  0.0938     0.7368 0.012 0.988
#> aberrant_ERR2585350     2  0.1843     0.7434 0.028 0.972
#> round_ERR2585250        1  0.3733     0.8088 0.928 0.072
#> round_ERR2585245        1  0.0000     0.8117 1.000 0.000
#> aberrant_ERR2585353     2  0.9944     0.3358 0.456 0.544
#> round_ERR2585258        1  0.3733     0.8067 0.928 0.072
#> aberrant_ERR2585354     2  0.9866     0.3892 0.432 0.568
#> round_ERR2585249        1  0.0000     0.8117 1.000 0.000
#> round_ERR2585268        1  0.6887     0.7251 0.816 0.184
#> aberrant_ERR2585356     1  0.8909     0.5015 0.692 0.308
#> round_ERR2585266        2  0.9795     0.4324 0.416 0.584
#> round_ERR2585231        1  0.0000     0.8117 1.000 0.000
#> round_ERR2585230        1  0.1633     0.8177 0.976 0.024
#> round_ERR2585267        1  0.0000     0.8117 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 cell_type(p) k
#> CV:hclust 125     5.51e-11 2
#> CV:hclust 122     5.79e-19 3
#> CV:hclust 127     2.32e-23 4
#> CV:hclust 100     1.29e-16 5
#> CV:hclust  79     8.25e-12 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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.856           0.927       0.968         0.5017 0.498   0.498
#> 3 3 0.615           0.726       0.837         0.3009 0.769   0.568
#> 4 4 0.724           0.804       0.881         0.1184 0.864   0.629
#> 5 5 0.712           0.722       0.832         0.0568 0.957   0.841
#> 6 6 0.715           0.592       0.755         0.0438 0.953   0.808

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
#> aberrant_ERR2585320     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585338     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585325     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585283     1  0.8267     0.6632 0.740 0.260
#> aberrant_ERR2585343     2  0.0938     0.9687 0.012 0.988
#> aberrant_ERR2585329     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585317     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585339     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585335     2  0.0672     0.9700 0.008 0.992
#> aberrant_ERR2585287     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585321     2  0.1414     0.9635 0.020 0.980
#> aberrant_ERR2585297     1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585337     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585319     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585315     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585336     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585307     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585301     2  0.0672     0.9700 0.008 0.992
#> aberrant_ERR2585326     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585331     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585346     1  0.5842     0.8376 0.860 0.140
#> aberrant_ERR2585314     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585298     1  0.5178     0.8721 0.884 0.116
#> aberrant_ERR2585345     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585299     1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585309     1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585303     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585313     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585318     2  0.0938     0.9687 0.012 0.988
#> aberrant_ERR2585328     2  0.0672     0.9700 0.008 0.992
#> aberrant_ERR2585330     2  0.0938     0.9687 0.012 0.988
#> aberrant_ERR2585293     1  0.7299     0.7523 0.796 0.204
#> aberrant_ERR2585342     2  0.0938     0.9687 0.012 0.988
#> aberrant_ERR2585348     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585352     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585308     1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585349     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585316     2  0.4939     0.8733 0.108 0.892
#> aberrant_ERR2585306     1  0.7299     0.7514 0.796 0.204
#> aberrant_ERR2585324     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585310     2  0.2603     0.9449 0.044 0.956
#> aberrant_ERR2585296     1  0.0672     0.9547 0.992 0.008
#> aberrant_ERR2585275     2  0.9993     0.0311 0.484 0.516
#> aberrant_ERR2585311     2  0.1184     0.9663 0.016 0.984
#> aberrant_ERR2585292     1  0.7299     0.7523 0.796 0.204
#> aberrant_ERR2585282     2  0.1184     0.9663 0.016 0.984
#> aberrant_ERR2585305     2  0.4690     0.8856 0.100 0.900
#> aberrant_ERR2585278     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585347     2  0.1633     0.9608 0.024 0.976
#> aberrant_ERR2585332     2  0.0938     0.9687 0.012 0.988
#> aberrant_ERR2585280     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585304     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585322     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585279     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585277     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585295     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585333     2  0.0938     0.9687 0.012 0.988
#> aberrant_ERR2585285     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585286     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585294     2  0.0938     0.9687 0.012 0.988
#> aberrant_ERR2585300     2  0.0938     0.9687 0.012 0.988
#> aberrant_ERR2585334     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585361     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585372     2  0.0938     0.9687 0.012 0.988
#> round_ERR2585217        1  0.9661     0.3832 0.608 0.392
#> round_ERR2585205        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585214        2  0.2778     0.9337 0.048 0.952
#> round_ERR2585202        2  0.3114     0.9257 0.056 0.944
#> aberrant_ERR2585367     2  0.0000     0.9718 0.000 1.000
#> round_ERR2585220        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585238        1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585276     2  0.0938     0.9687 0.012 0.988
#> round_ERR2585218        1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585363     2  0.0000     0.9718 0.000 1.000
#> round_ERR2585201        1  0.5737     0.8518 0.864 0.136
#> round_ERR2585210        1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585362     2  0.0938     0.9687 0.012 0.988
#> aberrant_ERR2585360     2  0.0938     0.9687 0.012 0.988
#> round_ERR2585209        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585242        1  0.3733     0.9099 0.928 0.072
#> round_ERR2585216        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585219        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585237        2  0.9286     0.4611 0.344 0.656
#> round_ERR2585198        2  0.4298     0.8906 0.088 0.912
#> round_ERR2585211        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585206        1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585281     2  0.0000     0.9718 0.000 1.000
#> round_ERR2585212        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585221        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585243        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585204        2  0.0376     0.9701 0.004 0.996
#> round_ERR2585213        2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585373     2  0.0938     0.9687 0.012 0.988
#> aberrant_ERR2585358     2  0.0938     0.9687 0.012 0.988
#> aberrant_ERR2585365     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585359     2  0.3584     0.9192 0.068 0.932
#> aberrant_ERR2585370     2  0.0000     0.9718 0.000 1.000
#> round_ERR2585215        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585262        1  0.7299     0.7623 0.796 0.204
#> round_ERR2585199        2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585369     2  0.0938     0.9687 0.012 0.988
#> round_ERR2585208        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585252        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585236        1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585284     1  0.0000     0.9597 1.000 0.000
#> round_ERR2585224        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585260        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585229        1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585364     1  0.9993     0.0768 0.516 0.484
#> round_ERR2585253        1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585368     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585371     2  0.0000     0.9718 0.000 1.000
#> round_ERR2585239        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585273        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585256        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585272        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585246        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585261        1  0.1633     0.9456 0.976 0.024
#> round_ERR2585254        1  0.2778     0.9254 0.952 0.048
#> round_ERR2585225        1  0.5059     0.8762 0.888 0.112
#> round_ERR2585235        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585271        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585251        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585255        1  0.5629     0.8569 0.868 0.132
#> round_ERR2585257        1  0.1184     0.9497 0.984 0.016
#> round_ERR2585226        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585265        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585259        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585247        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585241        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585263        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585264        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585233        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585223        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585234        2  0.9963     0.0955 0.464 0.536
#> round_ERR2585222        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585228        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585248        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585240        1  0.4690     0.8860 0.900 0.100
#> round_ERR2585270        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585232        1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585341     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585355     2  0.0000     0.9718 0.000 1.000
#> round_ERR2585227        1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585351     2  0.1184     0.9663 0.016 0.984
#> round_ERR2585269        1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585357     2  0.0000     0.9718 0.000 1.000
#> aberrant_ERR2585350     2  0.0000     0.9718 0.000 1.000
#> round_ERR2585250        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585245        1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585353     2  0.0938     0.9687 0.012 0.988
#> round_ERR2585258        1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585354     2  0.0938     0.9687 0.012 0.988
#> round_ERR2585249        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585268        1  0.0000     0.9597 1.000 0.000
#> aberrant_ERR2585356     2  0.3879     0.9120 0.076 0.924
#> round_ERR2585266        1  0.5294     0.8686 0.880 0.120
#> round_ERR2585231        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585230        1  0.0000     0.9597 1.000 0.000
#> round_ERR2585267        1  0.0000     0.9597 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 cell_type(p) k
#> CV:kmeans 155     4.72e-21 2
#> CV:kmeans 144     1.58e-22 3
#> CV:kmeans 151     9.92e-28 4
#> CV:kmeans 141     9.08e-25 5
#> CV:kmeans 123     1.07e-21 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 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-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 0.875           0.936       0.971         0.5031 0.497   0.497
#> 3 3 0.801           0.841       0.934         0.3145 0.761   0.555
#> 4 4 0.786           0.819       0.909         0.1164 0.856   0.615
#> 5 5 0.709           0.658       0.812         0.0545 0.964   0.867
#> 6 6 0.649           0.514       0.734         0.0413 0.951   0.810

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
#> aberrant_ERR2585320     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585338     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585325     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585283     1  0.7219      0.759 0.800 0.200
#> aberrant_ERR2585343     2  0.0938      0.971 0.012 0.988
#> aberrant_ERR2585329     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585317     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585339     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585335     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585287     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585321     2  0.2603      0.946 0.044 0.956
#> aberrant_ERR2585297     1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585337     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585319     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585315     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585336     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585307     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585301     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585326     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585331     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585346     1  0.6438      0.807 0.836 0.164
#> aberrant_ERR2585314     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585298     1  0.4161      0.899 0.916 0.084
#> aberrant_ERR2585345     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585299     1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585309     1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585303     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585313     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585318     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585328     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585330     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585293     1  0.6712      0.791 0.824 0.176
#> aberrant_ERR2585342     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585348     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585352     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585308     1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585349     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585316     2  0.7528      0.721 0.216 0.784
#> aberrant_ERR2585306     1  0.5519      0.849 0.872 0.128
#> aberrant_ERR2585324     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585310     2  0.4939      0.886 0.108 0.892
#> aberrant_ERR2585296     1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585275     1  0.9323      0.491 0.652 0.348
#> aberrant_ERR2585311     2  0.2236      0.952 0.036 0.964
#> aberrant_ERR2585292     1  0.6712      0.791 0.824 0.176
#> aberrant_ERR2585282     2  0.2948      0.938 0.052 0.948
#> aberrant_ERR2585305     2  0.5519      0.861 0.128 0.872
#> aberrant_ERR2585278     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585347     2  0.3584      0.925 0.068 0.932
#> aberrant_ERR2585332     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585280     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585304     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585322     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585279     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585277     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585295     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585333     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585285     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585286     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585294     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585300     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585334     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585361     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585372     2  0.0000      0.978 0.000 1.000
#> round_ERR2585217        1  0.8861      0.584 0.696 0.304
#> round_ERR2585205        1  0.0000      0.960 1.000 0.000
#> round_ERR2585214        2  0.3584      0.920 0.068 0.932
#> round_ERR2585202        2  0.5178      0.866 0.116 0.884
#> aberrant_ERR2585367     2  0.0000      0.978 0.000 1.000
#> round_ERR2585220        1  0.0000      0.960 1.000 0.000
#> round_ERR2585238        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585276     2  0.0376      0.976 0.004 0.996
#> round_ERR2585218        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585363     2  0.0000      0.978 0.000 1.000
#> round_ERR2585201        1  0.4298      0.896 0.912 0.088
#> round_ERR2585210        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585362     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585360     2  0.0672      0.973 0.008 0.992
#> round_ERR2585209        1  0.0000      0.960 1.000 0.000
#> round_ERR2585242        1  0.2778      0.927 0.952 0.048
#> round_ERR2585216        1  0.0000      0.960 1.000 0.000
#> round_ERR2585219        1  0.0000      0.960 1.000 0.000
#> round_ERR2585237        2  0.9491      0.408 0.368 0.632
#> round_ERR2585198        2  0.5842      0.835 0.140 0.860
#> round_ERR2585211        1  0.0000      0.960 1.000 0.000
#> round_ERR2585206        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585281     2  0.0000      0.978 0.000 1.000
#> round_ERR2585212        1  0.0000      0.960 1.000 0.000
#> round_ERR2585221        1  0.0000      0.960 1.000 0.000
#> round_ERR2585243        1  0.0000      0.960 1.000 0.000
#> round_ERR2585204        2  0.1843      0.957 0.028 0.972
#> round_ERR2585213        2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585373     2  0.0938      0.971 0.012 0.988
#> aberrant_ERR2585358     2  0.0672      0.973 0.008 0.992
#> aberrant_ERR2585365     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585359     2  0.3879      0.916 0.076 0.924
#> aberrant_ERR2585370     2  0.0000      0.978 0.000 1.000
#> round_ERR2585215        1  0.0000      0.960 1.000 0.000
#> round_ERR2585262        1  0.4939      0.875 0.892 0.108
#> round_ERR2585199        2  0.1633      0.961 0.024 0.976
#> aberrant_ERR2585369     2  0.0000      0.978 0.000 1.000
#> round_ERR2585208        1  0.0000      0.960 1.000 0.000
#> round_ERR2585252        1  0.0000      0.960 1.000 0.000
#> round_ERR2585236        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585284     1  0.0000      0.960 1.000 0.000
#> round_ERR2585224        1  0.0000      0.960 1.000 0.000
#> round_ERR2585260        1  0.0000      0.960 1.000 0.000
#> round_ERR2585229        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585364     1  0.9775      0.324 0.588 0.412
#> round_ERR2585253        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585368     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585371     2  0.0000      0.978 0.000 1.000
#> round_ERR2585239        1  0.0000      0.960 1.000 0.000
#> round_ERR2585273        1  0.0000      0.960 1.000 0.000
#> round_ERR2585256        1  0.0000      0.960 1.000 0.000
#> round_ERR2585272        1  0.0000      0.960 1.000 0.000
#> round_ERR2585246        1  0.0000      0.960 1.000 0.000
#> round_ERR2585261        1  0.0672      0.955 0.992 0.008
#> round_ERR2585254        1  0.1184      0.949 0.984 0.016
#> round_ERR2585225        1  0.3584      0.912 0.932 0.068
#> round_ERR2585235        1  0.0000      0.960 1.000 0.000
#> round_ERR2585271        1  0.0000      0.960 1.000 0.000
#> round_ERR2585251        1  0.0000      0.960 1.000 0.000
#> round_ERR2585255        1  0.4562      0.888 0.904 0.096
#> round_ERR2585257        1  0.1633      0.944 0.976 0.024
#> round_ERR2585226        1  0.0000      0.960 1.000 0.000
#> round_ERR2585265        1  0.0000      0.960 1.000 0.000
#> round_ERR2585259        1  0.0000      0.960 1.000 0.000
#> round_ERR2585247        1  0.0000      0.960 1.000 0.000
#> round_ERR2585241        1  0.0000      0.960 1.000 0.000
#> round_ERR2585263        1  0.0000      0.960 1.000 0.000
#> round_ERR2585264        1  0.0000      0.960 1.000 0.000
#> round_ERR2585233        1  0.0000      0.960 1.000 0.000
#> round_ERR2585223        1  0.0000      0.960 1.000 0.000
#> round_ERR2585234        1  0.9944      0.188 0.544 0.456
#> round_ERR2585222        1  0.0000      0.960 1.000 0.000
#> round_ERR2585228        1  0.0000      0.960 1.000 0.000
#> round_ERR2585248        1  0.0000      0.960 1.000 0.000
#> round_ERR2585240        1  0.3431      0.915 0.936 0.064
#> round_ERR2585270        1  0.0000      0.960 1.000 0.000
#> round_ERR2585232        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585341     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585355     2  0.0000      0.978 0.000 1.000
#> round_ERR2585227        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585351     2  0.1633      0.962 0.024 0.976
#> round_ERR2585269        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585357     2  0.0000      0.978 0.000 1.000
#> aberrant_ERR2585350     2  0.0000      0.978 0.000 1.000
#> round_ERR2585250        1  0.0000      0.960 1.000 0.000
#> round_ERR2585245        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585353     2  0.0000      0.978 0.000 1.000
#> round_ERR2585258        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585354     2  0.0000      0.978 0.000 1.000
#> round_ERR2585249        1  0.0000      0.960 1.000 0.000
#> round_ERR2585268        1  0.0000      0.960 1.000 0.000
#> aberrant_ERR2585356     2  0.5629      0.854 0.132 0.868
#> round_ERR2585266        1  0.4022      0.902 0.920 0.080
#> round_ERR2585231        1  0.0000      0.960 1.000 0.000
#> round_ERR2585230        1  0.0000      0.960 1.000 0.000
#> round_ERR2585267        1  0.0000      0.960 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 cell_type(p) k
#> CV:skmeans 156     2.86e-21 2
#> CV:skmeans 148     1.81e-22 3
#> CV:skmeans 149     2.65e-27 4
#> CV:skmeans 131     1.19e-22 5
#> CV:skmeans 106     3.76e-18 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 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-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.314           0.721       0.863         0.2910 0.771   0.771
#> 3 3 0.192           0.462       0.705         0.8226 0.585   0.487
#> 4 4 0.219           0.218       0.626         0.1104 0.653   0.442
#> 5 5 0.268           0.427       0.640         0.0431 0.737   0.476
#> 6 6 0.382           0.303       0.695         0.0676 0.731   0.414

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
#> aberrant_ERR2585320     1  0.6973     0.7366 0.812 0.188
#> aberrant_ERR2585338     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585325     1  0.4161     0.8154 0.916 0.084
#> aberrant_ERR2585283     2  0.0000     0.7243 0.000 1.000
#> aberrant_ERR2585343     2  0.9881     0.3067 0.436 0.564
#> aberrant_ERR2585329     1  0.0376     0.8336 0.996 0.004
#> aberrant_ERR2585317     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585339     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585335     1  0.6343     0.7791 0.840 0.160
#> aberrant_ERR2585287     2  0.5946     0.6663 0.144 0.856
#> aberrant_ERR2585321     1  0.9970     0.0692 0.532 0.468
#> aberrant_ERR2585297     1  0.8499     0.6789 0.724 0.276
#> aberrant_ERR2585337     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585319     1  0.4939     0.8031 0.892 0.108
#> aberrant_ERR2585315     1  0.0938     0.8336 0.988 0.012
#> aberrant_ERR2585336     1  0.0672     0.8342 0.992 0.008
#> aberrant_ERR2585307     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585301     1  0.4161     0.8202 0.916 0.084
#> aberrant_ERR2585326     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585331     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585346     2  0.0000     0.7243 0.000 1.000
#> aberrant_ERR2585314     1  0.2423     0.8316 0.960 0.040
#> aberrant_ERR2585298     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585345     1  0.0376     0.8336 0.996 0.004
#> aberrant_ERR2585299     1  0.7139     0.7566 0.804 0.196
#> aberrant_ERR2585309     1  0.9427     0.5330 0.640 0.360
#> aberrant_ERR2585303     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585313     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585318     1  0.8661     0.6540 0.712 0.288
#> aberrant_ERR2585328     1  0.8207     0.6781 0.744 0.256
#> aberrant_ERR2585330     1  0.9000     0.5784 0.684 0.316
#> aberrant_ERR2585293     2  0.0000     0.7243 0.000 1.000
#> aberrant_ERR2585342     1  0.8499     0.6282 0.724 0.276
#> aberrant_ERR2585348     1  0.8763     0.5542 0.704 0.296
#> aberrant_ERR2585352     1  0.2603     0.8322 0.956 0.044
#> aberrant_ERR2585308     2  0.9580     0.4207 0.380 0.620
#> aberrant_ERR2585349     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585316     2  0.9491     0.4613 0.368 0.632
#> aberrant_ERR2585306     1  0.9909     0.2568 0.556 0.444
#> aberrant_ERR2585324     1  0.3274     0.8243 0.940 0.060
#> aberrant_ERR2585310     1  0.0672     0.8341 0.992 0.008
#> aberrant_ERR2585296     1  0.3879     0.8220 0.924 0.076
#> aberrant_ERR2585275     2  0.7139     0.6973 0.196 0.804
#> aberrant_ERR2585311     1  0.8955     0.6186 0.688 0.312
#> aberrant_ERR2585292     2  0.0000     0.7243 0.000 1.000
#> aberrant_ERR2585282     2  0.9970     0.1122 0.468 0.532
#> aberrant_ERR2585305     1  0.7139     0.7552 0.804 0.196
#> aberrant_ERR2585278     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585347     2  0.7376     0.6945 0.208 0.792
#> aberrant_ERR2585332     1  0.9491     0.2904 0.632 0.368
#> aberrant_ERR2585280     1  0.5629     0.7876 0.868 0.132
#> aberrant_ERR2585304     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585322     1  0.0376     0.8336 0.996 0.004
#> aberrant_ERR2585279     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585277     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585295     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585333     1  0.8661     0.6248 0.712 0.288
#> aberrant_ERR2585285     1  0.5059     0.8043 0.888 0.112
#> aberrant_ERR2585286     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585294     1  0.5059     0.8027 0.888 0.112
#> aberrant_ERR2585300     1  0.9963     0.1225 0.536 0.464
#> aberrant_ERR2585334     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585361     1  0.6148     0.7698 0.848 0.152
#> aberrant_ERR2585372     1  0.9000     0.6012 0.684 0.316
#> round_ERR2585217        1  0.0672     0.8340 0.992 0.008
#> round_ERR2585205        1  0.8144     0.7070 0.748 0.252
#> round_ERR2585214        1  0.0000     0.8328 1.000 0.000
#> round_ERR2585202        1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585367     1  0.3114     0.8257 0.944 0.056
#> round_ERR2585220        1  0.5519     0.8090 0.872 0.128
#> round_ERR2585238        1  0.8555     0.6736 0.720 0.280
#> aberrant_ERR2585276     1  0.6438     0.7599 0.836 0.164
#> round_ERR2585218        1  0.7453     0.7431 0.788 0.212
#> aberrant_ERR2585363     1  0.0672     0.8342 0.992 0.008
#> round_ERR2585201        1  0.0376     0.8330 0.996 0.004
#> round_ERR2585210        1  0.8661     0.6626 0.712 0.288
#> aberrant_ERR2585362     1  0.7674     0.7325 0.776 0.224
#> aberrant_ERR2585360     1  0.7219     0.7477 0.800 0.200
#> round_ERR2585209        1  0.0938     0.8327 0.988 0.012
#> round_ERR2585242        1  0.0376     0.8330 0.996 0.004
#> round_ERR2585216        1  0.5519     0.7962 0.872 0.128
#> round_ERR2585219        1  0.6887     0.7615 0.816 0.184
#> round_ERR2585237        1  0.0000     0.8328 1.000 0.000
#> round_ERR2585198        1  0.0000     0.8328 1.000 0.000
#> round_ERR2585211        1  0.8499     0.6811 0.724 0.276
#> round_ERR2585206        1  0.8144     0.7064 0.748 0.252
#> aberrant_ERR2585281     1  0.0376     0.8333 0.996 0.004
#> round_ERR2585212        1  0.6048     0.7899 0.852 0.148
#> round_ERR2585221        1  0.9209     0.5841 0.664 0.336
#> round_ERR2585243        1  0.7299     0.7571 0.796 0.204
#> round_ERR2585204        1  0.0000     0.8328 1.000 0.000
#> round_ERR2585213        1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585373     1  0.9732     0.3990 0.596 0.404
#> aberrant_ERR2585358     2  0.7219     0.6962 0.200 0.800
#> aberrant_ERR2585365     1  0.0938     0.8344 0.988 0.012
#> aberrant_ERR2585359     2  0.0000     0.7243 0.000 1.000
#> aberrant_ERR2585370     1  0.0000     0.8328 1.000 0.000
#> round_ERR2585215        1  0.9881     0.3129 0.564 0.436
#> round_ERR2585262        1  0.0376     0.8330 0.996 0.004
#> round_ERR2585199        1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585369     1  0.7219     0.7295 0.800 0.200
#> round_ERR2585208        1  0.9393     0.5392 0.644 0.356
#> round_ERR2585252        1  0.8861     0.6394 0.696 0.304
#> round_ERR2585236        1  0.8144     0.7101 0.748 0.252
#> aberrant_ERR2585284     2  0.0000     0.7243 0.000 1.000
#> round_ERR2585224        1  0.9933     0.2508 0.548 0.452
#> round_ERR2585260        1  0.7815     0.7292 0.768 0.232
#> round_ERR2585229        1  0.9087     0.6062 0.676 0.324
#> aberrant_ERR2585364     2  0.0672     0.7229 0.008 0.992
#> round_ERR2585253        1  0.9710     0.4295 0.600 0.400
#> aberrant_ERR2585368     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585371     1  0.0000     0.8328 1.000 0.000
#> round_ERR2585239        1  0.8386     0.6898 0.732 0.268
#> round_ERR2585273        1  0.5519     0.7988 0.872 0.128
#> round_ERR2585256        1  0.1414     0.8335 0.980 0.020
#> round_ERR2585272        1  0.1843     0.8324 0.972 0.028
#> round_ERR2585246        1  0.6048     0.7946 0.852 0.148
#> round_ERR2585261        1  0.0000     0.8328 1.000 0.000
#> round_ERR2585254        1  0.0376     0.8330 0.996 0.004
#> round_ERR2585225        1  0.0672     0.8330 0.992 0.008
#> round_ERR2585235        1  0.9661     0.4387 0.608 0.392
#> round_ERR2585271        1  0.9323     0.5591 0.652 0.348
#> round_ERR2585251        1  0.2948     0.8281 0.948 0.052
#> round_ERR2585255        1  0.0938     0.8325 0.988 0.012
#> round_ERR2585257        1  0.0376     0.8330 0.996 0.004
#> round_ERR2585226        1  0.5842     0.7985 0.860 0.140
#> round_ERR2585265        1  0.0672     0.8341 0.992 0.008
#> round_ERR2585259        1  0.3431     0.8265 0.936 0.064
#> round_ERR2585247        1  0.5842     0.7904 0.860 0.140
#> round_ERR2585241        1  0.6247     0.7761 0.844 0.156
#> round_ERR2585263        1  0.3431     0.8270 0.936 0.064
#> round_ERR2585264        2  0.5178     0.7261 0.116 0.884
#> round_ERR2585233        1  0.1843     0.8328 0.972 0.028
#> round_ERR2585223        1  0.6623     0.7697 0.828 0.172
#> round_ERR2585234        1  0.0376     0.8330 0.996 0.004
#> round_ERR2585222        1  0.7745     0.7304 0.772 0.228
#> round_ERR2585228        1  0.6531     0.7690 0.832 0.168
#> round_ERR2585248        2  0.4562     0.7293 0.096 0.904
#> round_ERR2585240        1  0.0376     0.8330 0.996 0.004
#> round_ERR2585270        1  0.4815     0.8100 0.896 0.104
#> round_ERR2585232        1  0.0938     0.8337 0.988 0.012
#> aberrant_ERR2585341     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585355     1  0.0000     0.8328 1.000 0.000
#> round_ERR2585227        1  0.2423     0.8308 0.960 0.040
#> aberrant_ERR2585351     1  0.5519     0.8027 0.872 0.128
#> round_ERR2585269        1  0.9460     0.5241 0.636 0.364
#> aberrant_ERR2585357     1  0.0000     0.8328 1.000 0.000
#> aberrant_ERR2585350     1  0.0000     0.8328 1.000 0.000
#> round_ERR2585250        1  0.6712     0.7798 0.824 0.176
#> round_ERR2585245        2  0.8499     0.6061 0.276 0.724
#> aberrant_ERR2585353     2  0.9993     0.0688 0.484 0.516
#> round_ERR2585258        1  0.7219     0.7527 0.800 0.200
#> aberrant_ERR2585354     1  0.1414     0.8327 0.980 0.020
#> round_ERR2585249        1  0.9170     0.5903 0.668 0.332
#> round_ERR2585268        1  0.1184     0.8347 0.984 0.016
#> aberrant_ERR2585356     2  0.9775     0.3443 0.412 0.588
#> round_ERR2585266        1  0.0000     0.8328 1.000 0.000
#> round_ERR2585231        1  0.9580     0.4873 0.620 0.380
#> round_ERR2585230        1  0.5519     0.8002 0.872 0.128
#> round_ERR2585267        2  0.9815     0.3018 0.420 0.580

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)

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

Signature heatmaps where rows are not scaled:

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

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 cell_type(p) k
#> CV:pam 143     9.46e-02 2
#> CV:pam 102     4.63e-15 3
#> CV:pam  41     2.04e-07 4
#> CV:pam  90     2.76e-10 5
#> CV:pam  60     9.11e-04 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 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-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 1.000           0.988       0.995         0.5034 0.497   0.497
#> 3 3 0.810           0.878       0.922         0.2310 0.894   0.786
#> 4 4 0.725           0.789       0.886         0.1598 0.870   0.670
#> 5 5 0.734           0.605       0.837         0.0480 0.940   0.797
#> 6 6 0.665           0.624       0.774         0.0366 0.937   0.779

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
#> aberrant_ERR2585320     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585338     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585325     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585283     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585343     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585329     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585317     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585339     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585335     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585287     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585321     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585297     1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585337     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585319     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585315     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585336     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585307     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585301     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585326     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585331     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585346     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585314     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585298     1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585345     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585299     1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585309     1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585303     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585313     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585318     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585328     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585330     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585293     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585342     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585348     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585352     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585308     1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585349     2  0.8207      0.666 0.256 0.744
#> aberrant_ERR2585316     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585306     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585324     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585310     2  0.6343      0.813 0.160 0.840
#> aberrant_ERR2585296     1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585275     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585311     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585292     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585282     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585305     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585278     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585347     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585332     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585280     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585304     2  0.8813      0.585 0.300 0.700
#> aberrant_ERR2585322     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585279     2  0.4431      0.897 0.092 0.908
#> aberrant_ERR2585277     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585295     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585333     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585285     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585286     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585294     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585300     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585334     2  0.2603      0.948 0.044 0.956
#> aberrant_ERR2585361     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585372     2  0.0000      0.989 0.000 1.000
#> round_ERR2585217        1  0.0000      1.000 1.000 0.000
#> round_ERR2585205        1  0.0000      1.000 1.000 0.000
#> round_ERR2585214        1  0.0000      1.000 1.000 0.000
#> round_ERR2585202        1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585367     2  0.0000      0.989 0.000 1.000
#> round_ERR2585220        1  0.0000      1.000 1.000 0.000
#> round_ERR2585238        1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585276     2  0.0000      0.989 0.000 1.000
#> round_ERR2585218        1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585363     2  0.0000      0.989 0.000 1.000
#> round_ERR2585201        1  0.0000      1.000 1.000 0.000
#> round_ERR2585210        1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585362     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585360     2  0.0000      0.989 0.000 1.000
#> round_ERR2585209        1  0.0000      1.000 1.000 0.000
#> round_ERR2585242        1  0.0000      1.000 1.000 0.000
#> round_ERR2585216        1  0.0000      1.000 1.000 0.000
#> round_ERR2585219        1  0.0000      1.000 1.000 0.000
#> round_ERR2585237        1  0.0000      1.000 1.000 0.000
#> round_ERR2585198        1  0.0000      1.000 1.000 0.000
#> round_ERR2585211        1  0.0000      1.000 1.000 0.000
#> round_ERR2585206        1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585281     2  0.0000      0.989 0.000 1.000
#> round_ERR2585212        1  0.0000      1.000 1.000 0.000
#> round_ERR2585221        1  0.0000      1.000 1.000 0.000
#> round_ERR2585243        1  0.0000      1.000 1.000 0.000
#> round_ERR2585204        1  0.0000      1.000 1.000 0.000
#> round_ERR2585213        1  0.1414      0.979 0.980 0.020
#> aberrant_ERR2585373     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585358     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585365     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585359     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585370     2  0.0000      0.989 0.000 1.000
#> round_ERR2585215        1  0.0000      1.000 1.000 0.000
#> round_ERR2585262        1  0.0000      1.000 1.000 0.000
#> round_ERR2585199        1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585369     2  0.0000      0.989 0.000 1.000
#> round_ERR2585208        1  0.0000      1.000 1.000 0.000
#> round_ERR2585252        1  0.0000      1.000 1.000 0.000
#> round_ERR2585236        1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585284     2  0.0376      0.986 0.004 0.996
#> round_ERR2585224        1  0.0000      1.000 1.000 0.000
#> round_ERR2585260        1  0.0000      1.000 1.000 0.000
#> round_ERR2585229        1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585364     2  0.0000      0.989 0.000 1.000
#> round_ERR2585253        1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585368     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585371     2  0.0000      0.989 0.000 1.000
#> round_ERR2585239        1  0.0000      1.000 1.000 0.000
#> round_ERR2585273        1  0.0000      1.000 1.000 0.000
#> round_ERR2585256        1  0.0000      1.000 1.000 0.000
#> round_ERR2585272        1  0.0000      1.000 1.000 0.000
#> round_ERR2585246        1  0.0000      1.000 1.000 0.000
#> round_ERR2585261        1  0.0000      1.000 1.000 0.000
#> round_ERR2585254        1  0.0000      1.000 1.000 0.000
#> round_ERR2585225        1  0.0000      1.000 1.000 0.000
#> round_ERR2585235        1  0.0000      1.000 1.000 0.000
#> round_ERR2585271        1  0.0000      1.000 1.000 0.000
#> round_ERR2585251        1  0.0000      1.000 1.000 0.000
#> round_ERR2585255        1  0.0000      1.000 1.000 0.000
#> round_ERR2585257        1  0.0000      1.000 1.000 0.000
#> round_ERR2585226        1  0.0000      1.000 1.000 0.000
#> round_ERR2585265        1  0.0000      1.000 1.000 0.000
#> round_ERR2585259        1  0.0000      1.000 1.000 0.000
#> round_ERR2585247        1  0.0000      1.000 1.000 0.000
#> round_ERR2585241        1  0.0000      1.000 1.000 0.000
#> round_ERR2585263        1  0.0000      1.000 1.000 0.000
#> round_ERR2585264        1  0.0000      1.000 1.000 0.000
#> round_ERR2585233        1  0.0000      1.000 1.000 0.000
#> round_ERR2585223        1  0.0000      1.000 1.000 0.000
#> round_ERR2585234        1  0.0000      1.000 1.000 0.000
#> round_ERR2585222        1  0.0000      1.000 1.000 0.000
#> round_ERR2585228        1  0.0000      1.000 1.000 0.000
#> round_ERR2585248        1  0.0000      1.000 1.000 0.000
#> round_ERR2585240        1  0.0000      1.000 1.000 0.000
#> round_ERR2585270        1  0.0000      1.000 1.000 0.000
#> round_ERR2585232        1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585341     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585355     2  0.0000      0.989 0.000 1.000
#> round_ERR2585227        1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585351     2  0.0000      0.989 0.000 1.000
#> round_ERR2585269        1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585357     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585350     2  0.0000      0.989 0.000 1.000
#> round_ERR2585250        1  0.0000      1.000 1.000 0.000
#> round_ERR2585245        1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585353     2  0.0000      0.989 0.000 1.000
#> round_ERR2585258        1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585354     2  0.0000      0.989 0.000 1.000
#> round_ERR2585249        1  0.0000      1.000 1.000 0.000
#> round_ERR2585268        1  0.0000      1.000 1.000 0.000
#> aberrant_ERR2585356     2  0.0000      0.989 0.000 1.000
#> round_ERR2585266        1  0.0000      1.000 1.000 0.000
#> round_ERR2585231        1  0.0000      1.000 1.000 0.000
#> round_ERR2585230        1  0.0000      1.000 1.000 0.000
#> round_ERR2585267        1  0.0000      1.000 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-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 cell_type(p) k
#> CV:mclust 160     5.69e-31 2
#> CV:mclust 151     1.88e-29 3
#> CV:mclust 146     1.99e-27 4
#> CV:mclust 116     4.06e-20 5
#> CV:mclust 119     8.64e-21 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 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-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 0.961           0.950       0.979         0.5013 0.498   0.498
#> 3 3 0.835           0.871       0.940         0.2905 0.794   0.609
#> 4 4 0.613           0.713       0.842         0.0794 0.959   0.887
#> 5 5 0.577           0.461       0.736         0.0647 0.929   0.805
#> 6 6 0.594           0.574       0.729         0.0474 0.910   0.730

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
#> aberrant_ERR2585320     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585338     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585325     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585283     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585343     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585329     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585317     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585339     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585335     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585287     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585321     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585297     1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585337     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585319     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585315     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585336     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585307     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585301     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585326     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585331     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585346     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585314     2  0.0938      0.979 0.012 0.988
#> aberrant_ERR2585298     1  0.3274      0.915 0.940 0.060
#> aberrant_ERR2585345     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585299     1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585309     1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585303     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585313     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585318     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585328     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585330     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585293     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585342     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585348     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585352     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585308     1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585349     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585316     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585306     2  0.2423      0.951 0.040 0.960
#> aberrant_ERR2585324     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585310     1  0.9661      0.380 0.608 0.392
#> aberrant_ERR2585296     1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585275     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585311     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585292     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585282     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585305     2  0.6801      0.773 0.180 0.820
#> aberrant_ERR2585278     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585347     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585332     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585280     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585304     2  0.9323      0.447 0.348 0.652
#> aberrant_ERR2585322     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585279     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585277     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585295     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585333     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585285     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585286     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585294     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585300     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585334     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585361     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585372     2  0.0000      0.989 0.000 1.000
#> round_ERR2585217        1  0.0376      0.963 0.996 0.004
#> round_ERR2585205        1  0.0000      0.966 1.000 0.000
#> round_ERR2585214        1  0.9881      0.274 0.564 0.436
#> round_ERR2585202        1  0.8081      0.684 0.752 0.248
#> aberrant_ERR2585367     2  0.0000      0.989 0.000 1.000
#> round_ERR2585220        1  0.0000      0.966 1.000 0.000
#> round_ERR2585238        1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585276     2  0.0000      0.989 0.000 1.000
#> round_ERR2585218        1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585363     2  0.0000      0.989 0.000 1.000
#> round_ERR2585201        1  0.5946      0.827 0.856 0.144
#> round_ERR2585210        1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585362     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585360     2  0.0000      0.989 0.000 1.000
#> round_ERR2585209        1  0.0000      0.966 1.000 0.000
#> round_ERR2585242        1  0.0000      0.966 1.000 0.000
#> round_ERR2585216        1  0.0000      0.966 1.000 0.000
#> round_ERR2585219        1  0.0000      0.966 1.000 0.000
#> round_ERR2585237        1  0.0000      0.966 1.000 0.000
#> round_ERR2585198        1  0.0672      0.960 0.992 0.008
#> round_ERR2585211        1  0.0000      0.966 1.000 0.000
#> round_ERR2585206        1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585281     2  0.0000      0.989 0.000 1.000
#> round_ERR2585212        1  0.0000      0.966 1.000 0.000
#> round_ERR2585221        1  0.0000      0.966 1.000 0.000
#> round_ERR2585243        1  0.0000      0.966 1.000 0.000
#> round_ERR2585204        1  0.9661      0.396 0.608 0.392
#> round_ERR2585213        2  0.2236      0.954 0.036 0.964
#> aberrant_ERR2585373     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585358     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585365     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585359     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585370     2  0.0000      0.989 0.000 1.000
#> round_ERR2585215        1  0.0000      0.966 1.000 0.000
#> round_ERR2585262        2  0.7376      0.731 0.208 0.792
#> round_ERR2585199        1  0.1633      0.947 0.976 0.024
#> aberrant_ERR2585369     2  0.0000      0.989 0.000 1.000
#> round_ERR2585208        1  0.0000      0.966 1.000 0.000
#> round_ERR2585252        1  0.0000      0.966 1.000 0.000
#> round_ERR2585236        1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585284     2  0.0000      0.989 0.000 1.000
#> round_ERR2585224        1  0.0000      0.966 1.000 0.000
#> round_ERR2585260        1  0.0000      0.966 1.000 0.000
#> round_ERR2585229        1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585364     2  0.0000      0.989 0.000 1.000
#> round_ERR2585253        1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585368     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585371     2  0.0000      0.989 0.000 1.000
#> round_ERR2585239        1  0.0000      0.966 1.000 0.000
#> round_ERR2585273        1  0.0000      0.966 1.000 0.000
#> round_ERR2585256        1  0.0000      0.966 1.000 0.000
#> round_ERR2585272        1  0.0000      0.966 1.000 0.000
#> round_ERR2585246        1  0.0000      0.966 1.000 0.000
#> round_ERR2585261        1  0.0000      0.966 1.000 0.000
#> round_ERR2585254        1  0.0000      0.966 1.000 0.000
#> round_ERR2585225        1  0.8713      0.611 0.708 0.292
#> round_ERR2585235        1  0.0000      0.966 1.000 0.000
#> round_ERR2585271        1  0.0000      0.966 1.000 0.000
#> round_ERR2585251        1  0.0000      0.966 1.000 0.000
#> round_ERR2585255        1  0.9248      0.517 0.660 0.340
#> round_ERR2585257        1  0.0000      0.966 1.000 0.000
#> round_ERR2585226        1  0.0000      0.966 1.000 0.000
#> round_ERR2585265        1  0.0000      0.966 1.000 0.000
#> round_ERR2585259        1  0.0000      0.966 1.000 0.000
#> round_ERR2585247        1  0.0000      0.966 1.000 0.000
#> round_ERR2585241        1  0.0000      0.966 1.000 0.000
#> round_ERR2585263        1  0.0000      0.966 1.000 0.000
#> round_ERR2585264        1  0.0000      0.966 1.000 0.000
#> round_ERR2585233        1  0.0000      0.966 1.000 0.000
#> round_ERR2585223        1  0.0000      0.966 1.000 0.000
#> round_ERR2585234        1  0.0000      0.966 1.000 0.000
#> round_ERR2585222        1  0.0000      0.966 1.000 0.000
#> round_ERR2585228        1  0.0000      0.966 1.000 0.000
#> round_ERR2585248        1  0.0000      0.966 1.000 0.000
#> round_ERR2585240        1  0.0376      0.963 0.996 0.004
#> round_ERR2585270        1  0.0000      0.966 1.000 0.000
#> round_ERR2585232        1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585341     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585355     2  0.0000      0.989 0.000 1.000
#> round_ERR2585227        1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585351     2  0.0672      0.982 0.008 0.992
#> round_ERR2585269        1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585357     2  0.0000      0.989 0.000 1.000
#> aberrant_ERR2585350     2  0.0000      0.989 0.000 1.000
#> round_ERR2585250        1  0.0000      0.966 1.000 0.000
#> round_ERR2585245        1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585353     2  0.0000      0.989 0.000 1.000
#> round_ERR2585258        1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585354     2  0.0000      0.989 0.000 1.000
#> round_ERR2585249        1  0.0000      0.966 1.000 0.000
#> round_ERR2585268        1  0.0000      0.966 1.000 0.000
#> aberrant_ERR2585356     2  0.0000      0.989 0.000 1.000
#> round_ERR2585266        1  0.6887      0.778 0.816 0.184
#> round_ERR2585231        1  0.0000      0.966 1.000 0.000
#> round_ERR2585230        1  0.0000      0.966 1.000 0.000
#> round_ERR2585267        1  0.0000      0.966 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-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 cell_type(p) k
#> CV:NMF 156     2.05e-28 2
#> CV:NMF 151     4.96e-22 3
#> CV:NMF 138     2.91e-19 4
#> CV:NMF  93     1.66e-10 5
#> CV:NMF 121     5.43e-15 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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.204           0.459       0.770         0.2982 0.718   0.718
#> 3 3 0.300           0.693       0.825         0.6865 0.596   0.488
#> 4 4 0.446           0.621       0.761         0.2579 0.809   0.614
#> 5 5 0.506           0.486       0.761         0.0832 0.982   0.949
#> 6 6 0.528           0.418       0.707         0.0557 0.855   0.636

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
#> aberrant_ERR2585320     2  0.3431   0.664046 0.064 0.936
#> aberrant_ERR2585338     2  0.0376   0.657948 0.004 0.996
#> aberrant_ERR2585325     2  0.3431   0.664046 0.064 0.936
#> aberrant_ERR2585283     1  0.5059   0.491431 0.888 0.112
#> aberrant_ERR2585343     2  0.6801   0.606066 0.180 0.820
#> aberrant_ERR2585329     2  0.0000   0.656225 0.000 1.000
#> aberrant_ERR2585317     2  0.0000   0.656225 0.000 1.000
#> aberrant_ERR2585339     2  0.0000   0.656225 0.000 1.000
#> aberrant_ERR2585335     2  0.2043   0.665498 0.032 0.968
#> aberrant_ERR2585287     1  0.9815   0.342845 0.580 0.420
#> aberrant_ERR2585321     2  0.5946   0.634175 0.144 0.856
#> aberrant_ERR2585297     1  0.9998   0.332090 0.508 0.492
#> aberrant_ERR2585337     2  0.0000   0.656225 0.000 1.000
#> aberrant_ERR2585319     2  0.1843   0.659916 0.028 0.972
#> aberrant_ERR2585315     2  0.0672   0.658869 0.008 0.992
#> aberrant_ERR2585336     2  0.0000   0.656225 0.000 1.000
#> aberrant_ERR2585307     2  0.2423   0.662089 0.040 0.960
#> aberrant_ERR2585301     2  0.2778   0.665951 0.048 0.952
#> aberrant_ERR2585326     2  0.0000   0.656225 0.000 1.000
#> aberrant_ERR2585331     2  0.0000   0.656225 0.000 1.000
#> aberrant_ERR2585346     1  0.4939   0.490890 0.892 0.108
#> aberrant_ERR2585314     2  0.0000   0.656225 0.000 1.000
#> aberrant_ERR2585298     2  0.8144   0.511042 0.252 0.748
#> aberrant_ERR2585345     2  0.0000   0.656225 0.000 1.000
#> aberrant_ERR2585299     2  0.9977  -0.195690 0.472 0.528
#> aberrant_ERR2585309     1  0.9552   0.619568 0.624 0.376
#> aberrant_ERR2585303     2  0.1184   0.662112 0.016 0.984
#> aberrant_ERR2585313     2  0.0000   0.656225 0.000 1.000
#> aberrant_ERR2585318     2  0.3114   0.667506 0.056 0.944
#> aberrant_ERR2585328     2  0.5629   0.643511 0.132 0.868
#> aberrant_ERR2585330     2  0.1414   0.660923 0.020 0.980
#> aberrant_ERR2585293     1  0.5059   0.491431 0.888 0.112
#> aberrant_ERR2585342     2  0.4161   0.660970 0.084 0.916
#> aberrant_ERR2585348     2  0.5178   0.648263 0.116 0.884
#> aberrant_ERR2585352     2  0.0672   0.656091 0.008 0.992
#> aberrant_ERR2585308     1  0.9933   0.464763 0.548 0.452
#> aberrant_ERR2585349     2  0.2423   0.667634 0.040 0.960
#> aberrant_ERR2585316     2  0.9087   0.392892 0.324 0.676
#> aberrant_ERR2585306     2  0.8955   0.405127 0.312 0.688
#> aberrant_ERR2585324     2  0.1843   0.659916 0.028 0.972
#> aberrant_ERR2585310     2  0.6973   0.595879 0.188 0.812
#> aberrant_ERR2585296     2  0.9000   0.395242 0.316 0.684
#> aberrant_ERR2585275     1  0.7056   0.490238 0.808 0.192
#> aberrant_ERR2585311     2  0.5059   0.646433 0.112 0.888
#> aberrant_ERR2585292     1  0.5059   0.491431 0.888 0.112
#> aberrant_ERR2585282     2  0.5178   0.648194 0.116 0.884
#> aberrant_ERR2585305     2  0.3584   0.667658 0.068 0.932
#> aberrant_ERR2585278     2  0.1184   0.660523 0.016 0.984
#> aberrant_ERR2585347     2  0.7376   0.578770 0.208 0.792
#> aberrant_ERR2585332     2  0.6048   0.631709 0.148 0.852
#> aberrant_ERR2585280     2  0.3274   0.666588 0.060 0.940
#> aberrant_ERR2585304     2  0.6531   0.602847 0.168 0.832
#> aberrant_ERR2585322     2  0.0672   0.659908 0.008 0.992
#> aberrant_ERR2585279     2  0.1184   0.662456 0.016 0.984
#> aberrant_ERR2585277     2  0.0000   0.656225 0.000 1.000
#> aberrant_ERR2585295     2  0.4161   0.657377 0.084 0.916
#> aberrant_ERR2585333     2  0.4690   0.656922 0.100 0.900
#> aberrant_ERR2585285     2  0.2423   0.666974 0.040 0.960
#> aberrant_ERR2585286     2  0.0000   0.656225 0.000 1.000
#> aberrant_ERR2585294     2  0.3431   0.664317 0.064 0.936
#> aberrant_ERR2585300     2  0.6148   0.627856 0.152 0.848
#> aberrant_ERR2585334     2  0.0000   0.656225 0.000 1.000
#> aberrant_ERR2585361     2  0.1414   0.660083 0.020 0.980
#> aberrant_ERR2585372     2  0.2948   0.659486 0.052 0.948
#> round_ERR2585217        2  0.7602   0.556996 0.220 0.780
#> round_ERR2585205        2  0.9977  -0.181198 0.472 0.528
#> round_ERR2585214        2  0.8081   0.517560 0.248 0.752
#> round_ERR2585202        2  0.7602   0.552672 0.220 0.780
#> aberrant_ERR2585367     2  0.3584   0.665287 0.068 0.932
#> round_ERR2585220        2  0.9775   0.123666 0.412 0.588
#> round_ERR2585238        2  0.9993  -0.241252 0.484 0.516
#> aberrant_ERR2585276     2  0.3274   0.669100 0.060 0.940
#> round_ERR2585218        2  0.9970  -0.152277 0.468 0.532
#> aberrant_ERR2585363     2  0.1414   0.661574 0.020 0.980
#> round_ERR2585201        2  0.8016   0.518448 0.244 0.756
#> round_ERR2585210        1  0.9998   0.331587 0.508 0.492
#> aberrant_ERR2585362     2  0.2236   0.663380 0.036 0.964
#> aberrant_ERR2585360     2  0.4298   0.655867 0.088 0.912
#> round_ERR2585209        2  0.8861   0.417218 0.304 0.696
#> round_ERR2585242        2  0.8386   0.483149 0.268 0.732
#> round_ERR2585216        2  0.9815   0.093196 0.420 0.580
#> round_ERR2585219        2  0.9775   0.132396 0.412 0.588
#> round_ERR2585237        2  0.7883   0.531934 0.236 0.764
#> round_ERR2585198        2  0.6973   0.587445 0.188 0.812
#> round_ERR2585211        2  1.0000  -0.305139 0.496 0.504
#> round_ERR2585206        1  1.0000   0.312318 0.504 0.496
#> aberrant_ERR2585281     2  0.1184   0.659395 0.016 0.984
#> round_ERR2585212        2  0.9732   0.145027 0.404 0.596
#> round_ERR2585221        1  0.9954   0.445724 0.540 0.460
#> round_ERR2585243        2  0.9881   0.019043 0.436 0.564
#> round_ERR2585204        2  0.7528   0.556743 0.216 0.784
#> round_ERR2585213        2  0.6887   0.589556 0.184 0.816
#> aberrant_ERR2585373     2  0.5408   0.650149 0.124 0.876
#> aberrant_ERR2585358     2  0.6623   0.614715 0.172 0.828
#> aberrant_ERR2585365     2  0.1184   0.660616 0.016 0.984
#> aberrant_ERR2585359     2  0.7453   0.581398 0.212 0.788
#> aberrant_ERR2585370     2  0.0000   0.656225 0.000 1.000
#> round_ERR2585215        1  0.9963   0.429385 0.536 0.464
#> round_ERR2585262        2  0.8144   0.518777 0.252 0.748
#> round_ERR2585199        2  0.6973   0.587445 0.188 0.812
#> aberrant_ERR2585369     2  0.2603   0.666101 0.044 0.956
#> round_ERR2585208        1  0.9922   0.494340 0.552 0.448
#> round_ERR2585252        1  0.9522   0.623826 0.628 0.372
#> round_ERR2585236        2  0.9286   0.319889 0.344 0.656
#> aberrant_ERR2585284     1  0.1843   0.441703 0.972 0.028
#> round_ERR2585224        1  0.9427   0.632403 0.640 0.360
#> round_ERR2585260        2  0.9881   0.020037 0.436 0.564
#> round_ERR2585229        2  0.9993  -0.257022 0.484 0.516
#> aberrant_ERR2585364     1  0.9977   0.257512 0.528 0.472
#> round_ERR2585253        1  0.9323   0.635164 0.652 0.348
#> aberrant_ERR2585368     2  0.0000   0.656225 0.000 1.000
#> aberrant_ERR2585371     2  0.0000   0.656225 0.000 1.000
#> round_ERR2585239        2  0.9881  -0.000569 0.436 0.564
#> round_ERR2585273        2  0.9988  -0.243367 0.480 0.520
#> round_ERR2585256        2  0.8955   0.410366 0.312 0.688
#> round_ERR2585272        2  0.9922  -0.057461 0.448 0.552
#> round_ERR2585246        1  0.9963   0.426314 0.536 0.464
#> round_ERR2585261        2  0.9087   0.375818 0.324 0.676
#> round_ERR2585254        2  0.7745   0.547295 0.228 0.772
#> round_ERR2585225        2  0.8267   0.503718 0.260 0.740
#> round_ERR2585235        2  0.9896  -0.042433 0.440 0.560
#> round_ERR2585271        2  0.9922  -0.039254 0.448 0.552
#> round_ERR2585251        2  0.9754   0.140028 0.408 0.592
#> round_ERR2585255        2  0.8267   0.505951 0.260 0.740
#> round_ERR2585257        2  0.8207   0.508144 0.256 0.744
#> round_ERR2585226        2  0.9815   0.086061 0.420 0.580
#> round_ERR2585265        2  0.9686   0.173690 0.396 0.604
#> round_ERR2585259        2  0.9491   0.241741 0.368 0.632
#> round_ERR2585247        2  0.9996  -0.265591 0.488 0.512
#> round_ERR2585241        2  0.9988  -0.209465 0.480 0.520
#> round_ERR2585263        2  0.9795   0.117545 0.416 0.584
#> round_ERR2585264        1  0.9323   0.635352 0.652 0.348
#> round_ERR2585233        2  0.8499   0.484896 0.276 0.724
#> round_ERR2585223        2  0.9896  -0.006914 0.440 0.560
#> round_ERR2585234        2  0.7883   0.530441 0.236 0.764
#> round_ERR2585222        2  0.9881   0.014445 0.436 0.564
#> round_ERR2585228        2  0.9896  -0.001454 0.440 0.560
#> round_ERR2585248        1  0.9286   0.633811 0.656 0.344
#> round_ERR2585240        2  0.9732   0.129915 0.404 0.596
#> round_ERR2585270        2  0.9866   0.038967 0.432 0.568
#> round_ERR2585232        2  0.8955   0.413433 0.312 0.688
#> aberrant_ERR2585341     2  0.2778   0.667288 0.048 0.952
#> aberrant_ERR2585355     2  0.0000   0.656225 0.000 1.000
#> round_ERR2585227        2  0.9815   0.075824 0.420 0.580
#> aberrant_ERR2585351     2  0.2778   0.665964 0.048 0.952
#> round_ERR2585269        1  0.9686   0.591977 0.604 0.396
#> aberrant_ERR2585357     2  0.0000   0.656225 0.000 1.000
#> aberrant_ERR2585350     2  0.0000   0.656225 0.000 1.000
#> round_ERR2585250        2  0.9795   0.120306 0.416 0.584
#> round_ERR2585245        1  0.9323   0.635352 0.652 0.348
#> aberrant_ERR2585353     2  0.4690   0.661042 0.100 0.900
#> round_ERR2585258        2  0.9732   0.154336 0.404 0.596
#> aberrant_ERR2585354     2  0.3879   0.659647 0.076 0.924
#> round_ERR2585249        1  0.9661   0.597972 0.608 0.392
#> round_ERR2585268        2  0.9491   0.261800 0.368 0.632
#> aberrant_ERR2585356     2  0.8207   0.515711 0.256 0.744
#> round_ERR2585266        2  0.8386   0.483149 0.268 0.732
#> round_ERR2585231        1  0.9522   0.624354 0.628 0.372
#> round_ERR2585230        2  0.9909  -0.045862 0.444 0.556
#> round_ERR2585267        1  0.9460   0.630205 0.636 0.364

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 cell_type(p) k
#> MAD:hclust  99     7.49e-07 2
#> MAD:hclust 135     6.69e-26 3
#> MAD:hclust 109     8.28e-19 4
#> MAD:hclust  97     2.41e-17 5
#> MAD:hclust  97     1.78e-18 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 0.829           0.932       0.970         0.5013 0.500   0.500
#> 3 3 0.608           0.690       0.838         0.2554 0.804   0.635
#> 4 4 0.655           0.619       0.787         0.1249 0.855   0.634
#> 5 5 0.660           0.742       0.828         0.0748 0.892   0.643
#> 6 6 0.706           0.717       0.797         0.0433 0.917   0.673

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
#> aberrant_ERR2585320     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585338     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585325     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585283     1  0.5946     0.8345 0.856 0.144
#> aberrant_ERR2585343     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585329     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585317     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585339     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585335     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585287     2  0.7139     0.7474 0.196 0.804
#> aberrant_ERR2585321     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585297     1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585337     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585319     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585315     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585336     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585307     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585301     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585326     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585331     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585346     1  0.5737     0.8441 0.864 0.136
#> aberrant_ERR2585314     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585298     1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585345     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585299     1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585309     1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585303     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585313     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585318     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585328     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585330     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585293     1  0.5178     0.8667 0.884 0.116
#> aberrant_ERR2585342     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585348     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585352     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585308     1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585349     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585316     2  0.9491     0.4079 0.368 0.632
#> aberrant_ERR2585306     1  0.6438     0.8113 0.836 0.164
#> aberrant_ERR2585324     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585310     2  0.4939     0.8699 0.108 0.892
#> aberrant_ERR2585296     2  0.9491     0.4618 0.368 0.632
#> aberrant_ERR2585275     1  0.6148     0.8251 0.848 0.152
#> aberrant_ERR2585311     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585292     1  0.5178     0.8667 0.884 0.116
#> aberrant_ERR2585282     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585305     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585278     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585347     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585332     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585280     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585304     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585322     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585279     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585277     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585295     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585333     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585285     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585286     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585294     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585300     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585334     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585361     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585372     2  0.0000     0.9643 0.000 1.000
#> round_ERR2585217        2  0.9044     0.5663 0.320 0.680
#> round_ERR2585205        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585214        2  0.7056     0.7715 0.192 0.808
#> round_ERR2585202        2  0.1633     0.9452 0.024 0.976
#> aberrant_ERR2585367     2  0.0000     0.9643 0.000 1.000
#> round_ERR2585220        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585238        1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585276     2  0.0000     0.9643 0.000 1.000
#> round_ERR2585218        1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585363     2  0.0000     0.9643 0.000 1.000
#> round_ERR2585201        1  0.1633     0.9530 0.976 0.024
#> round_ERR2585210        1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585362     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585360     2  0.0000     0.9643 0.000 1.000
#> round_ERR2585209        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585242        1  0.5946     0.8220 0.856 0.144
#> round_ERR2585216        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585219        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585237        2  0.6148     0.8198 0.152 0.848
#> round_ERR2585198        2  0.5842     0.8329 0.140 0.860
#> round_ERR2585211        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585206        1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585281     2  0.0000     0.9643 0.000 1.000
#> round_ERR2585212        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585221        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585243        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585204        2  0.4939     0.8672 0.108 0.892
#> round_ERR2585213        2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585373     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585358     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585365     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585359     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585370     2  0.0000     0.9643 0.000 1.000
#> round_ERR2585215        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585262        2  0.9087     0.5573 0.324 0.676
#> round_ERR2585199        2  0.0376     0.9613 0.004 0.996
#> aberrant_ERR2585369     2  0.0000     0.9643 0.000 1.000
#> round_ERR2585208        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585252        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585236        1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585284     1  0.5408     0.8579 0.876 0.124
#> round_ERR2585224        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585260        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585229        1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585364     1  0.8499     0.6363 0.724 0.276
#> round_ERR2585253        1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585368     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585371     2  0.0000     0.9643 0.000 1.000
#> round_ERR2585239        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585273        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585256        1  0.0376     0.9699 0.996 0.004
#> round_ERR2585272        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585246        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585261        1  0.9954     0.0859 0.540 0.460
#> round_ERR2585254        2  0.9286     0.5163 0.344 0.656
#> round_ERR2585225        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585235        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585271        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585251        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585255        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585257        1  0.0376     0.9699 0.996 0.004
#> round_ERR2585226        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585265        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585259        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585247        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585241        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585263        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585264        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585233        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585223        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585234        2  0.8386     0.6609 0.268 0.732
#> round_ERR2585222        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585228        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585248        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585240        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585270        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585232        1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585341     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585355     2  0.0000     0.9643 0.000 1.000
#> round_ERR2585227        1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585351     2  0.0000     0.9643 0.000 1.000
#> round_ERR2585269        1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585357     2  0.0000     0.9643 0.000 1.000
#> aberrant_ERR2585350     2  0.0000     0.9643 0.000 1.000
#> round_ERR2585250        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585245        1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585353     2  0.0000     0.9643 0.000 1.000
#> round_ERR2585258        1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585354     2  0.0000     0.9643 0.000 1.000
#> round_ERR2585249        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585268        1  0.0000     0.9730 1.000 0.000
#> aberrant_ERR2585356     2  0.1184     0.9515 0.016 0.984
#> round_ERR2585266        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585231        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585230        1  0.0000     0.9730 1.000 0.000
#> round_ERR2585267        1  0.0000     0.9730 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 cell_type(p) k
#> MAD:kmeans 157     1.66e-17 2
#> MAD:kmeans 141     2.34e-21 3
#> MAD:kmeans 126     1.04e-21 4
#> MAD:kmeans 146     4.45e-25 5
#> MAD:kmeans 139     1.28e-23 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 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-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 0.877           0.926       0.970         0.5029 0.498   0.498
#> 3 3 0.871           0.883       0.949         0.3124 0.770   0.569
#> 4 4 0.828           0.830       0.923         0.1201 0.845   0.592
#> 5 5 0.725           0.665       0.817         0.0533 0.969   0.885
#> 6 6 0.669           0.617       0.753         0.0361 0.975   0.896

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
#> aberrant_ERR2585320     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585338     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585325     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585283     1  0.5519      0.851 0.872 0.128
#> aberrant_ERR2585343     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585329     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585317     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585339     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585335     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585287     2  0.8861      0.549 0.304 0.696
#> aberrant_ERR2585321     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585297     1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585337     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585319     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585315     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585336     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585307     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585301     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585326     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585331     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585346     1  0.5408      0.855 0.876 0.124
#> aberrant_ERR2585314     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585298     1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585345     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585299     1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585309     1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585303     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585313     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585318     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585328     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585330     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585293     1  0.4161      0.896 0.916 0.084
#> aberrant_ERR2585342     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585348     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585352     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585308     1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585349     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585316     2  0.9996      0.014 0.488 0.512
#> aberrant_ERR2585306     1  0.5408      0.857 0.876 0.124
#> aberrant_ERR2585324     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585310     2  0.6623      0.791 0.172 0.828
#> aberrant_ERR2585296     1  0.8763      0.574 0.704 0.296
#> aberrant_ERR2585275     1  0.5842      0.837 0.860 0.140
#> aberrant_ERR2585311     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585292     1  0.4161      0.896 0.916 0.084
#> aberrant_ERR2585282     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585305     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585278     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585347     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585332     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585280     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585304     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585322     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585279     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585277     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585295     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585333     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585285     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585286     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585294     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585300     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585334     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585361     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585372     2  0.0000      0.967 0.000 1.000
#> round_ERR2585217        2  0.9970      0.139 0.468 0.532
#> round_ERR2585205        1  0.0000      0.968 1.000 0.000
#> round_ERR2585214        2  0.7299      0.746 0.204 0.796
#> round_ERR2585202        2  0.3431      0.910 0.064 0.936
#> aberrant_ERR2585367     2  0.0000      0.967 0.000 1.000
#> round_ERR2585220        1  0.0000      0.968 1.000 0.000
#> round_ERR2585238        1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585276     2  0.0000      0.967 0.000 1.000
#> round_ERR2585218        1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585363     2  0.0000      0.967 0.000 1.000
#> round_ERR2585201        1  0.0000      0.968 1.000 0.000
#> round_ERR2585210        1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585362     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585360     2  0.0000      0.967 0.000 1.000
#> round_ERR2585209        1  0.0000      0.968 1.000 0.000
#> round_ERR2585242        1  0.0938      0.959 0.988 0.012
#> round_ERR2585216        1  0.0000      0.968 1.000 0.000
#> round_ERR2585219        1  0.0000      0.968 1.000 0.000
#> round_ERR2585237        2  0.5842      0.830 0.140 0.860
#> round_ERR2585198        2  0.5842      0.829 0.140 0.860
#> round_ERR2585211        1  0.0000      0.968 1.000 0.000
#> round_ERR2585206        1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585281     2  0.0000      0.967 0.000 1.000
#> round_ERR2585212        1  0.0000      0.968 1.000 0.000
#> round_ERR2585221        1  0.0000      0.968 1.000 0.000
#> round_ERR2585243        1  0.0000      0.968 1.000 0.000
#> round_ERR2585204        2  0.4562      0.878 0.096 0.904
#> round_ERR2585213        2  0.1184      0.954 0.016 0.984
#> aberrant_ERR2585373     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585358     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585365     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585359     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585370     2  0.0000      0.967 0.000 1.000
#> round_ERR2585215        1  0.0000      0.968 1.000 0.000
#> round_ERR2585262        2  0.9933      0.198 0.452 0.548
#> round_ERR2585199        2  0.1633      0.947 0.024 0.976
#> aberrant_ERR2585369     2  0.0000      0.967 0.000 1.000
#> round_ERR2585208        1  0.0000      0.968 1.000 0.000
#> round_ERR2585252        1  0.0000      0.968 1.000 0.000
#> round_ERR2585236        1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585284     1  0.5059      0.869 0.888 0.112
#> round_ERR2585224        1  0.0000      0.968 1.000 0.000
#> round_ERR2585260        1  0.0000      0.968 1.000 0.000
#> round_ERR2585229        1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585364     1  0.8443      0.640 0.728 0.272
#> round_ERR2585253        1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585368     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585371     2  0.0000      0.967 0.000 1.000
#> round_ERR2585239        1  0.0000      0.968 1.000 0.000
#> round_ERR2585273        1  0.0000      0.968 1.000 0.000
#> round_ERR2585256        1  0.0000      0.968 1.000 0.000
#> round_ERR2585272        1  0.0000      0.968 1.000 0.000
#> round_ERR2585246        1  0.0000      0.968 1.000 0.000
#> round_ERR2585261        1  0.4939      0.866 0.892 0.108
#> round_ERR2585254        1  0.9815      0.256 0.580 0.420
#> round_ERR2585225        1  0.0000      0.968 1.000 0.000
#> round_ERR2585235        1  0.0000      0.968 1.000 0.000
#> round_ERR2585271        1  0.0000      0.968 1.000 0.000
#> round_ERR2585251        1  0.0000      0.968 1.000 0.000
#> round_ERR2585255        1  0.0000      0.968 1.000 0.000
#> round_ERR2585257        1  0.0000      0.968 1.000 0.000
#> round_ERR2585226        1  0.0000      0.968 1.000 0.000
#> round_ERR2585265        1  0.0000      0.968 1.000 0.000
#> round_ERR2585259        1  0.0000      0.968 1.000 0.000
#> round_ERR2585247        1  0.0000      0.968 1.000 0.000
#> round_ERR2585241        1  0.0000      0.968 1.000 0.000
#> round_ERR2585263        1  0.0000      0.968 1.000 0.000
#> round_ERR2585264        1  0.0000      0.968 1.000 0.000
#> round_ERR2585233        1  0.0000      0.968 1.000 0.000
#> round_ERR2585223        1  0.0000      0.968 1.000 0.000
#> round_ERR2585234        1  0.9580      0.374 0.620 0.380
#> round_ERR2585222        1  0.0000      0.968 1.000 0.000
#> round_ERR2585228        1  0.0000      0.968 1.000 0.000
#> round_ERR2585248        1  0.0000      0.968 1.000 0.000
#> round_ERR2585240        1  0.0000      0.968 1.000 0.000
#> round_ERR2585270        1  0.0000      0.968 1.000 0.000
#> round_ERR2585232        1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585341     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585355     2  0.0000      0.967 0.000 1.000
#> round_ERR2585227        1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585351     2  0.0000      0.967 0.000 1.000
#> round_ERR2585269        1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585357     2  0.0000      0.967 0.000 1.000
#> aberrant_ERR2585350     2  0.0000      0.967 0.000 1.000
#> round_ERR2585250        1  0.0000      0.968 1.000 0.000
#> round_ERR2585245        1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585353     2  0.0000      0.967 0.000 1.000
#> round_ERR2585258        1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585354     2  0.0000      0.967 0.000 1.000
#> round_ERR2585249        1  0.0000      0.968 1.000 0.000
#> round_ERR2585268        1  0.0000      0.968 1.000 0.000
#> aberrant_ERR2585356     2  0.1414      0.951 0.020 0.980
#> round_ERR2585266        1  0.0000      0.968 1.000 0.000
#> round_ERR2585231        1  0.0000      0.968 1.000 0.000
#> round_ERR2585230        1  0.0000      0.968 1.000 0.000
#> round_ERR2585267        1  0.0000      0.968 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 cell_type(p) k
#> MAD:skmeans 155     3.94e-19 2
#> MAD:skmeans 148     5.16e-22 3
#> MAD:skmeans 147     7.14e-27 4
#> MAD:skmeans 127     1.30e-22 5
#> MAD:skmeans 113     8.42e-19 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 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-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.703           0.911       0.945          0.148 0.904   0.904
#> 3 3 0.367           0.607       0.844          1.150 0.829   0.811
#> 4 4 0.308           0.659       0.815          0.201 0.950   0.934
#> 5 5 0.295           0.606       0.794          0.088 0.965   0.953
#> 6 6 0.415           0.646       0.831          0.366 0.691   0.586

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
#> aberrant_ERR2585320     1  0.5737      0.879 0.864 0.136
#> aberrant_ERR2585338     1  0.0000      0.946 1.000 0.000
#> aberrant_ERR2585325     1  0.5519      0.881 0.872 0.128
#> aberrant_ERR2585283     2  0.0000      0.861 0.000 1.000
#> aberrant_ERR2585343     1  0.6531      0.843 0.832 0.168
#> aberrant_ERR2585329     1  0.1843      0.942 0.972 0.028
#> aberrant_ERR2585317     1  0.1633      0.943 0.976 0.024
#> aberrant_ERR2585339     1  0.3114      0.931 0.944 0.056
#> aberrant_ERR2585335     1  0.5059      0.894 0.888 0.112
#> aberrant_ERR2585287     2  0.9170      0.556 0.332 0.668
#> aberrant_ERR2585321     1  0.5737      0.874 0.864 0.136
#> aberrant_ERR2585297     1  0.1184      0.943 0.984 0.016
#> aberrant_ERR2585337     1  0.1414      0.944 0.980 0.020
#> aberrant_ERR2585319     1  0.5519      0.881 0.872 0.128
#> aberrant_ERR2585315     1  0.5178      0.891 0.884 0.116
#> aberrant_ERR2585336     1  0.2603      0.936 0.956 0.044
#> aberrant_ERR2585307     1  0.2043      0.941 0.968 0.032
#> aberrant_ERR2585301     1  0.2236      0.940 0.964 0.036
#> aberrant_ERR2585326     1  0.1633      0.943 0.976 0.024
#> aberrant_ERR2585331     1  0.0000      0.946 1.000 0.000
#> aberrant_ERR2585346     2  0.0376      0.862 0.004 0.996
#> aberrant_ERR2585314     1  0.2423      0.937 0.960 0.040
#> aberrant_ERR2585298     1  0.0376      0.946 0.996 0.004
#> aberrant_ERR2585345     1  0.2423      0.937 0.960 0.040
#> aberrant_ERR2585299     1  0.0672      0.947 0.992 0.008
#> aberrant_ERR2585309     1  0.0938      0.944 0.988 0.012
#> aberrant_ERR2585303     1  0.1843      0.942 0.972 0.028
#> aberrant_ERR2585313     1  0.4815      0.901 0.896 0.104
#> aberrant_ERR2585318     1  0.5178      0.892 0.884 0.116
#> aberrant_ERR2585328     1  0.4161      0.915 0.916 0.084
#> aberrant_ERR2585330     1  0.5737      0.874 0.864 0.136
#> aberrant_ERR2585293     2  0.0376      0.861 0.004 0.996
#> aberrant_ERR2585342     1  0.5737      0.874 0.864 0.136
#> aberrant_ERR2585348     1  0.5629      0.877 0.868 0.132
#> aberrant_ERR2585352     1  0.2603      0.936 0.956 0.044
#> aberrant_ERR2585308     1  0.4161      0.920 0.916 0.084
#> aberrant_ERR2585349     1  0.0938      0.945 0.988 0.012
#> aberrant_ERR2585316     1  0.6712      0.824 0.824 0.176
#> aberrant_ERR2585306     1  0.4298      0.912 0.912 0.088
#> aberrant_ERR2585324     1  0.5294      0.888 0.880 0.120
#> aberrant_ERR2585310     1  0.0938      0.946 0.988 0.012
#> aberrant_ERR2585296     1  0.0000      0.946 1.000 0.000
#> aberrant_ERR2585275     2  0.9170      0.555 0.332 0.668
#> aberrant_ERR2585311     1  0.5519      0.882 0.872 0.128
#> aberrant_ERR2585292     2  0.0376      0.861 0.004 0.996
#> aberrant_ERR2585282     1  0.5842      0.875 0.860 0.140
#> aberrant_ERR2585305     1  0.5408      0.886 0.876 0.124
#> aberrant_ERR2585278     1  0.2423      0.937 0.960 0.040
#> aberrant_ERR2585347     1  0.6247      0.857 0.844 0.156
#> aberrant_ERR2585332     1  0.6148      0.860 0.848 0.152
#> aberrant_ERR2585280     1  0.5737      0.874 0.864 0.136
#> aberrant_ERR2585304     1  0.0376      0.946 0.996 0.004
#> aberrant_ERR2585322     1  0.1843      0.942 0.972 0.028
#> aberrant_ERR2585279     1  0.0376      0.946 0.996 0.004
#> aberrant_ERR2585277     1  0.1184      0.945 0.984 0.016
#> aberrant_ERR2585295     1  0.4690      0.903 0.900 0.100
#> aberrant_ERR2585333     1  0.6148      0.860 0.848 0.152
#> aberrant_ERR2585285     1  0.5408      0.885 0.876 0.124
#> aberrant_ERR2585286     1  0.2236      0.939 0.964 0.036
#> aberrant_ERR2585294     1  0.0672      0.946 0.992 0.008
#> aberrant_ERR2585300     1  0.5294      0.892 0.880 0.120
#> aberrant_ERR2585334     1  0.0000      0.946 1.000 0.000
#> aberrant_ERR2585361     1  0.5178      0.891 0.884 0.116
#> aberrant_ERR2585372     1  0.5842      0.871 0.860 0.140
#> round_ERR2585217        1  0.0672      0.945 0.992 0.008
#> round_ERR2585205        1  0.0938      0.944 0.988 0.012
#> round_ERR2585214        1  0.0000      0.946 1.000 0.000
#> round_ERR2585202        1  0.0000      0.946 1.000 0.000
#> aberrant_ERR2585367     1  0.1633      0.944 0.976 0.024
#> round_ERR2585220        1  0.0672      0.945 0.992 0.008
#> round_ERR2585238        1  0.0938      0.944 0.988 0.012
#> aberrant_ERR2585276     1  0.4815      0.902 0.896 0.104
#> round_ERR2585218        1  0.0938      0.944 0.988 0.012
#> aberrant_ERR2585363     1  0.4815      0.902 0.896 0.104
#> round_ERR2585201        1  0.0376      0.946 0.996 0.004
#> round_ERR2585210        1  0.0938      0.944 0.988 0.012
#> aberrant_ERR2585362     1  0.3114      0.935 0.944 0.056
#> aberrant_ERR2585360     1  0.5059      0.897 0.888 0.112
#> round_ERR2585209        1  0.0376      0.946 0.996 0.004
#> round_ERR2585242        1  0.0000      0.946 1.000 0.000
#> round_ERR2585216        1  0.0938      0.944 0.988 0.012
#> round_ERR2585219        1  0.0938      0.944 0.988 0.012
#> round_ERR2585237        1  0.0376      0.946 0.996 0.004
#> round_ERR2585198        1  0.0000      0.946 1.000 0.000
#> round_ERR2585211        1  0.0938      0.944 0.988 0.012
#> round_ERR2585206        1  0.1184      0.944 0.984 0.016
#> aberrant_ERR2585281     1  0.1633      0.943 0.976 0.024
#> round_ERR2585212        1  0.0938      0.944 0.988 0.012
#> round_ERR2585221        1  0.0672      0.946 0.992 0.008
#> round_ERR2585243        1  0.0938      0.944 0.988 0.012
#> round_ERR2585204        1  0.0000      0.946 1.000 0.000
#> round_ERR2585213        1  0.0000      0.946 1.000 0.000
#> aberrant_ERR2585373     1  0.5519      0.883 0.872 0.128
#> aberrant_ERR2585358     1  0.6801      0.829 0.820 0.180
#> aberrant_ERR2585365     1  0.1843      0.942 0.972 0.028
#> aberrant_ERR2585359     1  0.9661      0.379 0.608 0.392
#> aberrant_ERR2585370     1  0.1414      0.944 0.980 0.020
#> round_ERR2585215        1  0.1414      0.943 0.980 0.020
#> round_ERR2585262        1  0.0376      0.946 0.996 0.004
#> round_ERR2585199        1  0.0000      0.946 1.000 0.000
#> aberrant_ERR2585369     1  0.3431      0.927 0.936 0.064
#> round_ERR2585208        1  0.0938      0.944 0.988 0.012
#> round_ERR2585252        1  0.0938      0.944 0.988 0.012
#> round_ERR2585236        1  0.1633      0.946 0.976 0.024
#> aberrant_ERR2585284     2  0.0376      0.862 0.004 0.996
#> round_ERR2585224        1  0.7139      0.812 0.804 0.196
#> round_ERR2585260        1  0.0938      0.946 0.988 0.012
#> round_ERR2585229        1  0.1184      0.946 0.984 0.016
#> aberrant_ERR2585364     2  0.7219      0.747 0.200 0.800
#> round_ERR2585253        1  0.2603      0.931 0.956 0.044
#> aberrant_ERR2585368     1  0.0000      0.946 1.000 0.000
#> aberrant_ERR2585371     1  0.0000      0.946 1.000 0.000
#> round_ERR2585239        1  0.0938      0.944 0.988 0.012
#> round_ERR2585273        1  0.0938      0.944 0.988 0.012
#> round_ERR2585256        1  0.0672      0.945 0.992 0.008
#> round_ERR2585272        1  0.0938      0.944 0.988 0.012
#> round_ERR2585246        1  0.1184      0.945 0.984 0.016
#> round_ERR2585261        1  0.0376      0.946 0.996 0.004
#> round_ERR2585254        1  0.0376      0.946 0.996 0.004
#> round_ERR2585225        1  0.0672      0.946 0.992 0.008
#> round_ERR2585235        1  0.0938      0.944 0.988 0.012
#> round_ERR2585271        1  0.0938      0.944 0.988 0.012
#> round_ERR2585251        1  0.0672      0.945 0.992 0.008
#> round_ERR2585255        1  0.0376      0.946 0.996 0.004
#> round_ERR2585257        1  0.0376      0.946 0.996 0.004
#> round_ERR2585226        1  0.0376      0.946 0.996 0.004
#> round_ERR2585265        1  0.0672      0.945 0.992 0.008
#> round_ERR2585259        1  0.0938      0.944 0.988 0.012
#> round_ERR2585247        1  0.0672      0.946 0.992 0.008
#> round_ERR2585241        1  0.0938      0.944 0.988 0.012
#> round_ERR2585263        1  0.0376      0.946 0.996 0.004
#> round_ERR2585264        1  0.9522      0.281 0.628 0.372
#> round_ERR2585233        1  0.0376      0.946 0.996 0.004
#> round_ERR2585223        1  0.0938      0.944 0.988 0.012
#> round_ERR2585234        1  0.0000      0.946 1.000 0.000
#> round_ERR2585222        1  0.0000      0.946 1.000 0.000
#> round_ERR2585228        1  0.0938      0.944 0.988 0.012
#> round_ERR2585248        1  0.5842      0.829 0.860 0.140
#> round_ERR2585240        1  0.0376      0.946 0.996 0.004
#> round_ERR2585270        1  0.0672      0.945 0.992 0.008
#> round_ERR2585232        1  0.0376      0.946 0.996 0.004
#> aberrant_ERR2585341     1  0.2423      0.939 0.960 0.040
#> aberrant_ERR2585355     1  0.1843      0.942 0.972 0.028
#> round_ERR2585227        1  0.0672      0.946 0.992 0.008
#> aberrant_ERR2585351     1  0.4298      0.914 0.912 0.088
#> round_ERR2585269        1  0.2423      0.931 0.960 0.040
#> aberrant_ERR2585357     1  0.1414      0.944 0.980 0.020
#> aberrant_ERR2585350     1  0.1843      0.942 0.972 0.028
#> round_ERR2585250        1  0.0938      0.946 0.988 0.012
#> round_ERR2585245        1  0.3733      0.908 0.928 0.072
#> aberrant_ERR2585353     1  0.5737      0.874 0.864 0.136
#> round_ERR2585258        1  0.1184      0.946 0.984 0.016
#> aberrant_ERR2585354     1  0.4298      0.914 0.912 0.088
#> round_ERR2585249        1  0.2778      0.932 0.952 0.048
#> round_ERR2585268        1  0.0376      0.946 0.996 0.004
#> aberrant_ERR2585356     1  0.5519      0.881 0.872 0.128
#> round_ERR2585266        1  0.0000      0.946 1.000 0.000
#> round_ERR2585231        1  0.2778      0.927 0.952 0.048
#> round_ERR2585230        1  0.0938      0.944 0.988 0.012
#> round_ERR2585267        1  0.0938      0.944 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-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 cell_type(p) k
#> MAD:pam 158     2.40e-02 2
#> MAD:pam 115     1.12e-07 3
#> MAD:pam 134     4.97e-02 4
#> MAD:pam 129     1.08e-02 5
#> MAD:pam 126     7.21e-14 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 1.000           0.988       0.995         0.5035 0.497   0.497
#> 3 3 0.766           0.800       0.891         0.1714 0.941   0.881
#> 4 4 0.845           0.908       0.937         0.1116 0.886   0.747
#> 5 5 0.794           0.818       0.907         0.1256 0.909   0.738
#> 6 6 0.748           0.631       0.834         0.0623 0.950   0.817

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
#> aberrant_ERR2585320     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585338     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585325     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585283     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585343     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585329     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585317     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585339     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585335     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585287     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585321     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585297     1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585337     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585319     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585315     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585336     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585307     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585301     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585326     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585331     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585346     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585314     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585298     1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585345     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585299     1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585309     1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585303     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585313     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585318     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585328     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585330     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585293     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585342     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585348     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585352     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585308     1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585349     2  0.3879      0.916 0.076 0.924
#> aberrant_ERR2585316     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585306     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585324     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585310     1  0.7299      0.744 0.796 0.204
#> aberrant_ERR2585296     1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585275     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585311     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585292     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585282     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585305     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585278     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585347     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585332     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585280     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585304     2  0.8813      0.571 0.300 0.700
#> aberrant_ERR2585322     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585279     2  0.5178      0.868 0.116 0.884
#> aberrant_ERR2585277     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585295     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585333     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585285     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585286     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585294     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585300     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585334     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585361     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585372     2  0.0000      0.994 0.000 1.000
#> round_ERR2585217        1  0.0000      0.995 1.000 0.000
#> round_ERR2585205        1  0.0000      0.995 1.000 0.000
#> round_ERR2585214        1  0.0000      0.995 1.000 0.000
#> round_ERR2585202        1  0.0376      0.991 0.996 0.004
#> aberrant_ERR2585367     2  0.0000      0.994 0.000 1.000
#> round_ERR2585220        1  0.0000      0.995 1.000 0.000
#> round_ERR2585238        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585276     2  0.0000      0.994 0.000 1.000
#> round_ERR2585218        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585363     2  0.0000      0.994 0.000 1.000
#> round_ERR2585201        1  0.0000      0.995 1.000 0.000
#> round_ERR2585210        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585362     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585360     2  0.0000      0.994 0.000 1.000
#> round_ERR2585209        1  0.0000      0.995 1.000 0.000
#> round_ERR2585242        1  0.0000      0.995 1.000 0.000
#> round_ERR2585216        1  0.0000      0.995 1.000 0.000
#> round_ERR2585219        1  0.0000      0.995 1.000 0.000
#> round_ERR2585237        1  0.0000      0.995 1.000 0.000
#> round_ERR2585198        1  0.0000      0.995 1.000 0.000
#> round_ERR2585211        1  0.0000      0.995 1.000 0.000
#> round_ERR2585206        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585281     2  0.0000      0.994 0.000 1.000
#> round_ERR2585212        1  0.0000      0.995 1.000 0.000
#> round_ERR2585221        1  0.0000      0.995 1.000 0.000
#> round_ERR2585243        1  0.0000      0.995 1.000 0.000
#> round_ERR2585204        1  0.0000      0.995 1.000 0.000
#> round_ERR2585213        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585373     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585358     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585365     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585359     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585370     2  0.0000      0.994 0.000 1.000
#> round_ERR2585215        1  0.0000      0.995 1.000 0.000
#> round_ERR2585262        1  0.6343      0.809 0.840 0.160
#> round_ERR2585199        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585369     2  0.0000      0.994 0.000 1.000
#> round_ERR2585208        1  0.0000      0.995 1.000 0.000
#> round_ERR2585252        1  0.0000      0.995 1.000 0.000
#> round_ERR2585236        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585284     2  0.0000      0.994 0.000 1.000
#> round_ERR2585224        1  0.0000      0.995 1.000 0.000
#> round_ERR2585260        1  0.0000      0.995 1.000 0.000
#> round_ERR2585229        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585364     2  0.0000      0.994 0.000 1.000
#> round_ERR2585253        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585368     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585371     2  0.0000      0.994 0.000 1.000
#> round_ERR2585239        1  0.0000      0.995 1.000 0.000
#> round_ERR2585273        1  0.0000      0.995 1.000 0.000
#> round_ERR2585256        1  0.0000      0.995 1.000 0.000
#> round_ERR2585272        1  0.0000      0.995 1.000 0.000
#> round_ERR2585246        1  0.0000      0.995 1.000 0.000
#> round_ERR2585261        1  0.0000      0.995 1.000 0.000
#> round_ERR2585254        1  0.0000      0.995 1.000 0.000
#> round_ERR2585225        1  0.0000      0.995 1.000 0.000
#> round_ERR2585235        1  0.0000      0.995 1.000 0.000
#> round_ERR2585271        1  0.0000      0.995 1.000 0.000
#> round_ERR2585251        1  0.0000      0.995 1.000 0.000
#> round_ERR2585255        1  0.0000      0.995 1.000 0.000
#> round_ERR2585257        1  0.0000      0.995 1.000 0.000
#> round_ERR2585226        1  0.0000      0.995 1.000 0.000
#> round_ERR2585265        1  0.0000      0.995 1.000 0.000
#> round_ERR2585259        1  0.0000      0.995 1.000 0.000
#> round_ERR2585247        1  0.0000      0.995 1.000 0.000
#> round_ERR2585241        1  0.0000      0.995 1.000 0.000
#> round_ERR2585263        1  0.0000      0.995 1.000 0.000
#> round_ERR2585264        1  0.0000      0.995 1.000 0.000
#> round_ERR2585233        1  0.0000      0.995 1.000 0.000
#> round_ERR2585223        1  0.0000      0.995 1.000 0.000
#> round_ERR2585234        1  0.0000      0.995 1.000 0.000
#> round_ERR2585222        1  0.0000      0.995 1.000 0.000
#> round_ERR2585228        1  0.0000      0.995 1.000 0.000
#> round_ERR2585248        1  0.0000      0.995 1.000 0.000
#> round_ERR2585240        1  0.0000      0.995 1.000 0.000
#> round_ERR2585270        1  0.0000      0.995 1.000 0.000
#> round_ERR2585232        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585341     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585355     2  0.0000      0.994 0.000 1.000
#> round_ERR2585227        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585351     2  0.0000      0.994 0.000 1.000
#> round_ERR2585269        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585357     2  0.0000      0.994 0.000 1.000
#> aberrant_ERR2585350     2  0.0000      0.994 0.000 1.000
#> round_ERR2585250        1  0.0000      0.995 1.000 0.000
#> round_ERR2585245        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585353     2  0.0000      0.994 0.000 1.000
#> round_ERR2585258        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585354     2  0.0000      0.994 0.000 1.000
#> round_ERR2585249        1  0.0000      0.995 1.000 0.000
#> round_ERR2585268        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585356     2  0.0000      0.994 0.000 1.000
#> round_ERR2585266        1  0.0000      0.995 1.000 0.000
#> round_ERR2585231        1  0.0000      0.995 1.000 0.000
#> round_ERR2585230        1  0.0000      0.995 1.000 0.000
#> round_ERR2585267        1  0.0000      0.995 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)

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

Signature heatmaps where rows are not scaled:

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

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 cell_type(p) k
#> MAD:mclust 160     3.08e-30 2
#> MAD:mclust 149     2.89e-28 3
#> MAD:mclust 155     7.53e-28 4
#> MAD:mclust 149     9.56e-26 5
#> MAD:mclust 134     1.62e-22 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 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-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.983       0.993         0.5026 0.498   0.498
#> 3 3 0.650           0.717       0.854         0.2623 0.800   0.617
#> 4 4 0.640           0.775       0.866         0.0621 0.904   0.759
#> 5 5 0.575           0.634       0.808         0.0700 0.987   0.964
#> 6 6 0.578           0.431       0.707         0.0604 0.962   0.891

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
#> aberrant_ERR2585320     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585338     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585325     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585283     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585343     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585329     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585317     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585339     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585335     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585287     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585321     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585297     1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585337     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585319     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585315     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585336     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585307     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585301     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585326     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585331     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585346     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585314     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585298     1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585345     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585299     1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585309     1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585303     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585313     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585318     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585328     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585330     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585293     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585342     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585348     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585352     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585308     1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585349     2  0.0376      0.986 0.004 0.996
#> aberrant_ERR2585316     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585306     2  0.0672      0.983 0.008 0.992
#> aberrant_ERR2585324     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585310     1  0.2423      0.957 0.960 0.040
#> aberrant_ERR2585296     1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585275     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585311     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585292     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585282     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585305     2  0.2423      0.952 0.040 0.960
#> aberrant_ERR2585278     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585347     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585332     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585280     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585304     2  0.1633      0.968 0.024 0.976
#> aberrant_ERR2585322     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585279     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585277     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585295     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585333     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585285     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585286     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585294     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585300     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585334     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585361     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585372     2  0.0000      0.990 0.000 1.000
#> round_ERR2585217        1  0.0000      0.995 1.000 0.000
#> round_ERR2585205        1  0.0000      0.995 1.000 0.000
#> round_ERR2585214        1  0.3274      0.936 0.940 0.060
#> round_ERR2585202        2  0.9661      0.357 0.392 0.608
#> aberrant_ERR2585367     2  0.0000      0.990 0.000 1.000
#> round_ERR2585220        1  0.0000      0.995 1.000 0.000
#> round_ERR2585238        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585276     2  0.0000      0.990 0.000 1.000
#> round_ERR2585218        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585363     2  0.0000      0.990 0.000 1.000
#> round_ERR2585201        1  0.0000      0.995 1.000 0.000
#> round_ERR2585210        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585362     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585360     2  0.0000      0.990 0.000 1.000
#> round_ERR2585209        1  0.0000      0.995 1.000 0.000
#> round_ERR2585242        1  0.0000      0.995 1.000 0.000
#> round_ERR2585216        1  0.0000      0.995 1.000 0.000
#> round_ERR2585219        1  0.0000      0.995 1.000 0.000
#> round_ERR2585237        1  0.0672      0.988 0.992 0.008
#> round_ERR2585198        1  0.0000      0.995 1.000 0.000
#> round_ERR2585211        1  0.0000      0.995 1.000 0.000
#> round_ERR2585206        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585281     2  0.0000      0.990 0.000 1.000
#> round_ERR2585212        1  0.0000      0.995 1.000 0.000
#> round_ERR2585221        1  0.0000      0.995 1.000 0.000
#> round_ERR2585243        1  0.0000      0.995 1.000 0.000
#> round_ERR2585204        1  0.7139      0.756 0.804 0.196
#> round_ERR2585213        2  0.2948      0.939 0.052 0.948
#> aberrant_ERR2585373     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585358     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585365     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585359     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585370     2  0.0000      0.990 0.000 1.000
#> round_ERR2585215        1  0.0000      0.995 1.000 0.000
#> round_ERR2585262        2  0.8909      0.559 0.308 0.692
#> round_ERR2585199        1  0.1843      0.970 0.972 0.028
#> aberrant_ERR2585369     2  0.0000      0.990 0.000 1.000
#> round_ERR2585208        1  0.0000      0.995 1.000 0.000
#> round_ERR2585252        1  0.0000      0.995 1.000 0.000
#> round_ERR2585236        1  0.0938      0.985 0.988 0.012
#> aberrant_ERR2585284     2  0.0000      0.990 0.000 1.000
#> round_ERR2585224        1  0.0000      0.995 1.000 0.000
#> round_ERR2585260        1  0.0000      0.995 1.000 0.000
#> round_ERR2585229        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585364     2  0.0000      0.990 0.000 1.000
#> round_ERR2585253        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585368     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585371     2  0.0000      0.990 0.000 1.000
#> round_ERR2585239        1  0.0000      0.995 1.000 0.000
#> round_ERR2585273        1  0.0000      0.995 1.000 0.000
#> round_ERR2585256        1  0.0000      0.995 1.000 0.000
#> round_ERR2585272        1  0.0000      0.995 1.000 0.000
#> round_ERR2585246        1  0.0000      0.995 1.000 0.000
#> round_ERR2585261        1  0.0000      0.995 1.000 0.000
#> round_ERR2585254        1  0.0000      0.995 1.000 0.000
#> round_ERR2585225        1  0.0000      0.995 1.000 0.000
#> round_ERR2585235        1  0.0000      0.995 1.000 0.000
#> round_ERR2585271        1  0.0000      0.995 1.000 0.000
#> round_ERR2585251        1  0.0000      0.995 1.000 0.000
#> round_ERR2585255        1  0.0376      0.992 0.996 0.004
#> round_ERR2585257        1  0.0000      0.995 1.000 0.000
#> round_ERR2585226        1  0.0000      0.995 1.000 0.000
#> round_ERR2585265        1  0.0000      0.995 1.000 0.000
#> round_ERR2585259        1  0.0000      0.995 1.000 0.000
#> round_ERR2585247        1  0.0000      0.995 1.000 0.000
#> round_ERR2585241        1  0.0000      0.995 1.000 0.000
#> round_ERR2585263        1  0.0000      0.995 1.000 0.000
#> round_ERR2585264        1  0.0000      0.995 1.000 0.000
#> round_ERR2585233        1  0.0000      0.995 1.000 0.000
#> round_ERR2585223        1  0.0000      0.995 1.000 0.000
#> round_ERR2585234        1  0.0000      0.995 1.000 0.000
#> round_ERR2585222        1  0.0000      0.995 1.000 0.000
#> round_ERR2585228        1  0.0000      0.995 1.000 0.000
#> round_ERR2585248        1  0.0000      0.995 1.000 0.000
#> round_ERR2585240        1  0.0000      0.995 1.000 0.000
#> round_ERR2585270        1  0.0000      0.995 1.000 0.000
#> round_ERR2585232        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585341     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585355     2  0.0000      0.990 0.000 1.000
#> round_ERR2585227        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585351     2  0.0000      0.990 0.000 1.000
#> round_ERR2585269        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585357     2  0.0000      0.990 0.000 1.000
#> aberrant_ERR2585350     2  0.0000      0.990 0.000 1.000
#> round_ERR2585250        1  0.0000      0.995 1.000 0.000
#> round_ERR2585245        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585353     2  0.0000      0.990 0.000 1.000
#> round_ERR2585258        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585354     2  0.0000      0.990 0.000 1.000
#> round_ERR2585249        1  0.0000      0.995 1.000 0.000
#> round_ERR2585268        1  0.0000      0.995 1.000 0.000
#> aberrant_ERR2585356     2  0.0000      0.990 0.000 1.000
#> round_ERR2585266        1  0.0000      0.995 1.000 0.000
#> round_ERR2585231        1  0.0000      0.995 1.000 0.000
#> round_ERR2585230        1  0.0000      0.995 1.000 0.000
#> round_ERR2585267        1  0.0000      0.995 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)

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

Signature heatmaps where rows are not scaled:

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

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 cell_type(p) k
#> MAD:NMF 159     2.51e-28 2
#> MAD:NMF 135     6.36e-20 3
#> MAD:NMF 148     1.48e-21 4
#> MAD:NMF 133     2.15e-18 5
#> MAD:NMF  82     5.63e-11 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 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 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 0.424           0.654       0.828         0.2769 0.916   0.916
#> 3 3 0.607           0.759       0.902         0.7498 0.583   0.545
#> 4 4 0.578           0.738       0.894         0.0159 1.000   0.999
#> 5 5 0.768           0.775       0.880         0.3077 0.777   0.577
#> 6 6 0.625           0.708       0.841         0.0680 0.972   0.916

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
#> aberrant_ERR2585320     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585338     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585325     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585283     2  0.9944      0.938 0.456 0.544
#> aberrant_ERR2585343     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585329     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585317     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585339     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585335     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585287     2  0.9833      0.556 0.424 0.576
#> aberrant_ERR2585321     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585297     1  0.1843      0.315 0.972 0.028
#> aberrant_ERR2585337     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585319     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585315     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585336     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585307     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585301     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585326     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585331     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585346     2  0.9944      0.938 0.456 0.544
#> aberrant_ERR2585314     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585298     1  0.9661      0.757 0.608 0.392
#> aberrant_ERR2585345     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585299     1  0.2778      0.267 0.952 0.048
#> aberrant_ERR2585309     1  0.2948      0.237 0.948 0.052
#> aberrant_ERR2585303     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585313     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585318     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585328     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585330     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585293     2  0.9944      0.938 0.456 0.544
#> aberrant_ERR2585342     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585348     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585352     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585308     1  0.2948      0.237 0.948 0.052
#> aberrant_ERR2585349     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585316     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585306     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585324     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585310     1  0.9988      0.782 0.520 0.480
#> aberrant_ERR2585296     1  0.8555      0.690 0.720 0.280
#> aberrant_ERR2585275     2  0.9944      0.938 0.456 0.544
#> aberrant_ERR2585311     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585292     2  0.9944      0.938 0.456 0.544
#> aberrant_ERR2585282     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585305     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585278     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585347     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585332     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585280     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585304     1  0.9881      0.773 0.564 0.436
#> aberrant_ERR2585322     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585279     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585277     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585295     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585333     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585285     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585286     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585294     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585300     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585334     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585361     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585372     1  1.0000      0.785 0.504 0.496
#> round_ERR2585217        1  0.9933      0.776 0.548 0.452
#> round_ERR2585205        1  0.0672      0.341 0.992 0.008
#> round_ERR2585214        1  0.9881      0.772 0.564 0.436
#> round_ERR2585202        1  0.9881      0.772 0.564 0.436
#> aberrant_ERR2585367     1  1.0000      0.785 0.504 0.496
#> round_ERR2585220        1  0.4022      0.482 0.920 0.080
#> round_ERR2585238        1  0.2236      0.278 0.964 0.036
#> aberrant_ERR2585276     1  1.0000      0.785 0.504 0.496
#> round_ERR2585218        1  0.0672      0.341 0.992 0.008
#> aberrant_ERR2585363     1  1.0000      0.785 0.504 0.496
#> round_ERR2585201        1  0.9754      0.763 0.592 0.408
#> round_ERR2585210        1  0.0376      0.365 0.996 0.004
#> aberrant_ERR2585362     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585360     1  1.0000      0.785 0.504 0.496
#> round_ERR2585209        1  0.9522      0.749 0.628 0.372
#> round_ERR2585242        1  0.9580      0.752 0.620 0.380
#> round_ERR2585216        1  0.5294      0.533 0.880 0.120
#> round_ERR2585219        1  0.4939      0.519 0.892 0.108
#> round_ERR2585237        1  0.9815      0.768 0.580 0.420
#> round_ERR2585198        1  0.9850      0.770 0.572 0.428
#> round_ERR2585211        1  0.0376      0.349 0.996 0.004
#> round_ERR2585206        1  0.0672      0.341 0.992 0.008
#> aberrant_ERR2585281     1  1.0000      0.785 0.504 0.496
#> round_ERR2585212        1  0.5294      0.534 0.880 0.120
#> round_ERR2585221        1  0.2043      0.288 0.968 0.032
#> round_ERR2585243        1  0.0376      0.350 0.996 0.004
#> round_ERR2585204        1  0.9881      0.772 0.564 0.436
#> round_ERR2585213        1  0.9881      0.772 0.564 0.436
#> aberrant_ERR2585373     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585358     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585365     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585359     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585370     1  1.0000      0.785 0.504 0.496
#> round_ERR2585215        1  0.0000      0.357 1.000 0.000
#> round_ERR2585262        1  0.9983      0.782 0.524 0.476
#> round_ERR2585199        1  0.9850      0.770 0.572 0.428
#> aberrant_ERR2585369     1  1.0000      0.785 0.504 0.496
#> round_ERR2585208        1  0.0938      0.333 0.988 0.012
#> round_ERR2585252        1  0.2948      0.237 0.948 0.052
#> round_ERR2585236        1  0.9286      0.733 0.656 0.344
#> aberrant_ERR2585284     2  0.9815      0.908 0.420 0.580
#> round_ERR2585224        1  0.2948      0.237 0.948 0.052
#> round_ERR2585260        1  0.1414      0.379 0.980 0.020
#> round_ERR2585229        1  0.2778      0.267 0.952 0.048
#> aberrant_ERR2585364     1  1.0000      0.785 0.504 0.496
#> round_ERR2585253        1  0.2948      0.237 0.948 0.052
#> aberrant_ERR2585368     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585371     1  1.0000      0.785 0.504 0.496
#> round_ERR2585239        1  0.2778      0.437 0.952 0.048
#> round_ERR2585273        1  0.3114      0.369 0.944 0.056
#> round_ERR2585256        1  0.8955      0.713 0.688 0.312
#> round_ERR2585272        1  0.0938      0.379 0.988 0.012
#> round_ERR2585246        1  0.2236      0.278 0.964 0.036
#> round_ERR2585261        1  0.9286      0.733 0.656 0.344
#> round_ERR2585254        1  0.9460      0.745 0.636 0.364
#> round_ERR2585225        1  0.9635      0.755 0.612 0.388
#> round_ERR2585235        1  0.8861      0.708 0.696 0.304
#> round_ERR2585271        1  0.1633      0.400 0.976 0.024
#> round_ERR2585251        1  0.6048      0.566 0.852 0.148
#> round_ERR2585255        1  0.9775      0.765 0.588 0.412
#> round_ERR2585257        1  0.9795      0.766 0.584 0.416
#> round_ERR2585226        1  0.5519      0.543 0.872 0.128
#> round_ERR2585265        1  0.2236      0.419 0.964 0.036
#> round_ERR2585259        1  0.9491      0.746 0.632 0.368
#> round_ERR2585247        1  0.2043      0.339 0.968 0.032
#> round_ERR2585241        1  0.1184      0.324 0.984 0.016
#> round_ERR2585263        1  0.7299      0.624 0.796 0.204
#> round_ERR2585264        1  0.2948      0.237 0.948 0.052
#> round_ERR2585233        1  0.9635      0.755 0.612 0.388
#> round_ERR2585223        1  0.1843      0.393 0.972 0.028
#> round_ERR2585234        1  0.9850      0.770 0.572 0.428
#> round_ERR2585222        1  0.2603      0.431 0.956 0.044
#> round_ERR2585228        1  0.2236      0.393 0.964 0.036
#> round_ERR2585248        1  0.2948      0.237 0.948 0.052
#> round_ERR2585240        1  0.8713      0.699 0.708 0.292
#> round_ERR2585270        1  0.5178      0.529 0.884 0.116
#> round_ERR2585232        1  0.8207      0.671 0.744 0.256
#> aberrant_ERR2585341     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585355     1  1.0000      0.785 0.504 0.496
#> round_ERR2585227        1  0.5737      0.552 0.864 0.136
#> aberrant_ERR2585351     1  1.0000      0.785 0.504 0.496
#> round_ERR2585269        1  0.2948      0.237 0.948 0.052
#> aberrant_ERR2585357     1  1.0000      0.785 0.504 0.496
#> aberrant_ERR2585350     1  1.0000      0.785 0.504 0.496
#> round_ERR2585250        1  0.8608      0.693 0.716 0.284
#> round_ERR2585245        1  0.2948      0.237 0.948 0.052
#> aberrant_ERR2585353     1  1.0000      0.785 0.504 0.496
#> round_ERR2585258        1  0.1843      0.393 0.972 0.028
#> aberrant_ERR2585354     1  1.0000      0.785 0.504 0.496
#> round_ERR2585249        1  0.2948      0.237 0.948 0.052
#> round_ERR2585268        1  0.8016      0.660 0.756 0.244
#> aberrant_ERR2585356     1  1.0000      0.785 0.504 0.496
#> round_ERR2585266        1  0.9393      0.741 0.644 0.356
#> round_ERR2585231        1  0.2948      0.237 0.948 0.052
#> round_ERR2585230        1  0.2423      0.425 0.960 0.040
#> round_ERR2585267        1  0.2948      0.237 0.948 0.052

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 cell_type(p) k
#> ATC:hclust 120     1.74e-01 2
#> ATC:hclust 138     7.06e-20 3
#> ATC:hclust 136     1.67e-19 4
#> ATC:hclust 145     1.22e-25 5
#> ATC:hclust 145     7.78e-25 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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           0.987       0.982         0.4912 0.498   0.498
#> 3 3 0.834           0.840       0.905         0.1760 0.960   0.919
#> 4 4 0.718           0.847       0.882         0.1591 0.831   0.647
#> 5 5 0.752           0.750       0.816         0.1108 0.892   0.675
#> 6 6 0.702           0.619       0.775         0.0537 0.915   0.678

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
#> aberrant_ERR2585320     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585338     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585325     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585283     1   0.634      0.813 0.840 0.160
#> aberrant_ERR2585343     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585329     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585317     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585339     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585335     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585287     2   0.184      0.969 0.028 0.972
#> aberrant_ERR2585321     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585297     1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585337     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585319     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585315     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585336     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585307     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585301     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585326     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585331     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585346     1   0.184      0.954 0.972 0.028
#> aberrant_ERR2585314     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585298     1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585345     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585299     1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585309     1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585303     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585313     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585318     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585328     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585330     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585293     1   0.118      0.960 0.984 0.016
#> aberrant_ERR2585342     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585348     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585352     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585308     1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585349     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585316     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585306     1   0.416      0.937 0.916 0.084
#> aberrant_ERR2585324     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585310     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585296     1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585275     1   0.563      0.849 0.868 0.132
#> aberrant_ERR2585311     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585292     1   0.118      0.960 0.984 0.016
#> aberrant_ERR2585282     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585305     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585278     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585347     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585332     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585280     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585304     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585322     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585279     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585277     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585295     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585333     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585285     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585286     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585294     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585300     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585334     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585361     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585372     2   0.000      0.997 0.000 1.000
#> round_ERR2585217        2   0.260      0.954 0.044 0.956
#> round_ERR2585205        1   0.184      0.989 0.972 0.028
#> round_ERR2585214        2   0.242      0.958 0.040 0.960
#> round_ERR2585202        2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585367     2   0.000      0.997 0.000 1.000
#> round_ERR2585220        1   0.184      0.989 0.972 0.028
#> round_ERR2585238        1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585276     2   0.000      0.997 0.000 1.000
#> round_ERR2585218        1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585363     2   0.000      0.997 0.000 1.000
#> round_ERR2585201        1   0.184      0.989 0.972 0.028
#> round_ERR2585210        1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585362     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585360     2   0.000      0.997 0.000 1.000
#> round_ERR2585209        1   0.184      0.989 0.972 0.028
#> round_ERR2585242        1   0.184      0.989 0.972 0.028
#> round_ERR2585216        1   0.184      0.989 0.972 0.028
#> round_ERR2585219        1   0.184      0.989 0.972 0.028
#> round_ERR2585237        2   0.311      0.941 0.056 0.944
#> round_ERR2585198        1   0.738      0.777 0.792 0.208
#> round_ERR2585211        1   0.184      0.989 0.972 0.028
#> round_ERR2585206        1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585281     2   0.000      0.997 0.000 1.000
#> round_ERR2585212        1   0.184      0.989 0.972 0.028
#> round_ERR2585221        1   0.184      0.989 0.972 0.028
#> round_ERR2585243        1   0.184      0.989 0.972 0.028
#> round_ERR2585204        2   0.224      0.962 0.036 0.964
#> round_ERR2585213        2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585373     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585358     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585365     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585359     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585370     2   0.000      0.997 0.000 1.000
#> round_ERR2585215        1   0.184      0.989 0.972 0.028
#> round_ERR2585262        2   0.000      0.997 0.000 1.000
#> round_ERR2585199        2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585369     2   0.000      0.997 0.000 1.000
#> round_ERR2585208        1   0.184      0.989 0.972 0.028
#> round_ERR2585252        1   0.184      0.989 0.972 0.028
#> round_ERR2585236        1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585284     1   0.680      0.785 0.820 0.180
#> round_ERR2585224        1   0.184      0.989 0.972 0.028
#> round_ERR2585260        1   0.184      0.989 0.972 0.028
#> round_ERR2585229        1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585364     2   0.000      0.997 0.000 1.000
#> round_ERR2585253        1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585368     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585371     2   0.000      0.997 0.000 1.000
#> round_ERR2585239        1   0.184      0.989 0.972 0.028
#> round_ERR2585273        1   0.184      0.989 0.972 0.028
#> round_ERR2585256        1   0.184      0.989 0.972 0.028
#> round_ERR2585272        1   0.184      0.989 0.972 0.028
#> round_ERR2585246        1   0.184      0.989 0.972 0.028
#> round_ERR2585261        1   0.184      0.989 0.972 0.028
#> round_ERR2585254        1   0.184      0.989 0.972 0.028
#> round_ERR2585225        1   0.184      0.989 0.972 0.028
#> round_ERR2585235        1   0.184      0.989 0.972 0.028
#> round_ERR2585271        1   0.184      0.989 0.972 0.028
#> round_ERR2585251        1   0.184      0.989 0.972 0.028
#> round_ERR2585255        1   0.184      0.989 0.972 0.028
#> round_ERR2585257        1   0.184      0.989 0.972 0.028
#> round_ERR2585226        1   0.184      0.989 0.972 0.028
#> round_ERR2585265        1   0.184      0.989 0.972 0.028
#> round_ERR2585259        1   0.184      0.989 0.972 0.028
#> round_ERR2585247        1   0.184      0.989 0.972 0.028
#> round_ERR2585241        1   0.184      0.989 0.972 0.028
#> round_ERR2585263        1   0.184      0.989 0.972 0.028
#> round_ERR2585264        1   0.184      0.989 0.972 0.028
#> round_ERR2585233        1   0.184      0.989 0.972 0.028
#> round_ERR2585223        1   0.184      0.989 0.972 0.028
#> round_ERR2585234        1   0.184      0.989 0.972 0.028
#> round_ERR2585222        1   0.184      0.989 0.972 0.028
#> round_ERR2585228        1   0.184      0.989 0.972 0.028
#> round_ERR2585248        1   0.184      0.989 0.972 0.028
#> round_ERR2585240        1   0.184      0.989 0.972 0.028
#> round_ERR2585270        1   0.184      0.989 0.972 0.028
#> round_ERR2585232        1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585341     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585355     2   0.000      0.997 0.000 1.000
#> round_ERR2585227        1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585351     2   0.000      0.997 0.000 1.000
#> round_ERR2585269        1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585357     2   0.000      0.997 0.000 1.000
#> aberrant_ERR2585350     2   0.000      0.997 0.000 1.000
#> round_ERR2585250        1   0.184      0.989 0.972 0.028
#> round_ERR2585245        1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585353     2   0.000      0.997 0.000 1.000
#> round_ERR2585258        1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585354     2   0.000      0.997 0.000 1.000
#> round_ERR2585249        1   0.184      0.989 0.972 0.028
#> round_ERR2585268        1   0.184      0.989 0.972 0.028
#> aberrant_ERR2585356     2   0.000      0.997 0.000 1.000
#> round_ERR2585266        1   0.184      0.989 0.972 0.028
#> round_ERR2585231        1   0.184      0.989 0.972 0.028
#> round_ERR2585230        1   0.184      0.989 0.972 0.028
#> round_ERR2585267        1   0.184      0.989 0.972 0.028

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 cell_type(p) k
#> ATC:kmeans 160     4.49e-20 2
#> ATC:kmeans 155     1.79e-25 3
#> ATC:kmeans 156     4.70e-28 4
#> ATC:kmeans 146     2.06e-24 5
#> ATC:kmeans 121     1.92e-20 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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           0.983       0.992         0.5030 0.498   0.498
#> 3 3 0.957           0.943       0.967         0.2500 0.848   0.702
#> 4 4 0.927           0.895       0.958         0.1225 0.883   0.704
#> 5 5 0.804           0.790       0.893         0.0717 0.921   0.750
#> 6 6 0.765           0.675       0.834         0.0378 0.985   0.941

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
#> aberrant_ERR2585320     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585338     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585325     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585283     1  0.6531      0.805 0.832 0.168
#> aberrant_ERR2585343     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585329     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585317     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585339     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585335     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585287     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585321     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585297     1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585337     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585319     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585315     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585336     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585307     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585301     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585326     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585331     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585346     1  0.1414      0.974 0.980 0.020
#> aberrant_ERR2585314     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585298     1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585345     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585299     1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585309     1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585303     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585313     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585318     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585328     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585330     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585293     1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585342     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585348     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585352     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585308     1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585349     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585316     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585306     1  0.3431      0.930 0.936 0.064
#> aberrant_ERR2585324     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585310     2  0.2236      0.958 0.036 0.964
#> aberrant_ERR2585296     1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585275     1  0.5408      0.861 0.876 0.124
#> aberrant_ERR2585311     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585292     1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585282     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585305     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585278     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585347     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585332     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585280     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585304     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585322     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585279     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585277     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585295     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585333     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585285     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585286     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585294     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585300     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585334     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585361     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585372     2  0.0000      0.991 0.000 1.000
#> round_ERR2585217        2  0.6048      0.833 0.148 0.852
#> round_ERR2585205        1  0.0000      0.993 1.000 0.000
#> round_ERR2585214        2  0.6712      0.796 0.176 0.824
#> round_ERR2585202        2  0.1414      0.973 0.020 0.980
#> aberrant_ERR2585367     2  0.0000      0.991 0.000 1.000
#> round_ERR2585220        1  0.0000      0.993 1.000 0.000
#> round_ERR2585238        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585276     2  0.0000      0.991 0.000 1.000
#> round_ERR2585218        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585363     2  0.0000      0.991 0.000 1.000
#> round_ERR2585201        1  0.0000      0.993 1.000 0.000
#> round_ERR2585210        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585362     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585360     2  0.0000      0.991 0.000 1.000
#> round_ERR2585209        1  0.0000      0.993 1.000 0.000
#> round_ERR2585242        1  0.0000      0.993 1.000 0.000
#> round_ERR2585216        1  0.0000      0.993 1.000 0.000
#> round_ERR2585219        1  0.0000      0.993 1.000 0.000
#> round_ERR2585237        2  0.6887      0.784 0.184 0.816
#> round_ERR2585198        1  0.0000      0.993 1.000 0.000
#> round_ERR2585211        1  0.0000      0.993 1.000 0.000
#> round_ERR2585206        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585281     2  0.0000      0.991 0.000 1.000
#> round_ERR2585212        1  0.0000      0.993 1.000 0.000
#> round_ERR2585221        1  0.0000      0.993 1.000 0.000
#> round_ERR2585243        1  0.0000      0.993 1.000 0.000
#> round_ERR2585204        2  0.6148      0.828 0.152 0.848
#> round_ERR2585213        2  0.0376      0.988 0.004 0.996
#> aberrant_ERR2585373     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585358     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585365     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585359     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585370     2  0.0000      0.991 0.000 1.000
#> round_ERR2585215        1  0.0000      0.993 1.000 0.000
#> round_ERR2585262        2  0.0000      0.991 0.000 1.000
#> round_ERR2585199        2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585369     2  0.0000      0.991 0.000 1.000
#> round_ERR2585208        1  0.0000      0.993 1.000 0.000
#> round_ERR2585252        1  0.0000      0.993 1.000 0.000
#> round_ERR2585236        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585284     1  0.6531      0.805 0.832 0.168
#> round_ERR2585224        1  0.0000      0.993 1.000 0.000
#> round_ERR2585260        1  0.0000      0.993 1.000 0.000
#> round_ERR2585229        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585364     2  0.0000      0.991 0.000 1.000
#> round_ERR2585253        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585368     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585371     2  0.0000      0.991 0.000 1.000
#> round_ERR2585239        1  0.0000      0.993 1.000 0.000
#> round_ERR2585273        1  0.0000      0.993 1.000 0.000
#> round_ERR2585256        1  0.0000      0.993 1.000 0.000
#> round_ERR2585272        1  0.0000      0.993 1.000 0.000
#> round_ERR2585246        1  0.0000      0.993 1.000 0.000
#> round_ERR2585261        1  0.0000      0.993 1.000 0.000
#> round_ERR2585254        1  0.0000      0.993 1.000 0.000
#> round_ERR2585225        1  0.0000      0.993 1.000 0.000
#> round_ERR2585235        1  0.0000      0.993 1.000 0.000
#> round_ERR2585271        1  0.0000      0.993 1.000 0.000
#> round_ERR2585251        1  0.0000      0.993 1.000 0.000
#> round_ERR2585255        1  0.0000      0.993 1.000 0.000
#> round_ERR2585257        1  0.0000      0.993 1.000 0.000
#> round_ERR2585226        1  0.0000      0.993 1.000 0.000
#> round_ERR2585265        1  0.0000      0.993 1.000 0.000
#> round_ERR2585259        1  0.0000      0.993 1.000 0.000
#> round_ERR2585247        1  0.0000      0.993 1.000 0.000
#> round_ERR2585241        1  0.0000      0.993 1.000 0.000
#> round_ERR2585263        1  0.0000      0.993 1.000 0.000
#> round_ERR2585264        1  0.0000      0.993 1.000 0.000
#> round_ERR2585233        1  0.0000      0.993 1.000 0.000
#> round_ERR2585223        1  0.0000      0.993 1.000 0.000
#> round_ERR2585234        1  0.0000      0.993 1.000 0.000
#> round_ERR2585222        1  0.0000      0.993 1.000 0.000
#> round_ERR2585228        1  0.0000      0.993 1.000 0.000
#> round_ERR2585248        1  0.0000      0.993 1.000 0.000
#> round_ERR2585240        1  0.0000      0.993 1.000 0.000
#> round_ERR2585270        1  0.0000      0.993 1.000 0.000
#> round_ERR2585232        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585341     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585355     2  0.0000      0.991 0.000 1.000
#> round_ERR2585227        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585351     2  0.0000      0.991 0.000 1.000
#> round_ERR2585269        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585357     2  0.0000      0.991 0.000 1.000
#> aberrant_ERR2585350     2  0.0000      0.991 0.000 1.000
#> round_ERR2585250        1  0.0000      0.993 1.000 0.000
#> round_ERR2585245        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585353     2  0.0000      0.991 0.000 1.000
#> round_ERR2585258        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585354     2  0.0000      0.991 0.000 1.000
#> round_ERR2585249        1  0.0000      0.993 1.000 0.000
#> round_ERR2585268        1  0.0000      0.993 1.000 0.000
#> aberrant_ERR2585356     2  0.0000      0.991 0.000 1.000
#> round_ERR2585266        1  0.0000      0.993 1.000 0.000
#> round_ERR2585231        1  0.0000      0.993 1.000 0.000
#> round_ERR2585230        1  0.0000      0.993 1.000 0.000
#> round_ERR2585267        1  0.0000      0.993 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-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 cell_type(p) k
#> ATC:skmeans 160     4.49e-20 2
#> ATC:skmeans 157     1.19e-24 3
#> ATC:skmeans 151     1.71e-28 4
#> ATC:skmeans 142     1.01e-25 5
#> ATC:skmeans 125     4.64e-22 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 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-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 0.556           0.869       0.927         0.4788 0.502   0.502
#> 3 3 0.734           0.765       0.829         0.2454 0.831   0.668
#> 4 4 0.869           0.869       0.949         0.1211 0.891   0.723
#> 5 5 0.800           0.784       0.914         0.0669 0.950   0.850
#> 6 6 0.769           0.729       0.889         0.0381 0.972   0.902

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
#> aberrant_ERR2585320     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585338     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585325     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585283     1  0.9129      0.607 0.672 0.328
#> aberrant_ERR2585343     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585329     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585317     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585339     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585335     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585287     2  0.9866      0.109 0.432 0.568
#> aberrant_ERR2585321     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585297     1  0.0000      0.892 1.000 0.000
#> aberrant_ERR2585337     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585319     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585315     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585336     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585307     2  0.4161      0.867 0.084 0.916
#> aberrant_ERR2585301     2  0.2603      0.908 0.044 0.956
#> aberrant_ERR2585326     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585331     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585346     1  0.4298      0.888 0.912 0.088
#> aberrant_ERR2585314     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585298     1  0.6148      0.874 0.848 0.152
#> aberrant_ERR2585345     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585299     1  0.0672      0.893 0.992 0.008
#> aberrant_ERR2585309     1  0.0000      0.892 1.000 0.000
#> aberrant_ERR2585303     2  0.0938      0.937 0.012 0.988
#> aberrant_ERR2585313     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585318     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585328     2  0.7139      0.717 0.196 0.804
#> aberrant_ERR2585330     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585293     1  0.0000      0.892 1.000 0.000
#> aberrant_ERR2585342     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585348     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585352     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585308     1  0.0000      0.892 1.000 0.000
#> aberrant_ERR2585349     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585316     2  0.5737      0.804 0.136 0.864
#> aberrant_ERR2585306     1  0.6247      0.872 0.844 0.156
#> aberrant_ERR2585324     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585310     1  0.7883      0.797 0.764 0.236
#> aberrant_ERR2585296     1  0.6247      0.872 0.844 0.156
#> aberrant_ERR2585275     1  0.9775      0.440 0.588 0.412
#> aberrant_ERR2585311     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585292     1  0.0000      0.892 1.000 0.000
#> aberrant_ERR2585282     2  0.0376      0.943 0.004 0.996
#> aberrant_ERR2585305     1  0.9710      0.494 0.600 0.400
#> aberrant_ERR2585278     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585347     2  0.0376      0.943 0.004 0.996
#> aberrant_ERR2585332     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585280     2  0.7376      0.699 0.208 0.792
#> aberrant_ERR2585304     1  0.8661      0.723 0.712 0.288
#> aberrant_ERR2585322     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585279     2  0.9358      0.389 0.352 0.648
#> aberrant_ERR2585277     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585295     2  0.9393      0.377 0.356 0.644
#> aberrant_ERR2585333     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585285     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585286     2  0.0376      0.943 0.004 0.996
#> aberrant_ERR2585294     2  0.8955      0.492 0.312 0.688
#> aberrant_ERR2585300     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585334     2  0.9248      0.422 0.340 0.660
#> aberrant_ERR2585361     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585372     2  0.0000      0.946 0.000 1.000
#> round_ERR2585217        1  0.7883      0.797 0.764 0.236
#> round_ERR2585205        1  0.0000      0.892 1.000 0.000
#> round_ERR2585214        1  0.7883      0.797 0.764 0.236
#> round_ERR2585202        1  0.7883      0.797 0.764 0.236
#> aberrant_ERR2585367     2  0.0000      0.946 0.000 1.000
#> round_ERR2585220        1  0.0672      0.893 0.992 0.008
#> round_ERR2585238        1  0.0000      0.892 1.000 0.000
#> aberrant_ERR2585276     2  0.8813      0.520 0.300 0.700
#> round_ERR2585218        1  0.0000      0.892 1.000 0.000
#> aberrant_ERR2585363     2  0.0000      0.946 0.000 1.000
#> round_ERR2585201        1  0.6623      0.860 0.828 0.172
#> round_ERR2585210        1  0.0000      0.892 1.000 0.000
#> aberrant_ERR2585362     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585360     2  0.0000      0.946 0.000 1.000
#> round_ERR2585209        1  0.6048      0.876 0.852 0.148
#> round_ERR2585242        1  0.6148      0.874 0.848 0.152
#> round_ERR2585216        1  0.0938      0.893 0.988 0.012
#> round_ERR2585219        1  0.0938      0.893 0.988 0.012
#> round_ERR2585237        1  0.7883      0.797 0.764 0.236
#> round_ERR2585198        1  0.6712      0.857 0.824 0.176
#> round_ERR2585211        1  0.0000      0.892 1.000 0.000
#> round_ERR2585206        1  0.0000      0.892 1.000 0.000
#> aberrant_ERR2585281     2  0.9393      0.377 0.356 0.644
#> round_ERR2585212        1  0.3879      0.889 0.924 0.076
#> round_ERR2585221        1  0.0000      0.892 1.000 0.000
#> round_ERR2585243        1  0.0000      0.892 1.000 0.000
#> round_ERR2585204        1  0.7883      0.797 0.764 0.236
#> round_ERR2585213        1  0.8207      0.771 0.744 0.256
#> aberrant_ERR2585373     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585358     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585365     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585359     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585370     2  0.0000      0.946 0.000 1.000
#> round_ERR2585215        1  0.0000      0.892 1.000 0.000
#> round_ERR2585262        1  0.8016      0.787 0.756 0.244
#> round_ERR2585199        1  0.7883      0.797 0.764 0.236
#> aberrant_ERR2585369     2  0.0000      0.946 0.000 1.000
#> round_ERR2585208        1  0.0000      0.892 1.000 0.000
#> round_ERR2585252        1  0.0000      0.892 1.000 0.000
#> round_ERR2585236        1  0.5059      0.885 0.888 0.112
#> aberrant_ERR2585284     1  0.8499      0.742 0.724 0.276
#> round_ERR2585224        1  0.0000      0.892 1.000 0.000
#> round_ERR2585260        1  0.0000      0.892 1.000 0.000
#> round_ERR2585229        1  0.0000      0.892 1.000 0.000
#> aberrant_ERR2585364     2  0.0000      0.946 0.000 1.000
#> round_ERR2585253        1  0.0000      0.892 1.000 0.000
#> aberrant_ERR2585368     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585371     2  0.0000      0.946 0.000 1.000
#> round_ERR2585239        1  0.3274      0.891 0.940 0.060
#> round_ERR2585273        1  0.0376      0.892 0.996 0.004
#> round_ERR2585256        1  0.6148      0.874 0.848 0.152
#> round_ERR2585272        1  0.0000      0.892 1.000 0.000
#> round_ERR2585246        1  0.0000      0.892 1.000 0.000
#> round_ERR2585261        1  0.6148      0.874 0.848 0.152
#> round_ERR2585254        1  0.6148      0.874 0.848 0.152
#> round_ERR2585225        1  0.6148      0.874 0.848 0.152
#> round_ERR2585235        1  0.5946      0.877 0.856 0.144
#> round_ERR2585271        1  0.0000      0.892 1.000 0.000
#> round_ERR2585251        1  0.5059      0.885 0.888 0.112
#> round_ERR2585255        1  0.7453      0.823 0.788 0.212
#> round_ERR2585257        1  0.6531      0.863 0.832 0.168
#> round_ERR2585226        1  0.6048      0.876 0.852 0.148
#> round_ERR2585265        1  0.0000      0.892 1.000 0.000
#> round_ERR2585259        1  0.5737      0.880 0.864 0.136
#> round_ERR2585247        1  0.0000      0.892 1.000 0.000
#> round_ERR2585241        1  0.0000      0.892 1.000 0.000
#> round_ERR2585263        1  0.6148      0.874 0.848 0.152
#> round_ERR2585264        1  0.0000      0.892 1.000 0.000
#> round_ERR2585233        1  0.6148      0.874 0.848 0.152
#> round_ERR2585223        1  0.0000      0.892 1.000 0.000
#> round_ERR2585234        1  0.6438      0.866 0.836 0.164
#> round_ERR2585222        1  0.6048      0.876 0.852 0.148
#> round_ERR2585228        1  0.0000      0.892 1.000 0.000
#> round_ERR2585248        1  0.0000      0.892 1.000 0.000
#> round_ERR2585240        1  0.6148      0.874 0.848 0.152
#> round_ERR2585270        1  0.5629      0.881 0.868 0.132
#> round_ERR2585232        1  0.6148      0.874 0.848 0.152
#> aberrant_ERR2585341     2  0.2948      0.900 0.052 0.948
#> aberrant_ERR2585355     2  0.0000      0.946 0.000 1.000
#> round_ERR2585227        1  0.5178      0.884 0.884 0.116
#> aberrant_ERR2585351     2  0.0000      0.946 0.000 1.000
#> round_ERR2585269        1  0.0000      0.892 1.000 0.000
#> aberrant_ERR2585357     2  0.0000      0.946 0.000 1.000
#> aberrant_ERR2585350     2  0.0000      0.946 0.000 1.000
#> round_ERR2585250        1  0.6148      0.874 0.848 0.152
#> round_ERR2585245        1  0.0000      0.892 1.000 0.000
#> aberrant_ERR2585353     2  0.0000      0.946 0.000 1.000
#> round_ERR2585258        1  0.0000      0.892 1.000 0.000
#> aberrant_ERR2585354     2  0.0000      0.946 0.000 1.000
#> round_ERR2585249        1  0.0000      0.892 1.000 0.000
#> round_ERR2585268        1  0.6148      0.874 0.848 0.152
#> aberrant_ERR2585356     2  0.0000      0.946 0.000 1.000
#> round_ERR2585266        1  0.6148      0.874 0.848 0.152
#> round_ERR2585231        1  0.0000      0.892 1.000 0.000
#> round_ERR2585230        1  0.2948      0.891 0.948 0.052
#> round_ERR2585267        1  0.0000      0.892 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 cell_type(p) k
#> ATC:pam 152     6.61e-24 2
#> ATC:pam 140     1.46e-23 3
#> ATC:pam 150     4.48e-24 4
#> ATC:pam 137     1.21e-22 5
#> ATC:pam 132     5.06e-20 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 0.999           0.981       0.992         0.5030 0.497   0.497
#> 3 3 0.931           0.926       0.968         0.1361 0.939   0.878
#> 4 4 0.818           0.823       0.918         0.1237 0.880   0.738
#> 5 5 0.820           0.827       0.919         0.1691 0.846   0.590
#> 6 6 0.718           0.708       0.797         0.0425 0.954   0.825

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
#> aberrant_ERR2585320     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585338     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585325     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585283     2   0.327     0.9396 0.060 0.940
#> aberrant_ERR2585343     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585329     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585317     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585339     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585335     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585287     2   0.327     0.9396 0.060 0.940
#> aberrant_ERR2585321     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585297     1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585337     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585319     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585315     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585336     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585307     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585301     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585326     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585331     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585346     2   0.327     0.9396 0.060 0.940
#> aberrant_ERR2585314     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585298     1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585345     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585299     1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585309     1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585303     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585313     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585318     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585328     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585330     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585293     2   0.327     0.9396 0.060 0.940
#> aberrant_ERR2585342     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585348     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585352     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585308     1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585349     2   0.260     0.9507 0.044 0.956
#> aberrant_ERR2585316     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585306     2   0.204     0.9622 0.032 0.968
#> aberrant_ERR2585324     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585310     2   1.000     0.0324 0.500 0.500
#> aberrant_ERR2585296     1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585275     2   0.327     0.9396 0.060 0.940
#> aberrant_ERR2585311     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585292     2   0.327     0.9396 0.060 0.940
#> aberrant_ERR2585282     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585305     2   0.278     0.9501 0.048 0.952
#> aberrant_ERR2585278     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585347     2   0.163     0.9682 0.024 0.976
#> aberrant_ERR2585332     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585280     2   0.184     0.9654 0.028 0.972
#> aberrant_ERR2585304     1   0.327     0.9344 0.940 0.060
#> aberrant_ERR2585322     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585279     2   0.518     0.8783 0.116 0.884
#> aberrant_ERR2585277     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585295     2   0.260     0.9532 0.044 0.956
#> aberrant_ERR2585333     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585285     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585286     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585294     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585300     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585334     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585361     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585372     2   0.000     0.9840 0.000 1.000
#> round_ERR2585217        1   0.000     0.9992 1.000 0.000
#> round_ERR2585205        1   0.000     0.9992 1.000 0.000
#> round_ERR2585214        1   0.000     0.9992 1.000 0.000
#> round_ERR2585202        1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585367     2   0.000     0.9840 0.000 1.000
#> round_ERR2585220        1   0.000     0.9992 1.000 0.000
#> round_ERR2585238        1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585276     2   0.000     0.9840 0.000 1.000
#> round_ERR2585218        1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585363     2   0.000     0.9840 0.000 1.000
#> round_ERR2585201        1   0.000     0.9992 1.000 0.000
#> round_ERR2585210        1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585362     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585360     2   0.000     0.9840 0.000 1.000
#> round_ERR2585209        1   0.000     0.9992 1.000 0.000
#> round_ERR2585242        1   0.000     0.9992 1.000 0.000
#> round_ERR2585216        1   0.000     0.9992 1.000 0.000
#> round_ERR2585219        1   0.000     0.9992 1.000 0.000
#> round_ERR2585237        1   0.000     0.9992 1.000 0.000
#> round_ERR2585198        1   0.000     0.9992 1.000 0.000
#> round_ERR2585211        1   0.000     0.9992 1.000 0.000
#> round_ERR2585206        1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585281     2   0.184     0.9654 0.028 0.972
#> round_ERR2585212        1   0.000     0.9992 1.000 0.000
#> round_ERR2585221        1   0.000     0.9992 1.000 0.000
#> round_ERR2585243        1   0.000     0.9992 1.000 0.000
#> round_ERR2585204        1   0.000     0.9992 1.000 0.000
#> round_ERR2585213        1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585373     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585358     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585365     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585359     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585370     2   0.000     0.9840 0.000 1.000
#> round_ERR2585215        1   0.000     0.9992 1.000 0.000
#> round_ERR2585262        1   0.000     0.9992 1.000 0.000
#> round_ERR2585199        1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585369     2   0.000     0.9840 0.000 1.000
#> round_ERR2585208        1   0.000     0.9992 1.000 0.000
#> round_ERR2585252        1   0.000     0.9992 1.000 0.000
#> round_ERR2585236        1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585284     2   0.327     0.9396 0.060 0.940
#> round_ERR2585224        1   0.000     0.9992 1.000 0.000
#> round_ERR2585260        1   0.000     0.9992 1.000 0.000
#> round_ERR2585229        1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585364     2   0.000     0.9840 0.000 1.000
#> round_ERR2585253        1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585368     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585371     2   0.000     0.9840 0.000 1.000
#> round_ERR2585239        1   0.000     0.9992 1.000 0.000
#> round_ERR2585273        1   0.000     0.9992 1.000 0.000
#> round_ERR2585256        1   0.000     0.9992 1.000 0.000
#> round_ERR2585272        1   0.000     0.9992 1.000 0.000
#> round_ERR2585246        1   0.000     0.9992 1.000 0.000
#> round_ERR2585261        1   0.000     0.9992 1.000 0.000
#> round_ERR2585254        1   0.000     0.9992 1.000 0.000
#> round_ERR2585225        1   0.000     0.9992 1.000 0.000
#> round_ERR2585235        1   0.000     0.9992 1.000 0.000
#> round_ERR2585271        1   0.000     0.9992 1.000 0.000
#> round_ERR2585251        1   0.000     0.9992 1.000 0.000
#> round_ERR2585255        1   0.000     0.9992 1.000 0.000
#> round_ERR2585257        1   0.000     0.9992 1.000 0.000
#> round_ERR2585226        1   0.000     0.9992 1.000 0.000
#> round_ERR2585265        1   0.000     0.9992 1.000 0.000
#> round_ERR2585259        1   0.000     0.9992 1.000 0.000
#> round_ERR2585247        1   0.000     0.9992 1.000 0.000
#> round_ERR2585241        1   0.000     0.9992 1.000 0.000
#> round_ERR2585263        1   0.000     0.9992 1.000 0.000
#> round_ERR2585264        1   0.000     0.9992 1.000 0.000
#> round_ERR2585233        1   0.000     0.9992 1.000 0.000
#> round_ERR2585223        1   0.000     0.9992 1.000 0.000
#> round_ERR2585234        1   0.000     0.9992 1.000 0.000
#> round_ERR2585222        1   0.000     0.9992 1.000 0.000
#> round_ERR2585228        1   0.000     0.9992 1.000 0.000
#> round_ERR2585248        1   0.000     0.9992 1.000 0.000
#> round_ERR2585240        1   0.000     0.9992 1.000 0.000
#> round_ERR2585270        1   0.000     0.9992 1.000 0.000
#> round_ERR2585232        1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585341     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585355     2   0.000     0.9840 0.000 1.000
#> round_ERR2585227        1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585351     2   0.000     0.9840 0.000 1.000
#> round_ERR2585269        1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585357     2   0.000     0.9840 0.000 1.000
#> aberrant_ERR2585350     2   0.000     0.9840 0.000 1.000
#> round_ERR2585250        1   0.000     0.9992 1.000 0.000
#> round_ERR2585245        1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585353     2   0.000     0.9840 0.000 1.000
#> round_ERR2585258        1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585354     2   0.000     0.9840 0.000 1.000
#> round_ERR2585249        1   0.000     0.9992 1.000 0.000
#> round_ERR2585268        1   0.000     0.9992 1.000 0.000
#> aberrant_ERR2585356     2   0.000     0.9840 0.000 1.000
#> round_ERR2585266        1   0.000     0.9992 1.000 0.000
#> round_ERR2585231        1   0.000     0.9992 1.000 0.000
#> round_ERR2585230        1   0.000     0.9992 1.000 0.000
#> round_ERR2585267        1   0.000     0.9992 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)

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

Signature heatmaps where rows are not scaled:

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

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 cell_type(p) k
#> ATC:mclust 159     5.02e-30 2
#> ATC:mclust 156     9.21e-30 3
#> ATC:mclust 148     2.21e-26 4
#> ATC:mclust 146     3.94e-25 5
#> ATC:mclust 139     2.43e-24 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 5576 rows and 160 columns.
#>   Top rows (558, 1116, 1673, 2230, 2788) 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 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-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.976       0.990         0.5015 0.499   0.499
#> 3 3 0.806           0.828       0.921         0.2964 0.809   0.633
#> 4 4 0.765           0.791       0.889         0.0870 0.872   0.667
#> 5 5 0.699           0.707       0.832         0.0364 0.977   0.922
#> 6 6 0.652           0.548       0.766         0.0478 0.959   0.861

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
#> aberrant_ERR2585320     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585338     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585325     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585283     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585343     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585329     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585317     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585339     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585335     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585287     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585321     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585297     1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585337     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585319     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585315     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585336     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585307     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585301     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585326     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585331     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585346     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585314     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585298     1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585345     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585299     1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585309     1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585303     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585313     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585318     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585328     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585330     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585293     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585342     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585348     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585352     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585308     1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585349     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585316     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585306     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585324     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585310     2  0.6048     0.8224 0.148 0.852
#> aberrant_ERR2585296     1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585275     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585311     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585292     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585282     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585305     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585278     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585347     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585332     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585280     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585304     2  0.0672     0.9824 0.008 0.992
#> aberrant_ERR2585322     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585279     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585277     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585295     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585333     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585285     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585286     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585294     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585300     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585334     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585361     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585372     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585217        1  0.0376     0.9859 0.996 0.004
#> round_ERR2585205        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585214        1  0.7815     0.7001 0.768 0.232
#> round_ERR2585202        1  0.8861     0.5651 0.696 0.304
#> aberrant_ERR2585367     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585220        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585238        1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585276     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585218        1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585363     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585201        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585210        1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585362     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585360     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585209        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585242        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585216        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585219        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585237        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585198        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585211        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585206        1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585281     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585212        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585221        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585243        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585204        1  0.7299     0.7447 0.796 0.204
#> round_ERR2585213        2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585373     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585358     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585365     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585359     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585370     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585215        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585262        2  0.7056     0.7587 0.192 0.808
#> round_ERR2585199        2  0.9977     0.0928 0.472 0.528
#> aberrant_ERR2585369     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585208        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585252        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585236        1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585284     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585224        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585260        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585229        1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585364     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585253        1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585368     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585371     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585239        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585273        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585256        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585272        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585246        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585261        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585254        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585225        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585235        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585271        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585251        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585255        1  0.1184     0.9745 0.984 0.016
#> round_ERR2585257        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585226        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585265        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585259        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585247        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585241        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585263        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585264        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585233        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585223        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585234        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585222        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585228        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585248        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585240        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585270        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585232        1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585341     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585355     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585227        1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585351     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585269        1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585357     2  0.0000     0.9901 0.000 1.000
#> aberrant_ERR2585350     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585250        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585245        1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585353     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585258        1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585354     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585249        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585268        1  0.0000     0.9896 1.000 0.000
#> aberrant_ERR2585356     2  0.0000     0.9901 0.000 1.000
#> round_ERR2585266        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585231        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585230        1  0.0000     0.9896 1.000 0.000
#> round_ERR2585267        1  0.0000     0.9896 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 cell_type(p) k
#> ATC:NMF 159     4.69e-29 2
#> ATC:NMF 145     1.67e-21 3
#> ATC:NMF 146     4.69e-19 4
#> ATC:NMF 131     1.51e-16 5
#> ATC:NMF 107     9.83e-12 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