1 module dhtslib.gff.writer; 2 3 import dhtslib.gff.record; 4 import dhtslib.recordwriter; 5 6 /// Record writer for GFF3Records 7 alias GFF2Writer = RecordWriter!GFF2Record; 8 9 /// Record writer for GFF3Records 10 alias GFF3Writer = RecordWriter!GFF3Record; 11 12 debug(dhtslib_unittest) unittest 13 { 14 import std.stdio; 15 import htslib.hts_log; 16 import std.range : take; 17 import std.algorithm : map; 18 import std.array : array; 19 import std.path : buildPath, dirName; 20 import dhtslib.gff.reader; 21 import dhtslib.coordinates; 22 hts_set_log_level(htsLogLevel.HTS_LOG_INFO); 23 hts_log_info(__FUNCTION__, "Testing GFF3Reader"); 24 hts_log_info(__FUNCTION__, "Loading test file"); 25 26 auto gffr = GFF3Reader(buildPath(dirName(dirName(dirName(dirName(__FILE__)))),"htslib","test","tabix","gff_file.gff")); 27 auto gffw = GFF3Writer("/tmp/test.gff", gffr.header); 28 auto rec = gffr.front; 29 gffw.write(rec); 30 gffr.popFront; 31 auto moreRecs = gffr.take(3); 32 gffw.writeRecords(moreRecs); 33 destroy(gffw); 34 gffr = GFF3Reader("/tmp/test.gff"); 35 rec = gffr.front; 36 37 assert(rec.contig == "X"); 38 assert(rec.source == "Vega"); 39 assert(rec.type == "exon"); 40 assert(rec.coordinates == OBC(2934816, 2935190)); 41 assert(rec.score == -1); 42 assert(rec.strand == '-'); 43 assert(rec.phase == -1); 44 assert(rec["Name"] == "OTTHUME00001604789"); 45 assert(rec["Parent"] == "OTTHUMT00000055643"); 46 gffr.popFront; 47 48 rec = gffr.front; 49 assert(rec.contig == "X"); 50 assert(rec.source == "Vega"); 51 assert(rec.type == "gene"); 52 assert(rec.coordinates == OBC(2934816, 2964270)); 53 assert(rec.score == -1); 54 assert(rec.strand == '-'); 55 assert(rec.phase == -1); 56 assert(rec["Name"] == "OTTHUMG00000137358"); 57 58 }