def test_header_header(): lines1 = [ header.HeaderLine("foo", "bar"), header.HeaderLine("foo2", "bar2") ] samples1 = header.SamplesInfos(["one", "two", "three"]) hdr1 = header.Header(lines1, samples1) lines2 = [ header.HeaderLine("foo", "bar"), header.HeaderLine("foo2", "bar2") ] samples2 = header.SamplesInfos(["one", "two", "three"]) hdr2 = header.Header(lines2, samples2) lines3 = [ header.HeaderLine("foo3", "bar"), header.HeaderLine("foo2", "bar2") ] samples3 = header.SamplesInfos(["one", "two", "three"]) hdr3 = header.Header(lines3, samples3) assert hdr1 == hdr2 assert hdr1 != hdr3 EXPECTED = ( "Header(lines=[HeaderLine('foo', 'bar'), HeaderLine('foo2', 'bar2')], " "samples=SamplesInfos(names=['one', 'two', 'three'], " "name_to_idx={'one': 0, 'three': 2, 'two': 1}))") assert str(hdr1) == EXPECTED with pytest.raises(TypeError): hash(hdr1)
def test_header_has_header_line_positive_no_samples(): lines = [] samples = header.SamplesInfos(["one", "two", "three"]) hdr = header.Header(lines, samples) assert not hdr.has_header_line("FORMAT", "DP") assert not hdr.has_header_line("INFO", "AD") assert not hdr.has_header_line("FILTER", "PASS") assert not hdr.has_header_line("contig", "1")
def test_header_checker_missing_fileformat(): # construct Header lines = [header.HeaderLine("key", "value")] hdr = header.Header(lines=lines, samples=header.SamplesInfos(["NA001"])) # setup HeaderChecker stream = io.StringIO() checker = parser.HeaderChecker() # execute with pytest.raises(exceptions.InvalidHeaderException): checker.run(hdr)
def test_header_checker_known_vcf_version(): # construct Header lines = [header.HeaderLine("fileformat", "VCFv4.3")] hdr = header.Header(lines=lines, samples=header.SamplesInfos(["NA001"])) # setup HeaderChecker stream = io.StringIO() checker = parser.HeaderChecker() # execute checker.run(hdr) # check result EXPECTED = "" assert stream.getvalue() == EXPECTED
def test_header_without_lines(): lines = [ header.HeaderLine("foo", "bar"), header.HeaderLine("foo2", "bar2") ] samples = header.SamplesInfos(["one", "two", "three"]) hdr = header.Header(lines, samples) hdr.add_filter_line(vcfpy.OrderedDict([("ID", "PASS")])) hdr.add_filter_line(vcfpy.OrderedDict([("ID", "q30")])) assert len(hdr.lines) == 4 hdr2 = header.header_without_lines(hdr, [("foo", "bar"), ("FILTER", "q30")]) assert len(hdr2.lines) == 2 assert hdr2.samples == hdr.samples
def test_write_header_no_samples(tmpdir_factory): # Create header to write out from scratch hdr = header.Header( lines=[header.HeaderLine("fileformat", "VCFv4.0")], samples=header.SamplesInfos([]) ) # Write out header path = tmpdir_factory.mktemp("write_header").join("out.vcf") w = writer.Writer.from_path(path, hdr) w.close() # Compare result RESULT = path.read() EXPECTED = textwrap.dedent( r""" ##fileformat=VCFv4.0 #CHROM POS ID REF ALT QUAL FILTER INFO """ ).lstrip() assert RESULT == EXPECTED
def test_write_record_no_samples(tmpdir_factory): O = vcfpy.OrderedDict # Create header without samples hdr = header.Header(lines=[header.HeaderLine("fileformat", "VCFv4.0")], samples=header.SamplesInfos([])) # construct record to write out from scratch r = record.Record("20", 100, [], "C", [record.Substitution(record.SNV, "T")], None, [], O()) # Write out header and record path = tmpdir_factory.mktemp("write_header").join("out.vcf") w = writer.Writer.from_path(path, hdr) w.write_record(r) w.close() # Compare result RESULT = path.read() EXPECTED = textwrap.dedent(""" ##fileformat=VCFv4.0 #CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO 20\t100\t.\tC\tT\t.\t.\t. """).lstrip() assert RESULT == EXPECTED
def test_header_has_header_line_positive(): lines = [ header.FormatHeaderLine.from_mapping( vcfpy.OrderedDict([("ID", "DP"), ("Number", "R"), ("Type", "Integer")])), header.InfoHeaderLine.from_mapping( vcfpy.OrderedDict([("ID", "AD"), ("Number", "R"), ("Type", "Integer")])), header.FilterHeaderLine.from_mapping( vcfpy.OrderedDict([("ID", "PASS"), ("Description", "All filters passed")])), header.ContigHeaderLine.from_mapping( vcfpy.OrderedDict([("ID", "1"), ("length", 234)])), ] samples = header.SamplesInfos(["one", "two", "three"]) hdr = header.Header(lines, samples) assert hdr.has_header_line("FORMAT", "DP") assert hdr.has_header_line("INFO", "AD") assert hdr.has_header_line("FILTER", "PASS") assert hdr.has_header_line("contig", "1")
def vcf_header(): return header.Header()