Search in sources :

Example 1 with GenomePosition

use of com.hartwig.hmftools.common.position.GenomePosition in project hmftools by hartwigmedical.

the class StructuralVariantLegPloidyFactory method create.

@VisibleForTesting
@NotNull
Optional<ModifiableStructuralVariantLegPloidy> create(@NotNull StructuralVariantLeg leg, @NotNull final GenomeRegionSelector<T> selector) {
    final GenomePosition svPositionLeft = GenomePositions.create(leg.chromosome(), leg.position() - 1);
    final Optional<Double> left = selector.select(svPositionLeft).flatMap(x -> Optional.ofNullable(copyNumberExtractor.apply(x))).filter(Doubles::positive);
    final Optional<Double> right = selector.select(leg).flatMap(x -> Optional.ofNullable(copyNumberExtractor.apply(x))).filter(Doubles::positive);
    final Optional<Double> correct;
    final Optional<Double> alternate;
    if (leg.orientation() == 1) {
        correct = left;
        alternate = right;
    } else {
        correct = right;
        alternate = left;
    }
    if (!correct.isPresent() && !alternate.isPresent()) {
        return Optional.empty();
    }
    final double vaf = leg.alleleFrequency();
    final double ploidy;
    final double weight;
    if (correct.isPresent()) {
        double copyNumber = correct.get();
        ploidy = purityAdjustedPloidy(leg.chromosome(), vaf, copyNumber);
        weight = 1;
    } else {
        double copyNumber = alternate.get();
        double reciprocalVAF = vaf / (1 - vaf);
        if (!Double.isFinite(reciprocalVAF)) {
            return Optional.empty();
        }
        ploidy = purityAdjustedPloidy(leg.chromosome(), reciprocalVAF, copyNumber);
        weight = 1 / (1 + Math.pow(Math.max(copyNumber, 2) / Math.min(Math.max(copyNumber, 0.01), 2), 2));
    }
    return Optional.of(ModifiableStructuralVariantLegPloidy.create().from(leg).setVaf(vaf).setOrientation(leg.orientation()).setUnweightedImpliedPloidy(ploidy).setLeftCopyNumber(left).setRightCopyNumber(right).setWeight(weight));
}
Also used : GenomeRegionSelector(com.hartwig.hmftools.common.region.GenomeRegionSelector) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) List(java.util.List) Lists(com.google.common.collect.Lists) GenomeRegionSelectorFactory(com.hartwig.hmftools.common.region.GenomeRegionSelectorFactory) GenomePosition(com.hartwig.hmftools.common.position.GenomePosition) Doubles(com.hartwig.hmftools.common.numeric.Doubles) PurityAdjuster(com.hartwig.hmftools.common.purple.PurityAdjuster) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) GenomePositions(com.hartwig.hmftools.common.position.GenomePositions) StructuralVariantLeg(com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg) GenomeRegion(com.hartwig.hmftools.common.region.GenomeRegion) Doubles(com.hartwig.hmftools.common.numeric.Doubles) GenomePosition(com.hartwig.hmftools.common.position.GenomePosition) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GenomePosition

use of com.hartwig.hmftools.common.position.GenomePosition in project hmftools by hartwigmedical.

the class BachelorEligibility method processStructuralVariant.

private Stream<EligibilityReport> processStructuralVariant(final String patient, final StructuralVariant structuralVariant) {
    final GenomePosition start = GenomePositions.create(structuralVariant.chromosome(true), structuralVariant.position(true));
    final GenomePosition end = GenomePositions.create(structuralVariant.chromosome(false), structuralVariant.position(false));
    final List<EligibilityReport> results = Lists.newArrayList();
    results.addAll(processStructuralVariant(patient, start, end, structuralVariant.type()));
    results.addAll(processStructuralVariant(patient, end, start, structuralVariant.type()));
    return results.stream();
}
Also used : GenomePosition(com.hartwig.hmftools.common.position.GenomePosition)

Example 3 with GenomePosition

use of com.hartwig.hmftools.common.position.GenomePosition in project hmftools by hartwigmedical.

the class StructuralVariantLegsFactory method create.

@NotNull
static List<StructuralVariantLegs> create(@NotNull final List<StructuralVariant> variants) {
    final List<ModifiableStructuralVariantLegs> result = createLegs(false, variants);
    final Multimap<GenomePosition, ModifiableStructuralVariantLegs> duplicates = findDuplicates(result);
    for (GenomePosition duplicatePosition : duplicates.keySet()) {
        final StructuralVariantLeg approvedLeg = reduce(duplicatePosition, duplicates.get(duplicatePosition));
        boolean match = false;
        for (ModifiableStructuralVariantLegs legs : duplicates.get(duplicatePosition)) {
            Optional<StructuralVariantLeg> start = legs.start();
            if (start.filter(x -> isDuplicate(duplicatePosition, x)).isPresent()) {
                assert start.isPresent();
                if (start.get().equals(approvedLeg)) {
                    match = true;
                } else {
                    legs.setStart(Optional.empty());
                }
            }
            Optional<StructuralVariantLeg> end = legs.end();
            if (end.filter(x -> isDuplicate(duplicatePosition, x)).isPresent()) {
                assert end.isPresent();
                if (end.get().equals(approvedLeg)) {
                    match = true;
                } else {
                    legs.setEnd(Optional.empty());
                }
            }
        }
        if (!match) {
            result.add(ModifiableStructuralVariantLegs.create().setStart(approvedLeg).setEnd(Optional.empty()));
        }
    }
    return new ArrayList<>(result);
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ListMultimap(com.google.common.collect.ListMultimap) Collection(java.util.Collection) Multimap(com.google.common.collect.Multimap) Collectors(java.util.stream.Collectors) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) ArrayList(java.util.ArrayList) List(java.util.List) Lists(com.google.common.collect.Lists) GenomePosition(com.hartwig.hmftools.common.position.GenomePosition) Doubles(com.hartwig.hmftools.common.numeric.Doubles) ImmutableStructuralVariantLegImpl(com.hartwig.hmftools.common.variant.structural.ImmutableStructuralVariantLegImpl) Optional(java.util.Optional) StructuralVariantType(com.hartwig.hmftools.common.variant.structural.StructuralVariantType) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) GenomePositions(com.hartwig.hmftools.common.position.GenomePositions) StructuralVariantLeg(com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg) StructuralVariantLeg(com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg) GenomePosition(com.hartwig.hmftools.common.position.GenomePosition) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GenomePosition

