Skip to content

Commit 27c7b30

Browse files
author
Nathan Lawlor
committed
Updated R version to 3.5
Updated NAMESPACE and DESCRIPTION to include SummarizedExperiment class Updated R code, man, test, and vignette to include SummarizedExperiment class Addressed minor formatting and warnings/notes
1 parent 725d18b commit 27c7b30

16 files changed

+120
-78
lines changed

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ Description: Iteratively Adjusted Surrogate Variable Analysis (IA-SVA) is a
1919
iii), if significant, use the estimated factor as an additional known
2020
factor in the next iteration to uncover further hidden factors.
2121
Depends:
22-
R (>= 3.2),
22+
R (>= 3.5),
2323
Imports:
2424
irlba,
2525
parallel,
2626
stats,
2727
cluster,
28-
graphics
28+
graphics,
29+
SummarizedExperiment
2930
License: GPL-2
3031
biocViews: Preprocessing, QualityControl, BatchEffect
3132
Suggests:

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export(fast_iasva)
44
export(find_markers)
55
export(iasva)
66
export(study_R2)
7+
importFrom(SummarizedExperiment,SummarizedExperiment)
8+
importFrom(SummarizedExperiment,assay)
79
importFrom(cluster,silhouette)
810
importFrom(graphics,Axis)
911
importFrom(graphics,mtext)

R/fast_iasva.R

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#' A function for fast IA-SVA
22
#'
33
#' The iterative procedure of fast IA-SVA is implemented in this
4-
#' function (fast_iasva). fast_iasva() iterativel identify a hidden factor
5-
#' for unwanted variation while accounting for all known factors,
6-
#' compute its contribution (i.e., the percentage of unmodeled variation
4+
#' function (fast_iasva). fast_iasva() iteratively identifies a hidden factor
5+
#' for unwanted variation while accounting for all known factors, and
6+
#' computes its contribution (i.e., the percentage of unmodeled variation
77
#' explained by the hidden factor) on the unmodeled variation in the data.
88
#' If the contribution is greater than a user-defined cutoff (pct.cutoff,
99
#' default = 1%), the factor is retained and used as a known variable in
1010
#' the next iteration to find further hidden factors.
1111
#' @importFrom irlba irlba
12+
#' @importFrom SummarizedExperiment SummarizedExperiment assay
1213
#'
13-
#' @param Y read counts matrix with samples in row and genes in column.
14-
#' @param X known variables.
14+
#' @param Y A SummarizedExperiment class containing read counts where
15+
#' rows represent genes and columns represent samples.
16+
#' @param X A design matrix of known variables (e.g., patient ID, gender).
1517
#' @param intercept If intercept = FALSE, the linear
1618
#' intercept is not included in the model.
1719
#' @param num.sv number of surrogate variables to estimate.
@@ -33,7 +35,6 @@
3335
#' @return n.sv number of obtained surrogate variables.
3436
#'
3537
#' @examples
36-
#' library(iasva)
3738
#' counts_file <- system.file("extdata", "iasva_counts_test.Rds",
3839
#' package = "iasva")
3940
#' counts <- readRDS(counts_file)
@@ -43,11 +44,14 @@
4344
#' Geo_Lib_Size <- colSums(log(counts + 1))
4445
#' Patient_ID <- anns$Patient_ID
4546
#' mod <- model.matrix(~Patient_ID + Geo_Lib_Size)
46-
#' iasva.res <- fast_iasva(t(counts), mod[, -1], num.sv = 5)
47+
#' summ_exp <- SummarizedExperiment::SummarizedExperiment(assays = counts)
48+
#' iasva.res <- fast_iasva(summ_exp, mod[, -1], num.sv = 5)
4749
#' @export
4850

4951
fast_iasva <- function(Y, X, intercept = TRUE, num.sv = NULL, pct.cutoff = 1,
5052
num.tsv = NULL, tol = 1e-10, verbose = FALSE) {
53+
# transpose the read counts
54+
Y <- t(assay(Y))
5155
cat("fast IA-SVA running...")
5256
if (min(Y) < 0) {
5357
Y <- Y + abs(min(Y))
@@ -118,7 +122,7 @@ fast_iasva <- function(Y, X, intercept = TRUE, num.sv = NULL, pct.cutoff = 1,
118122
cat(paste0("\nSV", isv, " Detected!"))
119123
}
120124
if (isv > 0) {
121-
colnames(sv) <- paste0("SV", 1:ncol(sv))
125+
colnames(sv) <- paste0("SV", seq(from = 1, to = ncol(sv), by = 1))
122126
cat(paste0("\n# of obtained surrogate variables: ", length(pct)))
123127
return(list(sv = sv, pct = pct, n.sv = length(pct)))
124128
} else {

R/find_markers.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
#' identifies marker genes highly correlated with each surrogate variable
66
#' and returns a read counts matrix of the markers.
77
#' @importFrom stats lm p.adjust
8+
#' @importFrom SummarizedExperiment SummarizedExperiment assay
89
#'
9-
#' @param Y read counts matrix with samples in row and genes in column.
10+
#' @param Y A SummarizedExperiment class containing read counts where
11+
#' rows represent genes and columns represent samples.
1012
#' @param iasva.sv matrix of estimated surrogate variables,
1113
#' one column for each surrogate variable.
1214
#' @param method multiple testing adjustment method, default = "BH".
@@ -18,7 +20,6 @@
1820
#' one column for each cell.
1921
#'
2022
#' @examples
21-
#' library(iasva)
2223
#' counts_file <- system.file("extdata", "iasva_counts_test.Rds",
2324
#' package = "iasva")
2425
#' counts <- readRDS(counts_file)
@@ -28,12 +29,15 @@
2829
#' Geo_Lib_Size <- colSums(log(counts + 1))
2930
#' Patient_ID <- anns$Patient_ID
3031
#' mod <- model.matrix(~Patient_ID + Geo_Lib_Size)
31-
#' iasva.res <- iasva(t(counts), mod[, -1], num.sv = 5, permute = FALSE)
32-
#' markers <- find_markers(t(counts), iasva.res$sv)
32+
#' summ_exp <- SummarizedExperiment::SummarizedExperiment(assays = counts)
33+
#' iasva.res <- iasva(summ_exp, mod[, -1], num.sv = 5, permute = FALSE)
34+
#' markers <- find_markers(summ_exp, iasva.res$sv)
3335
#' @export
3436

3537
find_markers <- function(Y, iasva.sv, method = "BH", sig.cutoff = 0.05,
3638
rsq.cutoff = 0.3, verbose = FALSE) {
39+
# transpose the read counts
40+
Y <- t(assay(Y))
3741
if (min(Y) < 0) {
3842
Y <- Y + abs(min(Y))
3943
}

R/iasva.R

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
#' unmodeled variation in the data. If the test statistic of detected factor
88
#' is significant, iasva() includes the factor as a known variable in the
99
#' next iteration to find further hidden factors.
10-
#'
11-
#' @param Y read counts matrix with samples in row and genes in column.
12-
#' @param X known variables including the primary variables of interest.
10+
#'
11+
#' @importFrom SummarizedExperiment SummarizedExperiment assay
12+
#' @param Y A SummarizedExperiment class containing read counts where
13+
#' rows represent genes and columns represent samples.
14+
#' @param X A model matrix of known variables
15+
#' including the primary variables of interest.
1316
#' @param intercept If intercept = FALSE, the linear intercept
1417
#' is not included in the model.
1518
#' @param num.sv number of surrogate variables to estimate.
@@ -36,7 +39,6 @@
3639
#' @return n.sv number of significant/obtained surrogate variables.
3740
#'
3841
#' @examples
39-
#' library(iasva)
4042
#' counts_file <- system.file("extdata", "iasva_counts_test.Rds",
4143
#' package = "iasva")
4244
#' counts <- readRDS(counts_file)
@@ -46,7 +48,8 @@
4648
#' Geo_Lib_Size <- colSums(log(counts + 1))
4749
#' Patient_ID <- anns$Patient_ID
4850
#' mod <- model.matrix(~Patient_ID + Geo_Lib_Size)
49-
#' iasva.res<- iasva(t(counts), mod[, -1],verbose = FALSE,
51+
#' summ_exp <- SummarizedExperiment::SummarizedExperiment(assays = counts)
52+
#' iasva.res<- iasva(summ_exp, mod[, -1],verbose = FALSE,
5053
#' permute = FALSE, num.sv = 5)
5154
#' @export
5255

@@ -78,7 +81,7 @@ iasva <- function(Y, X, intercept = TRUE, num.sv = NULL, permute = TRUE,
7881
cat(paste0("\nSV", isv, " Detected!"))
7982
}
8083
if (isv > 0) {
81-
colnames(sv) <- paste0("SV", 1:ncol(sv))
84+
colnames(sv) <- paste0("SV", seq(from = 1, to = ncol(sv)))
8285
cat(paste0("\n# of significant surrogate variables: ", length(pval)))
8386
return(list(sv = sv, pc.stat.obs = pc.stat.obs,
8487
pval = pval, n.sv = length(pval)))

R/iasva_unit.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
iasva_unit <- function(Y, X, intercept = TRUE, permute = TRUE, num.p = 100,
55
threads = 1, num.sv.permtest = NULL,
66
tol = 1e-10, verbose = FALSE) {
7+
# transpose the read counts
8+
Y <- t(assay(Y))
79
if (min(Y) < 0) {
810
Y <- Y + abs(min(Y))
911
}
@@ -60,13 +62,14 @@ iasva_unit <- function(Y, X, intercept = TRUE, permute = TRUE, num.p = 100,
6062
if (threads > 1) {
6163
threads <- min(threads, detectCores() - 1)
6264
cl <- makeCluster(threads)
63-
pc.stat.null.vec <- tryCatch(parSapply(cl, 1:num.p, permute.svd),
65+
pc.stat.null.vec <- tryCatch(parSapply(cl,
66+
seq(from = 1, to = num.p), permute.svd),
6467
error = function(err) {
6568
stopCluster(cl); stop(err)
6669
})
6770
stopCluster(cl)
6871
} else {
69-
pc.stat.null.vec <- sapply(1:num.p, permute.svd)
72+
pc.stat.null.vec <- vapply(seq(from = 1, to = num.p), permute.svd)
7073
}
7174
if (verbose) {
7275
cat("\n Empirical null distribution of the PC statistic:",

R/study_R2.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
#' @importFrom graphics Axis mtext par plot
99
#' @importFrom stats .lm.fit cutree dist hclust lm p.adjust resid
1010
#' @importFrom cluster silhouette
11+
#' @importFrom SummarizedExperiment SummarizedExperiment assay
1112
#'
12-
#' @param Y read counts matrix with samples in row and genes in column.
13+
#' @param Y A SummarizedExperiment class containing read counts where
14+
#' rows represent genes and columns represent samples.
1315
#' @param iasva.sv matrix of estimated surrogate variables,
1416
#' one column for each surrogate variable.
1517
#' @param selected.svs list of SVs that are selected for the
@@ -21,7 +23,6 @@
2123
#' as a function of R2 and corresponding matrices.
2224
#'
2325
#' @examples
24-
#' library(iasva)
2526
#' counts_file <- system.file("extdata", "iasva_counts_test.Rds",
2627
#' package = "iasva")
2728
#' counts <- readRDS(counts_file)
@@ -31,10 +32,11 @@
3132
#' Geo_Lib_Size <- colSums(log(counts + 1))
3233
#' Patient_ID <- anns$Patient_ID
3334
#' mod <- model.matrix(~Patient_ID + Geo_Lib_Size)
34-
#' iasva.res<- iasva(t(counts), mod[, -1],verbose = FALSE,
35+
#' summ_exp <- SummarizedExperiment::SummarizedExperiment(assays = counts)
36+
#' iasva.res<- iasva(summ_exp, mod[, -1],verbose = FALSE,
3537
#' permute = FALSE, num.sv = 5)
3638
#' iasva.sv <- iasva.res$sv
37-
#' study_res <- study_R2(t(counts), iasva.sv)
39+
#' study_res <- study_R2(summ_exp, iasva.sv)
3840
#'
3941
#' @export
4042

@@ -68,11 +70,11 @@ study_R2 <- function(Y, iasva.sv, selected.svs = 2,
6870
pch = 18, col = "blue", type = "b", lty = 2, cex = 2)
6971
Axis(1, at = seq(1, length(Number.of.genes)), side = 1,
7072
labels = seq(0.1, end.point, 0.05), las = 2)
71-
par(new = T)
72-
plot(C.scores, xlab = "", ylab = "", axes = F, pch = 18, col = "red",
73+
par(new = TRUE)
74+
plot(C.scores, xlab = "", ylab = "", axes = FALSE, pch = 18, col = "red",
7375
type = "b", lty = 2, cex = 2)
7476
Axis(side = 4)
7577
mtext(side = 4, line = 2, "Average Silhouette Score", col = "red")
76-
par(new = F)
78+
par(new = FALSE)
7779
return(output.matrix)
7880
}

man/fast_iasva.Rd

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

man/find_markers.Rd

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

man/iasva.Rd

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

0 commit comments

Comments
 (0)