1 module dhtslib.bed.writer; 2 3 import dhtslib.bed.record; 4 import dhtslib.recordwriter; 5 6 /// Record writer for BedRecords 7 alias BedWriter = RecordWriter!BedRecord; 8 9 10 debug(dhtslib_unittest) unittest 11 { 12 import std.stdio; 13 import htslib.hts_log; 14 import std.range : take; 15 import std.algorithm : map; 16 import std.array : array; 17 import std.path : buildPath, dirName; 18 import dhtslib.bed.reader; 19 import dhtslib.coordinates; 20 hts_set_log_level(htsLogLevel.HTS_LOG_INFO); 21 hts_log_info(__FUNCTION__, "Testing GFF3Reader"); 22 hts_log_info(__FUNCTION__, "Loading test file"); 23 24 auto bedr = BedReader(buildPath(dirName(dirName(dirName(dirName(__FILE__)))),"htslib","test","tabix","bed_file.bed")); 25 auto bedw = BedWriter("/tmp/test.bed", bedr.header); 26 auto rec = bedr.front; 27 bedw.write(rec); 28 bedr.popFront; 29 auto moreRecs = bedr.take(3); 30 bedw.writeRecords(moreRecs); 31 destroy(bedw); 32 33 bedr = BedReader("/tmp/test.bed"); 34 rec = bedr.front; 35 assert(rec.contig == "X"); 36 assert(rec.coordinates == ZBHO(1000, 1100)); 37 assert(rec.name == "X1"); 38 assert(rec.score == 500); 39 assert(rec.strand == '+'); 40 assert(rec.thickStart == 1000); 41 assert(rec.thickEnd == 1100); 42 assert(rec.itemRGB == RGB(255,0,0)); 43 bedr.popFront; 44 45 rec = bedr.front; 46 assert(rec.contig == "X"); 47 assert(rec.coordinates == ZBHO(1200, 1300)); 48 assert(rec.name == "X2"); 49 assert(rec.score == 500); 50 assert(rec.strand == '+'); 51 assert(rec.thickStart == 1200); 52 assert(rec.thickEnd == 1300); 53 assert(rec.itemRGB == RGB(255,0,0)); 54 55 rec.contig = "X1"; 56 rec.coordinates = ZBHO(1201, 1301); 57 rec.name = "X21"; 58 rec.score = 501; 59 rec.strand = '-'; 60 rec.thickStart = 1201; 61 rec.thickEnd = 1301; 62 rec.itemRGB = RGB(255,0,1); 63 64 assert(rec.contig == "X1"); 65 assert(rec.coordinates == ZBHO(1201, 1301)); 66 assert(rec.name == "X21"); 67 assert(rec.score == 501); 68 assert(rec.strand == '-'); 69 assert(rec.thickStart == 1201); 70 assert(rec.thickEnd == 1301); 71 assert(rec.itemRGB == RGB(255,0,1)); 72 73 assert(rec.toString == "X1\t1201\t1301\tX21\t501\t-\t1201\t1301\t255,0,1"); 74 75 }