Exemple #1
0
def test_where_eq(O):
    errors = []
    setupGraph(O)

    count = 0
    for i in O.query().V().where(aql.eq("_gid", "vertex3")):
        count += 1
        if i['gid'] != "vertex3":
            errors.append("Wrong vertex returned %s" % (i))
    if count != 1:
        errors.append(
            "Fail: O.query().V().where(aql.eq(\"_gid\", \"vertex3\")) %s != %s"
            % (count, 1))

    count = 0
    for i in O.query().V().where(aql.eq("_label", "person")):
        count += 1
        if i['label'] != "person":
            errors.append("Wrong vertex label %s" % (i['label']))
    if count != 4:
        errors.append(
            "Fail: O.query().V().where(aql.eq(\"_label\", \"person\")) %s != %s"
            % (count, 4))

    count = 0
    for i in O.query().V().where(aql.eq("occupation", "jedi")):
        count += 1
        if i['gid'] not in ["vertex2", "vertex5"]:
            errors.append("Wrong vertex returned %s" % (i))
    if count != 2:
        errors.append(
            "Fail: O.query().V().where(aql.eq(\"occupation\", \"jedi\")) %s != %s"
            % (count, 2))

    return errors
Exemple #2
0
def run(args):
    conn = aql.Connection(args.arachne)
    O = conn.graph(args.graph)
    ensembl_id = conversions.hugo_ensembl(args.gene)
    gid = "gene:" + ensembl_id

    sample_mutation_status = {}

    query =  O.query().V(gid).\
             in_("variantIn").mark("variant").\
             out("variantCall").where(aql.eq("method", "MUTECT")).mark("callset").\
             out("callSetOf").where(aql.eq("sample_type", "Primary Tumor")).mark("sample").\
             in_("fileFor").mark("cel")
    if args.project is not None:
        query = query.where(aql.eq("project", args.project))
    query = query.mark("cel").\
            select(["variant", "sample", "callset", "cel"])

    for res in query:
        if res.variant.data.alternateBases != res.variant.data.referenceBases:
            if res.cel.data.individual_barcode not in sample_mutation_status:
                sample_mutation_status[res.cel.data.individual_barcode] = 2

    query = O.query().V().where(aql.eq("_label", "CELFile"))
    if args.project is not None:
        query = query.where(aql.eq("project", args.project))

    for res in query:
        if res.data.individual_barcode not in sample_mutation_status:
            sample_mutation_status[res.data.individual_barcode] = 1

    for k in sample_mutation_status:
        print(k, k, sample_mutation_status[k], sep="\t")

    return
Exemple #3
0
def test_render(O):
    errors = []

    O.addVertex("1", "Person", {"name": "marko", "age": "29"})
    O.addVertex("2", "Person", {"name": "vadas", "age": "27"})
    O.addVertex("3", "Software", {"name": "lop", "lang": "java"})
    O.addVertex("4", "Person", {"name": "josh", "age": "32"})
    O.addVertex("5", "Software", {"name": "ripple", "lang": "java"})
    O.addVertex("6", "Person", {"name": "peter", "age": "35"})

    O.addEdge("1", "3", "created", {"weight": 0.4})
    O.addEdge("1", "2", "knows", {"weight": 0.5})
    O.addEdge("1", "4", "knows", {"weight": 1.0})
    O.addEdge("4", "3", "created", {"weight": 0.4})
    O.addEdge("6", "3", "created", {"weight": 0.2})
    O.addEdge("4", "5", "created", {"weight": 1.0})

    query = O.query().V().where(aql.eq("_label", "Person")).render({
        "Name": "name",
        "Age": "age"
    })
    for row in query:
        if 'Age' not in row or "Name" not in row:
            errors.append("Missing fields")

    query = O.query().V().where(aql.eq("_label", "Person")).render({
        "Name":
        "name",
        "NonExistent":
        "non-existent"
    })
    for row in query:
        if 'NonExistent' not in row or "Name" not in row:
            errors.append("Missing fields")

    query = O.query().V().where(aql.eq("_label",
                                       "Person")).render(["name", "age"])
    for row in query:
        if not isinstance(row, list):
            errors.append("unexpected output format")
        if len(row) != 2:
            errors.append("Missing fields")

    query = O.query().V().where(aql.eq("_label", "Person")).render(
        ["name", "non-existent"])
    for row in query:
        if not isinstance(row, list):
            errors.append("unexpected output format")
        if len(row) != 2:
            errors.append("Missing fields")

    return errors
Exemple #4
0
def test_where_not(O):
    errors = []
    setupGraph(O)

    count = 0
    for i in O.query().V().where(aql.not_(aql.eq("_label", "person"))):
        count += 1
        if i['gid'] not in ["vertex3", "vertex4"]:
            errors.append("Wrong vertex returned %s" % (i))
    if count != 2:
        errors.append(
            "Fail: O.query().V().where(aql.not_(aql.eq(\"_label\", \"person\"))) %s != %s"
            % (count, 2))

    count = 0
    for i in O.query().V().where(aql.not_(aql.neq("_label", "person"))):
        count += 1
        if i['gid'] not in ["vertex1", "vertex2", "vertex5", "vertex6"]:
            errors.append("Wrong vertex returned %s" % (i))
    if count != 4:
        errors.append(
            "Fail: O.query().V().where(aql.not_(aql.neq(\"_label\", \"person\"))) %s != %s"
            % (count, 4))

    return errors
def test_distinct(O):
    errors = []

    O.addVertex("1", "Person", {"name": "marko", "age": 29})
    O.addVertex("2", "Person", {"name": "vadas", "age": 25})
    O.addVertex("4", "Person", {"name": "josh", "age": 32})
    O.addVertex("6", "Person", {"name": "peter", "age": 35})
    O.addVertex("7", "Person", {"name": "marko", "age": 41})
    O.addVertex("9", "Person", {"name": "alex", "age": 30})
    O.addVertex("10", "Person", {"name": "alex", "age": 45})
    O.addVertex("11", "Person", {"name": "steve", "age": 26})
    O.addVertex("12", "Person", {"name": "alice", "age": 22})
    O.addVertex("13", "Person", {"name": "wanda", "age": 36})
    O.addVertex("5", "Software", {"name": "ripple", "lang": "java"})
    O.addVertex("3", "Software", {"name": "lop", "lang": "java"})
    O.addVertex("8", "Software", {"name": "funnel", "lang": "go"})
    O.addVertex("14", "Software", {"name": "arachne", "lang": None})

    O.addEdge("1", "5", "developer", gid="edge1")
    O.addEdge("7", "5", "developer", gid="edge2")
    O.addEdge("3", "8", "dependency", gid="edge3")

    count = 0
    for i in O.query().V().distinct():
        count += 1
    if count != 14:
        errors.append("Distinct %s != %s" % (count, 14))

    count = 0
    for i in O.query().V().distinct("_gid"):
        count += 1
    if count != 14:
        errors.append("Distinct %s != %s" % (count, 14))

    count = 0
    for i in O.query().V().distinct("name"):
        count += 1
    if count != 12:
        errors.append("Distinct %s != %s" % (count, 12))

    count = 0
    for i in O.query().V().distinct("lang"):
        count += 1
    if count != 3:
        errors.append("Distinct %s != %s" % (count, 3))

    count = 0
    for i in O.query().V().distinct("non-existent-field"):
        count += 1
    if count != 0:
        errors.append("Distinct %s != %s" % (count, 0))

    count = 0
    for i in O.query().V().where(aql.eq(
            "_label", "Person")).mark("person").out().distinct("$person.name"):
        count += 1
    if count != 1:
        errors.append("Distinct %s != %s" % (count, 1))

    return errors
Exemple #6
0
def test_where_or(O):
    errors = []
    setupGraph(O)

    count = 0
    for i in O.query().V().where(
            aql.or_(aql.eq("occupation", "sith"), aql.eq("occupation",
                                                         "jedi"))):
        count += 1
        if i['gid'] not in ["vertex2", "vertex5", "vertex6"]:
            errors.append("Wrong vertex returned %s" % (i))
    if count != 3:
        errors.append(
            "Fail: O.query().V().where(aql.or_(aql.eq(\"occupation\", \"sith\"), aql.eq(\"occupation\", \"jedi\"))) %s != %s"
            % (count, 3))

    return errors
Exemple #7
0
def test_where_and(O):
    errors = []
    setupGraph(O)

    count = 0
    for i in O.query().V().where(
            aql.and_(aql.eq("_label", "person"), aql.eq("occupation",
                                                        "jedi"))):
        count += 1
        if i['gid'] not in ["vertex2", "vertex5"]:
            errors.append("Wrong vertex returned %s" % (i))
    if count != 2:
        errors.append(
            "Fail: O.query().V().where(aql.and_(aql.eq(\"_label\", \"person\"), aql.eq(\"occupation\", \"jedi\"))) %s != %s"
            % (count, 2))

    return errors
