Skip to content

Commit a8f51dc

Browse files
committed
updated R functions to support SingleCellExperiment objects
1 parent 893a6e2 commit a8f51dc

File tree

5 files changed

+25
-16
lines changed

5 files changed

+25
-16
lines changed

R/fast_iasva.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
#' the next iteration to find further hidden factors.
1111
#' @importFrom irlba irlba
1212
#' @importFrom SummarizedExperiment SummarizedExperiment assay
13+
#' @importFrom SingleCellExperiment SingleCellExperiment
1314
#'
14-
#' @param Y A SummarizedExperiment class containing read counts where
15-
#' rows represent genes and columns represent samples.
15+
#' @param Y A SummarizedExperiment or SingleCellExperiment class containing
16+
#' read counts where rows represent genes and columns represent samples.
1617
#' @param X A design matrix of known variables (e.g., patient ID, gender).
1718
#' @param intercept If intercept = FALSE, the linear
1819
#' intercept is not included in the model.
@@ -51,11 +52,12 @@
5152
fast_iasva <- function(Y, X, intercept = TRUE, num.sv = NULL, pct.cutoff = 1,
5253
num.tsv = NULL, tol = 1e-10, verbose = FALSE) {
5354
# error handling
54-
stopifnot(class(Y)[1] == "SummarizedExperiment", is.numeric(tol),
55+
stopifnot(class(Y)[1] == "SummarizedExperiment" | class(Y) == "SingleCellExperiment",
56+
is.numeric(tol),
5557
is.matrix(X))
5658

5759
# transpose the read counts
58-
Y <- t(assay(Y))
60+
Y <- as.matrix(t(assay(Y)))
5961
message("fast IA-SVA running...")
6062
if (min(Y) < 0) {
6163
Y <- Y + abs(min(Y))

R/find_markers.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
#' and returns a read counts matrix of the markers.
77
#' @importFrom stats lm p.adjust
88
#' @importFrom SummarizedExperiment SummarizedExperiment assay
9+
#' @importFrom SingleCellExperiment SingleCellExperiment
910
#'
10-
#' @param Y A SummarizedExperiment class containing read counts where
11-
#' rows represent genes and columns represent samples.
11+
#' @param Y A SummarizedExperiment or SingleCellExperiment class containing
12+
#' read counts where rows represent genes and columns represent samples.
1213
#' @param iasva.sv matrix of estimated surrogate variables,
1314
#' one column for each surrogate variable.
1415
#' @param method multiple testing adjustment method, default = "BH".
@@ -37,13 +38,14 @@
3738
find_markers <- function(Y, iasva.sv, method = "BH", sig.cutoff = 0.05,
3839
rsq.cutoff = 0.3, verbose = FALSE) {
3940
# error handling
40-
stopifnot(class(Y)[1] == "SummarizedExperiment", is.numeric(sig.cutoff),
41+
stopifnot(class(Y)[1] == "SummarizedExperiment" | class(Y) == "SingleCellExperiment",
42+
is.numeric(sig.cutoff),
4143
is.numeric(rsq.cutoff), is.matrix(iasva.sv),
4244
method %in% c("holm", "hochberg", "hommel", "bonferroni",
4345
"BH", "BY", "fdr", "none"))
4446

4547
# transpose the read counts
46-
Y <- t(assay(Y))
48+
Y <- as.matrix(t(assay(Y)))
4749
if (min(Y) < 0) {
4850
Y <- Y + abs(min(Y))
4951
}

R/iasva.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
#' next iteration to find further hidden factors.
1010
#'
1111
#' @importFrom SummarizedExperiment SummarizedExperiment assay
12-
#' @param Y A SummarizedExperiment class containing read counts where
13-
#' rows represent genes and columns represent samples.
12+
#' @importFrom SingleCellExperiment SingleCellExperiment
13+
#' @param Y A SummarizedExperiment or SingleCellExperiment class containing
14+
#' read counts where rows represent genes and columns represent samples.
1415
#' @param X A model matrix of known variables
1516
#' including the primary variables of interest.
1617
#' @param intercept If intercept = FALSE, the linear intercept
@@ -57,7 +58,8 @@ iasva <- function(Y, X, intercept = TRUE, num.sv = NULL, permute = TRUE,
5758
num.p = 100, sig.cutoff = 0.05, threads = 1,
5859
num.sv.permtest = NULL, tol = 1e-10, verbose = FALSE) {
5960
# error handling
60-
stopifnot(class(Y)[1] == "SummarizedExperiment", is.numeric(tol),
61+
stopifnot(class(Y)[1] == "SummarizedExperiment" | class(Y) == "SingleCellExperiment",
62+
is.numeric(tol),
6163
is.matrix(X), is.numeric(num.p), is.numeric(sig.cutoff),
6264
is.numeric(threads))
6365
message("IA-SVA running...")

R/iasva_unit.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
#' @importFrom irlba irlba
33
#' @importFrom BiocParallel bplapply MulticoreParam
44
#' @importFrom SummarizedExperiment SummarizedExperiment assay
5+
#' @importFrom SingleCellExperiment SingleCellExperiment
56

67
iasva_unit <- function(Y, X, intercept = TRUE, permute = TRUE, num.p = 100,
78
threads = 1, num.sv.permtest = NULL,
89
tol = 1e-10, verbose = FALSE) {
910
# error handling
10-
stopifnot(class(Y)[1] == "SummarizedExperiment", is.numeric(tol),
11+
stopifnot(class(Y)[1] == "SummarizedExperiment" | class(Y) == "SingleCellExperiment",
12+
is.numeric(tol),
1113
is.matrix(X), is.numeric(num.p),
1214
is.numeric(threads))
1315

1416
# transpose the read counts
15-
Y <- t(assay(Y))
17+
Y <- as.matrix(t(assay(Y)))
1618
if (min(Y) < 0) {
1719
Y <- Y + abs(min(Y))
1820
}

R/study_R2.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
#' @importFrom stats .lm.fit cutree dist hclust lm p.adjust resid
1010
#' @importFrom cluster silhouette
1111
#' @importFrom SummarizedExperiment SummarizedExperiment assay
12+
#' @importFrom SingleCellExperiment SingleCellExperiment
1213
#'
13-
#' @param Y A SummarizedExperiment class containing read counts where
14-
#' rows represent genes and columns represent samples.
14+
#' @param Y A SummarizedExperiment or SingleCellExperiment class containing
15+
#' read counts where rows represent genes and columns represent samples.
1516
#' @param iasva.sv matrix of estimated surrogate variables,
1617
#' one column for each surrogate variable.
1718
#' @param selected.svs list of SVs that are selected for the
@@ -43,7 +44,7 @@
4344
study_R2 <- function(Y, iasva.sv, selected.svs = 2,
4445
no.clusters = 2, verbose = FALSE) {
4546
# error handling
46-
stopifnot(class(Y)[1] == "SummarizedExperiment",
47+
stopifnot(class(Y)[1] == "SummarizedExperiment" | class(Y) == "SingleCellExperiment",
4748
is.numeric(selected.svs),
4849
is.matrix(iasva.sv), is.numeric(no.clusters))
4950
C.scores <- matrix(0, 0, 0)

0 commit comments

Comments
 (0)