def test_gaf_writer():
    association = GoAssociation(
        source_line="",
        subject=Subject(
            id=Curie("PomBase", "SPAC25B8.17"),
            label="ypf1",
            type="protein",
            fullname=
            "intramembrane aspartyl protease of the perinuclear ER membrane Ypf1 (predicted)",
            synonyms=["ppp81"],
            taxon=Curie("NCBITaxon", "4896")),
        object=Term(id=Curie("GO", "0000006"),
                    taxon=Curie("NCBITaxon", "4896")),
        negated=False,
        qualifiers=[],
        aspect="C",
        relation=Curie("BFO", "0000050"),
        interacting_taxon=Curie("NCBITaxon", "555"),
        evidence=Evidence(
            type=Curie("ECO", "0000266"),
            has_supporting_reference=[Curie("GO_REF", "0000024")],
            with_support_from=[
                ConjunctiveSet(elements=[Curie("SGD", "S000001583")])
            ]),
        provided_by="PomBase",
        date="20150305",
        subject_extensions=[
            ExtensionUnit(relation=Curie("rdfs", "subClassOf"),
                          term=Curie("UniProtKB", "P12345"))
        ],
        object_extensions=[
            ConjunctiveSet(elements=[
                ExtensionUnit(relation=Curie("BFO", "0000050"),
                              term=Curie("X", "1"))
            ])
        ],
        properties=dict())
    out = io.StringIO()
    writer = assocwriter.GafWriter(file=out)
    # `out` will get written with gaf lines from the above assocation object
    expected = "PomBase\tSPAC25B8.17\typf1\t\tGO:0000006\tGO_REF:0000024\tISO\tSGD:S000001583\tC\tintramembrane aspartyl protease of the perinuclear ER membrane Ypf1 (predicted)\tppp81\tprotein\ttaxon:4896|taxon:555\t20150305\tPomBase\tpart_of(X:1)\tUniProtKB:P12345"
    writer.write_assoc(association)
    print(out.getvalue())
    gaf = [
        line.strip("\n") for line in out.getvalue().split("\n")
        if not line.startswith("!")
    ][0]
    assert expected == gaf
Exemple #2
0
def test_bioentities_get_when_empty():
    e = collections.BioEntities(dict())
    assert e.get(Curie("FOO", "123")) == None
Exemple #3
0
def test_bioentities_merge():
    e = collections.BioEntities({
        Curie("FOO", "123"):
        Subject(Curie("FOO", "123"), "hello", "world", [], "protien",
                Curie("NCBITaxon", "12345"))
    })

    o = collections.BioEntities({
        Curie("BAR", "987"):
        Subject(Curie("BAR", "987"), "goodbye", "world", [], "protien",
                Curie("NCBITaxon", "999"))
    })

    assert e.merge(o) == collections.BioEntities({
        Curie("FOO", "123"):
        Subject(Curie("FOO", "123"), "hello", "world", [], "protien",
                Curie("NCBITaxon", "12345")),
        Curie("BAR", "987"):
        Subject(Curie("BAR", "987"), "goodbye", "world", [], "protien",
                Curie("NCBITaxon", "999"))
    })
def test_conjunctive_set_str_to_conjunctions():
    c = association.ConjunctiveSet.str_to_conjunctions("")
    assert c == []

    c = association.ConjunctiveSet.str_to_conjunctions("MGI:12345")
    assert c == [association.ConjunctiveSet([Curie.from_str("MGI:12345")])]

    c = association.ConjunctiveSet.str_to_conjunctions("MGI:12345,MGI:12345")
    assert c == [
        association.ConjunctiveSet(
            [Curie.from_str("MGI:12345"),
             Curie.from_str("MGI:12345")])
    ]

    c = association.ConjunctiveSet.str_to_conjunctions("MGI:12345|MGI:12345")
    assert c == [
        association.ConjunctiveSet([Curie.from_str("MGI:12345")]),
        association.ConjunctiveSet([Curie.from_str("MGI:12345")])
    ]

    c = association.ConjunctiveSet.str_to_conjunctions(
        "MGI:12345,DOI:333|GO:987")
    assert c == [
        association.ConjunctiveSet(
            [Curie.from_str("MGI:12345"),
             Curie.from_str("DOI:333")]),
        association.ConjunctiveSet([Curie.from_str("GO:987")])
    ]

    c = association.ConjunctiveSet.str_to_conjunctions(
        "part_of(MGI:123),part_of(FOO:456)|has_direct_input(BAR:987)",
        conjunct_element_builder=lambda u: association.ExtensionUnit.from_str(
            u))
    assert c == [
        association.ConjunctiveSet([
            association.ExtensionUnit(Curie.from_str("BFO:0000050"),
                                      Curie.from_str("MGI:123")),
            association.ExtensionUnit(Curie.from_str("BFO:0000050"),
                                      Curie.from_str("FOO:456"))
        ]),
        association.ConjunctiveSet([
            association.ExtensionUnit(Curie.from_str("GOREL:0000752"),
                                      Curie.from_str("BAR:987"))
        ])
    ]

    c = association.ConjunctiveSet.str_to_conjunctions(
        "HECK_NO,part_of(FOO:456)|has_direct_input(BAR:987)",
        conjunct_element_builder=lambda u: association.ExtensionUnit.from_str(
            u))
    assert c == association.Error("HECK_NO")
def test_subject_types_label():
    s = association.Subject(Curie.from_str("HELLO:12345"), "Hello object",
                            ["fullname"], [], ["mRNA", "tRNA"],
                            association.Curie.from_str("NCBITaxon:12345"))
    assert [Curie.from_str("SO:0000234"),
            Curie.from_str("SO:0000253")] == s.type
def test_subject_types_unknown():
    s = association.Subject(Curie.from_str("HELLO:12345"), "Hello object",
                            ["fullname"], [], [],
                            association.Curie.from_str("NCBITaxon:12345"))
    assert [Curie(namespace="CHEBI", identity="33695")] == s.type