use of com.hartwig.hmftools.common.position.GenomePosition in project hmftools by hartwigmedical.

the class ClusterFactory method cluster.

@NotNull
@VisibleForTesting
List<Cluster> cluster(@NotNull final Collection<ClusterVariantLeg> variantPositions, @NotNull final Collection<PCFPosition> pcfPositions, @NotNull final List<CobaltRatio> cobaltRatios) {
    final List<GenomePosition> allPositions = Lists.newArrayList();
    allPositions.addAll(variantPositions);
    allPositions.addAll(pcfPositions);
    Collections.sort(allPositions);
    final List<Cluster> result = Lists.newArrayList();
    int cobaltIndex = 0;
    ModifiableCluster segment = null;
    for (GenomePosition position : allPositions) {
        if (position.position() == 1) {
            continue;
        }
        while (cobaltIndex < cobaltRatios.size() - 1 && cobaltRatios.get(cobaltIndex).position() < position.position()) {
            cobaltIndex++;
        }
        final long earliestDetectableCopyNumberChangePosition = earliestDetectableCopyNumberChangePosition(position.position(), cobaltIndex, cobaltRatios);
        if (segment == null || earliestDetectableCopyNumberChangePosition > segment.end()) {
            if (segment != null) {
                result.add(segment);
            }
            segment = ModifiableCluster.create().setChromosome(position.chromosome()).setStart(earliestDetectableCopyNumberChangePosition);
        }
        segment.setEnd(position.position());
        if (position instanceof ClusterVariantLeg) {
            segment.addVariants((ClusterVariantLeg) position);
        } else {
            segment.addPcfPositions((PCFPosition) position);
        }
    }
    if (segment != null) {
        result.add(segment);
    }
    return result;
}
Also used : GenomePosition(com.hartwig.hmftools.common.position.GenomePosition) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GenomePosition

use of com.hartwig.hmftools.common.position.GenomePosition in project hmftools by hartwigmedical.

the class PurpleSegmentFactory method create.

@NotNull
@VisibleForTesting
static List<PurpleSegment> create(@NotNull final ChromosomeLength chromosome, @NotNull final Collection<Cluster> clusters) {
    final List<PurpleSegment> result = Lists.newArrayList();
    ModifiablePurpleSegment segment = create(chromosome.chromosome(), 1).setSupport(SegmentSupport.TELOMERE);
    for (final Cluster cluster : clusters) {
        boolean ratioSupport = !cluster.ratios().isEmpty();
        final List<ClusterVariantLeg> variants = cluster.variants();
        if (!variants.isEmpty()) {
            for (final ClusterVariantLeg variant : variants) {
                if (variant.position() != segment.start()) {
                    result.add(updatedStatusForCentromere(segment.setEnd(variant.position() - 1)));
                    segment = createFromCluster(cluster, variant, ratioSupport);
                } else {
                    segment.setSupport(SegmentSupport.MULTIPLE);
                }
            }
            segment.setSvCluster(false);
        } else {
            final List<PCFPosition> pcfPositions = cluster.pcfPositions();
            // JOBA: DO FIRST
            final GenomePosition firstRatioBreak = pcfPositions.get(0);
            result.add(updatedStatusForCentromere(segment.setEnd(firstRatioBreak.position() - 1)));
            segment = create(firstRatioBreak.chromosome(), firstRatioBreak.position());
        }
    }
    result.add(segment.setEnd(chromosome.length()));
    return result;
}
Also used : GenomePosition(com.hartwig.hmftools.common.position.GenomePosition) PCFPosition(com.hartwig.hmftools.common.pcf.PCFPosition) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GenomePosition (com.hartwig.hmftools.common.position.GenomePosition)7 NotNull (org.jetbrains.annotations.NotNull)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Lists (com.google.common.collect.Lists)3 Multimap (com.google.common.collect.Multimap)3 GenomePositions (com.hartwig.hmftools.common.position.GenomePositions)3 StructuralVariant (com.hartwig.hmftools.common.variant.structural.StructuralVariant)3 Collections (java.util.Collections)3 List (java.util.List)3 Doubles (com.hartwig.hmftools.common.numeric.Doubles)2 StructuralVariantLeg (com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg)2 StructuralVariantType (com.hartwig.hmftools.common.variant.structural.StructuralVariantType)2 Collection (java.util.Collection)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 HashMultimap (com.google.common.collect.HashMultimap)1 ListMultimap (com.google.common.collect.ListMultimap)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1