@Override public void processArguments( final GATKArgumentCollection argumentCollection ) { if (argumentCollection.bamCompression != null) setCompressionLevel(argumentCollection.bamCompression); setGenerateMD5(argumentCollection.enableBAMmd5); setIndexOnTheFly(!argumentCollection.disableBAMIndexing); setSimplifyBAM(argumentCollection.simplifyBAM); }
/** * As {@link #createSAMFileWriter(String, org.broadinstitute.gatk.engine.GenomeAnalysisEngine)}, but also sets the header */ public static SAMFileWriter createSAMFileWriter(final String file, final GenomeAnalysisEngine engine, final SAMFileHeader header) { final SAMFileWriterStub output = (SAMFileWriterStub) createSAMFileWriter(file, engine); output.writeHeader(header); return output; }
@Override public void processArguments( final GATKArgumentCollection argumentCollection ) { setDoNotWriteGenotypes(argumentCollection.sitesOnlyVCF); setSkipWritingCommandLineHeader(argumentCollection.disableCommandLineInVCF); setForceBCF(argumentCollection.forceBCFOutput); setWriteFullFormatField(argumentCollection.neverTrimVCFFormatField); }
/** * Subclasses of CommandLinePrograms can provide their own types of command-line arguments. * @return A collection of type descriptors generating implementation-dependent placeholders. */ protected Collection<ArgumentTypeDescriptor> getArgumentTypeDescriptors() { return Arrays.asList( new VCFWriterArgumentTypeDescriptor(engine,System.out,argumentSources), new SAMFileWriterArgumentTypeDescriptor(engine,System.out), new OutputStreamArgumentTypeDescriptor(engine,System.out) ); }
@DataProvider(name = "OutputProvider") public Object[][] OutputProvider() { ObjectArrayList<Object[]> tests = new ObjectArrayList<Object[]>(); final ATDTestCommandLineProgram clp = new ATDTestCommandLineProgram(); for ( final Object obj : Arrays.asList(clp.new OutputRequiredSamArgumentSource(), clp.new OutputRequiredVcfArgumentSource(), clp.new OutputRequiredStreamArgumentSource()) ) { for ( final boolean provided : Arrays.asList(true, false) ) { tests.add(new Object[]{obj, true, true, provided}); } } for ( final Object obj : Arrays.asList(clp.new OutputNotRequiredSamArgumentSource(), clp.new OutputNotRequiredVcfArgumentSource(), clp.new OutputNotRequiredStreamArgumentSource()) ) { for ( final boolean provided : Arrays.asList(true, false) ) { tests.add(new Object[]{obj, false, true, provided}); } } for ( final Object obj : Arrays.asList(clp.new OutputNotRequiredNoDefaultSamArgumentSource(), clp.new OutputNotRequiredNoDefaultVcfArgumentSource(), clp.new OutputNotRequiredNoDefaultStreamArgumentSource()) ) { for ( final boolean provided : Arrays.asList(true, false) ) { tests.add(new Object[]{obj, false, false, provided}); } } return tests.toArray(new Object[][]{}); }
private static boolean outputIsStdout(final Object out) { if ( out == null ) { return false; } else if ( out instanceof SAMFileWriterStub ) { return ((SAMFileWriterStub)out).getOutputStream() != System.out; } else if ( out instanceof VariantContextWriterStub ) { return ((VariantContextWriterStub)out).getOutputStream() == System.out; } else if ( out instanceof OutputStreamStub ) { return ((OutputStreamStub)out).getOutputStream() == System.out; } return false; }
@Override public Object parse( ParsingEngine parsingEngine, ArgumentSource source, Type type, ArgumentMatches matches ) { // Extract all possible parameters that could be passed to a BAM file writer? ArgumentDefinition bamArgumentDefinition = createDefaultArgumentDefinition(source); ArgumentMatchValue writerFileName = getArgumentValue( bamArgumentDefinition, matches ); // Create the stub SAMFileWriterStub stub = null; // stub = new SAMFileWriterStub(engine, defaultOutputStream); if (writerFileName != null && writerFileName.asFile() != null ) { stub = new SAMFileWriterStub(engine, writerFileName.asFile()); // WARNING: Side effects required by engine! parsingEngine.addTags(stub,getArgumentTags(matches)); engine.addOutput(stub); } return stub; }
/** * Should we also write a BCF file alongside our VCF file for testing * * TODO -- remove me when argument generateShadowBCF is removed * * @return */ public boolean alsoWriteBCFForTest() { return engine.getArguments().numberOfDataThreads == 1 && // only works single threaded ! isCompressed() && // for non-compressed outputs getOutputFile() != null && // that are going to disk engine.getArguments().generateShadowBCF; // and we actually want to do it }
@Override public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source, Type type) { if(source.isRequired() || !source.defaultsToStdout()) throw new ReviewedGATKException("BUG: tried to create type default for argument type descriptor that can't support a type default."); OutputStreamStub stub = new OutputStreamStub(defaultOutputStream); engine.addOutput(stub); return createInstanceOfClass((Class)type,stub); }
@Test(dataProvider = "OutputProvider") public void testOutput(final ATDTestCommandLineProgram.ATDTestOutputArgumentSource argumentSource, final boolean required, final boolean hasDefault, final boolean provided) { final ParsingEngine parser = new ParsingEngine(new ATDTestCommandLineProgram()); parser.addArgumentSource(argumentSource.getClass()); parser.parse(provided ? new String[] {"out", "foo"} : new String[] {}); try { parser.loadArgumentsIntoObject(argumentSource); if ( !provided && (required || !hasDefault) ) Assert.assertEquals(argumentSource.getOut(), null); else if ( !provided ) Assert.assertNotEquals(argumentSource.getOut(), null); else if ( argumentSource.getOut() == null || !(argumentSource.getOut() instanceof SAMFileWriterStub) ) // can't test this one case Assert.assertEquals(!provided, outputIsStdout(argumentSource.getOut())); } catch (Exception e) { throw new ReviewedGATKException(e.getMessage()); } }
public EnumSet<Options> getWriterOptions() { return getWriterOptions(false); }
/** * Gets a string representation of this object. * @return a string representation of this object. */ @Override public String toString() { return (getOutputFile() == null) ? "(Stream)" : getOutputFile().getAbsolutePath(); }
/** * Creates a SAMFileWriter using all of the features currently set in the engine (command line arguments, ReadTransformers, etc) * @param file the filename to write to * @param engine the engine * @return a SAMFileWriter with the correct options set */ public static SAMFileWriter createSAMFileWriter(final String file, final GenomeAnalysisEngine engine) { final SAMFileWriterStub output = new SAMFileWriterStub(engine, new File(file)); output.processArguments(engine.getArguments()); return output; }
@Test public void testOutputPathWithNullFile() { tracker.validateOutputPath(new OutputStreamStub(System.out)); } }
@Override public boolean supports( Class type ) { return getConstructorForClass(type) != null; }
public SAMFileWriterStorage( SAMFileWriterStub stub ) { this(stub,stub.getOutputFile()); }
/** * Provide a mechanism for injecting supplemental streams for external management. * @param stub Stream to manage. */ public <T> void addOutput(Stub<T> stub, Storage<T> storage) { stub.register(this); outputs.put(stub,storage); validateOutputPath(stub); }
@Override protected Collection<ArgumentTypeDescriptor> getArgumentTypeDescriptors() { List<ArgumentTypeDescriptor> typeDescriptors = new ArrayList<ArgumentTypeDescriptor>(); typeDescriptors.add(new VCFWriterArgumentTypeDescriptor(GATKEngine,System.out,Collections.<Object>emptyList())); typeDescriptors.add(new SAMFileWriterArgumentTypeDescriptor(GATKEngine,System.out)); typeDescriptors.add(new OutputStreamArgumentTypeDescriptor(GATKEngine,System.out)); return typeDescriptors; }
/** * 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 (Exception e) { throw new DynamicClassResolutionException(type, e); } } }
@Override public Collection<ArgumentTypeDescriptor> getArgumentTypeDescriptors() { final GenomeAnalysisEngine engine = new GenomeAnalysisEngine(); return Arrays.asList( new SAMFileWriterArgumentTypeDescriptor(engine, System.out), new OutputStreamArgumentTypeDescriptor(engine, System.out), new VCFWriterArgumentTypeDescriptor(engine, System.out, null)); }