Date: 2021-07-26 10:19:05 CEST, cola version: 1.9.4
Document is loading...
First the variable is renamed to res_rh
.
res_rh = rh
The partition hierarchy and all available functions which can be applied to res_rh
object.
res_rh
#> A 'HierarchicalPartition' object with 'ATC:skmeans' method.
#> On a matrix with 11135 rows and 96 columns.
#> Performed in total 600 partitions.
#> There are 3 groups under the following parameters:
#> - min_samples: 6
#> - mean_silhouette_cutoff: 0.9
#> - min_n_signatures: 195 (signatures are selected based on:)
#> - fdr_cutoff: 0.05
#> - group_diff (scaled values): 0.5
#>
#> Hierarchy of the partition:
#> 0, 96 cols
#> |-- 01, 45 cols, 41 signatures (c)
#> |-- 02, 30 cols, 131 signatures (c)
#> `-- 03, 21 cols, 2 signatures (c)
#> Stop reason:
#> c) There were too few signatures.
#>
#> Following methods can be applied to this 'HierarchicalPartition' object:
#> [1] "all_leaves" "all_nodes" "cola_report" "collect_classes"
#> [5] "colnames" "compare_signatures" "dimension_reduction" "functional_enrichment"
#> [9] "get_anno_col" "get_anno" "get_children_nodes" "get_classes"
#> [13] "get_matrix" "get_signatures" "is_leaf_node" "max_depth"
#> [17] "merge_node" "ncol" "node_info" "node_level"
#> [21] "nrow" "rownames" "show" "split_node"
#> [25] "suggest_best_k" "test_to_known_factors" "top_rows_heatmap" "top_rows_overlap"
#>
#> You can get result for a single node by e.g. object["01"]
The call of hierarchical_partition()
was:
#> hierarchical_partition(data = mat, anno = anno, subset = 500, cores = 4)
Dimension of the input matrix:
mat = get_matrix(res_rh)
dim(mat)
#> [1] 11135 96
All the methods that were tried:
res_rh@param$combination_method
#> [[1]]
#> [1] "ATC" "skmeans"
The density distribution for each sample is visualized as 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_rh),
col = get_anno_col(res_rh)), ylab = "value", cluster_columns = TRUE, show_column_names = FALSE,
mc.cores = 1)
Some values about the hierarchy:
all_nodes(res_rh)
#> [1] "0" "01" "02" "03"
all_leaves(res_rh)
#> [1] "01" "02" "03"
node_info(res_rh)
#> id best_method depth best_k n_columns n_signatures p_signatures is_leaf
#> 1 0 ATC:skmeans 1 3 96 3905 0.35070 FALSE
#> 2 01 ATC:skmeans 2 2 45 41 0.00368 TRUE
#> 3 02 ATC:skmeans 2 2 30 131 0.01176 TRUE
#> 4 03 ATC:skmeans 2 2 21 2 0.00018 TRUE
In the output from node_info()
, there are the following columns:
id
: The node id.best_method
: The best method selected.depth
: Depth of the node in the hierarchy.best_k
: Best number of groups of the partition on that node.n_columns
: Number of columns in the submatrix.n_signatures
: Number of signatures with the best_k
.p_signatures
: Proportion of hte signatures in total number of rows in the matrix.is_leaf
: Whether the node is a leaf.Labels of nodes are encoded in a special way. The number of digits correspond to the depth of the node in the hierarchy and the value of the digits correspond to the index of the subgroup in the current node, E.g. a label of “012” means the node is the second subgroup of the partition which is the first subgroup of the root node.
Following table shows the best k
(number of partitions) for each node in the
partition hierarchy. Clicking on the node name in the table goes to the
corresponding section for the partitioning on that node.
The cola vignette explains the definition of the metrics used for determining the best number of partitions.
suggest_best_k(res_rh)
Node | Best method | Is leaf | Best k | 1-PAC | Mean silhouette | Concordance | #samples | |
---|---|---|---|---|---|---|---|---|
Node0 | ATC:skmeans | 3 | 0.97 | 0.96 | 0.98 | 96 | ** | |
Node01-leaf | ATC:skmeans | ✓ (c) | 2 | 1.00 | 0.97 | 0.99 | 45 | ** |
Node02-leaf | ATC:skmeans | ✓ (c) | 3 | 0.97 | 0.92 | 0.96 | 30 | ** |
Node03-leaf | ATC:skmeans | ✓ (c) | 2 | 1.00 | 0.97 | 0.99 | 21 | ** |
Stop reason: c) There were too few signatures.
**: 1-PAC > 0.95, *: 1-PAC > 0.9
The nodes of the hierarchy can be merged by setting the merge_node
parameters. Here we
control the hierarchy with the min_n_signatures
parameter. The value of min_n_signatures
is
from node_info()
.
collect_classes(res_rh, merge_node = merge_node_param(min_n_signatures = 3905))
Following shows the table of the partitions (You need to click the show/hide code output link to see it).
get_classes(res_rh, merge_node = merge_node_param(min_n_signatures = 3905))
#> ERR488983 ERR488967 ERR488989 ERR489021 ERR488955 ERR489013 ERR489019 ERR488974 ERR488990 ERR489038
#> "03" "01" "01" "02" "03" "02" "01" "02" "03" "01"
#> ERR489032 ERR489045 ERR489000 ERR489007 ERR489042 ERR489035 ERR488973 ERR488979 ERR488997 ERR489014
#> "03" "01" "01" "03" "03" "02" "02" "03" "03" "02"
#> ERR488958 ERR488952 ERR489026 ERR488984 ERR488960 ERR489028 ERR489022 ERR488964 ERR488980 ERR489010
#> "02" "01" "01" "03" "02" "01" "01" "01" "01" "02"
#> ERR488956 ERR489046 ERR489031 ERR488993 ERR488999 ERR488977 ERR489003 ERR489009 ERR489004 ERR488994
#> "02" "01" "01" "01" "02" "01" "02" "03" "01" "01"
#> ERR488970 ERR489036 ERR489041 ERR489017 ERR488963 ERR488987 ERR488969 ERR489025 ERR489015 ERR488953
#> "01" "01" "01" "03" "03" "01" "02" "03" "02" "01"
#> ERR488959 ERR489027 ERR488961 ERR488985 ERR489006 ERR489034 ERR489043 ERR488978 ERR488996 ERR488972
#> "01" "02" "01" "01" "02" "02" "01" "02" "01" "02"
#> ERR488991 ERR488975 ERR489044 ERR489033 ERR489039 ERR489001 ERR488966 ERR488988 ERR488982 ERR489020
#> "01" "01" "03" "02" "01" "02" "02" "03" "01" "02"
#> ERR488954 ERR489018 ERR489012 ERR489016 ERR488986 ERR488968 ERR488962 ERR489024 ERR489005 ERR488971
#> "01" "01" "03" "03" "03" "01" "01" "01" "02" "02"
#> ERR488995 ERR489040 ERR489037 ERR489030 ERR489047 ERR488998 ERR488976 ERR488992 ERR489008 ERR489002
#> "02" "01" "03" "03" "01" "01" "02" "01" "01" "02"
#> ERR489023 ERR489029 ERR488981 ERR488965 ERR489011 ERR488957
#> "02" "01" "03" "01" "01" "02"
Heatmaps of the top rows:
top_rows_heatmap(res_rh)
Top rows on each node:
top_rows_overlap(res_rh, method = "upset")
#> Error: Expect at least two lists.
UMAP plot which shows how samples are separated.
par(mfrow = c(1, 2))
dimension_reduction(res_rh, merge_node = merge_node_param(min_n_signatures = 3905),
method = "UMAP", top_value_method = "SD", top_n = 1200, scale_rows = FALSE)
dimension_reduction(res_rh, merge_node = merge_node_param(min_n_signatures = 3905),
method = "UMAP", top_value_method = "ATC", top_n = 1200, scale_rows = TRUE)
Signatures on the heatmap are the union of all signatures found on every node on the hierarchy. The number of k-means on rows are automatically selected by the function.
get_signatures(res_rh, merge_node = merge_node_param(min_n_signatures = 3905))
Compare signatures from different nodes:
compare_signatures(res_rh, verbose = FALSE)
If there are too many signatures, top_signatures = ...
can be set to only show the
signatures with the highest FDRs. Note it only works on every node and the final signatures
are the union of all signatures of all nodes.
# code only for demonstration
# e.g. to show the top 500 most significant rows on each node.
tb = get_signature(res_rh, top_signatures = 500)
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_rh, merge_node = merge_node_param(min_n_signatures = 3905))
#> anno
#> class 0.446
Child nodes: Node01-leaf , Node02-leaf , Node03-leaf .
The object with results only for a single top-value method and a single partitioning method can be extracted as:
res = res_rh["0"]
A summary of res
and all the functions that can be applied to it:
res
#> A 'ConsensusPartition' object with k = 2, 3, 4.
#> On a matrix with 10578 rows and 96 columns.
#> Top rows (1058) are extracted by 'ATC' method.
#> Subgroups are detected by 'skmeans' method.
#> Performed in total 150 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_partitions"
#> [7] "compare_signatures" "consensus_heatmap" "dimension_reduction"
#> [10] "functional_enrichment" "get_anno_col" "get_anno"
#> [13] "get_classes" "get_consensus" "get_matrix"
#> [16] "get_membership" "get_param" "get_signatures"
#> [19] "get_stats" "is_best_k" "is_stable_k"
#> [22] "membership_heatmap" "ncol" "nrow"
#> [25] "plot_ecdf" "predict_classes" "rownames"
#> [28] "select_partition_number" "show" "suggest_best_k"
#> [31] "test_to_known_factors" "top_rows_heatmap"
collect_plots()
function collects all the plots made from res
for all k
(number of subgroups)
into one single page to provide an easy and fast comparison between different k
.
collect_plots(res)
The plots are:
k
and the heatmap of
predicted classes for each k
.k
.k
.k
.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:
k
;k
, the area increased is defined as \(A_k - A_{k-1}\).The detailed explanations of these statistics can be found in the cola vignette.
Generally speaking, higher 1-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)
The numeric values for all these statistics can be obtained by get_stats()
.
get_stats(res)
#> k 1-PAC mean_silhouette concordance area_increased Rand Jaccard
#> 2 2 1.000 0.998 0.999 0.4947 0.505 0.505
#> 3 3 0.970 0.959 0.981 0.2885 0.805 0.631
#> 4 4 0.849 0.825 0.924 0.0794 0.924 0.797
suggest_best_k()
suggests the best \(k\) based on these statistics. The rules are as follows:
suggest_best_k(res)
#> [1] 3
#> attr(,"optional")
#> [1] 2
There is also optional best \(k\) = 2 that is worth to check.
Following is 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 subgroup
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.
cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#> class entropy silhouette p1 p2
#> ERR488983 2 0.000 0.997 0.0 1.0
#> ERR488967 1 0.000 1.000 1.0 0.0
#> ERR488989 1 0.000 1.000 1.0 0.0
#> ERR489021 2 0.000 0.997 0.0 1.0
#> ERR488955 1 0.000 1.000 1.0 0.0
#> ERR489013 2 0.000 0.997 0.0 1.0
#> ERR489019 1 0.000 1.000 1.0 0.0
#> ERR488974 2 0.000 0.997 0.0 1.0
#> ERR488990 2 0.000 0.997 0.0 1.0
#> ERR489038 1 0.000 1.000 1.0 0.0
#> ERR489032 1 0.000 1.000 1.0 0.0
#> ERR489045 1 0.000 1.000 1.0 0.0
#> ERR489000 1 0.000 1.000 1.0 0.0
#> ERR489007 1 0.000 1.000 1.0 0.0
#> ERR489042 1 0.000 1.000 1.0 0.0
#> ERR489035 2 0.000 0.997 0.0 1.0
#> ERR488973 2 0.000 0.997 0.0 1.0
#> ERR488979 1 0.000 1.000 1.0 0.0
#> ERR488997 1 0.000 1.000 1.0 0.0
#> ERR489014 2 0.000 0.997 0.0 1.0
#> ERR488958 2 0.000 0.997 0.0 1.0
#> ERR488952 1 0.000 1.000 1.0 0.0
#> ERR489026 1 0.000 1.000 1.0 0.0
#> ERR488984 1 0.000 1.000 1.0 0.0
#> ERR488960 2 0.000 0.997 0.0 1.0
#> ERR489028 1 0.000 1.000 1.0 0.0
#> ERR489022 1 0.000 1.000 1.0 0.0
#> ERR488964 1 0.000 1.000 1.0 0.0
#> ERR488980 1 0.000 1.000 1.0 0.0
#> ERR489010 2 0.000 0.997 0.0 1.0
#> ERR488956 2 0.000 0.997 0.0 1.0
#> ERR489046 1 0.000 1.000 1.0 0.0
#> ERR489031 1 0.000 1.000 1.0 0.0
#> ERR488993 1 0.000 1.000 1.0 0.0
#> ERR488999 2 0.000 0.997 0.0 1.0
#> ERR488977 1 0.000 1.000 1.0 0.0
#> ERR489003 2 0.000 0.997 0.0 1.0
#> ERR489009 2 0.000 0.997 0.0 1.0
#> ERR489004 1 0.000 1.000 1.0 0.0
#> ERR488994 1 0.000 1.000 1.0 0.0
#> ERR488970 1 0.000 1.000 1.0 0.0
#> ERR489036 1 0.000 1.000 1.0 0.0
#> ERR489041 1 0.000 1.000 1.0 0.0
#> ERR489017 2 0.000 0.997 0.0 1.0
#> ERR488963 2 0.000 0.997 0.0 1.0
#> ERR488987 1 0.000 1.000 1.0 0.0
#> ERR488969 2 0.000 0.997 0.0 1.0
#> ERR489025 2 0.000 0.997 0.0 1.0
#> ERR489015 2 0.000 0.997 0.0 1.0
#> ERR488953 1 0.000 1.000 1.0 0.0
#> ERR488959 1 0.000 1.000 1.0 0.0
#> ERR489027 2 0.000 0.997 0.0 1.0
#> ERR488961 1 0.000 1.000 1.0 0.0
#> ERR488985 1 0.000 1.000 1.0 0.0
#> ERR489006 2 0.000 0.997 0.0 1.0
#> ERR489034 2 0.000 0.997 0.0 1.0
#> ERR489043 1 0.000 1.000 1.0 0.0
#> ERR488978 2 0.000 0.997 0.0 1.0
#> ERR488996 1 0.000 1.000 1.0 0.0
#> ERR488972 2 0.000 0.997 0.0 1.0
#> ERR488991 1 0.000 1.000 1.0 0.0
#> ERR488975 1 0.000 1.000 1.0 0.0
#> ERR489044 2 0.000 0.997 0.0 1.0
#> ERR489033 2 0.000 0.997 0.0 1.0
#> ERR489039 1 0.000 1.000 1.0 0.0
#> ERR489001 2 0.000 0.997 0.0 1.0
#> ERR488966 2 0.000 0.997 0.0 1.0
#> ERR488988 1 0.000 1.000 1.0 0.0
#> ERR488982 1 0.000 1.000 1.0 0.0
#> ERR489020 2 0.000 0.997 0.0 1.0
#> ERR488954 1 0.000 1.000 1.0 0.0
#> ERR489018 1 0.000 1.000 1.0 0.0
#> ERR489012 2 0.000 0.997 0.0 1.0
#> ERR489016 1 0.000 1.000 1.0 0.0
#> ERR488986 2 0.469 0.889 0.1 0.9
#> ERR488968 1 0.000 1.000 1.0 0.0
#> ERR488962 1 0.000 1.000 1.0 0.0
#> ERR489024 1 0.000 1.000 1.0 0.0
#> ERR489005 2 0.000 0.997 0.0 1.0
#> ERR488971 2 0.000 0.997 0.0 1.0
#> ERR488995 2 0.000 0.997 0.0 1.0
#> ERR489040 1 0.000 1.000 1.0 0.0
#> ERR489037 2 0.000 0.997 0.0 1.0
#> ERR489030 2 0.000 0.997 0.0 1.0
#> ERR489047 1 0.000 1.000 1.0 0.0
#> ERR488998 1 0.000 1.000 1.0 0.0
#> ERR488976 2 0.000 0.997 0.0 1.0
#> ERR488992 1 0.000 1.000 1.0 0.0
#> ERR489008 1 0.000 1.000 1.0 0.0
#> ERR489002 2 0.000 0.997 0.0 1.0
#> ERR489023 2 0.000 0.997 0.0 1.0
#> ERR489029 1 0.000 1.000 1.0 0.0
#> ERR488981 1 0.000 1.000 1.0 0.0
#> ERR488965 1 0.000 1.000 1.0 0.0
#> ERR489011 1 0.000 1.000 1.0 0.0
#> ERR488957 2 0.000 0.997 0.0 1.0
cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#> class entropy silhouette p1 p2 p3
#> ERR488983 3 0.0000 0.928 0.00 0.00 1.00
#> ERR488967 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488989 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489021 2 0.1529 0.954 0.00 0.96 0.04
#> ERR488955 3 0.0000 0.928 0.00 0.00 1.00
#> ERR489013 2 0.0000 0.985 0.00 1.00 0.00
#> ERR489019 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488974 2 0.0000 0.985 0.00 1.00 0.00
#> ERR488990 3 0.0000 0.928 0.00 0.00 1.00
#> ERR489038 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489032 3 0.5560 0.607 0.30 0.00 0.70
#> ERR489045 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489000 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489007 3 0.2066 0.899 0.06 0.00 0.94
#> ERR489042 3 0.0892 0.923 0.02 0.00 0.98
#> ERR489035 2 0.0000 0.985 0.00 1.00 0.00
#> ERR488973 2 0.0000 0.985 0.00 1.00 0.00
#> ERR488979 3 0.0000 0.928 0.00 0.00 1.00
#> ERR488997 3 0.0000 0.928 0.00 0.00 1.00
#> ERR489014 2 0.0000 0.985 0.00 1.00 0.00
#> ERR488958 2 0.0000 0.985 0.00 1.00 0.00
#> ERR488952 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489026 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488984 3 0.3686 0.831 0.14 0.00 0.86
#> ERR488960 2 0.0000 0.985 0.00 1.00 0.00
#> ERR489028 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489022 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488964 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488980 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489010 2 0.0000 0.985 0.00 1.00 0.00
#> ERR488956 2 0.5706 0.526 0.00 0.68 0.32
#> ERR489046 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489031 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488993 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488999 2 0.0000 0.985 0.00 1.00 0.00
#> ERR488977 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489003 2 0.0000 0.985 0.00 1.00 0.00
#> ERR489009 3 0.0000 0.928 0.00 0.00 1.00
#> ERR489004 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488994 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488970 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489036 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489041 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489017 3 0.4291 0.769 0.00 0.18 0.82
#> ERR488963 3 0.0892 0.920 0.00 0.02 0.98
#> ERR488987 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488969 2 0.0000 0.985 0.00 1.00 0.00
#> ERR489025 3 0.0000 0.928 0.00 0.00 1.00
#> ERR489015 2 0.0892 0.972 0.00 0.98 0.02
#> ERR488953 1 0.3686 0.827 0.86 0.00 0.14
#> ERR488959 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489027 2 0.0000 0.985 0.00 1.00 0.00
#> ERR488961 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488985 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489006 2 0.0000 0.985 0.00 1.00 0.00
#> ERR489034 2 0.0000 0.985 0.00 1.00 0.00
#> ERR489043 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488978 2 0.0000 0.985 0.00 1.00 0.00
#> ERR488996 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488972 2 0.0892 0.972 0.00 0.98 0.02
#> ERR488991 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488975 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489044 3 0.0000 0.928 0.00 0.00 1.00
#> ERR489033 2 0.0000 0.985 0.00 1.00 0.00
#> ERR489039 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489001 2 0.0000 0.985 0.00 1.00 0.00
#> ERR488966 2 0.0000 0.985 0.00 1.00 0.00
#> ERR488988 3 0.0892 0.923 0.02 0.00 0.98
#> ERR488982 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489020 2 0.0000 0.985 0.00 1.00 0.00
#> ERR488954 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489018 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489012 3 0.2066 0.894 0.00 0.06 0.94
#> ERR489016 3 0.0892 0.923 0.02 0.00 0.98
#> ERR488986 3 0.0000 0.928 0.00 0.00 1.00
#> ERR488968 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488962 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489024 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489005 2 0.0000 0.985 0.00 1.00 0.00
#> ERR488971 2 0.0892 0.972 0.00 0.98 0.02
#> ERR488995 2 0.0000 0.985 0.00 1.00 0.00
#> ERR489040 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489037 3 0.3686 0.816 0.00 0.14 0.86
#> ERR489030 3 0.0892 0.921 0.00 0.02 0.98
#> ERR489047 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488998 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488976 2 0.0892 0.972 0.00 0.98 0.02
#> ERR488992 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489008 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489002 2 0.0000 0.985 0.00 1.00 0.00
#> ERR489023 2 0.0000 0.985 0.00 1.00 0.00
#> ERR489029 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488981 3 0.5560 0.607 0.30 0.00 0.70
#> ERR488965 1 0.0000 0.997 1.00 0.00 0.00
#> ERR489011 1 0.0000 0.997 1.00 0.00 0.00
#> ERR488957 2 0.0000 0.985 0.00 1.00 0.00
cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#> class entropy silhouette p1 p2 p3 p4
#> ERR488983 3 0.0000 0.718 0.00 0.00 1.00 0.00
#> ERR488967 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR488989 1 0.1211 0.930 0.96 0.00 0.00 0.04
#> ERR489021 3 0.3975 0.623 0.00 0.24 0.76 0.00
#> ERR488955 3 0.5256 0.432 0.04 0.00 0.70 0.26
#> ERR489013 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR489019 1 0.3975 0.683 0.76 0.00 0.00 0.24
#> ERR488974 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR488990 3 0.0000 0.718 0.00 0.00 1.00 0.00
#> ERR489038 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489032 4 0.6808 0.481 0.32 0.00 0.12 0.56
#> ERR489045 1 0.1211 0.932 0.96 0.00 0.00 0.04
#> ERR489000 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489007 4 0.1637 0.752 0.00 0.00 0.06 0.94
#> ERR489042 4 0.6714 0.390 0.10 0.00 0.36 0.54
#> ERR489035 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR488973 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR488979 4 0.2345 0.741 0.00 0.00 0.10 0.90
#> ERR488997 3 0.4790 0.232 0.00 0.00 0.62 0.38
#> ERR489014 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR488958 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR488952 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489026 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR488984 4 0.1411 0.754 0.02 0.00 0.02 0.96
#> ERR488960 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR489028 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489022 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR488964 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR488980 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489010 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR488956 3 0.5535 0.359 0.00 0.42 0.56 0.02
#> ERR489046 1 0.2011 0.892 0.92 0.00 0.00 0.08
#> ERR489031 1 0.3975 0.673 0.76 0.00 0.00 0.24
#> ERR488993 1 0.2647 0.851 0.88 0.00 0.00 0.12
#> ERR488999 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR488977 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489003 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR489009 3 0.0000 0.718 0.00 0.00 1.00 0.00
#> ERR489004 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR488994 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR488970 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489036 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489041 1 0.0707 0.946 0.98 0.00 0.00 0.02
#> ERR489017 3 0.0707 0.722 0.00 0.02 0.98 0.00
#> ERR488963 3 0.2335 0.707 0.00 0.02 0.92 0.06
#> ERR488987 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR488969 2 0.5902 0.569 0.00 0.70 0.14 0.16
#> ERR489025 3 0.0707 0.711 0.00 0.00 0.98 0.02
#> ERR489015 2 0.4855 0.159 0.00 0.60 0.40 0.00
#> ERR488953 4 0.4624 0.514 0.34 0.00 0.00 0.66
#> ERR488959 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489027 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR488961 1 0.1211 0.930 0.96 0.00 0.00 0.04
#> ERR488985 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489006 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR489034 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR489043 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR488978 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR488996 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR488972 3 0.4855 0.424 0.00 0.40 0.60 0.00
#> ERR488991 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR488975 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489044 3 0.0707 0.711 0.00 0.00 0.98 0.02
#> ERR489033 2 0.0707 0.944 0.00 0.98 0.02 0.00
#> ERR489039 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489001 2 0.1211 0.921 0.00 0.96 0.04 0.00
#> ERR488966 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR488988 4 0.0707 0.750 0.00 0.00 0.02 0.98
#> ERR488982 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489020 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR488954 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489018 1 0.4406 0.571 0.70 0.00 0.00 0.30
#> ERR489012 3 0.0707 0.722 0.00 0.02 0.98 0.00
#> ERR489016 4 0.3853 0.704 0.02 0.00 0.16 0.82
#> ERR488986 3 0.3975 0.465 0.00 0.00 0.76 0.24
#> ERR488968 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR488962 1 0.4907 0.267 0.58 0.00 0.00 0.42
#> ERR489024 1 0.0707 0.946 0.98 0.00 0.00 0.02
#> ERR489005 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR488971 3 0.4948 0.331 0.00 0.44 0.56 0.00
#> ERR488995 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR489040 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489037 3 0.2706 0.706 0.00 0.08 0.90 0.02
#> ERR489030 4 0.3335 0.686 0.00 0.02 0.12 0.86
#> ERR489047 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR488998 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR488976 3 0.4977 0.284 0.00 0.46 0.54 0.00
#> ERR488992 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489008 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489002 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR489023 2 0.0000 0.963 0.00 1.00 0.00 0.00
#> ERR489029 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR488981 4 0.1637 0.748 0.06 0.00 0.00 0.94
#> ERR488965 1 0.0000 0.960 1.00 0.00 0.00 0.00
#> ERR489011 1 0.0707 0.946 0.98 0.00 0.00 0.02
#> ERR488957 2 0.0000 0.963 0.00 1.00 0.00 0.00
Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.
consensus_heatmap(res, k = 2)
consensus_heatmap(res, k = 3)
consensus_heatmap(res, k = 4)
Heatmaps for the membership of samples in all partitions to see how consistent they are:
membership_heatmap(res, k = 2)
membership_heatmap(res, k = 3)
membership_heatmap(res, k = 4)
As soon as the classes for columns are determined, the signatures that are significantly different between subgroups can be looked for. Following are the heatmaps for signatures.
Signature heatmaps where rows are scaled:
Signature heatmaps where rows are not scaled:
get_signatures(res, k = 2, scale_rows = FALSE)
get_signatures(res, k = 3, scale_rows = FALSE)
get_signatures(res, k = 4, scale_rows = FALSE)
Compare the overlap of signatures from different k:
compare_signatures(res)
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:
which_row
: row indices corresponding to the input matrix.fdr
: FDR for the differential test. mean_x
: The mean value in group x.scaled_mean_x
: The mean value in group x after rows are scaled.km
: Row groups if k-means clustering is applied to rows (which is done by automatically selecting number of clusters).If there are too many signatures, top_signatures = ...
can be set to only show the
signatures with the highest FDRs:
# code only for demonstration
# e.g. to show the top 500 most significant rows
tb = get_signature(res, k = ..., top_signatures = 500)
If the signatures are defined as these which are uniquely high in current group, diff_method
argument
can be set to "uniquely_high_in_one_group"
:
# code only for demonstration
tb = get_signature(res, k = ..., diff_method = "uniquely_high_in_one_group")
UMAP plot which shows how samples are separated.
dimension_reduction(res, k = 2, method = "UMAP")
dimension_reduction(res, k = 3, method = "UMAP")
dimension_reduction(res, k = 4, method = "UMAP")
Following heatmap shows how subgroups are split when increasing k
:
collect_classes(res)
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_sample anno(p-value) k
#> ATC:skmeans 96 0.452 2
#> ATC:skmeans 96 0.446 3
#> ATC:skmeans 85 0.435 4
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.
sessionInfo()
#> R version 4.1.0 (2021-05-18)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: CentOS Linux 7 (Core)
#>
#> Matrix products: default
#> BLAS/LAPACK: /usr/lib64/libopenblas-r0.3.3.so
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
#> [4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
#> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
#> [10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
#>
#> attached base packages:
#> [1] grid parallel stats4 stats graphics grDevices utils datasets methods
#> [10] base
#>
#> other attached packages:
#> [1] genefilter_1.74.0 ComplexHeatmap_2.8.0 markdown_1.1
#> [4] knitr_1.33 scRNAseq_2.6.1 SingleCellExperiment_1.14.1
#> [7] SummarizedExperiment_1.22.0 Biobase_2.52.0 GenomicRanges_1.44.0
#> [10] GenomeInfoDb_1.28.1 IRanges_2.26.0 S4Vectors_0.30.0
#> [13] BiocGenerics_0.38.0 MatrixGenerics_1.4.0 matrixStats_0.59.0
#> [16] cola_1.9.4
#>
#> loaded via a namespace (and not attached):
#> [1] circlize_0.4.13 AnnotationHub_3.0.1 BiocFileCache_2.0.0
#> [4] lazyeval_0.2.2 polylabelr_0.2.0 splines_4.1.0
#> [7] Polychrome_1.3.1 BiocParallel_1.26.1 ggplot2_3.3.5
#> [10] digest_0.6.27 foreach_1.5.1 ensembldb_2.16.3
#> [13] htmltools_0.5.1.1 viridis_0.6.1 fansi_0.5.0
#> [16] magrittr_2.0.1 memoise_2.0.0 cluster_2.1.2
#> [19] doParallel_1.0.16 Biostrings_2.60.1 annotate_1.70.0
#> [22] askpass_1.1 prettyunits_1.1.1 colorspace_2.0-2
#> [25] blob_1.2.1 rappdirs_0.3.3 xfun_0.24
#> [28] dplyr_1.0.7 crayon_1.4.1 RCurl_1.98-1.3
#> [31] microbenchmark_1.4-7 jsonlite_1.7.2 impute_1.66.0
#> [34] brew_1.0-6 survival_3.2-11 iterators_1.0.13
#> [37] glue_1.4.2 polyclip_1.10-0 gtable_0.3.0
#> [40] zlibbioc_1.38.0 XVector_0.32.0 GetoptLong_1.0.5
#> [43] DelayedArray_0.18.0 shape_1.4.6 scales_1.1.1
#> [46] data.tree_1.0.0 DBI_1.1.1 Rcpp_1.0.7
#> [49] viridisLite_0.4.0 xtable_1.8-4 progress_1.2.2
#> [52] clue_0.3-59 reticulate_1.20 bit_4.0.4
#> [55] mclust_5.4.7 umap_0.2.7.0 httr_1.4.2
#> [58] RColorBrewer_1.1-2 ellipsis_0.3.2 pkgconfig_2.0.3
#> [61] XML_3.99-0.6 dbplyr_2.1.1 utf8_1.2.1
#> [64] tidyselect_1.1.1 rlang_0.4.11 later_1.2.0
#> [67] AnnotationDbi_1.54.1 munsell_0.5.0 BiocVersion_3.13.1
#> [70] tools_4.1.0 cachem_1.0.5 generics_0.1.0
#> [73] RSQLite_2.2.7 ExperimentHub_2.0.0 evaluate_0.14
#> [76] stringr_1.4.0 fastmap_1.1.0 yaml_2.2.1
#> [79] bit64_4.0.5 purrr_0.3.4 dendextend_1.15.1
#> [82] KEGGREST_1.32.0 AnnotationFilter_1.16.0 mime_0.11
#> [85] slam_0.1-48 xml2_1.3.2 biomaRt_2.48.2
#> [88] compiler_4.1.0 rstudioapi_0.13 filelock_1.0.2
#> [91] curl_4.3.2 png_0.1-7 interactiveDisplayBase_1.30.0
#> [94] tibble_3.1.2 stringi_1.7.3 highr_0.9
#> [97] GenomicFeatures_1.44.0 RSpectra_0.16-0 lattice_0.20-44
#> [100] ProtGenerics_1.24.0 Matrix_1.3-4 vctrs_0.3.8
#> [103] pillar_1.6.1 lifecycle_1.0.0 BiocManager_1.30.16
#> [106] eulerr_6.1.0 GlobalOptions_0.1.2 bitops_1.0-7
#> [109] irlba_2.3.3 httpuv_1.6.1 rtracklayer_1.52.0
#> [112] R6_2.5.0 BiocIO_1.2.0 promises_1.2.0.1
#> [115] gridExtra_2.3 codetools_0.2-18 assertthat_0.2.1
#> [118] openssl_1.4.4 rjson_0.2.20 GenomicAlignments_1.28.0
#> [121] Rsamtools_2.8.0 GenomeInfoDbData_1.2.6 hms_1.1.0
#> [124] skmeans_0.2-13 Cairo_1.5-12.2 scatterplot3d_0.3-41
#> [127] shiny_1.6.0 restfulr_0.0.13