Class FastaReferenceWriterBuilder
- java.lang.Object
-
- htsjdk.samtools.reference.FastaReferenceWriterBuilder
-
public class FastaReferenceWriterBuilder extends Object
Buider for aFastaReferenceWriter
You can set each of the four outputs (fasta, dictionary and index, both gzi and fai) to a file or a stream. by default if you provide a file to the fasta an accompanying set of indexes and dictionary will be created. This behaviour can be controlled by
setMakeDictOutput(boolean)
andsetMakeFaiOutput(boolean)
andsetMakeGziOutput(boolean)
The default bases-per-line is 60.
Setting a file or an output stream for any of the four outputs (fasta, fai, gzi or dict) will invalidate the other output type (i.e. setting a file output will invalidate a previous stream and vice-versa).
-
-
Constructor Summary
Constructors Constructor Description FastaReferenceWriterBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description FastaReferenceWriter
build()
Create theFastaReferenceWriter
.protected static int
checkBasesPerLine(int value)
boolean
getEmitMd5()
FastaReferenceWriterBuilder
setBasesPerLine(int basesPerLine)
Sets the number of bases each line of the fasta file will have.FastaReferenceWriterBuilder
setDictFile(Path dictFile)
Set the output dictionary file to write to.FastaReferenceWriterBuilder
setDictOutput(OutputStream dictOutput)
Set the output stream for writing the dictionary.FastaReferenceWriterBuilder
setEmitMd5(boolean emitMd5)
FastaReferenceWriterBuilder
setFastaFile(Path fastaFile)
Set the output fasta file to write to.FastaReferenceWriterBuilder
setFastaOutput(OutputStream fastaOutput)
Set the output stream for writing the reference.FastaReferenceWriterBuilder
setGziIndexFile(Path gziIndexFile)
Set the output gzi index file to write to.FastaReferenceWriterBuilder
setGziIndexOutput(OutputStream gziIndexOutput)
Set the output stream for writing the index.FastaReferenceWriterBuilder
setIndexFile(Path faiIndexFile)
Set the output fai index file to write to.FastaReferenceWriterBuilder
setIndexOutput(OutputStream faiIndexOutput)
Set the output stream for writing the index.FastaReferenceWriterBuilder
setMakeDictOutput(boolean makeDictOutput)
Sets whether to automatically generate an dictionary file from the name of the fasta-file (assuming it is given as a file).FastaReferenceWriterBuilder
setMakeFaiOutput(boolean makeFaiOutput)
Sets whether to automatically generate an index file from the name of the fasta-file (assuming it is given as a file).FastaReferenceWriterBuilder
setMakeGziOutput(boolean makeGziOutput)
Sets whether to automatically generate a gzi index file using an index file name derived from the name of the fasta-file (assuming the fasta file is a valid bgzipped file).
-
-
-
Method Detail
-
checkBasesPerLine
protected static int checkBasesPerLine(int value)
-
setFastaFile
public FastaReferenceWriterBuilder setFastaFile(Path fastaFile)
Set the output fasta file to write to. Will automatically write a blockCompressed output for files ending with ".gz" extension. If the index file and output stream are both null and makeFaiOutput is true (default), a default index file will be created as well. If the gzi index file and output stream are both null and makeGziOutput is true (default), a default gzi index file will be created if the output is block compressed. If the dictionary file and output stream are both null and makeDictOutput is true (default), a default dictionary file will be created as well. You can only provide a compressed stream to the fastaOutput, and only in the case that an index isn't written.- Parameters:
fastaFile
- aPath
to the output fasta file.- Returns:
- this builder
-
setMakeFaiOutput
public FastaReferenceWriterBuilder setMakeFaiOutput(boolean makeFaiOutput)
Sets whether to automatically generate an index file from the name of the fasta-file (assuming it is given as a file). This can only happen if both the index file and output stream have not been provided.- Parameters:
makeFaiOutput
- a boolean flag- Returns:
- this builder
-
setMakeDictOutput
public FastaReferenceWriterBuilder setMakeDictOutput(boolean makeDictOutput)
Sets whether to automatically generate an dictionary file from the name of the fasta-file (assuming it is given as a file). This can only happen if both the dictionary file and output stream have not been provided.- Parameters:
makeDictOutput
- a boolean flag- Returns:
- this builder
-
setMakeGziOutput
public FastaReferenceWriterBuilder setMakeGziOutput(boolean makeGziOutput)
Sets whether to automatically generate a gzi index file using an index file name derived from the name of the fasta-file (assuming the fasta file is a valid bgzipped file). This can only happen if neither an index file nor an index output stream are provided.- Parameters:
makeGziOutput
- a boolean flag- Returns:
- this builder
-
setBasesPerLine
public FastaReferenceWriterBuilder setBasesPerLine(int basesPerLine)
Sets the number of bases each line of the fasta file will have. the default is 60- Parameters:
basesPerLine
- integer (must be positive, validated onbuild()
) indicating the number of bases per line in the output- Returns:
- this builder
-
setIndexFile
public FastaReferenceWriterBuilder setIndexFile(Path faiIndexFile)
Set the output fai index file to write to.
-
setGziIndexFile
public FastaReferenceWriterBuilder setGziIndexFile(Path gziIndexFile)
Set the output gzi index file to write to.
-
setDictFile
public FastaReferenceWriterBuilder setDictFile(Path dictFile)
Set the output dictionary file to write to.
-
setFastaOutput
public FastaReferenceWriterBuilder setFastaOutput(OutputStream fastaOutput)
Set the output stream for writing the reference. Doesn't support compressed streams.NOTE: If you would like to output a BlockCompressed fasta file it is recommended you use
setFastaFile(Path)
as that codepath will handle generation of a gzi index automatically.- Parameters:
fastaOutput
- aOutputStream
for the output fasta file.- Returns:
- this builder
-
setIndexOutput
public FastaReferenceWriterBuilder setIndexOutput(OutputStream faiIndexOutput)
Set the output stream for writing the index.- Parameters:
faiIndexOutput
- aOutputStream
for the output index. Doesn't support compressed streams.- Returns:
- this builder
-
setGziIndexOutput
public FastaReferenceWriterBuilder setGziIndexOutput(OutputStream gziIndexOutput)
Set the output stream for writing the index.- Parameters:
gziIndexOutput
- aOutputStream
for the gzi output index. Doesn't support compressed streams.- Returns:
- this builder
-
setDictOutput
public FastaReferenceWriterBuilder setDictOutput(OutputStream dictOutput)
Set the output stream for writing the dictionary.- Parameters:
dictOutput
- aOutputStream
for the output dictionary. Doesn't support compressed streams.- Returns:
- this builder
-
build
public FastaReferenceWriter build() throws IOException
Create theFastaReferenceWriter
. This is were all the validations happen:- -One of fastaFile and fastaOutput must be non-null.
- -the number of bases-per-line must be positive
- Returns:
- a
FastaReferenceWriter
- Throws:
IOException
- if trouble opening files
-
getEmitMd5
public boolean getEmitMd5()
- Returns:
- whether the reference builder will emit M5 tag in the header lines
-
setEmitMd5
public FastaReferenceWriterBuilder setEmitMd5(boolean emitMd5)
- Parameters:
emitMd5
- whether the reference builder will emit the M5 tag in the header line * (and populate it with the md5 digest of the sequence)- Returns:
- this builder
-
-