internal static IWittyerVariant Create([NotNull] IVcfVariant baseVariant, string sample, double percentageDistance, uint basepairDistance, IReadOnlyList <uint> bins, WittyerVariantType svType) { if (svType == WittyerVariantType.Invalid) { throw new InvalidDataException( $"Invalid {VcfConstants.SvTypeKey} in variant: \n{baseVariant}\nNot sure why you got here though. Check with a witty.er developer!"); } var end = baseVariant.Position + baseVariant.GetSvLength(); var baseInterval = BedInterval.Create(baseVariant.Position, end); var borderInterval = baseVariant.Position.CalculateBorderInterval(baseInterval, baseVariant.ParseCi(WittyerConstants.Cipos), percentageDistance, basepairDistance); // wittyerVariant should all have end border, it's a matter of how to find it, // either END key in INFO field, sort out through SVLEN or other ways, details can be defined in FindEndBorder() later var endInterval = (end - 1).CalculateBorderInterval(baseInterval, baseVariant.ParseCi(WittyerConstants.Ciend), percentageDistance, basepairDistance); var posContigAndInterval = ContigAndInterval.Create(baseVariant.Contig, borderInterval.Start, borderInterval.Stop + 1); var endContigAndInterval = ContigAndInterval.Create(baseVariant.Contig, endInterval.Start, endInterval.Stop + 1); return(Create(baseVariant, baseInterval, svType, posContigAndInterval, Winner.Create(svType, baseInterval, bins), new List <OverlapAnnotation>(), WittyerSample.CreateOverall(baseVariant, sample, svType == WittyerVariantType.CopyNumberReference), endContigAndInterval)); }
internal static IWittyerBnd Create([NotNull] IVcfVariant variant, IVcfVariant secondVariant, [CanBeNull] string sampleName, double percentageDistance, uint basepairDistance, IReadOnlyList <uint> bins) { var(first, second) = MiscUtils.FindBndEntriesOrder(variant, secondVariant); var posInterval = first.CalculateBndBorderInterval(second, first.ParseCi(WittyerConstants.Cipos), percentageDistance, basepairDistance); var endInterval = second.CalculateBndBorderInterval(first, second.ParseCi(WittyerConstants.Cipos), percentageDistance, basepairDistance); var svType = variant.ParseWittyerVariantType(sampleName); var winner = GetWinner(); var overlapInfo = new List <OverlapAnnotation>(); var sample = WittyerSample.CreateOverall(variant, sampleName, false); return(Create(first, posInterval, winner, endInterval, overlapInfo, sample, second, svType)); Winner GetWinner() { if (svType == WittyerVariantType.TranslocationBreakend) { return(Winner.Create(svType)); } if (svType != WittyerVariantType.Insertion) { return(Winner.Create(svType, BedInterval.Create(first.Position, second.Position + 1), bins)); } uint?end = null; // insertion, try sequences first if (variant.IsSimpleSequence(out var length)) { end = length; } // try svlength, but if not, assume unknown length. else if (variant.TryGetSvLength(out length) == null) { end = length; } return(Winner.Create(svType, end == null ? null : BedInterval.Create(variant.Position, variant.Position + end.Value), bins)); } }
internal static IWittyerVariant Create([NotNull] IVcfVariant baseVariant, [CanBeNull] IVcfSample sample, [NotNull] WittyerType svType, [NotNull] IReadOnlyList <uint> bins, [CanBeNull] double?percentageDistance, uint basepairDistance) { // originalInterval is needed to adjust CIPOS and CIEND against for PD/BPD, but it won't be used for actual reflen and binning. var baseInterval = baseVariant.ToBedInterval(true, out var originalEnd, out var sharedFirstBase); if (baseInterval == null) { throw new InvalidOperationException( $"Expected failure of {nameof(WittyerUtils.ToBedInterval)} to throw, but didn't..."); } // CI intervals are always based on the original POS/END var posStart = baseVariant.Position; if (sharedFirstBase) { posStart++; } var ciPosInterval = posStart.ConvertPositionToCiInterval(baseVariant, WittyerConstants.Cipos); var ciEndInterval = originalEnd.ConvertPositionToCiInterval(baseVariant, WittyerConstants.Ciend); var baseStart = sharedFirstBase ? baseInterval.Start : baseInterval.Start + 1; // not sharing first base (ref site or complex types, etc) need adjustment // the pd/bpd intervals are based on the trimmed variant's coordinates. var(posInterval, endInterval) = WittyerUtils.GetPosAndEndInterval(baseVariant.Contig, percentageDistance, basepairDistance, ciPosInterval, baseStart, ciEndInterval, baseInterval.Stop); return(new WittyerVariantInternal(svType, baseVariant, baseInterval, Winner.Create(svType, baseInterval, bins), posInterval, ciPosInterval, endInterval, ciEndInterval, WittyerSample.CreateFromVariant(baseVariant, sample, svType == WittyerType.CopyNumberReference))); }
internal static IWittyerBnd Create([NotNull] IVcfVariant first, [CanBeNull] IVcfSample originalSample, [NotNull] WittyerType svType, [NotNull] IReadOnlyList <uint> bins, uint bpd, double?percentageDistance, [NotNull] IVcfVariant second) { if (!ReferenceEquals(first, second)) { (first, second) = FindBndEntriesOrder(in first, in second); } var ciPosInterval = first.Position.ConvertPositionToCiInterval(first, WittyerConstants.Cipos); var ciEndInterval = ReferenceEquals(first, second) ? ciPosInterval // same variant means same intervals. : second.Position.ConvertPositionToCiInterval(second, WittyerConstants.Cipos); IContigAndInterval posInterval, endInterval; if (ReferenceEquals(first, second)) // insertions need trimming and stuff. { var trimmed = first.TryNormalizeVariant(VariantNormalizer.TrimCommonBases, 0).GetOrThrow(); var tuple = (bpd, bpd); var(posStart, posStop) = trimmed.Position.ConvertPositionToCiInterval(tuple); WittyerUtils.GetBetterInterval(ciPosInterval, ref posStart, ref posStop); posInterval = endInterval = ContigAndInterval.Create(first.Contig, posStart, posStop); } else { (posInterval, endInterval) = WittyerUtils.GetPosAndEndInterval(first.Contig, svType == WittyerType.IntraChromosomeBreakend ? percentageDistance : null, bpd, ciPosInterval, first.Position, ciEndInterval, second.Position, second.Contig); } var winner = GetWinner(); var sample = WittyerSample.CreateFromVariant(first, originalSample, false); return(new WittyerBndInternal(svType, first, posInterval, ciPosInterval, second, endInterval, ciEndInterval, winner, sample)); (IVcfVariant first, IVcfVariant second) FindBndEntriesOrder(in IVcfVariant variantA, in IVcfVariant variantB) => ContigAndPositionComparer.Default.Compare(variantA, variantB) > 0 ? (variantB, variantA) : (variantA, variantB); Winner GetWinner() { if (svType == WittyerType.TranslocationBreakend) { return(Winner.Create(svType)); } IInterval <uint> bedInterval; if (svType == WittyerType.Insertion) { bedInterval = GetInsertionInterval(first); } else { var start = first.Position; if (start > 0) { start--; } bedInterval = BedInterval.Create(start, second.Position); } return(Winner.Create(svType, bedInterval, bins)); } }