def test_bedrecord__accessors__3_fields(): record = BEDRecord("my_contig\t12\t345") assert record.contig == "my_contig" assert record.start == 12 assert record.end == 345 with pytest.raises(IndexError): record.name() with pytest.raises(IndexError): record.score() with pytest.raises(IndexError): record.strand()
def parse_intervals(genotype): records = {} for line in genotype.header: match = _VCF_DICT.match(line) if not match: continue key, values = match.groups() if key == "contig": values = dict(pair.split("=", 1) for pair in values.split(",")) record = BEDRecord() record.contig = values["ID"] record.start = 0 record.end = int(values["length"]) record.name = record.contig record.strand = "+" records[record.contig] = [record] if not records: sys.stderr.write("ERROR: List of contigs not found in VCF header; " "specifying --intervals is required!\n") return None return records
def test_bedrecord__setters__unset_fields__after_end(): record = BEDRecord("") record.strand = "-" assert_equal(str(record), "\t0\t0\t\t0\t-") record = BEDRecord("my_name") record.strand = "-" assert_equal(str(record), "my_name\t0\t0\t\t0\t-") record = BEDRecord("my_name\t17") record.strand = "-" assert_equal(str(record), "my_name\t17\t0\t\t0\t-") record = BEDRecord("my_name\t17\t258") record.strand = "-" assert_equal(str(record), "my_name\t17\t258\t\t0\t-") record = BEDRecord("my_name\t17\t258\tregion") record.strand = "-" assert_equal(str(record), "my_name\t17\t258\tregion\t0\t-") record = BEDRecord("my_name\t17\t258\tregion\t33") record.strand = "-" assert_equal(str(record), "my_name\t17\t258\tregion\t33\t-") record = BEDRecord("my_name\t17\t258\tregion\t33\t+") record.strand = "-" assert_equal(str(record), "my_name\t17\t258\tregion\t33\t-")
def test_bedrecord__setters__type_errors(): record = BEDRecord("my_contig\t12\t345\tname\t0\t+") with pytest.raises(ValueError): record.contig = 17 with pytest.raises(ValueError): record.start = "foo" with pytest.raises(ValueError): record.end = "foo" with pytest.raises(ValueError): record.name = 17.3 with pytest.raises(ValueError): record.score = "foo" with pytest.raises(ValueError): record.strand = "foo"
def test_bedrecord__setters__unset_fields__at_end(): record = BEDRecord("my_contig\t12\t345") record.name = "my_region" assert_equal(record.name, "my_region") record.score = -13 assert_equal(record.score, -13) record.strand = '-' assert_equal(record.strand, '-') assert_equal(str(record), "my_contig\t12\t345\tmy_region\t-13\t-") assert_equal( repr(record), "BEDRecord(contig='my_contig', start=12, end=345, " "name='my_region', score=-13, strand='-')")
def test_bedrecord__setters__unset_fields__at_end(): record = BEDRecord("my_contig\t12\t345") record.name = "my_region" assert_equal(record.name, "my_region") record.score = -13 assert_equal(record.score, -13) record.strand = '-' assert_equal(record.strand, '-') assert_equal(str(record), "my_contig\t12\t345\tmy_region\t-13\t-") assert_equal(repr(record), "BEDRecord(contig='my_contig', start=12, end=345, " "name='my_region', score=-13, strand='-')")
def test_bedrecord__setters__unset_fields__at_end(): record = BEDRecord("my_contig\t12\t345") record.name = "my_region" assert record.name == "my_region" record.score = -13 assert record.score == -13 record.strand = "-" assert record.strand == "-" assert str(record) == "my_contig\t12\t345\tmy_region\t-13\t-" assert ( repr(record) == "BEDRecord(contig='my_contig', start=12, end=345, " "name='my_region', score=-13, strand='-')" )