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));
}
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();
}
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);
}
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;
}
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;
}
Aggregations