From b875faca0bc062ba374f91b51ac8d9f42e096a62 Mon Sep 17 00:00:00 2001 From: pdiakumis Date: Tue, 28 Nov 2023 20:44:36 +1100 Subject: [PATCH] cttso: support CopyNumberVariants.vcf.gz --- NAMESPACE | 1 + R/regex.R | 4 +- R/tso.R | 50 +++++++++++++- man/TsoCopyNumberVariantsVcfFile.Rd | 101 ++++++++++++++++++++++++++++ 4 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 man/TsoCopyNumberVariantsVcfFile.Rd diff --git a/NAMESPACE b/NAMESPACE index e0816bd..5ba32c8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,6 +14,7 @@ export(PloidyEstimationMetricsFile) export(ReplayFile) export(TimeMetricsFile) export(TsoAlignCollapseFusionCallerMetricsFile) +export(TsoCopyNumberVariantsVcfFile) export(TsoFragmentLengthHistFile) export(TsoFusionsCsvFile) export(TsoMergedSmallVariantsVcfFile) diff --git a/R/regex.R b/R/regex.R index 698ffed..2219242 100644 --- a/R/regex.R +++ b/R/regex.R @@ -40,6 +40,8 @@ DR_FILE_REGEX <- tibble::tribble( "SampleAnalysisResults\\.json\\.gz$", "TsoSampleAnalysisResultsFile", "MergedSmallVariants\\.vcf\\.gz$", "TsoMergedSmallVariantsVcfFile", "MergedSmallVariants\\.vcf\\.gz\\.tbi$", "TsoMergedSmallVariantsVcfIndexFile", + "CopyNumberVariants\\.vcf\\.gz$", "TsoCopyNumberVariantsVcfFile", + "CopyNumberVariants\\.vcf\\.gz\\.tbi$", "TsoCopyNumberVariantsVcfIndexFile", "fastqc_metrics\\.csv$", "NULL", "insert-stats\\.tab$", "NULL", "sv_metrics\\.csv$", "NULL", @@ -65,7 +67,7 @@ DR_FILE_REGEX <- tibble::tribble( "-qc_summary\\.tsv\\.gz$", "UmQcSumFile" ) -FILES_DOWNLOAD_BUT_IGNORE <- c("TsoMergedSmallVariantsVcfIndexFile") +FILES_DOWNLOAD_BUT_IGNORE <- c("TsoMergedSmallVariantsVcfIndexFile", "TsoMergedSmallVariantsVcfIndexFile") #' Evaluate dracarys Function #' diff --git a/R/tso.R b/R/tso.R index a5300e1..6167365 100644 --- a/R/tso.R +++ b/R/tso.R @@ -1,3 +1,47 @@ +#' TsoCopyNumberVariantsVcfFile R6 Class +#' +#' @description +#' Contains methods for reading and displaying contents of the +#' `CopyNumberVariants.vcf.gz` file output from TSO. +#' +#' @examples +#' \dontrun{ +#' x <- normalizePath("~/icav1/g/production/analysis_data/SBJ00704/tso_ctdna_tumor_only/202311242b9666e0/L2301411/Results/PTC_ctTSO231120_L2301411/dracarys_gds_sync/PTC_ctTSO231120_L2301411_CopyNumberVariants.vcf.gz") +#' d <- TsoCopyNumberVariantsVcfFile$new(x) +#' d_parsed <- d$read() # or read(d) +#' d$write(d_parsed, out_dir = tempdir(), prefix = "sample705", out_format = "tsv") +#' d$write(d_parsed, prefix = "FOO", out_format = "delta", drid = "wfr.123") +#' } +#' @export +TsoCopyNumberVariantsVcfFile <- R6::R6Class( + "TsoCopyNumberVariantsVcfFile", + inherit = File, + public = list( + #' @description + #' Reads the `CopyNumberVariants.vcf.gz` file output from TSO. + #' + #' @return tibble with variants. + read = function() { + x <- self$path + bcftools_parse_vcf(x, only_pass = TRUE) + }, + #' @description + #' Writes a tidy version of the `CopyNumberVariants.vcf.gz` file output from TSO. + #' + #' @param d Parsed object from `self$read()`. + #' @param prefix Prefix of output file(s). + #' @param out_dir Output directory. + #' @param out_format Format of output file(s). + #' @param drid dracarys ID to use for the dataset (e.g. `wfrid.123`, `prid.456`). + write = function(d, out_dir = NULL, prefix, out_format = "tsv", drid = NULL) { + if (!is.null(out_dir)) { + prefix <- file.path(out_dir, prefix) + } + # prefix2 <- glue("{prefix}copynumber_variants") + write_dracarys(obj = d, prefix = prefix, out_format = out_format, drid = drid) + } + ) +) #' TsoMergedSmallVariantsVcfFile R6 Class #' #' @description @@ -367,7 +411,11 @@ TsoFusionsCsvFile <- R6::R6Class( BP2_Depth = "d", Total_Depth = "d", VAF = "d", Gene1 = "c", Gene2 = "c", Contig = "c", Filter = "c", Is_Cosmic_GenePair = "l" ) - readr::read_csv(x, col_types = ct, comment = "#") + res <- readr::read_csv(x, col_types = ct, comment = "#") + if (nrow(res) == 0) { + return(empty_tbl(cnames = names(ct))) + } + return(res) }, #' @description diff --git a/man/TsoCopyNumberVariantsVcfFile.Rd b/man/TsoCopyNumberVariantsVcfFile.Rd new file mode 100644 index 0000000..49d12e2 --- /dev/null +++ b/man/TsoCopyNumberVariantsVcfFile.Rd @@ -0,0 +1,101 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tso.R +\name{TsoCopyNumberVariantsVcfFile} +\alias{TsoCopyNumberVariantsVcfFile} +\title{TsoCopyNumberVariantsVcfFile R6 Class} +\description{ +Contains methods for reading and displaying contents of the +\code{CopyNumberVariants.vcf.gz} file output from TSO. +} +\examples{ +\dontrun{ +x <- normalizePath("~/icav1/g/production/analysis_data/SBJ00704/tso_ctdna_tumor_only/202311242b9666e0/L2301411/Results/PTC_ctTSO231120_L2301411/dracarys_gds_sync/PTC_ctTSO231120_L2301411_CopyNumberVariants.vcf.gz") +d <- TsoCopyNumberVariantsVcfFile$new(x) +d_parsed <- d$read() # or read(d) +d$write(d_parsed, out_dir = tempdir(), prefix = "sample705", out_format = "tsv") +d$write(d_parsed, prefix = "FOO", out_format = "delta", drid = "wfr.123") +} +} +\section{Super class}{ +\code{\link[dracarys:File]{dracarys::File}} -> \code{TsoCopyNumberVariantsVcfFile} +} +\section{Methods}{ +\subsection{Public methods}{ +\itemize{ +\item \href{#method-TsoCopyNumberVariantsVcfFile-read}{\code{TsoCopyNumberVariantsVcfFile$read()}} +\item \href{#method-TsoCopyNumberVariantsVcfFile-write}{\code{TsoCopyNumberVariantsVcfFile$write()}} +\item \href{#method-TsoCopyNumberVariantsVcfFile-clone}{\code{TsoCopyNumberVariantsVcfFile$clone()}} +} +} +\if{html}{\out{ +
Inherited methods + +
+}} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-TsoCopyNumberVariantsVcfFile-read}{}}} +\subsection{Method \code{read()}}{ +Reads the \code{CopyNumberVariants.vcf.gz} file output from TSO. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{TsoCopyNumberVariantsVcfFile$read()}\if{html}{\out{
}} +} + +\subsection{Returns}{ +tibble with variants. +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-TsoCopyNumberVariantsVcfFile-write}{}}} +\subsection{Method \code{write()}}{ +Writes a tidy version of the \code{CopyNumberVariants.vcf.gz} file output from TSO. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{TsoCopyNumberVariantsVcfFile$write( + d, + out_dir = NULL, + prefix, + out_format = "tsv", + drid = NULL +)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{d}}{Parsed object from \code{self$read()}.} + +\item{\code{out_dir}}{Output directory.} + +\item{\code{prefix}}{Prefix of output file(s).} + +\item{\code{out_format}}{Format of output file(s).} + +\item{\code{drid}}{dracarys ID to use for the dataset (e.g. \code{wfrid.123}, \code{prid.456}).} +} +\if{html}{\out{
}} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-TsoCopyNumberVariantsVcfFile-clone}{}}} +\subsection{Method \code{clone()}}{ +The objects of this class are cloneable with this method. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{TsoCopyNumberVariantsVcfFile$clone(deep = FALSE)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{deep}}{Whether to make a deep clone.} +} +\if{html}{\out{
}} +} +} +}