Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add anno height #84

Merged
merged 10 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ Suggests:
rmarkdown,
qpdf,
covr,
roxygen2
roxygen2,
forcats
VignetteBuilder:
knitr
RdMacros:
Expand All @@ -64,5 +65,5 @@ Biarch: true
biocViews: AssayDomain, Infrastructure
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
Language: en-US
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ importFrom(grDevices,colorRampPalette)
importFrom(grid,gpar)
importFrom(grid,grid.points)
importFrom(grid,unit)
importFrom(grid,unit.c)
importFrom(lifecycle,deprecate_warn)
importFrom(lifecycle,is_present)
importFrom(magrittr,"%$%")
Expand All @@ -40,9 +41,11 @@ importFrom(purrr,as_mapper)
importFrom(purrr,map)
importFrom(purrr,map2)
importFrom(purrr,map_chr)
importFrom(purrr,map_dfr)
importFrom(purrr,map_lgl)
importFrom(purrr,negate)
importFrom(purrr,pmap)
importFrom(purrr,reduce)
importFrom(purrr,when)
importFrom(rlang,dots_list)
importFrom(rlang,enquo)
Expand All @@ -58,6 +61,7 @@ importFrom(stats,hclust)
importFrom(stats,sd)
importFrom(stats,setNames)
importFrom(stats,terms)
importFrom(tibble,enframe)
importFrom(tibble,rowid_to_column)
importFrom(utils,capture.output)
importFrom(utils,head)
Expand Down
8 changes: 5 additions & 3 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#' @param transform A function, used to transform .value, for example log1p
#' @param .scale A character string. Possible values are c(\"none\", \"row\", \"column\", \"both\")
#' @param palette_value A character vector, or a function for higher customisation (colorRamp2). This is the palette that will be used as gradient for abundance. If palette_value is a vector of hexadecimal colours, it should have 3 values. If you want more customisation, you can pass to palette_value a function, that is derived as for example `colorRamp2(c(-2, 0, 2), palette_value)`
#' @param palette_grouping A list of character vectors. This is the list of palettes that will be used for grouping
#' @param palette_grouping A list of character vectors. This is the list of palettes that will be used for grouping
#' @param ... Further arguments to be passed to ComplexHeatmap::Heatmap
#'
#' @details To be added.
Expand Down Expand Up @@ -280,6 +280,7 @@ add_grouping = function(my_input_heatmap){
#' @importFrom rlang is_function
#' @importFrom purrr when
#' @importFrom rlang dots_list
#' @importFrom grid unit
#'
#' @name add_annotation
#' @rdname add_annotation
Expand All @@ -289,6 +290,7 @@ add_grouping = function(my_input_heatmap){
#' @param type A character vector of the set c(\"tile\", \"point\", \"bar\", \"line\")
#' @param palette_discrete A list of character vectors. This is the list of palettes that will be used for horizontal and vertical discrete annotations. The discrete classification of annotations depends on the column type of your input tibble (e.g., character and factor).
#' @param palette_continuous A list of character vectors. This is the list of palettes that will be used for horizontal and vertical continuous annotations. The continuous classification of annotations depends on the column type of your input tibble (e.g., integer, numerical, double).
#' @param size A grid::unit object, e.g. unit(2, "cm"). This is the height or width of the annotation depending on the orientation.
#' @param ... The arguments that will be passed to top_annotation or left_annotation of the ComplexHeatmap container
#'
#' @details To be added.
Expand All @@ -304,7 +306,7 @@ add_annotation = function(my_input_heatmap,
annotation,
type = rep("tile", length(quo_names(annotation))),
palette_discrete = list(),
palette_continuous = list(), ...) {
palette_continuous = list(), size = NULL, ...) {

# Solve CRAN note
annot_type = NULL
Expand Down Expand Up @@ -364,7 +366,7 @@ add_annotation = function(my_input_heatmap,
get_top_left_annotation( !!.horizontal,
!!.vertical,
!!.abundance,
!!annotation, palette_annotation, type, x_y_annot_cols, ...)
!!annotation, palette_annotation, type, x_y_annot_cols, size, ...)

# Number of grouping
how_many_discrete = .data_annot %>% filter(annot_type=="discrete") %>% nrow
Expand Down
33 changes: 21 additions & 12 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,15 @@ setMethod("heatmap", "tbl_df", heatmap_)
#'
#' @importFrom rlang enquo
#' @importFrom magrittr "%>%"
#'
#' @importFrom grid unit
#'
#' @name add_tile
#' @rdname add_tile-method
#'
#' @param .data A `tbl_df` formatted as | <ELEMENT> | <FEATURE> | <VALUE> | <...> |
#' @param .column Vector of quotes
#' @param palette A character vector of colors This is the list of palettes that will be used for horizontal and vertical discrete annotations. The discrete classification of annotations depends on the column type of your input tibble (e.g., character and factor).
#' @param size A grid::unit object, e.g. unit(2, "cm"). This is the height or width of the annotation depending on the orientation.
#' @param ... The arguments that will be passed to top_annotation or left_annotation of the ComplexHeatmap container
#'
#' @details It uses `ComplexHeatmap` as visualisation tool.
Expand All @@ -346,7 +347,7 @@ setMethod("heatmap", "tbl_df", heatmap_)
#' @export
setGeneric("add_tile", function(.data,
.column,
palette = NULL, ...)
palette = NULL, size = NULL, ...)
standardGeneric("add_tile"))

#' add_tile
Expand All @@ -358,7 +359,7 @@ setGeneric("add_tile", function(.data,
#'
setMethod("add_tile", "InputHeatmap", function(.data,
.column,
palette = NULL, ...){
palette = NULL, size = NULL,...){

.column = enquo(.column)

Expand All @@ -381,6 +382,8 @@ setMethod("add_tile", "InputHeatmap", function(.data,
select(!!.column) %>%
sapply(class) %>%
when(. %in% c("integer", "numerical", "numeric", "double") & !is.null(palette) ~ list(palette), ~ list()),

size = size,
...
)

Expand All @@ -394,6 +397,7 @@ setMethod("add_tile", "InputHeatmap", function(.data,
#'
#' @importFrom rlang enquo
#' @importFrom magrittr "%>%"
#' @importFrom grid unit
#'
#'
#' @name add_point
Expand All @@ -402,6 +406,7 @@ setMethod("add_tile", "InputHeatmap", function(.data,
#' @param .data A `tbl_df` formatted as | <ELEMENT> | <FEATURE> | <VALUE> | <...> |
#' @param .column Vector of quotes
#' @param palette A character vector of colors This is the list of palettes that will be used for horizontal and vertical discrete annotations. The discrete classification of annotations depends on the column type of your input tibble (e.g., character and factor).
#' @param size A grid::unit object, e.g. unit(2, "cm"). This is the height or width of the annotation depending on the orientation.
#' @param ... The arguments that will be passed to top_annotation or left_annotation of the ComplexHeatmap container
#'
#' @details It uses `ComplexHeatmap` as visualisation tool.
Expand All @@ -428,7 +433,7 @@ setMethod("add_tile", "InputHeatmap", function(.data,
#' @export
setGeneric("add_point", function(.data,
.column,
palette = NULL, ...)
palette = NULL, size = NULL,...)
standardGeneric("add_point"))

#' add_point
Expand All @@ -440,11 +445,11 @@ setGeneric("add_point", function(.data,
#'
setMethod("add_point", "InputHeatmap", function(.data,
.column,
palette = NULL, ...){
palette = NULL, size = NULL,...){

.column = enquo(.column)

.data %>% add_annotation( !!.column, type = "point", ...)
.data %>% add_annotation( !!.column, type = "point", size = size,...)

})

Expand All @@ -456,6 +461,7 @@ setMethod("add_point", "InputHeatmap", function(.data,
#'
#' @importFrom rlang enquo
#' @importFrom magrittr "%>%"
#' @importFrom grid unit
#'
#'
#' @name add_line
Expand All @@ -464,6 +470,7 @@ setMethod("add_point", "InputHeatmap", function(.data,
#' @param .data A `tbl_df` formatted as | <ELEMENT> | <FEATURE> | <VALUE> | <...> |
#' @param .column Vector of quotes
#' @param palette A character vector of colors This is the list of palettes that will be used for horizontal and vertical discrete annotations. The discrete classification of annotations depends on the column type of your input tibble (e.g., character and factor).
#' @param size A grid::unit object, e.g. unit(2, "cm"). This is the height or width of the annotation depending on the orientation.
#' @param ... The arguments that will be passed to top_annotation or left_annotation of the ComplexHeatmap container
#'
#' @details It uses `ComplexHeatmap` as visualisation tool.
Expand All @@ -490,7 +497,7 @@ setMethod("add_point", "InputHeatmap", function(.data,
#' @export
setGeneric("add_line", function(.data,
.column,
palette = NULL, ...)
palette = NULL,size = NULL, ...)
standardGeneric("add_line"))

#' add_line
Expand All @@ -503,11 +510,11 @@ setGeneric("add_line", function(.data,
#'
setMethod("add_line", "InputHeatmap", function(.data,
.column,
palette = NULL, ...){
palette = NULL, size = NULL,...){

.column = enquo(.column)

.data %>% add_annotation( !!.column, type = "line", ...)
.data %>% add_annotation( !!.column, type = "line", size = size,...)

})

Expand All @@ -519,6 +526,7 @@ setMethod("add_line", "InputHeatmap", function(.data,
#'
#' @importFrom rlang enquo
#' @importFrom magrittr "%>%"
#' @importFrom grid unit
#'
#'
#' @name add_bar
Expand All @@ -527,6 +535,7 @@ setMethod("add_line", "InputHeatmap", function(.data,
#' @param .data A `tbl_df` formatted as | <ELEMENT> | <FEATURE> | <VALUE> | <...> |
#' @param .column Vector of quotes
#' @param palette A character vector of colors This is the list of palettes that will be used for horizontal and vertical discrete annotations. The discrete classification of annotations depends on the column type of your input tibble (e.g., character and factor).
#' @param size A grid::unit object, e.g. unit(2, "cm"). This is the height or width of the annotation depending on the orientation.
#' @param ... The arguments that will be passed to top_annotation or left_annotation of the ComplexHeatmap container
#'
#' @details It uses `ComplexHeatmap` as visualisation tool.
Expand All @@ -553,7 +562,7 @@ setMethod("add_line", "InputHeatmap", function(.data,
#' @export
setGeneric("add_bar", function(.data,
.column,
palette = NULL, ...)
palette = NULL, size = NULL,...)
standardGeneric("add_bar"))

#' add_bar
Expand All @@ -565,11 +574,11 @@ setGeneric("add_bar", function(.data,
#'
setMethod("add_bar", "InputHeatmap", function(.data,
.column,
palette = NULL, ...){
palette = NULL, size = NULL,...){

.column = enquo(.column)

.data %>% add_annotation( !!.column, type = "bar", ...)
.data %>% add_annotation( !!.column, type = "bar", size = size,...)

})

Expand Down
Loading