From 28bf7ec8ad70ba8ba88bc649ed0efc571da5f1a3 Mon Sep 17 00:00:00 2001 From: kiran Date: Sun, 17 May 2009 04:09:23 +0000 Subject: [PATCH] Aesthetic cleanup. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@735 348d0f76-0448-11de-a6fe-93d51630548a --- .../secondarybase/AnnotateSecondaryBase.java | 11 +++--- .../sting/secondarybase/BasecallingStats.java | 35 +++++++++++++++---- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/java/src/org/broadinstitute/sting/secondarybase/AnnotateSecondaryBase.java b/java/src/org/broadinstitute/sting/secondarybase/AnnotateSecondaryBase.java index c3117ec44..9886f9f72 100755 --- a/java/src/org/broadinstitute/sting/secondarybase/AnnotateSecondaryBase.java +++ b/java/src/org/broadinstitute/sting/secondarybase/AnnotateSecondaryBase.java @@ -36,7 +36,6 @@ public class AnnotateSecondaryBase extends CommandLineProgram { @Argument(fullName="cycle_end", shortName="CE", doc="On what cycle does the read end? (0-based inclusive)") public int CYCLE_END; @Argument(fullName="tlim", shortName="T", doc="Number of reads to use for parameter initialization", required=false) public int TRAINING_LIMIT = 250000; @Argument(fullName="clim", shortName="C", doc="Number of reads to basecall", required=false) public int CALLING_LIMIT = Integer.MAX_VALUE; - @Argument(fullName="context", shortName="X", doc="Attempt to correct for context?", required=false) public Boolean CONTEXT = false; @Argument(fullName="runbarcode", shortName="B", doc="Run barcode (embedded as part of the read name") public String RUN_BARCODE; public static void main(String[] argv) { @@ -48,12 +47,12 @@ public class AnnotateSecondaryBase extends CommandLineProgram { BasecallingTrainingSet trainingSet = new BasecallingTrainingSet(BUSTARD_DIR, LANE, CYCLE_BEGIN, CYCLE_END, TRAINING_LIMIT); // Iterate through raw Firecrest data and store the first N reads up to TRAINING_LIMIT - System.out.println("Loading training set from the first " + TRAINING_LIMIT + " reads in the raw data..."); + System.out.println("Loading training set from the first " + TRAINING_LIMIT + " unambiguous reads in the raw data..."); trainingSet.loadFirstNUnambiguousReadsTrainingSet(); // Iterate through the stored training data and add the info to the BasecallingReadModel System.out.println("Applying training set..."); - BasecallingReadModel model = new BasecallingReadModel(CYCLE_END - CYCLE_BEGIN + 1, CONTEXT); + BasecallingReadModel model = new BasecallingReadModel(CYCLE_END - CYCLE_BEGIN + 1, true); model.train(trainingSet); // Call bases and write results @@ -69,13 +68,15 @@ public class AnnotateSecondaryBase extends CommandLineProgram { FourProbRead fpr = model.call(rr); sfw.addAlignment(constructSAMRecord(rr, fpr, sfh, RUN_BARCODE)); - bstats.update(rr, fpr, 10000); + bstats.update(rr, fpr); + + bstats.notifyOnInterval(10000); } iparser.close(); sfw.close(); - System.out.printf("%% bases consistent: %d/%d (%4.4f)\n", bstats.getBasesConsistent(), bstats.getBasesTotal(), bstats.getPercentConsistent()); + bstats.notifyNow(); System.out.println("Done."); return 0; diff --git a/java/src/org/broadinstitute/sting/secondarybase/BasecallingStats.java b/java/src/org/broadinstitute/sting/secondarybase/BasecallingStats.java index a1edf0bb7..908f79c17 100755 --- a/java/src/org/broadinstitute/sting/secondarybase/BasecallingStats.java +++ b/java/src/org/broadinstitute/sting/secondarybase/BasecallingStats.java @@ -51,7 +51,7 @@ public class BasecallingStats { * @return the percent of bases called consistently */ public double getPercentConsistent() { - return ((double) getBasesConsistent())/((double) getBasesTotal()); + return 100.0*((double) getBasesConsistent())/((double) getBasesTotal()); } /** @@ -60,7 +60,7 @@ public class BasecallingStats { * @param rr the raw Illumina read * @param fpr the FourProb read */ - public void update(RawRead rr, FourProbRead fpr, int updateInterval) { + public void update(RawRead rr, FourProbRead fpr) { for (int cycle = 0; cycle < fpr.size(); cycle++) { int rawBaseIndex = BaseUtils.simpleBaseToBaseIndex((char) rr.getSequence()[cycle]); int fpBaseIndex = fpr.get(cycle).indexAtRank(0); @@ -74,10 +74,33 @@ public class BasecallingStats { } } - if (basesTotal % updateInterval == 0 && basesTotal > 0) { - System.out.printf("%% bases consistent: %d/%d (%4.4f)\r", basesConsistent, basesTotal, ((double) basesConsistent)/((double) basesTotal)); - } - readsTotal++; } + + /** + * Returns basecalling stats info in a nicely formatted string + * + * @return nicely formatted string containing basecalling stats + */ + public String toString() { + return String.format("%% bases consistent: %d/%d (%2.2f%%)", getBasesConsistent(), getBasesTotal(), getPercentConsistent()); + } + + /** + * Periodically print a line containing basecalling stats + * + * @param interval the periodicity of the messages given in number of bases observed + */ + public void notifyOnInterval(int interval) { + if (getBasesTotal() > 0 && getBasesTotal() % interval == 0) { + System.out.printf("%s\r", toString()); + } + } + + /** + * Immediately print a line containing basecalling stats + */ + public void notifyNow() { + System.out.printf("%s\n", toString()); + } }