Clean up the code a bit following the introduction of reduceByInterval.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2887 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
199b43fcf2
commit
553d39bb00
|
|
@ -47,7 +47,7 @@ public class AllLocusView extends LocusView {
|
|||
public AllLocusView(ShardDataProvider provider) {
|
||||
super( provider );
|
||||
// Seed the state tracking members with the first possible seek position and the first possible locus context.
|
||||
locusIterator = new GenomeLocusIterator( Collections.singletonList(provider.getLocus()) );
|
||||
locusIterator = new GenomeLocusIterator(provider.getLocus());
|
||||
if( locusIterator.hasNext() ) {
|
||||
nextPosition = locusIterator.next();
|
||||
nextLocus = hasNextLocus() ? nextLocus() : createEmptyLocus(nextPosition);
|
||||
|
|
|
|||
|
|
@ -66,20 +66,7 @@ public class IndexDelimitedLocusShardStrategy implements ShardStrategy {
|
|||
throw new StingException("Cannot power an IndexDelimitedLocusShardStrategy with this data source.");
|
||||
|
||||
blockDrivenDataSource = (BlockDrivenSAMDataSource)dataSource;
|
||||
|
||||
// Create a list of contig name -> genome loc, sorted in INSERTION ORDER.
|
||||
LinkedHashMap<String,List<GenomeLoc>> locationToReference = new LinkedHashMap<String,List<GenomeLoc>>();
|
||||
for(GenomeLoc location: locations) {
|
||||
if(!locationToReference.containsKey(location.getContig()))
|
||||
locationToReference.put(location.getContig(),new ArrayList<GenomeLoc>());
|
||||
locationToReference.get(location.getContig()).add(location);
|
||||
}
|
||||
|
||||
// TODO: Not sure there's any reason to pre-separate the contigs now that we're using a streaming approach to file pointer allocation.
|
||||
for(String contig: locationToReference.keySet()) {
|
||||
filePointers.addAll(batchLociIntoBins(locationToReference.get(contig),blockDrivenDataSource.getNumIndexLevels()-1));
|
||||
}
|
||||
|
||||
filePointers.addAll(batchLociIntoBins(locations.toList(),blockDrivenDataSource.getNumIndexLevels()-1));
|
||||
filePointerIterator = filePointers.iterator();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import org.broadinstitute.sting.utils.GenomeLocParser;
|
|||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
/**
|
||||
* User: hanna
|
||||
* Date: May 12, 2009
|
||||
|
|
@ -24,28 +23,24 @@ import java.util.List;
|
|||
*/
|
||||
public class GenomeLocusIterator implements Iterator<GenomeLoc> {
|
||||
/**
|
||||
* An iterator to the entire data structure over which we're iterating.
|
||||
* The entire region over which we're iterating.
|
||||
*/
|
||||
private final Iterator<GenomeLoc> locusIterator;
|
||||
private GenomeLoc completeLocus;
|
||||
|
||||
/**
|
||||
* The multi-base pair long locus referring to the current locus.
|
||||
* The current position in the traversal.
|
||||
*/
|
||||
private GenomeLoc currentLocus = null;
|
||||
|
||||
/**
|
||||
* The 1 base pair long location.
|
||||
*/
|
||||
private GenomeLoc currentLocation = null;
|
||||
private GenomeLoc currentLocus;
|
||||
|
||||
/**
|
||||
* Creates an iterator that can traverse over the entire
|
||||
* reference specified in the given ShardDataProvider.
|
||||
* @param loci the list of loci over which to iterate.
|
||||
* @param completeLocus Data provider to use as a backing source.
|
||||
* Provider must have a reference (hasReference() == true).
|
||||
*/
|
||||
public GenomeLocusIterator( List<GenomeLoc> loci ) {
|
||||
this.locusIterator = loci.iterator();
|
||||
seedNextLocus();
|
||||
public GenomeLocusIterator( GenomeLoc completeLocus ) {
|
||||
this.completeLocus = completeLocus;
|
||||
this.currentLocus = GenomeLocParser.createGenomeLoc(completeLocus.getContig(),completeLocus.getStart());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -53,7 +48,7 @@ public class GenomeLocusIterator implements Iterator<GenomeLoc> {
|
|||
* @return True if the iterator has more elements. False otherwise.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return currentLocation != null;
|
||||
return !currentLocus.isPast(completeLocus);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -63,29 +58,12 @@ public class GenomeLocusIterator implements Iterator<GenomeLoc> {
|
|||
public GenomeLoc next() {
|
||||
if( !hasNext() )
|
||||
throw new NoSuchElementException("No elements remaining in bounded reference region.");
|
||||
GenomeLoc toReturn = currentLocation.clone();
|
||||
seedNextLocus();
|
||||
GenomeLoc toReturn = (GenomeLoc)currentLocus.clone();
|
||||
currentLocus = GenomeLocParser.incPos(currentLocus);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException( "ReferenceLocusIterator is read-only" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Position currentLocation at the next locus, if possible.
|
||||
*/
|
||||
private void seedNextLocus() {
|
||||
if(currentLocus != null && currentLocation != null)
|
||||
currentLocation = GenomeLocParser.incPos(currentLocation);
|
||||
|
||||
// If initializing or the location was pushed off the current locus, reinitialize using the next locus.
|
||||
if(currentLocus == null || currentLocation == null || currentLocation.isPast(currentLocus)) {
|
||||
currentLocus = currentLocation = null;
|
||||
if(locusIterator.hasNext()){
|
||||
currentLocus = locusIterator.next();
|
||||
currentLocation = GenomeLocParser.createGenomeLoc(currentLocus.getContig(),currentLocus.getStart());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,9 +89,9 @@ public class LocusReferenceViewTest extends ReferenceViewTemplate {
|
|||
*/
|
||||
protected void validateLocation( GenomeLoc loc ) {
|
||||
Shard shard = new LocusShard(Collections.singletonList(loc));
|
||||
GenomeLocusIterator shardIterator = new GenomeLocusIterator(shard.getGenomeLocs());
|
||||
GenomeLocusIterator shardIterator = new GenomeLocusIterator(loc);
|
||||
|
||||
ShardDataProvider dataProvider = new ShardDataProvider(shard, shard.getGenomeLocs().get(0), null, sequenceFile, null);
|
||||
ShardDataProvider dataProvider = new ShardDataProvider(shard, loc, null, sequenceFile, null);
|
||||
LocusReferenceView view = new LocusReferenceView(dataProvider);
|
||||
|
||||
while (shardIterator.hasNext()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue