From 88a48821ea238e15393d22a1cc9fdc2a3866ce6b Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 12 Mar 2010 22:35:49 +0000 Subject: [PATCH] removed the dependence on removeRegion() in GenomeLocSortedSet git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2993 348d0f76-0448-11de-a6fe-93d51630548a --- .../shards/IntervalShardStrategy.java | 2 +- .../shards/LocusShardStrategy.java | 30 ++++++++----------- .../sting/utils/GenomeLocSortedSet.java | 9 ++++++ .../shards/LinearLocusShardStrategyTest.java | 2 +- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/shards/IntervalShardStrategy.java b/java/src/org/broadinstitute/sting/gatk/datasources/shards/IntervalShardStrategy.java index 51d18f728..8eb2c750d 100755 --- a/java/src/org/broadinstitute/sting/gatk/datasources/shards/IntervalShardStrategy.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/shards/IntervalShardStrategy.java @@ -94,7 +94,7 @@ public class IntervalShardStrategy implements ShardStrategy { // get the first region in the list GenomeLoc loc = regions.iterator().next(); - regions.removeRegion(loc); + regions.remove(loc); return new IntervalShard(loc,type); } diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/shards/LocusShardStrategy.java b/java/src/org/broadinstitute/sting/gatk/datasources/shards/LocusShardStrategy.java index 8add18a33..68245cc1d 100755 --- a/java/src/org/broadinstitute/sting/gatk/datasources/shards/LocusShardStrategy.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/shards/LocusShardStrategy.java @@ -62,7 +62,7 @@ public abstract class LocusShardStrategy implements ShardStrategy { * * @param dic the seq dictionary */ - LocusShardStrategy( SAMSequenceDictionary dic ) { + LocusShardStrategy(SAMSequenceDictionary dic) { this.dic = dic; limitingFactor = -1; mLoc = GenomeLocParser.createGenomeLoc(0, 0, 0); @@ -76,7 +76,7 @@ public abstract class LocusShardStrategy implements ShardStrategy { * * @param old the old strategy */ - LocusShardStrategy( LocusShardStrategy old ) { + LocusShardStrategy(LocusShardStrategy old) { this.dic = old.dic; this.mLoc = old.mLoc; this.seqLoc = old.seqLoc; @@ -92,7 +92,7 @@ public abstract class LocusShardStrategy implements ShardStrategy { * @param dic the seq dictionary * @param intervals file */ - LocusShardStrategy( SAMSequenceDictionary dic, GenomeLocSortedSet intervals ) { + LocusShardStrategy(SAMSequenceDictionary dic, GenomeLocSortedSet intervals) { this.dic = dic; this.intervals = intervals.clone(); // set the starting point to the beginning interval @@ -152,7 +152,7 @@ public abstract class LocusShardStrategy implements ShardStrategy { if (this.intervals == null) { return nonIntervaledNext(length, proposedSize, nextStart); } else { - return intervaledNext(proposedSize); + return intervaledNext(); } } @@ -160,26 +160,20 @@ public abstract class LocusShardStrategy implements ShardStrategy { /** * Interval based next processing * - * @param proposedSize the proposed size * * @return the shard that represents this data */ - private Shard intervaledNext( long proposedSize ) { - if (( this.intervals == null ) || ( intervals.isEmpty() )) { + private Shard intervaledNext() { + if ((this.intervals == null) || (intervals.isEmpty())) { throw new StingException("LocusShardStrategy: genomic regions list is empty in next() function."); } // get the first region in the list GenomeLoc loc = intervals.iterator().next(); - if (loc.getStop() - loc.getStart() <= proposedSize) { - intervals.removeRegion(loc); - return new IntervalShard(loc,Shard.ShardType.LOCUS_INTERVAL); - } else { - GenomeLoc subLoc = GenomeLocParser.createGenomeLoc(loc.getContigIndex(), loc.getStart(), loc.getStart() + proposedSize - 1); - intervals.removeRegion(subLoc); - return new IntervalShard(subLoc,Shard.ShardType.LOCUS_INTERVAL); - } + intervals.remove(loc); + return new IntervalShard(loc, Shard.ShardType.LOCUS_INTERVAL); + } /** @@ -191,7 +185,7 @@ public abstract class LocusShardStrategy implements ShardStrategy { * * @return the shard to return to the user */ - private Shard nonIntervaledNext( long length, long proposedSize, long nextStart ) { + private Shard nonIntervaledNext(long length, long proposedSize, long nextStart) { // can we fit it into the current seq size? if (nextStart + proposedSize - 1 < length) { lastGenomeLocSize = proposedSize; @@ -223,7 +217,7 @@ public abstract class LocusShardStrategy implements ShardStrategy { private void jumpContig() { ++seqLoc; - if (!( seqLoc < dic.getSequences().size() )) { + if (!(seqLoc < dic.getSequences().size())) { nextContig = false; return; } @@ -246,7 +240,7 @@ public abstract class LocusShardStrategy implements ShardStrategy { if (this.intervals == null) { return nextContig; } else { - return ( this.intervals.size() > 0 ); + return (this.intervals.size() > 0); } } diff --git a/java/src/org/broadinstitute/sting/utils/GenomeLocSortedSet.java b/java/src/org/broadinstitute/sting/utils/GenomeLocSortedSet.java index 22aeeae65..5663dfc6e 100755 --- a/java/src/org/broadinstitute/sting/utils/GenomeLocSortedSet.java +++ b/java/src/org/broadinstitute/sting/utils/GenomeLocSortedSet.java @@ -223,6 +223,15 @@ public class GenomeLocSortedSet extends AbstractSet { return returnValue; } + /** + * a simple removal of an interval contained in this list. The interval must be identical to one in the list (no partial locations or overlapping) + * @param location the GenomeLoc to remove + */ + public void remove(GenomeLoc location) { + if (!mArray.contains(location)) throw new IllegalArgumentException("Unable to remove location: " + location + ", not in the list"); + mArray.remove(location); + } + /** * create a list of genomic locations, given a reference sequence * diff --git a/java/test/org/broadinstitute/sting/gatk/datasources/shards/LinearLocusShardStrategyTest.java b/java/test/org/broadinstitute/sting/gatk/datasources/shards/LinearLocusShardStrategyTest.java index 3f8c422a5..dfe5aa6bf 100755 --- a/java/test/org/broadinstitute/sting/gatk/datasources/shards/LinearLocusShardStrategyTest.java +++ b/java/test/org/broadinstitute/sting/gatk/datasources/shards/LinearLocusShardStrategyTest.java @@ -113,7 +113,7 @@ public class LinearLocusShardStrategyTest extends BaseTest { Shard d = strat.next(); assertTrue(d instanceof LocusShard); assertEquals("Sharding strategy must emit single locus shards",1,d.getGenomeLocs().size()); - assertTrue((d.getGenomeLocs().get(0).getStop() - d.getGenomeLocs().get(0).getStart()) == 199); + assertEquals(199,(d.getGenomeLocs().get(0).getStop() - d.getGenomeLocs().get(0).getStart())); ++counter; } assertTrue(counter == 1);