private SAMFileWriter createCRAMWriter(final SAMFileWriterFactory factory, final SAMFileHeader header, final File file, final File referenceFasta) { return factory.makeCRAMWriter(header, file, referenceFasta); }
/** * Create a CRAMFileWriter on an output stream. Requires the input to be presorted to match the sort order defined * by the input header. * * Note: does not honor factory settings for CREATE_MD5, CREATE_INDEX, USE_ASYNC_IO. * * @param header entire header. Sort order is determined by the sortOrder property of this arg. * @param stream where to write the output. * @param referenceFasta reference sequence file * @return CRAMFileWriter */ public CRAMFileWriter makeCRAMWriter(final SAMFileHeader header, final OutputStream stream, final File referenceFasta) { return makeCRAMWriter(header, stream, IOUtil.toPath( referenceFasta )); }
/** * Create a CRAMFileWriter on an output file. * * Note: does not honor factory setting for USE_ASYNC_IO. * * @param header entire header. Sort order is determined by the sortOrder property of this arg. * @param presorted if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder. * @param outputFile where to write the output. Must end with .sam, .bam or .cram. * @param referenceFasta reference sequence file * @return CRAMFileWriter * */ public CRAMFileWriter makeCRAMWriter(final SAMFileHeader header, final boolean presorted, final File outputFile, final File referenceFasta) { return makeCRAMWriter(header, presorted, outputFile.toPath(), IOUtil.toPath(referenceFasta)); }
/** * Create a CRAMFileWriter on an output stream. Requires the input to be presorted to match the sort order defined * by the input header. * * Note: does not honor factory settings for CREATE_MD5, CREATE_INDEX, USE_ASYNC_IO. * * @param header entire header. Sort order is determined by the sortOrder property of this arg. * @param stream where to write the output. * @param referenceFasta reference sequence file * @return CRAMFileWriter */ public CRAMFileWriter makeCRAMWriter(final SAMFileHeader header, final OutputStream stream, final File referenceFasta) { return makeCRAMWriter(header, stream, IOUtil.toPath( referenceFasta )); }
/** * Create a CRAMFileWriter on an output file. * * Note: does not honor factory setting for USE_ASYNC_IO. * * @param header entire header. Sort order is determined by the sortOrder property of this arg. * @param presorted if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder. * @param outputFile where to write the output. Must end with .sam, .bam or .cram. * @param referenceFasta reference sequence file * @return CRAMFileWriter * */ public CRAMFileWriter makeCRAMWriter(final SAMFileHeader header, final boolean presorted, final File outputFile, final File referenceFasta) { return makeCRAMWriter(header, presorted, outputFile.toPath(), IOUtil.toPath(referenceFasta)); }
/** * Create a CRAMFileWriter on an output file. Requires input record to be presorted to match the * sort order defined by the input header. * * Note: does not honor factory settings for USE_ASYNC_IO. * * @param header entire header. Sort order is determined by the sortOrder property of this arg. * @param outputPath where to write the output. Must end with .sam, .bam or .cram. * @param referenceFasta reference sequence file * @return CRAMFileWriter * * @deprecated since 6/18, prefer {@link #makeWriter(SAMFileHeader, boolean, Path, Path)} for creating bam/cram writers * however {@link #makeCRAMWriter(SAMFileHeader, boolean, Path, Path)} is the direct replacement for this method */ @Deprecated public CRAMFileWriter makeCRAMWriter(final SAMFileHeader header, final Path outputPath, final File referenceFasta) { return makeCRAMWriter(header, true, outputPath, IOUtil.toPath( referenceFasta )); }
/** * Create a CRAMFileWriter on an output file. * * Note: does not honor factory setting for USE_ASYNC_IO. * * @param header entire header. Sort order is determined by the sortOrder property of this arg. * @param presorted if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder. * @param output where to write the output. Must end with .sam, .bam or .cram. * @param referenceFasta reference sequence file * @return CRAMFileWriter * * @deprecated since 6/18, prefer {@link #makeWriter(SAMFileHeader, boolean, Path, Path)} for creating bam/cram writers * however {@link #makeCRAMWriter(SAMFileHeader, boolean, Path, Path)} is the direct replacement for this method * */ @Deprecated public CRAMFileWriter makeCRAMWriter(final SAMFileHeader header, final boolean presorted, final Path output, final File referenceFasta) { return makeCRAMWriter(header, presorted, output, IOUtil.toPath( referenceFasta )); }
/** * Create a CRAMFileWriter on an output file. Requires input record to be presorted to match the * sort order defined by the input header. * * Note: does not honor factory settings for USE_ASYNC_IO. * * @param header entire header. Sort order is determined by the sortOrder property of this arg. * @param outputPath where to write the output. Must end with .sam, .bam or .cram. * @param referenceFasta reference sequence file * @return CRAMFileWriter * * @deprecated since 6/18, prefer {@link #makeWriter(SAMFileHeader, boolean, Path, Path)} for creating bam/cram writers * however {@link #makeCRAMWriter(SAMFileHeader, boolean, Path, Path)} is the direct replacement for this method */ @Deprecated public CRAMFileWriter makeCRAMWriter(final SAMFileHeader header, final Path outputPath, final File referenceFasta) { return makeCRAMWriter(header, true, outputPath, IOUtil.toPath( referenceFasta )); }
/** * Create a CRAMFileWriter on an output file. * * Note: does not honor factory setting for USE_ASYNC_IO. * * @param header entire header. Sort order is determined by the sortOrder property of this arg. * @param presorted if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder. * @param output where to write the output. Must end with .sam, .bam or .cram. * @param referenceFasta reference sequence file * @return CRAMFileWriter * * @deprecated since 6/18, prefer {@link #makeWriter(SAMFileHeader, boolean, Path, Path)} for creating bam/cram writers * however {@link #makeCRAMWriter(SAMFileHeader, boolean, Path, Path)} is the direct replacement for this method * */ @Deprecated public CRAMFileWriter makeCRAMWriter(final SAMFileHeader header, final boolean presorted, final Path output, final File referenceFasta) { return makeCRAMWriter(header, presorted, output, IOUtil.toPath( referenceFasta )); }
/** * * Create a SAM, BAM or CRAM writer based on examination of the outputPath extension. * * @param header header. Sort order is determined by the sortOrder property of this arg. * @param presorted if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder. * @param outputPath where to write the output. Must end with .sam, .bam or .cram. * @param referenceFasta reference sequence file * @return SAMFileWriter appropriate for the file type specified in outputPath * */ public SAMFileWriter makeWriter(final SAMFileHeader header, final boolean presorted, final Path outputPath, final Path referenceFasta) { if (null != outputPath && outputPath.toString().endsWith(SamReader.Type.CRAM_TYPE.fileExtension())) { return makeCRAMWriter(header, presorted, outputPath, referenceFasta); } else { return makeSAMOrBAMWriter(header, presorted, outputPath); } }
/** * * Create a SAM, BAM or CRAM writer based on examination of the outputPath extension. * * @param header header. Sort order is determined by the sortOrder property of this arg. * @param presorted if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder. * @param outputPath where to write the output. Must end with .sam, .bam or .cram. * @param referenceFasta reference sequence file * @return SAMFileWriter appropriate for the file type specified in outputPath * */ public SAMFileWriter makeWriter(final SAMFileHeader header, final boolean presorted, final Path outputPath, final Path referenceFasta) { if (null != outputPath && outputPath.toString().endsWith(SamReader.Type.CRAM_TYPE.fileExtension())) { return makeCRAMWriter(header, presorted, outputPath, referenceFasta); } else { return makeSAMOrBAMWriter(header, presorted, outputPath); } }
break; case CRAM: writer = writerFactory.makeCRAMWriter(reader.getFileHeader(), os, params.reference); break;
@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 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); }
break; case CRAM: w = new SAMFileWriterFactory().makeCRAMWriter(header, baos, (File) null); break; default: