Beispiel #1
0
def test_guess_cluster_category():
    tests = [('lantipeptide', 'type'), ('NC_003888', 'acc'),
             ('Streptomyces', 'genus'), ('coelicolor', 'species'),
             ('not-in-database', 'unknown')]

    for search_term, expected in tests:
        term = QueryTerm.from_string(search_term)
        assert clusters.guess_cluster_category(term) == expected, search_term
Beispiel #2
0
def test_query_term_from_string():
    string = ""
    with pytest.raises(ValueError):
        QueryTerm.from_string(string)

    string = "nrps"
    term = QueryTerm.from_string(string)
    assert term.kind == 'expression'
    assert term.category == 'unknown'
    assert term.term == 'nrps'

    string = "[type]nrps"
    term = QueryTerm.from_string(string)
    assert term.kind == 'expression'
    assert term.category == 'type'
    assert term.term == 'nrps'

    string = "[contigedge]true"
    term = QueryTerm.from_string(string)
    assert term.kind == 'expression'
    assert term.category == 'contigedge'
    assert term.term is True

    string = "nrps AND 1234"
    term = QueryTerm.from_string(string)
    assert term.kind == 'operation'
    assert term.operation == 'and'
    assert term.left.term == 'nrps'
    assert term.right.term == '1234'

    string = "nrps OR 1234"
    term = QueryTerm.from_string(string)
    assert term.kind == 'operation'
    assert term.operation == 'or'
    assert term.left.term == 'nrps'
    assert term.right.term == '1234'

    string = "nrps EXCEPT 1234"
    term = QueryTerm.from_string(string)
    assert term.kind == 'operation'
    assert term.operation == 'except'
    assert term.left.term == 'nrps'
    assert term.right.term == '1234'

    string = "nrps 1234"
    term = QueryTerm.from_string(string)
    assert term.kind == 'operation'
    assert term.operation == 'and'
    assert term.left.term == 'nrps'
    assert term.right.term == '1234'

    string = "ripp AND ( streptomyces OR lactococcus )"
    term = QueryTerm.from_string(string)
    assert term.kind == 'operation'
    assert term.left.term == 'ripp'
    assert term.right.kind == 'operation'
    assert term.right.left.term == 'streptomyces'
    assert term.right.right.term == 'lactococcus'

    string = "lanthipeptide ((Streptomyces coelicolor) OR (Lactococcus lactis))"
    term = QueryTerm.from_string(string)
    assert term.kind == 'operation'
    assert term.left.term == 'lanthipeptide'
    assert term.right.kind == 'operation'
    assert term.right.left.kind == 'operation'
    assert term.right.left.left.term == 'Streptomyces'
    assert term.right.right.kind == 'operation'
    assert term.right.right.right.term == 'lactis'

    with pytest.raises(ValueError):
        string = "AND ripp"
        term = QueryTerm.from_string(string)

    with pytest.raises(ValueError):
        string = "END"
        term = QueryTerm.from_string(string)

    with pytest.raises(ValueError):
        string = "( ripp"
        term = QueryTerm.from_string(string)
Beispiel #3
0
def test_query_term_from_string():
    string = ""
    with pytest.raises(ValueError):
        QueryTerm.from_string(string)

    string = "nrps"
    term = QueryTerm.from_string(string)
    assert term.kind == 'expression'
    assert term.category == 'unknown'
    assert term.term == 'nrps'

    string = "[type]nrps"
    term = QueryTerm.from_string(string)
    assert term.kind == 'expression'
    assert term.category == 'type'
    assert term.term == 'nrps'

    string = "nrps AND 1234"
    term = QueryTerm.from_string(string)
    assert term.kind == 'operation'
    assert term.operation == 'and'
    assert term.left.term == 'nrps'
    assert term.right.term == '1234'

    string = "nrps OR 1234"
    term = QueryTerm.from_string(string)
    assert term.kind == 'operation'
    assert term.operation == 'or'
    assert term.left.term == 'nrps'
    assert term.right.term == '1234'

    string = "nrps EXCEPT 1234"
    term = QueryTerm.from_string(string)
    assert term.kind == 'operation'
    assert term.operation == 'except'
    assert term.left.term == 'nrps'
    assert term.right.term == '1234'

    string = "nrps 1234"
    term = QueryTerm.from_string(string)
    assert term.kind == 'operation'
    assert term.operation == 'and'
    assert term.left.term == 'nrps'
    assert term.right.term == '1234'

    string = "ripp AND ( streptomyces OR lactococcus )"
    term = QueryTerm.from_string(string)
    assert term.kind == 'operation'
    assert term.left.term == 'ripp'
    assert term.right.kind == 'operation'
    assert term.right.left.term == 'streptomyces'
    assert term.right.right.term == 'lactococcus'

    string = "lanthipeptide ((Streptomyces coelicolor) OR (Lactococcus lactis))"
    term = QueryTerm.from_string(string)
    assert term.kind == 'operation'
    assert term.left.term == 'lanthipeptide'
    assert term.right.kind == 'operation'
    assert term.right.left.kind == 'operation'
    assert term.right.left.left.term == 'Streptomyces'
    assert term.right.right.kind == 'operation'
    assert term.right.right.right.term == 'lactis'

    with pytest.raises(ValueError):
        string = "AND ripp"
        term = QueryTerm.from_string(string)

    with pytest.raises(ValueError):
        string = "END"
        term = QueryTerm.from_string(string)

    with pytest.raises(ValueError):
        string = "( ripp"
        term = QueryTerm.from_string(string)