Support for reseting the system; Cleanup later
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@174 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
499c422de6
commit
9f500215da
|
|
@ -1,6 +1,7 @@
|
||||||
package org.broadinstitute.sting.gatk.iterators;
|
package org.broadinstitute.sting.gatk.iterators;
|
||||||
|
|
||||||
import net.sf.samtools.util.CloseableIterator;
|
import net.sf.samtools.util.CloseableIterator;
|
||||||
|
import net.sf.samtools.util.RuntimeIOException;
|
||||||
import net.sf.samtools.SAMRecord;
|
import net.sf.samtools.SAMRecord;
|
||||||
import net.sf.samtools.AlignmentBlock;
|
import net.sf.samtools.AlignmentBlock;
|
||||||
import org.broadinstitute.sting.utils.*;
|
import org.broadinstitute.sting.utils.*;
|
||||||
|
|
@ -29,13 +30,14 @@ public class LocusIteratorByHanger extends LocusIterator {
|
||||||
private RefHanger<Integer> offsetHanger = new RefHanger<Integer>();
|
private RefHanger<Integer> offsetHanger = new RefHanger<Integer>();
|
||||||
final int INCREMENT_SIZE = 100;
|
final int INCREMENT_SIZE = 100;
|
||||||
final boolean DEBUG = false;
|
final boolean DEBUG = false;
|
||||||
|
boolean justCleared = false;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// constructors and other basic operations
|
// constructors and other basic operations
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------------------------------
|
||||||
public LocusIteratorByHanger(final CloseableIterator<SAMRecord> samIterator) {
|
public LocusIteratorByHanger(final Iterator<SAMRecord> samIterator) {
|
||||||
this.it = new PushbackIterator<SAMRecord>(samIterator);
|
this.it = new PushbackIterator<SAMRecord>(samIterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,12 +69,29 @@ public class LocusIteratorByHanger extends LocusIterator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
System.out.printf("clear() called%n");
|
||||||
|
readHanger.clear();
|
||||||
|
offsetHanger.clear();
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// next() routine and associated collection operations
|
// next() routine and associated collection operations
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------------------------------
|
||||||
public LocusContext next() {
|
public LocusContext next() {
|
||||||
|
// if ( it.hasNext() && ! readHanger.isEmpty() ) {
|
||||||
|
// // todo: this needs to be deleted
|
||||||
|
// final SAMRecord read = it.peek();
|
||||||
|
// GenomeLoc readLoc = Utils.genomicLocationOf(read);
|
||||||
|
// System.out.printf("Comparing %s to %s%n", readLoc, readHanger.getLeftLoc());
|
||||||
|
// if ( readLoc.compareTo(readHanger.getLeftLoc()) == -1 ) {
|
||||||
|
// clear();
|
||||||
|
// return next();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
if ( ! currentPositionIsFullyCovered() )
|
if ( ! currentPositionIsFullyCovered() )
|
||||||
expandWindow(INCREMENT_SIZE);
|
expandWindow(INCREMENT_SIZE);
|
||||||
|
|
||||||
|
|
@ -90,6 +109,7 @@ public class LocusIteratorByHanger extends LocusIterator {
|
||||||
protected void hangRead(final SAMRecord read) {
|
protected void hangRead(final SAMRecord read) {
|
||||||
GenomeLoc readLoc = new GenomeLoc(read.getReferenceName(), read.getAlignmentStart());
|
GenomeLoc readLoc = new GenomeLoc(read.getReferenceName(), read.getAlignmentStart());
|
||||||
//System.out.printf("Adding read %s at %d%n", read.getReadName(), read.getAlignmentStart());
|
//System.out.printf("Adding read %s at %d%n", read.getReadName(), read.getAlignmentStart());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for ( int i = 0; i < read.getReadLength(); i++ ) {
|
for ( int i = 0; i < read.getReadLength(); i++ ) {
|
||||||
GenomeLoc offset = new GenomeLoc(readLoc.getContig(), readLoc.getStart() + i);
|
GenomeLoc offset = new GenomeLoc(readLoc.getContig(), readLoc.getStart() + i);
|
||||||
|
|
@ -149,6 +169,7 @@ public class LocusIteratorByHanger extends LocusIterator {
|
||||||
}
|
}
|
||||||
|
|
||||||
SAMRecord read = it.next();
|
SAMRecord read = it.next();
|
||||||
|
justCleared = false;
|
||||||
|
|
||||||
GenomeLoc readLoc = Utils.genomicLocationOf(read);
|
GenomeLoc readLoc = Utils.genomicLocationOf(read);
|
||||||
if ( DEBUG ) {
|
if ( DEBUG ) {
|
||||||
|
|
@ -171,6 +192,57 @@ public class LocusIteratorByHanger extends LocusIterator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private final void expandWindow(final int incrementSize) {
|
||||||
|
// if ( DEBUG ) {
|
||||||
|
// System.out.printf("entering expandWindow..., hasNext=%b%n", it.hasNext());
|
||||||
|
// printState();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// while ( it.hasNext() ) {
|
||||||
|
// if ( DEBUG ) {
|
||||||
|
// System.out.printf("Expanding window%n");
|
||||||
|
// printState();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// SAMRecord read = it.next();
|
||||||
|
// justCleared = false;
|
||||||
|
//
|
||||||
|
// GenomeLoc readLoc = Utils.genomicLocationOf(read);
|
||||||
|
// if ( DEBUG ) {
|
||||||
|
// System.out.printf(" Expanding window sizes %d with %d : left=%s, right=%s, readLoc = %s, cmp=%d%n",
|
||||||
|
// readHanger.size(), incrementSize,
|
||||||
|
// readHanger.hasHangers() ? readHanger.getLeftLoc() : "NA",
|
||||||
|
// readHanger.hasHangers() ? readHanger.getRightLoc() : "NA",
|
||||||
|
// readLoc,
|
||||||
|
// readHanger.hasHangers() ? readLoc.compareTo(readHanger.getLeftLoc()) : -100);
|
||||||
|
// }
|
||||||
|
// //if ( readHanger.size() >= incrementSize ) {
|
||||||
|
// //if ( readHanger.hasHangers() && readLoc.compareTo(readHanger.getLeftLoc()) == 1) {
|
||||||
|
// if ( readHanger.hasHangers() && readLoc.distance(readHanger.getLeftLoc()) >= incrementSize ) {
|
||||||
|
// // We've collected up enough reads
|
||||||
|
// it.pushback(read);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// hangRead(read);
|
||||||
|
// }
|
||||||
|
// catch ( RuntimeIOException rio ) {
|
||||||
|
// System.out.printf("Clearing state...");
|
||||||
|
// // todo: good god, this is dangerous, we are reseting state because the reads are out of order
|
||||||
|
// if ( ! justCleared ) {
|
||||||
|
// rio.printStackTrace();
|
||||||
|
// justCleared = true;
|
||||||
|
// clear();
|
||||||
|
// }
|
||||||
|
// it.next(); // throw away the offending read
|
||||||
|
// expandWindow(INCREMENT_SIZE);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
public void remove() {
|
public void remove() {
|
||||||
throw new UnsupportedOperationException("Can not remove records from a SAM file via an iterator!");
|
throw new UnsupportedOperationException("Can not remove records from a SAM file via an iterator!");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue