Skip to content

Commit

Permalink
Do not error out readCurationFile when CSV is missing and directory i…
Browse files Browse the repository at this point in the history
…s not writable when re-generating it (closes lima1#196).
  • Loading branch information
lima1 committed Aug 20, 2021
1 parent b83e851 commit 1a1ee1d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Package: PureCN
Type: Package
Title: Copy number calling and SNV classification using
targeted short read sequencing
Version: 1.23.16
Date: 2021-08-17
Version: 1.23.17
Date: 2021-08-20
Authors@R: c(person("Markus", "Riester",
role = c("aut", "cre"),
email = "[email protected]",
Expand Down
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ SIGNIFICANT USER-VISIBLE CHANGES
- min.logr.sdev is now accessible in PureCN.R via --minlogrsdev
o Added pairwise sample distances to normalDB output object helpful for
finding noisy samples or batches in normal databases
o Do not error out readCurationFile when CSV is missing and directory
is not writable when re-generating it (#196)

BUGFIXES

Expand Down
12 changes: 7 additions & 5 deletions R/filterIntervals.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,19 @@ filterIntervals <- function(normal, tumor, log.ratio, seg.file,
min.targeted.base, min.coverage)

if (!is.null(normalDB)) {
min.coverage <- min.coverage / 10000
min.coverage <- 0
normal$average.coverage[is.na(normal$average.coverage)] <- min.coverage
flog.info("normalDB provided. Setting minimum coverage for segmentation to %.4fX.", min.coverage)
} else {
flog.warn("No normalDB provided. Provide one for better results.")
}

intervalsUsed <- .filterIntervalsCoverage(intervalsUsed, normal, tumor,
min.coverage)

intervalsUsed <- .filterIntervalsTotalCounts(intervalsUsed, normal, tumor,
min.total.counts)

intervalsUsed <- .filterIntervalsCoverage(intervalsUsed, normal, tumor,
min.coverage)

intervalsUsed <- .filterIntervalsMappability(intervalsUsed, tumor,
min.mappability)

Expand Down Expand Up @@ -224,6 +225,7 @@ normalDB.min.coverage, normalDB.max.missing) {
}
intervalsUsed
}

.filterIntervalsTotalCounts <- function(intervalsUsed, normal, tumor, min.total.counts) {

well.covered.interval.idx <- (normal$counts + tumor$counts) >= min.total.counts
Expand Down Expand Up @@ -258,7 +260,7 @@ normalDB.min.coverage, normalDB.max.missing) {
.filterIntervalsMappability <- function(intervalsUsed, tumor, min.mappability) {
if (is.null(tumor$mappability) || all(is.na(tumor$mappability))) {
return(intervalsUsed)
}
}
if (any(is.na(tumor$mappability))) {
flog.warn("Some intervals do not have a mappability score, assuming they are fine.")
}
Expand Down
24 changes: 14 additions & 10 deletions R/readCurationFile.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#' Read curation file
#'
#'
#' Function that can be used to read the curated output of the
#' \code{\link{runAbsoluteCN}} function.
#'
#'
#'
#'
#' @param file.rds Output of the \code{\link{runAbsoluteCN}} function,
#' serialized with \code{saveRDS}.
#' @param file.curation Filename of a curation file that points to the correct
Expand All @@ -21,25 +21,29 @@
#' @author Markus Riester
#' @seealso \code{\link{runAbsoluteCN} \link{createCurationFile}}
#' @examples
#'
#'
#' data(purecn.example.output)
#' file.rds <- "Sample1_PureCN.rds"
#' createCurationFile(file.rds)
#' # User can change the maximum likelihood solution manually in the generated
#' createCurationFile(file.rds)
#' # User can change the maximum likelihood solution manually in the generated
#' # CSV file. The correct solution is then loaded with readCurationFile.
#' purecn.curated.example.output <-readCurationFile(file.rds)
#'
#' purecn.curated.example.output <-readCurationFile(file.rds)
#'
#' @export readCurationFile
#' @importFrom utils read.csv
readCurationFile <- function(file.rds,
file.curation = gsub(".rds$", ".csv", file.rds),
remove.failed = FALSE, report.best.only=FALSE, min.ploidy = NULL,
remove.failed = FALSE, report.best.only = FALSE, min.ploidy = NULL,
max.ploidy = NULL) {
flog.info("Reading %s...", file.rds)
res <- readRDS(file.rds)
if (!file.exists(file.curation)) {
flog.warn("Curation file %s does not exist, creating one.", file.curation)
createCurationFile(file.rds)
output <- try(createCurationFile(file.rds))
if (is(output, "try-error")) {
flog.warn("Failed to write %s: %s", file.curation, output)
return(res)
}
}
curation <- read.csv(file.curation, as.is=TRUE, nrows=1)
.checkLogical <- function(field) {
Expand Down
6 changes: 3 additions & 3 deletions man/readCurationFile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1a1ee1d

Please sign in to comment.