public static void SubstractIntervalWorks(IInterval <uint> interval, IEnumerable <IInterval <uint> > expected) { var target = new InclusiveInterval <uint>(10, 15); var actual = target.Subtract(interval.FollowedBy()); Assert.Equal(expected, actual); }
public void InsertNonOverlappingAtEnd() { var tree = MergedIntervalTree.Create(ExistingIntervals); var target = new InclusiveInterval <uint>(ExistingIntervals.Last().Stop + 1, uint.MaxValue); tree.Add(target); MultiAssert.Equal(ExistingIntervals.Count + 1, tree.Count()); MultiAssert.Equal(target, tree.Last()); MultiAssert.AssertAll(); }
public void InsertNonOverlappingAtMiddle() { var tree = MergedIntervalTree.Create(ExistingIntervals); var target = new InclusiveInterval <uint>(ExistingIntervals[0].Stop + 1, ExistingIntervals[1].Start - 1); tree.Add(target); // non-overlapping should have one more interval Assert.Equal(ExistingIntervals.Count + 1, tree.Count()); }
internal static InclusiveInterval <uint> CalculateBorderInterval(this uint position, [NotNull] IInterval <uint> baseInterval, InclusiveInterval <int> confidentInterval, double percentageDistance, uint basepairDistance) { var pd = (uint)Math.Round(baseInterval.GetLength() * percentageDistance, MidpointRounding.AwayFromZero); return(pd < basepairDistance ? position.ConvertPositionToInterval(pd, pd) : position.CalculateBasePairDistance(confidentInterval, basepairDistance)); }
public void InsertTotallyOverlappingBecomesOneInterval() { var tree = MergedIntervalTree.Create(ExistingIntervals); var target = new InclusiveInterval <uint>(ExistingIntervals[0].Stop, ExistingIntervals.Last().Start); tree.Add(target); MultiAssert.Equal(1, tree.Count()); MultiAssert.Equal(ExistingIntervals.First().Start, tree.First().Start); MultiAssert.Equal(ExistingIntervals.Last().Stop, tree.Last().Stop); MultiAssert.AssertAll(); }
public void CalculateBndBorderDistanceWorks([NotNull] string chr, uint position, [NotNull] string otherChr, uint otherPos, int ciStart, int ciEnd, double percentDistance, uint basepairDistance, uint borderStart, uint borderEnd) { var thisPos = ContigAndPosition.Create(ContigInfo.Create(chr), position); var otherPosition = ContigAndPosition.Create(ContigInfo.Create(otherChr), otherPos); var ci = new InclusiveInterval <int>(ciStart, ciEnd); var actualCi = thisPos.CalculateBndBorderInterval(otherPosition, ci, percentDistance, basepairDistance); var expectedCi = ContigAndInterval.Create(ContigInfo.Create(chr), borderStart, borderEnd); Assert.Equal(expectedCi, actualCi); }
public void CalculateBorderDistanceWorks(uint position, uint end, int ciStart, int ciEnd, double percentDistance, uint basepairDistance, uint borderStart, uint borderEnd, bool isEnd) { var baseInterval = new InclusiveInterval <uint>(position, end); var ci = new InclusiveInterval <int>(ciStart, ciEnd); var target = isEnd ? end : position; var actualInterval = target.CalculateBorderInterval(baseInterval, ci, percentDistance, basepairDistance); var expectedInterval = new InclusiveInterval <uint>(borderStart, borderEnd); Assert.Equal(expectedInterval, actualInterval); }
public void InsertNonOverlappingAtBeginning() { var tree = MergedIntervalTree.Create(ExistingIntervals); var target = new InclusiveInterval <uint>(uint.MinValue, ExistingIntervals[0].Start - 1); tree.Add(target); // non-overlapping should have one more interval MultiAssert.Equal(ExistingIntervals.Count + 1, tree.Count()); MultiAssert.Equal(tree.First().Start, target.Start); MultiAssert.Equal(tree.First().Stop, target.Stop); MultiAssert.AssertAll(); }
private static InclusiveInterval <uint> CalculateBasePairDistance(this uint position, [NotNull] InclusiveInterval <int> confidentialInterval, uint basePairInterval) { var start = (int)Math.Min(confidentialInterval.Start, -basePairInterval); if (start < 0) { start = -start; } var stop = (uint)Math.Max(confidentialInterval.Stop, basePairInterval); return(position.ConvertPositionToInterval((uint)start, stop)); }
public void InsertIntervalBarelyOverlappingFirstTwoInterval() { var tree = MergedIntervalTree.Create(ExistingIntervals); var target = new InclusiveInterval <uint>(ExistingIntervals[0].Stop, ExistingIntervals[1].Start); tree.Add(target); // insert one, but remove 2 would be net of - 1 MultiAssert.Equal(ExistingIntervals.Count - 1, tree.Count()); MultiAssert.Equal(ExistingIntervals.First().Start, tree.First().Start); // overlapping the two first ones means the second's stop is the stop of first in tree MultiAssert.Equal(ExistingIntervals.Skip(1).First().Stop, tree.First().Stop); MultiAssert.AssertAll(); }
internal static IContigAndInterval CalculateBndBorderInterval([NotNull] this IContigAndPosition position, [NotNull] IContigAndPosition otherPosition, InclusiveInterval <int> confidentInterval, double percentageDistance, uint basepairDistance) { //inter-chromosome breakend var interval = position.Position.CalculateBasePairDistance(confidentInterval, basepairDistance); //intra-chromosome breakend if (position.Contig.Equals(otherPosition.Contig) && position.Position != otherPosition.Position) //Insertion does not count PD as well { interval = position.Position.CalculateBorderInterval( new ClosedOpenInterval <uint>(Math.Min(position.Position, otherPosition.Position), Math.Max(position.Position, otherPosition.Position)), confidentInterval, percentageDistance, basepairDistance); } return(ContigAndInterval.Create(position.Contig, interval.Start, interval.Stop)); }