print the current location in read walkers (in addition to the number of reads processed), along with some refactoring to support the change.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2006 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
aaron 2009-11-10 05:57:01 +00:00
parent c9c3cf477a
commit 2ed423ed56
7 changed files with 56 additions and 23 deletions

View File

@ -21,6 +21,9 @@ public abstract class TraversalEngine {
/** our log, which we want to capture anything from this class */ /** our log, which we want to capture anything from this class */
protected static Logger logger = Logger.getLogger(TraversalEngine.class); protected static Logger logger = Logger.getLogger(TraversalEngine.class);
/** what kind of traversal we're undertaking. This allows us to format output correctly */
public enum TRAVERSAL_TYPE { READ, LOCUS, LOCUS_WINDOW, DUPLICATE };
/** /**
* set the max number of iterations * set the max number of iterations
* @param maximumIterations the number of iterations * @param maximumIterations the number of iterations
@ -41,10 +44,10 @@ public abstract class TraversalEngine {
/** /**
* Forward request to printProgress * Forward request to printProgress
* *
* @param type the type of traversal * @param type the TRAVERSAL_TYPE of the traversal
* @param loc the location * @param loc the location
*/ */
public void printProgress(final String type, GenomeLoc loc) { public void printProgress(final TRAVERSAL_TYPE type, GenomeLoc loc) {
printProgress(false, type, loc); printProgress(false, type, loc);
} }
@ -56,7 +59,7 @@ public abstract class TraversalEngine {
* @param type String to print out describing our atomic traversal type ("read", "locus", etc) * @param type String to print out describing our atomic traversal type ("read", "locus", etc)
* @param loc Current location * @param loc Current location
*/ */
private void printProgress(boolean mustPrint, final String type, GenomeLoc loc) { private void printProgress(boolean mustPrint, final TRAVERSAL_TYPE type, GenomeLoc loc) {
final long nRecords = TraversalStatistics.nRecords; final long nRecords = TraversalStatistics.nRecords;
final long curTime = System.currentTimeMillis(); final long curTime = System.currentTimeMillis();
final double elapsed = (curTime - startTime) / 1000.0; final double elapsed = (curTime - startTime) / 1000.0;
@ -65,12 +68,39 @@ public abstract class TraversalEngine {
if (mustPrint || nRecords == 1 || nRecords % N_RECORDS_TO_PRINT == 0 || maxElapsedIntervalForPrinting(curTime)) { if (mustPrint || nRecords == 1 || nRecords % N_RECORDS_TO_PRINT == 0 || maxElapsedIntervalForPrinting(curTime)) {
this.lastProgressPrintTime = curTime; this.lastProgressPrintTime = curTime;
final double secsPer1MReads = (elapsed * 1000000.0) / nRecords; final double secsPer1MReads = (elapsed * 1000000.0) / nRecords;
if (loc != null) switch (type) {
logger.info(String.format("[PROGRESS] Traversed to %s, processing %,d %s in %.2f secs (%.2f secs per 1M %s)", loc, nRecords, type, elapsed, secsPer1MReads, type)); case LOCUS:
else logger.info(String.format("[PROGRESS] Traversed to %s, processing %,d loci in %.2f secs (%.2f secs per 1M loci)",
logger.info(String.format("[PROGRESS] Traversed %,d %s in %.2f secs (%.2f secs per 1M %s)", nRecords, type, elapsed, secsPer1MReads, type)); loc,
nRecords,
} elapsed,
secsPer1MReads));break;
case READ:
logger.info(String.format("[PROGRESS] Traversed %,d reads in %.2f secs %s(%.2f secs per 1M reads)",
nRecords,
elapsed,
(loc != null) ? String.format("at location %s ",loc) : "",
secsPer1MReads));break;
case DUPLICATE:
logger.info(String.format("[PROGRESS] Traversed %,d dups in %.2f secs %s(%.2f secs per 1M dups)",
nRecords,
elapsed,
(loc != null) ? String.format("at location %s ",loc) : "",
secsPer1MReads));break;
case LOCUS_WINDOW:
logger.info(String.format("[PROGRESS] Traversed %,d intervals in %.2f secs over interval %s (%.2f secs per 1M intervals)",
nRecords,
elapsed,
loc,
secsPer1MReads));break;
default:
logger.info(String.format("[PROGRESS] Traversed %,d records in %.2f secs (%.2f secs per 1M intervals)%s",
nRecords,
elapsed,
secsPer1MReads,
(loc != null) ? String.format(", last location seen was %s",loc) : ""));
}
}
} }
/** /**
@ -84,11 +114,11 @@ public abstract class TraversalEngine {
/** /**
* Called after a traversal to print out information about the traversal process * Called after a traversal to print out information about the traversal process
* *
* @param type String describing this type of traversal ("loci", "read") * @param type TRAVERSAL_TYPE describing this type of traversal
* @param sum The reduce result of the traversal * @param sum The reduce result of the traversal
* @param <T> ReduceType of the traversal * @param <T> ReduceType of the traversal
*/ */
protected <T> void printOnTraversalDone(final String type, T sum) { protected <T> void printOnTraversalDone(final TRAVERSAL_TYPE type, T sum) {
printProgress(true, type, null); printProgress(true, type, null);
logger.info("Traversal reduce result is " + sum); logger.info("Traversal reduce result is " + sum);
final long curTime = System.currentTimeMillis(); final long curTime = System.currentTimeMillis();

View File

@ -203,7 +203,7 @@ public class TraverseDuplicates extends TraversalEngine {
if (duplicateReads.size() > 0) if (duplicateReads.size() > 0)
sum = mapOne(dupWalker, uniqueReads, duplicateReads, site, refBases, locus, sum); sum = mapOne(dupWalker, uniqueReads, duplicateReads, site, refBases, locus, sum);
printProgress("dups", site); printProgress(TRAVERSAL_TYPE.DUPLICATE, site);
if (this.maximumIterations > 0 && TraversalStatistics.nRecords > this.maximumIterations) { if (this.maximumIterations > 0 && TraversalStatistics.nRecords > this.maximumIterations) {
logger.warn(String.format(("Maximum number of duplicate sets encountered, terminating traversal " + TraversalStatistics.nRecords))); logger.warn(String.format(("Maximum number of duplicate sets encountered, terminating traversal " + TraversalStatistics.nRecords)));
@ -309,6 +309,6 @@ public class TraverseDuplicates extends TraversalEngine {
* @param <T> Type of the result. * @param <T> Type of the result.
*/ */
public <T> void printOnTraversalDone(T sum) { public <T> void printOnTraversalDone(T sum) {
printOnTraversalDone("reads", sum); printOnTraversalDone(TRAVERSAL_TYPE.DUPLICATE, sum);
} }
} }

View File

@ -86,7 +86,7 @@ public class TraverseLoci extends TraversalEngine {
break; break;
} }
printProgress(UNIT_STRING, locus.getLocation()); printProgress(TRAVERSAL_TYPE.LOCUS, locus.getLocation());
} }
} }
@ -113,7 +113,7 @@ public class TraverseLoci extends TraversalEngine {
* @param <T> Type of the result. * @param <T> Type of the result.
*/ */
public <T> void printOnTraversalDone( T sum ) { public <T> void printOnTraversalDone( T sum ) {
printOnTraversalDone( UNIT_STRING, sum ); printOnTraversalDone( TRAVERSAL_TYPE.LOCUS, sum );
} }
/** /**

View File

@ -58,7 +58,7 @@ public class TraverseLocusWindows extends TraversalEngine {
sum = locusWindowWalker.reduce(x, sum); sum = locusWindowWalker.reduce(x, sum);
} }
printProgress("intervals", locus.getLocation()); printProgress(TRAVERSAL_TYPE.LOCUS_WINDOW, locus.getLocation());
return sum; return sum;
} }
@ -98,7 +98,7 @@ public class TraverseLocusWindows extends TraversalEngine {
* @param <T> Type of the result. * @param <T> Type of the result.
*/ */
public <T> void printOnTraversalDone( T sum ) { public <T> void printOnTraversalDone( T sum ) {
printOnTraversalDone( "intervals", sum ); printOnTraversalDone( TRAVERSAL_TYPE.LOCUS_WINDOW, sum );
} }
} }

View File

@ -121,7 +121,10 @@ public class TraverseReads extends TraversalEngine {
sum = readWalker.reduce(x, sum); sum = readWalker.reduce(x, sum);
} }
printProgress("reads", null); printProgress(TRAVERSAL_TYPE.READ,
(read.getReferenceIndex() == SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX) ?
null :
GenomeLocParser.createGenomeLoc(read.getReferenceIndex(),read.getAlignmentStart()));
} }
return sum; return sum;
} }
@ -133,6 +136,6 @@ public class TraverseReads extends TraversalEngine {
* @param <T> Type of the result. * @param <T> Type of the result.
*/ */
public <T> void printOnTraversalDone( T sum ) { public <T> void printOnTraversalDone( T sum ) {
printOnTraversalDone( "reads", sum ); printOnTraversalDone(TRAVERSAL_TYPE.READ, sum );
} }
} }

