redimMatrix: redimMatrix()

View source: R/redimMatrix.R

redimMatrixR Documentation

redimMatrix()

Description

Reduce the input matrix size by applying a summary function on cells to be fused.

Usage

redimMatrix(
  mat,
  target_height = 100,
  target_width = 100,
  summary_func = function(x) mean(x, na.rm = TRUE),
  output_type = 0,
  n_core = 1
)

Arguments

mat

the input matrix.

target_height

height of the output matrix (should be smaller than or equal to nrow(mat)).

target_width

width of the output matrix (should be smaller than or equal to ncol(mat)).

summary_func

how to summerize cells? A function such has mean, median, max, or meanColors.

output_type

Type of the output, to be passed to vapply's FUN.VALUE.

n_core

number of core to use for parallel processing.

Details

This function is used to reduce matrix right before plotting them in order to avoid overplotting issues as well as other plotting artefacts.

Value

a resized matrix of size target_width x target_height where the summary_fun was apply to adjacent cells.

See Also

meanColor

Examples

data("stackepi")
mat <- SummarizedExperiment::assay(stackepi, "DNAme")
dim(mat)
smallMat <- redimMatrix(mat, target_height = 10, target_width = ncol(mat))
dim(smallMat)

# changing the summary function
mat <- matrix(sample(1:40,100,replace=TRUE),nrow=10,ncol=10)
dim(mat)
smallMat <- redimMatrix(mat, target_height = 5, target_width = ncol(mat),
   summary_func = function(x) max(x, na.rm = TRUE))
dim(smallMat)

# working with colors
colmat <- matrix(
    c("red", "red", "blue", "blue", "red", "blue", "blue", "green"),
    ncol = 2
)
redimMatrix(colmat, target_height = 2, target_width = 2,
            summary_func = meanColor, output_type = "color")


GenEpi-GenPhySE/epistack documentation built on July 27, 2023, 1:09 a.m.