-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- new `getSomaScanVersion()` and `checkSomaScanVersion()` functions - reorganized docs to merge with `getAdatVersion()` - getAdatVersion()` now takes the full attributes as its input, rather than `x$Header.Meta` - updated documentation - fixes #83
- Loading branch information
Showing
9 changed files
with
191 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#' Helpers to Extract Information from an ADAT | ||
#' | ||
#' [getAdatVersion()] determines the the ADAT version | ||
#' number from a parsed ADAT header.\cr\cr | ||
#' [getSomaScanVersion()] determines the version of | ||
#' SomaScan assay that a `soma_adat` object was run on. | ||
#' These are elements of the `HEADER` attributes of the object.\cr\cr | ||
#' [checkSomaScanVersion()] determines if the version of | ||
#' is a recognized version of SomaScan.\cr | ||
#' \cr | ||
#' Table of current SomaScan Assay versions: | ||
#' \tabular{lll}{ | ||
#' **Version** \tab **Name** \tab **Size** \cr | ||
#' `V4` \tab 5k \tab 5284 \cr | ||
#' `v4.1` \tab 7k \tab 7596 \cr | ||
#' `v5.0` \tab 11k \tab 11083 \cr | ||
#' } | ||
#' | ||
#' @name adat-helpers | ||
#' @param atts The *attributes* of a `soma_adat` object. | ||
#' @return Either a character string of length 1, or `NULL`. | ||
#' \item{[getAdatVersion()]}{The key-value of the `Version` as a string.} | ||
#' \item{[getSomaScanVersion()]}{The key-value of the `AssayVersion` as a string.} | ||
#' \item{[checkSomaScanVersion()]}{Returns `NULL` (invisibly) if checks pass.} | ||
#' @author Stu Field | ||
#' @examples | ||
#' atts <- attributes(example_data) | ||
#' getAdatVersion(atts) | ||
#' | ||
#' atts$Header.Meta$HEADER$Version <- "1.0" | ||
#' getAdatVersion(atts) | ||
#' @export | ||
getAdatVersion <- function(atts) { | ||
|
||
x <- atts$Header.Meta$HEADER | ||
vidx <- grep("^Version$|^AdatVersion$", names(x)) | ||
|
||
if ( length(vidx) == 0L ) { | ||
stop( | ||
"Unable to identify ADAT Version from Header information. ", | ||
"Please check 'Header.Meta'.", call. = FALSE | ||
) | ||
} | ||
|
||
version <- as.character(x[[vidx]]) | ||
|
||
if ( length(version) > 1L ) { | ||
warning( | ||
"Version length > 1 ... there may be empty tabs in ", | ||
"the header block above the data matrix.", call. = FALSE | ||
) | ||
version <- version[1L] | ||
} | ||
|
||
if ( identical(version, "1.01") ) { | ||
stop( | ||
"Invalid Version (", .value("1.01"), "). Please modify to `1.0.1`.", | ||
call. = FALSE | ||
) | ||
} | ||
version | ||
} | ||
|
||
|
||
.ss_ver_map <- c(v3 = "1129", v3.0 = "1129", | ||
v4 = "5k", v4.0 = "5k", | ||
v4.1 = "7k", | ||
v5 = "11k", v5.0 = "11k") | ||
|
||
|
||
#' Gets the SomaScan version | ||
#' | ||
#' @rdname adat-helpers | ||
#' @inheritParams is_intact_attr | ||
#' @examples | ||
#' | ||
#' ver <- getSomaScanVersion(example_data) | ||
#' ver | ||
#' @export | ||
getSomaScanVersion <- function(adat) { | ||
as.character(attr(adat, "Header.Meta")$HEADER$AssayVersion) | ||
} | ||
|
||
|
||
#' Checks the SomaScan version | ||
#' | ||
#' @rdname adat-helpers | ||
#' @param ver `character(1)`. The SomaScan version as a string. | ||
#' @note The `"v"` is case insensitive. | ||
#' @examples | ||
#' | ||
#' is.null(checkSomaScanVersion(ver)) | ||
#' @export | ||
checkSomaScanVersion <- function(ver) { | ||
allowed <- c("v3.0", "v4", "v4.0", "v4.1", "v5", "v5.0") | ||
if ( !tolower(ver) %in% allowed ) { | ||
stop("Unsupported assay version: ", .value(ver), | ||
". Supported versions: ", .value(allowed), call. = FALSE) | ||
} | ||
invisible(NULL) | ||
} |
This file was deleted.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
|
||
test_that("`getSomaScanVersion()` returns the ADAT version string", { | ||
expect_equal(getSomaScanVersion(example_data), "V4") | ||
}) | ||
|
||
test_that("`checkSomaScanVersion()` returns the correct error mode", { | ||
expect_null(checkSomaScanVersion("V4")) | ||
expect_null(checkSomaScanVersion("v4")) | ||
expect_null(checkSomaScanVersion("v4.1")) | ||
expect_null(checkSomaScanVersion("v5.0")) | ||
expect_null(checkSomaScanVersion("v5")) | ||
expect_error(checkSomaScanVersion("V2"), "Unsupported") | ||
expect_error(checkSomaScanVersion("foo"), "Unsupported") | ||
}) |