Example #1
0
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()
Example #2
0
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
Example #3
0
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
Example #4
0
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"
Example #5
0
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='-')")
Example #7
0
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='-')"
    )