-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GridEven and GridManual (#303)
- Loading branch information
Showing
19 changed files
with
415 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
|
||
#' @include Grid.R | ||
#' @include generics.R | ||
NULL | ||
|
||
|
||
#' @rdname Grid-Dev | ||
.GridEven <- setClass( | ||
"GridEven", | ||
contains = "Grid", | ||
slots = c( | ||
"subjects" = "character", | ||
"length.out" = "numeric" | ||
) | ||
) | ||
|
||
|
||
#' @rdname Grid-Functions | ||
#' @export | ||
GridEven <- function(subjects = NULL, length.out = 30) { | ||
.GridEven( | ||
subjects = subjects, | ||
length.out = length.out | ||
) | ||
} | ||
|
||
|
||
setValidity( | ||
"GridEven", | ||
function(object) { | ||
if (length(object@length.out) != 1 || all(object@length.out <= 0)) { | ||
return("The `length.out` argument must be a positive integer") | ||
} | ||
} | ||
) | ||
|
||
|
||
#' @rdname Quant-Dev | ||
#' @export | ||
as.QuantityGenerator.GridEven <- function(object, data, ...) { | ||
assert_class(data, "DataJoint") | ||
data_list <- as.list(data) | ||
subjects <- unlist(as.list(object, data = data), use.names = FALSE) | ||
assert_that( | ||
all(subjects %in% names(data_list$subject_to_index)), | ||
msg = "All subject names must be in the `DataSubject` object" | ||
) | ||
|
||
spec <- lapply( | ||
subjects, | ||
\(sub) { | ||
subject_index <- data_list$subject_to_index[[sub]] | ||
time_index <- data_list$subject_tumour_index == subject_index | ||
subject_times <- data_list$tumour_time[time_index] | ||
seq(min(subject_times), max(subject_times), length.out = object@length.out) | ||
} | ||
) | ||
names(spec) <- subjects | ||
|
||
as.QuantityGenerator( | ||
GridManual(spec), | ||
data = data | ||
) | ||
} | ||
|
||
|
||
#' @rdname Quant-Dev | ||
#' @export | ||
as.QuantityCollapser.GridEven <- function(object, data, ...) { | ||
generator <- as.QuantityGenerator(object, data) | ||
QuantityCollapser( | ||
times = generator@times, | ||
groups = generator@subjects, | ||
indexes = as.list(seq_along(generator@times)) | ||
) | ||
} | ||
|
||
|
||
#' @export | ||
as.list.GridEven <- function(x, data, ...) { | ||
subjects_to_list(x@subjects, data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
|
||
#' @include Grid.R | ||
#' @include generics.R | ||
NULL | ||
|
||
|
||
#' @rdname Grid-Dev | ||
.GridManual <- setClass( | ||
"GridManual", | ||
contains = "Grid", | ||
slots = c( | ||
"spec" = "list" | ||
) | ||
) | ||
|
||
|
||
#' @rdname Grid-Functions | ||
#' @export | ||
GridManual <- function(spec) { | ||
.GridManual( | ||
spec = spec | ||
) | ||
} | ||
|
||
|
||
setValidity( | ||
"GridManual", | ||
function(object) { | ||
subject_names <- names(object@spec) | ||
subject_names_valid <- subject_names[!is.na(subject_names) & subject_names != ""] | ||
if (length(subject_names_valid) != length(object@spec)) { | ||
return("Each element of `subjects` must be named") | ||
} | ||
for (times in object@spec) { | ||
if (!is.numeric(times)) { | ||
return("Each element of `spec` must be a numeric vector") | ||
} | ||
if (length(times) != length(unique(times))) { | ||
return("Each time vector per subject must be unique") | ||
} | ||
} | ||
return(TRUE) | ||
} | ||
) | ||
|
||
|
||
#' @rdname Quant-Dev | ||
#' @export | ||
as.QuantityGenerator.GridManual <- function(object, data, ...) { | ||
assert_class(data, "DataJoint") | ||
data_list <- as.list(data) | ||
assert_that( | ||
all(names(object@spec) %in% names(data_list$subject_to_index)), | ||
msg = "All subject names must be in the `DataSubject` object" | ||
) | ||
lens <- vapply(object@spec, length, numeric(1)) | ||
.QuantityGenerator( | ||
times = unlist(object@spec, use.names = FALSE), | ||
subjects = rep(names(object@spec), lens) | ||
) | ||
} | ||
|
||
|
||
#' @rdname Quant-Dev | ||
#' @export | ||
as.QuantityCollapser.GridManual <- function(object, data, ...) { | ||
generator <- as.QuantityGenerator(object, data) | ||
QuantityCollapser( | ||
times = generator@times, | ||
groups = generator@subjects, | ||
indexes = as.list(seq_along(generator@times)) | ||
) | ||
} | ||
|
||
|
||
#' @export | ||
as.list.GridManual <- function(x, data, ...) { | ||
subs <- as.list(names(x@spec)) | ||
names(subs) <- names(x@spec) | ||
subs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.