get_prior: Get prior CTS profile and covariance matrix from single-cell...

View source: R/bmind_func.r

get_priorR Documentation

Get prior CTS profile and covariance matrix from single-cell data

Description

It calculates prior CTS profile and covariance matrix from single-cell data. The output can serve as hyper-parameters in bMIND. Only genes with positive definite covariance matrix are outputted.

Usage

get_prior(sc, sample = NULL, cell_type = NULL, meta_sc = NULL, filter_pd = T)

Arguments

sc

single-cell count matrix, gene x cell.

sample

variable for sample ID. It is used to generate pseudo-bulk data and calculate cell-type covariance matrix across samples for each gene.

cell_type

variable for cell type labels.

meta_sc

data.frame for meta of cells (cell x features, including columns 'sample' (sample ID), 'cell_type'). Not required if sample and cell_type are provided.

filter_pd

option to filer out genes without positive-definite cell-type covariance matrix, default is TRUE.

Value

A list containing

profile

CTS profile matrix (gene x cell type), in log2(CPM + 1) scale.

covariance

CTS covariance matrix (gene x cell type x cell type).

Examples

suppressMessages(library(scRNAseq))

suppressMessages(dar <- DarmanisBrainData())

# focus on adult cells with non-hybrid lables
dar = dar[, !dar$cell.type %in% c('fetal_quiescent', 'fetal_replicating', 'hybrid')]
dar = dar[rowSums(counts(dar))!=0,]

table(dar$cell.type, dar$experiment_sample_name)

# the error is caused by OPC is only from one sample
prior = get_prior(sc = counts(dar), sample = dar$experiment_sample_name, cell_type = dar$cell.type)

# drop cells only from one sample
dar = dar[, !dar$cell.type %in% c('OPC')]
dar = dar[rowSums(counts(dar))!=0,]

prior = get_prior(sc = counts(dar), sample = dar$experiment_sample_name, cell_type = dar$cell.type)

dim(prior$profile)
head(prior$profile)

dim(prior$covariance)
prior$covariance[1,,]

# Note bMIND requires positive-definite prior covariance matrix
prior_all = get_prior(sc = counts(dar), sample = dar$experiment_sample_name, cell_type = dar$cell.type, filter_pd = F)

randel/MIND documentation built on May 6, 2023, 7:45 a.m.