/** * Useful test method. Creates a (temporary) indexed BAM so that we can store a sam in the testdata set. * * @param samFile the sam file to convert to bam and index * @return File a (temporary) bam file (index file is created in same path). */ public static File createIndexedBam(final File samFile, final File tempFilePrefix) throws IOException { final File output = File.createTempFile(tempFilePrefix.getAbsolutePath(), ".bam"); output.deleteOnExit(); final File indexFile = new File(output.getAbsolutePath() + ".bai"); indexFile.deleteOnExit(); final SamReader in = SamReaderFactory.makeDefault().open(samFile); SAMFileWriter out = new SAMFileWriterFactory().setCreateIndex(true).makeBAMWriter(in.getFileHeader(), true, output); in.iterator().stream().forEach(out::addAlignment); out.close(); in.close(); return output; } }
@Test(dataProvider = "testSameUnclipped5PrimeOppositeStrandData") public void testSameUnclipped5PrimeOppositeStrand(final File input) throws IOException { final AbstractMarkDuplicatesCommandLineProgramTester tester = new BySumOfBaseQAndInOriginalOrderMDTester(); try (final SamReader reader = SamReaderFactory.makeDefault().open(input)) { tester.setHeader(reader.getFileHeader()); reader.iterator().stream().forEach(tester::addRecord); } tester.setExpectedOpticalDuplicate(0); tester.runTest(); }
@Test(dataProvider = "queryGroupedInput") public void testQueryGroupedInput(final File input) throws IOException { final AbstractMarkDuplicatesCommandLineProgramTester tester = new BySumOfBaseQAndInOriginalOrderMDTester(); try(final SamReader reader = SamReaderFactory.makeDefault().open(input)) { tester.setHeader(reader.getFileHeader()); reader.iterator().stream().forEach(tester::addRecord); } tester.setExpectedOpticalDuplicate(0); tester.addArg("ASSUME_SORT_ORDER=queryname"); tester.runTest(); } }
@Test public void testCalculateNmTag() { final File TEST_DIR = new File("src/test/resources/htsjdk/samtools/SequenceUtil"); final File referenceFile = new File(TEST_DIR, "reference_with_lower_and_uppercase.fasta"); final File samFile = new File(TEST_DIR, "upper_and_lowercase_read.sam"); SamReader reader = SamReaderFactory.makeDefault().open(samFile); ReferenceSequenceFile ref = ReferenceSequenceFileFactory.getReferenceSequenceFile(referenceFile); reader.iterator().stream().forEach(r -> { Integer nm = SequenceUtil.calculateSamNmTag(r, ref.getSequence(r.getContig()).getBases()); String md = r.getStringAttribute(SAMTag.MD.name()); Assert.assertEquals(r.getIntegerAttribute(SAMTag.NM.name()), nm, "problem with NM in read \'" + r.getReadName() + "\':"); SequenceUtil.calculateMdAndNmTags(r, ref.getSequence(r.getContig()).getBases(), true, true); Assert.assertEquals(r.getIntegerAttribute(SAMTag.NM.name()), nm, "problem with NM in read \'" + r.getReadName() + "\':"); if (md != null) { Assert.assertEquals(r.getStringAttribute(SAMTag.MD.name()), md, "problem with MD in read \'" + r.getReadName() + "\':"); } }); }