/** * A utility function for subtracting a collection of IntervalLists from another. Resulting loci are those that are in the first collection * but not the second. * * @param lhs the collection of IntervalList from which to subtract intervals * @param rhs the collection of intervals to subtract * @return an IntervalList comprising all loci that are in the first collection but not the second lhs-rhs=answer. */ public static IntervalList subtract(final Collection<IntervalList> lhs, final Collection<IntervalList> rhs) { return intersection( union(lhs), invert(union(rhs))); }
/** * A utility function for subtracting a collection of IntervalLists from another. Resulting loci are those that are in the first collection * but not the second. * * @param listsToSubtractFrom the collection of IntervalList from which to subtract intervals * @param listsToSubtract the collection of intervals to subtract * @return an IntervalLists comprising all loci that are in first collection but not second. */ public static IntervalList subtract(final Collection<IntervalList> listsToSubtractFrom, final Collection<IntervalList> listsToSubtract) { return intersection( union(listsToSubtractFrom), invert(union(listsToSubtract))); }
/** * A utility function for subtracting a collection of IntervalLists from another. Resulting loci are those that are in the first collection * but not the second. * * @param lhs the collection of IntervalList from which to subtract intervals * @param rhs the collection of intervals to subtract * @return an IntervalList comprising all loci that are in the first collection but not the second lhs-rhs=answer. */ public static IntervalList subtract(final Collection<IntervalList> lhs, final Collection<IntervalList> rhs) { return intersection( union(lhs), invert(union(rhs))); }
@Test(dataProvider = "invertData") public void testInvert(final IntervalList list, final IntervalList inverse) throws Exception { Assert.assertEquals( CollectionUtil.makeCollection(IntervalList.invert(list).iterator()), CollectionUtil.makeCollection(inverse.iterator())); }
@Test(dataProvider = "invertData") public void testInvertSquared(final IntervalList list, @SuppressWarnings("UnusedParameters") final IntervalList ignored) throws Exception { final IntervalList inverseSquared = IntervalList.invert(IntervalList.invert(list)); final IntervalList originalClone = new IntervalList(list.getHeader()); for (final Interval interval : list) { originalClone.add(interval); } Assert.assertEquals( CollectionUtil.makeCollection(inverseSquared.iterator()), CollectionUtil.makeCollection(originalClone.uniqued().iterator())); }
final IntervalList possiblyInvertedResult = INVERT ? IntervalList.invert(possiblySortedResult) : possiblySortedResult;
final IntervalList possiblyInvertedResult = INVERT ? IntervalList.invert(possiblySortedResult) : possiblySortedResult;
@Test(dataProvider = "VCFCompData") public void testFromVCF(final Path vcf, final Path compInterval, final boolean invertVCF) { final IntervalList compList = IntervalList.fromPath(compInterval); final IntervalList list = invertVCF ? IntervalList.invert(VCFFileReader.toIntervalList(vcf)) : VCFFileReader.toIntervalList(vcf); compList.getHeader().getSequenceDictionary().assertSameDictionary(list.getHeader().getSequenceDictionary()); final Collection<Interval> intervals = CollectionUtil.makeCollection(list.iterator()); final Collection<Interval> compIntervals = CollectionUtil.makeCollection(compList.iterator()); //assert that the intervals correspond Assert.assertEquals(intervals, compIntervals); final List<String> intervalNames = new LinkedList<>(); final List<String> compIntervalNames = new LinkedList<>(); for (final Interval interval : intervals) { intervalNames.add(interval.getName()); } for (final Interval interval : compIntervals) { compIntervalNames.add(interval.getName()); } //assert that the names match Assert.assertEquals(intervalNames, compIntervalNames); }
@Test(dataProvider = "VCFCompData") public void testFromVCFWithPath(final Path vcf, final Path compInterval, final boolean invertVCF) { final IntervalList compList = IntervalList.fromPath(compInterval); final IntervalList list = invertVCF ? IntervalList.invert(VCFFileReader.toIntervalList(vcf)) : VCFFileReader.toIntervalList(vcf); compList.getHeader().getSequenceDictionary().assertSameDictionary(list.getHeader().getSequenceDictionary()); final Collection<Interval> intervals = CollectionUtil.makeCollection(list.iterator()); final Collection<Interval> compIntervals = CollectionUtil.makeCollection(compList.iterator()); //assert that the intervals correspond Assert.assertEquals(intervals, compIntervals); final List<String> intervalNames = new LinkedList<>(); final List<String> compIntervalNames = new LinkedList<>(); for (final Interval interval : intervals) { intervalNames.add(interval.getName()); } for (final Interval interval : compIntervals) { compIntervalNames.add(interval.getName()); } //assert that the names match Assert.assertEquals(intervalNames, compIntervalNames); }
SCATTER_MANY_INTERVAL_FILE, 2, IntervalListScatterMode.INTERVAL_COUNT, Arrays.asList(IntervalList.overlaps(LIST_TO_SCATTER_MANY, half), IntervalList.overlaps(LIST_TO_SCATTER_MANY, IntervalList.invert(half))))); IntervalList.overlaps(LIST_TO_SCATTER_MANY, IntervalList.invert(IntervalList.concatenate(Arrays.asList( IntervalList.overlaps(LIST_TO_SCATTER_MANY, third), IntervalList.overlaps(LIST_TO_SCATTER_MANY, secondThird))
new Object[]{list1, IntervalList.invert(list1), new IntervalList(list1.getHeader())}, // should be empty new Object[]{list2, list1, two_overlaps_one}, new Object[]{list3, list2, three_overlaps_two},