diff --git a/java/src/org/broadinstitute/sting/alignment/AlignmentWalker.java b/java/src/org/broadinstitute/sting/alignment/AlignmentWalker.java index 3787c9fb9..640b30c3f 100644 --- a/java/src/org/broadinstitute/sting/alignment/AlignmentWalker.java +++ b/java/src/org/broadinstitute/sting/alignment/AlignmentWalker.java @@ -27,6 +27,7 @@ package org.broadinstitute.sting.alignment; import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.walkers.ReadWalker; import org.broadinstitute.sting.gatk.walkers.WalkerName; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; @@ -37,6 +38,7 @@ import net.sf.samtools.*; import net.sf.picard.reference.ReferenceSequenceFileFactory; import java.io.File; +import java.io.PrintStream; /** * Aligns reads to a given reference using Heng Li's BWA aligner, presenting the resulting alignments in SAM or BAM format. @@ -53,6 +55,9 @@ public class AlignmentWalker extends ReadWalker { @Argument(fullName = "outputBam", shortName = "ob", doc = "Write output to this BAM filename instead of STDOUT", required = false) private String outputBamFile = null; + @Output + private PrintStream out = null; + @Argument(fullName = "bam_compression", shortName = "compress", doc = "Compression level to use for writing BAM files", required = false) private Integer bamCompression = 5; diff --git a/java/src/org/broadinstitute/sting/alignment/CountBestAlignmentsWalker.java b/java/src/org/broadinstitute/sting/alignment/CountBestAlignmentsWalker.java index 2090f0ffa..1a1e1197d 100644 --- a/java/src/org/broadinstitute/sting/alignment/CountBestAlignmentsWalker.java +++ b/java/src/org/broadinstitute/sting/alignment/CountBestAlignmentsWalker.java @@ -32,9 +32,11 @@ import org.broadinstitute.sting.alignment.bwa.BWTFiles; import org.broadinstitute.sting.alignment.bwa.BWAConfiguration; import org.broadinstitute.sting.alignment.bwa.c.BWACAligner; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import net.sf.samtools.SAMRecord; import java.util.*; +import java.io.PrintStream; /** * Counts the number of best alignments as presented by BWA and outputs a histogram of number of placements vs. the @@ -50,6 +52,9 @@ public class CountBestAlignmentsWalker extends ReadWalker { @Argument(fullName="BWTPrefix",shortName="BWT",doc="Index files generated by bwa index -d bwtsw",required=false) private String prefix = null; + @Output + private PrintStream out = null; + /** * The actual aligner. */ diff --git a/java/src/org/broadinstitute/sting/commandline/Argument.java b/java/src/org/broadinstitute/sting/commandline/Argument.java index e4f31e145..557fbe34e 100755 --- a/java/src/org/broadinstitute/sting/commandline/Argument.java +++ b/java/src/org/broadinstitute/sting/commandline/Argument.java @@ -79,7 +79,7 @@ public @interface Argument { /** * Should this command-line argument be exclusive of others. Should be * a comma-separated list of names of arguments of which this should be - * independent. + * independent. * @return A comma-separated string listing other arguments of which this * argument should be independent. */ diff --git a/java/src/org/broadinstitute/sting/commandline/ArgumentMatch.java b/java/src/org/broadinstitute/sting/commandline/ArgumentMatch.java index 56bedc012..e894cc830 100755 --- a/java/src/org/broadinstitute/sting/commandline/ArgumentMatch.java +++ b/java/src/org/broadinstitute/sting/commandline/ArgumentMatch.java @@ -25,6 +25,8 @@ package org.broadinstitute.sting.commandline; +import org.broadinstitute.sting.gatk.walkers.Multiplexer; + import java.util.*; /** @@ -50,8 +52,17 @@ public class ArgumentMatch implements Iterable { * Create a new argument match, defining its properties later. Used to create invalid arguments. */ public ArgumentMatch() { - this.label = null; - this.definition = null; + this(null,null); + } + + /** + * Minimal constructor for transform function. + * @param label Label of the argument match. Must not be null. + * @param definition The associated definition, if one exists. May be null. + */ + private ArgumentMatch(String label,ArgumentDefinition definition) { + this.label = label; + this.definition = definition; } /** @@ -64,6 +75,7 @@ public class ArgumentMatch implements Iterable { this( label, definition, index, null ); } + private ArgumentMatch( String label, ArgumentDefinition definition, int index, String value ) { this.label = label; this.definition = definition; @@ -74,6 +86,26 @@ public class ArgumentMatch implements Iterable { indices.put(index,values ); } + /** + * Reformat the given entries with the given multiplexer and key. + * TODO: Generify this. + * @param multiplexer Multiplexer that controls the transformation process. + * @param key Key which specifies the transform. + * @return A variant of this ArgumentMatch with all keys transformed. + */ + ArgumentMatch transform(Multiplexer multiplexer, Object key) { + SortedMap> newIndices = new TreeMap>(); + for(Map.Entry> index: indices.entrySet()) { + List newEntries = new ArrayList(); + for(String entry: index.getValue()) + newEntries.add(multiplexer.transformArgument(key,entry)); + newIndices.put(index.getKey(),newEntries); + } + ArgumentMatch newArgumentMatch = new ArgumentMatch(label,definition); + newArgumentMatch.indices.putAll(newIndices); + return newArgumentMatch; + } + /** * Return a string representation of the given argument match, for debugging purposes. * @return String representation of the match. diff --git a/java/src/org/broadinstitute/sting/commandline/ArgumentMatches.java b/java/src/org/broadinstitute/sting/commandline/ArgumentMatches.java index 03978adac..e1e240f51 100755 --- a/java/src/org/broadinstitute/sting/commandline/ArgumentMatches.java +++ b/java/src/org/broadinstitute/sting/commandline/ArgumentMatches.java @@ -25,6 +25,8 @@ package org.broadinstitute.sting.commandline; +import org.broadinstitute.sting.gatk.walkers.Multiplexer; + import java.util.*; /** * Represents a list of potential matches between the arguments defined @@ -160,6 +162,19 @@ public class ArgumentMatches implements Iterable { return matches; } + /** + * Reformat the given entries with the given multiplexer and key. + * TODO: Generify this. + * @param multiplexer Multiplexer that controls the transformation process. + * @param key Key which specifies the transform. + */ + ArgumentMatches transform(Multiplexer multiplexer, Object key) { + ArgumentMatches newArgumentMatches = new ArgumentMatches(); + for(ArgumentMatch match: argumentMatches.values()) + newArgumentMatches.mergeInto(match.transform(multiplexer,key)); + return newArgumentMatches; + } + /** * Merges the given argument match into the set of existing argument matches. * If multiple arguments are present, those arguments will end up grouped. diff --git a/java/src/org/broadinstitute/sting/commandline/ArgumentSource.java b/java/src/org/broadinstitute/sting/commandline/ArgumentSource.java index 1ded083bf..41356d1de 100644 --- a/java/src/org/broadinstitute/sting/commandline/ArgumentSource.java +++ b/java/src/org/broadinstitute/sting/commandline/ArgumentSource.java @@ -25,6 +25,8 @@ package org.broadinstitute.sting.commandline; +import org.broadinstitute.sting.utils.StingException; + import java.lang.reflect.Field; import java.util.Arrays; import java.util.List; @@ -67,9 +69,28 @@ public class ArgumentSource { * @param field Field containing the argument. Field must be annotated with 'Input' or 'Output'. */ public ArgumentSource( Field[] parentFields, Field field ) { + this(parentFields,field,ArgumentTypeDescriptor.create(field.getType())); + } + + /** + * Create a new command-line argument target. + * @param parentFields Parent fields containing the the field. Field must be annotated with 'ArgumentCollection'. + * @param field Field containing the argument. Field must be annotated with 'Input' or 'Output'. + * @param typeDescriptor custom type descriptor to use when parsing. + */ + private ArgumentSource( Field[] parentFields, Field field, ArgumentTypeDescriptor typeDescriptor) { this.parentFields = parentFields; this.field = field; - this.typeDescriptor = ArgumentTypeDescriptor.create( field.getType() ); + this.typeDescriptor = typeDescriptor; + } + + /** + * Somewhat hackish copy constructor to track fields with a custom type descriptor. + * TODO: Separate type descriptor from ArgumentSource in general usage. + * @param typeDescriptor New type descriptor for the object. + */ + public ArgumentSource copyWithCustomTypeDescriptor(final ArgumentTypeDescriptor typeDescriptor) { + return new ArgumentSource(parentFields,field,typeDescriptor); } /** @@ -111,15 +132,15 @@ public class ArgumentSource { * @return True if this descriptor wants to override any default the user specified. False otherwise. */ public boolean overridesDefault() { - return typeDescriptor.overridesDefault(); + return typeDescriptor.createsTypeDefault(this,field.getType()); } /** * Provides the default value for the command-line argument. * @return Default value to load into the object. */ - public Object getDefault() { - return typeDescriptor.getDefault(); + public Object createDefault() { + return typeDescriptor.createTypeDefault(this,field.getType()); } /** @@ -155,6 +176,26 @@ public class ArgumentSource { return field.isAnnotationPresent(Hidden.class); } + /** + * Is this command-line argument dependent on some primitive argument types? + * @return True if this command-line argument depends on other arguments; false otherwise. + */ + public boolean isDependent() { + return typeDescriptor instanceof MultiplexArgumentTypeDescriptor; + } + + /** + * Builds out a new type descriptor for the given dependent argument as a function + * of the containing object. + * @param containingObject The containing object. + * @return An argument type descriptor for the custom derivative field. + */ + public MultiplexArgumentTypeDescriptor createDependentTypeDescriptor(Object containingObject) { + if(!isDependent()) + throw new StingException("Field " + field.getName() + " is independent; no dependent type descriptor can be derived."); + return ((MultiplexArgumentTypeDescriptor)typeDescriptor).createCustomTypeDescriptor(this,containingObject); + } + /** * Gets a string representation of the argument source for debugging. * @return String representation of the argument source. diff --git a/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java b/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java index 1e0e574a9..945f68741 100644 --- a/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java @@ -26,11 +26,15 @@ package org.broadinstitute.sting.commandline; import org.broadinstitute.sting.utils.StingException; +import org.broadinstitute.sting.utils.classloader.JVMUtils; +import org.broadinstitute.sting.gatk.walkers.Multiplex; +import org.broadinstitute.sting.gatk.walkers.Multiplexer; import org.apache.log4j.Logger; import java.lang.annotation.Annotation; import java.lang.reflect.*; import java.util.*; +import java.io.OutputStream; /** * An descriptor capable of providing parsers that can parse any type @@ -52,7 +56,8 @@ public abstract class ArgumentTypeDescriptor { * The type of set used must be ordered (but not necessarily sorted). */ private static Set descriptors = new LinkedHashSet( Arrays.asList(new SimpleArgumentTypeDescriptor(), - new CompoundArgumentTypeDescriptor()) ); + new CompoundArgumentTypeDescriptor(), + new MultiplexArgumentTypeDescriptor()) ); /** * Adds new, user defined descriptors to the head of the descriptor list. @@ -88,20 +93,18 @@ public abstract class ArgumentTypeDescriptor { public abstract boolean supports( Class type ); /** - * This argument type descriptor wants to override any default value the user might have specified. - * @return True if this descriptor wants to override any default the user specified. False otherwise. + * Returns false if a type-specific default can be employed. + * @param source Source of the command-line argument. + * @return True to throw in a type specific default. False otherwise. */ - public boolean overridesDefault() { - return false; - } + public boolean createsTypeDefault(ArgumentSource source,Class type) { return false; } /** - * Provides the default value for the command-line argument. - * @return Default value to load into the object. + * Generates a default for the given type. + * @param source Source of the command-line argument. + * @return A default value for the given type. */ - public Object getDefault() { - throw new UnsupportedOperationException(String.format("Type descriptor %s cannot override default value of command-line argument",this.getClass())); - } + public Object createTypeDefault(ArgumentSource source,Class type) { throw new UnsupportedOperationException("Unable to create default for type " + getClass()); } /** * Given the given argument source and attributes, synthesize argument definitions for command-line arguments. @@ -156,15 +159,7 @@ public abstract class ArgumentTypeDescriptor { * @throws IllegalArgumentException If more than one parameterized type is found on the field. */ protected Class getCollectionComponentType( Field field ) { - // If this is a parameterized collection, find the contained type. If blow up if more than one type exists. - if( field.getGenericType() instanceof ParameterizedType) { - ParameterizedType parameterizedType = (ParameterizedType)field.getGenericType(); - if( parameterizedType.getActualTypeArguments().length > 1 ) - throw new IllegalArgumentException("Unable to determine collection type of field: " + field.toString()); - return (Class)parameterizedType.getActualTypeArguments()[0]; - } - else - return String.class; + return null; } /** @@ -322,6 +317,7 @@ class SimpleArgumentTypeDescriptor extends ArgumentTypeDescriptor { } } + /** * A mapping of the primitive types to their associated wrapper classes. Is there really no way to infer @@ -338,7 +334,7 @@ class SimpleArgumentTypeDescriptor extends ArgumentTypeDescriptor { put( Float.TYPE, Float.class ); put( Double.TYPE, Double.class ); } - }; + }; } /** @@ -413,4 +409,167 @@ class CompoundArgumentTypeDescriptor extends ArgumentTypeDescriptor { else throw new StingException("Unsupported compound argument type: " + type); } + + /** + * Return the component type of a field, or String.class if the type cannot be found. + * @param field The reflected field to inspect. + * @return The parameterized component type, or String.class if the parameterized type could not be found. + * @throws IllegalArgumentException If more than one parameterized type is found on the field. + */ + @Override + protected Class getCollectionComponentType( Field field ) { + // If this is a parameterized collection, find the contained type. If blow up if more than one type exists. + if( field.getGenericType() instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType)field.getGenericType(); + if( parameterizedType.getActualTypeArguments().length > 1 ) + throw new IllegalArgumentException("Unable to determine collection type of field: " + field.toString()); + return (Class)parameterizedType.getActualTypeArguments()[0]; + } + else + return String.class; + } +} + +class MultiplexArgumentTypeDescriptor extends ArgumentTypeDescriptor { + /** + * The multiplexer controlling how data is split. + */ + private final Multiplexer multiplexer; + + /** + * The set of identifiers for the multiplexed entries. + */ + private final Collection multiplexedIds; + + public MultiplexArgumentTypeDescriptor() { + this.multiplexer = null; + this.multiplexedIds = null; + } + + /** + * Private constructor to use in creating a closure of the MultiplexArgumentTypeDescriptor specific to the + * given set of multiplexed ids. + * @param multiplexedIds The collection of multiplexed entries + */ + private MultiplexArgumentTypeDescriptor(final Multiplexer multiplexer, final Collection multiplexedIds) { + this.multiplexer = multiplexer; + this.multiplexedIds = multiplexedIds; + } + + @Override + public boolean supports( Class type ) { + return ( Map.class.isAssignableFrom(type) ); + } + + @Override + public boolean createsTypeDefault(ArgumentSource source,Class type) { + if(multiplexer == null || multiplexedIds == null) + throw new StingException("No multiplexed ids available"); + // Always create a multiplexed mapping. + return true; + } + + @Override + public Object createTypeDefault(ArgumentSource source,Class type) { + if(multiplexer == null || multiplexedIds == null) + throw new StingException("No multiplexed ids available"); + + Map multiplexedMapping = new HashMap(); + Class componentType = getCollectionComponentType(source.field); + ArgumentTypeDescriptor componentTypeDescriptor = ArgumentTypeDescriptor.create(componentType); + + for(Object id: multiplexedIds) { + Object value = null; + if(componentTypeDescriptor.createsTypeDefault(source,componentType)) + value = componentTypeDescriptor.createTypeDefault(source,componentType); + multiplexedMapping.put(id,value); + } + return multiplexedMapping; + } + + + @Override + public Object parse( ArgumentSource source, Class type, ArgumentMatches matches ) { + if(multiplexedIds == null) + throw new StingException("Cannot directly parse a MultiplexArgumentTypeDescriptor; must create a derivative type descriptor first."); + + Map multiplexedMapping = new HashMap(); + Class componentType = getCollectionComponentType(source.field); + + for(Object id: multiplexedIds) { + Object value = ArgumentTypeDescriptor.create(componentType).parse(source,componentType,matches.transform(multiplexer,id)); + multiplexedMapping.put(id,value); + } + return multiplexedMapping; + } + + public MultiplexArgumentTypeDescriptor createCustomTypeDescriptor(ArgumentSource dependentArgument,Object containingObject) { + String[] sourceFields = dependentArgument.field.getAnnotation(Multiplex.class).arguments(); + + List allSources = ParsingEngine.extractArgumentSources(containingObject.getClass()); + Class[] sourceTypes = new Class[sourceFields.length]; + Object[] sourceValues = new Object[sourceFields.length]; + int currentField = 0; + + for(String sourceField: sourceFields) { + boolean fieldFound = false; + for(ArgumentSource source: allSources) { + if(!source.field.getName().equals(sourceField)) + continue; + if(source.field.isAnnotationPresent(Multiplex.class)) + throw new StingException("Command-line arguments can only depend on independent fields"); + sourceTypes[currentField] = source.field.getType(); + sourceValues[currentField] = JVMUtils.getFieldValue(source.field,containingObject); + currentField++; + fieldFound = true; + } + if(!fieldFound) + throw new StingException(String.format("Unable to find source field %s, referred to by dependent field %s",sourceField,dependentArgument.field.getName())); + } + + Class multiplexerType = dependentArgument.field.getAnnotation(Multiplex.class).value(); + Constructor multiplexerConstructor = null; + try { + multiplexerConstructor = multiplexerType.getConstructor(sourceTypes); + multiplexerConstructor.setAccessible(true); + } + catch(NoSuchMethodException ex) { + throw new StingException(String.format("Unable to find constructor for class %s with parameters %s",multiplexerType.getName(),Arrays.deepToString(sourceFields)),ex); + } + + Multiplexer multiplexer = null; + try { + multiplexer = multiplexerConstructor.newInstance(sourceValues); + } + catch(IllegalAccessException ex) { + throw new StingException(String.format("Constructor for class %s with parameters %s is inaccessible",multiplexerType.getName(),Arrays.deepToString(sourceFields)),ex); + } + catch(InstantiationException ex) { + throw new StingException(String.format("Can't create class %s with parameters %s",multiplexerType.getName(),Arrays.deepToString(sourceFields)),ex); + } + catch(InvocationTargetException ex) { + throw new StingException(String.format("Can't invoke constructor of class %s with parameters %s",multiplexerType.getName(),Arrays.deepToString(sourceFields)),ex); + } + + return new MultiplexArgumentTypeDescriptor(multiplexer,multiplexer.multiplex()); + } + + /** + * Return the component type of a field, or String.class if the type cannot be found. + * @param field The reflected field to inspect. + * @return The parameterized component type, or String.class if the parameterized type could not be found. + * @throws IllegalArgumentException If more than one parameterized type is found on the field. + */ + @Override + protected Class getCollectionComponentType( Field field ) { + // Multiplex arguments must resolve to maps from which the clp should extract the second type. + if( field.getGenericType() instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType)field.getGenericType(); + if( parameterizedType.getActualTypeArguments().length != 2 ) + throw new IllegalArgumentException("Unable to determine collection type of field: " + field.toString()); + return (Class)parameterizedType.getActualTypeArguments()[1]; + } + else + return String.class; + } } diff --git a/java/src/org/broadinstitute/sting/commandline/Output.java b/java/src/org/broadinstitute/sting/commandline/Output.java index 23f1a4cd2..5386a3a94 100644 --- a/java/src/org/broadinstitute/sting/commandline/Output.java +++ b/java/src/org/broadinstitute/sting/commandline/Output.java @@ -40,7 +40,7 @@ public @interface Output { * prefixed on the command-line with a double dash (--). * @return Selected full name, or "" to use the default. */ - String fullName() default ""; + String fullName() default "out"; /** * Specified short name of the command. Short names should be prefixed @@ -48,21 +48,21 @@ public @interface Output { * short names or be separated from them by a space. * @return Selected short name, or "" for none. */ - String shortName() default ""; + String shortName() default "o"; /** * Documentation for the command-line argument. Should appear when the * --help argument is specified. * @return Doc string associated with this command-line argument. */ - String doc(); + String doc() default "An output file presented to the walker. Will overwrite contents if file exists."; /** * Is this command-line argument required. The application should exit * printing help if this command-line argument is not specified. * @return True if the argument is required. False otherwise. */ - boolean required() default true; + boolean required() default false; /** * Should this command-line argument be exclusive of others. Should be diff --git a/java/src/org/broadinstitute/sting/commandline/ParsingEngine.java b/java/src/org/broadinstitute/sting/commandline/ParsingEngine.java index d48123a4d..53eaa3a01 100755 --- a/java/src/org/broadinstitute/sting/commandline/ParsingEngine.java +++ b/java/src/org/broadinstitute/sting/commandline/ParsingEngine.java @@ -254,8 +254,22 @@ public class ParsingEngine { */ public void loadArgumentsIntoObject( Object object ) { List argumentSources = extractArgumentSources(object.getClass()); - for( ArgumentSource argumentSource: argumentSources ) + + List dependentArguments = new ArrayList(); + for( ArgumentSource argumentSource: argumentSources ) { + // If this argument source depends on other command-line arguments, skip it and make a note to process it later. + if(argumentSource.isDependent()) { + dependentArguments.add(argumentSource); + continue; + } loadValueIntoObject( argumentSource, object, argumentMatches.findMatches(argumentSource) ); + } + + for(ArgumentSource dependentArgument: dependentArguments) { + MultiplexArgumentTypeDescriptor dependentDescriptor = dependentArgument.createDependentTypeDescriptor(object); + ArgumentSource dependentSource = dependentArgument.copyWithCustomTypeDescriptor(dependentDescriptor); + loadValueIntoObject(dependentSource,object,argumentMatches.findMatches(dependentSource)); + } } /** @@ -277,7 +291,7 @@ public class ParsingEngine { throw new StingException("Internal command-line parser error: unable to find a home for argument matches " + argumentMatches); for( Object target: targets ) { - Object value = (argumentMatches.size() != 0) ? source.parse(argumentMatches) : source.getDefault(); + Object value = (argumentMatches.size() != 0) ? source.parse(argumentMatches) : source.createDefault(); JVMUtils.setFieldValue(source.field,target,value); } } diff --git a/java/src/org/broadinstitute/sting/gatk/CommandLineExecutable.java b/java/src/org/broadinstitute/sting/gatk/CommandLineExecutable.java index 8169fc7f3..f93af2ad6 100644 --- a/java/src/org/broadinstitute/sting/gatk/CommandLineExecutable.java +++ b/java/src/org/broadinstitute/sting/gatk/CommandLineExecutable.java @@ -99,13 +99,9 @@ public abstract class CommandLineExecutable extends CommandLineProgram { * @return A collection of type descriptors generating implementation-dependent placeholders. */ protected Collection getArgumentTypeDescriptors() { - return Arrays.asList( new VCFWriterArgumentTypeDescriptor(GATKEngine), - new SAMFileReaderArgumentTypeDescriptor(GATKEngine), - new SAMFileWriterArgumentTypeDescriptor(GATKEngine), - new OutputStreamArgumentTypeDescriptor(GATKEngine) ); + return GATKEngine.getArgumentTypeDescriptors(); } - /** * GATK can add arguments dynamically based on analysis type. * diff --git a/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java b/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java index f38ebdd77..41fcd9ca8 100755 --- a/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java +++ b/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java @@ -44,7 +44,7 @@ import org.broadinstitute.sting.gatk.filters.FilterManager; import org.broadinstitute.sting.gatk.filters.ReadGroupBlackListFilter; import org.broadinstitute.sting.gatk.filters.ZeroMappingQualityReadFilter; import org.broadinstitute.sting.gatk.io.OutputTracker; -import org.broadinstitute.sting.gatk.io.stubs.Stub; +import org.broadinstitute.sting.gatk.io.stubs.*; import org.broadinstitute.sting.gatk.refdata.tracks.RMDTrack; import org.broadinstitute.sting.gatk.refdata.tracks.RMDTrackManager; import org.broadinstitute.sting.gatk.refdata.utils.RMDIntervalGenerator; @@ -52,6 +52,7 @@ import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.utils.*; import org.broadinstitute.sting.commandline.ArgumentException; import org.broadinstitute.sting.commandline.ArgumentSource; +import org.broadinstitute.sting.commandline.ArgumentTypeDescriptor; import java.io.File; import java.util.*; @@ -161,7 +162,7 @@ public class GenomeAnalysisEngine { // our microscheduler, which is in charge of running everything MicroScheduler microScheduler = createMicroscheduler(my_walker); - // create the output streams + // create the output streams " initializeOutputStreams(my_walker, microScheduler.getOutputTracker()); initializeIntervals(); @@ -516,6 +517,19 @@ public class GenomeAnalysisEngine { } + /** + * Subclasses of CommandLinePrograms can provide their own types of command-line arguments. + * @return A collection of type descriptors generating implementation-dependent placeholders. + */ + protected Collection getArgumentTypeDescriptors() { + return Arrays.asList( new VCFWriterArgumentTypeDescriptor(this,System.out), + new SAMFileReaderArgumentTypeDescriptor(this), + new SAMFileWriterArgumentTypeDescriptor(this,System.out), + new OutputStreamArgumentTypeDescriptor(this,System.out) ); + } + + + /** * Bundles all the source information about the reads into a unified data structure. * @@ -856,11 +870,6 @@ public class GenomeAnalysisEngine { * @param outputTracker the tracker supplying the initialization data. */ private void initializeOutputStreams(Walker walker, OutputTracker outputTracker) { - if (argCollection.outErrFileName != null) - outputTracker.initializeCoreIO(argCollection.outErrFileName, argCollection.outErrFileName); - else - outputTracker.initializeCoreIO(argCollection.outFileName, argCollection.errFileName); - for (Map.Entry input : inputs.entrySet()) outputTracker.addInput(input.getKey(), input.getValue()); for (Stub stub : outputs) diff --git a/java/src/org/broadinstitute/sting/gatk/arguments/GATKArgumentCollection.java b/java/src/org/broadinstitute/sting/gatk/arguments/GATKArgumentCollection.java index 33e8d3a22..0f295089f 100755 --- a/java/src/org/broadinstitute/sting/gatk/arguments/GATKArgumentCollection.java +++ b/java/src/org/broadinstitute/sting/gatk/arguments/GATKArgumentCollection.java @@ -30,7 +30,6 @@ import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.interval.IntervalMergingRule; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.Input; -import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.DownsampleType; import org.broadinstitute.sting.utils.interval.IntervalSetRule; import org.simpleframework.xml.*; @@ -113,21 +112,6 @@ public class GATKArgumentCollection { @Input(fullName = "hapmap_chip", shortName = "hc", doc = "Hapmap chip file", required = false) public String HAPMAPChipFile = null; - /** An output file presented to the walker. */ - @Element(required = false) - @Output(fullName = "out", shortName = "o", doc = "An output file presented to the walker. Will overwrite contents if file exists.", required = false) - public String outFileName = null; - - /** An error output file presented to the walker. */ - @Element(required = false) - @Output(fullName = "err", shortName = "e", doc = "An error output file presented to the walker. Will overwrite contents if file exists.", required = false) - public String errFileName = null; - - /** A joint file for both 'normal' and error output presented to the walker. */ - @Element(required = false) - @Output(fullName = "outerr", shortName = "oe", doc = "A joint file for 'normal' and error output presented to the walker. Will overwrite contents if file exists.", required = false) - public String outErrFileName = null; - @Element(required = false) @Argument(fullName = "filterZeroMappingQualityReads", shortName = "fmq0", doc = "If true, mapping quality zero reads will be filtered at the lowest GATK level. Vastly improves performance at areas with abnormal depth due to mapping Q0 reads", required = false) public Boolean filterZeroMappingQualityReads = false; @@ -325,15 +309,6 @@ public class GATKArgumentCollection { (other.downsampleCoverage != null && !other.downsampleCoverage.equals(this.downsampleCoverage))) { return false; } - if (!other.outFileName.equals(this.outFileName)) { - return false; - } - if (!other.errFileName.equals(this.errFileName)) { - return false; - } - if (!other.outErrFileName.equals(this.outErrFileName)) { - return false; - } if (other.numberOfThreads != this.numberOfThreads) { return false; } diff --git a/java/src/org/broadinstitute/sting/gatk/examples/CoverageBySample.java b/java/src/org/broadinstitute/sting/gatk/examples/CoverageBySample.java index 7ed7f9003..a1419ba70 100644 --- a/java/src/org/broadinstitute/sting/gatk/examples/CoverageBySample.java +++ b/java/src/org/broadinstitute/sting/gatk/examples/CoverageBySample.java @@ -6,13 +6,17 @@ import org.broadinstitute.sting.gatk.refdata.*; import org.broadinstitute.sting.gatk.walkers.LocusWalker; import org.broadinstitute.sting.gatk.contexts.*; import org.broadinstitute.sting.utils.pileup.*; +import org.broadinstitute.sting.commandline.Output; import java.util.*; +import java.io.PrintStream; /** * Computes the coverage per sample. */ public class CoverageBySample extends LocusWalker { + @Output + protected PrintStream out; private HashSet sampleNames = new HashSet(); diff --git a/java/src/org/broadinstitute/sting/gatk/io/OutputTracker.java b/java/src/org/broadinstitute/sting/gatk/io/OutputTracker.java index 97a66be22..3ecf6f115 100755 --- a/java/src/org/broadinstitute/sting/gatk/io/OutputTracker.java +++ b/java/src/org/broadinstitute/sting/gatk/io/OutputTracker.java @@ -67,30 +67,6 @@ public abstract class OutputTracker { */ protected OutputStreamStub errStub = null; - /** - * Create an object to manage output given filenames for the output and error files. - * If no files are specified, returns null. - * @param outFileName Name of the output file. - * @param errFileName Name of the error file. - */ - public void initializeCoreIO( String outFileName, String errFileName ) { - // If the two output streams match and are non-null, initialize them identically. - // Otherwise, initialize them separately. - if( outFileName != null && outFileName.equals(errFileName) ) { - outStub = errStub = new OutputStreamStub(new File(outFileName)); - addOutput(outStub,new OutputStreamStorage(outStub)); - } - else { - outStub = (outFileName != null) ? new OutputStreamStub(new File(outFileName)) - : new OutputStreamStub(System.out); - addOutput(outStub,new OutputStreamStorage(outStub)); - - errStub = (errFileName != null) ? new OutputStreamStub(new File(errFileName)) - : new OutputStreamStub(System.err); - addOutput(errStub,new OutputStreamStorage(errStub)); - } - } - /** * Gets the output storage associated with a given stub. * @param stub The stub for which to find / create the right output stream. @@ -100,9 +76,6 @@ public abstract class OutputTracker { public abstract T getStorage( Stub stub ); public void prepareWalker( Walker walker ) { - installStub( walker, "out", new PrintStream(outStub) ); - installStub( walker, "err", new PrintStream(errStub) ); - for( Map.Entry io: inputs.entrySet() ) { ArgumentSource targetField = io.getKey(); Object targetValue = io.getValue(); diff --git a/java/src/org/broadinstitute/sting/gatk/io/storage/SAMFileWriterStorage.java b/java/src/org/broadinstitute/sting/gatk/io/storage/SAMFileWriterStorage.java index 2b5cf2b8c..d516066f6 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/storage/SAMFileWriterStorage.java +++ b/java/src/org/broadinstitute/sting/gatk/io/storage/SAMFileWriterStorage.java @@ -31,6 +31,7 @@ import net.sf.samtools.util.CloseableIterator; import java.io.*; import org.broadinstitute.sting.gatk.io.stubs.SAMFileWriterStub; +import org.broadinstitute.sting.utils.StingException; /** * Provides temporary storage for SAMFileWriters. @@ -48,10 +49,17 @@ public class SAMFileWriterStorage implements SAMFileWriter, Storage, VCFWriter { if(stub.getFile() != null) { this.file = stub.getFile(); try { - this.stream = new PrintStream(stub.getFile()); + this.stream = new PrintStream(file); } catch(IOException ex) { throw new StingException("Unable to open target output stream",ex); @@ -45,7 +45,7 @@ public class VCFWriterStorage implements Storage, VCFWriter { else throw new StingException("Unable to create target to which to write; storage was provided with neither a file nor a stream."); - writer = new VCFWriterImpl(stream); + writer = new StandardVCFWriter(stream); } /** @@ -61,7 +61,7 @@ public class VCFWriterStorage implements Storage, VCFWriter { catch(IOException ex) { throw new StingException("Unable to open target output stream",ex); } - writer = new VCFWriterImpl(this.stream); + writer = new StandardVCFWriter(this.stream); Set samples = SampleUtils.getSAMFileSamples(stub.getSAMFileHeader()); writer.writeHeader(new VCFHeader(null, samples)); } diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/OutputStreamArgumentTypeDescriptor.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/OutputStreamArgumentTypeDescriptor.java index 228fb09bc..75b29e47e 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/OutputStreamArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/OutputStreamArgumentTypeDescriptor.java @@ -33,6 +33,7 @@ import java.io.OutputStream; import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Field; /** * Insert an OutputStreamStub instead of a full-fledged concrete OutputStream implementations. @@ -41,14 +42,21 @@ public class OutputStreamArgumentTypeDescriptor extends ArgumentTypeDescriptor { /** * The engine into which output stubs should be fed. */ - private GenomeAnalysisEngine engine; + private final GenomeAnalysisEngine engine; + + /** + * The default output stream to write to write this info if + */ + private final OutputStream defaultOutputStream; /** * Create a new OutputStream argument, notifying the given engine when that argument has been created. * @param engine Engine to add SAMFileWriter output to. + * @param defaultOutputStream Default target for output file. */ - public OutputStreamArgumentTypeDescriptor( GenomeAnalysisEngine engine ) { - this.engine = engine; + public OutputStreamArgumentTypeDescriptor(GenomeAnalysisEngine engine,OutputStream defaultOutputStream) { + this.engine = engine; + this.defaultOutputStream = defaultOutputStream; } @Override @@ -56,6 +64,18 @@ public class OutputStreamArgumentTypeDescriptor extends ArgumentTypeDescriptor { return getConstructorForClass(type) != null; } + @Override + public boolean createsTypeDefault(ArgumentSource source,Class type) { + return true; + } + + @Override + public Object createTypeDefault(ArgumentSource source,Class type) { + OutputStreamStub stub = new OutputStreamStub(defaultOutputStream); + engine.addOutput(stub); + return createInstanceOfClass(type,stub); + } + @Override public Object parse( ArgumentSource source, Class type, ArgumentMatches matches ) { ArgumentDefinition definition = createDefaultArgumentDefinition(source); @@ -65,18 +85,7 @@ public class OutputStreamArgumentTypeDescriptor extends ArgumentTypeDescriptor { engine.addOutput(stub); - try { - return getConstructorForClass(type).newInstance(stub); - } - catch( InstantiationException ex ) { - throw new StingException("Could not instantiate class with OutputStream constructor: " + type.getName()); - } - catch( IllegalAccessException ex ) { - throw new StingException("Could not access class with OutputStream constructor: " + type.getName()); - } - catch( InvocationTargetException ex ) { - throw new StingException("Could not invoke constructor for class with OutputStream constructor: " + type.getName()); - } + return createInstanceOfClass(type,stub); } /** @@ -92,4 +101,25 @@ public class OutputStreamArgumentTypeDescriptor extends ArgumentTypeDescriptor { return null; } } + + /** + * Creat a new instance of the class accepting a single outputstream constructor. + * @param type Type of object to create. + * @param outputStream resulting output stream. + * @return A new instance of the outputstream-derived class. + */ + private Object createInstanceOfClass(Class type,OutputStream outputStream) { + try { + return getConstructorForClass(type).newInstance(outputStream); + } + catch( InstantiationException ex ) { + throw new StingException("Could not instantiate class with OutputStream constructor: " + type.getName()); + } + catch( IllegalAccessException ex ) { + throw new StingException("Could not access class with OutputStream constructor: " + type.getName()); + } + catch( InvocationTargetException ex ) { + throw new StingException("Could not invoke constructor for class with OutputStream constructor: " + type.getName()); + } + } } diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileReaderArgumentTypeDescriptor.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileReaderArgumentTypeDescriptor.java index a1c1ddea4..12363bc61 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileReaderArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileReaderArgumentTypeDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 The Broad Institute + * Copyright (c) 2010, The Broad Institute * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -12,15 +12,14 @@ * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. - * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. */ package org.broadinstitute.sting.gatk.io.stubs; @@ -34,6 +33,7 @@ import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; import net.sf.samtools.SAMFileReader; import java.io.File; +import java.io.OutputStream; /** * Describe how to parse SAMFileReaders. diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterArgumentTypeDescriptor.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterArgumentTypeDescriptor.java index 7f9802220..e542cc2d2 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterArgumentTypeDescriptor.java @@ -35,6 +35,7 @@ import java.lang.annotation.Annotation; import java.util.List; import java.util.Arrays; import java.io.File; +import java.io.OutputStream; /** * Insert a SAMFileWriterStub instead of a full-fledged concrete OutputStream implementations. @@ -49,16 +50,22 @@ public class SAMFileWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor /** * The engine into which output stubs should be fed. */ - private GenomeAnalysisEngine engine; + private final GenomeAnalysisEngine engine; + + /** + * The default location to which data should be written if the user specifies no such location. + */ + private final OutputStream defaultOutputStream; /** * Create a new SAMFileWriter argument, notifying the given engine when that argument has been created. * @param engine Engine to add SAMFileWriter output to. + * @param defaultOutputStream the target for the data */ - public SAMFileWriterArgumentTypeDescriptor( GenomeAnalysisEngine engine ) { + public SAMFileWriterArgumentTypeDescriptor( GenomeAnalysisEngine engine, OutputStream defaultOutputStream ) { this.engine = engine; + this.defaultOutputStream = defaultOutputStream; } - @Override public boolean supports( Class type ) { @@ -71,6 +78,18 @@ public class SAMFileWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor createBAMCompressionArgumentDefinition(source) ); } + @Override + public boolean createsTypeDefault(ArgumentSource source,Class type) { + return true; + } + + @Override + public Object createTypeDefault(ArgumentSource source,Class type) { + SAMFileWriterStub stub = new SAMFileWriterStub(engine,defaultOutputStream); + engine.addOutput(stub); + return stub; + } + @Override public Object parse( ArgumentSource source, Class type, ArgumentMatches matches ) { String writerFileName = getArgumentValue( createBAMArgumentDefinition(source), matches ); diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterStub.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterStub.java index da3237e26..e47aea6fe 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterStub.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterStub.java @@ -30,6 +30,7 @@ import net.sf.samtools.SAMRecord; import net.sf.samtools.SAMFileHeader; import java.io.File; +import java.io.OutputStream; import org.broadinstitute.sting.gatk.io.OutputTracker; import org.broadinstitute.sting.gatk.io.StingSAMFileWriter; @@ -59,6 +60,11 @@ public class SAMFileWriterStub implements Stub, StingSAMFileWrite */ private final File samFile; + /** + * The target output stream, to be used in place of the SAM file. + */ + private final OutputStream samOutputStream; + /** * The validation stringency to apply when reading this file. */ @@ -90,6 +96,18 @@ public class SAMFileWriterStub implements Stub, StingSAMFileWrite public SAMFileWriterStub( GenomeAnalysisEngine engine, File samFile ) { this.engine = engine; this.samFile = samFile; + this.samOutputStream = null; + } + + /** + * Create a new stub given the requested SAM file and compression level. + * @param engine source of header data, maybe other data about input files. + * @param stream Output stream to which data should be written. + */ + public SAMFileWriterStub( GenomeAnalysisEngine engine, OutputStream stream ) { + this.engine = engine; + this.samFile = null; + this.samOutputStream = stream; } /** @@ -100,6 +118,10 @@ public class SAMFileWriterStub implements Stub, StingSAMFileWrite return samFile; } + public OutputStream getSAMOutputStream() { + return samOutputStream; + } + /** * Retrieves the header to use when creating the new SAM file. * @return header to use when creating the new SAM file. diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/VCFWriterArgumentTypeDescriptor.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/VCFWriterArgumentTypeDescriptor.java index 7d9e764c2..895607c3a 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/VCFWriterArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/VCFWriterArgumentTypeDescriptor.java @@ -30,6 +30,7 @@ import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; import java.io.File; +import java.io.OutputStream; import java.lang.annotation.Annotation; import java.util.List; import java.util.Arrays; @@ -46,12 +47,19 @@ public class VCFWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor { */ private GenomeAnalysisEngine engine; + /** + * The default location to which data should be written if the user specifies no such location. + */ + private final OutputStream defaultOutputStream; + /** * Create a new GenotypeWriter argument, notifying the given engine when that argument has been created. * @param engine the engine to be notified. + * @param defaultOutputStream the default output stream to be written to if nothing else is specified. */ - public VCFWriterArgumentTypeDescriptor(GenomeAnalysisEngine engine) { + public VCFWriterArgumentTypeDescriptor(GenomeAnalysisEngine engine, OutputStream defaultOutputStream) { this.engine = engine; + this.defaultOutputStream = defaultOutputStream; } /** @@ -64,12 +72,6 @@ public class VCFWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor { return VCFWriter.class.equals(type); } - /** - * Create the argument definitions associated with this source. - * Assumes that this type descriptor is relevant for this source. - * @param source Source class and field for the given argument. - * @return A list of all associated argument definitions. - */ @Override public List createArgumentDefinitions( ArgumentSource source ) { return Arrays.asList( createGenotypeFileArgumentDefinition(source) ); @@ -80,19 +82,15 @@ public class VCFWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor { * @return true always. */ @Override - public boolean overridesDefault() { + public boolean createsTypeDefault(ArgumentSource source,Class type) { return true; } - /** - * Provide the default value for this argument. - * @return A VCFGenotypeWriter which writes to the default output stream. - */ @Override - public Object getDefault() { - VCFWriterStub defaultGenotypeWriter = new VCFWriterStub(engine,System.out); - engine.addOutput(defaultGenotypeWriter); - return defaultGenotypeWriter; + public Object createTypeDefault(ArgumentSource source,Class type) { + VCFWriterStub stub = new VCFWriterStub(engine,defaultOutputStream); + engine.addOutput(stub); + return stub; } /** diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/VCFWriterStub.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/VCFWriterStub.java index 694f53e63..fb5ef0374 100755 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/VCFWriterStub.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/VCFWriterStub.java @@ -27,6 +27,7 @@ package org.broadinstitute.sting.gatk.io.stubs; import java.io.File; import java.io.PrintStream; +import java.io.OutputStream; import org.broad.tribble.util.variantcontext.VariantContext; import org.broad.tribble.vcf.VCFHeader; @@ -83,10 +84,10 @@ public class VCFWriterStub implements Stub, VCFWriter { * @param engine GATK engine. * @param genotypeStream stream to (ultimately) write. */ - public VCFWriterStub(GenomeAnalysisEngine engine,PrintStream genotypeStream) { + public VCFWriterStub(GenomeAnalysisEngine engine, OutputStream genotypeStream) { this.engine = engine; this.genotypeFile = null; - this.genotypeStream = genotypeStream; + this.genotypeStream = new PrintStream(genotypeStream); } /** diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/ClipReadsWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/ClipReadsWalker.java index acbc708bb..17a45cd6a 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/ClipReadsWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/ClipReadsWalker.java @@ -31,6 +31,7 @@ import net.sf.picard.reference.ReferenceSequenceFile; import net.sf.picard.reference.ReferenceSequence; import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.*; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.gatk.io.StingSAMFileWriter; @@ -41,6 +42,7 @@ import java.util.*; import java.util.regex.Pattern; import java.util.regex.Matcher; import java.io.File; +import java.io.PrintStream; import net.sf.samtools.util.StringUtil; @@ -50,6 +52,9 @@ import net.sf.samtools.util.StringUtil; */ @Requires({DataSource.READS}) public class ClipReadsWalker extends ReadWalker { + @Output + PrintStream out; + /** * an optional argument to dump the reads out to a BAM file */ diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/FlagStatWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/FlagStatWalker.java index 1a6ffd09d..13a55eaac 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/FlagStatWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/FlagStatWalker.java @@ -3,9 +3,11 @@ package org.broadinstitute.sting.gatk.walkers; import net.sf.samtools.SAMRecord; import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; +import org.broadinstitute.sting.commandline.Output; import java.text.DecimalFormat; import java.text.NumberFormat; +import java.io.PrintStream; /* @@ -41,6 +43,9 @@ import java.text.NumberFormat; */ @Requires({DataSource.READS}) public class FlagStatWalker extends ReadWalker { + @Output + PrintStream out; + // what comes out of the flagstat static class FlagStat { long readCount = 0L; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/Multiplex.java b/java/src/org/broadinstitute/sting/gatk/walkers/Multiplex.java new file mode 100644 index 000000000..3af974dbd --- /dev/null +++ b/java/src/org/broadinstitute/sting/gatk/walkers/Multiplex.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2010, The Broad Institute + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +package org.broadinstitute.sting.gatk.walkers; + +import java.lang.annotation.*; + +/** + * Indicates that the class should be multiplexed according to the rules + * specified in the multiplexer. + * + * @author mhanna + * @version 0.1 + */ +@Documented +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD}) +public @interface Multiplex { + public Class value(); + public String[] arguments() default {}; +} diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/Multiplexer.java b/java/src/org/broadinstitute/sting/gatk/walkers/Multiplexer.java new file mode 100644 index 000000000..357803b20 --- /dev/null +++ b/java/src/org/broadinstitute/sting/gatk/walkers/Multiplexer.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, The Broad Institute + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +package org.broadinstitute.sting.gatk.walkers; + +import java.util.Collection; + +/** + * An interface for multiplexing output streams. + * + * @author mhanna + * @version 0.1 + */ +public interface Multiplexer { + /** + * Generate a list of the potential outputs that can be created as a function of the other + * command-line arguments in this class. + * @return A collection of unique identifiers for the file multiplex. + */ + public Collection multiplex(); + + /** + * Transform the given command-line argument into a suitable form specific to this filename. + * @param multiplexedEntry Identifies the individual component of the multiplex. Will be a value in the collection + * passed back by multiplex(). + * @param argument The actual command-line argument, supplied for transformation. + * @return A transformed representation of the command-line argument. + */ + public String transformArgument(final T multiplexedEntry, final String argument); +} diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/PileupWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/PileupWalker.java index 48103c0ea..69d7243c8 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/PileupWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/PileupWalker.java @@ -35,11 +35,13 @@ import org.broadinstitute.sting.gatk.refdata.utils.helpers.DbSNPHelper; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.pileup.ReadBackedExtendedEventPileup; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; import java.util.ArrayList; import java.util.List; +import java.io.PrintStream; /** * Prints the alignment in the pileup format. In the pileup format, each line represents a genomic position, @@ -60,6 +62,9 @@ import java.util.List; * samtools pileup [-f in.ref.fasta] [-t in.ref_list] [-l in.site_list] [-iscg] [-T theta] [-N nHap] [-r pairDiffRate] */ public class PileupWalker extends LocusWalker implements TreeReducible { + @Output + PrintStream out; + @Argument(fullName="alwaysShowSecondBase",doc="If true, prints dummy bases for the second bases in the BAM file where they are missing",required=false) public boolean alwaysShowSecondBase = false; @@ -160,4 +165,11 @@ public class PileupWalker extends LocusWalker implements TreeR return rodString; } + + @Override + public void onTraversalDone(Integer result) { + // Double check traversal result to make count is the same. + // TODO: Is this check necessary? + out.println("[REDUCE RESULT] Traversal result is: " + result); + } } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/PrintRODsWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/PrintRODsWalker.java index 031734ec4..9ac3fc0e6 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/PrintRODsWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/PrintRODsWalker.java @@ -30,14 +30,18 @@ import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.refdata.VariantContextAdaptors; import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature; +import org.broadinstitute.sting.commandline.Output; import java.util.Iterator; +import java.io.PrintStream; /** * Prints out all of the RODs in the input data set. Data is rendered using the toString() method * of the given ROD. */ public class PrintRODsWalker extends RodWalker { + @Output + PrintStream out; /** * Initialize the number of loci processed to zero. diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java index 192a10369..2b1d3abe9 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java @@ -33,6 +33,8 @@ import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.Output; +import java.io.PrintStream; + /** * Renders, in SAM/BAM format, all reads from the input data set in the order in which they appear * in the input file. It can dynamically merge the contents of multiple input BAM files, resulting @@ -41,10 +43,9 @@ import org.broadinstitute.sting.commandline.Output; */ @Requires({DataSource.READS, DataSource.REFERENCE}) public class PrintReadsWalker extends ReadWalker { - /** an optional argument to dump the reads out to a BAM file */ - @Output(fullName = "outputBamFile", shortName = "of", doc = "Write output to this BAM filename instead of STDOUT", required = false) - SAMFileWriter outputBamFile = null; + @Output(doc="Write output to this BAM filename instead of STDOUT",required=false) + SAMFileWriter out; @Argument(fullName = "readGroup", shortName = "readGroup", doc="Discard reads not belonging to the specified read group", required = false) String readGroup = null; @Argument(fullName = "platform", shortName = "platform", doc="Discard reads not generated by the specified platform", required = false) @@ -103,7 +104,7 @@ public class PrintReadsWalker extends ReadWalker { * @return SAMFileWriter, set to the BAM output file if the command line option was set, null otherwise */ public SAMFileWriter reduceInit() { - return outputBamFile; + return out; } /** @@ -113,12 +114,7 @@ public class PrintReadsWalker extends ReadWalker { * @return the SAMFileWriter, so that the next reduce can emit to the same source */ public SAMFileWriter reduce( SAMRecord read, SAMFileWriter output ) { - if (output != null) { - output.addAlignment(read); - } else { - out.println(read.format()); - } - + out.addAlignment(read); return output; } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/VariantsToVCF.java b/java/src/org/broadinstitute/sting/gatk/walkers/VariantsToVCF.java index 0f0fd018e..40b7b421d 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/VariantsToVCF.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/VariantsToVCF.java @@ -35,6 +35,7 @@ import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.variantcontext.VariantContextUtils; import org.broadinstitute.sting.gatk.refdata.*; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.refdata.utils.helpers.DbSNPHelper; import org.broadinstitute.sting.utils.vcf.VCFUtils; import org.broadinstitute.sting.utils.genotype.vcf.*; @@ -42,6 +43,7 @@ import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.SampleUtils; import java.util.*; +import java.io.PrintStream; /** * Converts variants from other file formats to VCF format. @@ -49,6 +51,8 @@ import java.util.*; @Requires(value={},referenceMetaData=@RMD(name=VariantsToVCF.INPUT_ROD_NAME,type= ReferenceOrderedDatum.class)) @Reference(window=@Window(start=0,stop=40)) public class VariantsToVCF extends RodWalker { + @Output + private PrintStream out; public static final String INPUT_ROD_NAME = "variant"; @@ -126,7 +130,7 @@ public class VariantsToVCF extends RodWalker { } } - vcfwriter = new VCFWriterImpl(out); + vcfwriter = new StandardVCFWriter(out); vcfwriter.writeHeader(new VCFHeader(hInfo, samples)); } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/Walker.java b/java/src/org/broadinstitute/sting/gatk/walkers/Walker.java index 546eb16a8..64ede866d 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/Walker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/Walker.java @@ -25,16 +25,13 @@ package org.broadinstitute.sting.gatk.walkers; -import java.io.PrintStream; import java.util.List; -import java.util.ArrayList; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; import org.broadinstitute.sting.gatk.filters.MalformedReadFilter; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.collections.Pair; import org.apache.log4j.Logger; -import net.sf.picard.filter.SamRecordFilter; /** * Created by IntelliJ IDEA. @@ -47,16 +44,6 @@ import net.sf.picard.filter.SamRecordFilter; public abstract class Walker { final protected static Logger logger = Logger.getLogger(Walker.class); - /** - * 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() { } @@ -134,7 +121,7 @@ public abstract class Walker { public abstract ReduceType reduce(MapType value, ReduceType sum); public void onTraversalDone(ReduceType result) { - out.println("[REDUCE RESULT] Traversal result is: " + result); + logger.info("[REDUCE RESULT] Traversal result is: " + result); } /** @@ -143,7 +130,7 @@ public abstract class Walker { */ public void onTraversalDone(List> results) { for ( Pair result : results ) { - out.printf("[INTERVAL REDUCE RESULT] at %s ", result.getFirst()); + logger.info(String.format("[INTERVAL REDUCE RESULT] at %s ", result.getFirst())); this.onTraversalDone(result.getSecond()); } } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java index 2250ffc05..aa4c7ecdf 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java @@ -44,11 +44,13 @@ import org.broadinstitute.sting.utils.classloader.PackageUtils; import org.broadinstitute.sting.utils.SampleUtils; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.CommandLineUtils; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.vcf.VCFUtils; import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; -import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; +import org.broadinstitute.sting.utils.genotype.vcf.StandardVCFWriter; import java.util.*; +import java.io.PrintStream; /** @@ -59,6 +61,8 @@ import java.util.*; @Reference(window=@Window(start=-50,stop=50)) @By(DataSource.REFERENCE) public class VariantAnnotator extends RodWalker { + @Output + protected PrintStream out; @Argument(fullName="sampleName", shortName="sample", doc="The sample (NA-ID) corresponding to the variant input (for non-VCF input only)", required=false) protected String sampleName = null; @@ -154,7 +158,7 @@ public class VariantAnnotator extends RodWalker { hInfo.add(new VCFHeaderLine("VariantAnnotator", "\"" + CommandLineUtils.createApproximateCommandLineArgumentString(getToolkit(), args, getClass()) + "\"")); } - vcfWriter = new VCFWriterImpl(out); + vcfWriter = new StandardVCFWriter(out); VCFHeader vcfHeader = new VCFHeader(hInfo, samples); vcfWriter.writeHeader(vcfHeader); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CallableLociWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CallableLociWalker.java index 651cdd381..da8706e62 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CallableLociWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CallableLociWalker.java @@ -31,6 +31,7 @@ import org.broadinstitute.sting.gatk.walkers.LocusWalker; import org.broadinstitute.sting.utils.*; import org.broadinstitute.sting.utils.pileup.PileupElement; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.EnumMap; import java.util.Map; @@ -47,6 +48,9 @@ import java.io.FileNotFoundException; */ @By(DataSource.REFERENCE) public class CallableLociWalker extends LocusWalker { + @Output + PrintStream out; + @Argument(fullName = "maxLowMAPQ", shortName = "mlmq", doc = "Maximum value for MAPQ to be considered a problematic mapped read. The gap between this value and mmq are reads that are not sufficiently well mapped for calling but aren't indicative of mapping problems.", required = false) byte maxLowMAPQ = 1; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoarseCoverageWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoarseCoverageWalker.java index ece400d5a..9620ce72e 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoarseCoverageWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoarseCoverageWalker.java @@ -31,6 +31,9 @@ import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.ReadWalker; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; + +import java.io.PrintStream; /** * Computes the coverage per every bases on the reference, or on the subset of the reference @@ -38,6 +41,8 @@ import org.broadinstitute.sting.commandline.Argument; * count anew, even if the count of bases in the last chunk on the previous contig did not reach specified . */ public class CoarseCoverageWalker extends ReadWalker { + @Output + public PrintStream out; @Argument(fullName="granularity", shortName="G", doc="Granularity", required=true) public Integer N; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CompareCallableLociWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CompareCallableLociWalker.java index 194e96803..57c675a83 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CompareCallableLociWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CompareCallableLociWalker.java @@ -30,14 +30,19 @@ import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.GenomeLocParser; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broad.tribble.bed.FullBEDFeature; import java.util.*; +import java.io.PrintStream; /** * Test routine for new VariantContext object */ public class CompareCallableLociWalker extends RodWalker, long[][]> { + @Output + protected PrintStream out; + @Argument(shortName="comp1", doc="First comparison track name", required=false) protected String COMP1 = "comp1"; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoverageUtils.java b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoverageUtils.java index 7a2251078..0705af8af 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoverageUtils.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoverageUtils.java @@ -7,10 +7,7 @@ import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.pileup.PileupElement; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * IF THERE IS NO JAVADOC RIGHT HERE, YELL AT chartl @@ -41,24 +38,24 @@ public class CoverageUtils { return counts; } - public static String getTypeID( SAMReadGroupRecord r, CoverageAggregator.AggregationType type ) { - if ( type == CoverageAggregator.AggregationType.SAMPLE ) { + public static String getTypeID( SAMReadGroupRecord r, DoCOutputType.Partition type ) { + if ( type == DoCOutputType.Partition.sample ) { return r.getSample(); - } else if ( type == CoverageAggregator.AggregationType.READGROUP ) { + } else if ( type == DoCOutputType.Partition.readgroup ) { return String.format("%s_rg_%s",r.getSample(),r.getReadGroupId()); - } else if ( type == CoverageAggregator.AggregationType.LIBRARY ) { + } else if ( type == DoCOutputType.Partition.library ) { return r.getLibrary(); } else { throw new StingException("Invalid type ID sent to getTypeID. This is a BUG!"); } } - public static Map> - getBaseCountsByPartition(AlignmentContext context, int minMapQ, int maxMapQ, byte minBaseQ, byte maxBaseQ, List types) { + public static Map> + getBaseCountsByPartition(AlignmentContext context, int minMapQ, int maxMapQ, byte minBaseQ, byte maxBaseQ, Collection types) { - Map> countsByIDByType = new HashMap>(); + Map> countsByIDByType = new HashMap>(); Map countsByRG = getBaseCountsByReadGroup(context,minMapQ,maxMapQ,minBaseQ,maxBaseQ); - for (CoverageAggregator.AggregationType t : types ) { + for (DoCOutputType.Partition t : types ) { // iterate through the read group counts and build the type associations for ( Map.Entry readGroupCountEntry : countsByRG.entrySet() ) { String typeID = getTypeID(readGroupCountEntry.getKey(),t); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DepthOfCoverageWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DepthOfCoverageWalker.java index e2f711b87..6846bafe4 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DepthOfCoverageWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DepthOfCoverageWalker.java @@ -30,21 +30,18 @@ import org.broad.tribble.FeatureSource; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; -import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedData; import org.broadinstitute.sting.gatk.refdata.SeekableRODIterator; import org.broadinstitute.sting.gatk.refdata.features.refseq.RefSeqCodec; import org.broadinstitute.sting.gatk.refdata.features.refseq.RefSeqFeature; import org.broadinstitute.sting.gatk.refdata.tracks.builders.TribbleRMDTrackBuilder; import org.broadinstitute.sting.gatk.refdata.utils.*; -import org.broadinstitute.sting.gatk.walkers.By; -import org.broadinstitute.sting.gatk.walkers.DataSource; -import org.broadinstitute.sting.gatk.walkers.LocusWalker; -import org.broadinstitute.sting.gatk.walkers.TreeReducible; +import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.io.File; import java.io.IOException; @@ -67,7 +64,11 @@ import java.util.*; // todo -- allow for user to set linear binning (default is logarithmic) // todo -- formatting --> do something special for end bins in getQuantile(int[] foo), this gets mushed into the end+-1 bins for now @By(DataSource.REFERENCE) -public class DepthOfCoverageWalker extends LocusWalker>, CoverageAggregator> implements TreeReducible { +public class DepthOfCoverageWalker extends LocusWalker>, CoveragePartitioner> implements TreeReducible { + @Output + @Multiplex(value=DoCOutputMultiplexer.class,arguments={"partitionTypes","refSeqGeneList","omitDepthOutput","omitIntervals","omitSampleSummary","omitLocusTable"}) + Map out; + @Argument(fullName = "start", doc = "Starting (left endpoint) for granular binning", required = false) int start = 1; @Argument(fullName = "stop", doc = "Ending (right endpoint) for granular binning", required = false) @@ -95,7 +96,7 @@ public class DepthOfCoverageWalker extends LocusWalker partitionTypes = EnumSet.of(DoCOutputType.Partition.sample); @Argument(fullName = "includeDeletions", shortName = "dels", doc = "Include information on deletions", required = false) boolean includeDeletions = false; @Argument(fullName = "ignoreDeletionSites", doc = "Ignore sites consisting only of deletions", required = false) @@ -108,10 +109,8 @@ public class DepthOfCoverageWalker extends LocusWalker aggregationTypes = new ArrayList(); - Map> orderCheck = new HashMap>(); + Map> orderCheck = new HashMap>(); //////////////////////////////////////////////////////////////////////////////////// // STANDARD WALKER METHODS @@ -145,33 +144,17 @@ public class DepthOfCoverageWalker extends LocusWalker allSamples = getSamplesFromToolKit(aggregationTypes); + HashSet allSamples = getSamplesFromToolKit(partitionTypes); for ( String s : allSamples) { out.printf("\t%s_%s","Depth_for",s); @@ -183,10 +166,10 @@ public class DepthOfCoverageWalker extends LocusWalker()); for ( String id : getSamplesFromToolKit(type) ) { orderCheck.get(type).add(id); @@ -195,28 +178,28 @@ public class DepthOfCoverageWalker extends LocusWalker getSamplesFromToolKit( List types ) { + private HashSet getSamplesFromToolKit( Collection types ) { HashSet partitions = new HashSet(); // since the DOCS object uses a HashMap, this will be in the same order - for (CoverageAggregator.AggregationType t : types ) { + for (DoCOutputType.Partition t : types ) { partitions.addAll(getSamplesFromToolKit(t)); } return partitions; } - private HashSet getSamplesFromToolKit(CoverageAggregator.AggregationType type) { + private HashSet getSamplesFromToolKit(DoCOutputType.Partition type) { HashSet partition = new HashSet(); - if ( type == CoverageAggregator.AggregationType.SAMPLE ) { + if ( type == DoCOutputType.Partition.sample ) { for ( Set sampleSet : getToolkit().getSamplesByReaders() ) { for ( String s : sampleSet ) { partition.add(s); } } - } else if ( type == CoverageAggregator.AggregationType.READGROUP ) { + } else if ( type == DoCOutputType.Partition.readgroup ) { for ( SAMReadGroupRecord rg : getToolkit().getSAMFileHeader().getReadGroups() ) { partition.add(rg.getSample()+"_rg_"+rg.getReadGroupId()); } - } else if ( type == CoverageAggregator.AggregationType.LIBRARY ) { + } else if ( type == DoCOutputType.Partition.library ) { for ( Set libraries : getToolkit().getLibrariesByReaders() ) { for ( String l : libraries ) { partition.add(l); @@ -233,9 +216,9 @@ public class DepthOfCoverageWalker extends LocusWalker> map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { + public Map> map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { if ( ! omitDepthOutput ) { - out.printf("%s",ref.getLocus()); // yes: print locus in map, and the rest of the info in reduce (for eventual cumulatives) + getCorrectStream(null, DoCOutputType.Aggregation.locus, DoCOutputType.FileType.summary).printf("%s",ref.getLocus()); // yes: print locus in map, and the rest of the info in reduce (for eventual cumulatives) //System.out.printf("\t[log]\t%s",ref.getLocus()); } - return CoverageUtils.getBaseCountsByPartition(context,minMappingQuality,maxMappingQuality,minBaseQuality,maxBaseQuality,aggregationTypes); + return CoverageUtils.getBaseCountsByPartition(context,minMappingQuality,maxMappingQuality,minBaseQuality,maxBaseQuality,partitionTypes); } - public CoverageAggregator reduce(Map> thisMap, CoverageAggregator prevReduce) { + public CoveragePartitioner reduce(Map> thisMap, CoveragePartitioner prevReduce) { if ( ! omitDepthOutput ) { - printDepths(out,thisMap, prevReduce.getIdentifiersByType()); + printDepths(getCorrectStream(null, DoCOutputType.Aggregation.locus, DoCOutputType.FileType.summary),thisMap,prevReduce.getIdentifiersByType()); // this is an additional iteration through thisMap, plus dealing with IO, so should be much slower without // turning on omit } @@ -265,7 +248,7 @@ public class DepthOfCoverageWalker extends LocusWalker> statsByInterval ) { - if ( refSeqGeneList != null && aggregationTypes.contains(CoverageAggregator.AggregationType.SAMPLE ) ) { + public void onTraversalDone( List> statsByInterval ) { + if ( refSeqGeneList != null && partitionTypes.contains(DoCOutputType.Partition.sample) ) { printGeneStats(statsByInterval); } - if ( aggregationTypes.contains(CoverageAggregator.AggregationType.SAMPLE) ) { - File intervalStatisticsFile = deriveFromStream("sample_interval_statistics"); - File intervalSummaryFile = deriveFromStream("sample_interval_summary"); - printIntervalStats(statsByInterval,intervalSummaryFile, intervalStatisticsFile, CoverageAggregator.AggregationType.SAMPLE ); - } - - if ( aggregationTypes.contains(CoverageAggregator.AggregationType.READGROUP ) ) { - File intervalStatisticsFile = deriveFromStream("read_group_interval_statistics"); - File intervalSummaryFile = deriveFromStream("read_group_interval_summary"); - printIntervalStats(statsByInterval,intervalSummaryFile, intervalStatisticsFile, CoverageAggregator.AggregationType.READGROUP); - } - - if ( aggregationTypes.contains(CoverageAggregator.AggregationType.LIBRARY) ) { - File intervalStatisticsFile = deriveFromStream("library_interval_statistics"); - File intervalSummaryFile = deriveFromStream("library_interval_summary"); - printIntervalStats(statsByInterval,intervalSummaryFile,intervalStatisticsFile,CoverageAggregator.AggregationType.LIBRARY); + for(DoCOutputType.Partition partition: partitionTypes) { + printIntervalStats(statsByInterval, + getCorrectStream(partition, DoCOutputType.Aggregation.interval, DoCOutputType.FileType.summary), + getCorrectStream(partition, DoCOutputType.Aggregation.interval, DoCOutputType.FileType.statistics), + partition); } onTraversalDone(mergeAll(statsByInterval)); } - public CoverageAggregator mergeAll(List> stats) { - CoverageAggregator first = stats.remove(0).second; - for ( Pair iStat : stats ) { + public CoveragePartitioner mergeAll(List> stats) { + CoveragePartitioner first = stats.remove(0).second; + for ( Pair iStat : stats ) { treeReduce(first,iStat.second); } return first; } - private DepthOfCoverageStats printIntervalStats(List> statsByInterval, File summaryFile, File statsFile, CoverageAggregator.AggregationType type) { - PrintStream summaryOut; - PrintStream statsOut; - - try { - summaryOut = summaryFile == null ? out : new PrintStream(summaryFile); - statsOut = statsFile == null ? out : new PrintStream(statsFile); - } catch ( IOException e ) { - throw new StingException("Unable to open interval file on reduce", e); - } - - Pair firstPair = statsByInterval.get(0); - CoverageAggregator firstAggregator = firstPair.second; + private DepthOfCoverageStats printIntervalStats(List> statsByInterval, PrintStream summaryOut, PrintStream statsOut, DoCOutputType.Partition type) { + Pair firstPair = statsByInterval.get(0); + CoveragePartitioner firstAggregator = firstPair.second; DepthOfCoverageStats firstStats = firstAggregator.getCoverageByAggregationType(type); StringBuilder summaryHeader = new StringBuilder(); @@ -360,7 +322,7 @@ public class DepthOfCoverageWalker extends LocusWalker targetAggregator : statsByInterval ) { + for ( Pair targetAggregator : statsByInterval ) { Pair targetStats = new Pair( targetAggregator.first, targetAggregator.second.getCoverageByAggregationType(type)); @@ -370,39 +332,29 @@ public class DepthOfCoverageWalker extends LocusWalker> statsByTarget) { + private void printGeneStats(List> statsByTarget) { LocationAwareSeekableRODIterator refseqIterator = initializeRefSeq(); List> statsByGene = new ArrayList>();// maintains order Map geneNamesToStats = new HashMap(); // allows indirect updating of objects in list - for ( Pair targetStats : statsByTarget ) { + for ( Pair targetStats : statsByTarget ) { String gene = getGeneName(targetStats.first,refseqIterator); if ( geneNamesToStats.keySet().contains(gene) ) { - geneNamesToStats.get(gene).merge(targetStats.second.getCoverageByAggregationType(CoverageAggregator.AggregationType.SAMPLE)); + geneNamesToStats.get(gene).merge(targetStats.second.getCoverageByAggregationType(DoCOutputType.Partition.sample)); } else { - geneNamesToStats.put(gene,new DepthOfCoverageStats(targetStats.second.getCoverageByAggregationType(CoverageAggregator.AggregationType.SAMPLE))); - statsByGene.add(new Pair(gene,new DepthOfCoverageStats(targetStats.second.getCoverageByAggregationType(CoverageAggregator.AggregationType.SAMPLE)))); + geneNamesToStats.put(gene,new DepthOfCoverageStats(targetStats.second.getCoverageByAggregationType(DoCOutputType.Partition.sample))); + statsByGene.add(new Pair(gene,new DepthOfCoverageStats(targetStats.second.getCoverageByAggregationType(DoCOutputType.Partition.sample)))); } } - PrintStream geneSummaryOut = getCorrectStream(out,deriveFromStream("gene_summary")); + PrintStream geneSummaryOut = getCorrectStream(DoCOutputType.Partition.sample, DoCOutputType.Aggregation.gene, DoCOutputType.FileType.summary); for ( Pair geneStats : statsByGene ) { printTargetSummary(geneSummaryOut,geneStats); } - - if ( ! getToolkit().getArguments().outFileName.contains("stdout")) { - geneSummaryOut.close(); - } - } //blatantly stolen from Andrew Kernytsky @@ -530,66 +482,42 @@ public class DepthOfCoverageWalker extends LocusWalker> countsBySampleByType, Map> identifiersByType) { + private void printDepths(PrintStream stream, Map> countsBySampleByType, Map> identifiersByType) { // get the depths per sample and build up the output string while tabulating total and average coverage StringBuilder perSampleOutput = new StringBuilder(); int tDepth = 0; boolean depthCounted = false; - for (CoverageAggregator.AggregationType type : aggregationTypes ) { + for (DoCOutputType.Partition type : partitionTypes ) { Map countsByID = countsBySampleByType.get(type); for ( String s : identifiersByType.get(type) ) { perSampleOutput.append(separator); @@ -783,7 +697,7 @@ public class DepthOfCoverageWalker extends LocusWalker order = orderCheck.get(t); List namesInAg = ag.getIdentifiersByType().get(t); @@ -834,38 +748,105 @@ public class DepthOfCoverageWalker extends LocusWalker { + private final Set partitions; + private final File refSeqGeneList; + private final boolean omitDepthOutput; + private final boolean omitIntervals; + private final boolean omitSampleSummary; + private final boolean omitLocusTable; - enum AggregationType { READGROUP, SAMPLE, LIBRARY } + /** + * Create a new multiplexer type using the values of all variable fields. + * @param partitions + * @param refSeqGeneList + * @param omitDepthOutput + * @param omitIntervals + * @param omitSampleSummary + * @param omitLocusTable + */ + public DoCOutputMultiplexer(final Set partitions, + final File refSeqGeneList, + final boolean omitDepthOutput, + final boolean omitIntervals, + final boolean omitSampleSummary, + final boolean omitLocusTable) { + this.partitions = partitions; + this.refSeqGeneList = refSeqGeneList; + this.omitDepthOutput = omitDepthOutput; + this.omitIntervals = omitIntervals; + this.omitSampleSummary = omitSampleSummary; + this.omitLocusTable = omitLocusTable; + } - private List types; - private Map coverageProfiles; - private Map> identifiersByType; + public Collection multiplex() { + List outputs = new ArrayList(); + if(!omitDepthOutput) outputs.add(new DoCOutputType(null, DoCOutputType.Aggregation.locus, DoCOutputType.FileType.summary)); + + if(!omitIntervals) { + for(DoCOutputType.Partition partition: partitions) { + outputs.add(new DoCOutputType(partition, DoCOutputType.Aggregation.interval, DoCOutputType.FileType.summary)); + outputs.add(new DoCOutputType(partition, DoCOutputType.Aggregation.interval, DoCOutputType.FileType.statistics)); + } + } + + if(refSeqGeneList != null && partitions.contains(DoCOutputType.Partition.sample)) { + DoCOutputType geneSummaryOut = new DoCOutputType(DoCOutputType.Partition.sample, DoCOutputType.Aggregation.gene, DoCOutputType.FileType.summary); + outputs.add(geneSummaryOut); + } + + if(!omitSampleSummary) { + for(DoCOutputType.Partition partition: partitions) { + outputs.add(new DoCOutputType(partition, DoCOutputType.Aggregation.cumulative, DoCOutputType.FileType.summary)); + outputs.add(new DoCOutputType(partition, DoCOutputType.Aggregation.cumulative, DoCOutputType.FileType.statistics)); + } + } + + if(!omitLocusTable) { + for(DoCOutputType.Partition partition: partitions) { + outputs.add(new DoCOutputType(partition, DoCOutputType.Aggregation.cumulative, DoCOutputType.FileType.coverage_counts)); + outputs.add(new DoCOutputType(partition, DoCOutputType.Aggregation.cumulative, DoCOutputType.FileType.coverage_proportions)); + } + } + + return outputs; + } + + public String transformArgument(final DoCOutputType outputType, final String argument) { + return outputType.getFileName(argument); + } +} + +class CoveragePartitioner { + private Collection types; + private Map coverageProfiles; + private Map> identifiersByType; private Set allIdentifiers; - public CoverageAggregator(List typesToUse, int start, int stop, int nBins) { - coverageProfiles = new HashMap(); - identifiersByType = new HashMap>(); + public CoveragePartitioner(Collection typesToUse, int start, int stop, int nBins) { + coverageProfiles = new HashMap(); + identifiersByType = new HashMap>(); types = typesToUse; - for ( AggregationType type : types ) { + for ( DoCOutputType.Partition type : types ) { coverageProfiles.put(type,new DepthOfCoverageStats(DepthOfCoverageStats.calculateBinEndpoints(start,stop,nBins))); identifiersByType.put(type,new ArrayList()); } allIdentifiers = new HashSet(); } - public void merge(CoverageAggregator otherAggregator) { - for ( AggregationType type : types ) { + public void merge(CoveragePartitioner otherAggregator) { + for ( DoCOutputType.Partition type : types ) { this.coverageProfiles.get(type).merge(otherAggregator.coverageProfiles.get(type)); } } - public DepthOfCoverageStats getCoverageByAggregationType(AggregationType t) { + public DepthOfCoverageStats getCoverageByAggregationType(DoCOutputType.Partition t) { return coverageProfiles.get(t); } - public void addIdentifiers(AggregationType t, Set ids) { + public void addIdentifiers(DoCOutputType.Partition t, Set ids) { for ( String s : ids ) { coverageProfiles.get(t).addSample(s); identifiersByType.get(t).add(s); @@ -875,7 +856,7 @@ class CoverageAggregator { } public void initialize(boolean useDels, boolean omitLocusTable) { - for ( AggregationType t : types ) { + for ( DoCOutputType.Partition t : types ) { if ( useDels ) { coverageProfiles.get(t).initializeDeletions(); } @@ -885,8 +866,8 @@ class CoverageAggregator { } } - public void update(Map> countsByIdentifierByType) { - for ( AggregationType t : types ) { + public void update(Map> countsByIdentifierByType) { + for ( DoCOutputType.Partition t : types ) { coverageProfiles.get(t).update(countsByIdentifierByType.get(t)); } } @@ -895,23 +876,7 @@ class CoverageAggregator { return allIdentifiers; } - public Map> getIdentifiersByType() { + public Map> getIdentifiersByType() { return identifiersByType; } - - public static AggregationType typeStringToAggregationType(String type) { - if ( type.equals("sample") ) { - return AggregationType.SAMPLE; - } - - if ( type.equals("library") ) { - return AggregationType.LIBRARY; - } - - if ( type.equals("readgroup") ) { - return AggregationType.READGROUP; - } - - throw new StingException("Valid partition type string "+type+" is not associated with an aggregation type. This is a BUG!"); - } } \ No newline at end of file diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DoCOutputType.java b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DoCOutputType.java new file mode 100644 index 000000000..a1c637aea --- /dev/null +++ b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DoCOutputType.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2010, The Broad Institute + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +package org.broadinstitute.sting.gatk.walkers.coverage; + +/** + * Models a single output file in the DoC walker. + * + * @author mhanna + * @version 0.1 + */ +public class DoCOutputType { + public enum Partition { readgroup, sample, library } + public enum Aggregation { locus, interval, gene, cumulative } + public enum FileType { summary, statistics, coverage_counts, coverage_proportions } + + private final Partition partition; + private final Aggregation aggregation; + private final FileType fileType; + + public DoCOutputType(final Partition partition, + final Aggregation aggregation, + final FileType fileType) { + this.partition = partition; + this.aggregation = aggregation; + this.fileType = fileType; + } + + public String getFileName(final String baseName) { + // main output + if(partition == null) + return baseName; + + // mhanna 22 Aug 2010 - Deliberately force this header replacement to make sure integration tests pass. + // TODO: Update integration tests and get rid of this. + String partitionType = (partition == DoCOutputType.Partition.readgroup ? "read_group" : partition.toString()); + + if(fileType == FileType.coverage_counts || fileType == FileType.coverage_proportions) { + // coverage counts / proportions files always include aggregation. + return baseName + "." + + partitionType + "_" + + aggregation + "_" + + fileType; + } + + return baseName + "." + + partitionType + "_" + + (aggregation == Aggregation.interval || aggregation == Aggregation.gene ? aggregation + "_" : "") + + fileType; + } + + public int hashCode() { + return (partition!=null?partition.ordinal()+1:0) * aggregation.ordinal() * fileType.ordinal(); + } + + public boolean equals(Object other) { + if(!(other instanceof DoCOutputType)) + return false; + DoCOutputType otherOutputType = (DoCOutputType)other; + return partition == otherOutputType.partition && + aggregation == otherOutputType.aggregation && + fileType == otherOutputType.fileType; + } +} diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/fasta/BamToFastqWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/fasta/BamToFastqWalker.java index 5ddfb9dfc..b15906a4a 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/fasta/BamToFastqWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/fasta/BamToFastqWalker.java @@ -32,6 +32,7 @@ import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import net.sf.samtools.SAMRecord; import java.io.*; @@ -42,6 +43,8 @@ import java.io.*; */ @WalkerName("BamToFastq") public class BamToFastqWalker extends ReadWalker { + @Output + private PrintStream out; @Argument(fullName="re_reverse", shortName="reverse", doc="re-reverse bases and quals of reads from the negative strand", required=false) private Boolean RE_REVERSE = false; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/fasta/FastaReferenceWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/fasta/FastaReferenceWalker.java index ad0a0e4b2..9c5a316d0 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/fasta/FastaReferenceWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/fasta/FastaReferenceWalker.java @@ -34,6 +34,9 @@ import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; + +import java.io.PrintStream; /** * Renders a new reference in FASTA format consisting of only those loci provided in the input data set. Has optional @@ -41,6 +44,7 @@ import org.broadinstitute.sting.commandline.Argument; */ @WalkerName("FastaReferenceMaker") public class FastaReferenceWalker extends RefWalker, GenomeLoc> { + @Output PrintStream out; @Argument(fullName="lineWidth", shortName="lw", doc="Maximum length of sequence to write per line", required=false) public int fastaLineWidth=60; @Argument(fullName="rawOnelineSeq", shortName="raw", doc="Print sequences with no FASTA header lines, one line per interval (i.e. lineWidth = infinity) - CAUTION: adjacent intervals will automatically be merged", required=false) public boolean fastaRawSeqs=false; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java index 75426edfd..ea8e4380a 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java @@ -38,11 +38,13 @@ import org.broadinstitute.sting.gatk.refdata.VariantContextAdaptors; import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.CommandLineUtils; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.vcf.VCFUtils; import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; -import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; +import org.broadinstitute.sting.utils.genotype.vcf.StandardVCFWriter; import java.util.*; +import java.io.PrintStream; /** @@ -51,6 +53,8 @@ import java.util.*; @Requires(value={},referenceMetaData=@RMD(name="variant", type=ReferenceOrderedDatum.class)) @Reference(window=@Window(start=-50,stop=50)) public class VariantFiltrationWalker extends RodWalker { + @Output + protected PrintStream out; @Argument(fullName="filterExpression", shortName="filter", doc="One or more expression used with INFO fields to filter (see wiki docs for more info)", required=false) protected ArrayList FILTER_EXPS = new ArrayList(); @@ -119,7 +123,7 @@ public class VariantFiltrationWalker extends RodWalker { hInfo.add(new VCFHeaderLine("VariantFiltration", "\"" + CommandLineUtils.createApproximateCommandLineArgumentString(getToolkit(), args, getClass()) + "\"")); } - writer = new VCFWriterImpl(out); + writer = new StandardVCFWriter(out); writer.writeHeader(new VCFHeader(hInfo, new TreeSet(vc.getSampleNames()))); } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/CreateTriggerTrack.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/CreateTriggerTrack.java index 66313a029..e836b071c 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/CreateTriggerTrack.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/CreateTriggerTrack.java @@ -29,6 +29,7 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; +import org.broadinstitute.sting.commandline.Output; import java.util.Collection; import java.io.PrintWriter; @@ -37,13 +38,9 @@ import java.io.PrintWriter; * Creates a bed-format trigger-track for the Unified Genotyper based on input variant files. */ public class CreateTriggerTrack extends RodWalker { - + @Output private PrintWriter writer; - public void initialize() { - writer = new PrintWriter(out); - } - public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { if ( tracker == null ) return 0; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java index 7c9e74939..245ff22c7 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java @@ -38,6 +38,8 @@ import org.broadinstitute.sting.utils.genotype.vcf.*; import java.util.*; import java.io.PrintStream; +import java.io.File; +import java.io.FileNotFoundException; /** @@ -54,10 +56,10 @@ public class UnifiedGenotyper extends LocusWalker annotationsToUse = new ArrayList(); @@ -81,6 +83,9 @@ public class UnifiedGenotyper extends LocusWalker { + @Output + PrintStream out; + @Argument(fullName="outputFile", shortName="O", doc="output file name (defaults to BED format)", required=true) java.io.File bed_file; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelRealigner.java b/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelRealigner.java index a317afced..4428c03ab 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelRealigner.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelRealigner.java @@ -46,6 +46,7 @@ import org.broadinstitute.sting.utils.collections.Pair; import java.io.File; import java.io.FileWriter; +import java.io.PrintStream; import java.util.*; /** @@ -69,6 +70,12 @@ public class IndelRealigner extends ReadWalker { @Argument(fullName="entropyThreshold", shortName="entropy", doc="percentage of mismatches at a locus to be considered having high entropy", required=false) protected double MISMATCH_THRESHOLD = 0.15; + @Output + protected PrintStream out; + + @Output(fullName = "err", shortName = "e", doc = "An error output file presented to the walker. Will overwrite contents if file exists.", required = false) + protected PrintStream err; + @Output(fullName="output", shortName="O", required=false, doc="Output bam") protected String writerFilename = null; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java b/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java index 24a368eed..a333b570d 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java @@ -37,12 +37,14 @@ import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.pileup.ExtendedEventPileupElement; import org.broadinstitute.sting.utils.pileup.PileupElement; import org.broadinstitute.sting.utils.pileup.ReadBackedExtendedEventPileup; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; import java.util.ArrayList; +import java.io.PrintStream; /** * Emits intervals for the Local Indel Realigner to target for cleaning. Ignores 454 and MQ0 reads. @@ -52,6 +54,8 @@ import java.util.ArrayList; @Allows(value={DataSource.READS, DataSource.REFERENCE}) @By(DataSource.REFERENCE) public class RealignerTargetCreator extends RodWalker { + @Output + protected PrintStream out; // mismatch/entropy/SNP arguments @Argument(fullName="windowSize", shortName="window", doc="window size for calculating entropy or SNP clusters", required=false) diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/qc/CountRodByRefWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/qc/CountRodByRefWalker.java index 27a85d78c..a4e80138f 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/qc/CountRodByRefWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/qc/CountRodByRefWalker.java @@ -29,7 +29,6 @@ import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.RefWalker; -import org.broadinstitute.sting.utils.classloader.JVMUtils; import org.broadinstitute.sting.utils.collections.ExpandingArrayList; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.commandline.Argument; @@ -50,8 +49,6 @@ public class CountRodByRefWalker extends RefWalker, Long>> implements TreeReducible, Long>> { + @Output + public PrintStream out; + @Argument(fullName = "verbose", shortName = "v", doc="If true, Countrod will print out detailed information about the rods it finds and locations", required = false) public boolean verbose = false; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/qc/CycleQualityWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/qc/CycleQualityWalker.java index 46b7dd770..b513b3dae 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/qc/CycleQualityWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/qc/CycleQualityWalker.java @@ -34,14 +34,12 @@ import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.collections.PrimitivePair; import org.broadinstitute.sting.utils.sam.AlignmentUtils; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import net.sf.samtools.SAMRecord; import net.sf.samtools.SAMReadGroupRecord; import java.util.*; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.BufferedWriter; +import java.io.*; /** * Created by IntelliJ IDEA. @@ -58,6 +56,9 @@ import java.io.BufferedWriter; */ @Requires({DataSource.READS}) public class CycleQualityWalker extends ReadWalker { + @Output + protected PrintStream out; + @Argument(fullName="mappedOnly", shortName="mo", doc="when this flag is set (default), statistics will be collected "+ "on mapped reads only, while unmapped reads will be discarded", required=false) protected boolean MAPPED_ONLY = true; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/qc/PrintLocusContextWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/qc/PrintLocusContextWalker.java index aa3abb0e5..f26f40a6a 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/qc/PrintLocusContextWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/qc/PrintLocusContextWalker.java @@ -4,9 +4,11 @@ import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.*; +import org.broadinstitute.sting.commandline.Output; import java.util.List; import java.util.Arrays; +import java.io.PrintStream; import net.sf.samtools.SAMRecord; @@ -15,6 +17,9 @@ import net.sf.samtools.SAMRecord; * all aligning reads in a compact but human-readable form. */ public class PrintLocusContextWalker extends LocusWalker implements TreeReducible { + @Output + private PrintStream out; + public AlignmentContext map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { out.printf( "In map: ref = %s, loc = %s, reads = %s%n", ref.getBaseAsChar(), context.getLocation(), diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/qc/ReadClippingStatsWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/qc/ReadClippingStatsWalker.java index fa10fca6b..a50129f24 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/qc/ReadClippingStatsWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/qc/ReadClippingStatsWalker.java @@ -32,13 +32,11 @@ import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.utils.MathUtils; import org.broadinstitute.sting.utils.sam.AlignmentUtils; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import net.sf.samtools.*; import java.util.*; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.BufferedWriter; +import java.io.*; /** * User: depristo @@ -52,6 +50,9 @@ import java.io.BufferedWriter; */ @Requires({DataSource.READS}) public class ReadClippingStatsWalker extends ReadWalker { + @Output + protected PrintStream out; + @Argument(fullName="mappedOnly", shortName="mo", doc="when this flag is set (default), statistics will be collected "+ "on mapped reads only, while unmapped reads will be discarded", required=false) protected boolean MAPPED_ONLY = true; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/qc/ValidatingPileupWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/qc/ValidatingPileupWalker.java index 95d72dae5..53685879f 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/qc/ValidatingPileupWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/qc/ValidatingPileupWalker.java @@ -35,9 +35,11 @@ import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; import java.util.Arrays; +import java.io.PrintStream; /** * At every locus in the input set, compares the pileup data (reference base, aligned base from @@ -46,6 +48,9 @@ import java.util.Arrays; */ @Requires(value={DataSource.READS,DataSource.REFERENCE},referenceMetaData=@RMD(name="pileup",type=SAMPileupFeature.class)) public class ValidatingPileupWalker extends LocusWalker implements TreeReducible { + @Output + private PrintStream out; + @Argument(fullName="continue_after_error",doc="Continue after an error",required=false) public boolean CONTINUE_AFTER_AN_ERROR = false; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/CovariateCounterWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/CovariateCounterWalker.java index 2d72fb439..88595cae6 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/CovariateCounterWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/CovariateCounterWalker.java @@ -83,6 +83,9 @@ public class CovariateCounterWalker extends LocusWalker { + @Output + PrintStream out; public void initialize() {} diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/sequenom/PickSequenomProbes.java b/java/src/org/broadinstitute/sting/gatk/walkers/sequenom/PickSequenomProbes.java index 28ac7123e..a1acd1ce4 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/sequenom/PickSequenomProbes.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/sequenom/PickSequenomProbes.java @@ -43,10 +43,12 @@ import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.Arrays; import java.util.Iterator; import java.util.Collection; +import java.io.PrintStream; /** @@ -57,6 +59,9 @@ import java.util.Collection; @Requires(value={DataSource.REFERENCE}) @Reference(window=@Window(start=-200,stop=200)) public class PickSequenomProbes extends RodWalker { + @Output + PrintStream out; + @Argument(required=false, shortName="snp_mask", doc="positions to be masked with N's") protected String SNP_MASK = null; @Argument(required=false, shortName="project_id",doc="If specified, all probenames will be prepended with 'project_id|'") diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/sequenom/SequenomValidationConverter.java b/java/src/org/broadinstitute/sting/gatk/walkers/sequenom/SequenomValidationConverter.java index a704573db..3adf0656b 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/sequenom/SequenomValidationConverter.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/sequenom/SequenomValidationConverter.java @@ -39,10 +39,12 @@ import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.utils.QualityUtils; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; -import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; +import org.broadinstitute.sting.utils.genotype.vcf.StandardVCFWriter; import java.util.*; +import java.io.PrintStream; /** * Converts Sequenom files to a VCF annotated with QC metrics (HW-equilibrium, % failed probes) @@ -50,6 +52,9 @@ import java.util.*; @Reference(window=@Window(start=0,stop=40)) @Requires(value={},referenceMetaData=@RMD(name="sequenom",type= ReferenceOrderedDatum.class)) public class SequenomValidationConverter extends RodWalker,Integer> { + @Output + protected PrintStream out; + @Argument(fullName="maxHardy", doc="Maximum phred-scaled Hardy-Weinberg violation pvalue to consider an assay valid [default:20]", required=false) protected double maxHardy = 20.0; @Argument(fullName="maxNoCall", doc="Maximum no-call rate (as a fraction) to consider an assay valid [default:0.05]", required=false) @@ -119,7 +124,7 @@ public class SequenomValidationConverter extends RodWalker(); - VCFWriter vcfWriter = new VCFWriterImpl(out); + VCFWriter vcfWriter = new StandardVCFWriter(out); // set up the info and filter headers Set hInfo = new HashSet(); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/VariantEvalWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/VariantEvalWalker.java index 1d2c33ccb..201c1111c 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/VariantEvalWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/VariantEvalWalker.java @@ -47,8 +47,9 @@ import org.broadinstitute.sting.utils.classloader.PackageUtils; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; -import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; +import org.broadinstitute.sting.utils.genotype.vcf.StandardVCFWriter; import org.broadinstitute.sting.utils.text.XReadLines; import java.io.File; @@ -110,6 +111,9 @@ import java.util.*; */ @Reference(window=@Window(start=-50,stop=50)) public class VariantEvalWalker extends RodWalker { + @Output + protected PrintStream out; + // -------------------------------------------------------------------------------------------------------------- // // walker arguments @@ -341,7 +345,7 @@ public class VariantEvalWalker extends RodWalker { determineContextNamePartSizes(); if ( outputVCF != null ) - writer = new VCFWriterImpl(new File(outputVCF)); + writer = new StandardVCFWriter(new File(outputVCF)); if ( rsIDFile != null ) { if ( maxRsIDBuild == Integer.MAX_VALUE ) diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/ApplyVariantCuts.java b/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/ApplyVariantCuts.java index 684f6d115..a74da7adf 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/ApplyVariantCuts.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/ApplyVariantCuts.java @@ -37,7 +37,7 @@ import org.broadinstitute.sting.utils.collections.ExpandingArrayList; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.utils.vcf.VCFUtils; import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; -import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; +import org.broadinstitute.sting.utils.genotype.vcf.StandardVCFWriter; import org.broadinstitute.sting.utils.text.XReadLines; import java.io.File; @@ -157,7 +157,7 @@ public class ApplyVariantCuts extends RodWalker { hInfo.addAll(VCFUtils.getHeaderFields(getToolkit())); hInfo.add(new VCFInfoHeaderLine("OQ", 1, VCFHeaderLineType.Float, "The original variant quality score")); hInfo.add(new VCFHeaderLine("source", "VariantOptimizer")); - vcfWriter = new VCFWriterImpl( new File(OUTPUT_FILENAME) ); + vcfWriter = new StandardVCFWriter( new File(OUTPUT_FILENAME) ); final TreeSet samples = new TreeSet(); samples.addAll(SampleUtils.getSampleListWithVCFHeader(getToolkit(), null)); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantRecalibrator.java b/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantRecalibrator.java index eb71a6e82..4d4f86c12 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantRecalibrator.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantRecalibrator.java @@ -41,7 +41,7 @@ import org.broadinstitute.sting.utils.collections.ExpandingArrayList; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.utils.vcf.VCFUtils; import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; -import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; +import org.broadinstitute.sting.utils.genotype.vcf.StandardVCFWriter; import java.io.File; import java.io.IOException; @@ -138,7 +138,7 @@ public class VariantRecalibrator extends RodWalker { + @Output + private PrintStream out; + // the types of combinations we currently allow @Argument(shortName="genotypeMergeOptions", doc="How should we merge genotype records for samples shared across the ROD files?", required=false) public VariantContextUtils.GenotypeMergeType genotypeMergeOption = VariantContextUtils.GenotypeMergeType.PRIORITIZE; @@ -81,7 +86,7 @@ public class CombineVariants extends RodWalker { private VariantAnnotatorEngine engine; public void initialize() { - vcfWriter = new VCFWriterImpl(out); + vcfWriter = new StandardVCFWriter(out); validateAnnotateUnionArguments(); Map vcfRods = VCFUtils.getVCFHeadersFromRods(getToolkit(), null); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/FilterLiftedVariants.java b/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/FilterLiftedVariants.java index 459c59913..18ba9e9b9 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/FilterLiftedVariants.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/FilterLiftedVariants.java @@ -26,7 +26,7 @@ package org.broadinstitute.sting.gatk.walkers.variantutils; import org.broad.tribble.util.variantcontext.VariantContext; import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; -import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; +import org.broadinstitute.sting.utils.genotype.vcf.StandardVCFWriter; import org.broadinstitute.sting.utils.vcf.VCFUtils; import org.broadinstitute.sting.utils.SampleUtils; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; @@ -34,15 +34,19 @@ import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedDatum; import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; +import org.broadinstitute.sting.commandline.Output; import org.broad.tribble.vcf.VCFHeader; import java.util.*; +import java.io.PrintStream; /** * Filters a lifted-over VCF file for ref bases that have been changed. */ @Requires(value={},referenceMetaData=@RMD(name="variant",type= ReferenceOrderedDatum.class)) public class FilterLiftedVariants extends RodWalker { + @Output + PrintStream out; private VCFWriter writer; @@ -52,7 +56,7 @@ public class FilterLiftedVariants extends RodWalker { Set samples = SampleUtils.getSampleListWithVCFHeader(getToolkit(), Arrays.asList("variant")); Map vcfHeaders = VCFUtils.getVCFHeadersFromRods(getToolkit(), Arrays.asList("variant")); - writer = new VCFWriterImpl(out); + writer = new StandardVCFWriter(out); final VCFHeader vcfHeader = new VCFHeader(vcfHeaders.containsKey("variant") ? vcfHeaders.get("variant").getMetaData() : null, samples); writer.writeHeader(vcfHeader); } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LiftoverVariants.java b/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LiftoverVariants.java index 3e0d1d67a..1b03e2640 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LiftoverVariants.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LiftoverVariants.java @@ -26,9 +26,10 @@ package org.broadinstitute.sting.gatk.walkers.variantutils; import org.broad.tribble.util.variantcontext.VariantContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.vcf.VCFUtils; import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; -import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; +import org.broadinstitute.sting.utils.genotype.vcf.StandardVCFWriter; import org.broadinstitute.sting.utils.GenomeLocParser; import org.broadinstitute.sting.utils.SampleUtils; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; @@ -40,6 +41,7 @@ import org.broadinstitute.sting.gatk.contexts.variantcontext.VariantContextUtils import org.broad.tribble.vcf.VCFHeader; import java.io.File; +import java.io.PrintStream; import java.util.*; import net.sf.picard.liftover.LiftOver; @@ -52,6 +54,8 @@ import net.sf.samtools.SAMFileReader; */ @Requires(value={},referenceMetaData=@RMD(name="variant", type=ReferenceOrderedDatum.class)) public class LiftoverVariants extends RodWalker { + @Output + protected PrintStream out; @Argument(fullName="chain", shortName="chain", doc="Chain file", required=true) protected File CHAIN = null; @@ -75,7 +79,7 @@ public class LiftoverVariants extends RodWalker { Set samples = SampleUtils.getSampleListWithVCFHeader(getToolkit(), Arrays.asList("variant")); Map vcfHeaders = VCFUtils.getVCFHeadersFromRods(getToolkit(), Arrays.asList("variant")); - writer = new VCFWriterImpl(out); + writer = new StandardVCFWriter(out); final VCFHeader vcfHeader = new VCFHeader(vcfHeaders.containsKey("variant") ? vcfHeaders.get("variant").getMetaData() : null, samples); writer.writeHeader(vcfHeader); } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/SelectVariants.java b/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/SelectVariants.java index 42875ad2d..1684858ce 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/SelectVariants.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/SelectVariants.java @@ -28,9 +28,8 @@ import org.broad.tribble.util.variantcontext.Genotype; import org.broad.tribble.util.variantcontext.VariantContext; import org.broad.tribble.vcf.VCFHeader; import org.broad.tribble.vcf.VCFHeaderLine; -import org.broad.tribble.vcf.VCFHeaderLineType; -import org.broad.tribble.vcf.VCFInfoHeaderLine; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.variantcontext.VariantContextUtils; @@ -40,15 +39,15 @@ import org.broadinstitute.sting.gatk.walkers.RMD; import org.broadinstitute.sting.gatk.walkers.Requires; import org.broadinstitute.sting.gatk.walkers.RodWalker; import org.broadinstitute.sting.utils.SampleUtils; -import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.text.XReadLines; import org.broadinstitute.sting.utils.vcf.VCFUtils; import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; -import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; +import org.broadinstitute.sting.utils.genotype.vcf.StandardVCFWriter; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.io.PrintStream; import java.io.File; import java.io.FileNotFoundException; @@ -58,6 +57,9 @@ import java.io.FileNotFoundException; */ @Requires(value={},referenceMetaData=@RMD(name="variant", type=ReferenceOrderedDatum.class)) public class SelectVariants extends RodWalker { + @Output + private PrintStream out; + @Argument(fullName="sample", shortName="sn", doc="Sample(s) to include. Can be a single sample, specified multiple times for many samples, a file containing sample names, a regular expression to select many samples, or any combination thereof.", required=false) public Set SAMPLE_EXPRESSIONS; @@ -83,7 +85,7 @@ public class SelectVariants extends RodWalker { * Set up the VCF writer, the sample expressions and regexs, and the JEXL matcher */ public void initialize() { - vcfWriter = new VCFWriterImpl(out); + vcfWriter = new StandardVCFWriter(out); ArrayList rodNames = new ArrayList(); rodNames.add("variant"); diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/AlignedReadsHistoWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/AlignedReadsHistoWalker.java index d9aabf4c7..0d4d5ab62 100755 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/AlignedReadsHistoWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/AlignedReadsHistoWalker.java @@ -5,6 +5,9 @@ import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.ReadWalker; import org.broadinstitute.sting.gatk.walkers.WalkerName; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; +import org.broadinstitute.sting.commandline.Output; + +import java.io.PrintStream; /** * Created by IntelliJ IDEA. @@ -15,6 +18,9 @@ import org.broadinstitute.sting.gatk.contexts.ReferenceContext; */ @WalkerName("Aligned_Reads_Histogram") public class AlignedReadsHistoWalker extends ReadWalker { + @Output + PrintStream out; + long[] alignCounts = new long[51]; public void initialize() { diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/AlleleBalanceHistogramWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/AlleleBalanceHistogramWalker.java index 017d44e68..ca68e6115 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/AlleleBalanceHistogramWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/AlleleBalanceHistogramWalker.java @@ -12,8 +12,10 @@ import org.broadinstitute.sting.gatk.walkers.RMD; import org.broadinstitute.sting.gatk.walkers.Requires; import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.pileup.PileupElement; +import org.broadinstitute.sting.commandline.Output; import java.util.*; +import java.io.PrintStream; /** * Created by IntelliJ IDEA. @@ -24,7 +26,8 @@ import java.util.*; */ @Requires(value= DataSource.REFERENCE,referenceMetaData = {@RMD(name="variants",type=ReferenceOrderedDatum.class)}) public class AlleleBalanceHistogramWalker extends LocusWalker, Map>> { - + @Output + PrintStream out; public Map> reduceInit() { return new HashMap>(); diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/BaseTransitionTableCalculatorJavaWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/BaseTransitionTableCalculatorJavaWalker.java index a6b58eebd..56abdce19 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/BaseTransitionTableCalculatorJavaWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/BaseTransitionTableCalculatorJavaWalker.java @@ -31,6 +31,7 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.*; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; @@ -50,6 +51,9 @@ import net.sf.samtools.SAMRecord; @By(DataSource.REFERENCE) @Reference(window=@Window(start=-3,stop=3)) public class BaseTransitionTableCalculatorJavaWalker extends LocusWalker,Set> implements TreeReducible> { + @Output + PrintStream out; + @Argument(fullName="usePreviousBases", doc="Use previous bases of the reference as part of the calculation, uses the specified number, defaults to 0", required=false) int nPreviousBases = 0; @Argument(fullName="useSecondaryBase",doc="Use the secondary base of a read as part of the calculation", required=false) diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/BeagleOutputByDepthWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/BeagleOutputByDepthWalker.java index f911a8652..d9e0c99ac 100755 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/BeagleOutputByDepthWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/BeagleOutputByDepthWalker.java @@ -30,6 +30,7 @@ import org.broad.tribble.util.variantcontext.Genotype; import org.broad.tribble.util.variantcontext.VariantContext; import org.broad.tribble.vcf.VCFConstants; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; @@ -55,6 +56,9 @@ public class BeagleOutputByDepthWalker extends RodWalker { private boolean newLine = true; + @Output + public PrintStream out; + @Argument(fullName = "output_file", shortName = "output", doc = "File to output results", required = true) public PrintStream outputWriter = null; diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/CountIntervals.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/CountIntervals.java index 44e2484fe..06db31622 100755 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/CountIntervals.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/CountIntervals.java @@ -1,6 +1,7 @@ package org.broadinstitute.sting.oneoffprojects.walkers; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; @@ -12,6 +13,7 @@ import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.collections.Pair; import java.util.List; +import java.io.PrintStream; /** * Counts the number of contiguous regions the walker traverses over. Slower than it needs to be, but @@ -19,6 +21,9 @@ import java.util.List; * This was its very first use. */ public class CountIntervals extends RefWalker { + @Output + PrintStream out; + @Argument(fullName="numOverlaps",shortName="no",doc="Count all occurrences of X or more overlapping intervals; defaults to 2", required=false) int numOverlaps = 2; diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/CreateTiTvTrack.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/CreateTiTvTrack.java index 8d9da0535..87b82c7c8 100755 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/CreateTiTvTrack.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/CreateTiTvTrack.java @@ -2,6 +2,7 @@ package org.broadinstitute.sting.oneoffprojects.walkers; import org.broad.tribble.util.variantcontext.VariantContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.variantcontext.VariantContextUtils; @@ -11,6 +12,7 @@ import org.broadinstitute.sting.utils.wiggle.WiggleHeader; import org.broadinstitute.sting.utils.wiggle.WiggleWriter; import java.util.ArrayList; +import java.io.PrintStream; /** * IF THERE IS NO JAVADOC RIGHT HERE, YELL AT chartl @@ -19,6 +21,9 @@ import java.util.ArrayList; * @Date Jul 21, 2010 */ public class CreateTiTvTrack extends RodWalker { + @Output + PrintStream out; + @Argument(shortName="size",doc="Size of the window",required = true) int size = -1; diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/DSBWalkerV3.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/DSBWalkerV3.java index 031a27291..2b165ce39 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/DSBWalkerV3.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/DSBWalkerV3.java @@ -29,11 +29,13 @@ import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.ReadWalker; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.*; import org.broadinstitute.sting.utils.sam.AlignmentUtils; import net.sf.samtools.SAMRecord; import java.util.*; +import java.io.PrintStream; /** * Created by IntelliJ IDEA. @@ -43,6 +45,8 @@ import java.util.*; * To change this template use File | Settings | File Templates. */ public class DSBWalkerV3 extends ReadWalker { + @Output + PrintStream out; @Argument(fullName="windowSize",shortName="W",doc="Size of the sliding window",required=true) int WINDOW_SIZE = 100; diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/DbSNPWindowCounter.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/DbSNPWindowCounter.java index 81b158a1e..0269ad09a 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/DbSNPWindowCounter.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/DbSNPWindowCounter.java @@ -7,6 +7,7 @@ import org.broad.tribble.dbsnp.DbSNPCodec; import org.broad.tribble.dbsnp.DbSNPFeature; import org.broad.tribble.iterators.CloseableTribbleIterator; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; @@ -20,6 +21,7 @@ import org.broadinstitute.sting.utils.StingException; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.PrintStream; /** * DbSNPWindowCounter @@ -36,6 +38,9 @@ public class DbSNPWindowCounter extends LocusWalker { // what we read in new tracks with private FeatureSource reader; + + @Output + private PrintStream out; @Argument(fullName = "dbSNPFile", shortName = "db", doc="The dbsnp file to search upstream and downstream for nearby snps", required = true) private File myDbSNPFile; diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/DesignFileGeneratorWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/DesignFileGeneratorWalker.java index 5a86e8e41..f7bab10c2 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/DesignFileGeneratorWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/DesignFileGeneratorWalker.java @@ -10,8 +10,10 @@ import org.broadinstitute.sting.gatk.walkers.RodWalker; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; import org.broadinstitute.sting.utils.StingException; +import org.broadinstitute.sting.commandline.Output; import java.util.*; +import java.io.PrintStream; /** * Takes an interval list and annotates intervals with genes and exons falling within that interval @@ -28,6 +30,9 @@ public class DesignFileGeneratorWalker extends RodWalker { private HashSet refseqBuffer = new HashSet(); private HashMap currentBedFeatures = new HashMap(); + @Output + PrintStream out; + public Long map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { // three items to look up: interval_list, refseq, gene* if ( tracker == null ) { diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ErrorRatePerReadPosition.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ErrorRatePerReadPosition.java index ac3e1c3c2..adf5173ce 100755 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ErrorRatePerReadPosition.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ErrorRatePerReadPosition.java @@ -6,10 +6,12 @@ import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.List; import java.util.HashMap; import java.util.HashSet; +import java.io.PrintStream; import net.sf.samtools.SAMRecord; import net.sf.samtools.SAMReadGroupRecord; @@ -18,6 +20,7 @@ import net.sf.samtools.SAMReadGroupRecord; * Computes the read error rate per position in read (in the original 5'->3' orientation that the read had coming off the machine) */ public class ErrorRatePerReadPosition extends LocusWalker { + @Output PrintStream out; @Argument(fullName="min_base_quality_score", shortName="mbq", doc="Minimum base quality required to consider a base for calling (default: 0)", required=false) public Integer MIN_BASE_QUAL = 0; @Argument(fullName="min_mapping_quality_score", shortName="mmq", doc="Minimum read mapping quality required to consider a read for calling (default: 0)", required=false) public Integer MIN_MAPPING_QUAL = 0; diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/GCCalculatorWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/GCCalculatorWalker.java index 1982a07e5..0d7b922f4 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/GCCalculatorWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/GCCalculatorWalker.java @@ -10,11 +10,13 @@ import org.broadinstitute.sting.gatk.walkers.RefWalker; import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.collections.Pair; +import org.broadinstitute.sting.commandline.Output; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.io.PrintStream; /** * IF THERE IS NO JAVADOC RIGHT HERE, YELL AT chartl @@ -23,6 +25,8 @@ import java.util.Set; * @Date May 19, 2010 */ public class GCCalculatorWalker extends RefWalker,Boolean>, Map>> { + @Output + PrintStream out; public Map> reduceInit() { return new HashMap>(); diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelAnnotator.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelAnnotator.java index 73851101c..cd2352af5 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelAnnotator.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelAnnotator.java @@ -4,6 +4,7 @@ import org.broad.tribble.FeatureSource; import org.broad.tribble.util.variantcontext.VariantContext; import org.broad.tribble.vcf.*; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.variantcontext.VariantContextUtils; @@ -21,6 +22,7 @@ import org.broadinstitute.sting.utils.genotype.vcf.*; import java.io.File; import java.io.IOException; +import java.io.PrintStream; import java.util.*; /** @@ -30,6 +32,8 @@ import java.util.*; * @Date Apr 21, 2010 */ public class IndelAnnotator extends RodWalker{ + @Output + PrintStream out; @Argument(fullName="refseq", shortName="refseq", doc="Name of RefSeq transcript annotation file. If specified, indels will be annotated with GENOMIC/UTR/INTRON/CODING and with the gene name", required=true) String RefseqFileName = null; @@ -85,7 +89,7 @@ public class IndelAnnotator extends RodWalker{ anno.add(new VCFInfoHeaderLine("type",1, VCFHeaderLineType.String,"Genomic interpretation (according to RefSeq)")); hInfo.addAll(anno); - vcfWriter = new VCFWriterImpl(out); + vcfWriter = new StandardVCFWriter(out); VCFHeader vcfHeader = new VCFHeader(hInfo, SampleUtils.getUniqueSamplesFromRods(getToolkit())); vcfWriter.writeHeader(vcfHeader); } diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelDBRateWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelDBRateWalker.java index c0feefda0..321b67460 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelDBRateWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelDBRateWalker.java @@ -4,6 +4,7 @@ import org.broad.tribble.util.variantcontext.VariantContext; import org.broad.tribble.vcf.VCFHeader; import org.broad.tribble.vcf.VCFHeaderLine; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.variantcontext.VariantContextUtils; @@ -17,7 +18,7 @@ import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.collections.ExpandingArrayList; import org.broadinstitute.sting.utils.vcf.VCFUtils; import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; -import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; +import org.broadinstitute.sting.utils.genotype.vcf.StandardVCFWriter; import java.io.PrintStream; import java.util.*; @@ -30,7 +31,8 @@ import java.util.*; */ @Reference(window=@Window(start=-40,stop=40)) public class IndelDBRateWalker extends RodWalker { - + @Output + PrintStream out; @Argument(fullName="indelWindow",doc="size of the window in which to look for indels; max 40",required=false) int indelWindow = 10; @Argument(fullName="writeVCF",doc="Writes \"overlapping\" variants to this vcf",required=false) @@ -47,7 +49,7 @@ public class IndelDBRateWalker extends RodWalker } if ( outVCF != null ) { - vcfWriter = new VCFWriterImpl(outVCF); + vcfWriter = new StandardVCFWriter(outVCF); Set header = new HashSet(); header.addAll(VCFUtils.getHeaderFields(getToolkit())); VCFHeader vcfHeader = new VCFHeader(header, SampleUtils.getUniqueSamplesFromRods(getToolkit())); diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelErrorRateWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelErrorRateWalker.java index ffe6b983a..a3296c9ce 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelErrorRateWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelErrorRateWalker.java @@ -38,10 +38,12 @@ import org.broadinstitute.sting.utils.pileup.ExtendedEventPileupElement; import org.broadinstitute.sting.utils.pileup.ReadBackedExtendedEventPileup; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.List; import java.util.LinkedList; import java.util.Iterator; +import java.io.PrintStream; /** * Created by IntelliJ IDEA. @@ -52,6 +54,8 @@ import java.util.Iterator; */ @Reference(window=@Window(start=-10,stop=10)) public class IndelErrorRateWalker extends LocusWalker { + @Output + PrintStream out; @Argument(fullName="minCoverage",shortName="minC",doc="Assess only sites with coverage at or above the specified value.",required=true) int MIN_COVERAGE = 0; @Argument(fullName="maxCoverage",shortName="maxC",doc="Assess only sites with coverage at or below the specified value.",required=false) diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/MendelianViolationClassifier.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/MendelianViolationClassifier.java index 7b56ab99f..b32d0d316 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/MendelianViolationClassifier.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/MendelianViolationClassifier.java @@ -6,6 +6,7 @@ import org.broad.tribble.util.variantcontext.VariantContext; import org.broad.tribble.vcf.VCFHeader; import org.broad.tribble.vcf.VCFHeaderLine; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.StratifiedAlignmentContext; @@ -23,7 +24,7 @@ import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.vcf.VCFUtils; import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; -import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; +import org.broadinstitute.sting.utils.genotype.vcf.StandardVCFWriter; import org.broadinstitute.sting.utils.pileup.PileupElement; import java.io.PrintStream; @@ -39,6 +40,8 @@ import java.util.*; * @Date Jun 8, 2010 */ public class MendelianViolationClassifier extends LocusWalker { + @Output + PrintStream out; @Argument(shortName="f",fullName="familyPattern",required=true,doc="Pattern for the family structure (usage: mom+dad=child)") String familyStr = null; @Argument(shortName="ob",fullName="outputBed",required=true,doc="Output file to write the homozygous region information to") @@ -373,7 +376,7 @@ public class MendelianViolationClassifier extends LocusWalker hInfo = new HashSet(); hInfo.addAll(VCFUtils.getHeaderFields(getToolkit())); hInfo.add(new VCFHeaderLine("source", "MendelianViolationClassifier")); diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/MismatchCounterWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/MismatchCounterWalker.java index d9b182629..10b7d5d2a 100755 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/MismatchCounterWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/MismatchCounterWalker.java @@ -6,11 +6,16 @@ import org.broadinstitute.sting.gatk.walkers.ReadWalker; import org.broadinstitute.sting.gatk.walkers.WalkerName; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.utils.Utils; +import org.broadinstitute.sting.commandline.Output; import java.util.List; +import java.io.PrintStream; @WalkerName("CountMismatches") public class MismatchCounterWalker extends ReadWalker { + @Output + PrintStream out; + public Integer map(ReferenceContext ref, SAMRecord read, ReadMetaDataTracker metaDataTracker) { int nMismatches = 0; diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/MismatchHistoWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/MismatchHistoWalker.java index db5d41e50..2c99315ca 100755 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/MismatchHistoWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/MismatchHistoWalker.java @@ -6,12 +6,16 @@ import org.broadinstitute.sting.gatk.walkers.ReadWalker; import org.broadinstitute.sting.gatk.walkers.WalkerName; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.utils.Utils; +import org.broadinstitute.sting.commandline.Output; import java.util.List; import static java.lang.reflect.Array.*; +import java.io.PrintStream; @WalkerName("Mismatch_Histogram") -public class MismatchHistoWalker extends ReadWalker { +public class MismatchHistoWalker extends ReadWalker { + @Output + PrintStream out; protected long[] mismatchCounts = new long[0]; protected final int MIN_TARGET_EDIT_DISTANCE = 5; diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/NeighborhoodQualityWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/NeighborhoodQualityWalker.java index d5737486b..884a71598 100755 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/NeighborhoodQualityWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/NeighborhoodQualityWalker.java @@ -4,10 +4,12 @@ import org.broadinstitute.sting.gatk.walkers.LocusWalker; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; +import org.broadinstitute.sting.commandline.Output; import net.sf.samtools.SAMRecord; import java.util.List; import java.util.Iterator; +import java.io.PrintStream; /* * Copyright (c) 2009 The Broad Institute @@ -71,6 +73,8 @@ import java.util.Iterator; */ public class NeighborhoodQualityWalker extends LocusWalker { + @Output + PrintStream out; public Integer map( RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context ) { float neighborhoodQualityScore = 0.0f; diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/PairedQualityScoreCountsWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/PairedQualityScoreCountsWalker.java index 7ddc2993e..cc41b42c1 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/PairedQualityScoreCountsWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/PairedQualityScoreCountsWalker.java @@ -33,8 +33,11 @@ import org.broadinstitute.sting.utils.QualityUtils; import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import net.sf.samtools.SAMRecord; +import java.io.PrintStream; + /** * This walker prints out quality score counts for first and second reads of a pair aggregated over all reads * in the interval. @@ -42,6 +45,9 @@ import net.sf.samtools.SAMRecord; * @Author: Chris Hartl */ public class PairedQualityScoreCountsWalker extends ReadWalker,Pair> { + @Output + public PrintStream out; + @Argument(fullName="readLength", shortName="rl", doc="Length of reads in the bam file", required=true) public int readLength = -1; diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ReadErrorRateWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ReadErrorRateWalker.java index a159f821d..550a3f74d 100755 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ReadErrorRateWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ReadErrorRateWalker.java @@ -29,6 +29,7 @@ import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.ReadWalker; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.walkers.TreeReducible; import org.broadinstitute.sting.utils.QualityUtils; import org.broadinstitute.sting.utils.BaseUtils; @@ -37,6 +38,7 @@ import net.sf.samtools.SAMRecord; import java.util.HashMap; import java.util.Map; import java.util.Random; +import java.io.PrintStream; /** * ReadErrorRateWalker assesses the error rate per read position ('cycle') by comparing the @@ -48,6 +50,7 @@ import java.util.Random; * @author Kiran Garimella */ public class ReadErrorRateWalker extends ReadWalker implements TreeReducible { + @Output PrintStream out; @Argument(fullName="printVisualHits", shortName="v", doc="print visual hits", required=false) public boolean printVisualHits = false; @Argument(fullName="useNextBestBase", shortName="nb", doc="use next best base", required=false) public boolean useNextBestBase = false; @Argument(fullName="useNonNextBestBase",shortName="nnb",doc="use nonnext best base",required=false) public boolean useNonNextBestBase = false; diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ReadQualityScoreWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ReadQualityScoreWalker.java index 4933b80c6..001cba3e3 100755 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ReadQualityScoreWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ReadQualityScoreWalker.java @@ -29,16 +29,14 @@ import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.ReadWalker; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; import org.broadinstitute.sting.utils.StingException; import net.sf.samtools.SAMRecord; import net.sf.samtools.SAMFileWriter; -import java.io.FileReader; -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.IOException; +import java.io.*; /** * Created by IntelliJ IDEA. @@ -61,6 +59,8 @@ import java.io.IOException; */ public class ReadQualityScoreWalker extends ReadWalker { + @Output + protected PrintStream out; @Argument(fullName = "inputQualityFile", shortName = "if", doc = "Input quality score file generated by NeighborhoodQualityWalker", required = true) protected String inputQualityFile = null; @Argument(fullName = "outputBamFile", shortName = "of", doc = "Write output to this BAM filename instead of STDOUT", required = false) diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ReplaceQuals.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ReplaceQuals.java index 63119025f..d8f37c01d 100755 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ReplaceQuals.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ReplaceQuals.java @@ -29,11 +29,13 @@ import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.ReadWalker; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.collections.Pair; import net.sf.samtools.*; import java.util.HashMap; import java.io.File; +import java.io.PrintStream; /** * ReadErrorRateWalker assesses the error rate per read position ('cycle') by comparing the @@ -45,6 +47,9 @@ import java.io.File; * @author Kiran Garimella */ public class ReplaceQuals extends ReadWalker { + @Output + public PrintStream out; + @Argument(shortName="inputQualsBAM",doc="BAM files containing qualities to be replaced",required=true) public String inputQualsBAM; diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/TestReadFishingWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/TestReadFishingWalker.java index b32d7e61e..e4ea1e9f6 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/TestReadFishingWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/TestReadFishingWalker.java @@ -33,6 +33,7 @@ import org.broadinstitute.sting.alignment.bwa.BWAConfiguration; import org.broadinstitute.sting.alignment.bwa.c.BWACAligner; import org.broadinstitute.sting.alignment.Alignment; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; @@ -44,6 +45,7 @@ import net.sf.picard.reference.IndexedFastaSequenceFile; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.PrintStream; import java.util.Scanner; import java.util.TreeMap; import java.util.SortedMap; @@ -60,6 +62,9 @@ public class TestReadFishingWalker extends ReadWalker { */ private BWAAligner aligner; + @Output + private PrintStream out; + @Argument(fullName="indel_calls",shortName="ic",doc="Indel calls to use to derive custom references",required=true) private File indelCalls; diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/TestVariantContextWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/TestVariantContextWalker.java index 9dccc1ebd..780ae6be9 100755 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/TestVariantContextWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/TestVariantContextWalker.java @@ -32,14 +32,19 @@ import org.broadinstitute.sting.gatk.refdata.*; import org.broadinstitute.sting.gatk.walkers.RodWalker; import org.broadinstitute.sting.utils.genotype.vcf.*; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.EnumSet; import java.io.File; +import java.io.PrintStream; /** * Test routine for new VariantContext object */ public class TestVariantContextWalker extends RodWalker { + @Output + PrintStream out; + @Argument(fullName="takeFirstOnly", doc="Only take the first second at a locus, as opposed to all", required=false) boolean takeFirstOnly = false; @@ -60,7 +65,7 @@ public class TestVariantContextWalker extends RodWalker { public void initialize() { if ( outputVCF != null ) - writer = new VCFWriterImpl(new File(outputVCF)); + writer = new StandardVCFWriter(new File(outputVCF)); } public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { @@ -100,4 +105,11 @@ public class TestVariantContextWalker extends RodWalker { public Integer reduce(Integer point, Integer sum) { return point + sum; } + + @Override + public void onTraversalDone(Integer result) { + // Double check traversal result to make count is the same. + // TODO: Is this check necessary? + out.println("[REDUCE RESULT] Traversal result is: " + result); + } } \ No newline at end of file diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/VCF4WriterTestWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/VCF4WriterTestWalker.java index 7611baccd..10d3e345c 100755 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/VCF4WriterTestWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/VCF4WriterTestWalker.java @@ -4,6 +4,7 @@ import org.broad.tribble.readers.AsciiLineReader; import org.broad.tribble.util.variantcontext.VariantContext; import org.broad.tribble.vcf.*; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.datasources.simpleDataSources.ReferenceOrderedDataSource; @@ -14,11 +15,12 @@ import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.vcf.VCFUtils; import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; -import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; +import org.broadinstitute.sting.utils.genotype.vcf.StandardVCFWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.PrintStream; import java.util.*; /* * Copyright (c) 2009 The Broad Institute @@ -53,6 +55,9 @@ import java.util.*; public class VCF4WriterTestWalker extends RodWalker { private VCFWriter vcfWriter; + @Output + private PrintStream out; + @Argument(fullName="output_file", shortName="output", doc="VCF file to which output should be written", required=true) private String OUTPUT_FILE = null; @@ -80,7 +85,7 @@ public class VCF4WriterTestWalker extends RodWalker { hInfo.addAll(VCFUtils.getHeaderFields(getToolkit())); - vcfWriter = new VCFWriterImpl(new File(OUTPUT_FILE)); + vcfWriter = new StandardVCFWriter(new File(OUTPUT_FILE)); VCFHeader header = null; for( final ReferenceOrderedDataSource source : dataSources ) { final RMDTrack rod = source.getReferenceOrderedData(); diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ValidateRODForReads.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ValidateRODForReads.java index e01272287..45768476d 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ValidateRODForReads.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/ValidateRODForReads.java @@ -7,11 +7,13 @@ import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature; import org.broadinstitute.sting.gatk.walkers.ReadWalker; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; +import org.broadinstitute.sting.commandline.Output; import java.util.Collection; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; +import java.io.PrintStream; /** * validate the rods for reads @@ -20,6 +22,9 @@ public class ValidateRODForReads extends ReadWalker { // a mapping of the position to the count of rods HashMap map = new LinkedHashMap(); + @Output + private PrintStream out; + @Override public Integer map(ReferenceContext ref, SAMRecord read, ReadMetaDataTracker tracker) { if (tracker != null) { diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/BeagleOutputToVCFWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/BeagleOutputToVCFWalker.java index 03bb4bab1..9056d917c 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/BeagleOutputToVCFWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/BeagleOutputToVCFWalker.java @@ -29,6 +29,7 @@ import org.broad.tribble.util.variantcontext.Allele; import org.broad.tribble.util.variantcontext.Genotype; import org.broad.tribble.util.variantcontext.VariantContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.variantcontext.*; @@ -44,7 +45,7 @@ import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.SampleUtils; import org.broadinstitute.sting.utils.vcf.VCFUtils; import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; -import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; +import org.broadinstitute.sting.utils.genotype.vcf.StandardVCFWriter; import org.broad.tribble.vcf.*; import java.io.*; @@ -65,6 +66,9 @@ public class BeagleOutputToVCFWalker extends RodWalker { public static final String PROBS_ROD_NAME = "beagleProbs"; public static final String PHASED_ROD_NAME = "beaglePhased"; + @Output + private PrintStream out; + @Argument(fullName="output_file", shortName="output", doc="VCF file to which output should be written", required=true) private String OUTPUT_FILE = null; @@ -93,7 +97,7 @@ public class BeagleOutputToVCFWalker extends RodWalker { hInfo.add(new VCFHeaderLine("source", "BeagleImputation")); // Open output file specified by output VCF ROD - vcfWriter = new VCFWriterImpl(new File(OUTPUT_FILE)); + vcfWriter = new StandardVCFWriter(new File(OUTPUT_FILE)); final List dataSources = this.getToolkit().getRodDataSources(); for( final ReferenceOrderedDataSource source : dataSources ) { diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CalculateAlleleLikelihoodsWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CalculateAlleleLikelihoodsWalker.java index 093460acf..d8e8bea94 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CalculateAlleleLikelihoodsWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CalculateAlleleLikelihoodsWalker.java @@ -30,12 +30,14 @@ import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.ArrayList; import java.util.Hashtable; import java.util.Enumeration; import java.util.Vector; import java.util.Collections; +import java.io.PrintStream; /** * Calculates likelihood of observing the data given pairs of HLA alleles. NOTE: run CalculateBaseLikelihoods first! Usage: java -jar GenomeAnalysisTK.jar -T CalculateAlleleLikelihoods -I /humgen/gsa-scr1/GSA/sjia/454_HLA/HLA/HLA.nuc.imputed.4digit.bam -R /broad/1KG/reference/human_b36_both.fasta -L /humgen/gsa-scr1/GSA/sjia/454_HLA/HAPMAP270/HLA_exons.interval -bl INPUT.baselikelihoods -eth\ @@ -44,6 +46,9 @@ nicity Caucasian | grep -v "INFO" | grep -v "DONE!" > OUTPUT.allelelikelihoods */ @Requires({DataSource.READS, DataSource.REFERENCE}) public class CalculateAlleleLikelihoodsWalker extends ReadWalker { + @Output + public PrintStream out; + @Argument(fullName = "baseLikelihoods", shortName = "bl", doc = "Base likelihoods file", required = true) public String baseLikelihoodsFile = ""; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CalculateBaseLikelihoodsWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CalculateBaseLikelihoodsWalker.java index dd82a8fd7..ec844d404 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CalculateBaseLikelihoodsWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CalculateBaseLikelihoodsWalker.java @@ -35,15 +35,21 @@ import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.genotype.DiploidGenotype; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; +import java.io.PrintStream; + /** * Calculates the probability of observing data for each genotype at every position. NOTE: run FindClosestAllele first to create .filter file. Usage: java -jar GenomeAnalysisTK.jar -T CalculateBaseLikelihoods -I INPUT.bam -R /broad/1KG/reference/human_b36_both.fasta -L /humgen/gsa-scr1/GSA/sjia/454_HLA/HAPMAP270/HLA_exons.interval [-filter INPUT.filter -minAllowedMismatches 7] | grep -v "INFO" | grep -v "MISALIGNED" > OUTPUT.baselikelihoods * @author shermanjia */ public class CalculateBaseLikelihoodsWalker extends LocusWalker>{ + @Output + public PrintStream out; + @Argument(fullName = "debugHLA", shortName = "debugHLA", doc = "Print debug", required = false) public boolean DEBUG = false; @Argument(fullName = "debugAlleles", shortName = "debugAlleles", doc = "Print likelihood scores for these alleles", required = false) diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CallHLAWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CallHLAWalker.java index cf2b0c33c..706aa0c4d 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CallHLAWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CallHLAWalker.java @@ -37,11 +37,9 @@ import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; import org.broadinstitute.sting.utils.genotype.DiploidGenotype; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; -import java.io.BufferedReader; -import java.io.DataInputStream; -import java.io.FileInputStream; -import java.io.InputStreamReader; +import java.io.*; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; @@ -51,6 +49,9 @@ import java.util.List; * @author shermanjia */ public class CallHLAWalker extends LocusWalker>{ + @Output + public PrintStream out; + @Argument(fullName="suppressLocusPrinting",doc="Suppress printing",required=false) public boolean suppressPrinting = false; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/ClusterReadsWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/ClusterReadsWalker.java index c979e42ff..d16d4d1d6 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/ClusterReadsWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/ClusterReadsWalker.java @@ -5,15 +5,21 @@ import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.ArrayList; import java.util.Hashtable; +import java.io.PrintStream; + /** * Compares reads to longest read at each exon. Usage: java -jar GenomeAnalysisTK.jar -T ClusterReads -I INPUT.bam -R /broad/1KG/reference/human_b36_both.fasta [-filter INPUT.filter] | grep -v INFO | sort -k1 > OUTPUT * @author shermanjia */ @Requires({DataSource.READS, DataSource.REFERENCE}) public class ClusterReadsWalker extends ReadWalker { + @Output + public PrintStream out; + @Argument(fullName = "filter", shortName = "filter", doc = "file containing reads to exclude", required = false) public String filterFile = ""; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CreateHaplotypesWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CreateHaplotypesWalker.java index 10fc948b2..0b63d3da9 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CreateHaplotypesWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CreateHaplotypesWalker.java @@ -4,14 +4,20 @@ import net.sf.samtools.SAMRecord; import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; +import org.broadinstitute.sting.commandline.Output; import java.util.Hashtable; +import java.io.PrintStream; + /** * Creates a haplotype file given reads (for SNP analysis, imputation, etc) * @author shermanjia */ @Requires({DataSource.READS, DataSource.REFERENCE}) public class CreateHaplotypesWalker extends ReadWalker { + @Output + PrintStream out; + CigarParser formatter = new CigarParser(); char c; boolean DEBUG = false; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CreatePedFileWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CreatePedFileWalker.java index bf2e56bf2..e1f28ece3 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CreatePedFileWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/CreatePedFileWalker.java @@ -30,10 +30,13 @@ import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.ArrayList; import java.util.Hashtable; import java.util.Enumeration; +import java.io.PrintStream; + /** * Creates a ped file of SNPs and amino acids coded as SNPs given an input ped file with 4-digit HLA alleles. Usage: java -jar GenomeAnalysisTK.jar -T CreatePedFile --allelesFile INPUT.ped -R /broad/1KG/reference/human_b36_both.fasta -I /humgen/gsa-sc\ r1/GSA/sjia/454_HLA/HLA/HLA.combined.4digitUnique.bam > OUTPUT.log @@ -41,6 +44,9 @@ r1/GSA/sjia/454_HLA/HLA/HLA.combined.4digitUnique.bam > OUTPUT.log */ @Requires({DataSource.READS, DataSource.REFERENCE}) public class CreatePedFileWalker extends ReadWalker { + @Output + public PrintStream out; + @Argument(fullName = "allelesFile", shortName = "allelesFile", doc = "Create ped file for HLA alleles named in this file", required = true) public String alleleNamesFile = ""; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/FindClosestHLAWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/FindClosestHLAWalker.java index 369778b80..df4169a3e 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/FindClosestHLAWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/FindClosestHLAWalker.java @@ -30,15 +30,21 @@ import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.ArrayList; import java.util.Hashtable; +import java.io.PrintStream; + /** * Finds the most similar HLA allele for each read (helps detect misalignments). Usage: java -jar GenomeAnalysisTK.jar -T FindClosestHLA -I INPUT.bam -R /broad/1KG/reference/human_b36_both.fasta -L INPUT.interval | grep -v INFO | sort -k1 > OUTPUT * @author shermanjia */ @Requires({DataSource.READS, DataSource.REFERENCE}) public class FindClosestHLAWalker extends ReadWalker { + @Output + protected PrintStream out; + @Argument(fullName = "debugRead", shortName = "debugRead", doc = "Print match score for read", required = false) public String debugRead = ""; @@ -300,5 +306,12 @@ public class FindClosestHLAWalker extends ReadWalker { public Integer reduce(Integer value, Integer sum) { return value + sum; } + + @Override + public void onTraversalDone(Integer result) { + // Double check traversal result to make count is the same. + // TODO: Is this check necessary? + out.println("[REDUCE RESULT] Traversal result is: " + result); + } } diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/FindPolymorphicSitesWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/FindPolymorphicSitesWalker.java index 668e62a9e..99d104ff6 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/FindPolymorphicSitesWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/FindPolymorphicSitesWalker.java @@ -5,15 +5,21 @@ import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.ArrayList; import java.util.Hashtable; +import java.io.PrintStream; + /** * Finds polymorphic sites in the HLA dictionary. Usage: java -jar GenomeAnalysisTK.jar -T FindPolymorphicSites -I HLA_DICTIONARY.bam -R /broad/1KG/reference/human_b36_both.fasta -L INPUT.interval -findFirst | grep -v INFO | sort -k1 > OUTPUT * @author shermanjia */ @Requires({DataSource.READS, DataSource.REFERENCE}) public class FindPolymorphicSitesWalker extends ReadWalker { + @Output + public PrintStream out; + @Argument(fullName = "debugRead", shortName = "debugRead", doc = "Print match score for read", required = false) public String debugRead = ""; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/HLACallerWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/HLACallerWalker.java index 16fbe9182..64c5b3d9d 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/HLACallerWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/HLACallerWalker.java @@ -31,9 +31,11 @@ import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.gatk.arguments.GATKArgumentCollection; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.*; import java.util.Map.Entry; +import java.io.PrintStream; /** * Calculates the likelihood of observing data given phase info from pairs of HLA alleles. Note: Run FindClosestAlleleWalker first! Usage: java -jar $GATK -T HLACaller -I INPUT.bam -R /broad/1KG/reference/human_b36_both.fasta -L /humgen/gsa-scr1/GSA/sjia/454_HLA/HAPMAP270/HLA_exons.interval -phaseInterval /humgen/gsa-scr1/GSA/sjia/454_HLA/HAPMAP270/HLA_exons.interval -bl IMPUT.baselikelihoods [-filter $ID.filter -minAllowe\ @@ -42,6 +44,9 @@ dMismatches 7] -ethnicity Caucasian | grep -v "INFO" | grep -v "DEBUG" | grep - */ @Requires({DataSource.READS, DataSource.REFERENCE}) public class HLACallerWalker extends ReadWalker { + @Output + private PrintStream out; + @Argument(fullName = "baseLikelihoods", shortName = "bl", doc = "Base likelihoods file", required = true) public String baseLikelihoodsFile = ""; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/ImputeAllelesWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/ImputeAllelesWalker.java index 9f2bbff87..393a3a0b9 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/ImputeAllelesWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/HLAcaller/ImputeAllelesWalker.java @@ -4,11 +4,9 @@ import net.sf.samtools.SAMRecord; import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; +import org.broadinstitute.sting.commandline.Output; -import java.io.FileInputStream; -import java.io.BufferedReader; -import java.io.DataInputStream; -import java.io.InputStreamReader; +import java.io.*; import java.util.ArrayList; import java.util.Hashtable; /** @@ -17,6 +15,9 @@ import java.util.Hashtable; */ @Requires({DataSource.READS, DataSource.REFERENCE}) public class ImputeAllelesWalker extends ReadWalker { + @Output + PrintStream out; + String HLAdatabaseFile ="/humgen/gsa-scr1/GSA/sjia/454_HLA/HLA/HLA_DICTIONARY.sam"; // String ClosestAllelesFile = "/humgen/gsa-scr1/GSA/sjia/454_HLA/HLA/HLA.CLASS1.closest"; String ClosestAllelesFile = "/humgen/gsa-scr1/GSA/sjia/454_HLA/HLA/HLA.CLASS2.closest"; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/LocusMismatchWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/LocusMismatchWalker.java index 8fb87ac35..3c3bdeafd 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/LocusMismatchWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/LocusMismatchWalker.java @@ -41,16 +41,21 @@ import org.broadinstitute.sting.gatk.walkers.genotyper.VariantCallContext; import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.pileup.PileupElement; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; import java.util.Collection; +import java.io.PrintStream; /** * Walker to calculate the number of mismatches, their base counts, and their quality sums at confidence ref sites" */ @By(DataSource.REFERENCE) public class LocusMismatchWalker extends LocusWalker implements TreeReducible { + @Output + PrintStream out; + //@Argument(fullName="confidentRefThreshold",doc="Set the lod score that defines confidence in ref, defaults to 4", required=false) //int confidentRefThreshold = 5; @Argument(fullName="maxNumMismatches",doc="Set the maximum number of mismatches at a locus before choosing not to use it in calculation. Defaults to 1.", required=false) diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/ReadBackedPhasingWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/ReadBackedPhasingWalker.java index 2a0f8c56e..610cfc86d 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/ReadBackedPhasingWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/ReadBackedPhasingWalker.java @@ -36,10 +36,11 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedDatum; import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.*; import org.broadinstitute.sting.utils.vcf.VCFUtils; import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; -import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; +import org.broadinstitute.sting.utils.genotype.vcf.StandardVCFWriter; import org.broadinstitute.sting.utils.pileup.PileupElement; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; @@ -56,6 +57,8 @@ import java.util.*; @ReadFilters( {ZeroMappingQualityReadFilter.class} ) // Filter out all reads with zero mapping quality public class ReadBackedPhasingWalker extends LocusWalker { + @Output + protected PrintStream out; @Argument(fullName = "cacheWindowSize", shortName = "cacheWindow", doc = "The window size (in bases) to cache variant sites and their reads; [default:20000]", required = false) protected Integer cacheWindow = 20000; @@ -89,7 +92,7 @@ public class ReadBackedPhasingWalker extends LocusWalker(vc.getSampleNames()))); } diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/SnpCallRateByCoverageWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/SnpCallRateByCoverageWalker.java index da9b6184d..83d050078 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/SnpCallRateByCoverageWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/SnpCallRateByCoverageWalker.java @@ -38,10 +38,12 @@ import org.broadinstitute.sting.gatk.walkers.genotyper.UnifiedGenotyperEngine; import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.MathUtils; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.ArrayList; import java.util.List; import java.util.Collection; +import java.io.PrintStream; /** @@ -49,6 +51,9 @@ import java.util.Collection; * positions to empirically assess the rate at which variants would be confidently and correctly called given different levels of coverage. */ public class SnpCallRateByCoverageWalker extends LocusWalker, String> { + @Output + PrintStream out; + // Control what goes into the variants file and what format that file should have @Argument(fullName="min_confidence_threshold", shortName="confidence", doc="The phred-scaled confidence threshold by which variants should be filtered", required=false) public int confidence = 50; @Argument(fullName="min_coverage", shortName="mincov", doc="Mininum coverage to downsample to", required=false) public int min_coverage=1; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/TrioGenotyperWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/TrioGenotyperWalker.java index bb9c8b14d..b80280d73 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/TrioGenotyperWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/TrioGenotyperWalker.java @@ -44,7 +44,7 @@ import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.QualityUtils; import org.broadinstitute.sting.utils.MathUtils; import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; -import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; +import org.broadinstitute.sting.utils.genotype.vcf.StandardVCFWriter; import org.broadinstitute.sting.gatk.walkers.varianteval.MendelianViolationEvaluator; import java.util.*; @@ -87,7 +87,7 @@ public class TrioGenotyperWalker extends RefWalker{ FAMILY_MEMBERS = Arrays.asList(mom, dad, kid); // initialize the writer - writer = new VCFWriterImpl(new File(vcfOutputFile)); + writer = new StandardVCFWriter(new File(vcfOutputFile)); } public VariantContext map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/VCFConcordance.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/VCFConcordance.java index 591487407..4024527ef 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/VCFConcordance.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/VCFConcordance.java @@ -10,14 +10,18 @@ import org.broadinstitute.sting.gatk.walkers.DataSource; import org.broadinstitute.sting.gatk.walkers.Requires; import org.broadinstitute.sting.gatk.walkers.RodWalker; import org.broadinstitute.sting.utils.GenomeLoc; +import org.broadinstitute.sting.commandline.Output; import java.util.EnumSet; +import java.io.PrintStream; /** * Calculates concordance between two VCF files; used for testing conversion of HapMap data to VCF */ @Requires(value={DataSource.REFERENCE}) public class VCFConcordance extends RodWalker { + @Output + PrintStream out; int correct = 0; int incorrect = 0; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/annotator/GenomicAnnotator.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/annotator/GenomicAnnotator.java index 05ac19369..93266285e 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/annotator/GenomicAnnotator.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/annotator/GenomicAnnotator.java @@ -28,6 +28,7 @@ package org.broadinstitute.sting.playground.gatk.walkers.annotator; import java.io.File; import java.io.IOException; +import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -45,6 +46,7 @@ import org.broad.tribble.util.variantcontext.VariantContext; import org.broad.tribble.vcf.VCFHeader; import org.broad.tribble.vcf.VCFHeaderLine; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.StratifiedAlignmentContext; @@ -63,7 +65,7 @@ import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.vcf.VCFUtils; import org.broadinstitute.sting.utils.genotype.vcf.VCFWriter; -import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; +import org.broadinstitute.sting.utils.genotype.vcf.StandardVCFWriter; /** * Annotates variant calls with information from user-specified tabular files. @@ -75,6 +77,9 @@ import org.broadinstitute.sting.utils.genotype.vcf.VCFWriterImpl; //@Reference(window=@Window(start=-50,stop=50)) @By(DataSource.REFERENCE) public class GenomicAnnotator extends RodWalker, LinkedList> implements TreeReducible> { + @Output + protected PrintStream out; + @Argument(fullName="vcfOutput", shortName="vcf", doc="VCF file to which all variants should be written with annotations", required=true) protected File VCF_OUT; @@ -241,7 +246,7 @@ public class GenomicAnnotator extends RodWalker, Link hInfo.add(new VCFHeaderLine("annotatorReference", getToolkit().getArguments().referenceFile.getName())); hInfo.addAll(engine.getVCFAnnotationDescriptions()); - vcfWriter = new VCFWriterImpl(VCF_OUT); + vcfWriter = new StandardVCFWriter(VCF_OUT); VCFHeader vcfHeader = new VCFHeader(hInfo, samples); vcfWriter.writeHeader(vcfHeader); } diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/annotator/TranscriptToInfo.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/annotator/TranscriptToInfo.java index 4f4c20cdf..a32766e3a 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/annotator/TranscriptToInfo.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/annotator/TranscriptToInfo.java @@ -25,10 +25,7 @@ package org.broadinstitute.sting.playground.gatk.walkers.annotator; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; +import java.io.*; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -42,6 +39,7 @@ import java.util.TreeMap; import net.sf.picard.util.Interval; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.datasources.simpleDataSources.ReferenceOrderedDataSource; @@ -85,6 +83,9 @@ public class TranscriptToInfo extends RodWalker, TreeMap //@Argument(fullName="pass-through", shortName="t", doc="Optionally specifies which columns from the transcript table should be copied verbatim (aka. passed-through) to the records in the output table. For example, -B transcripts,AnnotatorInputTable,/data/refGene.txt -t id will cause the refGene id column to be copied to the output table.", required=false) //protected String[] PASS_THROUGH_COLUMNS = {}; + @Output + private PrintWriter out; + @Argument(fullName="unique-gene-name-columns", shortName="n", doc="Specifies which column(s) from the transcript table contains the gene name(s). For example, -B transcripts,AnnotatorInputTable,/data/refGene.txt -n name,name2 specifies that the name and name2 columns are gene names. WARNING: the gene names for each record, when taken together, should provide a unique id for that record relative to all other records in the file. If this is not the case, an error will be thrown. ", required=true) private String[] GENE_NAME_COLUMNS = {}; @@ -129,8 +130,6 @@ public class TranscriptToInfo extends RodWalker, TreeMap //This is to avoid silently loosing data in the TreeMaps. private final Map keyChecker = new HashMap(); - private String outputFilename = null; - private int transcriptsProcessedCounter = 0; private long transcriptsThatDontStartWithMethionineOrEndWithStopCodonCounter = 0; @@ -218,17 +217,6 @@ public class TranscriptToInfo extends RodWalker, TreeMap OUTPUT_FILE_HEADER_LINE = outputHeaderLine.toString(); - - //init the output file - outputFilename = getToolkit().getArguments().outFileName; - if(outputFilename == null) { - throw new StingException("Output file not specified. (Used -o command-line-arg)" ); - } - - if(!new File(outputFilename).canWrite()) { - throw new StingException("Unable to write to output file: " + outputFilename ); - } - } /** @@ -978,23 +966,10 @@ public class TranscriptToInfo extends RodWalker, TreeMap return; } - logger.info("Writing " + result.size() + " lines to: " + outputFilename + ". Average of " + (totalPositionsCounter == 0 ? 0 : (10*result.size()/totalPositionsCounter)/10.0f) + " lines per genomic position."); - BufferedWriter fileWriter = null; - try { - fileWriter = new BufferedWriter(new FileWriter(outputFilename)); - fileWriter.write(OUTPUT_FILE_HEADER_LINE + '\n'); - for(String value : result.values() ) { - fileWriter.write(value + "\n"); - } - } catch(IOException e) { - logger.info("Unable to write to file: " + outputFilename); - } finally { - try { - if (fileWriter != null) - fileWriter.close(); - } catch(IOException e) { - logger.info("Unable to write to file: " + outputFilename); - } + logger.info("Writing " + result.size() + " lines to: " + out + ". Average of " + (totalPositionsCounter == 0 ? 0 : (10*result.size()/totalPositionsCounter)/10.0f) + " lines per genomic position."); + out.println(OUTPUT_FILE_HEADER_LINE); + for(String value : result.values() ) { + out.println(value); } logger.info("Skipped " + skippedPositionsCounter + " in-transcript genomic positions out of "+ totalPositionsCounter + " total (" + ( totalPositionsCounter == 0 ? 0 : (100*skippedPositionsCounter)/totalPositionsCounter) + "%)"); diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/contamination/FindContaminatingReadGroupsWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/contamination/FindContaminatingReadGroupsWalker.java index 939db258f..5c106eb5f 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/contamination/FindContaminatingReadGroupsWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/contamination/FindContaminatingReadGroupsWalker.java @@ -33,6 +33,7 @@ import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.playground.utils.NamedTable; import net.sf.samtools.SAMRecord; import net.sf.samtools.SAMReadGroupRecord; @@ -42,6 +43,7 @@ import cern.jet.stat.Probability; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.io.PrintStream; /** * FindContaminatingReadGroupsWalker lists read groups in a single-sample BAM file that appear @@ -51,6 +53,9 @@ import java.util.List; * @author Kiran Garimella */ public class FindContaminatingReadGroupsWalker extends LocusWalker { + @Output + private PrintStream out; + @Argument(fullName="balance", shortName="bal", doc="The expected alternate allele balance for homozygous-variant sites", required=false) private Double BALANCE = 0.95; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/ComputeConfusionMatrix.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/ComputeConfusionMatrix.java index a4c8318b9..11a4ab70e 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/ComputeConfusionMatrix.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/ComputeConfusionMatrix.java @@ -32,12 +32,14 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.BaseUtils; import net.sf.samtools.SAMRecord; import java.util.HashMap; import java.util.Arrays; import java.util.Hashtable; +import java.io.PrintStream; /** * Computes empirical base confusion matrix, and optionally computes @@ -45,6 +47,9 @@ import java.util.Hashtable; */ @Reference(window=@Window(start=-5,stop=5)) public class ComputeConfusionMatrix extends LocusWalker { + @Output + protected PrintStream out; + @Argument(fullName="minimumDepth", shortName="minDepth", doc="Require locus pileup to have specified minimum depth (default: 10)", required=false) public Integer MIN_DEPTH = 10; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/QualityScoreDistribution.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/QualityScoreDistribution.java index cce5774fc..8be94d143 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/QualityScoreDistribution.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/QualityScoreDistribution.java @@ -32,16 +32,21 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.QualityUtils; import net.sf.samtools.SAMRecord; import java.util.*; +import java.io.PrintStream; /** * Compute quality score distribution */ public class QualityScoreDistribution extends LocusWalker { + @Output + PrintStream out; + private HashMap qualDists; public void initialize() { diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/SNPDensity.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/SNPDensity.java index a004dac80..4947bf988 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/SNPDensity.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/SNPDensity.java @@ -34,8 +34,10 @@ import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.EnumSet; +import java.io.PrintStream; /** * Computes the density of SNPs passing and failing filters in intervals on the genome and emits a table for display @@ -43,6 +45,9 @@ import java.util.EnumSet; @By(DataSource.REFERENCE) @Requires(value={},referenceMetaData=@RMD(name="eval",type=ReferenceOrderedDatum.class)) public class SNPDensity extends RefWalker, SNPDensity.Counter> { + @Output + private PrintStream out; + @Argument(fullName="granularity", shortName="granularity", doc="", required=false) private int granularity = 1000000; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/duplicates/CombineDuplicatesWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/duplicates/CombineDuplicatesWalker.java index 72e225b8c..09e48833e 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/duplicates/CombineDuplicatesWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/duplicates/CombineDuplicatesWalker.java @@ -30,10 +30,12 @@ import org.broadinstitute.sting.gatk.walkers.DuplicateWalker; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.duplicates.DupUtils; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.List; import java.util.Set; import java.util.ArrayList; +import java.io.PrintStream; import net.sf.samtools.SAMRecord; import net.sf.samtools.SAMFileWriter; @@ -43,6 +45,9 @@ import net.sf.samtools.SAMFileWriter; * the specified output BAM location. If no output location is specified, the reads are written to STDOUT. */ public class CombineDuplicatesWalker extends DuplicateWalker, SAMFileWriter> { + @Output + public PrintStream out; + @Argument(fullName="outputBAM", shortName="outputBAM", required=false, doc="BAM File to write combined duplicates to") public SAMFileWriter outputBAM = null; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/duplicates/CountDuplicatesWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/duplicates/CountDuplicatesWalker.java index 041b455bb..522fdad13 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/duplicates/CountDuplicatesWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/duplicates/CountDuplicatesWalker.java @@ -31,10 +31,12 @@ import org.broadinstitute.sting.gatk.walkers.DuplicateWalker; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.List; import java.util.Set; import java.util.ArrayList; +import java.io.PrintStream; /** * a class to store the traversal information we pass around @@ -51,6 +53,9 @@ class DuplicateCount { * @author mark DePristo */ public class CountDuplicatesWalker extends DuplicateWalker { + @Output + PrintStream out; + @Argument(fullName="quietLocus", required=false, doc="If true, per locus information isn't printed") public boolean quiet = false; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/graphalign/GraphReferenceAssessor.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/graphalign/GraphReferenceAssessor.java index 433491712..1f7a85df3 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/graphalign/GraphReferenceAssessor.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/graphalign/GraphReferenceAssessor.java @@ -30,6 +30,7 @@ import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.utils.*; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.*; import java.io.*; @@ -42,6 +43,9 @@ import net.sf.samtools.SAMRecord; * reference for each read [Not for public use and will change drastically in the future]. */ public class GraphReferenceAssessor extends ReadWalker { + @Output + PrintStream out; + @Argument(fullName="graphFile", shortName="GF", doc="", required=true) String graphFile = null; ObjectInputStream graphSerialStream = null; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/hybridselection/CoverageAcrossBaitsWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/hybridselection/CoverageAcrossBaitsWalker.java index f8046ce37..8e5aaf591 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/hybridselection/CoverageAcrossBaitsWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/hybridselection/CoverageAcrossBaitsWalker.java @@ -37,10 +37,12 @@ import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.io.PrintStream; /** * Accumulates coverage across hybrid selection bait intervals to assess effect of bait adjacency and overlap on coverage @@ -48,6 +50,9 @@ import java.util.List; @By(DataSource.REFERENCE) public class CoverageAcrossBaitsWalker extends LocusWalker, CoverageAcrossBaitsWalker.Coverage> { + @Output + public PrintStream out; + /* Accumulates coverage across hybrid selection bait intervals to assess effect of bait adjacency. Requires input bait intervals that have an overhang beyond the actual bait interval to capture coverage data at these points. Outputs R parseable file that has all data in lists and then does some basic plotting. diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/hybridselection/HybSelPerformanceWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/hybridselection/HybSelPerformanceWalker.java index 2b5769125..5b2debf51 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/hybridselection/HybSelPerformanceWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/hybridselection/HybSelPerformanceWalker.java @@ -50,9 +50,11 @@ import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import java.io.File; import java.io.IOException; +import java.io.PrintStream; import java.util.Collection; import java.util.List; @@ -63,6 +65,9 @@ import java.util.List; */ @By(DataSource.REFERENCE) public class HybSelPerformanceWalker extends LocusWalker implements TreeReducible { + @Output + public PrintStream out; + @Argument(fullName="min_mapq", shortName="mmq", required=false, doc="Minimum mapping quality of reads to consider") public Integer MIN_MAPQ = 1; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/papergenotyper/GATKPaperGenotyper.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/papergenotyper/GATKPaperGenotyper.java index 87879fd48..0c6b17c43 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/papergenotyper/GATKPaperGenotyper.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/papergenotyper/GATKPaperGenotyper.java @@ -33,8 +33,11 @@ import org.broadinstitute.sting.gatk.walkers.TreeReducible; import org.broadinstitute.sting.gatk.walkers.genotyper.DiploidGenotypePriors; import org.broadinstitute.sting.utils.MathUtils; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; +import java.io.PrintStream; + /** * A simple Bayesian genotyper, that outputs a text based call format. Intended to be used only as an @@ -46,6 +49,9 @@ public class GATKPaperGenotyper extends LocusWalker implements Tre // the possible diploid genotype strings private static enum GENOTYPE { AA, AC, AG, AT, CC, CG, CT, GG, GT, TT } + @Output + private PrintStream out; + @Argument(fullName = "log_odds_score", shortName = "LOD", doc = "The LOD threshold for us to call confidently a genotype", required = false) private double LODScore = 3.0; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/poolseq/PowerBelowFrequencyWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/poolseq/PowerBelowFrequencyWalker.java index 823274537..536c1458c 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/poolseq/PowerBelowFrequencyWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/poolseq/PowerBelowFrequencyWalker.java @@ -32,6 +32,7 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.QualityUtils; import org.broadinstitute.sting.utils.MathUtils; @@ -40,6 +41,7 @@ import org.broadinstitute.sting.playground.utils.PoolUtils; import net.sf.samtools.SAMRecord; import java.util.List; +import java.io.PrintStream; /** * Created by IntelliJ IDEA. @@ -54,6 +56,9 @@ import java.util.List; */ @By(DataSource.REFERENCE) public class PowerBelowFrequencyWalker extends LocusWalker { + @Output + PrintStream out; + @Argument(fullName="lodThreshold", shortName="lod", doc="Threshold for log likelihood ratio to be called a SNP. Defaults to 3.0", required = false) public double lodThresh = 3.0; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/qc/CountPairsWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/qc/CountPairsWalker.java index bcee401f0..f2145411d 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/qc/CountPairsWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/qc/CountPairsWalker.java @@ -27,10 +27,12 @@ package org.broadinstitute.sting.playground.gatk.walkers.qc; import org.broadinstitute.sting.gatk.walkers.ReadPairWalker; import org.broadinstitute.sting.utils.collections.ExpandingArrayList; +import org.broadinstitute.sting.commandline.Output; import net.sf.samtools.SAMRecord; import java.util.Collection; import java.util.List; +import java.io.PrintStream; /** * Counts the number of read pairs encountered in a file sorted in @@ -41,6 +43,9 @@ import java.util.List; * @version 0.1 */ public class CountPairsWalker extends ReadPairWalker { + @Output + private PrintStream out; + /** * How many reads are the first in a pair, based on flag 0x0040 from the SAM spec. */ diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/secondaryBases/SecondaryBaseTransitionTableWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/secondaryBases/SecondaryBaseTransitionTableWalker.java index 76d80c47f..1bf73e418 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/secondaryBases/SecondaryBaseTransitionTableWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/secondaryBases/SecondaryBaseTransitionTableWalker.java @@ -12,8 +12,10 @@ import org.broadinstitute.sting.playground.utils.NamedTable; import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.pileup.PileupElement; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; +import org.broadinstitute.sting.commandline.Output; import java.util.HashMap; +import java.io.PrintStream; /** * Given a secondary base annotated .bam file and a reference, this walker generates a table of secondary base counts @@ -24,6 +26,8 @@ import java.util.HashMap; @Reference(window=@Window(start=-1,stop=1)) public class SecondaryBaseTransitionTableWalker extends LocusWalker { + @Output + PrintStream out; HashMap counts = new HashMap(); private UnifiedGenotyperEngine ug; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/validation/RodSystemValidationWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/validation/RodSystemValidationWalker.java index 14a3d6c85..178aedac7 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/validation/RodSystemValidationWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/validation/RodSystemValidationWalker.java @@ -2,6 +2,7 @@ package org.broadinstitute.sting.playground.gatk.walkers.validation; import org.broad.tribble.util.variantcontext.VariantContext; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; @@ -27,6 +28,9 @@ public class RodSystemValidationWalker extends RodWalker { // the divider to use in some of the text output private static final String DIVIDER = ","; + @Output + public PrintStream out; + @Argument(fullName="PerLocusEqual",required=false,doc="Should we check that all records at the same site produce equivilent variant contexts") public boolean allRecordsVariantContextEquivalent = false; @@ -110,6 +114,13 @@ public class RodSystemValidationWalker extends RodWalker { return value + sum; } + @Override + public void onTraversalDone(Integer result) { + // Double check traversal result to make count is the same. + // TODO: Is this check necessary? + out.println("[REDUCE RESULT] Traversal result is: " + result); + } + // shamelessly absconded and adapted from http://www.javalobby.org/java/forums/t84420.html private String md5sum(File f) { InputStream is; diff --git a/java/src/org/broadinstitute/sting/queue/extensions/gatk/GATKExtensionsGenerator.java b/java/src/org/broadinstitute/sting/queue/extensions/gatk/GATKExtensionsGenerator.java index 72f30f3b5..553156e47 100644 --- a/java/src/org/broadinstitute/sting/queue/extensions/gatk/GATKExtensionsGenerator.java +++ b/java/src/org/broadinstitute/sting/queue/extensions/gatk/GATKExtensionsGenerator.java @@ -83,10 +83,10 @@ public class GATKExtensionsGenerator extends CommandLineProgram { @Override protected Collection getArgumentTypeDescriptors() { List typeDescriptors = new ArrayList(); - typeDescriptors.add(new VCFWriterArgumentTypeDescriptor(GATKEngine)); + typeDescriptors.add(new VCFWriterArgumentTypeDescriptor(GATKEngine,System.out)); typeDescriptors.add(new SAMFileReaderArgumentTypeDescriptor(GATKEngine)); - typeDescriptors.add(new SAMFileWriterArgumentTypeDescriptor(GATKEngine)); - typeDescriptors.add(new OutputStreamArgumentTypeDescriptor(GATKEngine)); + typeDescriptors.add(new SAMFileWriterArgumentTypeDescriptor(GATKEngine,System.out)); + typeDescriptors.add(new OutputStreamArgumentTypeDescriptor(GATKEngine,System.out)); return typeDescriptors; } diff --git a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterImpl.java b/java/src/org/broadinstitute/sting/utils/genotype/vcf/StandardVCFWriter.java similarity index 99% rename from java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterImpl.java rename to java/src/org/broadinstitute/sting/utils/genotype/vcf/StandardVCFWriter.java index 57a7dc796..6012fc31d 100644 --- a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterImpl.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/vcf/StandardVCFWriter.java @@ -40,7 +40,7 @@ import java.util.*; /** * this class writes VCF files */ -public class VCFWriterImpl implements VCFWriter { +public class StandardVCFWriter implements VCFWriter { // the VCF header we're storing protected VCFHeader mHeader = null; @@ -56,7 +56,7 @@ public class VCFWriterImpl implements VCFWriter { * * @param location the file location to write to */ - public VCFWriterImpl(File location) { + public StandardVCFWriter(File location) { FileOutputStream output; try { output = new FileOutputStream(location); @@ -73,7 +73,7 @@ public class VCFWriterImpl implements VCFWriter { * * @param output the file location to write to */ - public VCFWriterImpl(OutputStream output) { + public StandardVCFWriter(OutputStream output) { mWriter = new BufferedWriter(new OutputStreamWriter(output)); } diff --git a/java/test/org/broadinstitute/sting/gatk/arguments/GATKArgumentCollectionUnitTest.java b/java/test/org/broadinstitute/sting/gatk/arguments/GATKArgumentCollectionUnitTest.java index a9134876b..7a5db4755 100755 --- a/java/test/org/broadinstitute/sting/gatk/arguments/GATKArgumentCollectionUnitTest.java +++ b/java/test/org/broadinstitute/sting/gatk/arguments/GATKArgumentCollectionUnitTest.java @@ -91,9 +91,6 @@ public class GATKArgumentCollectionUnitTest extends BaseTest { collect.intervals = new ArrayList(); collect.intervals.add("intervals".toLowerCase()); collect.excludeIntervals = new ArrayList(); - collect.outFileName = "outFileName".toLowerCase(); - collect.errFileName = "errFileName".toLowerCase(); - collect.outErrFileName = "outErrFileName".toLowerCase(); collect.numberOfThreads = 1; // make some rod bindings up diff --git a/java/test/org/broadinstitute/sting/gatk/io/OutputTrackerUnitTest.java b/java/test/org/broadinstitute/sting/gatk/io/OutputTrackerUnitTest.java deleted file mode 100755 index e7fcf6fb0..000000000 --- a/java/test/org/broadinstitute/sting/gatk/io/OutputTrackerUnitTest.java +++ /dev/null @@ -1,143 +0,0 @@ -package org.broadinstitute.sting.gatk.io; - -import org.junit.Test; -import org.junit.After; -import org.junit.Assert; -import org.broadinstitute.sting.BaseTest; -import org.broadinstitute.sting.gatk.io.stubs.OutputStreamStub; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.PrintWriter; -import java.util.Scanner; -/** - * User: hanna - * Date: Apr 30, 2009 - * Time: 10:20:18 AM - * BROAD INSTITUTE SOFTWARE COPYRIGHT NOTICE AND AGREEMENT - * Software and documentation are copyright 2005 by the Broad Institute. - * All rights are reserved. - * - * Users acknowledge that this software is supplied without any warranty or support. - * The Broad Institute is not responsible for its use, misuse, or - * functionality. - */ - -/** - * For the file opening and closing mechanisms. - */ - -public class OutputTrackerUnitTest extends BaseTest { - public static final String OUTPUT_FILENAME = "OutputTrackerUnitTest.out"; - public static final String ERROR_FILENAME = "OutputTrackerUnitTest.err"; - - @After - public void cleanupTestFiles() { - File outFile = new File( OUTPUT_FILENAME ); - File errFile = new File( ERROR_FILENAME ); - - if( outFile.exists() ) outFile.delete(); - if( errFile.exists() ) errFile.delete(); - } - - @Test - public void testNullInputs() { - OutputTracker ot = new DirectOutputTracker(); - ot.initializeCoreIO(null,null); - - Assert.assertNotNull("OutputTracker: Output stream is null.", ot.outStub ); - Assert.assertNotNull("OutputTracker: Error stream is null.", ot.errStub ); - - OutputStreamStub outStream = ot.outStub; - Assert.assertNull("OutputTracker: Output file incorrectly initialized.", outStream.getOutputFile()); - Assert.assertSame("OutputTracker: Output stream incorrectly initialized.", System.out, outStream.getOutputStream()); - - OutputStreamStub errStream = ot.errStub; - Assert.assertNull("OutputTracker: Error file incorrectly initialized.", errStream.getOutputFile()); - Assert.assertSame("OutputTracker: Error stream incorrectly initialized.", System.err, errStream.getOutputStream()); - } - - @Test - public void testOutputStreamAlone() throws FileNotFoundException { - OutputTracker ot = new DirectOutputTracker(); - ot.initializeCoreIO(OUTPUT_FILENAME,null); - - final String OUTPUT_TEXT = "out stream test"; - PrintWriter outWriter = new PrintWriter(ot.outStub); - outWriter.append(OUTPUT_TEXT); - outWriter.close(); - - Scanner outScanner = new Scanner(new File(OUTPUT_FILENAME)); - String outText = outScanner.nextLine(); - Assert.assertFalse("Out stream has too much data", outScanner.hasNext()); - - Assert.assertEquals("OutputTracker: Written output is incorrect", outText, OUTPUT_TEXT); - - OutputStreamStub errStream = ot.errStub; - Assert.assertNull("OutputTracker: Error file incorrectly initialized.", errStream.getOutputFile()); - Assert.assertSame("OutputTracker: Error stream incorrectly initialized.", System.err, errStream.getOutputStream()); - } - - @Test - public void testErrorStreamAlone() throws FileNotFoundException { - OutputTracker ot = new DirectOutputTracker(); - ot.initializeCoreIO(null,ERROR_FILENAME); - - OutputStreamStub outStream = ot.outStub; - Assert.assertNull("OutputTracker: Output file incorrectly initialized.", outStream.getOutputFile()); - Assert.assertSame("OutputTracker: Output stream incorrectly initialized.", System.out, outStream.getOutputStream()); - - final String ERROR_TEXT = "err stream test"; - PrintWriter errWriter = new PrintWriter(ot.errStub); - errWriter.append(ERROR_TEXT); - errWriter.close(); - - Scanner errScanner = new Scanner(new File(ERROR_FILENAME)); - String errText = errScanner.nextLine(); - Assert.assertFalse("Err stream has too much data", errScanner.hasNext()); - - Assert.assertEquals("OutputTracker: Written error text is incorrect", errText, ERROR_TEXT); - } - - @Test - public void testIndependentStreams() throws FileNotFoundException { - OutputTracker ot = new DirectOutputTracker(); - ot.initializeCoreIO(OUTPUT_FILENAME,ERROR_FILENAME); - - final String OUTPUT_TEXT = "out stream test"; - PrintWriter outWriter = new PrintWriter(ot.outStub); - outWriter.append(OUTPUT_TEXT); - outWriter.close(); - - final String ERROR_TEXT = "err stream test"; - PrintWriter errWriter = new PrintWriter(ot.errStub); - errWriter.append(ERROR_TEXT); - errWriter.close(); - - Scanner outScanner = new Scanner(new File(OUTPUT_FILENAME)); - String outText = outScanner.nextLine(); - Assert.assertFalse("Out stream has too much data", outScanner.hasNext()); - - Scanner errScanner = new Scanner(new File(ERROR_FILENAME)); - String errText = errScanner.nextLine(); - Assert.assertFalse("Err stream has too much data", errScanner.hasNext()); - - Assert.assertEquals("OutputTracker: Written output text is incorrect", outText, OUTPUT_TEXT); - Assert.assertEquals("OutputTracker: Written error text is incorrect", errText, ERROR_TEXT); - } - - @Test - public void testIdenticalInputsGetIdenticalResults() { - OutputTracker ot = new DirectOutputTracker(); - ot.initializeCoreIO(OUTPUT_FILENAME,OUTPUT_FILENAME); - - Assert.assertNotNull("OutputTracker: Output stream is null.", ot.outStub ); - Assert.assertNotNull("OutputTracker: Error stream is null.", ot.errStub ); - - OutputStreamStub outStream = ot.outStub; - OutputStreamStub errStream = ot.errStub; - - Assert.assertSame("OutputTracker: files don't match", outStream.getOutputFile(), errStream.getOutputFile()); - Assert.assertSame("OutputTracker: streams don't match", outStream.getOutputStream(), errStream.getOutputStream()); - } -} diff --git a/java/test/org/broadinstitute/sting/gatk/traversals/TraverseReadsUnitTest.java b/java/test/org/broadinstitute/sting/gatk/traversals/TraverseReadsUnitTest.java index 6448b5b3a..b81db8853 100755 --- a/java/test/org/broadinstitute/sting/gatk/traversals/TraverseReadsUnitTest.java +++ b/java/test/org/broadinstitute/sting/gatk/traversals/TraverseReadsUnitTest.java @@ -25,6 +25,7 @@ import java.io.PrintStream; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; +import java.util.Collections; /** * @@ -81,22 +82,9 @@ public class TraverseReadsUnitTest extends BaseTest { fail("Couldn't open the output file"); } - // Connect print stream to the output stream - ps = new PrintStream(out); bamList = new ArrayList(); bamList.add(bam); countReadWalker = new CountReadsWalker(); - try { - Field f = Walker.class.getDeclaredField("out"); - f.setAccessible(true); - f.set(countReadWalker, ps); - - } catch (IllegalAccessException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. - } catch (NoSuchFieldException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. - fail("Couldn't set the walkers printstream"); - } traversalEngine = new TraverseReads(); diff --git a/java/test/org/broadinstitute/sting/gatk/walkers/PrintReadsWalkerUnitTest.java b/java/test/org/broadinstitute/sting/gatk/walkers/PrintReadsWalkerUnitTest.java index 976eff31d..c59730807 100644 --- a/java/test/org/broadinstitute/sting/gatk/walkers/PrintReadsWalkerUnitTest.java +++ b/java/test/org/broadinstitute/sting/gatk/walkers/PrintReadsWalkerUnitTest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import net.sf.samtools.SAMRecord; import net.sf.samtools.SAMFileHeader; +import net.sf.samtools.SAMFileWriterFactory; /* @@ -70,6 +71,8 @@ public class PrintReadsWalkerUnitTest extends BaseTest { public void testReadCount() { PrintReadsWalker walker = new PrintReadsWalker(); ArtificialSAMFileWriter writer = new ArtificialSAMFileWriter(); + walker.out = writer; + trav.traverse(walker, null, writer); assertEquals(readTotal, writer.getRecords().size()); } @@ -78,6 +81,8 @@ public class PrintReadsWalkerUnitTest extends BaseTest { @Test public void testNullRead() { PrintReadsWalker walker = new PrintReadsWalker(); + ArtificialSAMFileWriter writer = new ArtificialSAMFileWriter(); + walker.out = writer; SAMRecord rec = walker.map(bases, null, null); assertTrue(rec == null); @@ -87,6 +92,9 @@ public class PrintReadsWalkerUnitTest extends BaseTest { @Test public void testReturnRead() { PrintReadsWalker walker = new PrintReadsWalker(); + ArtificialSAMFileWriter writer = new ArtificialSAMFileWriter(); + walker.out = writer; + SAMFileHeader head = ArtificialSAMUtils.createArtificialSamHeader(3,1,1000); SAMRecord rec = ArtificialSAMUtils.createArtificialRead(head, "FakeRead", 1, 1, 50); SAMRecord ret = walker.map(bases, rec,null); @@ -98,9 +106,11 @@ public class PrintReadsWalkerUnitTest extends BaseTest { @Test public void testReducingRead() { PrintReadsWalker walker = new PrintReadsWalker(); - SAMFileHeader head = ArtificialSAMUtils.createArtificialSamHeader(3,1,1000); - SAMRecord rec = ArtificialSAMUtils.createArtificialRead(head, "FakeRead", 1, 1, 50); ArtificialSAMFileWriter writer = new ArtificialSAMFileWriter(); + walker.out = writer; + + SAMFileHeader head = ArtificialSAMUtils.createArtificialSamHeader(3,1,1000); + SAMRecord rec = ArtificialSAMUtils.createArtificialRead(head, "FakeRead", 1, 1, 50); SAMRecord ret = walker.map(bases, null,null); walker.reduce(ret,writer); diff --git a/java/test/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterUnitTest.java b/java/test/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterUnitTest.java index 9c720fdc8..de18053ef 100644 --- a/java/test/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterUnitTest.java +++ b/java/test/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterUnitTest.java @@ -45,7 +45,7 @@ public class VCFWriterUnitTest extends BaseTest { @Test public void testBasicWriteAndRead() { VCFHeader header = createFakeHeader(metaData,additionalColumns); - VCFWriter writer = new VCFWriterImpl(fakeVCFFile); + VCFWriter writer = new StandardVCFWriter(fakeVCFFile); writer.writeHeader(header); writer.add(createVC(header),"A".getBytes()[0]); writer.add(createVC(header),"A".getBytes()[0]);