Skip to content

Commit 724f67c

Browse files
committed
update top_markers function, allow batch correction.
1 parent 4682572 commit 724f67c

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ biocViews: Software, GeneExpression, Transcriptomics
1414
License: MIT + file LICENSE
1515
Encoding: UTF-8
1616
Roxygen: list(markdown = TRUE)
17-
RoxygenNote: 7.3.1
17+
RoxygenNote: 7.3.2
1818
Collate:
1919
'AllClasses.R'
2020
'tf_idf_iae_wrappers.R'

R/top_markers.R

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ top_markers_abs <- function(data, label, n = 10,
106106
#' @param data matrix, features in row and samples in column
107107
#' @param n integer, number of returned top genes for each group
108108
#' @param family family for glm, details in [stats::glm()]
109+
#' @param batch a vector of batch labels, default NULL
109110
#' @param scale logical, if to scale data by row
110111
#' @param use.mgm logical, if to scale data using [scale_mgm()]
111112
#' @param softmax logical, if to apply softmax transformation on output
@@ -119,6 +120,7 @@ top_markers_abs <- function(data, label, n = 10,
119120
#' top_markers_glm(data, label = rep(c("A", "B"), 5))
120121
top_markers_glm <- function(data, label, n = 10,
121122
family = gaussian(), # score are continuous non-negative, can use gamma or inverse.gaussian, if continuous and unbounded use gaussian, if discrete use poisson, if binary or proportions between [0,1] or binary freq counts use binomial
123+
batch = NULL,
122124
scale = TRUE, use.mgm = TRUE,
123125
pooled.sd = FALSE,
124126
# log = TRUE,
@@ -144,8 +146,17 @@ top_markers_glm <- function(data, label, n = 10,
144146
# data <- log(data + 1e-8)
145147
# }
146148

147-
## estimate betas based on given group
148-
betas <- apply(data, 1, \(s) glm(s ~ 0 + label, family = family)$coef)
149+
## estimate betas based on given group and/or batch
150+
if (is.null(batch)) {
151+
## model with group label
152+
betas <- apply(data, 1, \(s) glm(s ~ 0 + label, family = family)$coef)
153+
} else {
154+
## model with both group and batch label
155+
betas <- apply(data, 1, \(s) glm(s ~ 0 + label + batch, family = family)$coef)
156+
## only extract betas for group label
157+
betas <- betas[grep("^label", rownames(betas)), ]
158+
}
159+
149160
rownames(betas) <- gsub("label", "", rownames(betas))
150161

151162
# ## compute logFC (1 vs all mean) for each group

man/smartid_Package.Rd

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/top_markers_glm.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)