Fixed a bug where empty intervals were being scattered zero ways parallel. Would be awesome to use the GAE at some point.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5718 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
kshakir 2011-04-29 22:42:48 +00:00
parent 2384e23274
commit 2d81262f87
2 changed files with 71 additions and 4 deletions

View File

@ -30,7 +30,7 @@ import org.broadinstitute.sting.utils.interval.IntervalUtils
import org.broadinstitute.sting.gatk.datasources.reference.ReferenceDataSource
import net.sf.samtools.SAMFileHeader
import java.util.Collections
import org.broadinstitute.sting.utils.GenomeLocParser
import org.broadinstitute.sting.utils.{GenomeLoc, GenomeLocSortedSet, GenomeLocParser}
case class GATKIntervals(reference: File, intervals: List[String]) {
private lazy val referenceDataSource = new ReferenceDataSource(reference)
@ -42,11 +42,15 @@ case class GATKIntervals(reference: File, intervals: List[String]) {
header
}
lazy val locs = {
lazy val locs: List[GenomeLoc] = {
val parser = new GenomeLocParser(referenceDataSource.getReference)
val parsedLocs = IntervalUtils.parseIntervalArguments(parser, intervals, false)
val parsedLocs =
if (intervals.isEmpty)
GenomeLocSortedSet.createSetFromSequenceDictionary(samFileHeader.getSequenceDictionary).toList
else
IntervalUtils.parseIntervalArguments(parser, intervals, false)
Collections.sort(parsedLocs)
parsedLocs
parsedLocs.toList
}
lazy val contigs = locs.map(_.getContig).distinct

View File

@ -0,0 +1,63 @@
/*
* Copyright (c) 2011, 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.queue.extensions.gatk
import java.io.File
import org.testng.Assert
import org.testng.annotations.Test
import org.broadinstitute.sting.BaseTest
import org.broadinstitute.sting.gatk.datasources.reference.ReferenceDataSource
import org.broadinstitute.sting.utils.fasta.CachingIndexedFastaSequenceFile
import org.broadinstitute.sting.utils.{GenomeLocSortedSet, GenomeLocParser}
import collection.JavaConversions._
class GATKIntervalsUnitTest {
private final lazy val reference = new File(BaseTest.hg18Reference)
private final lazy val genomeLocParser = new GenomeLocParser(new CachingIndexedFastaSequenceFile(reference))
private final lazy val referenceLocs = GenomeLocSortedSet.
createSetFromSequenceDictionary(new ReferenceDataSource(reference).getReference.getSequenceDictionary).toList.toList
@Test
def testWithIntervals() {
val chr1 = genomeLocParser.parseGenomeInterval("chr1:1-1")
val chr2 = genomeLocParser.parseGenomeInterval("chr2:2-3")
val chr3 = genomeLocParser.parseGenomeInterval("chr3:3-5")
val gi = new GATKIntervals(reference, List("chr1:1-1", "chr2:2-3", "chr3:3-5"))
Assert.assertEquals(gi.locs, List(chr1, chr2, chr3))
Assert.assertEquals(gi.contigs, List("chr1", "chr2", "chr3"))
Assert.assertEquals(gi.getSplits(2).toList, List(2, 3))
Assert.assertEquals(gi.getSplits(3).toList, List(1, 2, 3))
}
@Test
def testEmptyIntervals() {
val gi = new GATKIntervals(reference, Nil)
Assert.assertEquals(gi.locs, referenceLocs)
Assert.assertEquals(gi.contigs.size, referenceLocs.size)
Assert.assertEquals(gi.getSplits(2).toList, List(10, 45))
Assert.assertEquals(gi.getSplits(4).toList, List(5, 10, 16, 45))
}
}