Search in sources :

Example 1 with ObservedRegion

use of com.hartwig.hmftools.common.purple.region.ObservedRegion in project hmftools by hartwigmedical.

the class FittedPurityFactory method fitPurity.

private void fitPurity(@NotNull final Collection<ObservedRegion> observedRegions) throws ExecutionException, InterruptedException {
    int totalBAFCount = 0;
    final List<ObservedRegion> filteredRegions = Lists.newArrayList();
    for (final ObservedRegion region : observedRegions) {
        final Chromosome chromosome = HumanChromosome.valueOf(region);
        if (region.bafCount() > 0 && positiveOrZero(region.observedTumorRatio()) && chromosome.isAutosome() && region.status() == GermlineStatus.DIPLOID && Doubles.lessOrEqual(region.observedTumorRatio(), MAX_TUMOR_RATIO_TO_FIT)) {
            totalBAFCount += region.bafCount();
            filteredRegions.add(region);
        }
    }
    List<Future<List<FittedPurity>>> futures = Lists.newArrayList();
    for (double purity = minPurity; lessOrEqual(purity, maxPurity); purity += purityIncrements) {
        futures.add(executorService.submit(callableFitPurity(purity, totalBAFCount, filteredRegions)));
    }
    for (Future<List<FittedPurity>> future : futures) {
        List<FittedPurity> fittedPurities = future.get();
        if (!fittedPurities.isEmpty()) {
            bestScoringPerPurity.add(fittedPurities.get(0));
        }
    }
    Collections.sort(bestScoringPerPurity);
}
Also used : Chromosome(com.hartwig.hmftools.common.chromosome.Chromosome) HumanChromosome(com.hartwig.hmftools.common.chromosome.HumanChromosome) Future(java.util.concurrent.Future) List(java.util.List) ObservedRegion(com.hartwig.hmftools.common.purple.region.ObservedRegion)

Example 2 with ObservedRegion

use of com.hartwig.hmftools.common.purple.region.ObservedRegion in project hmftools by hartwigmedical.

the class FittedPurityFactory method fitPurity.

@NotNull
private FittedPurity fitPurity(final double purity, final double normFactor, final double totalBafCount, @NotNull final Collection<ObservedRegion> observedRegions) {
    ImmutableFittedPurity.Builder builder = ImmutableFittedPurity.builder().purity(purity).normFactor(normFactor);
    double ploidyPenalty = 0;
    double modelDeviation = 0;
    double diploidProportion = 0;
    double averagePloidy = 0;
    for (final ObservedRegion enrichedRegion : observedRegions) {
        final FittedRegion fittedRegion = fittedRegionFactory.fitRegion(purity, normFactor, enrichedRegion);
        ploidyPenalty += enrichedRegion.bafCount() / totalBafCount * fittedRegion.ploidyPenalty();
        modelDeviation += enrichedRegion.bafCount() / totalBafCount * fittedRegion.deviation();
        averagePloidy += fittedRegion.tumorCopyNumber() * fittedRegion.bafCount() / totalBafCount;
        if (fittedRegion.modelPloidy() == 2) {
            diploidProportion += enrichedRegion.bafCount() / totalBafCount;
        }
    }
    return builder.score(ploidyPenalty * modelDeviation).diploidProportion(diploidProportion).ploidy(averagePloidy).build();
}
Also used : FittedRegion(com.hartwig.hmftools.common.purple.region.FittedRegion) ObservedRegion(com.hartwig.hmftools.common.purple.region.ObservedRegion) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ObservedRegion (com.hartwig.hmftools.common.purple.region.ObservedRegion)2 Chromosome (com.hartwig.hmftools.common.chromosome.Chromosome)1 HumanChromosome (com.hartwig.hmftools.common.chromosome.HumanChromosome)1 FittedRegion (com.hartwig.hmftools.common.purple.region.FittedRegion)1 List (java.util.List)1 Future (java.util.concurrent.Future)1 NotNull (org.jetbrains.annotations.NotNull)1