getBetaTheta: Pull out cell-type proportions across pixels (theta) and...

View source: R/functions.R

getBetaThetaR Documentation

Pull out cell-type proportions across pixels (theta) and cell-type gene probabilities (beta) matrices from fitted LDA models from fitLDA

Description

Pull out cell-type proportions across pixels (theta) and cell-type gene probabilities (beta) matrices from fitted LDA models from fitLDA

Usage

getBetaTheta(
  lda,
  corpus = NULL,
  perc.filt = 0.05,
  betaScale = 1,
  verbose = TRUE
)

Arguments

lda

an LDA model from "topicmodels" R package. From list of models returned by fitLDA

corpus

If corpus is NULL, then it will use the original corpus that the model was fitted to. Otherwise, compute deconvolved topics from this new corpus. Needs to be pixels x genes and nonnegative integer counts. Each row needs at least 1 nonzero entry (default: NULL)

perc.filt

proportion threshold to remove cell-types in pixels (default: 0.05)

betaScale

factor to scale the predicted cell-type gene expression profiles (default: 1)

verbose

Boolean for verbosity (default: TRUE)

Value

A list that contains

  • beta: cell-type (rows) by gene (columns) distribution matrix. Each row is a probability distribution of a cell-type expressing each gene in the corpus

  • theta: pixel (rows) by cell-types (columns) distribution matrix. Each row is the cell-type composition for a given pixel

Examples

data(mOB)
pos <- mOB$pos
cd <- mOB$counts
counts <- cleanCounts(cd, min.lib.size = 100)
corpus <- restrictCorpus(counts, removeAbove=1.0, removeBelow = 0.05)
ldas <- fitLDA(t(as.matrix(corpus)), Ks = 3, ncores=2)
optLDA <- optimalModel(models = ldas, opt = 3)
results <- getBetaTheta(optLDA, perc.filt = 0.05, betaScale = 1000)
head(results$theta)
head(results$beta)


JEFworks-Lab/STdeconvolve documentation built on Nov. 14, 2024, 7:24 p.m.