Search in sources :

Example 11 with GATKReadFilterPluginDescriptor

use of org.broadinstitute.hellbender.cmdline.GATKPlugin.GATKReadFilterPluginDescriptor in project gatk by broadinstitute.

the class ReadFilterPluginUnitTest method testDisableToolDefaultFilters.

@Test(dataProvider = "disableToolDefaulFiltersArguments")
public void testDisableToolDefaultFilters(final String[] args, final List<ReadFilter> defaultFilters, final ReadFilter expectedFilter) {
    CommandLineParser clp = new CommandLineArgumentParser(new Object(), Collections.singletonList(new GATKReadFilterPluginDescriptor(defaultFilters)));
    clp.parseArguments(nullMessageStream, args);
    GATKReadFilterPluginDescriptor readFilterPlugin = clp.getPluginDescriptor(GATKReadFilterPluginDescriptor.class);
    Assert.assertTrue(readFilterPlugin.userArgs.getDisableToolDefaultReadFilters());
    // no instances because no readFilter was provided
    List<ReadFilter> readFilters = readFilterPlugin.getAllInstances();
    Assert.assertEquals(readFilters.size(), (expectedFilter == null) ? 0 : 1);
    // all the default filters returns true for isDisabledFilter if it is not the expected
    defaultFilters.stream().map(df -> df.getClass().getSimpleName()).filter(df -> expectedFilter == null || expectedFilter.getClass().getSimpleName().equals(df)).forEach(df -> Assert.assertTrue(readFilterPlugin.isDisabledFilter(df.getClass().getSimpleName())));
    ReadFilter rf = instantiateFilter(clp, createHeaderWithReadGroups());
    Assert.assertEquals(rf.getClass().getSimpleName(), (expectedFilter == null) ? ReadFilterLibrary.ALLOW_ALL_READS.getClass().getSimpleName() : expectedFilter.getClass().getSimpleName());
}
Also used : TextCigarCodec(htsjdk.samtools.TextCigarCodec) PrintStream(java.io.PrintStream) Cigar(htsjdk.samtools.Cigar) Arrays(java.util.Arrays) DataProvider(org.testng.annotations.DataProvider) CommandLineArgumentParser(org.broadinstitute.barclay.argparser.CommandLineArgumentParser) CommandLineParser(org.broadinstitute.barclay.argparser.CommandLineParser) GATKReadFilterPluginDescriptor(org.broadinstitute.hellbender.cmdline.GATKPlugin.GATKReadFilterPluginDescriptor) Test(org.testng.annotations.Test) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) ArtificialReadUtils(org.broadinstitute.hellbender.utils.read.ArtificialReadUtils) Assert(org.testng.Assert) NullOutputStream(org.apache.commons.io.output.NullOutputStream) Collections(java.util.Collections) CommandLineException(org.broadinstitute.barclay.argparser.CommandLineException) 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 12 with GATKReadFilterPluginDescriptor

use of org.broadinstitute.hellbender.cmdline.GATKPlugin.GATKReadFilterPluginDescriptor in project gatk by broadinstitute.

the class ReadFilterPluginUnitTest method testEnableNonExistentFilter.

@Test(expectedExceptions = CommandLineException.class)
public void testEnableNonExistentFilter() {
    CommandLineParser clp = new CommandLineArgumentParser(new Object(), Collections.singletonList(new GATKReadFilterPluginDescriptor(null)));
    clp.parseArguments(nullMessageStream, new String[] { "--RF", "fakeFilter" });
}
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 13 with GATKReadFilterPluginDescriptor

use of org.broadinstitute.hellbender.cmdline.GATKPlugin.GATKReadFilterPluginDescriptor in project gatk by broadinstitute.

the class ReadFilterPluginUnitTest method testDisableDefaultsAndReenableWithDifferentArgs.

@Test
public void testDisableDefaultsAndReenableWithDifferentArgs() {
    GATKReadFilterPluginDescriptor rfDesc = new GATKReadFilterPluginDescriptor(Collections.singletonList(new ReadLengthReadFilter(1, 10)));
    CommandLineParser clp = new CommandLineArgumentParser(new Object(), Collections.singletonList(rfDesc));
    clp.parseArguments(nullMessageStream, new String[] { "--disableToolDefaultReadFilters", "--readFilter", ReadLengthReadFilter.class.getSimpleName(), "--maxReadLength", "13" });
    List<ReadFilter> allFilters = rfDesc.getAllInstances();
    ReadLengthReadFilter rf = (ReadLengthReadFilter) allFilters.get(0);
    Assert.assertEquals(rf.maxReadLength.intValue(), 13);
}
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 14 with GATKReadFilterPluginDescriptor

use of org.broadinstitute.hellbender.cmdline.GATKPlugin.GATKReadFilterPluginDescriptor in project gatk by broadinstitute.

the class ReadFilterPluginUnitTest method testPreserveToolDefaultFilterOrder.

