Skip to contents

This function zeroes out all but the top-k most highly expressed genes in each column of a gene expression matrix. It supports both dense and sparse inputs.

Usage

maskTopKGenes(data, k = 20)

Arguments

data

A gene expression matrix with genes as rows and cells (or spatial spots) as columns. Can be a dense numeric matrix, or a sparse dgCMatrix.

k

Integer. Number of top expressed genes to retain per column. Default is 20.

Value

A dense numeric matrix with the same dimensions as data, with only the top-k values retained per column.

Examples

mat <- matrix(runif(1000), nrow = 100)
masked <- maskTopKGenes(mat, k = 10)