Skip to content

Commit

Permalink
remove unused data
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Jul 22, 2024
1 parent 1223e94 commit 7965809
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 12 deletions.
5 changes: 4 additions & 1 deletion R/htanno-.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ HtannoProto <- ggplot2::ggproto("HtannoProto",
# otherwise, they won't be collected.
extra_params = character(),
setup_params = function(self) .subset2(self, "params"),
setup_data = function(self) .subset2(self, "data"),

# use `NULL`, if you don't need any data from the heatmap
# use `.subset2(self, "data")` if you want to attach the matrix
setup_data = function(self) NULL,

# Following fields should be defined for the new `Htanno` object.
# argument name in the function doesn't matter.
Expand Down
20 changes: 12 additions & 8 deletions R/htanno-gg.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ gganno_left <- function(...) htanno_gg(position = "left", ...)
gganno_right <- function(...) htanno_gg(position = "right", ...)

HtannoGG <- ggplot2::ggproto("HtannoGG", HtannoProto,
setup_data = function(self) {
data <- .subset2(self, "data")
# matrix: will be reshaped to the long-format data.frame
# data.frame: won't do any thing special
if (is.matrix(data)) {
data <- melt_matrix(data)
} else {
data <- as_tibble0(data, rownames = ".row_names")
data$.row_index <- seq_len(nrow(data))
}
data
},
ggplot = function(self, mapping) {
ans <- ggplot2::ggplot(mapping = mapping) +
ggplot2::theme_bw()
Expand All @@ -57,14 +69,6 @@ HtannoGG <- ggplot2::ggproto("HtannoGG", HtannoProto,
draw = function(self, panels, index) {
data <- .subset2(self, "data")
axis <- to_coord_axis(.subset2(self, "position"))
# matrix: will be reshaped to the long-format data.frame
# data.frame: won't do any thing special
if (is.matrix(data)) {
data <- melt_matrix(data)
} else {
data <- as_tibble0(data, rownames = ".row_names")
data$.row_index <- seq_len(nrow(data))
}
coords <- data_frame0(.panel = panels[index], .index = index)
coords[[paste0(".", axis)]] <- seq_along(index)
data <- merge(data, coords,
Expand Down
1 change: 1 addition & 0 deletions R/htanno-reorder.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ htanno_reorder <- function(fun = rowMeans, ..., strict = TRUE,
}

HtannoReorder <- ggplot2::ggproto("HtannoReorder", HtannoProto,
setup_data = function(self) .subset2(self, "data"),
compute = function(self, panels, index, fun, fun_params, strict) {
data <- .subset2(self, "data")
position <- .subset2(self, "position")
Expand Down
9 changes: 6 additions & 3 deletions R/initialize-htanno.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ initialize_htanno_layout <- function(object, heatmap, object_name) {
params <- object$setup_params()
object$params <- params

# prepare data --------------------------------------
data <- object$setup_data()
object$data <- data
# rows are observations, this data came from `htanno_setup_data`, which can
# be used to check the axis dimention
data <- .subset2(object, "data")

# set up data --------------------------------------
object$data <- object$setup_data()

# prepare old layout --------------------------------
old_panels <- slot(heatmap, paste0(axis, "_panels"))
Expand Down
Binary file modified tests/testthat/_snaps/htanno/dendro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/testthat/_snaps/htanno/dendro_cutree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/testthat/_snaps/htanno/dendro_left_between_group_reorder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/testthat/_snaps/htanno/dendro_top_between_group.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7965809

Please sign in to comment.