Creates new BAM writer outputting to file or stream. Automatically writes BAM magic number (4 bytes).
By default, the writer attempts to automatically create index when writing coordinate-sorted files. If this behaviour is not desired, it can be switched off before writing SAM header.
Flushes buffer and closes output stream. Adds BAM EOF block automatically.
Flushes current BGZF block.
Can be called right after the stream constructor, only once
Writes BAM read. Throws exception if read reference ID is out of range.
Writes reference sequence information. Should be called after dumping SAM header. Writer will store this array to use later for resolving read reference IDs to names.
Writes SAM header. Should be called after construction.
import bio.std.hts.bam.writer, bio.std.hts.bam.reader; ... auto src = new BamReader("in.bam"); auto dst = new BamWriter("out.bam", 9); // maximal compression scope (exit) dst.finish(); // close the stream at exit dst.writeSamHeader(src.header); // copy header and reference sequence info dst.writeReferenceSequenceInfo(src.reference_sequences); foreach (read; src.reads) { if (read.mapping_quality > 10) // skip low-quality reads dst.writeRecord(read); }
Class for outputting BAM.
Compresses BGZF blocks in parallel. Tries to write reads so that they don't cross BGZF block borders.
Usage is very simple, see example below.