コード例 #1
0
def test_validation_tloc():
    """Validate reaction"""

    assertion = AssertionStr(
        subject="tloc(p(MGI:Lipe), fromLoc(GO:0005737), toLoc(GO:0005811))")

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors == []

    assertion = AssertionStr(
        subject=
        'tloc(p(HGNC:NFE2L2), fromLoc(MESH:Cytoplasm), toLoc(MESH:"Cell Nucleus"))'
    )

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors == []
コード例 #2
0
def test_validate_complex_nsarg():

    assertion = AssertionStr(
        subject=
        'p(HGNC:PTHLH) increases act(complex(SCOMP:"Nfkb Complex"), ma(tscript))'
    )

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors == []

    assertion = AssertionStr(
        subject='complex(GO:"transcription factor AP-1 complex")')

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors == []
コード例 #3
0
def test_assertion_str():

    assertion = AssertionStr(subject=" hello", relation="there", object="world ")

    assert assertion.entire == "hello there world"

    # Does not update assertion.entire when SRO fields are altered
    assertion.entire = ""

    assertion.object = ""

    assert assertion.entire != "hello there"
コード例 #4
0
def get_bel_canonicalize(bel_assertion: str, version: str = "latest"):
    """Get Canonicalized Assertion"""

    assertion = AssertionStr(entire=bel_assertion)

    ast = bel.lang.ast.BELAst(assertion=assertion)

    canonicalized = ast.canonicalize().to_string()
    return {"canonicalized": canonicalized, "original": bel_assertion}
コード例 #5
0
def validate_assertion(bel_assertion: str):
    """Validate BEL Assertion"""

    validated = bel.nanopub.validate.validate_assertion(
        AssertionStr(entire=bel_assertion))

    logger.info(f"Validated: {validated}")

    return validated
コード例 #6
0
def test_validate_missing_left_quote():

    assertion = AssertionStr(subject='p(HGNC:AKT1")')
    expected = "Missing left quote before right quote at position 11"
    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors[0].msg == expected
コード例 #7
0
def test_validate_bad_nsarg():

    assertion = AssertionStr(subject="p(HGNC:)")
    expected = "Could not match function: proteinAbundance arguments to BEL Specification"
    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors[0].msg == expected
コード例 #8
0
def test_validate_missing_right_quote():

    assertion = AssertionStr(subject='p(HGNC:"AKT1)')
    expected = "Missing right quote after left quote at position 7 and before position 13"
    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors[0].msg == expected
コード例 #9
0
def test_validate_bad_function():

    assertion = AssertionStr(subject="ppp(HGNC:PTHLH)")
    expected = "Could not parse Assertion - bad relation? HGNC:9607!PTHLH"
    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors[0].msg == expected
コード例 #10
0
def test_validate_pmod_function_errors(test_input, expected):
    """Accept Single or three letter Amino Acid code"""

    assertion = AssertionStr(entire=test_input)

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors[0].msg == expected
コード例 #11
0
def test_validate_frag_function():
    """Validate functions"""

    assertion = AssertionStr(entire='p(HGNC:AKT1, frag("26_141"))')

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors == []
コード例 #12
0
def test_validate_abundance_namespace():
    """Validate abundance namespace"""

    assertion = AssertionStr(subject="a(CHEBI:15377!water)", )

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors == []
コード例 #13
0
def test_validate_namespace_using_synonyms():
    """Validate nsarg that doesn't match alt_keys but does match synonyms"""

    assertion = AssertionStr(subject="p(MGI:Emr4)", )

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors == []
コード例 #14
0
def test_validate_simple_function():
    """Validate simple function"""

    assertion = AssertionStr(entire="p(HGNC:AKT1)")

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors == []
コード例 #15
0
def test_validate_nsarg():
    """Validate path()"""

    assertion = AssertionStr(subject="path(DO:COVID-19)")

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors == []
コード例 #16
0
def test_validate_obsolete_nsarg():

    assertion = AssertionStr(subject="r(HGNC:A2MP)")
    expected = "BEL Entity name is obsolete - please update to HGNC:8!A2MP1"

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors[0].msg == expected
コード例 #17
0
def test_validate_strarg():

    assertion = AssertionStr(subject='complex("missing")')
    expected = "String argument not allowed as an optional or multiple argument. Probably missing a namespace."

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors[0].msg == expected
コード例 #18
0
def test_validate_empty_function():
    """Validate empty function"""

    assertion = AssertionStr(entire="p()")

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors[0].msg == "No arguments in function: proteinAbundance"
    assert ast.errors[0].severity == "Error"
コード例 #19
0
def test_ast_parse_fus():

    assertion = AssertionStr(
        entire="act(p(fus(HGNC:EWSR1, start, HGNC:FLI1, end)), ma(tscript))")

    ast = bel.lang.ast.BELAst(assertion=assertion)

    print("To String", ast.to_string())

    assert (
        ast.to_string() ==
        "act(p(fus(HGNC:3508!EWSR1, start, HGNC:3749!FLI1, end)), ma(tscript))"
    )
