Example #1
0
def test_filter_annotations1():

    annotations = [
        Annotation(start=1, end=10, bitscore=20),
        Annotation(start=5, end=10, bitscore=30),
        Annotation(start=9, end=15, bitscore=10),
        Annotation(start=16, end=20, bitscore=30),
        Annotation(start=16, end=20, bitscore=20),
        Annotation(start=21, end=30, bitscore=40),
    ]
    choose_func = None

    assert filter_annotations(annotations, choose_func=choose_func) == \
        set(
            [
                annotations[1],
                annotations[2],
                annotations[3],
                annotations[5],
            ]
        )
Example #2
0
def test_filter_attr_num_ge_fail2():
    a = Annotation()
    assert not filter_attr_num(a, 'bitscore', 15, True)
Example #3
0
    a = Annotation(bitscore=10)
    assert filter_attr_num(a, 'bitscore', 10, False)


def test_filter_attr_num_le_fail1():
    a = Annotation(bitscore=10)
    assert not filter_attr_num(a, 'bitscore', 5, False)


def test_filter_attr_num_le_fail2():
    a = Annotation()
    assert not filter_attr_num(a, 'bitscore', 5, False)


@pytest.mark.parametrize("annotation,attr,value,greater,result", [
    (Annotation(bitscore=11), 'bitscore', 10, True, True),
    (Annotation(bitscore=10), 'bitscore', 10, True, False),
    (Annotation(bitscore=None), 'bitscore', 10, True, False),
    (Annotation(bitscore=11), 'bitscore', 10, False, False),
    (Annotation(bitscore=9), 'bitscore', 10, False, True),
])
def test_filter_attr_num_s(annotation, attr, value, greater, result):
    assert filter_attr_num_s(annotation, attr, value, greater) == result


def test_filter_attr_str_eq_ok1():
    a = Annotation(ec='1.1.1.1')
    assert filter_attr_str(a, 'ec', '1.1.1.1', True)


def test_filter_attr_str_eq_fail1():
Example #4
0
def test_choose_annotation_contained1():
    # same size, better score
    a = Annotation(start=1, end=10, bitscore=10)
    b = Annotation(start=1, end=10, bitscore=15)
    assert choose_annotation(a, b) == a
Example #5
0
def test_choose_annotation_none2():
    # overlap lower than the limits
    a = Annotation(start=1, end=10, bitscore=10)
    b = Annotation(start=9, end=12, bitscore=10)
    assert choose_annotation(a, b, overlap=2) is None
Example #6
0
def test_choose_annotation_overlap2():
    # overlapping, same score, choose longer
    a = Annotation(start=1, end=11, bitscore=10)
    b = Annotation(start=5, end=11, bitscore=10)
    assert choose_annotation(a, b, overlap=4) == b
Example #7
0
def test_filter_attr_str_in_ok1():
    a = Annotation(ec='1.1.1.1')
    assert filter_attr_str(a, 'ec', '1.1.1.1', False)
Example #8
0
def test_choose_annotation_overlap1():
    # overlapping, better score
    a = Annotation(start=1, end=10, bitscore=10)
    b = Annotation(start=5, end=11, bitscore=15)
    assert choose_annotation(a, b, overlap=4) == a
Example #9
0
def test_filter_len_le_fail1():
    a = Annotation(start=1, end=10)
    assert not filter_len(a, 5, False)
Example #10
0
def test_filter_len_ge_fail1():
    a = Annotation(start=1, end=3)
    assert not filter_len(a, 5, True)
Example #11
0
def test_filter_len_le_ok2():
    # lower
    a = Annotation(start=1, end=3)
    assert filter_len(a, 5, False)
Example #12
0
def test_filter_len_ge_ok2():
    # greater
    a = Annotation(start=1, end=3)
    assert filter_len(a, 2, True)
Example #13
0
def test_filter_len_le_ok1():
    # equal
    a = Annotation(start=1, end=2)
    assert filter_len(a, 2, False)
Example #14
0
def test_filter_base_fail2():
    a = Annotation(seq_id='seq1')
    assert not filter_base(a, 'seqid', 'seq1')
Example #15
0
def test_filter_attr_num_le_ok2():
    a = Annotation(bitscore=10)
    assert filter_attr_num(a, 'bitscore', 10, False)
Example #16
0
def test_filter_attr_num_le_fail2():
    a = Annotation()
    assert not filter_attr_num(a, 'bitscore', 5, False)
Example #17
0
def test_filter_base_num_ge_ok2():
    a = Annotation(bitscore=10)
    assert filter_base_num(a, 'bitscore', 10, True)
Example #18
0
def test_filter_attr_str_eq_fail2():
    a = Annotation(ec='1.1.1.1')
    assert not filter_attr_str(a, 'ec', '1.1.1', True)
Example #19
0
def test_filter_base_num_ge_fail1():
    a = Annotation(bitscore=10)
    assert not filter_base_num(a, 'bitscore', 15, True)
Example #20
0
def test_filter_attr_str_in_fail2():
    a = Annotation(ec='1.1.1.1')
    assert not filter_attr_str(a, 'ec', '1.1.1.2', False)
Example #21
0
def test_choose_annotation_contained2():
    # same score, longer
    a = Annotation(start=1, end=10, bitscore=10)
    b = Annotation(start=5, end=10, bitscore=10)
    assert choose_annotation(a, b) == b
Example #22
0
def test_choose_annotation_none1():
    # no overlap
    a = Annotation(start=1, end=10, bitscore=10)
    b = Annotation(start=11, end=12, bitscore=10)
    assert choose_annotation(a, b, overlap=4) is None
Example #23
0
def test_filter_base_num_le_ok1():
    a = Annotation(bitscore=10)
    assert filter_base_num(a, 'bitscore', 15, False)
Example #24
0
def test_filter_base_num_le_fail1():
    a = Annotation(bitscore=10)
    assert not filter_base_num(a, 'bitscore', 5, False)
Example #25
0
def test_filter_attr_num_ge_ok1():
    a = Annotation(bitscore=10)
    assert filter_attr_num(a, 'bitscore', 5, True)
Example #26
0
def test_filter_base_ok1():
    a = Annotation(seq_id='seq1')
    assert filter_base(a, 'seq_id', 'seq1')
Example #27
0
def annotations():
    return [
        Annotation(seq_id='1', start=0, end=100, strand='+', uid='u1'),
        Annotation(seq_id='1', start=10, end=100, strand='-', uid='u2'),
        Annotation(seq_id='2', start=0, end=100, strand='+', uid='u3'),
    ]