From 8fbcab53dd4ade836c2229cd47e9c2968742ad49 Mon Sep 17 00:00:00 2001 From: Gavin Ha Date: Wed, 6 Feb 2019 19:42:57 -0500 Subject: [PATCH 1/2] ploidy2 path fix Typo in ploidyRun2 path corrected. Fixes #65 Thanks to @aleighgreen for finding this typo --- scripts/snakemake/TitanCNA.snakefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/snakemake/TitanCNA.snakefile b/scripts/snakemake/TitanCNA.snakefile index 098b582..fa56281 100644 --- a/scripts/snakemake/TitanCNA.snakefile +++ b/scripts/snakemake/TitanCNA.snakefile @@ -71,7 +71,7 @@ rule selectSolution: "logs/titan/selectSolution.log" shell: """ - ploidyRun2=results/titan/titanCNA_ploidy2/ + ploidyRun2=results/titan/hmm/titanCNA_ploidy2/ if [ -d results/titan/hmm/titanCNA_ploidy3/ ]; then ploidyRun3=results/titan/hmm/titanCNA_ploidy3/ else @@ -84,4 +84,4 @@ rule selectSolution: fi Rscript {params.solutionRscript} --ploidyRun2 $ploidyRun2 --ploidyRun3 $ploidyRun3 --ploidyRun4 $ploidyRun4 --threshold {params.threshold} --outFile {output} > {log} 2> {log} """ - \ No newline at end of file + From 88a51c0a327c8a590563894b829539b538a95fa5 Mon Sep 17 00:00:00 2001 From: Gavin Ha Date: Fri, 8 Feb 2019 14:30:59 -0500 Subject: [PATCH 2/2] fix Corrected_Ratio column in output segs file Corrected_Ratio contained all NAs because correctIntegerCN() was looking at the Median_HaplotypeRatio column. Median_HaplotypeRatio should only be present in the segs and results objects/files for 10X Genomics WGS data. Now, Median_HaplotypeRatio will not be included in the output files if not using TitanCNA_10X_snakemake pipeline. Fixes #67. Thanks to @aleighgreen for catching this bug. --- R/utils.R | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/R/utils.R b/R/utils.R index 164169a..dc62c75 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1080,8 +1080,12 @@ outputTitanSegments <- function(results, id, convergeParams, filename = NULL, ig results$HaplotypeRatio <- pmax(results$HaplotypeRatio, 1-results$HaplotypeRatio) } segs <- data.table(Sample = character(), Chromosome = character(), Start_Position.bp. = integer(), - End_Position.bp. = integer(), Length.snp. = integer(), Median_Ratio = numeric(), - Median_HaplotypeRatio = numeric(), Median_logR = numeric(), TITAN_state = integer(), + End_Position.bp. = integer(), Length.snp. = integer(), Median_Ratio = numeric()) + # add HaplotypeRatio column if also present in results object + if (!is.null(results$HaplotypeRatio)){ + segs <- cbind(segs, Median_HaplotypeRatio = numeric()) + } + segs <- cbind(segs, Median_logR = numeric(), TITAN_state = integer(), TITAN_call = character(), Copy_Number = integer(), MinorCN = integer(), MajorCN = integer(), Clonal_Cluster = integer(), Cellular_Prevalence = numeric())[1:numSegs] segs[, Sample := id] @@ -1106,8 +1110,6 @@ outputTitanSegments <- function(results, id, convergeParams, filename = NULL, ig segs[j, "Cellular_Prevalence"] <- segDF[1, "CellularPrevalence"] if (!is.null(segDF$HaplotypeRatio)){ segs[j, "Median_HaplotypeRatio"] <- round(median(segDF$HaplotypeRatio, na.rm = TRUE), digits = 6) - }else{ - segs[j, "Median_HaplotypeRatio"] <- NA } if (segDF[1, "Chr"] == segDF[numR, "Chr"]){ segs[j, "End_Position.bp."] <- segDF[numR, "Position"] @@ -1180,7 +1182,9 @@ correctIntegerCN <- function(cn, segs, purity, ploidy, maxCNtoCorrect.autosomes ## determine if Median_HaplotypeRatio (segs) and HaplotypeRatio (cn) columns exists (i.e. 10X analysis) segs.allelicRatioColName <- "Median_Ratio" if ("Median_HaplotypeRatio" %in% names(segs)){ - segs.allelicRatioColName <- "Median_HaplotypeRatio" + if (segs[, Median_HaplotypeRatio]){ + segs.allelicRatioColName <- "Median_HaplotypeRatio" + } } cn.allelicRatioColName <- "AllelicRatio" if ("HaplotypeRatio" %in% names(cn)){