コード例 #20
0
def test_validate_fus2():
    """Validate fus()"""

    assertion = AssertionStr(
        subject="p(fus(HGNC:EWSR1, start, HGNC:FLI1, end))")

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors == []
コード例 #21
0
def test_validate_empty_modifier():
    """Validate empty modifier"""

    assertion = AssertionStr(entire="p(HGNC:AKT1, frag())")

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors[0].msg == "No arguments in function: fragment"
    assert ast.errors[0].severity == "Error"
コード例 #22
0
def test_get_species():
    """Collect all NSArg species for Assertion"""

    assertion = AssertionStr(
        entire="p(HGNC:391!AKT1) increases p(MGI:87986!Akt1)")

    ast = bel.lang.ast.BELAst(assertion=assertion)

    species = ast.get_species_keys()

    print("Species", species)

    assert species == ["TAX:9606", "TAX:10090"]
コード例 #23
0
def test_validate_deg_function():
    """Validate functions"""

    assertion = AssertionStr(
        entire='deg(a(CHEBI:"intermediate-density lipoprotein"))')

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors == []
コード例 #24
0
def test_validate_fus5():
    """Validate fus()"""

    assertion = AssertionStr(
        subject='r(fus(HGNC:TMPRSS2, "r.1_79", HGNC:ERG, "r.312_5034"))')

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors == []
コード例 #25
0
def test_validate_missing_parts():
    """Test object only or missing object or relation bel assertion"""

    assertion = AssertionStr(object="p(HGNC:AKT1)")
    ast = bel.lang.ast.BELAst(assertion=assertion)

    print("Validation messages - object only")
    for error in ast.errors:
        print("    ", error.json(), "\n")

    assert ast.errors[0].msg == "Missing Assertion Subject or Relation"

    assertion = AssertionStr(relation="increases")
    ast = bel.lang.ast.BELAst(assertion=assertion)

    print("Validation messages - relation only")
    for error in ast.errors:
        print("    ", error.json(), "\n")

    assert ast.errors[0].msg == "Missing Assertion Object"

    assertion = AssertionStr(relation="increases", object="p(HGNC:AKT1)")
    ast = bel.lang.ast.BELAst(assertion=assertion)

    print("Validation messages - relation and object")
    for error in ast.errors:
        print("    ", error.json(), "\n")

    assert ast.errors[0].msg == "Missing Assertion Subject or Relation"

    assertion = AssertionStr(subject="p(HGNC:AKT1)", object="p(HGNC:AKT1)")
    ast = bel.lang.ast.BELAst(assertion=assertion)

    print("Validation messages - subject and object")
    for error in ast.errors:
        print("    ", error.json(), "\n")

    assert ast.errors[0].msg == "Missing Assertion Subject or Relation"
コード例 #26
0
def test_validate_fus1():
    """Validate fus()"""

    # HGNC:NPM isn't valid - but it gets converted to updated entity
    assertion = AssertionStr(
        subject='p(fus(HGNC:NPM, "1_117", HGNC:ALK, end))')

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors == []
コード例 #27
0
def test_ast_subcomponents_simple():

    test_input = "path(DO:0080600!COVID-19)"
    assertion = AssertionStr(entire=test_input)

    ast = bel.lang.ast.BELAst(assertion=assertion)

    subcomponents = ast.subcomponents()

    print("Subcomponents", subcomponents)

    assert subcomponents == [
        "path(DO:0080600!COVID-19)", "DO:0080600!COVID-19", "DO:COVID-19"
    ]
コード例 #28
0
def test_validate_complex_missing_namespace():
    """Validate path()"""

    assertion = AssertionStr(subject="complex(UNKNOWN:test)")
    expected = (
        "Unknown BEL Entity UNKNOWN:test - cannot determine if this matches function signature"
    )
    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert ast.errors[0].msg == expected
コード例 #29
0
def test_validate_complex_nsarg_quoted_colon():

    assertion = AssertionStr(subject='complex(SCOMP:"KLF1:SWI/SNF complex")')

    ast = bel.lang.ast.BELAst(assertion=assertion)

    ast.validate()

    print("Errors", ast.errors)

    assert (
        ast.errors[0].msg ==
        'Unknown BEL Entity SCOMP:"KLF1:SWI/SNF complex" - cannot determine if this matches function signature'
    )
コード例 #30
0
def test_ast_subcomponents_complex():

    test_input = """rxn(reactants(complex(p(HGNC:5241!HSPA8), p(HGNC:6501!LAMP2), p(reactome:R-HSA-9622845.1!"HSP90AA1, HSP90AB1"), loc(GO:0005829!cytosol))), products(complex(p(HGNC:6501!LAMP2), p(reactome:R-HSA-9622845.1!"HSP90AA1, HSP90AB1"), loc(GO:0005765!"lysosomal membrane")), p(HGNC:5241!HSPA8, loc(GO:0005829!cytosol))))"""

    assertion = AssertionStr(entire=test_input)

    ast = bel.lang.ast.BELAst(assertion=assertion)

    subcomponents = ast.subcomponents()

    pprint.pprint(subcomponents)

    assert subcomponents == [
        "path(DO:0080600!COVID-19)", "DO:0080600!COVID-19", "DO:COVID-19"
    ]