-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from pawelqs/develop
Develop
- Loading branch information
Showing
11 changed files
with
314 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: cevomod | ||
Title: Cancer Evolution Models | ||
Version: 2.0.0 | ||
Version: 2.1.0 | ||
Authors@R: | ||
person("Paweł", "Kuś", , "[email protected]", role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0002-4367-9821")) | ||
|
@@ -29,7 +29,8 @@ Suggests: | |
shinyWidgets, | ||
testthat (>= 3.0.0), | ||
tidyverse, | ||
vdiffr | ||
vdiffr, | ||
readthis | ||
Config/testthat/edition: 3 | ||
VignetteBuilder: knitr | ||
Imports: | ||
|
@@ -59,6 +60,7 @@ Depends: | |
R (>= 2.10) | ||
Remotes: | ||
caravagnalab/mobster, | ||
caravagnalab/BMix | ||
caravagnalab/BMix, | ||
pawelqs/readthis | ||
LazyData: true | ||
URL: https://pawelqs.github.io/cevomod/, https://github.com/pawelqs/cevomod |
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,126 @@ | ||
|
||
#' readthis integration | ||
#' | ||
#' @description | ||
#' [readthis](https://github.com/pawelqs/readthis) package may be used to easily | ||
#' read the data from some popular mutation callers into R environment. readthis | ||
#' functions can be supplied not only with the single file paths, but also with | ||
#' lists of files or even paths to the directories with files to be loaded (and | ||
#' cevodata object is to store the data from many samples!) | ||
#' | ||
#' readthis functions return tibbles or list of tibbles. These tibbles/ | ||
#' objects usually are instances of *cevo_<software_name>* S3 classes. cevomod | ||
#' implements methods that allow to add these types of data to the cevodata | ||
#' objects conveniently. | ||
#' | ||
#' @param cd <cevodata> object | ||
#' @param data Object read with readthis functions | ||
#' @param name Name for the data | ||
#' @param verbose Verbose? | ||
#' @param ... Other arguments | ||
#' | ||
#' @examples | ||
#' # library(cevomod) | ||
#' | ||
#' ascat_dir <- system.file("extdata", "ASCAT", package = "readthis") | ||
#' ascat <- readthis::read_ascat_files(ascat_dir) | ||
#' cd <- init_cevodata("Test dataset") |> | ||
#' add_data(ascat) | ||
#' | ||
#' @name readthis-integration | ||
NULL | ||
|
||
|
||
|
||
#' @describeIn readthis-integration add_data() function takes cevodata as the | ||
#' first argument, so it is a preferred method for adding data in R pipelines. | ||
#' @export | ||
add_data <- function(cd, data, ...) { | ||
add_to_cevodata(data, cd) | ||
} | ||
|
||
|
||
#' @describeIn readthis-integration add_to_cevodata() is a generic with a set | ||
#' of methods for different classes of `data`. These methods are called by | ||
#' add_data() function. | ||
#' @export | ||
add_to_cevodata <- function(data, cd, name, verbose, ...) { | ||
UseMethod("add_to_cevodata") | ||
} | ||
|
||
|
||
#' @export | ||
add_to_cevodata.cevo_ASCAT <- function(data, cd, | ||
name = "ASCAT", | ||
verbose = get_cevomod_verbosity(), | ||
...) { | ||
sample_data <- data$sample_statistics |> | ||
mutate(ascat_purity = 1 - .data$normal_contamination) | ||
cd |> | ||
add_CNV_data(data$cnvs, name = name) |> | ||
add_sample_data(sample_data) |> | ||
use_purity("ascat_purity", verbose = verbose) | ||
} | ||
|
||
|
||
#' @export | ||
add_to_cevodata.cevo_FACETS <- function(data, cd, | ||
name = "FACETS", | ||
verbose = get_cevomod_verbosity(), | ||
...) { | ||
cnvs <- data |> | ||
select(-"Purity", -"Ploidy") | ||
sample_data <- data |> | ||
select("sample_id", facets_purity = "Purity", facets_ploidy = "Ploidy") |> | ||
unique() | ||
cd |> | ||
add_CNV_data(data, name = name) |> | ||
add_sample_data(sample_data) |> | ||
use_purity("facets_purity", verbose = verbose) | ||
} | ||
|
||
|
||
#' @export | ||
add_to_cevodata.cevo_Mutect <- function(data, cd, | ||
name = "Mutect", | ||
verbose = get_cevomod_verbosity(), | ||
...) { | ||
patient_ids_present <- "patient_id" %in% names(data) | ||
|
||
if (patient_ids_present) { | ||
sample_data <- data |> | ||
select("patient_id", "sample_id") |> | ||
unique() | ||
data$patient_id <- NULL | ||
} | ||
|
||
cd <- add_SNV_data(cd, data, name = name) | ||
if (patient_ids_present) { | ||
cd <- add_sample_data(cd, sample_data) | ||
} | ||
|
||
cd | ||
} | ||
|
||
|
||
#' @export | ||
add_to_cevodata.cevo_Strelka <- function(data, cd, | ||
name = "Strelka", | ||
verbose = get_cevomod_verbosity(), | ||
...) { | ||
patient_ids_present <- "patient_id" %in% names(data) | ||
|
||
if (patient_ids_present) { | ||
sample_data <- data |> | ||
select("patient_id", "sample_id") |> | ||
unique() | ||
data$patient_id <- NULL | ||
} | ||
|
||
cd <- add_SNV_data(cd, data, name = name) | ||
if (patient_ids_present) { | ||
cd <- add_sample_data(cd, sample_data) | ||
} | ||
|
||
cd | ||
} |
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
test_that("adding ASCAT data works", { | ||
ascat_dir <- system.file("extdata", "ASCAT", package = "readthis") | ||
data <- readthis::read_ascat_files(ascat_dir, sample_id_pattern = "(?<=ASCAT\\/)[:alnum:]*(?=\\.)") | ||
cd <- init_cevodata("Test dataset") |> | ||
add_data(data) | ||
expect_s3_class(cd, "cevodata") | ||
expect_s3_class(CNVs(cd), "tbl") | ||
expect_equal(cd$active_CNVs, "ASCAT") | ||
expect_equal(dim(CNVs(cd)), c(20, 8)) | ||
expect_equal(cd$metadata$purity, c(0.99322, 0.99322)) | ||
expect_equal(cd$metadata$purity, cd$metadata$ascat_purity) | ||
}) | ||
|
||
|
||
|
||
test_that("adding FACETS data works", { | ||
facets_dir <- system.file("extdata", "FACETS", package = "readthis") | ||
data <- readthis::read_facets_cnvs(facets_dir) | ||
cd <- init_cevodata("Test dataset") |> | ||
add_data(data) | ||
expect_s3_class(cd, "cevodata") | ||
expect_s3_class(CNVs(cd), "tbl") | ||
expect_equal(cd$active_CNVs, "FACETS") | ||
expect_equal(dim(CNVs(cd)), c(128, 18)) | ||
expect_equal(cd$metadata$purity, c(0.3, 0.3)) | ||
expect_equal(cd$metadata$purity, cd$metadata$facets_purity) | ||
}) | ||
|
||
|
||
|
||
test_that("adding Mutect2 data works", { | ||
path <- system.file("extdata", "Mutect", package = "readthis") | ||
data <- readthis::read_mutect_snvs( | ||
path, | ||
patient_id_pattern = "(?<=Mutect\\/)[:alnum:]*(?=\\.)", | ||
verbose = FALSE | ||
) | ||
cd <- init_cevodata("Test dataset") |> | ||
add_data(data) | ||
expect_s3_class(cd, "cevodata") | ||
expect_s3_class(SNVs(cd), "tbl") | ||
expect_equal(cd$active_SNVs, "Mutect") | ||
expect_equal(dim(SNVs(cd)), c(16, 14)) | ||
expect_equal(cd$metadata$sample_id, c("S1_L1", "S1_P1", "S2_L1", "S2_P1")) | ||
expect_equal(cd$metadata$patient_id, c("S1", "S1", "S2", "S2")) | ||
}) | ||
|
||
|
||
|
||
test_that("adding Strelka data works", { | ||
path <- system.file("extdata", "Strelka", package = "readthis") | ||
data <- readthis::read_strelka_somatic_snvs( | ||
path, | ||
patient_id_pattern = "(?<=Strelka\\/)[:alnum:]*(?=\\.)", | ||
verbose = FALSE | ||
) |> | ||
mutate(sample_id = str_c(patient_id, sample_id, sep = "_")) | ||
cd <- init_cevodata("Test dataset") |> | ||
add_data(data) | ||
expect_s3_class(cd, "cevodata") | ||
expect_s3_class(SNVs(cd), "tbl") | ||
expect_equal(cd$active_SNVs, "Strelka") | ||
expect_equal(dim(SNVs(cd)), c(18, 11)) | ||
expect_equal(cd$metadata$sample_id, c("S1_TUMOR", "S2_TUMOR")) | ||
}) |
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