BGZFile

Encapsulates a bgzipped (block gzipped) file. Implements InputRange interface using htslib calls to bgzf_getline().

Constructors

this
this(string fn)

Open filename fn for reading

Members

Functions

byLine
auto byLine()

Returns a foward range of each line the internal buffer is reused so you must copy if you want it to stick around

byLineCopy
auto byLineCopy()

Returns a foward range of each line same as above but we copy for you

Examples

import std.stdio;
import htslib.hts_log;
import std.algorithm : map;
import std.array : array;
import std.path : buildPath,dirName;
import std.range : drop;
hts_set_log_level(htsLogLevel.HTS_LOG_INFO);
hts_log_info(__FUNCTION__, "Testing BGZFile");
hts_log_info(__FUNCTION__, "Loading test file");

auto bg = BGZFile(buildPath(dirName(dirName(dirName(__FILE__))),"htslib","test","fastqs.fq"));
auto f = File(buildPath(dirName(dirName(dirName(__FILE__))),"htslib","test","fastqs.fq"));
assert(f.byLineCopy.array.length == 500);
assert(bg.byLineCopy.array.length == 500);
assert(bg.byLineCopy.array.length == 500);
assert(bg.byLine.array.length == 500);


auto range = bg.byLineCopy;
auto range1 = range.save;
range = range.drop(200);
auto range2 = range.save;
range = range.drop(200);
auto range3 = range.save;

assert(range1.array.length == 500);
assert(range2.array.length == 300);
assert(range3.array.length == 100);

auto range4 = bg.byLine;
auto range5 = range4.save;
range4 = range4.drop(200);
auto range6 = range4.save;
range4 = range4.drop(200);
auto range7 = range4.save;

assert(range5.array.length == 500);
assert(range6.array.length == 300);
assert(range7.array.length == 100);
// assert(bg.array == ["122333444455555"]);

Meta