downsample_matrix: downsample matrix by cluster or completely random

Description Usage Arguments Value Examples

View source: R/utils.R

Description

downsample matrix by cluster or completely random

Usage

1
2
3
4
5
6
7
downsample_matrix(
  mat,
  n = 1,
  keep_cluster_proportions = TRUE,
  metadata = NULL,
  cluster_col = "cluster"
)

Arguments

mat

expression matrix

n

number per cluster or fraction to keep

keep_cluster_proportions

whether to subsample

metadata

data.frame or vector containing cluster assignments per cell. Order must match column order in supplied matrix. If a data.frame provide the cluster_col parameters.

cluster_col

column in metadata with cluster number

Value

new smaller mat with less cell_id columns

Examples

1
2
3
4
5
6
7
8
set.seed(42)
mat <- downsample_matrix(
    mat = pbmc_matrix_small,
    metadata = pbmc_meta$classified,
    n = 10,
    keep_cluster_proportions = TRUE
)
mat[1:3, 1:3]

NCBI-Hackathons/RClusterCT documentation built on July 20, 2021, 3:15 p.m.