Package htsjdk.samtools
Class SAMFileWriterFactory
java.lang.Object
htsjdk.samtools.SAMFileWriterFactory
- All Implemented Interfaces:
Cloneable
Create a writer for writing SAM, BAM, or CRAM files.
-
Constructor Summary
ConstructorsConstructorDescriptionsimple constructorcopy constructor -
Method Summary
Modifier and TypeMethodDescriptionclone()
int
static boolean
Gets the default for subsequent SAMFileWriterFactories that do not specify whether to create an index.static boolean
Gets the default for whether to create md5Files for BAM files this factory.int
Gets the maximum number of records held in RAM before spilling to disk during sorting.Gets the temporary directory that will be used when sorting data.makeBAMWriter
(SAMFileHeader header, boolean presorted, File outputFile) Create a BAMFileWriter that is ready to receive SAMRecords.makeBAMWriter
(SAMFileHeader header, boolean presorted, File outputFile, int compressionLevel) Create a BAMFileWriter that is ready to receive SAMRecords.makeBAMWriter
(SAMFileHeader header, boolean presorted, OutputStream stream) Create a BAMFileWriter for writing to a stream that is ready to receive SAMRecords.makeBAMWriter
(SAMFileHeader header, boolean presorted, Path outputPath) Create a BAMFileWriter that is ready to receive SAMRecords.makeBAMWriter
(SAMFileHeader header, boolean presorted, Path outputPath, int compressionLevel) Create a BAMFileWriter that is ready to receive SAMRecords.makeCRAMWriter
(SAMFileHeader header, boolean presorted, File outputFile, File referenceFasta) Create a CRAMFileWriter on an output file.makeCRAMWriter
(SAMFileHeader header, boolean presorted, Path output, File referenceFasta) Deprecated.makeCRAMWriter
(SAMFileHeader header, boolean presorted, Path output, Path referenceFasta) Create a CRAMFileWriter on an output file.makeCRAMWriter
(SAMFileHeader header, File outputFile, File referenceFasta) Create a CRAMFileWriter on an output file.makeCRAMWriter
(SAMFileHeader header, OutputStream stream, File referenceFasta) Create a CRAMFileWriter on an output stream.makeCRAMWriter
(SAMFileHeader header, OutputStream stream, Path referenceFasta) Create a CRAMFileWriter on an output stream.makeCRAMWriter
(SAMFileHeader header, Path outputPath, File referenceFasta) Deprecated.since 6/18, prefermakeWriter(SAMFileHeader, boolean, Path, Path)
for creating bam/cram writers howevermakeCRAMWriter(SAMFileHeader, boolean, Path, Path)
is the direct replacement for this methodmakeSAMOrBAMWriter
(SAMFileHeader header, boolean presorted, File outputFile) Create either a SAM or a BAM writer based on examination of the outputFile extension, defaults to BAM writer.makeSAMOrBAMWriter
(SAMFileHeader header, boolean presorted, Path outputPath) Create either a SAM or a BAM writer based on examination of the outputPath extension.makeSAMWriter
(SAMFileHeader header, boolean presorted, File outputFile) Create a SAMTextWriter that is ready to receive SAMRecords.makeSAMWriter
(SAMFileHeader header, boolean presorted, OutputStream stream) Create a SAMTextWriter for writing to a stream that is ready to receive SAMRecords.makeSAMWriter
(SAMFileHeader header, boolean presorted, Path outputPath) Create a SAMTextWriter that is ready to receive SAMRecords.makeWriter
(SAMFileHeader header, boolean presorted, File outputFile, File referenceFasta) Create a SAM, BAM or CRAM writer based on examination of the outputFile extension.makeWriter
(SAMFileHeader header, boolean presorted, Path outputPath, File referenceFasta) Deprecated.since 6/18, usemakeWriter(SAMFileHeader, boolean, Path, Path)
insteadmakeWriter
(SAMFileHeader header, boolean presorted, Path outputPath, Path referenceFasta) Create a SAM, BAM or CRAM writer based on examination of the outputPath extension.setAsyncOutputBufferSize
(int asyncOutputBufferSize) If and only if using asynchronous IO then sets the maximum number of records that can be buffered per SAMFileWriter before producers will block when trying to write another SAMRecord.setBufferSize
(int bufferSize) Controls size of write buffer.setCompressionLevel
(int compressionLevel) set compression level 0!none 9: maxsetCreateIndex
(boolean setting) Convenience method allowing newSAMFileWriterFactory().setCreateIndex(true); Equivalent to SAMFileWriterFactory.setDefaultCreateIndexWhileWriting(true); newSAMFileWriterFactory(); If a BAM or CRAM (not SAM) file is created, the setting is true, and the file header specifies coordinate order, then a BAM index file will be written along with the BAM file.setCreateMd5File
(boolean createMd5File) Sets whether to create md5Files for BAMs from this factory.static void
setDefaultCreateIndexWhileWriting
(boolean setting) Sets the default for subsequent SAMFileWriterFactories that do not specify whether to create an index.static void
setDefaultCreateMd5File
(boolean createMd5File) Sets the default for whether to create md5Files for BAM files this factory.setDeflaterFactory
(DeflaterFactory deflaterFactory) Set the deflater factory used by BAM writers created by this writer factory.setMaxRecordsInRam
(int maxRecordsInRam) Before creating a writer that is not presorted, this method may be called in order to override the default number of SAMRecords stored in RAM before spilling to disk (c.f.setSamFlagFieldOutput
(SamFlagField samFlagFieldOutput) Set the flag output format only when writing text.setTempDirectory
(File tmpDir) Set the temporary directory to use when sort data.setUseAsyncIo
(boolean useAsyncIo) Turn on or off the use of asynchronous IO for writing output SAM and BAM files.toString()
-
Constructor Details
-
SAMFileWriterFactory
public SAMFileWriterFactory()simple constructor -
SAMFileWriterFactory
copy constructor
-
-
Method Details
-
clone
-
setDefaultCreateMd5File
public static void setDefaultCreateMd5File(boolean createMd5File) Sets the default for whether to create md5Files for BAM files this factory. -
getDefaultCreateMd5File
public static boolean getDefaultCreateMd5File()Gets the default for whether to create md5Files for BAM files this factory.- See Also:
-
setCreateMd5File
Sets whether to create md5Files for BAMs from this factory. -
setDeflaterFactory
Set the deflater factory used by BAM writers created by this writer factory. Must not be null. If this method is not called, the defaultDeflaterFactory
is used which creates the default JDKDeflater
. This method returns the SAMFileWriterFactory itself. -
setCompressionLevel
set compression level 0!none 9: max -
getCompressionLevel
public int getCompressionLevel() -
setDefaultCreateIndexWhileWriting
public static void setDefaultCreateIndexWhileWriting(boolean setting) Sets the default for subsequent SAMFileWriterFactories that do not specify whether to create an index. If a BAM (not SAM) file is created, the setting is true, and the file header specifies coordinate order, then a BAM index file will be written along with the BAM file.- Parameters:
setting
- whether to attempt to create a BAM index while creating the BAM file
-
getDefaultCreateIndexWhileWriting
public static boolean getDefaultCreateIndexWhileWriting()Gets the default for subsequent SAMFileWriterFactories that do not specify whether to create an index. -
setCreateIndex
Convenience method allowing newSAMFileWriterFactory().setCreateIndex(true); Equivalent to SAMFileWriterFactory.setDefaultCreateIndexWhileWriting(true); newSAMFileWriterFactory(); If a BAM or CRAM (not SAM) file is created, the setting is true, and the file header specifies coordinate order, then a BAM index file will be written along with the BAM file.- Parameters:
setting
- whether to attempt to create a BAM index while creating the BAM file.- Returns:
- this factory object
-
setMaxRecordsInRam
Before creating a writer that is not presorted, this method may be called in order to override the default number of SAMRecords stored in RAM before spilling to disk (c.f. SAMFileWriterImpl.MAX_RECORDS_IN_RAM). When writing very large sorted SAM files, you may need call this method in order to avoid running out of file handles. The RAM available to the JVM may need to be increased in order to hold the specified number of records in RAM. This value affects the number of records stored in subsequent calls to one of the make...() methods.- Parameters:
maxRecordsInRam
- Number of records to store in RAM before spilling to temporary file when creating a sorted SAM or BAM file.
-
getMaxRecordsInRam
public int getMaxRecordsInRam()Gets the maximum number of records held in RAM before spilling to disk during sorting.- See Also:
-
setUseAsyncIo
Turn on or off the use of asynchronous IO for writing output SAM and BAM files. If true then each SAMFileWriter creates a dedicated thread which is used for compression and IO activities. -
setAsyncOutputBufferSize
If and only if using asynchronous IO then sets the maximum number of records that can be buffered per SAMFileWriter before producers will block when trying to write another SAMRecord. -
setBufferSize
Controls size of write buffer. Default value: [[htsjdk.samtools.Defaults#BUFFER_SIZE]] -
setTempDirectory
Set the temporary directory to use when sort data.- Parameters:
tmpDir
- Path to the temporary directory
-
getTempDirectory
Gets the temporary directory that will be used when sorting data.- See Also:
-
setSamFlagFieldOutput
Set the flag output format only when writing text. Default value: [[htsjdk.samtools.SAMTextWriter.samFlagFieldOutput.DECIMAL]] -
makeBAMWriter
Create a BAMFileWriter that is ready to receive SAMRecords. Uses default compression level.- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.presorted
- if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.outputFile
- where to write the output.
-
makeBAMWriter
Create a BAMFileWriter that is ready to receive SAMRecords. Uses default compression level.- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.presorted
- if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.outputPath
- where to write the output.
-
makeBAMWriter
public SAMFileWriter makeBAMWriter(SAMFileHeader header, boolean presorted, File outputFile, int compressionLevel) Create a BAMFileWriter that is ready to receive SAMRecords.- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.presorted
- if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.outputFile
- where to write the output.compressionLevel
- Override default compression level with the given value, between 0 (fastest) and 9 (smallest).
-
makeBAMWriter
public SAMFileWriter makeBAMWriter(SAMFileHeader header, boolean presorted, Path outputPath, int compressionLevel) Create a BAMFileWriter that is ready to receive SAMRecords.- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.presorted
- if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.outputPath
- where to write the output.compressionLevel
- Override default compression level with the given value, between 0 (fastest) and 9 (smallest).
-
makeSAMWriter
Create a SAMTextWriter that is ready to receive SAMRecords.- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.presorted
- if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.outputFile
- where to write the output.
-
makeSAMWriter
Create a SAMTextWriter that is ready to receive SAMRecords.- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.presorted
- if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.outputPath
- where to write the output.
-
makeSAMWriter
Create a SAMTextWriter for writing to a stream that is ready to receive SAMRecords. This method does not support the creation of an MD5 file- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.presorted
- if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.stream
- the stream to write records to. Note that this method does not buffer the stream, so the caller must buffer if desired. Note that PrintStream is buffered.
-
makeBAMWriter
Create a BAMFileWriter for writing to a stream that is ready to receive SAMRecords. This method does not support the creation of an MD5 file- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.presorted
- if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.stream
- the stream to write records to. Note that this method does not buffer the stream, so the caller must buffer if desired. Note that PrintStream is buffered.
-
makeSAMOrBAMWriter
Create either a SAM or a BAM writer based on examination of the outputFile extension, defaults to BAM writer.- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.presorted
- presorted if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.outputFile
- where to write the output. Must end with .sam or .bam.- Returns:
- SAM or BAM writer based on file extension of outputFile.
-
makeSAMOrBAMWriter
Create either a SAM or a BAM writer based on examination of the outputPath extension.- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.presorted
- presorted if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.outputPath
- where to write the output. Must end with .sam or .bam.- Returns:
- SAM or BAM writer based on file extension of outputPath.
-
makeWriter
public SAMFileWriter makeWriter(SAMFileHeader header, boolean presorted, File outputFile, File referenceFasta) Create a SAM, BAM or CRAM writer based on examination of the outputFile extension. The method assumes BAM file format for unknown file extensions.- Parameters:
header
- header. Sort order is determined by the sortOrder property of this arg.presorted
- if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.outputFile
- where to write the output. Should end with .sam, .bam or .cram.referenceFasta
- reference sequence file- Returns:
- SAMFileWriter appropriate for SAM and CRAM file types specified in outputFile, or a BAM writer for all other types
-
makeWriter
@Deprecated public SAMFileWriter makeWriter(SAMFileHeader header, boolean presorted, Path outputPath, File referenceFasta) Deprecated.since 6/18, usemakeWriter(SAMFileHeader, boolean, Path, Path)
insteadCreate a SAM, BAM or CRAM writer based on examination of the outputPath extension.- Parameters:
header
- header. Sort order is determined by the sortOrder property of this arg.presorted
- if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.outputPath
- where to write the output. Must end with .sam, .bam or .cram.referenceFasta
- reference sequence file- Returns:
- SAMFileWriter appropriate for the file type specified in outputPath
-
makeWriter
public SAMFileWriter makeWriter(SAMFileHeader header, boolean presorted, Path outputPath, Path referenceFasta) Create a SAM, BAM or CRAM writer based on examination of the outputPath extension.- Parameters:
header
- header. Sort order is determined by the sortOrder property of this arg.presorted
- if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.outputPath
- where to write the output. Must end with .sam, .bam or .cram.referenceFasta
- reference sequence file- Returns:
- SAMFileWriter appropriate for the file type specified in outputPath
-
makeCRAMWriter
public CRAMFileWriter makeCRAMWriter(SAMFileHeader header, OutputStream stream, 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.- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.stream
- where to write the output.referenceFasta
- reference sequence file- Returns:
- CRAMFileWriter
-
makeCRAMWriter
public CRAMFileWriter makeCRAMWriter(SAMFileHeader header, OutputStream stream, Path 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.- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.stream
- where to write the output.referenceFasta
- reference sequence file- Returns:
- CRAMFileWriter
-
makeCRAMWriter
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.- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.outputFile
- where to write the output. Must end with .sam, .bam or .cram.referenceFasta
- reference sequence file- Returns:
- CRAMFileWriter
-
makeCRAMWriter
@Deprecated public CRAMFileWriter makeCRAMWriter(SAMFileHeader header, Path outputPath, File referenceFasta) Deprecated.since 6/18, prefermakeWriter(SAMFileHeader, boolean, Path, Path)
for creating bam/cram writers howevermakeCRAMWriter(SAMFileHeader, boolean, Path, Path)
is the direct replacement for this methodCreate 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.- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.outputPath
- where to write the output. Must end with .sam, .bam or .cram.referenceFasta
- reference sequence file- Returns:
- CRAMFileWriter
-
makeCRAMWriter
public CRAMFileWriter makeCRAMWriter(SAMFileHeader header, boolean presorted, File outputFile, File referenceFasta) Create a CRAMFileWriter on an output file. Note: does not honor factory setting for USE_ASYNC_IO.- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.presorted
- if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.outputFile
- where to write the output. Must end with .sam, .bam or .cram.referenceFasta
- reference sequence file- Returns:
- CRAMFileWriter
-
makeCRAMWriter
@Deprecated public CRAMFileWriter makeCRAMWriter(SAMFileHeader header, boolean presorted, Path output, File referenceFasta) Deprecated.since 6/18, prefermakeWriter(SAMFileHeader, boolean, Path, Path)
for creating bam/cram writers howevermakeCRAMWriter(SAMFileHeader, boolean, Path, Path)
is the direct replacement for this methodCreate a CRAMFileWriter on an output file. Note: does not honor factory setting for USE_ASYNC_IO.- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.presorted
- if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.output
- where to write the output. Must end with .sam, .bam or .cram.referenceFasta
- reference sequence file- Returns:
- CRAMFileWriter
-
makeCRAMWriter
public CRAMFileWriter makeCRAMWriter(SAMFileHeader header, boolean presorted, Path output, Path referenceFasta) Create a CRAMFileWriter on an output file. Note: does not honor factory setting for USE_ASYNC_IO.- Parameters:
header
- entire header. Sort order is determined by the sortOrder property of this arg.presorted
- if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.output
- where to write the output. Must end with .sam, .bam or .cram.referenceFasta
- reference sequence file- Returns:
- CRAMFileWriter
-
toString
-
makeWriter(SAMFileHeader, boolean, Path, Path)
for creating bam/cram writers howevermakeCRAMWriter(SAMFileHeader, boolean, Path, Path)
is the direct replacement for this method