Search in sources :

Example 1 with CommandLineArgumentParser

use of org.broadinstitute.barclay.argparser.CommandLineArgumentParser in project gatk by broadinstitute.

the class VariantWalkerIntegrationTest method testBestSequenceDictionary_FromVariantIndex.

@Test
public void testBestSequenceDictionary_FromVariantIndex() throws Exception {
    final GATKTool tool = new TestGATKToolWithFeatures();
    final CommandLineParser clp = new CommandLineArgumentParser(tool);
    final File vcfFile = new File(publicTestDir + "org/broadinstitute/hellbender/engine/example_variants_noSequenceDict.vcf");
    final String[] args = { "--variant", vcfFile.getCanonicalPath() };
    clp.parseArguments(System.out, args);
    tool.onStartup();
    // make sure we get the seq dict from the index when there isn't one in the VCF and there is no reference available
    final SAMSequenceDictionary toolDict = tool.getBestAvailableSequenceDictionary();
    Assert.assertTrue(toolDict.getSequences().stream().allMatch(seqRec -> seqRec.getSequenceLength() == 0));
}
Also used : CommandLineProgramProperties(org.broadinstitute.barclay.argparser.CommandLineProgramProperties) Iterator(java.util.Iterator) CommandLineArgumentParser(org.broadinstitute.barclay.argparser.CommandLineArgumentParser) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) Argument(org.broadinstitute.barclay.argparser.Argument) TestProgramGroup(org.broadinstitute.hellbender.cmdline.TestProgramGroup) ExampleVariantWalker(org.broadinstitute.hellbender.tools.examples.ExampleVariantWalker) CommandLineParser(org.broadinstitute.barclay.argparser.CommandLineParser) ArgumentsBuilder(org.broadinstitute.hellbender.utils.test.ArgumentsBuilder) Test(org.testng.annotations.Test) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest) File(java.io.File) ArrayList(java.util.ArrayList) List(java.util.List) UserException(org.broadinstitute.hellbender.exceptions.UserException) Assert(org.testng.Assert) VariantContext(htsjdk.variant.variantcontext.VariantContext) CommandLineArgumentParser(org.broadinstitute.barclay.argparser.CommandLineArgumentParser) CommandLineParser(org.broadinstitute.barclay.argparser.CommandLineParser) File(java.io.File) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 2 with CommandLineArgumentParser

use of org.broadinstitute.barclay.argparser.CommandLineArgumentParser in project gatk by broadinstitute.

the class ReadFilterPluginUnitTest method testDanglingFilterArguments.

// fail if a filter's arguments are passed but the filter itself is not enabled
@Test(dataProvider = "filtersWithRequiredArguments", expectedExceptions = CommandLineException.class)
public void testDanglingFilterArguments(final String filter, final String argName, final String argValue) {
    CommandLineParser clp = new CommandLineArgumentParser(new Object(), Collections.singletonList(new GATKReadFilterPluginDescriptor(null)));
    // no read filter set
    String[] args = { argName, argValue };
    // no need to instantiate the filters - dependency errors are caught by the command line parser
    clp.parseArguments(nullMessageStream, args);
}
Also used : GATKReadFilterPluginDescriptor(org.broadinstitute.hellbender.cmdline.GATKPlugin.GATKReadFilterPluginDescriptor) CommandLineArgumentParser(org.broadinstitute.barclay.argparser.CommandLineArgumentParser) CommandLineParser(org.broadinstitute.barclay.argparser.CommandLineParser) Test(org.testng.annotations.Test)

Example 3 with CommandLineArgumentParser

use of org.broadinstitute.barclay.argparser.CommandLineArgumentParser in project gatk by broadinstitute.

the class ReadFilterPluginUnitTest method testPreserveCommandLineOrder.

