private WittyerSampleInternal(IVcfSample baseSample, WitDecision wit, [NotNull] IImmutableList <MatchEnum> what, [NotNull] IImmutableList <FailedReason> why) { _baseSample = baseSample; Wit = wit; What = what; Why = why; }
/// <inheritdoc /> public void Finalize(WitDecision falseDecision, EvaluationMode mode, GenomeIntervalTree <IContigAndInterval> includedRegions) { bool?isIncluded = null; if (includedRegions != null) { isIncluded = includedRegions.TryGetValue(OriginalVariant.Contig, out var tree) && tree.Search(CiPosInterval).Any() && // or there's overlap in bed regions (ReferenceEquals(OriginalVariant, EndOriginalVariant) || Equals(OriginalVariant.Contig, EndOriginalVariant.Contig) || includedRegions.TryGetValue(EndOriginalVariant.Contig, out tree) && tree.Search(CiEndInterval).Any()); // or end overlaps. } WittyerVariantInternal.Finalize(this, _overlapInfo, falseDecision, mode, isIncluded); }
private static bool ParseVariantGetTag([NotNull] string variant, WitDecision targetDecision) { var parser = VcfVariantParserSettings.Create(new List <string> { "sample" }); var vcfVariant = VcfVariant.TryParse(variant, parser).GetOrThrow(); var sampleDictionary = vcfVariant.Samples.Single().Value.SampleDictionary; if (vcfVariant.Info.TryGetValue(WittyerConstants.WittyerMetaInfoLineKeys.Who, out var who)) { if (who.Split(WittyerConstants.SampleValueDel).Length > WittyerConstants.MaxNumberOfAnnotations) { return(false); } } return(sampleDictionary .TryGetValue(WittyerConstants.WittyerMetaInfoLineKeys.Wit).Any(it => it != VcfConstants.MissingValueString && (it != targetDecision.ToStringDescription() && it != NotAssessedString || sampleDictionary .TryGetValue(WittyerConstants.WittyerMetaInfoLineKeys.Why) .Any(val => val != VcfConstants.MissingValueString)))); }
/// <inheritdoc /> public void Finalize(WitDecision falseDecision, EvaluationMode mode, GenomeIntervalTree <IContigAndInterval> includedRegions) { bool?isIncluded = null; if (includedRegions != null) { isIncluded = false; if (includedRegions.TryGetValue(Contig, out var tree)) { var startPosition = CiPosInterval.Stop - 1; var endPosition = CiEndInterval.Start; if (startPosition >= endPosition) { // means cipos or ciend goes past each other // so any overlap with Start to Stop should mean included. isIncluded = tree.Search(this).Any(); } else { // ReSharper disable once LoopCanBeConvertedToQuery // prevent closure allocation foreach (var overlap in tree.Search(startPosition)) { if (!overlap.Contains(endPosition)) { continue; } isIncluded = true; break; } } } } Finalize(this, _overlapInfo, falseDecision, mode, isIncluded); }
internal static void Finalize([NotNull] IMutableWittyerSimpleVariant variant, [NotNull] List <OverlapAnnotation> annotations, WitDecision falseDecision, EvaluationMode mode, bool?isIncluded) { annotations.Sort(); WittyerSampleInternal unwrappedSample; switch (variant.Sample) { case WittyerSampleInternal simple: unwrappedSample = simple; break; case WittyerCopyNumberSample cnSample: unwrappedSample = cnSample.BaseSample; break; case WittyerGenotypedSample gtSample: unwrappedSample = gtSample.BaseSample; break; case WittyerGenotypedCopyNumberSample gtCnSample: unwrappedSample = gtCnSample.BaseSample.BaseSample; break; default: throw new InvalidDataException( "Not sure how we get here, you must have created some non-existed wittyer sample type, check with developer!"); } // expected results: // isIncluded == null means no bedRegion, so everything is normal. // isIncluded != null means bedRegion, so if false, override the results as such: // Wit = NotAssessed. // Why[0] if Unset = OutsideBedRegion unwrappedSample.What = ImmutableList <MatchEnum> .Empty; unwrappedSample.Why = ImmutableList <FailedReason> .Empty; var isTp = false; for (var i = 0; i < variant.OverlapInfo.Count; i++) { var what = variant.OverlapInfo[i].What; unwrappedSample.What = unwrappedSample.What.Add(what); isTp = isTp || what == MatchEnum.AlleleAndGenotypeMatch || (mode == EvaluationMode.SimpleCounting || mode == EvaluationMode.CrossTypeAndSimpleCounting) && what == MatchEnum.AlleleMatch; var why = variant.OverlapInfo[i].Why; if (why == FailedReason.Unset) { why = i == 0 && isIncluded == false ? FailedReason.OutsideBedRegion : what == MatchEnum.Unmatched ? FailedReason.NoOverlap : FailedReason.Other; } unwrappedSample.Why = unwrappedSample.Why.Add(why); } if (unwrappedSample.What.Count == 0) { unwrappedSample.What = EmptyWhat; } if (unwrappedSample.Why.Count == 0) { unwrappedSample.Why = isIncluded == false ? EmptyOutsideBedWhy : isTp ? EmptyTrueWhy : EmptyFalseWhy; } unwrappedSample.Wit = isIncluded == null || isIncluded.Value ? isTp ? WitDecision.TruePositive : falseDecision : WitDecision.NotAssessed; }
public static IWittyerSample Create([NotNull] IVcfSample baseSample, WitDecision wit, [NotNull] IImmutableList <MatchEnum> what, [NotNull] IImmutableList <FailedReason> why) => WittyerSampleInternal.Create(baseSample, wit, what, why);
internal static WittyerSampleInternal Create([NotNull] IVcfSample baseSample, WitDecision wit, [NotNull] IImmutableList <MatchEnum> what, [NotNull] IImmutableList <FailedReason> why) => new WittyerSampleInternal(baseSample, wit, what, why);