View File

@ -118,7 +118,7 @@ public class ArtificialReadsTraversal extends TraversalEngine {
sum = readWalker.reduce(x, sum); sum = readWalker.reduce(x, sum);
} }
if (alignment != null) { printProgress("loci", alignment.getLocation()); } if (alignment != null) { printProgress(TRAVERSAL_TYPE.READ, alignment.getLocation()); }
} }
return sum; return sum;
} }
@ -131,7 +131,7 @@ public class ArtificialReadsTraversal extends TraversalEngine {
* @param <T> Type of the result. * @param <T> Type of the result.
*/ */
public <T> void printOnTraversalDone( T sum ) { public <T> void printOnTraversalDone( T sum ) {
printOnTraversalDone("reads", sum); printOnTraversalDone(TRAVERSAL_TYPE.READ, sum);
} }

View File

@ -139,7 +139,7 @@ public class TraverseReadsTest extends BaseTest {
} }
traversalEngine.printOnTraversalDone("loci", accumulator); traversalEngine.printOnTraversalDone(TraversalEngine.TRAVERSAL_TYPE.READ, accumulator);
countReadWalker.onTraversalDone(accumulator); countReadWalker.onTraversalDone(accumulator);
if (!(accumulator instanceof Integer)) { if (!(accumulator instanceof Integer)) {
@ -185,7 +185,7 @@ public class TraverseReadsTest extends BaseTest {
dataProvider.close(); dataProvider.close();
} }
traversalEngine.printOnTraversalDone("loci", accumulator); traversalEngine.printOnTraversalDone(TraversalEngine.TRAVERSAL_TYPE.READ, accumulator);
countReadWalker.onTraversalDone(accumulator); countReadWalker.onTraversalDone(accumulator);
if (!(accumulator instanceof Integer)) { if (!(accumulator instanceof Integer)) {