Provide out and err PrintStreams to the walkers.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@213 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
hanna 2009-03-27 15:03:32 +00:00
parent c6d9848d08
commit 4a6be896b9
13 changed files with 112 additions and 41 deletions

View File

@ -19,6 +19,8 @@ import org.broadinstitute.sting.utils.Utils;
import org.broadinstitute.sting.utils.cmdLine.CommandLineProgram;
import java.io.File;
import java.io.PrintStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -49,6 +51,33 @@ public class GenomeAnalysisTK extends CommandLineProgram {
public boolean DEBUGGING = false;
public boolean WALK_ALL_LOCI = false;
/**
* An output file presented to the walker.
*/
public String outFileName = null;
/**
* An error output file presented to the walker.
*/
public String errFileName = null;
/**
* A joint file for both 'normal' and error output presented to the walker.
*/
public String outErrFileName = null;
/**
* The output stream, initialized from OUTFILENAME / OUTERRFILENAME.
* Used by the walker.
*/
public PrintStream out = System.out;
/**
* The output stream, initialized from ERRFILENAME / OUTERRFILENAME.
* Used by the walker.
*/
public PrintStream err = System.err;
/**
* our log, which we want to capture anything from this class
*/
@ -74,6 +103,9 @@ public class GenomeAnalysisTK extends CommandLineProgram {
m_parser.addOptionalFlag("sort_on_the_fly", "F", "If set, enables on fly sorting of reads file.", "ENABLED_SORT_ON_FLY");
m_parser.addOptionalArg("intervals_file", "V", "File containing list of genomic intervals to operate on. line := <contig> <start> <end>", "INTERVALS_FILE");
m_parser.addOptionalArg("all_loci", "A", "Should we process all loci, not just those covered by reads", "WALK_ALL_LOCI");
m_parser.addOptionalArg("out", "o", "An output file presented to the walker. Will overwrite contents if file exists.", "outFileName" );
m_parser.addOptionalArg("err", "e", "An error output file presented to the walker. Will overwrite contents if file exists.", "errFileName" );
m_parser.addOptionalArg("outerr", "oe", "A joint file for 'normal' and error output presented to the walker. Will overwrite contents if file exists.", "outErrFileName");
}
/**
@ -136,6 +168,8 @@ public class GenomeAnalysisTK extends CommandLineProgram {
rods.add(gff);
}
initializeOutputStreams();
this.engine = new TraversalEngine(INPUT_FILE, REF_FILE_ARG, rods);
// Prepare the sort ordering w.r.t. the sequence dictionary
@ -206,6 +240,33 @@ public class GenomeAnalysisTK extends CommandLineProgram {
return 0;
}
/**
* Initialize the output streams as specified by the user.
*/
private void initializeOutputStreams() {
if( outErrFileName != null && (outFileName != null || errFileName != null) )
throw new IllegalArgumentException("Can't set output/error output file with either out file name or err file name");
try {
if( outErrFileName != null ) {
PrintStream outErrStream = new PrintStream( outErrFileName );
out = outErrStream;
err = outErrStream;
}
if ( outFileName != null ) {
out = new PrintStream( outFileName );
}
if( errFileName != null ) {
err = new PrintStream( errFileName );
}
}
catch( FileNotFoundException ex ) {
throw new RuntimeException("Unable to open a walker output file.", ex);
}
}
/**
* An inappropriately placed validation and performance testing routine for jumping
* around in the fasta sequence file.

View File

@ -14,7 +14,7 @@ import java.util.List;
*/
public class DepthOfCoverageWalker extends LocusWalker<Integer, Integer> {
public Integer map(List<ReferenceOrderedDatum> rodData, char ref, LocusContext context) {
System.out.printf("%s: %d%n", context.getLocation(), context.getReads().size() );
out.printf("%s: %d%n", context.getLocation(), context.getReads().size() );
return 1;
}

View File

@ -18,8 +18,6 @@ public class PileupWalker extends LocusWalker<Integer, Integer> {
public void initialize() {
}
public String walkerType() { return "ByLocus"; }
// Do we actually want to operate on the context?
public boolean filter(List<ReferenceOrderedDatum> rodData, char ref, LocusContext context) {
return true; // We are keeping all the reads
@ -55,7 +53,7 @@ public class PileupWalker extends LocusWalker<Integer, Integer> {
rodString = "[ROD: " + rodString + "]";
//if ( context.getLocation().getStart() % 1 == 0 ) {
System.out.printf("%s: %s %s %s %s%n", context.getLocation(), ref, bases, quals, rodString);
out.printf("%s: %s %s %s %s%n", context.getLocation(), ref, bases, quals, rodString);
//}
return 1;

View File

@ -5,7 +5,7 @@ import org.broadinstitute.sting.gatk.LocusContext;
public class PrintReadsWalker extends ReadWalker<Integer, Integer> {
public Integer map(LocusContext context, SAMRecord read) {
System.out.println(read.format());
out.println(read.format());
return 1;
}

View File

@ -1,5 +1,7 @@
package org.broadinstitute.sting.gatk.walkers;
import java.io.PrintStream;
import org.broadinstitute.sting.gatk.GenomeAnalysisTK;
/**
@ -12,8 +14,20 @@ import org.broadinstitute.sting.gatk.GenomeAnalysisTK;
public abstract class Walker<ReduceType> {
// TODO: Can a walker be templatized so that map and reduce live here?
/**
* A stream for writing normal (non-error) output. System.out by default.
*/
protected PrintStream out = null;
/**
* A stream for writing error output. System.err by default.
*/
protected PrintStream err = null;
protected Walker() {
GenomeAnalysisTK.Instance.loadArgumentsIntoObject(this);
out = GenomeAnalysisTK.Instance.out;
err = GenomeAnalysisTK.Instance.err;
}
/**

View File

@ -49,7 +49,7 @@ public class AlignedReadsHistoWalker extends ReadWalker<Integer, Integer> {
int curTotal = 0;
for ( int i = 0; i < alignCounts.length; i++ ) {
curTotal += alignCounts[i];
System.out.printf("%3d %10d%n", i, curTotal);
out.printf("%3d %10d%n", i, curTotal);
}
}
}

View File

@ -94,9 +94,9 @@ public class AlleleFrequencyMetricsWalker extends LocusWalker<AlleleFrequencyEst
}
// Hapmap debug info
System.out.format("HAPMAP %.2f %.2f %.2f ", hapmap_q, alleleFreq.qstar, alleleFreq.lodVsRef);
out.format("HAPMAP %.2f %.2f %.2f ", hapmap_q, alleleFreq.qstar, alleleFreq.lodVsRef);
String called_genotype = alleleFreq.asString();
System.out.format("%s %s %c %c", hapmap_genotype, called_genotype, alleleFreq.ref, alleleFreq.alt);
out.format("%s %s %c %c", hapmap_genotype, called_genotype, alleleFreq.ref, alleleFreq.alt);
if (alleleFreq.lodVsNextBest >= LOD_cutoff) {
@ -124,7 +124,7 @@ public class AlleleFrequencyMetricsWalker extends LocusWalker<AlleleFrequencyEst
}
}
System.out.print("\n");
out.print("\n");
}
return alleleFreq;
@ -134,29 +134,29 @@ public class AlleleFrequencyMetricsWalker extends LocusWalker<AlleleFrequencyEst
{
if (num_loci_total == 0) { return; }
System.out.printf("\n");
System.out.printf("METRICS Allele Frequency Metrics (LOD >= %.0f)\n", LOD_cutoff);
System.out.printf("METRICS -------------------------------------------------\n");
System.out.printf("METRICS Total loci : %d\n", num_loci_total);
System.out.printf("METRICS Total called with confidence : %d (%.2f%%)\n", num_loci_confident, 100.0 * (float)num_loci_confident / (float)num_loci_total);
out.printf("\n");
out.printf("METRICS Allele Frequency Metrics (LOD >= %.0f)\n", LOD_cutoff);
out.printf("METRICS -------------------------------------------------\n");
out.printf("METRICS Total loci : %d\n", num_loci_total);
out.printf("METRICS Total called with confidence : %d (%.2f%%)\n", num_loci_confident, 100.0 * (float)num_loci_confident / (float)num_loci_total);
if (num_variants != 0)
{
System.out.printf("METRICS Number of variants : %d (%.2f%%) (1/%d)\n", num_variants, 100.0 * (float)num_variants / (float)num_loci_confident, num_loci_confident / num_variants);
System.out.printf("METRICS Fraction of variant sites in dbSNP : %.2f%%\n", 100.0 * (float)dbsnp_hits / (float)num_variants);
System.out.printf("METRICS -------------------------------------------------\n");
System.out.printf("METRICS -- Hapmap Genotyping performance --\n");
System.out.printf("METRICS Num. conf. calls at Hapmap chip sites : %d\n", hapmap_genotype_correct + hapmap_genotype_incorrect);
System.out.printf("METRICS Conf. calls at chip sites correct : %d\n", hapmap_genotype_correct);
System.out.printf("METRICS Conf. calls at chip sites incorrect : %d\n", hapmap_genotype_incorrect);
System.out.printf("METRICS %% of confident calls that are correct : %.2f%%\n", 100.0 * (float) hapmap_genotype_correct / (float)(hapmap_genotype_correct + hapmap_genotype_incorrect));
System.out.printf("METRICS -------------------------------------------------\n");
System.out.printf("METRICS -- Hapmap Reference/Variant performance --\n");
System.out.printf("METRICS Num. conf. calls at Hapmap chip sites : %d\n", hapmap_refvar_correct + hapmap_refvar_incorrect);
System.out.printf("METRICS Conf. calls at chip sites correct : %d\n", hapmap_refvar_correct);
System.out.printf("METRICS Conf. calls at chip sites incorrect : %d\n", hapmap_refvar_incorrect);
System.out.printf("METRICS %% of confident calls that are correct : %.2f%%\n", 100.0 * (float) hapmap_refvar_correct / (float)(hapmap_refvar_correct + hapmap_refvar_incorrect));
out.printf("METRICS Number of variants : %d (%.2f%%) (1/%d)\n", num_variants, 100.0 * (float)num_variants / (float)num_loci_confident, num_loci_confident / num_variants);
out.printf("METRICS Fraction of variant sites in dbSNP : %.2f%%\n", 100.0 * (float)dbsnp_hits / (float)num_variants);
out.printf("METRICS -------------------------------------------------\n");
out.printf("METRICS -- Hapmap Genotyping performance --\n");
out.printf("METRICS Num. conf. calls at Hapmap chip sites : %d\n", hapmap_genotype_correct + hapmap_genotype_incorrect);
out.printf("METRICS Conf. calls at chip sites correct : %d\n", hapmap_genotype_correct);
out.printf("METRICS Conf. calls at chip sites incorrect : %d\n", hapmap_genotype_incorrect);
out.printf("METRICS %% of confident calls that are correct : %.2f%%\n", 100.0 * (float) hapmap_genotype_correct / (float)(hapmap_genotype_correct + hapmap_genotype_incorrect));
out.printf("METRICS -------------------------------------------------\n");
out.printf("METRICS -- Hapmap Reference/Variant performance --\n");
out.printf("METRICS Num. conf. calls at Hapmap chip sites : %d\n", hapmap_refvar_correct + hapmap_refvar_incorrect);
out.printf("METRICS Conf. calls at chip sites correct : %d\n", hapmap_refvar_correct);
out.printf("METRICS Conf. calls at chip sites incorrect : %d\n", hapmap_refvar_incorrect);
out.printf("METRICS %% of confident calls that are correct : %.2f%%\n", 100.0 * (float) hapmap_refvar_correct / (float)(hapmap_refvar_correct + hapmap_refvar_incorrect));
}
System.out.println();
out.println();
}
public void onTraversalDone()
@ -174,7 +174,7 @@ public class AlleleFrequencyMetricsWalker extends LocusWalker<AlleleFrequencyEst
{
// Print RESULT data for confident calls
//if ((alleleFreq.lodVsRef >= 5) || (alleleFreq.lodVsRef <= -5)) { System.out.print(alleleFreq.asTabularString()); }
System.out.print(alleleFreq.asTabularString());
out.print(alleleFreq.asTabularString());
if (this.num_loci_total % 1000 == 0) { printMetrics(); }

View File

@ -38,8 +38,8 @@ public class BaseQualityDumpWalker extends ReadWalker<Integer, Integer> {
for ( int i = 0; i < qualStr.length(); i++)
scores[(reverseFlag ? (qualStr.length()-1-i) : i)] += (int)qualStr.charAt(i) - 33;
for ( int i = 0; i < scores.length; i++ )
System.out.print(scores[i] + " ");
System.out.println("");
out.print(scores[i] + " ");
out.println("");
}
return 1;

View File

@ -53,7 +53,7 @@ public class BaseQualityHistoWalker extends ReadWalker<Integer, Integer> {
}
for ( int i = 0; i < lastNonZero+1; i++ ) {
System.out.printf("%3d : %10d%n", i, this.qualCounts[i]);
out.printf("%3d : %10d%n", i, this.qualCounts[i]);
}
}
}

View File

@ -27,10 +27,10 @@ public class MismatchCounterWalker extends ReadWalker<Integer, Integer> {
assert(refSeq.size() == readBases.size());
System.out.printf("start, stop = %d %d%n", start, stop);
System.out.println(read.format());
System.out.println(Utils.baseList2string(refSeq));
System.out.println(Utils.baseList2string(readBases));
out.printf("start, stop = %d %d%n", start, stop);
out.println(read.format());
out.println(Utils.baseList2string(refSeq));
out.println(Utils.baseList2string(readBases));
}
return nMismatches;

View File

@ -72,7 +72,7 @@ public class MismatchHistoWalker extends ReadWalker<Integer, Integer> {
public void onTraversalDone() {
for ( int i = 0; i < mismatchCounts.length; i++ )
System.out.println((i+1) + "\t" + mismatchCounts[i]);
out.println((i+1) + "\t" + mismatchCounts[i]);
}
private static Object resizeArray (Object oldArray, int newSize) {

View File

@ -126,7 +126,7 @@ public class SingleSampleGenotyper extends LocusWalker<Integer, Integer> {
if ( context.getLocation().getStart() % 1 == 0 ) {
//System.out.printf("%s: %s %s %s %s%n", context.getLocation(), ref, bases, quals, rodString);
System.out.printf("%s %s %s %s\n", ref, bases, G.toString(), rodString);
out.printf("%s %s %s %s\n", ref, bases, G.toString(), rodString);
}
return 1;

View File

@ -412,8 +412,6 @@ public class ArgumentParser {
String fullName = (argument.fullName().length() != 0) ? argument.fullName() : field.getName().trim().toLowerCase();
String shortName = (argument.shortName().length() != 0) ? argument.shortName() : fullName.substring(0,1);
if(shortName.length() != 1)
throw new IllegalArgumentException("Invalid short name: " + shortName);
String description = argument.doc();
boolean isRequired = argument.required();
boolean isFlag = (field.getType() == Boolean.class) || (field.getType() == Boolean.TYPE);