Search in sources :

Example 6 with SamReaderFactory

use of htsjdk.samtools.SamReaderFactory in project gatk by broadinstitute.

the class CompareSAMs method doWork.

@Override
protected Object doWork() {
    IOUtil.assertFileIsReadable(samFiles.get(0));
    IOUtil.assertFileIsReadable(samFiles.get(1));
    SamReaderFactory factory = SamReaderFactory.makeDefault().validationStringency(VALIDATION_STRINGENCY);
    SamReader sam1 = factory.referenceSequence(REFERENCE_SEQUENCE).open(samFiles.get(0));
    SamReader sam2 = factory.referenceSequence(REFERENCE_SEQUENCE).open(samFiles.get(1));
    SamComparison comparison = new SamComparison(sam1, sam2);
    comparison.printReport();
    if (comparison.areEqual()) {
        System.out.println("Files match.");
    } else {
        System.out.println("Files differ.");
    }
    CloserUtil.close(sam1);
    CloserUtil.close(sam2);
    return comparison.areEqual();
}
Also used : SamReader(htsjdk.samtools.SamReader) SamReaderFactory(htsjdk.samtools.SamReaderFactory) SamComparison(org.broadinstitute.hellbender.utils.read.SamComparison)

Example 7 with SamReaderFactory

use of htsjdk.samtools.SamReaderFactory in project gatk by broadinstitute.

the class GATKToolUnitTest method testReadsHeader.

@Test
public void testReadsHeader() throws Exception {
    final GATKTool tool = new TestGATKToolWithReads();
    final CommandLineParser clp = new CommandLineArgumentParser(tool);
    final File bamFile = new File(publicTestDir + "org/broadinstitute/hellbender/engine/reads_data_source_test1.bam");
    final String[] args = { "-I", bamFile.getCanonicalPath() };
    clp.parseArguments(System.out, args);
    tool.onStartup();
    final SAMFileHeader headerForReads = tool.getHeaderForReads();
    final SamReaderFactory factory = //read the file directly and compare headers
    SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT);
    try (SamReader samReader = factory.open(bamFile)) {
        final SAMFileHeader samFileHeader = samReader.getFileHeader();
        Assert.assertEquals(headerForReads, samFileHeader);
    }
    tool.doWork();
    tool.onShutdown();
}
Also used : SamReader(htsjdk.samtools.SamReader) CommandLineArgumentParser(org.broadinstitute.barclay.argparser.CommandLineArgumentParser) SamReaderFactory(htsjdk.samtools.SamReaderFactory) CommandLineParser(org.broadinstitute.barclay.argparser.CommandLineParser) SAMFileHeader(htsjdk.samtools.SAMFileHeader) File(java.io.File) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 8 with SamReaderFactory

use of htsjdk.samtools.SamReaderFactory in project gatk by broadinstitute.

the class PrintReadsSparkIntegrationTest method testReadFilters.

@Test(dataProvider = "readFilterTestData", groups = "spark")
public void testReadFilters(final String input, final String reference, final String extOut, final List<String> inputArgs, final int expectedCount) throws IOException {
    final File outFile = createTempFile("testReadFilter", extOut);
    final ArgumentsBuilder args = new ArgumentsBuilder();
    args.add("-I");
    args.add(new File(TEST_DATA_DIR, input).getAbsolutePath());
    args.add("-O");
    args.add(outFile.getAbsolutePath());
    if (reference != null) {
        args.add("-R");
        args.add(new File(TEST_DATA_DIR, reference).getAbsolutePath());
    }
    for (final String filter : inputArgs) {
        args.add(filter);
    }
    runCommandLine(args);
    SamReaderFactory factory = SamReaderFactory.makeDefault();
    if (reference != null) {
        factory = factory.referenceSequence(new File(TEST_DATA_DIR, reference));
    }
    int count = 0;
    try (final SamReader reader = factory.open(outFile)) {
        Iterator<SAMRecord> it = reader.iterator();
        while (it.hasNext()) {
            SAMRecord rec = it.next();
            count++;
        }
    }
    Assert.assertEquals(count, expectedCount);
}
Also used : SamReader(htsjdk.samtools.SamReader) SamReaderFactory(htsjdk.samtools.SamReaderFactory) SAMRecord(htsjdk.samtools.SAMRecord) ArgumentsBuilder(org.broadinstitute.hellbender.utils.test.ArgumentsBuilder) File(java.io.File) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Aggregations

SamReaderFactory (htsjdk.samtools.SamReaderFactory)8 SamReader (htsjdk.samtools.SamReader)7 SAMRecord (htsjdk.samtools.SAMRecord)4 File (java.io.File)4 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)3 Test (org.testng.annotations.Test)3 CommandLineProgramTest (org.broadinstitute.hellbender.CommandLineProgramTest)2 UserException (org.broadinstitute.hellbender.exceptions.UserException)2 ArgumentsBuilder (org.broadinstitute.hellbender.utils.test.ArgumentsBuilder)2 SAMFileHeader (htsjdk.samtools.SAMFileHeader)1 SecondaryOrSupplementarySkippingIterator (htsjdk.samtools.SecondaryOrSupplementarySkippingIterator)1 IndexedFastaSequenceFile (htsjdk.samtools.reference.IndexedFastaSequenceFile)1 CommandLineArgumentParser (org.broadinstitute.barclay.argparser.CommandLineArgumentParser)1 CommandLineParser (org.broadinstitute.barclay.argparser.CommandLineParser)1 ProgressMeter (org.broadinstitute.hellbender.engine.ProgressMeter)1 SamComparison (org.broadinstitute.hellbender.utils.read.SamComparison)1