Browse code

add consensus k-means

jokergoo authored on 22/03/2019 15:02:46
Showing12 changed files

... ...
@@ -263,6 +263,10 @@ importFrom("circlize", add_transparency)
263 263
 importFrom("circlize", colorRamp2)
264 264
 importFrom("circlize", rand_color)
265 265
 importFrom("circlize", smartAlign)
266
+importFrom("clue", as.cl_hard_partition)
267
+importFrom("clue", cl_class_ids)
268
+importFrom("clue", cl_consensus)
269
+importFrom("clue", cl_ensemble)
266 270
 importFrom("colorspace", diverge_hcl)
267 271
 importFrom("colorspace", rainbow_hcl)
268 272
 importFrom("parallel", "mclapply")
... ...
@@ -270,7 +274,4 @@ importFrom("utils", "combn")
270 274
 importFrom("utils", "getFromNamespace")
271 275
 importFrom("utils", "packageDescription")
272 276
 importFrom("utils", "str")
273
-importFrom("clue", as.cl_hard_partition)
274
-importFrom("clue", cl_ensemble)
275
-importFrom("clue", cl_consensus)
276
-importFrom("clue", cl_class_ids)
277
+
... ...
@@ -1,31 +1,31 @@
1
-setGeneric('column_order', function(object, ...) standardGeneric('column_order'))
2
-setGeneric('draw_dimnames', function(object, ...) standardGeneric('draw_dimnames'))
3
-setGeneric('make_column_cluster', function(object, ...) standardGeneric('make_column_cluster'))
4
-setGeneric('copy_all', function(object, ...) standardGeneric('copy_all'))
5 1
 setGeneric('annotation_legend_size', function(object, ...) standardGeneric('annotation_legend_size'))
6 2
 setGeneric('draw_dend', function(object, ...) standardGeneric('draw_dend'))
7
-setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
8
-setGeneric('row_order', function(object, ...) standardGeneric('row_order'))
9
-setGeneric('get_color_mapping_list', function(object, ...) standardGeneric('get_color_mapping_list'))
10
-setGeneric('draw_heatmap_legend', function(object, ...) standardGeneric('draw_heatmap_legend'))
3
+setGeneric('make_column_cluster', function(object, ...) standardGeneric('make_column_cluster'))
4
+setGeneric('adjust_heatmap_list', function(object, ...) standardGeneric('adjust_heatmap_list'))
5
+setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
6
+setGeneric('map_to_colors', function(object, ...) standardGeneric('map_to_colors'))
7
+setGeneric('copy_all', function(object, ...) standardGeneric('copy_all'))
8
+setGeneric('row_dend', function(object, ...) standardGeneric('row_dend'))
9
+setGeneric('make_row_cluster', function(object, ...) standardGeneric('make_row_cluster'))
10
+setGeneric('heatmap_legend_size', function(object, ...) standardGeneric('heatmap_legend_size'))
11
+setGeneric('make_layout', function(object, ...) standardGeneric('make_layout'))
12
+setGeneric('set_component_height', function(object, ...) standardGeneric('set_component_height'))
13
+setGeneric('re_size', function(object, ...) standardGeneric('re_size'))
14
+setGeneric('column_order', function(object, ...) standardGeneric('column_order'))
15
+setGeneric('draw_annotation', function(object, ...) standardGeneric('draw_annotation'))
16
+setGeneric('component_width', function(object, ...) standardGeneric('component_width'))
17
+setGeneric('set_component_width', function(object, ...) standardGeneric('set_component_width'))
11 18
 setGeneric('column_dend', function(object, ...) standardGeneric('column_dend'))
19
+setGeneric('draw_annotation_legend', function(object, ...) standardGeneric('draw_annotation_legend'))
12 20
 setGeneric('draw_heatmap_body', function(object, ...) standardGeneric('draw_heatmap_body'))
21
+setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
13 22
 setGeneric('component_height', function(object, ...) standardGeneric('component_height'))
14 23
 setGeneric('draw', function(object, ...) standardGeneric('draw'))
