use of htsjdk.samtools.SamReader in project gatk by broadinstitute.
the class WalkerOutputIntegrationTest method testPGOnByDefault.
@Test
public void testPGOnByDefault() throws IOException {
final File inFile = new File(TEST_DATA_DIR, "testPGOnByDefault.bam");
final File outFile = BaseTest.createTempFile("testNoConflictRG", ".bam");
final String[] args = new String[] { //NOTE: no addOutputSAMProgramRecord argument
"--input", inFile.getAbsolutePath(), "--output", outFile.getAbsolutePath() };
runCommandLine(args);
try (final SamReader reader1 = SamReaderFactory.makeDefault().open(inFile)) {
Assert.assertNotNull(reader1.getFileHeader().getProgramRecord("GATK PrintReads"));
}
try (final SamReader reader2 = SamReaderFactory.makeDefault().open(inFile)) {
Assert.assertNull(reader2.getFileHeader().getProgramRecord("GATK PrintReads.1"));
}
//output has both GATK PrintReads and GATK PrintReads.1 in headers
try (final SamReader reader3 = SamReaderFactory.makeDefault().open(outFile)) {
Assert.assertNotNull(reader3.getFileHeader().getProgramRecord("GATK PrintReads"));
}
try (final SamReader reader4 = SamReaderFactory.makeDefault().open(outFile)) {
Assert.assertNotNull(reader4.getFileHeader().getProgramRecord("GATK PrintReads.1"));
}
}
use of htsjdk.samtools.SamReader in project gatk by broadinstitute.
the class FilterReadsIntegrationTest method validateSortOrder.
private boolean validateSortOrder(final String resultFileName, final String referenceFileName, final String sortOrderName) throws IOException {
final File path = new File(resultFileName);
IOUtil.assertFileIsReadable(path);
final File refFile = null == referenceFileName ? null : new File(TEST_DATA_DIR, referenceFileName);
try (final SamReader in = SamReaderFactory.makeDefault().referenceSequence(refFile).open(path)) {
final SAMFileHeader header = in.getFileHeader();
final SAMFileHeader.SortOrder hdrOrder = header.getSortOrder();
switch(sortOrderName) {
case "coordinate":
{
return hdrOrder == SAMFileHeader.SortOrder.coordinate;
}
case "queryname":
{
return hdrOrder == SAMFileHeader.SortOrder.queryname;
}
case "unsorted":
default:
// don't care what it is
return true;
}
}
}
use of htsjdk.samtools.SamReader in project gatk by broadinstitute.
the class NioBam method getReads.
/** Parses the BAM file into SAMRecords. Will be distributed onto at least 'numPartitions' partitions. **/
public JavaRDD<SAMRecord> getReads(JavaSparkContext ctx, int numPartitions) {
try {
Path bamPath = IOUtils.getPath(bam);
ChannelAsSeekableStream bamOverNIO = new ChannelAsSeekableStream(Files.newByteChannel(bamPath), bamPath.toString());
final byte[] index = getIndex();
SeekableStream indexInMemory = new ByteArraySeekableStream(index);
SamReader bam3 = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.LENIENT).enable(SamReaderFactory.Option.CACHE_FILE_BASED_INDEXES).open(SamInputResource.of(bamOverNIO).index(indexInMemory));
List<QueryInterval> chunks = getAllChunksBalanced(bam3, numPartitions);
// Ideally we'd get exactly the number of chunks the user is asking for, but until then...
logger.debug("We got: " + chunks.size() + " chunks.");
return ctx.parallelize(chunks, chunks.size()).flatMap(qi -> new ReadsIterable(bam, index, qi).iterator());
} catch (IOException e) {
throw new GATKException("I/O error loading reads", e);
}
}
use of htsjdk.samtools.SamReader in project gatk by broadinstitute.
the class GetBayesianHetCoverageIntegrationTest method initHeaders.
@BeforeClass
public void initHeaders() throws IOException {
try (final SamReader normalBamReader = SamReaderFactory.makeDefault().open(NORMAL_BAM_FILE);
final SamReader tumorBamReader = SamReaderFactory.makeDefault().open(TUMOR_BAM_FILE)) {
normalHeader = normalBamReader.getFileHeader();
tumorHeader = tumorBamReader.getFileHeader();
}
}
use of htsjdk.samtools.SamReader in project gatk by broadinstitute.
the class RevertBaseQualityScoresIntegrationTest method hasOriginalQualScores.
private static boolean hasOriginalQualScores(final File bam) throws IOException {
try (final SamReader reader = SamReaderFactory.makeDefault().open(bam)) {
for (SAMRecord read : reader) {
final byte[] originalBaseQualities = read.getOriginalBaseQualities();
Assert.assertNotNull(originalBaseQualities);
final byte[] baseQualities = read.getBaseQualities();
Assert.assertEquals(originalBaseQualities.length, baseQualities.length);
for (int i = 0; i < originalBaseQualities.length; ++i) {
if (originalBaseQualities[i] != baseQualities[i]) {
return false;
}
}
}
}
return true;
}
Aggregations