Skip to content

Commit

Permalink
anno_block(): allows to set width and height
Browse files Browse the repository at this point in the history
  • Loading branch information
jokergoo committed Jun 29, 2020
1 parent 3759e44 commit 82c1779
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 89 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CHANGES in VERSION 2.5.4
* fixed a bug where slice clusters were wrongly reordered.
* `Heatmap()`: add `border_gp` argument.
* Legends are nicely placed.
* `anno_block()`: allows to set height and width.

========================

Expand Down
46 changes: 23 additions & 23 deletions R/00_S4_generic_methods.R
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
setGeneric('get_legend_param_list', function(object, ...) standardGeneric('get_legend_param_list'))
setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
setGeneric('re_size', function(object, ...) standardGeneric('re_size'))
setGeneric('draw_annotation_legend', function(object, ...) standardGeneric('draw_annotation_legend'))
setGeneric('draw_heatmap_body', function(object, ...) standardGeneric('draw_heatmap_body'))
setGeneric('make_layout', function(object, ...) standardGeneric('make_layout'))
setGeneric('component_height', function(object, ...) standardGeneric('component_height'))
setGeneric('draw_dimnames', function(object, ...) standardGeneric('draw_dimnames'))
setGeneric('draw_heatmap_legend', function(object, ...) standardGeneric('draw_heatmap_legend'))
setGeneric('draw_dend', function(object, ...) standardGeneric('draw_dend'))
setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
setGeneric('draw_annotation', function(object, ...) standardGeneric('draw_annotation'))
setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
setGeneric('adjust_heatmap_list', function(object, ...) standardGeneric('adjust_heatmap_list'))
setGeneric('map_to_colors', function(object, ...) standardGeneric('map_to_colors'))
setGeneric('make_row_cluster', function(object, ...) standardGeneric('make_row_cluster'))
setGeneric('draw_title', function(object, ...) standardGeneric('draw_title'))
setGeneric('heatmap_legend_size', function(object, ...) standardGeneric('heatmap_legend_size'))
setGeneric('draw', function(object, ...) standardGeneric('draw'))
setGeneric('row_order', function(object, ...) standardGeneric('row_order'))
setGeneric('make_layout', function(object, ...) standardGeneric('make_layout'))
setGeneric('annotation_legend_size', function(object, ...) standardGeneric('annotation_legend_size'))
setGeneric('column_dend', function(object, ...) standardGeneric('column_dend'))
setGeneric('draw_heatmap_body', function(object, ...) standardGeneric('draw_heatmap_body'))
setGeneric('draw_annotation_legend', function(object, ...) standardGeneric('draw_annotation_legend'))
setGeneric('get_color_mapping_list', function(object, ...) standardGeneric('get_color_mapping_list'))
setGeneric('get_legend_param_list', function(object, ...) standardGeneric('get_legend_param_list'))
setGeneric('set_component_height', function(object, ...) standardGeneric('set_component_height'))
setGeneric('component_height', function(object, ...) standardGeneric('component_height'))
setGeneric('make_column_cluster', function(object, ...) standardGeneric('make_column_cluster'))
setGeneric('draw_title', function(object, ...) standardGeneric('draw_title'))
setGeneric('column_order', function(object, ...) standardGeneric('column_order'))
setGeneric('set_component_height', function(object, ...) standardGeneric('set_component_height'))
setGeneric('draw_dend', function(object, ...) standardGeneric('draw_dend'))
setGeneric('component_width', function(object, ...) standardGeneric('component_width'))
setGeneric('row_dend', function(object, ...) standardGeneric('row_dend'))
setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
setGeneric('get_color_mapping_list', function(object, ...) standardGeneric('get_color_mapping_list'))
setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
setGeneric('add_heatmap', function(object, ...) standardGeneric('add_heatmap'))
setGeneric('draw_heatmap_legend', function(object, ...) standardGeneric('draw_heatmap_legend'))
setGeneric('draw_annotation', function(object, ...) standardGeneric('draw_annotation'))
setGeneric('heatmap_legend_size', function(object, ...) standardGeneric('heatmap_legend_size'))
setGeneric('column_dend', function(object, ...) standardGeneric('column_dend'))
setGeneric('copy_all', function(object, ...) standardGeneric('copy_all'))
setGeneric('draw_dimnames', function(object, ...) standardGeneric('draw_dimnames'))
setGeneric('map_to_colors', function(object, ...) standardGeneric('map_to_colors'))
setGeneric('make_row_cluster', function(object, ...) standardGeneric('make_row_cluster'))
setGeneric('add_heatmap', function(object, ...) standardGeneric('add_heatmap'))
setGeneric('row_order', function(object, ...) standardGeneric('row_order'))
setGeneric('set_component_width', function(object, ...) standardGeneric('set_component_width'))
setGeneric('row_dend', function(object, ...) standardGeneric('row_dend'))
setGeneric('component_width', function(object, ...) standardGeneric('component_width'))
19 changes: 15 additions & 4 deletions R/AnnotationFunction-function.R
Original file line number Diff line number Diff line change
Expand Up @@ -3247,11 +3247,22 @@ anno_block = function(gp = gpar(), labels = NULL, labels_gp = gpar(), labels_rot
}
if(length(labels)) {
if(which == "column") {
height = grobHeight(textGrob(labels, rot = labels_rot, gp = labels_gp))
height = height + unit(5, "mm")
if(missing(height)) {
height = grobHeight(textGrob(labels, rot = labels_rot, gp = labels_gp))
height = height + unit(5, "mm")
} else {
if(!inherits(height, "unit")) {
stop_wrap("Since you specified `height`, the value should be `unit` object.")
}
}
} else {
width = grobWidth(textGrob(labels, rot = labels_rot, gp = labels_gp))
width = width + unit(5, "mm")
if(missing(width)) {
width = grobWidth(textGrob(labels, rot = labels_rot, gp = labels_gp))
width = width + unit(5, "mm")
} else {
if(!inherits(width, "unit")) {
stop_wrap("Since you specified `width`, the value should be `unit` object.")
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions R/HeatmapList-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ setMethod(f = "add_heatmap",
# -annotation_legend_side side of the annotation legends
# -show_annotation_legend whether show annotation legends
# -annotation_legend_list user-defined legends which are put after the annotation legends
# -align_heatmap_legend How to align the legends to heatmap. Possible values are "heatmap_center", "heatmap_top" and "global_center". If the value is ``NULL``,
# it automatically picks the proper value from the three options.
# -align_annotation_legend How to align the legends to heatmap. Possible values are "heatmap_center", "heatmap_top" and "global_center".
# -gap gap between heatmaps/annotations
# -ht_gap same as ``gap``.
# -main_heatmap index of main heatmap. The value can be a numeric index or the heatmap name
Expand Down
33 changes: 33 additions & 0 deletions R/HeatmapList-get_order.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ setMethod(f = "row_order",
signature = "HeatmapList",
definition = function(object, name = NULL) {

if(!object@layout$initialized) {
warning_wrap("The heatmap list has not been initialized. You might have different results if you repeatedly execute this function. It is more suggested to do as `ht_list = draw(ht_list); row_order(ht_list)`.")
}

object = make_layout(object)

if(!is.null(name)) {
Expand Down Expand Up @@ -82,6 +86,11 @@ setMethod(f = "row_order",
signature = "Heatmap",
definition = function(object) {

if(!object@layout$initialized) {
warning_wrap("The heatmap has not been initialized. You might have different results if you repeatedly execute this function. It is more suggested to do as `ht = draw(ht); row_order(ht)`.")
}


object = prepare(object)

lt = object@row_order_list
Expand Down Expand Up @@ -123,6 +132,10 @@ setMethod(f = "column_order",
signature = "HeatmapList",
definition = function(object, name = NULL) {

if(!object@layout$initialized) {
warning_wrap("The heatmap list has not been initialized. You might have different results if you repeatedly execute this function. It is more suggested to do as `ht_list = draw(ht_list); column_order(ht_list)`.")
}

object = make_layout(object)

if(!is.null(name)) {
Expand Down Expand Up @@ -177,6 +190,10 @@ setMethod(f = "column_order",
signature = "Heatmap",
definition = function(object) {

if(!object@layout$initialized) {
warning_wrap("The heatmap has not been initialized. You might have different results if you repeatedly execute this function. It is more suggested to do as `ht = draw(ht); column_order(ht)`.")
}

object = prepare(object)

lt = object@column_order_list
Expand Down Expand Up @@ -216,6 +233,10 @@ setMethod(f = "row_dend",
signature = "HeatmapList",
definition = function(object, name = NULL) {

if(!object@layout$initialized) {
warning_wrap("The heatmap list has not been initialized. You might have different results if you repeatedly execute this function. It is more suggested to do as `ht_list = draw(ht_list); row_dend(ht_list)`.")
}

object = make_layout(object)

if(!is.null(name)) {
Expand Down Expand Up @@ -272,6 +293,10 @@ setMethod(f = "row_dend",
signature = "Heatmap",
definition = function(object) {

if(!object@layout$initialized) {
warning_wrap("The heatmap has not been initialized. You might have different results if you repeatedly execute this function. It is more suggested to do as `ht = draw(ht); row_dend(ht)`.")
}

object = prepare(object)

lt = object@row_dend_list
Expand Down Expand Up @@ -313,6 +338,10 @@ setMethod(f = "column_dend",
signature = "HeatmapList",
definition = function(object, name = NULL) {

if(!object@layout$initialized) {
warning_wrap("The heatmap list has not been initialized. You might have different results if you repeatedly execute this function. It is more suggested to do as `ht_list = draw(ht_list); column_dend(ht_list)`.")
}

object = make_layout(object)

if(!is.null(name)) {
Expand Down Expand Up @@ -369,6 +398,10 @@ setMethod(f = "column_dend",
signature = "Heatmap",
definition = function(object) {

if(!object@layout$initialized) {
warning_wrap("The heatmap has not been initialized. You might have different results if you repeatedly execute this function. It is more suggested to do as `ht = draw(ht); column_dend(ht)`.")
}

object = prepare(object)

lt = object@column_dend_list
Expand Down
3 changes: 3 additions & 0 deletions R/HeatmapList-layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
# -annotation_legend_side Side of annotation legends.
# -show_annotation_legend Whether show annotation legends.
# -annotation_legend_list A list of self-defined legends, should be wrapped into a list of `grid::grob` objects. Normally they are constructed by `Legend`.
# -align_heatmap_legend How to align the legends to heatmap. Possible values are "heatmap_center", "heatmap_top" and "global_center". If the value is ``NULL``,
# it automatically picks the proper value from the three options.
# -align_annotation_legend How to align the legends to heatmap. Possible values are "heatmap_center", "heatmap_top" and "global_center".
# -ht_gap Gap between heatmaps, should be a `grid::unit` object. It can be a vector of length 1 or the number of heamtaps/annotations.
# -main_heatmap Name or index for the main heatmap.
# -padding Padding of the whole plot. The four values correspond to the bottom, left, top and right paddings.
Expand Down
Loading

0 comments on commit 82c1779

Please sign in to comment.