An iterator for Eric to use when injecting his new wrapping reads -- a stopgap solution for getting additional caching
functionality into a SAMRecord. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2173 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
26db15be5c
commit
3300ca906a
|
|
@ -403,7 +403,9 @@ public class SAMDataSource implements SimpleDataSource {
|
|||
*/
|
||||
private StingSAMIterator createIterator( DataStreamSegment segment ) {
|
||||
StingSAMIterator iterator = resourcePool.iterator(segment);
|
||||
return new MalformedSAMFilteringIterator( getHeader(), iterator, violations );
|
||||
StingSAMIterator malformedWrappedIterator = new MalformedSAMFilteringIterator( getHeader(), iterator, violations );
|
||||
StingSAMIterator readWrappingIterator = new ReadWrappingIterator(malformedWrappedIterator);
|
||||
return readWrappingIterator;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
package org.broadinstitute.sting.gatk.iterators;
|
||||
|
||||
import net.sf.samtools.SAMRecord;
|
||||
import org.broadinstitute.sting.gatk.Reads;
|
||||
|
||||
/**
|
||||
* An iterator which wraps each SAMRecord inside a wrapper class, bringing new functionality to the read while
|
||||
* presenting the original SAMRecord interface.
|
||||
*
|
||||
* @author mhanna
|
||||
* @version 0.1
|
||||
*/
|
||||
public class ReadWrappingIterator implements StingSAMIterator {
|
||||
/**
|
||||
* Iterator to which to pass
|
||||
*/
|
||||
private StingSAMIterator wrappedIterator;
|
||||
|
||||
/**
|
||||
* Decorate the given iterator inside a ReadWrappingIterator.
|
||||
* @param wrappedIterator
|
||||
*/
|
||||
public ReadWrappingIterator(StingSAMIterator wrappedIterator) {
|
||||
this.wrappedIterator = wrappedIterator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get metadata about the reads' sources, etc.
|
||||
* @return Source info about the reads.
|
||||
*/
|
||||
public Reads getSourceInfo() {
|
||||
return wrappedIterator.getSourceInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for use in foreach loops. Dangerous because it does not actually
|
||||
* reset the iterator.
|
||||
* @return An iterator through the current data stream.
|
||||
*/
|
||||
public StingSAMIterator iterator() {
|
||||
// NOTE: this iterator doesn't perform any kind of reset operation; it just returns itself.
|
||||
// can we do something better? Do we really have to provide support for the Iterable interface?
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close this iterator.
|
||||
*/
|
||||
public void close() {
|
||||
wrappedIterator.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the iterator contain more values?
|
||||
* @return True if there are more left to return, false otherwise.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return wrappedIterator.hasNext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next value in the sequence.
|
||||
* @return Next value in the sequence. By convention, a NoSuchElementException should be thrown if
|
||||
* no next exists.
|
||||
*/
|
||||
public SAMRecord next() {
|
||||
return wrappedIterator.next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the current element from the list. Unsupported in this wrapper.
|
||||
*/
|
||||
public void remove() { throw new UnsupportedOperationException("Cannot remove from a ReadWrappingIterator"); }
|
||||
}
|
||||
Loading…
Reference in New Issue