# == title # Get row order from a heatmap list # # == param # -object a `HeatmapList-class` object # # == value # The format of the returned object depends on whether rows/columns of the heatmaps are split. # # == author # Zuguang Gu <z.gu@dkfz.de> # # == example # mat = matrix(rnorm(100), 10) # ht_list = Heatmap(mat) + Heatmap(mat) # ht_list = draw(ht_list) # row_order(ht_list) # ht_list = Heatmap(mat, row_km = 2) + Heatmap(mat) # ht_list = draw(ht_list) # row_order(ht_list) # ht_list = Heatmap(mat, row_km = 2) %v% Heatmap(mat) # ht_list = draw(ht_list) # row_order(ht_list) setMethod(f = "row_order", signature = "HeatmapList", definition = function(object) { object = make_layout(object) n = length(object@ht_list) ht_index = which(sapply(seq_along(object@ht_list), function(i) inherits(object@ht_list[[i]], "Heatmap"))) if(length(ht_index) == 0) { return(NULL) } if(object@direction == "horizontal") { lt = object@ht_list[[ ht_index[1] ]]@row_order_list if(length(lt) == 1) { return(lt[[1]]) } else { return(lt) } } else { lt_rd = list() for(i in ht_index) { lt = object@ht_list[[i]]@row_order_list lt_rd = c(lt_rd, list(lt)) } names(lt_rd) = names(object@ht_list)[ht_index] proper_format_lt(lt_rd) } }) # == title # Get row order from a heatmap # # == param # -object a `Heatmap-class` object # # == value # The format of the returned object depends on whether rows/columns of the heatmaps are split. # # == author # Zuguang Gu <z.gu@dkfz.de> # # == example # mat = matrix(rnorm(100), 10) # ht = Heatmap(mat) # ht = draw(ht) # row_order(ht) # ht = Heatmap(mat, row_km = 2) # ht = draw(ht) # row_order(ht) # setMethod(f = "row_order", signature = "Heatmap", definition = function(object) { object = prepare(object) lt = object@row_order_list if(length(lt) == 1) { return(lt[[1]]) } else { return(lt) } }) # == title # Get column order from a heatmap list # # == param # -object a `HeatmapList-class` object # # == value # The format of the returned object depends on whether rows/columns of the heatmaps are split. # # == author # Zuguang Gu <z.gu@dkfz.de> # # == example # mat = matrix(rnorm(100), 10) # ht_list = Heatmap(mat) + Heatmap(mat) # ht_list = draw(ht_list) # column_order(ht_list) # ht_list = Heatmap(mat, column_km = 2) + Heatmap(mat, column_km = 2) # ht_list = draw(ht_list) # column_order(ht_list) # ht_list = Heatmap(mat) %v% Heatmap(mat) # ht_list = draw(ht_list) # column_order(ht_list) # ht_list = Heatmap(mat, column_km = 2) %v% Heatmap(mat) # ht_list = draw(ht_list) # column_order(ht_list) setMethod(f = "column_order", signature = "HeatmapList", definition = function(object) { object = make_layout(object) n = length(object@ht_list) ht_index = which(sapply(seq_along(object@ht_list), function(i) inherits(object@ht_list[[i]], "Heatmap"))) if(length(ht_index) == 0) { return(NULL) } if(object@direction == "vertical") { lt = object@ht_list[[ ht_index[1] ]]@column_order_list if(length(lt) == 1) { return(lt[[1]]) } else { return(lt) } } else { lt_rd = list() for(i in ht_index) { lt = object@ht_list[[i]]@column_order_list lt_rd = c(lt_rd, list(lt)) } names(lt_rd) = names(object@ht_list)[ht_index] proper_format_lt(lt_rd) } }) # == title # Get column order from a heatmap list # # == param # -object a `Heatmap-class` object # # == value # The format of the returned object depends on whether rows/columns of the heatmaps are split. # # == author # Zuguang Gu <z.gu@dkfz.de> # # == example # mat = matrix(rnorm(100), 10) # ht = Heatmap(mat) # ht = draw(ht) # column_order(ht) # ht = Heatmap(mat, column_km = 2) # ht = draw(ht) # column_order(ht) setMethod(f = "column_order", signature = "Heatmap", definition = function(object) { object = prepare(object) lt = object@column_order_list if(length(lt) == 1) { return(lt[[1]]) } else { return(lt) } }) # == title # Get row dendrograms from a heatmap list # # == param # -object a `HeatmapList-class` object # # == value # The format of the returned object depends on whether rows/columns of the heatmaps are split. # # == author # Zuguang Gu <z.gu@dkfz.de> # # == example # mat = matrix(rnorm(100), 10) # ht_list = Heatmap(mat) + Heatmap(mat) # ht_list = draw(ht_list) # row_dend(ht_list) # ht_list = Heatmap(mat, row_km = 2) + Heatmap(mat) # ht_list = draw(ht_list) # row_dend(ht_list) # ht_list = Heatmap(mat, row_km = 2) %v% Heatmap(mat) # ht_list = draw(ht_list) # row_dend(ht_list) setMethod(f = "row_dend", signature = "HeatmapList", definition = function(object) { object = make_layout(object) n = length(object@ht_list) ht_index = which(sapply(seq_along(object@ht_list), function(i) inherits(object@ht_list[[i]], "Heatmap"))) if(length(ht_index) == 0) { return(NULL) } if(object@direction == "horizontal") { lt = object@ht_list[[ ht_index[1] ]]@row_dend_list if(length(lt) == 1) { return(lt[[1]]) } else { return(lt) } } else { lt_rd = list() for(i in ht_index) { lt = object@ht_list[[i]]@row_dend_list lt_rd = c(lt_rd, list(lt)) } names(lt_rd) = names(object@ht_list)[ht_index] proper_format_lt(lt_rd) } }) # == title # Get row dendrograms from a heatmap # # == param # -object a `Heatmap-class` object # # == value # The format of the returned object depends on whether rows/columns of the heatmaps are split. # # == author # Zuguang Gu <z.gu@dkfz.de> # # == example # mat = matrix(rnorm(100), 10) # ht = Heatmap(mat) # ht = draw(ht) # row_dend(ht) # ht = Heatmap(mat, row_km = 2) # ht = draw(ht) # row_dend(ht) # setMethod(f = "row_dend", signature = "Heatmap", definition = function(object) { object = prepare(object) lt = object@row_dend_list if(length(lt) == 1) { return(lt[[1]]) } else { return(lt) } }) # == title # Get column dendrograms from a heatmap list # # == param # -object a `HeatmapList-class` object # # == value # The format of the returned object depends on whether rows/columns of the heatmaps are split. # # == author # Zuguang Gu <z.gu@dkfz.de> # # == example # mat = matrix(rnorm(100), 10) # ht_list = Heatmap(mat) + Heatmap(mat) # ht_list = draw(ht_list) # column_dend(ht_list) # ht_list = Heatmap(mat, column_km = 2) + Heatmap(mat, column_km = 2) # ht_list = draw(ht_list) # column_dend(ht_list) # ht_list = Heatmap(mat) %v% Heatmap(mat) # ht_list = draw(ht_list) # column_dend(ht_list) # ht_list = Heatmap(mat, column_km = 2) %v% Heatmap(mat) # ht_list = draw(ht_list) # column_dend(ht_list) setMethod(f = "column_dend", signature = "HeatmapList", definition = function(object) { object = make_layout(object) n = length(object@ht_list) ht_index = which(sapply(seq_along(object@ht_list), function(i) inherits(object@ht_list[[i]], "Heatmap"))) if(length(ht_index) == 0) { return(NULL) } if(object@direction == "vertical") { lt = object@ht_list[[ ht_index[1] ]]@column_dend_list if(length(lt) == 1) { return(lt[[1]]) } else { return(lt) } } else { lt_rd = list() for(i in ht_index) { lt = object@ht_list[[i]]@column_dend_list lt_rd = c(lt_rd, list(lt)) } names(lt_rd) = names(object@ht_list)[ht_index] proper_format_lt(lt_rd) } }) # == title # Get column dendrograms from a heatmap # # == param # -object a `Heatmap-class` object # # == value # The format of the returned object depends on whether rows/columns of the heatmaps are split. # # == author # Zuguang Gu <z.gu@dkfz.de> # # == example # mat = matrix(rnorm(100), 10) # ht = Heatmap(mat) # ht = draw(ht) # column_dend(ht) # ht = Heatmap(mat, column_km = 2) # ht = draw(ht) # column_dend(ht) # setMethod(f = "column_dend", signature = "Heatmap", definition = function(object) { object = prepare(object) lt = object@column_dend_list if(length(lt) == 1) { return(lt[[1]]) } else { return(lt) } }) proper_format_lt = function(lt) { n_ht = length(lt) # for a single heatmap if(n_ht == 1) { if(length(lt[[1]]) == 1) { return(lt[[1]][[1]]) } else { return(lt[[1]]) } } else { has_splitting = any(sapply(lt, function(x) length(x) != 1)) if(has_splitting) { return(lt) } else { return(lapply(lt, function(x) x[[1]])) } } }