15
-setGeneric('draw_title', function(object, ...) standardGeneric('draw_title'))
16
-setGeneric('set_component_width', function(object, ...) standardGeneric('set_component_width'))
17
-setGeneric('component_width', function(object, ...) standardGeneric('component_width'))
18
-setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
19
-setGeneric('draw_annotation_legend', function(object, ...) standardGeneric('draw_annotation_legend'))
20
-setGeneric('make_layout', function(object, ...) standardGeneric('make_layout'))
21
-setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
22
-setGeneric('row_dend', function(object, ...) standardGeneric('row_dend'))
23
-setGeneric('re_size', function(object, ...) standardGeneric('re_size'))
24 24
 setGeneric('add_heatmap', function(object, ...) standardGeneric('add_heatmap'))
25
-setGeneric('map_to_colors', function(object, ...) standardGeneric('map_to_colors'))
26
-setGeneric('set_component_height', function(object, ...) standardGeneric('set_component_height'))
27
-setGeneric('adjust_heatmap_list', function(object, ...) standardGeneric('adjust_heatmap_list'))
25
+setGeneric('get_color_mapping_list', function(object, ...) standardGeneric('get_color_mapping_list'))
26
+setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
27
+setGeneric('row_order', function(object, ...) standardGeneric('row_order'))
28
+setGeneric('draw_dimnames', function(object, ...) standardGeneric('draw_dimnames'))
29
+setGeneric('draw_title', function(object, ...) standardGeneric('draw_title'))
30
+setGeneric('draw_heatmap_legend', function(object, ...) standardGeneric('draw_heatmap_legend'))
28 31
 setGeneric('get_legend_param_list', function(object, ...) standardGeneric('get_legend_param_list'))
29
-setGeneric('draw_annotation', function(object, ...) standardGeneric('draw_annotation'))
30
-setGeneric('make_row_cluster', function(object, ...) standardGeneric('make_row_cluster'))
31
-setGeneric('heatmap_legend_size', function(object, ...) standardGeneric('heatmap_legend_size'))
... ...
@@ -152,10 +152,11 @@ Heatmap = setClass("Heatmap",
152 152
 # -split A vector or a data frame by which the rows are split. But if ``cluster_rows`` is a clustering object, ``split`` can be a single number
153 153
 #        indicating to split the dendrogram by `stats::cutree`.
154 154
 # -row_km Same as ``km``.
155
-# -row_km_repeats Number of k-means runs to get a consensus k-means clustering.
155
+# -row_km_repeats Number of k-means runs to get a consensus k-means clustering. Note if ``row_km_repeats`` is set to more than one, the final number
156
+#                of groups might be smaller than ``row_km``, but this might means the original ``row_km`` is not a good choice.
156 157
 # -row_split Same as ``split``.
157 158
 # -column_km K-means clustering on columns.
158
-# -column_km_repeats Number of k-means runs to get a consensus k-means clustering.
159
+# -column_km_repeats Number of k-means runs to get a consensus k-means clustering. Similar as ``row_km_repeats``.
159 160
 # -column_split Split on columns. For heatmap splitting, please refer to https://jokergoo.github.io/ComplexHeatmap-reference/book/a-single-heatmap.html#heatmap-split .
160 161
 # -gap Gap between row slices if the heatmap is split by rows. The value should be a `grid::unit` object.
161 162
 # -row_gap Same as ``gap``.
... ...
@@ -67,8 +67,10 @@ Heatmap(matrix, col, name,
67 67
     km = 1,
68 68
     split = NULL,
69 69
     row_km = km,
70
+    row_km_repeats = 10,
70 71
     row_split = split,
71 72
     column_km = 1,
73
+    column_km_repeats = 10,
72 74
     column_split = NULL,
73 75
     gap = unit(1, "mm"),
74 76
     row_gap = unit(1, "mm"),
... ...
@@ -149,8 +151,10 @@ Heatmap(matrix, col, name,
149 151
   \item{km}{Apply k-means clustering on rows. If the value is larger than 1, the heatmap will be split by rows according to the k-means clustering. For each row slice, hierarchical clustering is still applied with parameters above.}
150 152
   \item{split}{A vector or a data frame by which the rows are split. But if \code{cluster_rows} is a clustering object, \code{split} can be a single number indicating to split the dendrogram by \code{\link[stats]{cutree}}.}
151 153
   \item{row_km}{Same as \code{km}.}
154
+  \item{row_km_repeats}{Number of k-means runs to get a consensus k-means clustering. Note if \code{row_km_repeats} is set to more than one, the final number of groups might be smaller than \code{row_km}, but this might means the original \code{row_km} is not a good choice.}
152 155
   \item{row_split}{Same as \code{split}.}
153 156
   \item{column_km}{K-means clustering on columns.}
157
+  \item{column_km_repeats}{Number of k-means runs to get a consensus k-means clustering. Similar as \code{row_km_repeats}.}
154 158
   \item{column_split}{Split on columns. For heatmap splitting, please refer to \url{https://jokergoo.github.io/ComplexHeatmap-reference/book/a-single-heatmap.html#heatmap-split} .}
155 159
   \item{gap}{Gap between row slices if the heatmap is split by rows. The value should be a \code{\link[grid]{unit}} object.}
156 160
   \item{row_gap}{Same as \code{gap}.}
... ...
@@ -10,9 +10,9 @@ Method dispatch page for \code{add_heatmap}.
10 10
 \code{add_heatmap} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{add_heatmap,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14 13
 \item \code{\link{add_heatmap,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
15 14
 \item \code{\link{add_heatmap,Heatmap-method}}, \code{\link{Heatmap-class}} class method
15
+\item \code{\link{add_heatmap,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
16 16
 }
17 17
 }
18 18
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{column_dend}.
10 10
 \code{column_dend} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{column_dend,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14 13
 \item \code{\link{column_dend,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14
+\item \code{\link{column_dend,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{column_order}.
10 10
 \code{column_order} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{column_order,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14 13
 \item \code{\link{column_order,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14
+\item \code{\link{column_order,Heatmap-method}}, \code{\link{Heatmap-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{component_height}.
10 10
 \code{component_height} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{component_height,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14 13
 \item \code{\link{component_height,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14
+\item \code{\link{component_height,Heatmap-method}}, \code{\link{Heatmap-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,12 +10,12 @@ Method dispatch page for \code{draw}.
10 10
 \code{draw} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
+\item \code{\link{draw,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
14
+\item \code{\link{draw,Heatmap-method}}, \code{\link{Heatmap-class}} class method
13 15
 \item \code{\link{draw,Legends-method}}, \code{\link{Legends-class}} class method
14 16
 \item \code{\link{draw,AnnotationFunction-method}}, \code{\link{AnnotationFunction-class}} class method
15 17
 \item \code{\link{draw,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
16 18
 \item \code{\link{draw,SingleAnnotation-method}}, \code{\link{SingleAnnotation-class}} class method
17
-\item \code{\link{draw,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
18
-\item \code{\link{draw,Heatmap-method}}, \code{\link{Heatmap-class}} class method
19 19
 }
20 20
 }
21 21
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{make_layout}.
10 10
 \code{make_layout} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{make_layout,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14 13
 \item \code{\link{make_layout,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14
+\item \code{\link{make_layout,Heatmap-method}}, \code{\link{Heatmap-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{row_dend}.
10 10
 \code{row_dend} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{row_dend,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14 13
 \item \code{\link{row_dend,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14
+\item \code{\link{row_dend,Heatmap-method}}, \code{\link{Heatmap-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,11 +10,11 @@ Method dispatch page for \code{show}.
10 10
 \code{show} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{show,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14
-\item \code{\link{show,SingleAnnotation-method}}, \code{\link{SingleAnnotation-class}} class method
15
-\item \code{\link{show,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
16 13
 \item \code{\link{show,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
17 14
 \item \code{\link{show,AnnotationFunction-method}}, \code{\link{AnnotationFunction-class}} class method
15
+\item \code{\link{show,Heatmap-method}}, \code{\link{Heatmap-class}} class method
16
+\item \code{\link{show,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
17
+\item \code{\link{show,SingleAnnotation-method}}, \code{\link{SingleAnnotation-class}} class method
18 18
 \item \code{\link{show,ColorMapping-method}}, \code{\link{ColorMapping-class}} class method
19 19
 }
20 20
 }