@Test(description = "Test CRAMReader 7 reference required", expectedExceptions = IllegalArgumentException.class) public void testCRAMReader7_ReferenceRequired() throws IOException { ReferenceSource refSource = null; new CRAMFileReader(CRAM_WITH_CRAI, CRAM_WITH_CRAI, refSource, ValidationStringency.STRICT); }
@Test(description = "Test CRAMReader 1 reference required", expectedExceptions = IllegalStateException.class) public void testCRAMReader1_ReferenceRequired() { InputStream bis = null; // assumes that reference_fasta property is not set and the download service is not enabled new CRAMFileReader(CRAM_WITH_CRAI, bis); }
@Test(description = "Test CRAMReader 4 reference required", expectedExceptions = IllegalArgumentException.class) public void testCRAMReader4_ReferenceRequired() { ReferenceSource refSource = null; new CRAMFileReader(CRAM_WITH_CRAI, refSource); }
@Test(description = "Test CRAMReader 3 reference required", expectedExceptions = IllegalArgumentException.class) public void testCRAMReader3_RequiredReference() { File indexFile = null; ReferenceSource refSource = null; new CRAMFileReader(CRAM_WITH_CRAI, indexFile, refSource); }
@Test(description = "Test CRAMReader 6 reference required", expectedExceptions = IllegalArgumentException.class) public void testCRAMReader6_ReferenceRequired() throws IOException { InputStream bis = new ByteArrayInputStream(new byte[0]); File file = null; ReferenceSource refSource = null; new CRAMFileReader(bis, file, refSource, ValidationStringency.STRICT); }
@Test(description = "Test CRAMReader 5 input required", expectedExceptions = IllegalArgumentException.class) public void testCRAMReader5_InputRequired() throws IOException { InputStream bis = null; SeekableFileStream sfs = null; new CRAMFileReader(bis, sfs, createReferenceSource(), ValidationStringency.STRICT); }
@Test public void testCRAMReader7_ShouldUseCRAMIndex() throws IOException { CRAMFileReader reader = new CRAMFileReader(CRAM_WITH_CRAI, INDEX_FILE, REFERENCE, ValidationStringency.STRICT); Assert.assertTrue(reader.hasIndex(), "Can't find existing CRAM index."); }
@Test(expectedExceptions = SAMException.class) public void testCRAMReader7_WithoutCRAMIndex() throws IOException { File indexFile = null; CRAMFileReader reader = new CRAMFileReader(CRAM_WITHOUT_CRAI, indexFile, REFERENCE, ValidationStringency.STRICT); reader.getIndex(); }
@Test(expectedExceptions = SAMException.class) public void testCRAMReader4_WithoutCRAMIndex() { CRAMFileReader reader = new CRAMFileReader(CRAM_WITHOUT_CRAI, REFERENCE); reader.getIndex(); }
@Test public void testCRAMReader7_ShouldAutomaticallyFindCRAMIndex()throws IOException { File indexFile = null; CRAMFileReader reader = new CRAMFileReader(CRAM_WITH_CRAI, indexFile, REFERENCE, ValidationStringency.STRICT); Assert.assertTrue(reader.hasIndex(), "Can't find existing CRAM index."); }
@Test(description = "Test CRAMReader 2 input required", expectedExceptions = IllegalArgumentException.class) public void testCRAMReader2_InputRequired() { File file = null; InputStream bis = null; new CRAMFileReader(file, bis, createReferenceSource()); }
@Test(description = "Test CRAMReader 4 input required", expectedExceptions = IllegalArgumentException.class) public void testCRAMReader4_InputRequired() { File inputFile = null; new CRAMFileReader(inputFile, createReferenceSource()); }
@Test(expectedExceptions = SAMException.class) public void testCRAMReader2_WithoutCRAMIndex() { InputStream inputStream = null; CRAMFileReader reader = new CRAMFileReader(CRAM_WITHOUT_CRAI, inputStream, REFERENCE); reader.getIndex(); }
@Test(description = "Test CRAMReader 6 input required", expectedExceptions = IllegalArgumentException.class) public void testCRAMReader6_InputRequired() throws IOException { InputStream bis = null; File file = null; new CRAMFileReader(bis, file, createReferenceSource(), ValidationStringency.STRICT); }
private static CRAMFileReader writeAndReadFromInMemoryCram(Collection<SAMRecord> records, CRAMReferenceSource source, SAMFileHeader header) throws IOException { try(ByteArrayOutputStream baos = new ByteArrayOutputStream(); CRAMFileWriter cramFileWriter = new CRAMFileWriter(baos, source, header, "whatever")){ records.forEach(cramFileWriter::addAlignment); //force a flush before reading from the buffer cramFileWriter.close(); return new CRAMFileReader(new ByteArrayInputStream(baos.toByteArray()), (SeekableStream) null, source, ValidationStringency.SILENT); } }
@Test public void testCRAMReader3_ShouldUseCRAMIndex() { CRAMFileReader reader = new CRAMFileReader(CRAM_WITH_CRAI, INDEX_FILE, REFERENCE); reader.getIndex(); Assert.assertTrue(reader.hasIndex(), "Can't find existing CRAM index."); }
@Test public void testCRAMReader3_ShouldAutomaticallyFindCRAMIndex() { File indexFile = null; CRAMFileReader reader = new CRAMFileReader(CRAM_WITH_CRAI, indexFile, REFERENCE); reader.getIndex(); Assert.assertTrue(reader.hasIndex(), "Can't find existing CRAM index."); }
@Test(expectedExceptions = CRAMException.class) public void testExceptionWhileReadingWithWrongReference() throws IOException { final CramTestCase test = new CramTestCase(); // try reading the CRAM file with the incorrect ref source that does not upper case bases: final CRAMFileReader reader = new CRAMFileReader(new ByteArrayInputStream(test.cramData), (File) null, test.referenceSourceMixedCase, ValidationStringency.STRICT); final SAMRecordIterator iterator = reader.getIterator(); // expect an exception here due to slice MD5 mismatch: iterator.hasNext(); }
private SAMRecordIterator getCramFileIterator(ValidationStringency valStringency) { final File refFile = new File("src/test/resources/htsjdk/samtools/cram/ce.fa"); final File cramFile = new File("src/test/resources/htsjdk/samtools/cram/ce#containsInvalidRecords.3.0.cram"); final ReferenceSource source = new ReferenceSource(refFile); final CRAMFileReader cramFileReader = new CRAMFileReader(cramFile, (SeekableStream) null, source); cramFileReader.setValidationStringency(valStringency); return cramFileReader.getIterator(); } }
@Test public void test_chrM_1500_location() throws IOException { CRAMFileReader reader = new CRAMFileReader(cramFile, indexFile, source); reader.setValidationStringency(ValidationStringency.SILENT); CloseableIterator<SAMRecord> iterator = reader.queryAlignmentStart("chrM", 1500); Assert.assertTrue(iterator.hasNext()); SAMRecord record = iterator.next(); Assert.assertEquals(record.getReferenceName(), "chrM"); Assert.assertTrue(record.getAlignmentStart() >= 1500); }