@Test
public void testPreserveCommandLineOrder() {
    List<ReadFilter> orderedDefaults = new ArrayList<>();
    orderedDefaults.add(new WellformedReadFilter());
    orderedDefaults.add(ReadFilterLibrary.HAS_READ_GROUP);
    orderedDefaults.add(ReadFilterLibrary.MAPPING_QUALITY_NOT_ZERO);
    CommandLineParser clp = new CommandLineArgumentParser(new Object(), Collections.singletonList(new GATKReadFilterPluginDescriptor(orderedDefaults)));
    clp.parseArguments(nullMessageStream, new String[] { "-readFilter", ReadFilterLibrary.MAPPED.getClass().getSimpleName(), "-readFilter", ReadFilterLibrary.HAS_MATCHING_BASES_AND_QUALS.getClass().getSimpleName(), "-readFilter", ReadFilterLibrary.GOOD_CIGAR.getClass().getSimpleName() });
    GATKReadFilterPluginDescriptor readFilterPlugin = clp.getPluginDescriptor(GATKReadFilterPluginDescriptor.class);
    // get and verify the list of filters enabled on the command line (not including defaults)
    List<ReadFilter> orderedFilters = readFilterPlugin.getAllInstances();
    Assert.assertEquals(orderedFilters.size(), 3);
    Assert.assertEquals(orderedFilters.get(0).getClass().getSimpleName(), ReadFilterLibrary.MAPPED.getClass().getSimpleName());
    Assert.assertEquals(orderedFilters.get(1).getClass().getSimpleName(), ReadFilterLibrary.HAS_MATCHING_BASES_AND_QUALS.getClass().getSimpleName());
    Assert.assertEquals(orderedFilters.get(2).getClass().getSimpleName(), ReadFilterLibrary.GOOD_CIGAR.getClass().getSimpleName());
    // Now get the final merged read filter and verify the execution order. We need to ensure that
    // getMergedReadFilter creates a composite filter that honors the filter test execution
    // order rules (tool defaults first, in order, followed by command line-specified, in order
    // listed), so validate by reaching inside the filter and navigating down the tree.
    ReadFilter rf = instantiateFilter(clp, createHeaderWithReadGroups());
    String[] expectedOrder = { WellformedReadFilter.class.getSimpleName(), ReadFilterLibrary.HAS_READ_GROUP.getClass().getSimpleName(), ReadFilterLibrary.MAPPING_QUALITY_NOT_ZERO.getClass().getSimpleName(), ReadFilterLibrary.MAPPED.getClass().getSimpleName(), ReadFilterLibrary.HAS_MATCHING_BASES_AND_QUALS.getClass().getSimpleName(), ReadFilterLibrary.GOOD_CIGAR.getClass().getSimpleName() };
    int count = ReadFilterUnitTest.verifyAndFilterOrder(rf, expectedOrder);
    Assert.assertEquals(count, 6);
}
Also used : GATKReadFilterPluginDescriptor(org.broadinstitute.hellbender.cmdline.GATKPlugin.GATKReadFilterPluginDescriptor) CommandLineArgumentParser(org.broadinstitute.barclay.argparser.CommandLineArgumentParser) ArrayList(java.util.ArrayList) CommandLineParser(org.broadinstitute.barclay.argparser.CommandLineParser) Test(org.testng.annotations.Test)

Example 4 with CommandLineArgumentParser

use of org.broadinstitute.barclay.argparser.CommandLineArgumentParser in project gatk by broadinstitute.

the class GATKToolUnitTest method testDisallowLexicographicallySortedVariantHeader_ifClashWithReference.

@Test(expectedExceptions = UserException.IncompatibleSequenceDictionaries.class)
public void testDisallowLexicographicallySortedVariantHeader_ifClashWithReference() throws Exception {
    final GATKTool tool = new TestGATKToolWithFeatures();
    final CommandLineParser clp = new CommandLineArgumentParser(tool);
    final File vcfFile = new File(publicTestDir + "org/broadinstitute/hellbender/engine/lexicographically_sorted_dict.vcf");
    final String[] args = { "--mask", vcfFile.getCanonicalPath(), "--reference", hg19MiniReference };
    clp.parseArguments(System.out, args);
    // This method throws despite the lexicographically-sorted sequence dictionary in the vcf.
    //This is because the reference sequence dictionary clashes with the one from the VCF.
    tool.onStartup();
}
Also used : CommandLineArgumentParser(org.broadinstitute.barclay.argparser.CommandLineArgumentParser) CommandLineParser(org.broadinstitute.barclay.argparser.CommandLineParser) File(java.io.File) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 5 with CommandLineArgumentParser

use of org.broadinstitute.barclay.argparser.CommandLineArgumentParser in project gatk by broadinstitute.

the class FeatureInputArgumentCollectionTest method testOptionalIsOptional.

@Test
public void testOptionalIsOptional() {
    Object req = new Object() {

        @ArgumentCollection
        private OptionalFeatureInputArgumentCollection ric = new OptionalFeatureInputArgumentCollection();
    };
    CommandLineParser clp = new CommandLineArgumentParser(req);
    String[] args = {};
    clp.parseArguments(System.out, args);
}
Also used : CommandLineArgumentParser(org.broadinstitute.barclay.argparser.CommandLineArgumentParser) CommandLineParser(org.broadinstitute.barclay.argparser.CommandLineParser) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

CommandLineArgumentParser (org.broadinstitute.barclay.argparser.CommandLineArgumentParser)47 CommandLineParser (org.broadinstitute.barclay.argparser.CommandLineParser)47 Test (org.testng.annotations.Test)44 GATKReadFilterPluginDescriptor (org.broadinstitute.hellbender.cmdline.GATKPlugin.GATKReadFilterPluginDescriptor)25 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)13 File (java.io.File)11 IndexedFastaSequenceFile (htsjdk.samtools.reference.IndexedFastaSequenceFile)9 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)7 SAMFileHeader (htsjdk.samtools.SAMFileHeader)6 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)6 ArrayList (java.util.ArrayList)6 List (java.util.List)3 ArgumentsBuilder (org.broadinstitute.hellbender.utils.test.ArgumentsBuilder)3 Assert (org.testng.Assert)3 SamReader (htsjdk.samtools.SamReader)2 VariantContext (htsjdk.variant.variantcontext.VariantContext)2 VCFFileReader (htsjdk.variant.vcf.VCFFileReader)2 Iterator (java.util.Iterator)2 Argument (org.broadinstitute.barclay.argparser.Argument)2 CommandLineProgramProperties (org.broadinstitute.barclay.argparser.CommandLineProgramProperties)2