Cleaning up the inheritance hierarchy from the previous commit.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2738 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
hanna 2010-01-29 19:13:36 +00:00
parent 88495a39d4
commit e7f5c93fe5
12 changed files with 84 additions and 94 deletions

View File

@ -41,7 +41,7 @@ import java.net.URL;
* Internal class for reading and querying BAM files.
*/
class BAMFileReader2
extends SAMFileReader2.ReaderImplementation2 {
extends SAMFileReader.ReaderImplementation {
// True if reading from a File rather than an InputStream
private boolean mIsSeekable = false;
// For converting bytes into other primitive types

View File

@ -62,14 +62,6 @@ public class SAMFileReader2 implements Iterable<SAMRecord> {
private ReaderImplementation mReader = null;
private File samFile = null;
/**
* Internal interface for SAM/BAM file reader implementations.
* Implemented as an abstract class to enforce better access control.
*/
static abstract class ReaderImplementation2 extends SAMFileReader.ReaderImplementation {
abstract CloseableIterator<SAMRecord> getIterator(List<Chunk> chunks);
}
/**
* Prepare to read a SAM or BAM file. Indexed lookup not allowed because reading from InputStream.
*/
@ -200,14 +192,14 @@ public class SAMFileReader2 implements Iterable<SAMRecord> {
public CloseableIterator<SAMRecord> iterator(List<Chunk> chunks) {
// TODO: Add sanity checks so that we're not doing this against a BAM file.
if(!(mReader instanceof BAMFileReader2))
throw new PicardException("This call requires a ReaderImplementation2-compliant interface");
throw new PicardException("This call cannot be performed without a backing BAMFileReader2");
return ((BAMFileReader2)mReader).getIterator(chunks);
}
public List<Chunk> getOverlappingFilePointers(final String sequence, final int start, final int end) {
// TODO: Add sanity checks so that we're not doing this against a BAM file.
if(!(mReader instanceof BAMFileReader2))
throw new PicardException("This call requires a ReaderImplementation2-compliant interface");
throw new PicardException("This call cannot be performed without a backing BAMFileReader2");
return ((BAMFileReader2)mReader).getOverlappingFilePointers(sequence,start,end);
}

View File

@ -0,0 +1,19 @@
package org.broadinstitute.sting.gatk.datasources.shards;
import net.sf.samtools.Chunk;
import java.util.List;
/**
* A common interface for shards that natively understand the BAM format.
*
* @author mhanna
* @version 0.1
*/
public interface BAMFormatAwareShard extends Shard {
/**
* Get the list of chunks delimiting this shard.
* @return a list of chunks that contain data for this shard.
*/
public List<Chunk> getChunks();
}

View File

@ -10,7 +10,7 @@ import java.util.List;
* @author mhanna
* @version 0.1
*/
public class BlockDelimitedReadShard extends ReadShard {
public class BlockDelimitedReadShard extends ReadShard implements BAMFormatAwareShard {
/**
* The list of chunks to retrieve when loading this shard.
*/

View File

@ -2,6 +2,7 @@ package org.broadinstitute.sting.gatk.datasources.shards;
import org.broadinstitute.sting.utils.GenomeLoc;
import org.broadinstitute.sting.utils.GenomeLocSortedSet;
import org.broadinstitute.sting.utils.StingException;
import net.sf.samtools.Chunk;
import java.util.List;
@ -35,29 +36,30 @@ import java.util.List;
/**
* A shard that's delimited based on the index rather than
*/
public class IndexDelimitedLocusShard implements Shard {
/**
* a collection of genomic locations to interate over
*/
private final GenomeLocSortedSet intervals;
public class IndexDelimitedLocusShard extends LocusShard implements BAMFormatAwareShard {
/**
* A list of the chunks associated with this shard.
*/
private final List<Chunk> chunks;
IndexDelimitedLocusShard(GenomeLocSortedSet intervals, List<Chunk> chunks) {
this.intervals = intervals;
this.chunks = chunks;
}
/**
* An IndexDelimitedLocusShard can be used either for LOCUS or LOCUS_INTERVAL shard types.
* Track which type is being used.
*/
private final ShardType shardType;
/**
* The locations represented by this shard.
* @return the genome location represented by this shard
* Create a new locus shard, divided by index.
* @param intervals List of intervals to process.
* @param chunks Chunks associated with that interval.
* @param shardType Type of the shard; must be either LOCUS or LOCUS_INTERVAL.
*/
public List<GenomeLoc> getGenomeLocs() {
return intervals.toList();
IndexDelimitedLocusShard(List<GenomeLoc> intervals, List<Chunk> chunks, ShardType shardType) {
super(intervals);
this.chunks = chunks;
if(shardType != ShardType.LOCUS && shardType != ShardType.LOCUS_INTERVAL)
throw new StingException("Attempted to create an IndexDelimitedLocusShard with invalid shard type: " + shardType);
this.shardType = shardType;
}
/**
@ -69,19 +71,10 @@ public class IndexDelimitedLocusShard implements Shard {
}
/**
* returns the type of shard, LOCUS_INTERVAL.
* @return LOCUS_INTERVAL, indicating the shard type
*/
public ShardType getShardType() {
return ShardType.LOCUS_INTERVAL;
}
/**
* String representation of this shard.
* @return A string representation of the boundaries of this shard.
* returns the type of shard.
*/
@Override
public String toString() {
return intervals.toString();
public ShardType getShardType() {
return shardType;
}
}

View File

@ -78,7 +78,7 @@ public class IndexDelimitedLocusShardStrategy implements ShardStrategy {
List<Chunk> filePointers = locations.get(loc);
locations.remove(loc);
return new IndexDelimitedLocusShard(GenomeLocSortedSet.createSetFromList(Arrays.asList(loc)),filePointers);
return new IndexDelimitedLocusShard(Collections.singletonList(loc),filePointers,Shard.ShardType.LOCUS_INTERVAL);
}
/** we don't support the remove command */

View File

@ -1,6 +1,7 @@
package org.broadinstitute.sting.gatk.datasources.shards;
import org.broadinstitute.sting.utils.GenomeLoc;
import org.broadinstitute.sting.utils.Utils;
import java.util.Collections;
import java.util.List;
@ -34,17 +35,16 @@ import java.util.List;
* in place so it's easier to change guts later.
*/
public class LocusShard implements Shard {
// currently our location
final GenomeLoc mLoc;
final List<GenomeLoc> loci;
public LocusShard(GenomeLoc loc) {
this.mLoc = loc;
public LocusShard(List<GenomeLoc> loci) {
this.loci = loci;
}
/** @return the genome location represented by this shard */
public List<GenomeLoc> getGenomeLocs() {
return Collections.singletonList(mLoc);
return loci;
}
/**
@ -56,21 +56,12 @@ public class LocusShard implements Shard {
return ShardType.LOCUS;
}
/**
* return a shard representing the passed in GenomeLoc
*
* @return
*/
public static LocusShard toShard(GenomeLoc loc) {
return new LocusShard(loc);
}
/**
* String representation of this shard.
* @return A string representation of the boundaries of this shard.
*/
@Override
public String toString() {
return mLoc.toString();
return Utils.join(";",loci);
}
}

View File

@ -8,6 +8,7 @@ import org.broadinstitute.sting.utils.StingException;
import org.broadinstitute.sting.utils.GenomeLocParser;
import java.util.Iterator;
import java.util.Collections;
/**
*
* User: aaron
@ -195,7 +196,7 @@ public abstract class LocusShardStrategy implements ShardStrategy {
if (nextStart + proposedSize - 1 < length) {
lastGenomeLocSize = proposedSize;
mLoc = GenomeLocParser.createGenomeLoc(dic.getSequence(seqLoc).getSequenceIndex(), nextStart, nextStart + proposedSize - 1);
return LocusShard.toShard(mLoc);
return new LocusShard(Collections.singletonList(mLoc));
}
// else we can't make it in the current location, we have to stitch one together
else {
@ -208,7 +209,7 @@ public abstract class LocusShardStrategy implements ShardStrategy {
// move to the next contig
// the next sequence should start at the begining of the next contig
Shard ret = LocusShard.toShard(GenomeLocParser.createGenomeLoc(dic.getSequence(seqLoc).getSequenceIndex(), nextStart, nextStart + lastGenomeLocSize - 1));
Shard ret = new LocusShard(Collections.singletonList(GenomeLocParser.createGenomeLoc(dic.getSequence(seqLoc).getSequenceIndex(), nextStart, nextStart + lastGenomeLocSize - 1)));
// now jump ahead to the next contig
jumpContig();

View File

@ -49,27 +49,19 @@ public class BlockDrivenSAMDataSource extends SAMDataSource {
}
public StingSAMIterator seek(Shard shard) {
if(!(shard instanceof BlockDelimitedReadShard) && !(shard instanceof IndexDelimitedLocusShard))
throw new StingException("BlockDrivenSAMDataSource cannot operate on shards of type: " + shard);
if(!(shard instanceof BAMFormatAwareShard))
throw new StingException("BlockDrivenSAMDataSource cannot operate on shards of type: " + shard.getClass());
if(shard instanceof ReadShard) {
CloseableIterator<SAMRecord> iterator = reader.iterator(((BlockDelimitedReadShard)shard).getChunks());
return applyDecoratingIterators(true,
StingSAMIteratorAdapter.adapt(reads, iterator),
reads.getDownsamplingFraction(),
reads.getValidationExclusionList().contains(ValidationExclusion.TYPE.NO_READ_ORDER_VERIFICATION),
reads.getSupplementalFilters());
}
else if(shard instanceof IndexDelimitedLocusShard) {
CloseableIterator<SAMRecord> iterator = reader.iterator(((IndexDelimitedLocusShard)shard).getChunks());
return applyDecoratingIterators(false,
StingSAMIteratorAdapter.adapt(reads, iterator),
reads.getDownsamplingFraction(),
reads.getValidationExclusionList().contains(ValidationExclusion.TYPE.NO_READ_ORDER_VERIFICATION),
reads.getSupplementalFilters());
}
// Since the beginning of time for the GATK, enableVerification has been true only for ReadShards. I don't
// know why this is. Please add a comment here if you do.
boolean enableVerification = shard instanceof ReadShard;
throw new UnsupportedOperationException("Unable to infer type of this shard.");
CloseableIterator<SAMRecord> iterator = reader.iterator(((BAMFormatAwareShard)shard).getChunks());
return applyDecoratingIterators(enableVerification,
StingSAMIteratorAdapter.adapt(reads,iterator),
reads.getDownsamplingFraction(),
reads.getValidationExclusionList().contains(ValidationExclusion.TYPE.NO_READ_ORDER_VERIFICATION),
reads.getSupplementalFilters());
}
/**

View File

@ -11,6 +11,8 @@ import org.broadinstitute.sting.gatk.iterators.GenomeLocusIterator;
import net.sf.picard.reference.ReferenceSequence;
import net.sf.samtools.util.StringUtil;
import java.util.Collections;
/*
* Copyright (c) 2009 The Broad Institute
*
@ -54,7 +56,7 @@ public class LocusReferenceViewTest extends ReferenceViewTemplate {
@Test
public void testOverlappingReferenceBases() {
Shard shard = new LocusShard(GenomeLocParser.createGenomeLoc(0, sequenceFile.getSequence("chrM").length() - 10, sequenceFile.getSequence("chrM").length()));
Shard shard = new LocusShard(Collections.singletonList(GenomeLocParser.createGenomeLoc(0, sequenceFile.getSequence("chrM").length() - 10, sequenceFile.getSequence("chrM").length())));
ShardDataProvider dataProvider = new ShardDataProvider(shard, null, sequenceFile, null);
LocusReferenceView view = new LocusReferenceView(dataProvider);
@ -71,7 +73,7 @@ public class LocusReferenceViewTest extends ReferenceViewTemplate {
/** Queries outside the bounds of the shard should generate an error. */
@Test(expected = InvalidPositionException.class)
public void testBoundsFailure() {
Shard shard = new LocusShard(GenomeLocParser.createGenomeLoc(0, 1, 50));
Shard shard = new LocusShard(Collections.singletonList(GenomeLocParser.createGenomeLoc(0, 1, 50)));
ShardDataProvider dataProvider = new ShardDataProvider(shard, null, sequenceFile, null);
LocusReferenceView view = new LocusReferenceView(dataProvider);
@ -86,7 +88,7 @@ public class LocusReferenceViewTest extends ReferenceViewTemplate {
* @param loc
*/
protected void validateLocation( GenomeLoc loc ) {
Shard shard = new LocusShard(loc);
Shard shard = new LocusShard(Collections.singletonList(loc));
GenomeLocusIterator shardIterator = new GenomeLocusIterator(shard.getGenomeLocs());
ShardDataProvider dataProvider = new ShardDataProvider(shard, null, sequenceFile, null);

View File

@ -45,7 +45,7 @@ public abstract class LocusViewTemplate extends BaseTest {
SAMRecordIterator iterator = new SAMRecordIterator();
GenomeLoc shardBounds = GenomeLocParser.createGenomeLoc("chr1", 1, 5);
Shard shard = new LocusShard(shardBounds);
Shard shard = new LocusShard(Collections.singletonList(shardBounds));
ShardDataProvider dataProvider = new ShardDataProvider(shard, iterator);
LocusView view = createView(dataProvider);
@ -59,7 +59,7 @@ public abstract class LocusViewTemplate extends BaseTest {
SAMRecordIterator iterator = new SAMRecordIterator(read);
GenomeLoc shardBounds = GenomeLocParser.createGenomeLoc("chr1", 1, 5);
Shard shard = new LocusShard(shardBounds);
Shard shard = new LocusShard(Collections.singletonList(shardBounds));
ShardDataProvider dataProvider = new ShardDataProvider(shard, iterator);
LocusView view = createView(dataProvider);
@ -72,7 +72,7 @@ public abstract class LocusViewTemplate extends BaseTest {
SAMRecord read = buildSAMRecord("chr1", 1, 5);
SAMRecordIterator iterator = new SAMRecordIterator(read);
Shard shard = new LocusShard(GenomeLocParser.createGenomeLoc("chr1", 1, 10));
Shard shard = new LocusShard(Collections.singletonList(GenomeLocParser.createGenomeLoc("chr1", 1, 10)));
ShardDataProvider dataProvider = new ShardDataProvider(shard, iterator);
LocusView view = createView(dataProvider);
@ -84,7 +84,7 @@ public abstract class LocusViewTemplate extends BaseTest {
SAMRecord read = buildSAMRecord("chr1", 6, 10);
SAMRecordIterator iterator = new SAMRecordIterator(read);
Shard shard = new LocusShard(GenomeLocParser.createGenomeLoc("chr1", 1, 10));
Shard shard = new LocusShard(Collections.singletonList(GenomeLocParser.createGenomeLoc("chr1", 1, 10)));
ShardDataProvider dataProvider = new ShardDataProvider(shard, iterator);
LocusView view = createView(dataProvider);
@ -96,7 +96,7 @@ public abstract class LocusViewTemplate extends BaseTest {
SAMRecord read = buildSAMRecord("chr1", 3, 7);
SAMRecordIterator iterator = new SAMRecordIterator(read);
Shard shard = new LocusShard(GenomeLocParser.createGenomeLoc("chr1", 1, 10));
Shard shard = new LocusShard(Collections.singletonList(GenomeLocParser.createGenomeLoc("chr1", 1, 10)));
ShardDataProvider dataProvider = new ShardDataProvider(shard, iterator);
LocusView view = createView(dataProvider);
@ -108,7 +108,7 @@ public abstract class LocusViewTemplate extends BaseTest {
SAMRecord read = buildSAMRecord("chr1", 1, 10);
SAMRecordIterator iterator = new SAMRecordIterator(read);
Shard shard = new LocusShard(GenomeLocParser.createGenomeLoc("chr1", 6, 15));
Shard shard = new LocusShard(Collections.singletonList(GenomeLocParser.createGenomeLoc("chr1", 6, 15)));
ShardDataProvider dataProvider = new ShardDataProvider(shard, iterator);
LocusView view = createView(dataProvider);
@ -120,7 +120,7 @@ public abstract class LocusViewTemplate extends BaseTest {
SAMRecord read = buildSAMRecord("chr1", 6, 15);
SAMRecordIterator iterator = new SAMRecordIterator(read);
Shard shard = new LocusShard(GenomeLocParser.createGenomeLoc("chr1", 1, 10));
Shard shard = new LocusShard(Collections.singletonList(GenomeLocParser.createGenomeLoc("chr1", 1, 10)));
ShardDataProvider dataProvider = new ShardDataProvider(shard, iterator);
LocusView view = createView(dataProvider);
@ -133,7 +133,7 @@ public abstract class LocusViewTemplate extends BaseTest {
SAMRecord read2 = buildSAMRecord("chr1", 6, 10);
SAMRecordIterator iterator = new SAMRecordIterator(read1, read2);
Shard shard = new LocusShard(GenomeLocParser.createGenomeLoc("chr1", 1, 10));
Shard shard = new LocusShard(Collections.singletonList(GenomeLocParser.createGenomeLoc("chr1", 1, 10)));
ShardDataProvider dataProvider = new ShardDataProvider(shard, iterator);
LocusView view = createView(dataProvider);
@ -150,7 +150,7 @@ public abstract class LocusViewTemplate extends BaseTest {
SAMRecord read4 = buildSAMRecord("chr1", 6, 10);
SAMRecordIterator iterator = new SAMRecordIterator(read1, read2, read3, read4);
Shard shard = new LocusShard(GenomeLocParser.createGenomeLoc("chr1", 1, 10));
Shard shard = new LocusShard(Collections.singletonList(GenomeLocParser.createGenomeLoc("chr1", 1, 10)));
ShardDataProvider dataProvider = new ShardDataProvider(shard, iterator);
LocusView view = createView(dataProvider);
@ -167,7 +167,7 @@ public abstract class LocusViewTemplate extends BaseTest {
SAMRecord read4 = buildSAMRecord("chr1", 5, 9);
SAMRecordIterator iterator = new SAMRecordIterator(read1, read2, read3, read4);
Shard shard = new LocusShard(GenomeLocParser.createGenomeLoc("chr1", 1, 10));
Shard shard = new LocusShard(Collections.singletonList(GenomeLocParser.createGenomeLoc("chr1", 1, 10)));
ShardDataProvider dataProvider = new ShardDataProvider(shard, iterator);
LocusView view = createView(dataProvider);
@ -186,7 +186,7 @@ public abstract class LocusViewTemplate extends BaseTest {
SAMRecord read6 = buildSAMRecord("chr1", 6, 10);
SAMRecordIterator iterator = new SAMRecordIterator(read1, read2, read3, read4, read5, read6);
Shard shard = new LocusShard(GenomeLocParser.createGenomeLoc("chr1", 1, 10));
Shard shard = new LocusShard(Collections.singletonList(GenomeLocParser.createGenomeLoc("chr1", 1, 10)));
ShardDataProvider dataProvider = new ShardDataProvider(shard, iterator);
LocusView view = createView(dataProvider);
@ -212,7 +212,7 @@ public abstract class LocusViewTemplate extends BaseTest {
SAMRecordIterator iterator = new SAMRecordIterator(read01, read02, read03, read04, read05, read06,
read07, read08, read09, read10, read11, read12);
Shard shard = new LocusShard(GenomeLocParser.createGenomeLoc("chr1", 6, 15));
Shard shard = new LocusShard(Collections.singletonList(GenomeLocParser.createGenomeLoc("chr1", 6, 15)));
ShardDataProvider dataProvider = new ShardDataProvider(shard, iterator);
LocusView view = createView(dataProvider);

View File

@ -52,7 +52,7 @@ public class ReferenceOrderedViewTest extends BaseTest {
*/
@Test
public void testNoBindings() {
Shard shard = new LocusShard(GenomeLocParser.createGenomeLoc("chrM",1,30));
Shard shard = new LocusShard(Collections.singletonList(GenomeLocParser.createGenomeLoc("chrM",1,30)));
ShardDataProvider provider = new ShardDataProvider(shard, null, seq, Collections.<ReferenceOrderedDataSource>emptyList());
ReferenceOrderedView view = new ManagingReferenceOrderedView( provider );
@ -69,7 +69,7 @@ public class ReferenceOrderedViewTest extends BaseTest {
ReferenceOrderedData rod = new ReferenceOrderedData("tableTest", file, TabularROD.class);
ReferenceOrderedDataSource dataSource = new ReferenceOrderedDataSource(rod);
Shard shard = new LocusShard(GenomeLocParser.createGenomeLoc("chrM",1,30));
Shard shard = new LocusShard(Collections.singletonList(GenomeLocParser.createGenomeLoc("chrM",1,30)));
ShardDataProvider provider = new ShardDataProvider(shard, null, seq, Collections.singletonList(dataSource));
ReferenceOrderedView view = new ManagingReferenceOrderedView( provider );
@ -95,7 +95,7 @@ public class ReferenceOrderedViewTest extends BaseTest {
ReferenceOrderedDataSource dataSource2 = new ReferenceOrderedDataSource(rod2);
Shard shard = new LocusShard(GenomeLocParser.createGenomeLoc("chrM",1,30));
Shard shard = new LocusShard(Collections.singletonList(GenomeLocParser.createGenomeLoc("chrM",1,30)));
ShardDataProvider provider = new ShardDataProvider(shard, null, seq, Arrays.asList(dataSource1,dataSource2));
ReferenceOrderedView view = new ManagingReferenceOrderedView( provider );