Skip to content

Commit 55905e7

Browse files
authored
Merge pull request #384 from lima1/issue_342
Issue 342
2 parents 88754b2 + 69f0492 commit 55905e7

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

R/filterIntervals.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,25 @@ normalDB.min.coverage, normalDB.max.missing) {
197197
intervalsUsed
198198
}
199199

200+
.filterIntervalsAllosome <- function(intervalsUsed, tumor, sex) {
201+
if (is.null(sex)) return(intervalsUsed)
202+
sex.chr <- .getSexChr(seqlevels(tumor))
203+
remove.chrs <- c()
204+
if (sex == "M" || sex == "?") {
205+
remove.chrs <- sex.chr
206+
} else if (sex == "F") {
207+
remove.chrs <- sex.chr[2]
208+
}
209+
nBefore <- sum(intervalsUsed)
210+
intervalsUsed <- intervalsUsed & !seqnames(tumor) %in% remove.chrs
211+
nAfter <- sum(intervalsUsed)
212+
if (nAfter < nBefore) {
213+
flog.info("Removing %i non-diploid allosome intervals.", nBefore - nAfter)
214+
}
215+
intervalsUsed
216+
}
217+
218+
200219
.filterIntervalsTotalNormalCoverage <- function(intervalsUsed, normal,
201220
min.targeted.base, min.coverage) {
202221
if (is.null(min.targeted.base) || is.null(min.coverage)) {

R/runAbsoluteCN.R

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,10 @@ runAbsoluteCN <- function(normal.coverage.file = NULL,
416416
}
417417

418418
sex <- .getSex(match.arg(sex), normal, tumor)
419-
tumor <- .fixAllosomeCoverage(sex, tumor)
420-
421419
if (!is.null(interval.file)) {
422420
tumor <- .addGCData(tumor, interval.file)
423421
}
422+
424423
if (is.null(centromeres) && !missing(genome)) {
425424
centromeres <- .getCentromerePositions(centromeres, genome,
426425
if (is.null(tumor)) NULL else .getSeqlevelsStyle(tumor))
@@ -442,6 +441,16 @@ runAbsoluteCN <- function(normal.coverage.file = NULL,
442441
# chr.hash is an internal data structure, so we need to do this separately.
443442
intervalsUsed <- .filterIntervalsChrHash(intervalsUsed, tumor, chr.hash)
444443
intervalsUsed <- .filterIntervalsCentromeres(intervalsUsed, tumor, centromeres)
444+
intervalsUsedAllosome <- intervalsUsed
445+
intervalsUsed <- .filterIntervalsAllosome(intervalsUsed, tumor, sex)
446+
447+
if (!is.null(normalDB$sd$weights)) {
448+
tumor$weights <- subsetByOverlaps(normalDB$sd$weights, tumor)$weights
449+
}
450+
tumorAllosome <- tumor
451+
tumorAllosome$log.ratio <- log.ratio
452+
tumorAllosome <- tumorAllosome[!intervalsUsed & intervalsUsedAllosome, ]
453+
445454
intervalsUsed <- which(intervalsUsed)
446455
if (length(tumor) != length(normal) ||
447456
length(tumor) != length(log.ratio)) {
@@ -468,9 +477,6 @@ runAbsoluteCN <- function(normal.coverage.file = NULL,
468477
flog.info("Mean off-target bin size: %.0f",
469478
mean(width(tumor[!tumor$on.target]), na.rm = TRUE))
470479
}
471-
if (!is.null(normalDB$sd$weights)) {
472-
tumor$weights <- subsetByOverlaps(normalDB$sd$weights, tumor)$weights
473-
}
474480
# not needed anymore
475481
normalDB <- NULL
476482

@@ -1145,7 +1151,7 @@ runAbsoluteCN <- function(normal.coverage.file = NULL,
11451151
list(
11461152
candidates = candidate.solutions,
11471153
results = results,
1148-
input = list(tumor = tumor.coverage.file, normal = normal.coverage.file,
1154+
input = list(tumor = tumor.coverage.file, normal = normal.coverage.file, allosome = tumorAllosome,
11491155
log.ratio = GRanges(normal[, 1], on.target = normal$on.target, log.ratio = log.ratio),
11501156
log.ratio.sdev = sd.seg, mapd = mapd, vcf = vcf, sampleid = sampleid,
11511157
test.num.copy = test.num.copy,

0 commit comments

Comments
 (0)