def test_add_flag(): vcf = VCF(VCF_PATH) vcf.add_info_to_header({'ID': 'myflag', 'Description': 'myflag', 'Type':'Flag', 'Number': '0'}) # NOTE that we have to add the info to the header of the reader, # not the writer because the record will be associated with the reader f = tempfile.mktemp(suffix=".vcf") atexit.register(os.unlink, f) w = Writer(f, vcf) rec = vcf.next() rec.INFO["myflag"] = True w.write_record(rec) w.close() v = next(VCF(f)) assert v.INFO["myflag"] is None, dict(v.INFO) f = tempfile.mktemp(suffix=".vcf") atexit.register(os.unlink, f) w = Writer(f, vcf) rec.INFO["myflag"] = False w.write_record(rec) v = next(VCF(f)) assert_raises(KeyError, v.INFO.__getitem__, "myflag")
def test_add_flag(): vcf = VCF(VCF_PATH) vcf.add_info_to_header({ 'ID': 'myflag', 'Description': 'myflag', 'Type': 'Flag', 'Number': '0' }) # NOTE that we have to add the info to the header of the reader, # not the writer because the record will be associated with the reader f = tempfile.mktemp(suffix=".vcf") atexit.register(os.unlink, f) w = Writer(f, vcf) rec = vcf.next() rec.INFO["myflag"] = True w.write_record(rec) w.close() v = next(VCF(f)) assert v.INFO["myflag"] is None, dict(v.INFO) f = tempfile.mktemp(suffix=".vcf") atexit.register(os.unlink, f) w = Writer(f, vcf) rec.INFO["myflag"] = False w.write_record(rec) v = next(VCF(f)) assert_raises(KeyError, v.INFO.__getitem__, "myflag")
def test_add_filter_to_header(): v = VCF(VCF_PATH) # NOTE that we have to add the filter to the header of the reader, # not the writer because the record will be associated with the reader v.add_filter_to_header({'ID': 'abcdefg', 'Description': 'abcdefg'}) f = tempfile.mktemp(suffix=".vcf") atexit.register(os.unlink, f) w = Writer(f, v) rec = v.next() rec.FILTER = ["abcdefg"] w.write_record(rec) w.close() v = next(VCF(f)) assert v.FILTER == "abcdefg", v.FILTER
def test_add_info_to_header(): v = VCF(VCF_PATH) v.add_info_to_header({'ID': 'abcdefg', 'Description': 'abcdefg', 'Type':'Character', 'Number': '1'}) # NOTE that we have to add the info to the header of the reader, # not the writer because the record will be associated with the reader f = tempfile.mktemp(suffix=".vcf") atexit.register(os.unlink, f) w = Writer(f, v) import sys rec = v.next() rec.INFO["abcdefg"] = "XXX" w.write_record(rec) w.close() v = next(VCF(f)) assert v.INFO["abcdefg"] == "XXX", dict(v.INFO)
def test_add_info_to_header(): v = VCF(VCF_PATH) v.add_info_to_header({ 'ID': 'abcdefg', 'Description': 'abcdefg', 'Type': 'Character', 'Number': '1' }) # NOTE that we have to add the info to the header of the reader, # not the writer because the record will be associated with the reader f = tempfile.mktemp(suffix=".vcf") atexit.register(os.unlink, f) w = Writer(f, v) import sys rec = v.next() rec.INFO["abcdefg"] = "XXX" w.write_record(rec) w.close() v = next(VCF(f)) assert v.INFO["abcdefg"] == "XXX", dict(v.INFO)
def test_writer(): v = VCF(VCF_PATH) f = tempfile.mktemp(suffix=".vcf") atexit.register(os.unlink, f) o = Writer(f, v) rec = v.next() rec.INFO["AC"] = "3" rec.FILTER = ["LowQual"] o.write_record(rec) rec.FILTER = ["LowQual", "VQSRTrancheSNP99.90to100.00"] o.write_record(rec) rec.FILTER = "PASS" o.write_record(rec) o.close() expected = ["LowQual", "LowQual;VQSRTrancheSNP99.90to100.00", None] for i, variant in enumerate(VCF(f)): assert variant.FILTER == expected[i], (variant.FILTER, expected[i])