@Override public SamReaderFactory referenceSequence(final Path referenceSequence) { this.referenceSource = new ReferenceSource(referenceSequence); return this; }
@Override public SamReaderFactory referenceSequence(final File referenceSequence) { this.referenceSource = new ReferenceSource(referenceSequence); return this; }
@Override public SamReaderFactory referenceSequence(final File referenceSequence) { this.referenceSource = new ReferenceSource(referenceSequence); return this; }
@Override public SamReaderFactory referenceSequence(final Path referenceSequence) { this.referenceSource = new ReferenceSource(referenceSequence); return this; }
public static ReferenceSource getReferenceSource( final Configuration conf) { //TODO: There isn't anything particularly CRAM-specific about reference source or validation // stringency other than that a reference source is required for CRAM files. We should move // the reference source and validation stringency property names and utility methods out of // CRAMInputFormat and SAMHeaderReader and combine them together into a single class for extracting // configuration params, but it would break backward compatibility with existing code that // is dependent on the CRAMInputFormat.REFERENCE_SOURCE_PATH_PROPERTY. final String refSourcePath = conf.get(CRAMInputFormat.REFERENCE_SOURCE_PATH_PROPERTY); return refSourcePath == null ? null : new ReferenceSource(NIOFileUtil.asPath(refSourcePath)); } }
public static ReferenceSource getReferenceSource( final Configuration conf) { //TODO: There isn't anything particularly CRAM-specific about reference source or validation // stringency other than that a reference source is required for CRAM files. We should move // the reference source and validation stringency property names and utility methods out of // CRAMInputFormat and SAMHeaderReader and combine them together into a single class for extracting // configuration params, but it would break backward compatibility with existing code that // is dependent on the CRAMInputFormat.REFERENCE_SOURCE_PATH_PROPERTY. final String refSourcePath = conf.get(CRAMInputFormat.REFERENCE_SOURCE_PATH_PROPERTY); return refSourcePath == null ? null : new ReferenceSource(NIOFileUtil.asPath(refSourcePath)); } }
public static ReferenceSource getReferenceSource( final Configuration conf) { //TODO: There isn't anything particularly CRAM-specific about reference source or validation // stringency other than that a reference source is required for CRAM files. We should move // the reference source and validation stringency property names and utility methods out of // CRAMInputFormat and SAMHeaderReader and combine them together into a single class for extracting // configuration params, but it would break backward compatibility with existing code that // is dependent on the CRAMInputFormat.REFERENCE_SOURCE_PATH_PROPERTY. final String refSourcePath = conf.get(CRAMInputFormat.REFERENCE_SOURCE_PATH_PROPERTY); return refSourcePath == null ? null : new ReferenceSource(NIOFileUtil.asPath(refSourcePath)); } }
private CRAMFileReader getCramFileReader(String file, String fileReference) { final ReferenceSource referenceSource = new ReferenceSource(new File(fileReference)); return new CRAMFileReader(new File(file), referenceSource); }
@Test(expectedExceptions = CRAMException.class) public void testContigNotFoundInRef() throws IOException { boolean sawException = false; final File CRAMFile = new File("src/test/resources/htsjdk/samtools/cram/CRAMException/testContigNotInRef.cram"); final File refFile = new File("src/test/resources/htsjdk/samtools/cram/CRAMException/testContigNotInRef.fa"); final ReferenceSource refSource = new ReferenceSource(refFile); final CRAMIterator iterator = new CRAMIterator(new FileInputStream(CRAMFile), refSource, ValidationStringency.STRICT); while (iterator.hasNext()) { iterator.next(); } }
private static ReferenceSource createReferenceSource() { byte[] refBases = new byte[10 * 10]; Arrays.fill(refBases, (byte) 'A'); InMemoryReferenceSequenceFile rsf = new InMemoryReferenceSequenceFile(); rsf.add("chr1", refBases); return new ReferenceSource(rsf); }
private ReferenceSource createReferenceSource() { byte[] refBases = new byte[1024 * 1024]; Arrays.fill(refBases, (byte) 'A'); InMemoryReferenceSequenceFile rsf = new InMemoryReferenceSequenceFile(); rsf.add("chr1", refBases); return new ReferenceSource(rsf); }
@Test public void testNoStringencyIteratorConstructor() throws IOException { final File CRAMFile = new File("src/test/resources/htsjdk/samtools/cram/auxf#values.3.0.cram"); final File refFile = new File("src/test/resources/htsjdk/samtools/cram/auxf.fa"); ReferenceSource refSource = new ReferenceSource(refFile); long[] boundaries = new long[] {0, (CRAMFile.length() - 1) << 16}; final CRAMIterator iterator = new CRAMIterator(new SeekableFileStream(CRAMFile), refSource, boundaries); long count = getIteratorCount(iterator); Assert.assertEquals(count, 2); }
@Test public void testIteratorConstructor() throws IOException { final File CRAMFile = new File("src/test/resources/htsjdk/samtools/cram/auxf#values.3.0.cram"); final File refFile = new File("src/test/resources/htsjdk/samtools/cram/auxf.fa"); ReferenceSource refSource = new ReferenceSource(refFile); long[] boundaries = new long[] {0, (CRAMFile.length() - 1) << 16}; final CRAMIterator iterator = new CRAMIterator( new SeekableFileStream(CRAMFile), refSource, boundaries, ValidationStringency.STRICT); long count = getIteratorCount(iterator); Assert.assertEquals(count, 2); }
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(); } }
private ReferenceSource createReferenceSource() { final byte[] refBases = new byte[1024 * 1024]; Arrays.fill(refBases, (byte) 'A'); InMemoryReferenceSequenceFile rsf = new InMemoryReferenceSequenceFile(); rsf.add("chr1", refBases); rsf.add("chr2", refBases); return new ReferenceSource(rsf); }
/** * Write a collection of SAMRecords into an in memory Cram file and then open a reader over it * @param records a Collection of SAMRecords * @param ref a set of bases to use as the single reference contig named "chr1" * @return a CRAMFileReader reading from an in memory buffer that has had the records written into it */ public static CRAMFileReader writeAndReadFromInMemoryCram(Collection<SAMRecord> records, byte[] ref) throws IOException { InMemoryReferenceSequenceFile refFile = new InMemoryReferenceSequenceFile(); refFile.add("chr1", ref); ReferenceSource source = new ReferenceSource(refFile); final SAMFileHeader header = records.iterator().next().getHeader(); return writeAndReadFromInMemoryCram(records, source, header); }
@Test public void testMakeCRAMWriterIgnoresOptions() throws Exception { final File outputFile = prepareOutputFile(CramIO.CRAM_FILE_EXTENSION); final SAMFileHeader header = new SAMFileHeader(); final SAMFileWriterFactory factory = createWriterFactoryWithOptions(header); final File referenceFile = new File(TEST_DATA_DIR, "hg19mini.fasta"); int nRecs; // Note: does not honor factory settings for CREATE_MD5 or CREATE_INDEX. try (final SAMFileWriter samWriter = factory.makeCRAMWriter(header, new FileOutputStream(outputFile), referenceFile)) { nRecs = fillSmallBam(samWriter); } verifyWriterOutput(outputFile, new ReferenceSource(referenceFile), nRecs, false); }
@Test(dataProvider="bamOrCramWriter") public void testMakeWriter(String extension) throws Exception { final File outputFile = prepareOutputFile(extension); final SAMFileHeader header = new SAMFileHeader(); final SAMFileWriterFactory factory = createWriterFactoryWithOptions(header); final File referenceFile = new File(TEST_DATA_DIR, "hg19mini.fasta"); int nRecs; try (final SAMFileWriter samWriter = factory.makeWriter(header, false, outputFile, referenceFile)) { nRecs = fillSmallBam(samWriter); } verifyWriterOutput(outputFile, new ReferenceSource(referenceFile), nRecs, true); }
@Test public void testMakeCRAMWriterWithOptions() throws Exception { final File outputFile = prepareOutputFile(CramIO.CRAM_FILE_EXTENSION); final SAMFileHeader header = new SAMFileHeader(); final SAMFileWriterFactory factory = createWriterFactoryWithOptions(header); final File referenceFile = new File(TEST_DATA_DIR, "hg19mini.fasta"); int nRecs; try (final SAMFileWriter samWriter = factory.makeCRAMWriter(header, false, outputFile, referenceFile)) { nRecs = fillSmallBam(samWriter); } verifyWriterOutput(outputFile, new ReferenceSource(referenceFile), nRecs, true); }
@Test public void testMakeCRAMWriterPresortedDefault() throws Exception { final File outputFile = prepareOutputFile(CramIO.CRAM_FILE_EXTENSION); final SAMFileHeader header = new SAMFileHeader(); final SAMFileWriterFactory factory = createWriterFactoryWithOptions(header); final File referenceFile = new File(TEST_DATA_DIR, "hg19mini.fasta"); int nRecs; // Defaults to preSorted==true try (final SAMFileWriter samWriter = factory.makeCRAMWriter(header, outputFile, referenceFile)) { nRecs = fillSmallBam(samWriter); } verifyWriterOutput(outputFile, new ReferenceSource(referenceFile), nRecs, true); }