diff --git a/DESCRIPTION b/DESCRIPTION index 2bdd7b4d16640c69bade9dabada01b5113cb01fd..734d7dc24c8178fe517205fe959ae568cae3347c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,8 @@ Imports: purrr, tibble, changepoint, - GenomicRanges + GenomicRanges, + plyranges Suggests: rmarkdown, knitr, diff --git a/NAMESPACE b/NAMESPACE index d5ab6dfe98f455cdc158622b01809ccd22543915..cddcbd931c945c0b7b8d2fbf4cc79d4183919bbf 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,6 +10,7 @@ export(extract_ranges) export(find_cpts) export(merge_segments) export(normalise_lr) +export(read_axiom) export(read_confidences) export(read_summary) export(regroup_data) diff --git a/R/read_axiom.R b/R/read_axiom.R new file mode 100644 index 0000000000000000000000000000000000000000..ba0b22f09672e6d2f0e6b1256c80e7e03e566433 --- /dev/null +++ b/R/read_axiom.R @@ -0,0 +1,93 @@ +#' Read Axiom genotyping output files +#' +#' @param path path to folder containing the files +#' @param read_conf whether or not to read the AxiomGT1.confidences.txt file (defaults to FALSE) +#' +#' @import dplyr +#' @import readr +#' @import stringr +#' +#' @return A [tibble()]. +#' @export +#' +#' @examples +#' \dontrun{ +#' read_axiom(path, read_conf = FALSE) +#' } + +read_axiom <- function(path, read_conf = FALSE) { + + # Set NULL variables + "." <- NULL + + # Check if all Axiom files exist in the folder + + message("Checking if Axiom files exist in the folder") + + if(!file.exists(paste0(path, "AxiomGT1.calls.final.txt"))) { + stop("AxiomGT1.calls.final.txt missing") + } + + if(read_conf == TRUE) { + if(!file.exists(paste0(path, "AxiomGT1.confidences.txt"))) { + stop("AxiomGT1.confidences.txt missing") + } + } + + if(!file.exists(paste0(path, "AxiomGT1.summary.txt"))) { + stop("AxiomGT1.summary.txt missing") + } + + # Read AxiomGT1.calls.final.txt -> 'calls' + + message("Reading AxiomGT1.calls.final.txt") + + calls <- readr::read_tsv(paste0(path, "AxiomGT1.calls.final.txt"), + show_col_types = FALSE) + assign(x = "calls", value = calls, pos = ".GlobalEnv") + + # Read AxiomGT1.confidences.txt -> 'confidences' + + if(read_conf == TRUE) { + + message("Reading AxiomGT1.confidences.txt") + + conf_colnames <- readr::read_lines(file = paste0(path, "AxiomGT1.confidences.txt"), + skip = (grep(pattern = "^probeset_id", + x = readLines(paste0(path, "AxiomGT1.confidences.txt"))) - 1), + n_max = 1) |> + stringr::str_split(pattern = "\t") |> + unlist() + + confidences <- vroom::vroom(file = paste0(path, "AxiomGT1.confidences.txt"), + delim = "\t", + comment = "#", + col_names = conf_colnames, + show_col_types = FALSE) |> + dplyr::filter(probeset_id != "probeset_id") + + assign(x = "confidences", value = confidences, pos = ".GlobalEnv") + + } + + # Read AxiomGT1.summary.txt -> 'summary' + + message("Reading AxiomGT1.summary.txt") + + summary_colnames <- readr::read_lines(file = paste0(path, "AxiomGT1.summary.txt"), + skip = (grep(pattern = "^probeset_id", + x = readLines(paste0(path, "AxiomGT1.summary.txt"))) - 1), + n_max = 1) |> + stringr::str_split(pattern = "\t") |> + unlist() + + summary <- vroom::vroom(file = paste0(path, "AxiomGT1.summary.txt"), + delim = "\t", + comment = "#", + col_names = summary_colnames, + show_col_types = FALSE) |> + dplyr::filter(probeset_id != "probeset_id") + + assign(x = "summary", value = summary, pos = ".GlobalEnv") + +} diff --git a/R/read_confidences.R b/R/read_confidences.R deleted file mode 100644 index 561fdefedc43c4ccc268b77232711c99c55356b8..0000000000000000000000000000000000000000 --- a/R/read_confidences.R +++ /dev/null @@ -1,38 +0,0 @@ -#' Read confidences file from genotyping pipeline output -#' -#' @param confidences_file path to confidences file -#' -#' @import dplyr -#' @import readr -#' @import stringr -#' -#' @return A [tibble()]. -#' @export -#' -#' @examples -#' \dontrun{ -#' read_confidences(confidences_file) -#' } - -read_confidences <- function(confidences_file) { - - # Set NULL variables - probeset_id <- "." <- NULL - - # Extract column names - colnames <- readr::read_lines(confidences_file) %>% - subset(grepl(pattern = "^probeset_id*", .)) %>% - stringr::str_split(pattern = "\t") %>% - unlist() - - # Read file - confidences_data <- readr::read_delim(file = confidences_file, - delim = "\t", - comment = "#", - col_names = colnames) %>% - filter(probeset_id != "probeset_id") - - # Set column names - #names(summary_data) <- col_names - -} diff --git a/R/read_summary.R b/R/read_summary.R deleted file mode 100644 index 1ad2ac337a84dc3a88ff6f1f35cd7806b58c41de..0000000000000000000000000000000000000000 --- a/R/read_summary.R +++ /dev/null @@ -1,37 +0,0 @@ -#' Read summary file from genotyping pipeline output -#' -#' @param summary_file path to summary file -#' -#' @import dplyr -#' @import readr -#' @import stringr -#' -#' @return A [tibble()]. -#' @export -#' -#' @examples -#' \dontrun{ -#' read_summary(summary_file) -#' } - -read_summary <- function(summary_file) { - - # Set NULL variables - "." <- NULL - - # Extract column names - colnames <- readr::read_lines(summary_file) %>% - subset(grepl(pattern = "^probeset_id*", .)) %>% - stringr::str_split(pattern = "\t") %>% - unlist() - - # Read file - summary_data <- readr::read_delim(file = summary_file, - delim = "\t", - comment = "#", - col_names = colnames) - - # Set column names - #names(summary_data) <- col_names - -} diff --git a/man/read_axiom.Rd b/man/read_axiom.Rd new file mode 100644 index 0000000000000000000000000000000000000000..791003de374a56acad9bf5a94584b28dbdf0e15a --- /dev/null +++ b/man/read_axiom.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/read_axiom.R +\name{read_axiom} +\alias{read_axiom} +\title{Read Axiom genotyping output files} +\usage{ +read_axiom(path, read_conf = FALSE) +} +\arguments{ +\item{path}{path to folder containing the files} + +\item{read_conf}{whether or not to read the AxiomGT1.confidences.txt file (defaults to FALSE)} +} +\value{ +A \code{\link[=tibble]{tibble()}}. +} +\description{ +Read Axiom genotyping output files +} +\examples{ +\dontrun{ +read_axiom(path, read_conf = FALSE) +} +}