@Test
public void testPreserveToolDefaultFilterOrder() {
    List<ReadFilter> orderedDefaults = new ArrayList<>();
    orderedDefaults.add(new WellformedReadFilter());
    orderedDefaults.add(ReadFilterLibrary.MAPPED);
    orderedDefaults.add(ReadFilterLibrary.HAS_READ_GROUP);
    orderedDefaults.add(ReadFilterLibrary.MAPPING_QUALITY_NOT_ZERO);
    orderedDefaults.add(ReadFilterLibrary.PAIRED);
    orderedDefaults.add(ReadFilterLibrary.NONZERO_FRAGMENT_LENGTH_READ_FILTER);
    orderedDefaults.add(ReadFilterLibrary.FIRST_OF_PAIR);
    orderedDefaults.add(ReadFilterLibrary.PROPERLY_PAIRED);
    orderedDefaults.add(ReadFilterLibrary.NOT_DUPLICATE);
    orderedDefaults.add(ReadFilterLibrary.NOT_SECONDARY_ALIGNMENT);
    orderedDefaults.add(ReadFilterLibrary.NOT_SUPPLEMENTARY_ALIGNMENT);
    CommandLineParser clp = new CommandLineArgumentParser(new Object(), Collections.singletonList(new GATKReadFilterPluginDescriptor(orderedDefaults)));
    clp.parseArguments(nullMessageStream, new String[] { //disable one just to mix things up
    "-disableReadFilter", ReadFilterLibrary.MAPPED.getClass().getSimpleName(), "-readFilter", ReadFilterLibrary.HAS_MATCHING_BASES_AND_QUALS.getClass().getSimpleName(), "-readFilter", 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 reach inside the filter and navigate 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.PAIRED.getClass().getSimpleName(), ReadFilterLibrary.NONZERO_FRAGMENT_LENGTH_READ_FILTER.getClass().getSimpleName(), ReadFilterLibrary.FIRST_OF_PAIR.getClass().getSimpleName(), ReadFilterLibrary.PROPERLY_PAIRED.getClass().getSimpleName(), ReadFilterLibrary.NOT_DUPLICATE.getClass().getSimpleName(), ReadFilterLibrary.NOT_SECONDARY_ALIGNMENT.getClass().getSimpleName(), ReadFilterLibrary.NOT_SUPPLEMENTARY_ALIGNMENT.getClass().getSimpleName(), ReadFilterLibrary.HAS_MATCHING_BASES_AND_QUALS.getClass().getSimpleName(), ReadFilterLibrary.GOOD_CIGAR.getClass().getSimpleName() };
    int count = ReadFilterUnitTest.verifyAndFilterOrder(rf, expectedOrder);
    Assert.assertEquals(count, 12);
}
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 15 with GATKReadFilterPluginDescriptor

use of org.broadinstitute.hellbender.cmdline.GATKPlugin.GATKReadFilterPluginDescriptor in project gatk by broadinstitute.

the class ReadFilterPluginUnitTest method testDisableOneFilter.

@Test
public void testDisableOneFilter() {
    CommandLineParser clp = new CommandLineArgumentParser(new Object(), Collections.singletonList(new GATKReadFilterPluginDescriptor(Collections.singletonList(ReadFilterLibrary.GOOD_CIGAR))));
    clp.parseArguments(nullMessageStream, new String[] { "--RF", ReadFilterLibrary.MAPPED.getClass().getSimpleName(), "--RF", ReadFilterLibrary.HAS_MATCHING_BASES_AND_QUALS.getClass().getSimpleName(), "-disableReadFilter", ReadFilterLibrary.GOOD_CIGAR.getClass().getSimpleName() });
    // get the command line read filters
    GATKReadFilterPluginDescriptor readFilterPlugin = clp.getPluginDescriptor(GATKReadFilterPluginDescriptor.class);
    List<ReadFilter> readFilters = readFilterPlugin.getAllInstances();
    Assert.assertEquals(readFilters.size(), 2);
    Assert.assertEquals(readFilters.get(0).getClass().getSimpleName(), ReadFilterLibrary.MAPPED.getClass().getSimpleName());
    Assert.assertEquals(readFilters.get(1).getClass().getSimpleName(), ReadFilterLibrary.HAS_MATCHING_BASES_AND_QUALS.getClass().getSimpleName());
    Assert.assertEquals(readFilterPlugin.userArgs.getUserDisabledReadFilterNames().size(), 1);
    Assert.assertTrue(readFilterPlugin.userArgs.getUserDisabledReadFilterNames().contains(ReadFilterLibrary.GOOD_CIGAR.getClass().getSimpleName()));
    Assert.assertTrue(readFilterPlugin.isDisabledFilter(ReadFilterLibrary.GOOD_CIGAR.getClass().getSimpleName()));
}
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)

Aggregations

CommandLineArgumentParser (org.broadinstitute.barclay.argparser.CommandLineArgumentParser)25 CommandLineParser (org.broadinstitute.barclay.argparser.CommandLineParser)25 GATKReadFilterPluginDescriptor (org.broadinstitute.hellbender.cmdline.GATKPlugin.GATKReadFilterPluginDescriptor)25 Test (org.testng.annotations.Test)25 SAMFileHeader (htsjdk.samtools.SAMFileHeader)5 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)5 ArrayList (java.util.ArrayList)4 Cigar (htsjdk.samtools.Cigar)1 TextCigarCodec (htsjdk.samtools.TextCigarCodec)1 PrintStream (java.io.PrintStream)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 NullOutputStream (org.apache.commons.io.output.NullOutputStream)1 CommandLineException (org.broadinstitute.barclay.argparser.CommandLineException)1 ArtificialReadUtils (org.broadinstitute.hellbender.utils.read.ArtificialReadUtils)1 Assert (org.testng.Assert)1 DataProvider (org.testng.annotations.DataProvider)1