diff --git a/public/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java b/public/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java index 0e97f30bc..b9d1a55c7 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java +++ b/public/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java @@ -385,7 +385,7 @@ public class GenomeAnalysisEngine { // this was very likely unintentional, the user should be informed of this. Note that this is different // from the case where intervals == null, which indicates either that there were no interval arguments, // or that -L all was specified. - if ( intervals != null && intervals.isEmpty() && argCollection.excludeIntervals != null ) { + if ( intervals != null && intervals.isEmpty() ) { throw new ArgumentException("The given combination of -L and -XL options results in an empty set. " + "No intervals to process."); } diff --git a/public/java/src/org/broadinstitute/sting/utils/interval/IntervalFileMergingIterator.java b/public/java/src/org/broadinstitute/sting/utils/interval/IntervalFileMergingIterator.java deleted file mode 100644 index 063fef7d7..000000000 --- a/public/java/src/org/broadinstitute/sting/utils/interval/IntervalFileMergingIterator.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2010 The Broad Institute - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.broadinstitute.sting.utils.interval; - -import org.broadinstitute.sting.gatk.iterators.PushbackIterator; -import org.broadinstitute.sting.utils.GenomeLoc; -import org.broadinstitute.sting.utils.GenomeLocParser; -import org.broadinstitute.sting.utils.exceptions.UserException; -import org.broadinstitute.sting.utils.text.XReadLines; - -import java.io.File; -import java.io.FileNotFoundException; -import java.util.Iterator; - -/** - * Created by IntelliJ IDEA. - * User: asivache - * Date: Jun 11, 2010 - * Time: 2:56:29 PM - * To change this template use File | Settings | File Templates. - */ - -/** This iterator reads intervals from interval file (can be gatk-style - * interval list or a bed file) and merges them on the fly. Very much alike - * IntervalUtils.sortAndMergeIntervals() but the list is read sequentially - * from a file upon request instead of loading the whole list into memory. - * Intervals in the underlying file MUST be - * pre-sorted into the reference order (they can overlap though, as this - * iterator is a merging one). - */ -public class IntervalFileMergingIterator implements Iterator { - private PushbackIterator it ; - private IntervalMergingRule myRule; - private File myFile; - - public IntervalFileMergingIterator(GenomeLocParser genomeLocParser,File f, IntervalMergingRule rule) { - myFile = f; - - try { - XReadLines reader = new XReadLines(f); - it = new PushbackIterator( new StringToGenomeLocIteratorAdapter( genomeLocParser,reader.iterator() )); - } catch ( FileNotFoundException e ) { - throw new UserException.CouldNotReadInputFile(f, e); - } - myRule = rule; - } - - public boolean hasNext() { - return it.hasNext(); - } - - /** Returns next merged interval from the underlying interval file. In other words, keeps reading intervals - * for as long as they overlap and returns a single merged interval encompassing the set of overlapping - * intervals read from the file. Non-overlapping intervals are returned as is. This method will throw an - * exception if it runs into an interval that is out of order. - * @return - */ - public GenomeLoc next() { - - GenomeLoc current = it.next(); - - while ( it.hasNext() ) { - GenomeLoc next = it.next(); - - if ( next.isBefore(current)) { - throw new UserException.MalformedFile(myFile, "Interval "+next+" in the interval file is out of order."); - } - - if (current.overlapsP(next)) { - current = current.merge(next); - } else if (current.contiguousP(next) && myRule == IntervalMergingRule.ALL) { - current = current.merge(next); - } else { - it.pushback(next); - break; - } - } - - return current; - } - - public void remove() { - throw new UnsupportedOperationException("method 'remove' is not supported by this iterator"); - } - -} diff --git a/public/java/src/org/broadinstitute/sting/utils/interval/NwayIntervalMergingIterator.java b/public/java/src/org/broadinstitute/sting/utils/interval/NwayIntervalMergingIterator.java deleted file mode 100644 index 7e87ce8b5..000000000 --- a/public/java/src/org/broadinstitute/sting/utils/interval/NwayIntervalMergingIterator.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) 2010 The Broad Institute - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.broadinstitute.sting.utils.interval; - -import org.broadinstitute.sting.utils.GenomeLoc; -import org.broadinstitute.sting.utils.exceptions.UserException; - -import java.util.Iterator; -import java.util.PriorityQueue; - -/** - * Created by IntelliJ IDEA. - * User: asivache - * Date: Oct 28, 2010 - * Time: 12:06:23 PM - * To change this template use File | Settings | File Templates. - */ - -/** - * An adapter over a collection of underlying Iterator objects (a single underlying iterator is allowed). Each - * individual underlying iterator must serve its intervals in coordinate-sorted order or an exception will be thrown. - * Intervals from individual underlying streams (iterators) are 1) merged into a single ordered stream; 2) each group of - * overlapping intervals from that merged stream are merged into a single interval; each call to next() returns such - * merged interval guaranteed to have no overlaps with the previous or next interval. - * - */ -public class NwayIntervalMergingIterator implements Iterator, Iterable { - - private PriorityQueue queue = null; - private IntervalMergingRule myRule; - - public NwayIntervalMergingIterator(IntervalMergingRule rule) { - myRule = rule; - queue = new PriorityQueue(); - } - - public void add(Iterator it) { - Element e = new Element(it); - if ( ! e.isEmpty() ) queue.add(e); - } - - public Iterator iterator() { - return this; - } - - /** - * Returns true if the iteration has more elements. (In other - * words, returns true if next would return an element - * rather than throwing an exception.) - * - * @return true if the iterator has more elements. - */ - public boolean hasNext() { - return ! queue.isEmpty(); //To change body of implemented methods use File | Settings | File Templates. - } - - /** - * Returns the next element in the iteration. - * - * @return the next element in the iteration. - * @throws java.util.NoSuchElementException - * iteration has no more elements. - */ - public GenomeLoc next() { - Element e = queue.poll(); - GenomeLoc result = e.current; - - // advance element (i.e. its underlying iterator) and reinsert into the queue - e.advance(); - if ( ! e.isEmpty() ) queue.add(e); - - while ( ! queue.isEmpty () ) { - e = queue.peek(); - - if (result.overlapsP(e.current) || myRule == IntervalMergingRule.ALL && result.contiguousP(e.current)) { - // we need to merge: - result = result.merge(e.current); - - // remove current head of the queue that we just merged into the result: - e = queue.poll(); - // advance element we just merged into the result and reinsert it into the queue (if it has any data left): - e.advance(); - if ( ! e.isEmpty() ) queue.add(e); - - } else { - // next element does not overlap with current result; we are done: return the result and that - // next element will wait for next call to next() - break; - } - - } - return result; //To change body of implemented methods use File | Settings | File Templates. - } - - /** - * Removes from the underlying collection the last element returned by the - * iterator (optional operation). This method can be called only once per - * call to next. The behavior of an iterator is unspecified if - * the underlying collection is modified while the iteration is in - * progress in any way other than by calling this method. - * - * @throws UnsupportedOperationException if the remove - * operation is not supported by this Iterator. - * @throws IllegalStateException if the next method has not - * yet been called, or the remove method has already - * been called after the last call to the next - * method. - */ - public void remove() { - throw new UnsupportedOperationException("remove() method not supported by this iterator"); - } - - private class Element implements Comparable { - private Iterator it; - private GenomeLoc current = null; - - private void advance() { - if ( it.hasNext() ) { - GenomeLoc next = it.next(); - if ( next.isBefore(current) ) { - throw new UserException("Interval list provided by underlying iterator "+it.getClass().getName() +" is out of order"); - } - current = next; - } - else current = null; - } - - public boolean isEmpty() { return current == null; } - - public Element(Iterator it) { - this.it = it; - if ( this.it.hasNext() ) current = this.it.next(); - } - - /** - * Compares this object with the specified object for order. Returns a - * negative integer, zero, or a positive integer as this object is less - * than, equal to, or greater than the specified object. - *

- *

The implementor must ensure sgn(x.compareTo(y)) == - * -sgn(y.compareTo(x)) for all x and y. (This - * implies that x.compareTo(y) must throw an exception iff - * y.compareTo(x) throws an exception.) - *

- *

The implementor must also ensure that the relation is transitive: - * (x.compareTo(y)>0 && y.compareTo(z)>0) implies - * x.compareTo(z)>0. - *

- *

Finally, the implementor must ensure that x.compareTo(y)==0 - * implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for - * all z. - *

- *

It is strongly recommended, but not strictly required that - * (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any - * class that implements the Comparable interface and violates - * this condition should clearly indicate this fact. The recommended - * language is "Note: this class has a natural ordering that is - * inconsistent with equals." - *

- *

In the foregoing description, the notation - * sgn(expression) designates the mathematical - * signum function, which is defined to return one of -1, - * 0, or 1 according to whether the value of - * expression is negative, zero or positive. - * - * @param o the object to be compared. - * @return a negative integer, zero, or a positive integer as this object - * is less than, equal to, or greater than the specified object. - * @throws ClassCastException if the specified object's type prevents it - * from being compared to this object. - */ - public int compareTo(Element o) { - if ( current == null ) return 1; - if ( o.current == null ) return -1; - return current.compareTo(o.current); //To change body of implemented methods use File | Settings | File Templates. - } - } -} diff --git a/public/java/src/org/broadinstitute/sting/utils/interval/StringToGenomeLocIteratorAdapter.java b/public/java/src/org/broadinstitute/sting/utils/interval/StringToGenomeLocIteratorAdapter.java deleted file mode 100644 index aa919b0ea..000000000 --- a/public/java/src/org/broadinstitute/sting/utils/interval/StringToGenomeLocIteratorAdapter.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2010 The Broad Institute - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.broadinstitute.sting.utils.interval; - -import org.broadinstitute.sting.gatk.iterators.PushbackIterator; -import org.broadinstitute.sting.utils.GenomeLoc; -import org.broadinstitute.sting.utils.GenomeLocParser; - -import java.util.Iterator; - -/** - * Created by IntelliJ IDEA. -* User: asivache -* Date: Jun 11, 2010 -* Time: 2:25:42 PM -* To change this template use File | Settings | File Templates. -*/ - -/** - * Wrap this adapter around Iterator to get Iterator. Each string coming from the underlying - * iterator is parsed and converted to GenomeLoc on the fly and the latter is returned on each call to next(). - * This adaptor silently skips empty lines received from the underlying string iterator. - * Two string formats are currently supported: BED and GATK. This iterator will throw an exception if it fails - * to parse a string. - */ -public class StringToGenomeLocIteratorAdapter implements Iterator { - private GenomeLocParser genomeLocParser; - - private PushbackIterator it = null; - - public StringToGenomeLocIteratorAdapter(GenomeLocParser genomeLocParser, Iterator it) { - this.genomeLocParser = genomeLocParser; - this.it = new PushbackIterator(it); - } - - public boolean hasNext() { - String s; - boolean success = false; - - // skip empty lines: - while ( it.hasNext() ) { - s = it.next(); - if ( s.length() != 0 && ! s.matches("^\\s+$")) { - success = true; - it.pushback(s); - break; - } - } - return success; - } - - public GenomeLoc next() { - return genomeLocParser.parseGenomeLoc(it.next()); - } - - public void remove() { - throw new UnsupportedOperationException("method 'remove' is not supported by this iterator"); - } -} diff --git a/public/java/test/org/broadinstitute/sting/utils/interval/IntervalFileMergingIteratorUnitTest.java b/public/java/test/org/broadinstitute/sting/utils/interval/IntervalFileMergingIteratorUnitTest.java deleted file mode 100644 index 6a90c7969..000000000 --- a/public/java/test/org/broadinstitute/sting/utils/interval/IntervalFileMergingIteratorUnitTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2010 The Broad Institute - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.broadinstitute.sting.utils.interval; - -import org.testng.Assert; -import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import org.broadinstitute.sting.BaseTest; -import org.broadinstitute.sting.utils.GenomeLocParser; -import org.broadinstitute.sting.utils.GenomeLoc; -import net.sf.picard.reference.ReferenceSequenceFileFactory; - -import java.io.File; -import java.util.Iterator; -import java.util.List; -import java.util.ArrayList; - -/** - * Created by IntelliJ IDEA. - * User: asivache - * Date: Jun 14, 2010 - * Time: 10:15:52 AM - * To change this template use File | Settings | File Templates. - */ -public class IntervalFileMergingIteratorUnitTest extends BaseTest { - - private static File refFile = new File(validationDataLocation + "Homo_sapiens_assembly17.fasta"); - private static String intervalFileNameGATK = validationDataLocation+"test.gatk.intervals"; - private static List results1 = null; - private static List results2 = null; - - private GenomeLocParser genomeLocParser; - - @BeforeClass - public void init() { - genomeLocParser = new GenomeLocParser(ReferenceSequenceFileFactory.getReferenceSequenceFile(refFile)); - - results1 = new ArrayList(); - results2 = new ArrayList(); - - results1.add(genomeLocParser.createGenomeLoc("chr1",1554)); - results1.add(genomeLocParser.createGenomeLoc("chr1",2538,2568)); - results1.add(genomeLocParser.createGenomeLoc("chr1",18932,19000)); - results1.add(genomeLocParser.createGenomeLoc("chr1",19001,25000)); - results1.add(genomeLocParser.createGenomeLoc("chr5",7415,7600)); - - results2.add(genomeLocParser.createGenomeLoc("chr1",1554)); - results2.add(genomeLocParser.createGenomeLoc("chr1",2538,2568)); - results2.add(genomeLocParser.createGenomeLoc("chr1",18932,25000)); - results2.add(genomeLocParser.createGenomeLoc("chr5",7415,7600)); - - } - - @Test - public void testGATKIntervalFileIterator_Overlap() { - logger.warn("Executing testGATKIntervalFileIterator_Overlap"); - - Iterator it = new IntervalFileMergingIterator(genomeLocParser,new File(intervalFileNameGATK),IntervalMergingRule.OVERLAPPING_ONLY); - Iterator check_it = results1.iterator(); - while(it.hasNext()) { - GenomeLoc l = it.next(); - GenomeLoc l_expected = check_it.next(); - //System.out.println("int: "+l+" expected: "+l_expected) ; - Assert.assertEquals(l_expected, l, "Unexpected location returned by the iterator: "+l); - } - } - - @Test - public void testGATKIntervalFileIterator_OverlapWithException() { - logger.warn("Executing testGATKIntervalFileIterator_OverlapWithException"); - - Iterator it = new IntervalFileMergingIterator(genomeLocParser,new File(intervalFileNameGATK),IntervalMergingRule.OVERLAPPING_ONLY); - Iterator check_it = results1.iterator(); - try { - while(it.hasNext()) { - GenomeLoc l = it.next(); - GenomeLoc l_expected = check_it.next(); -// System.out.println("int: "+l+" expected: "+l_expected) ; - } - } catch ( ReviewedStingException e) { - Assert.assertEquals("Interval chr5:7414 in the interval file is out of order.", e.getMessage()); - } - } - - @Test - public void testGATKIntervalFileIterator_All() { - logger.warn("Executing testGATKIntervalFileIterator_All"); - - Iterator it = new IntervalFileMergingIterator(genomeLocParser,new File(intervalFileNameGATK),IntervalMergingRule.ALL); - Iterator check_it = results2.iterator(); - while(it.hasNext()) { - GenomeLoc l = it.next(); - GenomeLoc l_expected = check_it.next(); -// System.out.println("int: "+l+" expected: "+l_expected) ; - Assert.assertEquals(l_expected, l, "Unexpected location returned by the iterator: "+l); - } - } - -} diff --git a/public/java/test/org/broadinstitute/sting/utils/interval/IntervalIntegrationTest.java b/public/java/test/org/broadinstitute/sting/utils/interval/IntervalIntegrationTest.java index 729b6fa37..d10b96253 100644 --- a/public/java/test/org/broadinstitute/sting/utils/interval/IntervalIntegrationTest.java +++ b/public/java/test/org/broadinstitute/sting/utils/interval/IntervalIntegrationTest.java @@ -25,8 +25,6 @@ package org.broadinstitute.sting.utils.interval; import org.broadinstitute.sting.WalkerTest; -import org.broadinstitute.sting.commandline.ArgumentException; -import org.broadinstitute.sting.utils.exceptions.UserException; import org.testng.annotations.Test; import java.io.File; @@ -194,7 +192,7 @@ public class IntervalIntegrationTest extends WalkerTest { } @Test(enabled = true, expectedExceptions = RuntimeException.class) - public void testEmptyVCFError() { + public void testEmptyVCFNoUnsafe() { String md5 = ""; WalkerTest.WalkerTestSpec spec = new WalkerTest.WalkerTestSpec( "-T CountLoci" + @@ -207,8 +205,8 @@ public class IntervalIntegrationTest extends WalkerTest { executeTest("testEmptyVCFError", spec); } - @Test(enabled = true) - public void testEmptyVCFNoError() { + @Test(enabled = true, expectedExceptions = RuntimeException.class) + public void testEmptyVCFWithUnsafe() { String md5 = ""; WalkerTest.WalkerTestSpec spec = new WalkerTest.WalkerTestSpec( "-T CountLoci" + diff --git a/public/java/test/org/broadinstitute/sting/utils/interval/NwayIntervalMergingIteratorUnitTest.java b/public/java/test/org/broadinstitute/sting/utils/interval/NwayIntervalMergingIteratorUnitTest.java deleted file mode 100644 index 0b4e52a3d..000000000 --- a/public/java/test/org/broadinstitute/sting/utils/interval/NwayIntervalMergingIteratorUnitTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2010, The Broad Institute - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.broadinstitute.sting.utils.interval; - -import org.broadinstitute.sting.BaseTest; -import org.broadinstitute.sting.utils.GenomeLocParser; -import org.broadinstitute.sting.utils.GenomeLoc; -import net.sf.picard.reference.ReferenceSequenceFileFactory; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.util.ArrayList; -import java.util.List; -import java.util.Iterator; -import java.io.File; - -/** - * Created by IntelliJ IDEA. - * User: asivache - * Date: Oct 28, 2010 - * Time: 2:46:03 PM - * To change this template use File | Settings | File Templates. - */ -public class NwayIntervalMergingIteratorUnitTest extends BaseTest { - - private static File refFile = new File(validationDataLocation + "Homo_sapiens_assembly17.fasta"); - private GenomeLocParser genomeLocParser; - - private static List stream1 = null; - private static List stream2 = null; - private static List expected = null; - - @BeforeClass - public static void init() { - GenomeLocParser genomeLocParser = new GenomeLocParser(ReferenceSequenceFileFactory.getReferenceSequenceFile(refFile)); - - stream1 = new ArrayList(); - stream2 = new ArrayList(); - expected = new ArrayList(); - - stream1.add(genomeLocParser.createGenomeLoc("chr1",1554,1560)); // 1 - stream1.add(genomeLocParser.createGenomeLoc("chr1",2538,2568)); // 3 - stream1.add(genomeLocParser.createGenomeLoc("chr1",2600,2610)); // 4 - stream1.add(genomeLocParser.createGenomeLoc("chr1",2609,2625)); // 4 - stream1.add(genomeLocParser.createGenomeLoc("chr1",18932,19000)); // 6 - stream1.add(genomeLocParser.createGenomeLoc("chr1",19001,25000)); //6 - - stream2.add(genomeLocParser.createGenomeLoc("chr1",1565,1570)); //2 - stream2.add(genomeLocParser.createGenomeLoc("chr1",2598,2604)); // 4 - stream2.add(genomeLocParser.createGenomeLoc("chr1",7415,7600)); // 5 - stream2.add(genomeLocParser.createGenomeLoc("chr1",18932,25000)); // 6 - stream2.add(genomeLocParser.createGenomeLoc("chr1",30000,35000)); // 7 - - expected.add(genomeLocParser.createGenomeLoc("chr1",1554,1560)); // 1 - expected.add(genomeLocParser.createGenomeLoc("chr1",1565,1570)); //2 - expected.add(genomeLocParser.createGenomeLoc("chr1",2538,2568)); // 3 - expected.add(genomeLocParser.createGenomeLoc("chr1",2598,2625)); // 4 - expected.add(genomeLocParser.createGenomeLoc("chr1",7415,7600)); // 5 - expected.add(genomeLocParser.createGenomeLoc("chr1",18932,25000)); // 6 - expected.add(genomeLocParser.createGenomeLoc("chr1",30000,35000)); // 7 - - - } - - @Test - public void testNwayIntervalMergingIterator() { - logger.warn("testNwayIntervalMergingIterator"); - - Iterator it1 = stream1.iterator(); - Iterator it2 = stream2.iterator(); - - Iterator e_it = expected.iterator(); - - - - NwayIntervalMergingIterator it = new NwayIntervalMergingIterator(IntervalMergingRule.OVERLAPPING_ONLY); - it.add(it1); - it.add(it2); - - while(it.hasNext()) { - GenomeLoc l = it.next(); - GenomeLoc l_expected = e_it.next(); - //System.out.println("int: "+l+" expected: "+l_expected) ; - Assert.assertEquals(l,l_expected,"Unexpected location returned by the iterator: "+l); - } - } - - -}