initializeBAMWriter(ret, header, presorted, createIndex);
/** * Create a BAMFileWriter that is ready to receive SAMRecords. * * @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 outputPath where to write the output. * @param compressionLevel Override default compression level with the given value, between 0 (fastest) and 9 (smallest). */ public SAMFileWriter makeBAMWriter(final SAMFileHeader header, final boolean presorted, final Path outputPath, final int compressionLevel) { try { final boolean createMd5File = this.createMd5File && IOUtil.isRegularPath(outputPath); if (this.createMd5File && !createMd5File) { log.warn("Cannot create MD5 file for BAM because output file is not a regular file: " + outputPath.toUri()); } OutputStream os = IOUtil.maybeBufferOutputStream(Files.newOutputStream(outputPath), bufferSize); if (createMd5File) os = new Md5CalculatingOutputStream(os, IOUtil.addExtension(outputPath,".md5")); final BAMFileWriter ret = new BAMFileWriter(os, outputPath.toUri().toString(), compressionLevel, deflaterFactory); final boolean createIndex = this.createIndex && IOUtil.isRegularPath(outputPath); if (this.createIndex && !createIndex) { log.warn("Cannot create index for BAM because output file is not a regular file: " + outputPath.toUri()); } initializeBAMWriter(ret, header, presorted, createIndex); if (this.useAsyncIo) return new AsyncSAMFileWriter(ret, this.asyncOutputBufferSize); else return ret; } catch (final IOException ioe) { throw new RuntimeIOException("Error opening file: " + outputPath.toUri(), ioe); } }
/** * Create a BAMFileWriter that is ready to receive SAMRecords. * * @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 outputPath where to write the output. * @param compressionLevel Override default compression level with the given value, between 0 (fastest) and 9 (smallest). */ public SAMFileWriter makeBAMWriter(final SAMFileHeader header, final boolean presorted, final Path outputPath, final int compressionLevel) { try { final boolean createMd5File = this.createMd5File && IOUtil.isRegularPath(outputPath); if (this.createMd5File && !createMd5File) { log.warn("Cannot create MD5 file for BAM because output file is not a regular file: " + outputPath.toUri()); } OutputStream os = IOUtil.maybeBufferOutputStream(Files.newOutputStream(outputPath), bufferSize); if (createMd5File) os = new Md5CalculatingOutputStream(os, IOUtil.addExtension(outputPath,".md5")); final BAMFileWriter ret = new BAMFileWriter(os, outputPath.toUri().toString(), compressionLevel, deflaterFactory); final boolean createIndex = this.createIndex && IOUtil.isRegularPath(outputPath); if (this.createIndex && !createIndex) { log.warn("Cannot create index for BAM because output file is not a regular file: " + outputPath.toUri()); } initializeBAMWriter(ret, header, presorted, createIndex); if (this.useAsyncIo) return new AsyncSAMFileWriter(ret, this.asyncOutputBufferSize); else return ret; } catch (final IOException ioe) { throw new RuntimeIOException("Error opening file: " + outputPath.toUri(), ioe); } }