Skip to content

Commit ecc7f29

Browse files
committed
Adds metadata support to analysis function/results
1 parent 7596dd6 commit ecc7f29

11 files changed

+82
-31
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: FacileAnalysis
22
Type: Package
33
Title: Modularized and interactive analyses over a FacileDataStore
4-
Version: 0.98.33
4+
Version: 0.98.34
55
Authors@R: c(
66
person(
77
"Steve", "Lianoglou",

NAMESPACE

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ S3method(is_anova,default)
5656
S3method(is_ttest,default)
5757
S3method(label,FacileAnovaAnalysisResult)
5858
S3method(label,FacileTtestAnalysisResult)
59+
S3method(metadata,FacileAnalysisResult)
5960
S3method(model,"NULL")
6061
S3method(model,FacileDgeAnalysisResult)
6162
S3method(model,FacileTtestComparisonAnalysisResult)
@@ -148,6 +149,7 @@ export(fsave)
148149
export(is_anova)
149150
export(is_ttest)
150151
export(messages)
152+
export(metadata)
151153
export(model)
152154
export(param)
153155
export(plot_data)

R/api.R

+11
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@ compare.FacileAnalysisResult <- function(x, y, ...) {
107107
ry <- ranks(y, ...)
108108
}
109109

110+
#' @export
111+
#' @noRd
112+
metadata <- function(x, ...) {
113+
UseMethod("metadata", x)
114+
}
115+
116+
#' @export
117+
#' @noRd
118+
metadata.FacileAnalysisResult <- function(x, ...) {
119+
x[["metadata"]]
120+
}
110121

111122
#' @export
112123
#' @noRd

R/fdge-base.R

+10-3
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@
8787
#' efds <- FacileData::exampleFacileDataSet()
8888
#' samples <- efds |>
8989
#' FacileData::filter_samples(indication == "BLCA") |>
90-
#' dplyr::mutate(something = sample(c("a", "b"), n(), replace = TRUE))
90+
#' dplyr::mutate(something = sample(c("a", "b"), dplyr::n(), replace = TRUE))
9191
#' mdef <- flm_def(samples, covariate = "sample_type",
9292
#' numer = "tumor", denom = "normal",
93-
#' batch = "sex")
94-
#' dge <- fdge(mdef, method = "voom")
93+
#' batch = "sex",
94+
#' metadata = list(label = "test flm"))
95+
#' dge <- fdge(mdef, method = "voom", metadata = list(label = "test dge"))
9596
#' if (interactive()) {
9697
#' viz(dge)
9798
#' viz(dge, "146909")
@@ -107,6 +108,7 @@
107108
fdge <- function(x, assay_name = NULL, method = NULL, features = NULL,
108109
filter = "default", with_sample_weights = FALSE,
109110
treat_lfc = NULL, ...,
111+
metadata = list(),
110112
verbose = FALSE) {
111113
UseMethod("fdge", x)
112114
}
@@ -117,6 +119,7 @@ fdge.FacileFailedModelDefinition <- function(x, assay_name = NULL,
117119
method = NULL, features = NULL,
118120
filter = "default",
119121
with_sample_weights = FALSE, ...,
122+
metadata = list(),
120123
verbose = FALSE) {
121124
stop("There are erros in this model:\n", paste(x$errors, collapse = "\n"))
122125
}
@@ -127,6 +130,7 @@ fdge.FacileFailedModelDefinition <- function(x, assay_name = NULL,
127130
fdge.FacileAnovaModelDefinition <- function(x, assay_name = NULL, method = NULL,
128131
features = NULL, filter = "default",
129132
with_sample_weights = FALSE, ...,
133+
metadata = list(),
130134
verbose = FALSE) {
131135
res <- NextMethod(coef = x[["coef"]])
132136
# rename .intercept. to mean.level
@@ -150,6 +154,7 @@ fdge.FacileTtestDGEModelDefinition <- function(x, assay_name = NULL,
150154
with_sample_weights = FALSE,
151155
treat_lfc = NULL,
152156
...,
157+
metadata = list(),
153158
verbose = FALSE) {
154159
res <- NextMethod(contrast = x[["contrast"]])
155160
res
@@ -170,6 +175,7 @@ fdge.FacileLinearModelDefinition <- function(x, assay_name = NULL,
170175
biocbox = NULL,
171176
trend.eBayes = FALSE,
172177
robust.eBayes = FALSE,
178+
metadata = list(),
173179
verbose = FALSE) {
174180
messages <- character()
175181
warnings <- character()
@@ -382,6 +388,7 @@ fdge.FacileLinearModelDefinition <- function(x, assay_name = NULL,
382388
weights = weights),
383389
# Standard FacileAnalysisResult things
384390
fds = .fds,
391+
metadata = metadata,
385392
messages = messages,
386393
warnings = warnings,
387394
errors = errors)

R/ffsea-base.R

+7-4
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
#' FacileData::filter_samples(indication == "CRC") |>
128128
#' fpca()
129129
#' pca1.gsea <- ffsea(pca.crc, gdb, dim = 1)
130-
ffsea <- function(x, fsets, methods = NULL, ...) {
130+
ffsea <- function(x, fsets, methods = NULL, ..., metadata = list()) {
131131
UseMethod("ffsea", x)
132132
}
133133

@@ -136,7 +136,8 @@ ffsea <- function(x, fsets, methods = NULL, ...) {
136136
#' of genes.
137137
#'
138138
#' @noRd
139-
ffsea.FacileTtestDGEModelDefinition <- function(x, fsets, methods = NULL, ...) {
139+
ffsea.FacileTtestDGEModelDefinition <- function(x, fsets, methods = NULL,
140+
..., metadata = list()) {
140141
stop("Run fdge(x) |> ffsea() for now")
141142
}
142143

@@ -164,7 +165,8 @@ ffsea.data.frame <- function(x, fsets, methods = NULL,
164165
biased_by = NULL, ...,
165166
feature.bias = "thebuckstopshere",
166167
xmeta. = "thebuckstopshere",
167-
groups = "thebuckstopshere") {
168+
groups = "thebuckstopshere",
169+
metadata = list()) {
168170
if (is.null(methods)) {
169171
stop("A gsea method name must be provided to the `methods` parameter.")
170172
}
@@ -238,7 +240,8 @@ ffsea.data.frame <- function(x, fsets, methods = NULL,
238240
rank_order = rank_order,
239241
group_by = group_by,
240242
biased_by = biased_by,
241-
x = x, fsets = fsets))
243+
x = x, fsets = fsets),
244+
metadata = metadata)
242245
fds = suppressWarnings(fds(x))
243246
class(out) <- c("FacileFseaAnalysisResult", "FacileAnalysisResult")
244247
out

R/flm_def-base.R

+12-6
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
#' flm_def(covariate = "stage", batch = "sex")
8686
flm_def <- function(x, covariate, numer = NULL, denom = NULL,
8787
batch = NULL, block = NULL,
88-
on_missing = c("warning", "error"), ...) {
88+
on_missing = c("warning", "error"), ..., metadata = list()) {
8989
UseMethod("flm_def", x)
9090
}
9191

@@ -107,6 +107,7 @@ flm_def <- function(x, covariate, numer = NULL, denom = NULL,
107107
flm_def.data.frame <- function(x, covariate, numer = NULL, denom = NULL,
108108
batch = NULL, block = NULL,
109109
on_missing = c("warning", "error"), ...,
110+
metadata = list(),
110111
contrast. = NULL,
111112
.fds = NULL) {
112113
on_missing <- match.arg(on_missing)
@@ -131,6 +132,7 @@ flm_def.data.frame <- function(x, covariate, numer = NULL, denom = NULL,
131132

132133
out <- list(
133134
# Standard FacileAnalysisResult things
135+
metadata = metadata,
134136
fds = .fds)
135137
class(out) <- c("FacileLinearModelDefinition", "FacileAnalysisResult")
136138
clazz <- "IncompleteModelDefintion"
@@ -333,15 +335,16 @@ flm_def.data.frame <- function(x, covariate, numer = NULL, denom = NULL,
333335
#' @importFrom FacileViz unselected
334336
flm_def.tbl <- function(x, covariate, numer = NULL, denom = NULL,
335337
batch = NULL, block = NULL,
336-
on_missing = c("warning", "error"), ...) {
338+
on_missing = c("warning", "error"), ...,
339+
metadata = list()) {
337340
x <- collect(x, n = Inf)
338341
if (unselected(numer)) numer <- NULL
339342
if (unselected(denom)) denom <- NULL
340343
if (unselected(batch)) batch <- NULL
341344

342345
flm_def.data.frame(x, covariate = covariate, numer = numer,
343346
denom = denom, batch = batch, block = block,
344-
on_missing = on_missing, ...)
347+
on_missing = on_missing, metadata = metadata, ...)
345348
}
346349

347350
#' @section facile_frame:
@@ -361,6 +364,7 @@ flm_def.tbl <- function(x, covariate, numer = NULL, denom = NULL,
361364
flm_def.facile_frame <- function(x, covariate, numer = NULL, denom = NULL,
362365
batch = NULL, block = NULL,
363366
on_missing = c("warning", "error"), ...,
367+
metadata = list(),
364368
custom_key = NULL) {
365369
.fds <- assert_class(fds(x), "FacileDataStore")
366370
assert_sample_subset(x)
@@ -389,7 +393,8 @@ flm_def.facile_frame <- function(x, covariate, numer = NULL, denom = NULL,
389393

390394
out <- flm_def.data.frame(x, covariate = covariate, numer = numer,
391395
denom = denom, batch = batch, block = block,
392-
on_missing = on_missing, .fds = .fds, ...)
396+
on_missing = on_missing, .fds = .fds,
397+
metadata = metadata, ...)
393398
out
394399
}
395400

@@ -399,7 +404,8 @@ flm_def.facile_frame <- function(x, covariate, numer = NULL, denom = NULL,
399404
flm_def.FacileDataStore <- function(x, covariate, numer = NULL, denom = NULL,
400405
batch = NULL, block = NULL,
401406
on_missing = c("warning", "error"),
402-
..., samples = NULL, custom_key = NULL) {
407+
..., metadata = list(),
408+
samples = NULL, custom_key = NULL) {
403409
if (is.null(samples)) samples <- samples(x)
404410
samples <- collect(samples, n = Inf)
405411

@@ -410,7 +416,7 @@ flm_def.FacileDataStore <- function(x, covariate, numer = NULL, denom = NULL,
410416

411417
flm_def(samples, covariate = covariate, numer = numer, denom = denom,
412418
batch = batch, block = block, on_missing = on_missing,
413-
custom_key = custom_key, ...)
419+
custom_key = custom_key, metadata = metadata, ...)
414420
}
415421

416422
# redo =========================================================================

R/fpca-base.R

+9-6
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
fpca <- function(x, assay_name = NULL, dims = 5, features = NULL,
134134
filter = "variance", ntop = 1000, row_covariates = NULL,
135135
col_covariates = NULL,
136-
batch = NULL, main = NULL, ...) {
136+
batch = NULL, main = NULL, ..., metadata = list()) {
137137
UseMethod("fpca", x)
138138
}
139139

@@ -145,15 +145,16 @@ fpca.FacileDataStore <- function(x, assay_name = NULL, dims = 5,
145145
row_covariates = NULL,
146146
col_covariates = NULL, batch = NULL,
147147
main = NULL, custom_key = Sys.getenv("USER"),
148-
..., samples = NULL) {
148+
..., samples = NULL, metadata = list()) {
149149
assert_int(dims, lower = 3L) # TODO: max = min(dim(x, assay_name = ??))
150150
if (is.null(samples)) samples <- samples(x)
151151
samples <- collect(samples, n = Inf)
152152
if (!is.null(features) && missing(filter)) {
153153
filter <- "none"
154154
}
155155
fpca(samples, assay_name, dims, features, filter, ntop,
156-
row_covariates, col_covariates, batch, main, custom_key, ...)
156+
row_covariates, col_covariates, batch, main, custom_key,
157+
metadata = metadata, ...)
157158
}
158159

159160
#' @section FacileDataStore (facile_frame):
@@ -171,7 +172,8 @@ fpca.facile_frame <- function(x, assay_name = NULL,
171172
features = NULL, filter = "variance", ntop = 1000,
172173
row_covariates = NULL,
173174
col_covariates = NULL, batch = NULL, main = NULL,
174-
custom_key = Sys.getenv("USER"), ...) {
175+
custom_key = Sys.getenv("USER"), ...,
176+
metadata = list()) {
175177
assert_int(dims, lower = 3L) # TODO: max = min(dim(x, assay_name = ??))
176178
.fds <- assert_class(fds(x), "FacileDataStore")
177179
assert_sample_subset(x)
@@ -224,7 +226,7 @@ fpca.facile_frame <- function(x, assay_name = NULL,
224226
out <- fpca(dat[["assay_data"]], dims, features, filter, ntop,
225227
row_covariates = dat[["features"]],
226228
col_covariates = dat[["samples"]],
227-
batch = batch, main = main, ...)
229+
batch = batch, main = main, metadata = metadata, ...)
228230

229231
out[["params"]][["assay_name"]] <- assay_name
230232
if (!is.null(batch)) out[["params"]][["batch"]] <- batch
@@ -265,7 +267,7 @@ fpca.matrix <- function(x, dims = min(5, ncol(x) - 1L), features = NULL,
265267
filter = "default", ntop = 1000,
266268
row_covariates = NULL, col_covariates = NULL,
267269
batch = NULL, main = NULL, use_irlba = dims < 7,
268-
center = TRUE, scale. = FALSE, ...) {
270+
center = TRUE, scale. = FALSE, ..., metadata = list()) {
269271
messages <- character()
270272
warnings <- character()
271273
errors <- character()
@@ -396,6 +398,7 @@ fpca.matrix <- function(x, dims = min(5, ncol(x) - 1L), features = NULL,
396398
use_irlba = use_irlba,
397399
batch = batch, main = main,
398400
center = center, scale. = scale.),
401+
metadata = metadata,
399402
messages = messages,
400403
warnings = warnings,
401404
errors = errors)

man/fdge.Rd

+18-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ffsea.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)