From 347608cfe0e059383137cd2cc7740e0791913f52 Mon Sep 17 00:00:00 2001 From: ebanks Date: Thu, 25 Jun 2009 14:32:05 +0000 Subject: [PATCH] remove hacked traversal in preparation for move to Matt's new one git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1091 348d0f76-0448-11de-a6fe-93d51630548a --- .../traversals/TraverseByLocusWindows.java | 132 +----------------- .../sting/gatk/walkers/LocusWindowWalker.java | 10 +- 2 files changed, 5 insertions(+), 137 deletions(-) diff --git a/java/src/org/broadinstitute/sting/gatk/traversals/TraverseByLocusWindows.java b/java/src/org/broadinstitute/sting/gatk/traversals/TraverseByLocusWindows.java index 8cb5417f3..978c6ed5c 100755 --- a/java/src/org/broadinstitute/sting/gatk/traversals/TraverseByLocusWindows.java +++ b/java/src/org/broadinstitute/sting/gatk/traversals/TraverseByLocusWindows.java @@ -76,10 +76,7 @@ public class TraverseByLocusWindows extends TraversalEngine { if ( !samReader.hasIndex() ) Utils.scareUser("Processing locations were requested, but no index was found for the input SAM/BAM file. This operation is potentially dangerously slow, aborting."); - if ( walker.actOnNonIntervalReads() ) - sum = fullInputTraversal(walker, locations, sum); - else - sum = strictIntervalTraversal(walker, locations, sum); + sum = intervalTraversal(walker, locations, sum); } //printOnTraversalDone("intervals", sum); @@ -87,8 +84,7 @@ public class TraverseByLocusWindows extends TraversalEngine { return sum; } - protected T strictIntervalTraversal(LocusWindowWalker walker, List locations, T sum) { - LocusContext nextLocusToCarry = null; + protected T intervalTraversal(LocusWindowWalker walker, List locations, T sum) { for ( GenomeLoc interval : locations ) { logger.debug(String.format("Processing interval %s", interval.toString())); @@ -97,129 +93,9 @@ public class TraverseByLocusWindows extends TraversalEngine { LocusContext locus = getLocusContext(wrappedIter, interval); readIter.close(); - if ( nextLocusToCarry == null ) { - nextLocusToCarry = locus; - } else if ( nextLocusToCarry.getLocation().overlapsP(locus.getLocation()) ) { - nextLocusToCarry = merge(nextLocusToCarry, locus); - } else { - sum = carryWalkerOverInterval(walker, sum, nextLocusToCarry); - nextLocusToCarry = locus; - } + //sum = carryWalkerOverInterval(walker, sum, locus); + System.out.println(locus.getLocation()); } - if ( nextLocusToCarry != null ) - sum = carryWalkerOverInterval(walker, sum, nextLocusToCarry); - return sum; - } - - protected T fullInputTraversal(LocusWindowWalker walker, List locations, T sum) { - ArrayList nextLociToCarry = new ArrayList(); - - // set everything up - GenomeLoc currentInterval = (locations.size() > 0 ? locations.get(0) : null); - int locationsIndex = 0; - ArrayList intervalReads = new ArrayList(); - Iterator readIter = getIteratorOverDesiredRegion(samReader,null); - - while (readIter.hasNext()) { - TraversalStatistics.nRecords++; - SAMRecord read = readIter.next(); - - - // apparently, unmapped reads can occur anywhere in the file! - if ( read.getReadUnmappedFlag() ) { - walker.nonIntervalReadAction(read); - continue; - } - - // if there are no locations or we're past the last one, then act on the read separately - if ( currentInterval == null ) { - if ( nextLociToCarry.size() > 0 ) { - sum = carryWalkerOverInterval(walker, sum, nextLociToCarry.get(0)); - for (int i=1; i < nextLociToCarry.size(); i++) - walker.nonIntervalReadAction(nextLociToCarry.get(i).getReads().get(0)); - nextLociToCarry.clear(); - } - walker.nonIntervalReadAction(read); - } - else { - GenomeLoc loc = GenomeLocParser.createGenomeLoc(read); - // if we're in the current interval, add it to the list - if ( currentInterval.overlapsP(loc) ) { - intervalReads.add(read); - } - // if we're not yet in the interval, act on the read separately - else if ( currentInterval.isPast(loc) ) { - if ( nextLociToCarry.size() == 0 ) { - walker.nonIntervalReadAction(read); - } else { - ArrayList list = new ArrayList(); - list.add(read); - nextLociToCarry.add(new LocusContext(loc, list, null)); - } - } - // otherwise, we're past the interval so first deal with the collected reads and then this one - else { - if ( intervalReads.size() > 0 ) { - Iterator wrappedIter = wrapReadsIterator(intervalReads.iterator(), false); - LocusContext locus = getLocusContext(wrappedIter, currentInterval); - - if ( nextLociToCarry.size() == 0 ) { - nextLociToCarry.add(locus); - } else if ( nextLociToCarry.get(0).getLocation().overlapsP(locus.getLocation()) ) { - LocusContext newLocus = merge(nextLociToCarry.get(0), locus); - for (int i=1; i < nextLociToCarry.size(); i++) - newLocus = merge(newLocus, nextLociToCarry.get(i)); - nextLociToCarry.clear(); - nextLociToCarry.add(newLocus); - } else { - sum = carryWalkerOverInterval(walker, sum, nextLociToCarry.get(0)); - for (int i=1; i < nextLociToCarry.size(); i++) - walker.nonIntervalReadAction(nextLociToCarry.get(i).getReads().get(0)); - nextLociToCarry.clear(); - nextLociToCarry.add(locus); - } - - // then prepare for the next interval - intervalReads.clear(); - } - currentInterval = (++locationsIndex < locations.size() ? locations.get(locationsIndex) : null); - - if ( nextLociToCarry.size() == 0 ) { - walker.nonIntervalReadAction(read); - } else { - ArrayList list = new ArrayList(); - list.add(read); - nextLociToCarry.add(new LocusContext(loc, list, null)); - } - } - } - } - // some cleanup - if ( intervalReads.size() > 0 ) { - Iterator wrappedIter = wrapReadsIterator(intervalReads.iterator(), false); - LocusContext locus = getLocusContext(wrappedIter, currentInterval); - if ( nextLociToCarry.size() == 0 ) { - nextLociToCarry.add(locus); - } else if ( nextLociToCarry.get(0).getLocation().overlapsP(locus.getLocation()) ) { - LocusContext newLocus = merge(nextLociToCarry.get(0), locus); - for (int i=1; i < nextLociToCarry.size(); i++) - newLocus = merge(newLocus, nextLociToCarry.get(i)); - nextLociToCarry.clear(); - nextLociToCarry.add(newLocus); - } else { - sum = carryWalkerOverInterval(walker, sum, nextLociToCarry.get(0)); - for (int i=1; i < nextLociToCarry.size(); i++) - walker.nonIntervalReadAction(nextLociToCarry.get(i).getReads().get(0)); - nextLociToCarry.clear(); - nextLociToCarry.add(locus); - } - } - if ( nextLociToCarry.size() > 0 ) { - sum = carryWalkerOverInterval(walker, sum, nextLociToCarry.get(0)); - for (int i=1; i < nextLociToCarry.size(); i++) - walker.nonIntervalReadAction(nextLociToCarry.get(i).getReads().get(0)); - } - return sum; } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/LocusWindowWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/LocusWindowWalker.java index 20073dfd2..623116e94 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/LocusWindowWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/LocusWindowWalker.java @@ -19,18 +19,10 @@ public abstract class LocusWindowWalker extends Walker