Ejemplo n.º 1
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
Ejemplo n.º 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
Ejemplo n.º 3
0
def test_bedrecord__setters__3_fields():
    record = BEDRecord("my_contig\t12\t345")

    record.contig = "chrZ"
    assert_equal(record.contig, "chrZ")

    record.end += 20
    assert_equal(record.end, 365)

    assert_equal(str(record), "chrZ\t12\t365")
    assert_equal(repr(record), "BEDRecord(contig='chrZ', start=12, end=365)")
Ejemplo n.º 4
0
def test_bedrecord__setters__3_fields():
    record = BEDRecord("my_contig\t12\t345")

    record.contig = "chrZ"
    assert record.contig == "chrZ"

    record.end += 20
    assert record.end == 365

    assert str(record) == "chrZ\t12\t365"
    assert repr(record) == "BEDRecord(contig='chrZ', start=12, end=365)"
Ejemplo n.º 5
0
def test_bedrecord__setters__3_fields():
    record = BEDRecord("my_contig\t12\t345")

    record.contig = "chrZ"
    assert_equal(record.contig, "chrZ")

    record.end += 20
    assert_equal(record.end, 365)

    assert_equal(str(record), "chrZ\t12\t365")
    assert_equal(repr(record),
                 "BEDRecord(contig='chrZ', start=12, end=365)")
Ejemplo n.º 6
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"