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();
}
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();
}
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);
}
Aggregations