Skip to content

Commit

Permalink
Reverting median BAF per segment back to mean as it affects the purit…
Browse files Browse the repository at this point in the history
…y estimates
  • Loading branch information
sdentro committed Dec 15, 2016
1 parent 267f9b7 commit 5870830
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
7 changes: 5 additions & 2 deletions R/fitcopynumber.R
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,11 @@ merge_segments = function(subclones, bafsegmented, logR, rho, psi, platform_gamm
# MERGE
new_entry = data.frame(subclones[i-1,])
new_entry$endpos = subclones[i,]$endpos
new_entry$BAF = median(c(bafsegmented$BAFphased[bafsegmented$Chromosome==subclones$chr[i-1] & bafsegmented$Position>=subclones$startpos[i-1] & bafsegmented$Position<=subclones$endpos[i-1]],
bafsegmented$BAFphased[bafsegmented$Chromosome==subclones$chr[i] & bafsegmented$Position>=subclones$startpos[i] & bafsegmented$Position<=subclones$endpos[i]]), na.rm=T)
# Adjusting the BAFseg values is commented out for now as it is introducing a bias in the purity
# new_entry$BAF = median(c(bafsegmented$BAFphased[bafsegmented$Chromosome==subclones$chr[i-1] & bafsegmented$Position>=subclones$startpos[i-1] & bafsegmented$Position<=subclones$endpos[i-1]],
# bafsegmented$BAFphased[bafsegmented$Chromosome==subclones$chr[i] & bafsegmented$Position>=subclones$startpos[i] & bafsegmented$Position<=subclones$endpos[i]]), na.rm=T)
new_entry$BAF = mean(c(bafsegmented$BAFphased[bafsegmented$Chromosome==subclones$chr[i-1] & bafsegmented$Position>=subclones$startpos[i-1] & bafsegmented$Position<=subclones$endpos[i-1]],
bafsegmented$BAFphased[bafsegmented$Chromosome==subclones$chr[i] & bafsegmented$Position>=subclones$startpos[i] & bafsegmented$Position<=subclones$endpos[i]]), na.rm=T)
new_entry$LogR = mean(c(logR[logR$Chromosome==subclones$chr[i-1] & logR$Position>=subclones$startpos[i-1] & logR$Position<=subclones$endpos[i-1], 3],
logR[logR$Chromosome==subclones$chr[i] & logR$Position>=subclones$startpos[i] & logR$Position<=subclones$endpos[i], 3]), na.rm=T)
subclones_cleaned = rbind(subclones_cleaned, new_entry)
Expand Down
11 changes: 6 additions & 5 deletions R/segmentation.R
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,12 @@ segment.baf.phased.sv = function(samplename, inputfile, outputfile, svs, gamma=1
res = Battenberg:::selectFastPcf(BAFphased,kmin,gamma*sdev,T)
BAFphseg = res$yhat
}

if (length(BAF) > 0) {
# Adjust the segment BAF to not take the mean as that is sensitive to improperly phased segments
BAFphseg = adjustSegmValues(data.frame(BAFphased=BAFphased, BAFseg=BAFphseg))$BAFseg
}

# Adjusting the BAFseg values is commented out for now as it is introducing a bias in the purity
# if (length(BAF) > 0) {
# # Adjust the segment BAF to not take the mean as that is sensitive to improperly phased segments
# BAFphseg = adjustSegmValues(data.frame(BAFphased=BAFphased, BAFseg=BAFphseg))$BAFseg
# }

return(data.frame(Chromosome=rep(chr, length(row.indices)),
Position=BAFrawchr[row.indices,1],
Expand Down
2 changes: 1 addition & 1 deletion R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @param sep Column separator (Default: \t)
#' @param chrom_col The column number that contains chromosome denominations. This column will automatically be cast as a character. Should be counted including the row.names (Default: 1)
#' @param skip The number of rows to skip before reading (Default: 0)
#' @return: A data frame with contents of the file
#' @return A data frame with contents of the file
#' @export
read_table_generic = function(file, header=T, row.names=F, stringsAsFactor=F, sep="\t", chrom_col=1, skip=0) {
# stringsAsFactor is not needed here, but kept for legacy purposes
Expand Down

0 comments on commit 5870830

Please sign in to comment.