Exemple #8
0
def test_match_count(O):
    errors = []

    O.addVertex("1", "Person", {"name": "marko", "age": "29"})
    O.addVertex("2", "Person", {"name": "vadas", "age": "27"})
    O.addVertex("3", "Software", {"name": "lop", "lang": "java"})
    O.addVertex("4", "Person", {"name": "josh", "age": "32"})
    O.addVertex("5", "Software", {"name": "ripple", "lang": "java"})
    O.addVertex("6", "Person", {"name": "peter", "age": "35"})

    O.addEdge("1", "3", "created", {"weight": 0.4})
    O.addEdge("1", "2", "knows", {"weight": 0.5})
    O.addEdge("1", "4", "knows", {"weight": 1.0})
    O.addEdge("4", "3", "created", {"weight": 0.4})
    O.addEdge("6", "3", "created", {"weight": 0.2})
    O.addEdge("4", "5", "created", {"weight": 1.0})

    query = O.query().V().match([
        O.query().mark('a').out('created').mark('b'),
        O.query().mark('b').where(aql.eq('$.name', 'lop')),
        O.query().mark('b').in_('created').mark('c'),
        O.query().mark('c').where(aql.eq('$.age', "29"))
    ]).select(['a', 'c'])

    count = 0
    for row in query.execute(stream=True):
        count += 1
        if len(row) != 2:
            errors.append("Incorrect number of marks returned in row")
            continue
        if row["c"]['data']['name'] != "marko":
            errors.append("Incorrect return")

    if count != 3:
        errors.append("Incorrect return count: %d != %d" % (count, 3))

    return errors
Exemple #9
0
def test_where_complex(O):
    errors = []
    setupGraph(O)

    count = 0
    for i in O.query().V().where(
            aql.and_(
                aql.eq("_label", "person"),
                aql.not_(
                    aql.or_(aql.eq("occupation", "jedi"),
                            aql.eq("occupation", "sith"))))):
        count += 1
        if i['gid'] != "vertex1":
            errors.append("Wrong vertex returned %s" % (i))
    if count != 1:
        errors.append(
            "Fail: O.query().V().where(aql.and_(aql.eq(\"_label\", \"person\"), aql.not_(aql.or_(aql.eq(\"occupation\", \"jedi\"), aql.eq(\"occupation\", \"sith\"))))) %s != %s"
            % (count, 1))

    count = 0
    for i in O.query().V().where(
            aql.not_(
                aql.or_(
                    aql.eq("_label", "robot"),
                    aql.eq("occupation", "jedi"),
                ))):
        count += 1
        if i['gid'] not in ["vertex1", "vertex6"]:
            errors.append("Wrong vertex returned %s" % (i))
    if count != 2:
        errors.append(
            "Fail: O.query().V().where(aql.not_(aql.and_(aql.eq(\"_label\", \"robot\"), aql.eq(\"occupation\", \"jedi\")))) %s != %s"
            % (count, 2))

    count = 0
    for i in O.query().V().where(
            aql.not_(
                aql.or_(
                    aql.eq("_label", "robot"),
                    aql.or_(aql.eq("occupation", "jedi"),
                            aql.contains("starships", "millennium falcon"))))):
        count += 1
        if i['gid'] != "vertex6":
            errors.append("Wrong vertex returned %s" % (i))
    if count != 1:
        errors.append(
            "Fail: O.query().V().where(aql.not_(aql.or_(aql.eq(\"_label\", \"robot\"), aql.or_(aql.eq(\"occupation\", \"jedi\"),  aql.contains(\"starships\", \"millennium falcon\"))))) %s != %s"
            % (count, 1))

    count = 0
    for i in O.query().V().where(
            aql.not_(
                aql.and_(
                    aql.eq("_label", "robot"),
                    aql.or_(aql.eq("occupation", "jedi"),
                            aql.contains("starships", "millennium falcon"))))):
        count += 1
    if count != 6:
        errors.append(
            "Fail: O.query().V().where(aql.not_(aql.and_(aql.eq(\"_label\", \"robot\"), aql.or_(aql.eq(\"occupation\", \"jedi\"),  aql.contains(\"starships\", \"millennium falcon\"))))) %s != %s"
            % (count, 6))

    return errors