Search in sources :

Example 31 with CommandLineParser

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

the class ReadFilterPluginUnitTest method testGetAllowedValuesForDescriptorArgument.

@Test(dataProvider = "defaultFiltersForAllowedValues")
public void testGetAllowedValuesForDescriptorArgument(final List<ReadFilter> defaultFilters) {
    final CommandLineParser clp = new CommandLineArgumentParser(new Object(), Collections.singletonList(new GATKReadFilterPluginDescriptor(defaultFilters)));
    clp.parseArguments(nullMessageStream, new String[] {});
    final GATKReadFilterPluginDescriptor pluginDescriptor = clp.getPluginDescriptor(GATKReadFilterPluginDescriptor.class);
    // the help for disableReadFilter should point out to the default filters in the order provided
    Assert.assertEquals(pluginDescriptor.getAllowedValuesForDescriptorArgument("disableReadFilter"), defaultFilters.stream().map(rf -> rf.getClass().getSimpleName()).collect(Collectors.toSet()));
    // test if the help for readFilter is not empty after parsing: if custom validation throws, the help should print the readFilter available
    // the complete set could not checked because that requires to discover all the implemented filters
    Assert.assertFalse(pluginDescriptor.getAllowedValuesForDescriptorArgument("readFilter").isEmpty());
}
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 32 with CommandLineParser

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

the class ReadFilterPluginUnitTest method testFilterArguments.

@Test(dataProvider = "filtersWithFilteringArguments")
public void testFilterArguments(final String filter, final Consumer<SetupTest> setup, final String argName, final String argValue) {
    final SAMFileHeader header = createHeaderWithReadGroups();
    final GATKRead read = simpleGoodRead(header);
    CommandLineParser clp = new CommandLineArgumentParser(new Object(), Collections.singletonList(new GATKReadFilterPluginDescriptor(null)));
    String[] args = { "--readFilter", filter, argName, argValue };
    clp.parseArguments(nullMessageStream, args);
    ReadFilter rf = instantiateFilter(clp, header);
    // to ensure that the filter is actually working, verify that the test record
    // we're using fails the filter test *before* we set it up to pass the filter
    Assert.assertFalse(rf.test(read));
    // setup the header and read for the test
    setup.accept(new SetupTest(header, read, argValue));
    Assert.assertTrue(rf.test(read));
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) GATKReadFilterPluginDescriptor(org.broadinstitute.hellbender.cmdline.GATKPlugin.GATKReadFilterPluginDescriptor) CommandLineArgumentParser(org.broadinstitute.barclay.argparser.CommandLineArgumentParser) CommandLineParser(org.broadinstitute.barclay.argparser.CommandLineParser) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Test(org.testng.annotations.Test)

Example 33 with CommandLineParser

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

the class ReadFilterPluginUnitTest method testNoFiltersSpecified.

@Test
public void testNoFiltersSpecified() {
    CommandLineParser clp = new CommandLineArgumentParser(new Object(), Collections.singletonList(new GATKReadFilterPluginDescriptor(null)));
    clp.parseArguments(nullMessageStream, new String[] {});
    // get the command line read filters
    final GATKReadFilterPluginDescriptor readFilterPlugin = clp.getPluginDescriptor(GATKReadFilterPluginDescriptor.class);
    final List<ReadFilter> readFilters = readFilterPlugin.getAllInstances();
    Assert.assertEquals(readFilters.size(), 0);
}
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 34 with CommandLineParser

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

the class ReadFilterPluginUnitTest method testDisableNotEnabledFilter.

@Test
public void testDisableNotEnabledFilter() {
    GATKReadFilterPluginDescriptor rfDesc = new GATKReadFilterPluginDescriptor(null);
    final CommandLineParser clp = new CommandLineArgumentParser(new Object(), Collections.singletonList(rfDesc));
    final String filterName = ReadFilterLibrary.MAPPED.getClass().getSimpleName();
    clp.parseArguments(nullMessageStream, new String[] { "-disableReadFilter", filterName });
    // Make sure mapped filter got disabled with no exception
    Assert.assertTrue(rfDesc.userArgs.getUserDisabledReadFilterNames().contains(filterName));
    Assert.assertTrue(rfDesc.isDisabledFilter(filterName));
}
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 35 with CommandLineParser

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

the class GATKToolUnitTest method testFeaturesHeader.

@Test
public void testFeaturesHeader() throws Exception {
    final TestGATKToolWithFeatures tool = new TestGATKToolWithFeatures();
    final CommandLineParser clp = new CommandLineArgumentParser(tool);
    final File vcfFile = new File(publicTestDir + "org/broadinstitute/hellbender/engine/feature_data_source_test_with_bigHeader.vcf");
    final String[] args = { "--mask", vcfFile.getCanonicalPath() };
    clp.parseArguments(System.out, args);
    tool.onStartup();
    final Object headerForFeatures = tool.getHeaderForFeatures(tool.mask);
    Assert.assertTrue(headerForFeatures instanceof VCFHeader);
    final VCFHeader vcfheaderForFeatures = (VCFHeader) headerForFeatures;
    try (final VCFFileReader vcfReader = new VCFFileReader(vcfFile, false)) {
        //read the file directly and compare headers
        final VCFHeader vcfFileHeader = vcfReader.getFileHeader();
        Assert.assertEquals(vcfheaderForFeatures.getGenotypeSamples(), vcfFileHeader.getGenotypeSamples());
        Assert.assertEquals(vcfheaderForFeatures.getInfoHeaderLines(), vcfFileHeader.getInfoHeaderLines());
        Assert.assertEquals(vcfheaderForFeatures.getFormatHeaderLines(), vcfFileHeader.getFormatHeaderLines());
        Assert.assertEquals(vcfheaderForFeatures.getFilterLines(), vcfFileHeader.getFilterLines());
        Assert.assertEquals(vcfheaderForFeatures.getContigLines(), vcfFileHeader.getContigLines());
        Assert.assertEquals(vcfheaderForFeatures.getOtherHeaderLines(), vcfFileHeader.getOtherHeaderLines());
    }
    tool.doWork();
    tool.onShutdown();
}
Also used : CommandLineArgumentParser(org.broadinstitute.barclay.argparser.CommandLineArgumentParser) VCFFileReader(htsjdk.variant.vcf.VCFFileReader) CommandLineParser(org.broadinstitute.barclay.argparser.CommandLineParser) VCFHeader(htsjdk.variant.vcf.VCFHeader) File(java.io.File) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) 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