From ee99320c835f51a2781b823c8e3f3f92eb3ee496 Mon Sep 17 00:00:00 2001 From: hanna Date: Tue, 12 May 2009 19:48:21 +0000 Subject: [PATCH] Removed at Mark's request. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@677 348d0f76-0448-11de-a6fe-93d51630548a --- .../iterators/SingleLocusContextIterator.java | 156 ------------------ 1 file changed, 156 deletions(-) delete mode 100755 java/src/org/broadinstitute/sting/playground/gatk/iterators/SingleLocusContextIterator.java diff --git a/java/src/org/broadinstitute/sting/playground/gatk/iterators/SingleLocusContextIterator.java b/java/src/org/broadinstitute/sting/playground/gatk/iterators/SingleLocusContextIterator.java deleted file mode 100755 index bb7eda734..000000000 --- a/java/src/org/broadinstitute/sting/playground/gatk/iterators/SingleLocusContextIterator.java +++ /dev/null @@ -1,156 +0,0 @@ -package org.broadinstitute.sting.playground.gatk.iterators; - -import net.sf.samtools.util.CloseableIterator; -import net.sf.samtools.SAMRecord; -import org.broadinstitute.sting.gatk.iterators.PushbackIterator; -import org.broadinstitute.sting.gatk.iterators.LocusContextIterator; -import org.broadinstitute.sting.gatk.LocusContext; -import org.broadinstitute.sting.utils.Utils; -import org.broadinstitute.sting.utils.Predicate; -import org.broadinstitute.sting.utils.GenomeLoc; - -import java.util.List; -import java.util.ArrayList; -import java.util.Iterator; - -import edu.mit.broad.picard.filter.SamRecordFilter; -import edu.mit.broad.picard.filter.FilteringIterator; - -/** - * Iterator that traverses a SAM File, accumulating information on a per-locus basis - */ -public class SingleLocusContextIterator extends LocusContextIterator { - - // ----------------------------------------------------------------------------------------------------------------- - // - // member fields - // - // ----------------------------------------------------------------------------------------------------------------- - private final PushbackIterator it; - private String contig = null; - private int position = -1; - private List reads = new ArrayList(100); - private List offsets = new ArrayList(100); - - // ----------------------------------------------------------------------------------------------------------------- - // - // constructors and other basic operations - // - // ----------------------------------------------------------------------------------------------------------------- - public SingleLocusContextIterator(final CloseableIterator samIterator) { - FilteringIterator filterIter = new FilteringIterator(samIterator, new locusStreamFilterFunc()); - this.it = new PushbackIterator(filterIter); - - } - - /** - * Class to filter out un-handle-able reads from the stream. - */ - class locusStreamFilterFunc implements SamRecordFilter { - public boolean filterOut(SAMRecord rec) { - return rec.getCigar().numCigarElements() > 1; - } - } - - public Iterator iterator() { - return this; - } - - public void close() { - //this.it.close(); - } - - public boolean hasNext() { - return it.hasNext(); - } - - // ----------------------------------------------------------------------------------------------------------------- - // - // next() routine and associated collection operations - // - // ----------------------------------------------------------------------------------------------------------------- - public LocusContext next() { - position += 1; - - if ( position != -1 ) { - cleanReads(); - expandReads(); - } - - if ( reads.isEmpty() ) { - // the window is empty, we need to jump to the first pos of the first read in the stream - SAMRecord read = it.next(); - pushRead(read); - contig = read.getReferenceName(); - position = read.getAlignmentStart() - 1; - return next(); - } - else { - // at this point, window contains all reads covering the pos, we need to return them - // and the offsets into each read for this loci - calcOffsetsOfWindow(position); - return new LocusContext(new GenomeLoc(contig, position), reads, offsets); - } - } - - private void pushRead(SAMRecord read) { - //System.out.printf(" -> Adding read %s %d-%d flags %s%n", read.getReadName(), read.getAlignmentStart(), read.getAlignmentEnd(), Utils.readFlagsAsString(read)); - reads.add(read); - } - - class KeepReadPFunc implements Predicate { - public boolean apply(SAMRecord read) { - return position >= read.getAlignmentStart() && - position < read.getAlignmentEnd() && - read.getReferenceName().equals(contig); // should be index for efficiency - } - } - Predicate KeepReadP = new SingleLocusContextIterator.KeepReadPFunc(); - - private void calcOffsetsOfWindow(final int position) { - offsets.clear(); - for ( SAMRecord read : reads ) { -// def calcOffset( read ): -// offset = self.pos - read.start -// return offset -// -// offsets = map(calcOffset, self.window) - final int offset = position - read.getAlignmentStart(); - assert(offset < read.getReadLength() ); - offsets.add(offset); - //System.out.printf("offsets [%d] %s%n", read.getAlignmentStart(), offsets); - } - } - - private void cleanReads() { - // def keepReadP( read ): - // return read.chr == chr and pos >= read.start and pos <= read.end - // self.window = filter( keepReadP, self.window ) - reads = Utils.filter(KeepReadP, reads); - } - - private void expandReads() { -// for read in self.rs: -// #print 'read', read, pos -// if read.chr == chr and read.start <= pos and read.end >= pos: -// self.pushRead(read) -// else: -// self.rs.unget( read ) -// #self.rs = chain( [read], self.rs ) -// break - while ( it.hasNext() ) { - SAMRecord read = it.next(); - if ( KeepReadP.apply( read ) ) { - pushRead(read); - } - else { - it.pushback(read); - break; - } - } - } - - public void remove() { - throw new UnsupportedOperationException("Can not remove records from a SAM file via an iterator!"); - } -}