diff --git a/DESCRIPTION b/DESCRIPTION index b44ba90..ea99a99 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: readthis Title: Read results from misc genomic tools -Version: 0.5.0 +Version: 0.6.0 Authors@R: person("Paweł", "Kuś", , "kpawel2210@gmail.com", role = c("aut", "cre")) Description: This package is for reading output files of: variant callers, diff --git a/NAMESPACE b/NAMESPACE index d9484ec..7eb2dc3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,7 +4,7 @@ export(read_ascat_files) export(read_clip_all) export(read_clip_all_wide) export(read_clip_best_lambda) -export(read_facets_cnvs) +export(read_facets_cnas) export(read_mutect_snvs) export(read_strelka_somatic_snvs) import(dplyr) diff --git a/NEWS.md b/NEWS.md index 700d476..fd25482 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +# readthis 0.6.0 +* Naming convention changed from CNVs to CNAs + # readthis 0.5.0 * Reading ASCAT SNVs diff --git a/R/ascat.R b/R/ascat.R index 17bd44a..aa76730 100644 --- a/R/ascat.R +++ b/R/ascat.R @@ -1,13 +1,13 @@ ## ------------------------------- Export -------------------------------------- -#' Read ASCAT CNV calls +#' Read ASCAT CNA calls #' -#' Reads the CNV variant calls and sample statistics from -#' [ASCAT](https://github.com/VanLoo-lab/ascat) CNV caller +#' Reads the CNA variant calls and sample statistics from +#' [ASCAT](https://github.com/VanLoo-lab/ascat) CNA caller #' #' @param path Can be either: -#' 1) path to a single csv file with ASCAT CNV calls -#' 2) tibble with sample_id, cnvs, and (optionally) sample_statistics columns +#' 1) path to a single csv file with ASCAT CNA calls +#' 2) tibble with sample_id, cnas, and (optionally) sample_statistics columns #' containing sample_ids and paths. #' 3) directory containing multiple ASCAT files with "*.csv" and #' "*.samplestatistics.*" names. @@ -62,7 +62,7 @@ read_ascat_files <- function(path, ascat <- read_ascat_files_from_dir(path, sample_id_pattern) } - ascat$cnvs <- use_chrom_naming_convention(ascat$cnvs, chrom_convention) + ascat$cnas <- use_chrom_naming_convention(ascat$cnas, chrom_convention) structure(ascat, class = c("cevo_ASCAT")) } @@ -70,7 +70,7 @@ read_ascat_files <- function(path, ## ----------------------- Higher level functions ----------------------------- read_ascat_files_single <- function(path, sample_statistics, sample_id) { - cnvs <- read_ascat_cnvs(path) |> + cnas <- read_ascat_cnas(path) |> mutate(sample_id = sample_id, .before = "chrom") if (!is.null(sample_statistics) && is_single_file(sample_statistics)) { stats <- read_ascat_samplestatistics(sample_statistics) |> @@ -78,16 +78,16 @@ read_ascat_files_single <- function(path, sample_statistics, sample_id) { } else { stats <- empty_ascat_samplestatistics() } - lst(cnvs, sample_statistics = stats) + lst(cnas, sample_statistics = stats) } read_ascat_files_from_dataframe <- function(path) { - cnvs <- path |> + cnas <- path |> select("sample_id", "csv") |> deframe() |> - map(read_ascat_cnvs) |> + map(read_ascat_cnas) |> bind_rows(.id = "sample_id") if (is.null(path[["sample_statistics"]])) { stats <- empty_ascat_samplestatistics() @@ -99,29 +99,29 @@ read_ascat_files_from_dataframe <- function(path) { map(read_ascat_samplestatistics) |> bind_rows(.id = "sample_id") } - lst(cnvs, sample_statistics = stats) + lst(cnas, sample_statistics = stats) } read_ascat_files_from_dir <- function(path, sample_id_pattern) { csv_files <- get_files(path, ".csv", sample_id_pattern) - cnvs <- csv_files |> - map(read_ascat_cnvs) |> + cnas <- csv_files |> + map(read_ascat_cnas) |> bind_rows(.id = "sample_id") stat_files <- get_files(path, "samplestatistics", sample_id_pattern) stats <- stat_files |> map(read_ascat_samplestatistics) |> bind_rows(.id = "sample_id") - lst(cnvs, sample_statistics = stats) + lst(cnas, sample_statistics = stats) } ## --------------------------- Base functions ---------------------------------- -read_ascat_cnvs <- function(path) { +read_ascat_cnas <- function(path) { csv_cols <- c("i", "chrom", "start", "end", "normal_cn_total", "normal_cn_minor", "total_cn", "minor_cn") - cnvs <- read_csv(path, col_names = csv_cols, col_types = "dcdddddd") |> + cnas <- read_csv(path, col_names = csv_cols, col_types = "dcdddddd") |> mutate(major_cn = .data$total_cn - .data$minor_cn) |> select( "chrom", "start", "end", @@ -129,7 +129,7 @@ read_ascat_cnvs <- function(path) { normal_cn = "normal_cn_total" ) - cnvs + cnas } diff --git a/R/facets.R b/R/facets.R index cc1d4a5..57071d5 100644 --- a/R/facets.R +++ b/R/facets.R @@ -1,9 +1,9 @@ ## ------------------------------- Export -------------------------------------- -#' Read FACETS CNV calls +#' Read FACETS CNA calls #' #' Reads the variant calls from [FACETS](https://github.com/mskcc/facets/tree/master) -#' CNV caller +#' CNA caller #' #' @param path Can be either: #' 1) path to a single file, sample ID can be passed using sample_id argument @@ -17,14 +17,14 @@ #' library(readthis) #' #' file1 <- system.file("extdata", "FACETS", "S1.csv", package = "readthis") -#' read_facets_cnvs(file1) +#' read_facets_cnas(file1) #' #' file2 <- system.file("extdata", "FACETS", "S2.csv", package = "readthis") #' files <- c(S1 = file1, S2 = file2) -#' read_facets_cnvs(files) +#' read_facets_cnas(files) #' #' dir <- system.file("extdata", "FACETS", package = "readthis") -#' read_facets_cnvs(dir) +#' read_facets_cnas(dir) #' #' @name facets NULL @@ -35,14 +35,14 @@ NULL #' read_facets_csv() reads a single csv file. If sample_id is not provided, #' file path is used #' @export -read_facets_cnvs <- function(path, +read_facets_cnas <- function(path, sample_id = path, chrom_convention = "UCSC") { if (is_single_file(path)) { - cnvs <- read_facets_csv(path) |> + cnas <- read_facets_csv(path) |> mutate(sample_id = sample_id, .before = "chrom") } else if (is_list_of_files(path)) { - cnvs <- map(path, read_facets_csv) |> + cnas <- map(path, read_facets_csv) |> bind_rows(.id = "sample_id") } else if (is_single_dir(path)) { files <- list.files(path, full.names = TRUE) @@ -51,13 +51,13 @@ read_facets_cnvs <- function(path, map_chr(last) |> str_replace(".csv", "") names(files) <- sample_ids - cnvs <- files |> + cnas <- files |> set_names(sample_ids) |> map(read_facets_csv) |> bind_rows(.id = "sample_id") } - cnvs |> + cnas |> use_chrom_naming_convention(chrom_convention) } @@ -66,10 +66,10 @@ read_facets_cnvs <- function(path, read_facets_csv <- function(file, chrom_convention = "UCSC") { - cnvs <- read_csv(file, col_types = "cddddddddiidiidd") |> + cnas <- read_csv(file, col_types = "cddddddddiidiidd") |> prepare_FACETS_columns() - class(cnvs) <- c("cevo_FACETS", class(cnvs)) - cnvs + class(cnas) <- c("cevo_FACETS", class(cnas)) + cnas } diff --git a/README.md b/README.md index 77ade32..e9e71d5 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ devtools::install_github("pawelqs/readthis") - [Strelka2](https://github.com/Illumina/strelka) (somatic SNVs only): `read_strelka_somatic_snvs()` - [Mutect2](https://github.com/Illumina/strelka) SNVs: `read_mutect_snvs()` -- [FACETS](https://github.com/mskcc/facets) CNVs: `read_facets_cnvs()` -- [ASCAT](https://github.com/VanLoo-lab/ascat) CNVs: `read_ascat_files()` (does not work with all the files) +- [FACETS](https://github.com/mskcc/facets) CNAs: `read_facets_cnas()` +- [ASCAT](https://github.com/VanLoo-lab/ascat) CNAs: `read_ascat_files()` (does not work with all the files) **Other tools:** diff --git a/man/facets.Rd b/man/facets.Rd index f632ca2..f064417 100644 --- a/man/facets.Rd +++ b/man/facets.Rd @@ -2,10 +2,10 @@ % Please edit documentation in R/facets.R \name{facets} \alias{facets} -\alias{read_facets_cnvs} -\title{Read FACETS CNV calls} +\alias{read_facets_cnas} +\title{Read FACETS CNA calls} \usage{ -read_facets_cnvs(path, sample_id = path, chrom_convention = "UCSC") +read_facets_cnas(path, sample_id = path, chrom_convention = "UCSC") } \arguments{ \item{path}{Can be either: @@ -22,7 +22,7 @@ guessed from the file names } \description{ Reads the variant calls from \href{https://github.com/mskcc/facets/tree/master}{FACETS} -CNV caller +CNA caller } \details{ read_facets_csv() reads a single csv file. If sample_id is not provided, @@ -32,13 +32,13 @@ file path is used library(readthis) file1 <- system.file("extdata", "FACETS", "S1.csv", package = "readthis") -read_facets_cnvs(file1) +read_facets_cnas(file1) file2 <- system.file("extdata", "FACETS", "S2.csv", package = "readthis") files <- c(S1 = file1, S2 = file2) -read_facets_cnvs(files) +read_facets_cnas(files) dir <- system.file("extdata", "FACETS", package = "readthis") -read_facets_cnvs(dir) +read_facets_cnas(dir) } diff --git a/man/read_ascat_files.Rd b/man/read_ascat_files.Rd index 7b67d86..9d3425d 100644 --- a/man/read_ascat_files.Rd +++ b/man/read_ascat_files.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/ascat.R \name{read_ascat_files} \alias{read_ascat_files} -\title{Read ASCAT CNV calls} +\title{Read ASCAT CNA calls} \usage{ read_ascat_files( path, @@ -15,8 +15,8 @@ read_ascat_files( \arguments{ \item{path}{Can be either: \enumerate{ -\item path to a single csv file with ASCAT CNV calls -\item tibble with sample_id, cnvs, and (optionally) sample_statistics columns +\item path to a single csv file with ASCAT CNA calls +\item tibble with sample_id, cnas, and (optionally) sample_statistics columns containing sample_ids and paths. \item directory containing multiple ASCAT files with "\emph{.csv" and "}.samplestatistics.*" names. @@ -38,8 +38,8 @@ when path is a directory} \item{chrom_convention}{UCSC/NCBI/keep} } \description{ -Reads the CNV variant calls and sample statistics from -\href{https://github.com/VanLoo-lab/ascat}{ASCAT} CNV caller +Reads the CNA variant calls and sample statistics from +\href{https://github.com/VanLoo-lab/ascat}{ASCAT} CNA caller } \examples{ library(readthis) diff --git a/tests/testthat/test-ascat.R b/tests/testthat/test-ascat.R index 21549bb..2a53fd5 100644 --- a/tests/testthat/test-ascat.R +++ b/tests/testthat/test-ascat.R @@ -1,6 +1,6 @@ test_that("read_ascat_csv() works", { path <- test_path("ASCAT", "S1.csv") - res <- read_ascat_cnvs(path) + res <- read_ascat_cnas(path) expect_s3_class(res, "tbl") expect_equal(dim(res), c(10, 7)) }) @@ -17,24 +17,24 @@ test_that("read_ascat_samplestatistics() works", { -test_that("read_ascat_files() works with cnvs only", { +test_that("read_ascat_files() works with cnas only", { path <- test_path("ASCAT", "S1.csv") res <- read_ascat_files(path) expect_s3_class(res, "cevo_ASCAT") - expect_equal(dim(res$cnvs), c(10, 8)) - expect_equal(unique(res$cnvs$sample_id), test_path("ASCAT", "S1.csv")) + expect_equal(dim(res$cnas), c(10, 8)) + expect_equal(unique(res$cnas$sample_id), test_path("ASCAT", "S1.csv")) }) -test_that("read_ascat_files() works with cnvs and sample statistics", { +test_that("read_ascat_files() works with cnas and sample statistics", { path <- test_path("ASCAT", "S1.csv") sample_statistics <- test_path("ASCAT", "S1.samplestatistics.txt") res <- read_ascat_files(path, sample_statistics) expect_s3_class(res, "cevo_ASCAT") - expect_equal(dim(res$cnvs), c(10, 8)) + expect_equal(dim(res$cnas), c(10, 8)) expect_equal(dim(res$sample_statistics), c(1, 8)) - expect_equal(unique(res$cnvs$sample_id), test_path("ASCAT", "S1.csv")) + expect_equal(unique(res$cnas$sample_id), test_path("ASCAT", "S1.csv")) expect_equal(unique(res$sample_statistics$sample_id), test_path("ASCAT", "S1.csv")) }) @@ -50,7 +50,7 @@ test_that("read_ascat_files() works with tibble of files", { ) res <- read_ascat_files(path) expect_s3_class(res, "cevo_ASCAT") - expect_equal(dim(res$cnvs), c(20, 8)) + expect_equal(dim(res$cnas), c(20, 8)) expect_equal(dim(res$sample_statistics), c(2, 8)) expect_equal(unique(res$sample_statistics$sample_id), c("S1", "S2")) }) @@ -67,9 +67,9 @@ test_that("read_ascat_files() works with tibble of files with NAs", { ) res <- read_ascat_files(path) expect_s3_class(res, "cevo_ASCAT") - expect_equal(dim(res$cnvs), c(20, 8)) + expect_equal(dim(res$cnas), c(20, 8)) expect_equal(dim(res$sample_statistics), c(1, 8)) - expect_equal(unique(res$cnvs$sample_id), c("S1", "S2")) + expect_equal(unique(res$cnas$sample_id), c("S1", "S2")) expect_equal(unique(res$sample_statistics$sample_id), "S1") }) @@ -79,7 +79,7 @@ test_that("read_ascat_files() works with directory", { path <- test_path("ASCAT") res <- read_ascat_files(path) expect_s3_class(res, "cevo_ASCAT") - expect_equal(dim(res$cnvs), c(20, 8)) + expect_equal(dim(res$cnas), c(20, 8)) expect_equal(dim(res$sample_statistics), c(2, 8)) expect_equal(unique(res$sample_statistics$sample_id), c("S1", "S2")) }) diff --git a/tests/testthat/test-facets.R b/tests/testthat/test-facets.R index 68bcc34..262ae51 100644 --- a/tests/testthat/test-facets.R +++ b/tests/testthat/test-facets.R @@ -1,26 +1,26 @@ -test_that("read_facets_cnvs() works with single file", { +test_that("read_facets_cnas() works with single file", { path <- test_path("FACETS", "S1.csv") - res <- read_facets_cnvs(path) + res <- read_facets_cnas(path) expect_s3_class(res, "cevo_FACETS") expect_equal(dim(res), c(64, 18)) expect_equal(unique(res$sample_id), path) }) -test_that("read_facets_cnvs() works with dir path file", { +test_that("read_facets_cnas() works with dir path file", { path <- test_path("FACETS") - res <- read_facets_cnvs(path) + res <- read_facets_cnas(path) expect_s3_class(res, "cevo_FACETS") expect_equal(dim(res), c(128, 18)) expect_equal(unique(res$sample_id), c("S1", "S2")) }) -test_that("read_facets_cnvs() works with list of files", { +test_that("read_facets_cnas() works with list of files", { path <- test_path("FACETS") path <- list.files(path, full.names = TRUE) |> set_names(c("S1", "S2")) - res <- read_facets_cnvs(path) + res <- read_facets_cnas(path) expect_s3_class(res, "cevo_FACETS") expect_equal(dim(res), c(128, 18)) expect_equal(unique(res$sample_id), c("S1", "S2"))