Example #1
0
def test_agent_text_storage():
    A1 = Agent('A', db_refs={'TEXT': 'A'})
    A2 = Agent('A', db_refs={'TEXT': 'alpha'})
    B1 = Agent('B', db_refs={'TEXT': 'bag'})
    B2 = Agent('B', db_refs={'TEXT': 'bug'})
    C = Agent('C')
    D = Agent('D')
    inp = [
        Complex([A1, B1], evidence=Evidence(text='A complex bag.')),
        Complex([B2, A2], evidence=Evidence(text='bug complex alpha once.')),
        Complex([B2, A2], evidence=Evidence(text='bug complex alpha again.')),
        Complex([A1, C, B2], evidence=Evidence(text='A complex C bug.')),
        Phosphorylation(A1, B1, evidence=Evidence(text='A phospo bags.')),
        Phosphorylation(A2, B2, evidence=Evidence(text='alpha phospho bugs.')),
        Conversion(D, [A1, B1], [C, D],
                   evidence=Evidence(text='D: A bag -> C D')),
        Conversion(D, [B1, A2], [C, D],
                   evidence=Evidence(text='D: bag a -> C D')),
        Conversion(D, [B2, A2], [D, C],
                   evidence=Evidence(text='D: bug a -> D C')),
        Conversion(D, [B1, A1], [C, D],
                   evidence=Evidence(text='D: bag A -> C D')),
        Conversion(D, [A1], [A1, C], evidence=Evidence(text='D: A -> A C'))
    ]
    pa = Preassembler(bio_ontology, inp)
    unq1 = pa.combine_duplicates()
    assert len(unq1) == 5, len(unq1)
    assert all([len(ev.annotations['prior_uuids']) == 1
                for s in unq1 for ev in s.evidence
                if len(s.evidence) > 1]),\
        'There can only be one prior evidence per uuid at this stage.'
    ev_uuid_dict = {
        ev.annotations['prior_uuids'][0]: ev.annotations['agents']
        for s in unq1 for ev in s.evidence
    }
    for s in inp:
        raw_text = [
            ag.db_refs.get('TEXT') for ag in s.agent_list(deep_sorted=True)
        ]
        assert raw_text == ev_uuid_dict[s.uuid]['raw_text'],\
            str(raw_text) + '!=' + str(ev_uuid_dict[s.uuid]['raw_text'])

    # Now run pa on the above corpus plus another statement.
    inp2 = unq1 + [
        Complex([A1, C, B1], evidence=Evidence(text='A complex C bag.'))
    ]
    pa2 = Preassembler(bio_ontology, inp2)
    unq2 = pa2.combine_duplicates()
    assert len(unq2) == 5, len(unq2)
    old_ev_list = []
    new_ev = None
    for s in unq2:
        for ev in s.evidence:
            if ev.text == inp2[-1].evidence[0].text:
                new_ev = ev
            else:
                old_ev_list.append(ev)
    assert all([len(ev.annotations['prior_uuids']) == 2 for ev in old_ev_list])
    assert new_ev
    assert len(new_ev.annotations['prior_uuids']) == 1
Example #2
0
def test_normalize_opposites():
    concept1 = 'wm/concept/causal_factor/food_security/food_stability'
    concept2 = 'wm/concept/causal_factor/food_insecurity/food_instability'
    concept3 = ('wm/concept/causal_factor/crisis_and_disaster/'
                'environmental_disasters/natural_disaster/flooding')

    # First test the inherently positive being the main grounding
    dbr = {'WM': [(concept1, 1.0), (concept2, 0.5), (concept3, 0.1)]}
    ev = Event(Concept('x', db_refs=dbr), delta=QualitativeDelta(polarity=1))
    pa = Preassembler(world_ontology, stmts=[ev])
    pa.normalize_opposites(ns='WM')
    # We are normalizing to food supply since that is the inherently
    # positive concept
    assert pa.stmts[0].concept.db_refs['WM'][0] == \
        (concept1, 1.0), pa.stmts[0].concept.db_refs['WM']
    assert pa.stmts[0].concept.db_refs['WM'][1] == \
        (concept1, 0.5), pa.stmts[0].concept.db_refs['WM']
    assert pa.stmts[0].concept.db_refs['WM'][2] == \
        (concept3, 0.1), pa.stmts[0].concept.db_refs['WM']
    assert pa.stmts[0].delta.polarity == 1

    # Next test the inherently negative being the main grounding
    dbr = {'WM': [(concept2, 1.0), (concept1, 0.5), (concept3, 0.1)]}
    ev = Event(Concept('x', db_refs=dbr), delta=QualitativeDelta(polarity=1))
    pa = Preassembler(world_ontology, stmts=[ev])
    pa.normalize_opposites(ns='WM')
    # We are normalizing to food supply since that is the inherently
    # positive concept
    assert pa.stmts[0].concept.db_refs['WM'][0] == \
           (concept1, 1.0), pa.stmts[0].concept.db_refs['WM']
    assert pa.stmts[0].concept.db_refs['WM'][1] == \
           (concept1, 0.5), pa.stmts[0].concept.db_refs['WM']
    assert pa.stmts[0].concept.db_refs['WM'][2] == \
           (concept3, 0.1), pa.stmts[0].concept.db_refs['WM']
    assert pa.stmts[0].delta.polarity == -1
Example #3
0
def test_split_idx():
    ras = Agent('RAS', db_refs={'FPLX': 'RAS'})
    kras = Agent('KRAS', db_refs={'HGNC': '6407'})
    hras = Agent('HRAS', db_refs={'HGNC': '5173'})
    st1 = Phosphorylation(Agent('x'), ras)
    st2 = Phosphorylation(Agent('x'), kras)
    st3 = Phosphorylation(Agent('x'), hras)
    pa = Preassembler(bio_ontology)
    maps = pa._generate_id_maps([st1, st2, st3])
    assert (1, 0) in maps, maps
    assert (2, 0) in maps, maps
    assert pa._comparison_counter == 2
    pa = Preassembler(bio_ontology)
    maps = pa._generate_id_maps([st1, st2, st3], split_idx=1)
    assert (2, 0) in maps, maps
    assert (1, 0) not in maps, maps
    assert pa._comparison_counter == 1

    # Test other endpoints
    refinements = pa._generate_relations([st1, st2, st3])
    assert refinements == \
        {st2.get_hash(): {st1.get_hash()},
         st3.get_hash(): {st1.get_hash()}}, refinements

    refinements = pa._generate_relation_tuples([st1, st2, st3])
    assert refinements == \
        {(st2.get_hash(), st1.get_hash()),
         (st3.get_hash(), st1.get_hash())}
Example #4
0
def test_event_assemble_location():
    rainfall = Concept('rainfall')
    loc1 = RefContext(name='x', db_refs={'GEOID': '1'})
    loc2 = RefContext(name='x', db_refs={'GEOID': '2'})
    ev1 = Event(rainfall, context=WorldContext(geo_location=loc1))
    ev2 = Event(rainfall, context=WorldContext(geo_location=loc2))

    pa = Preassembler(hierarchies=hierarchies, stmts=[ev1, ev2],
                      matches_fun=None)
    unique_stmts = pa.combine_duplicates()

    assert len(unique_stmts) == 1
    pa = Preassembler(hierarchies=hierarchies, stmts=[ev1, ev2],
                      matches_fun=location_matches)
    unique_stmts = pa.combine_duplicates()
    assert len(unique_stmts) == 2
Example #5
0
def test_association_refinement():
    unrelated = 'wm/concept/causal_factor/wild_food_sources'
    parent = 'wm/concept/causal_factor/health_and_life'
    child = 'wm/concept/causal_factor/health_and_life/' \
        'living_condition/food_safety'
    parent_event = Event(Concept('parent', db_refs={'WM': [(parent, 1.0)]}))
    unrelated_event = \
        Event(Concept('unrelated', db_refs={'WM': [(unrelated, 1.0)]}))
    child_event = Event(Concept('child', db_refs={'WM': [(child, 1.0)]}))
    st1 = Association([parent_event, unrelated_event],
                      evidence=[Evidence(source_api='eidos1')])
    st2 = Association([unrelated_event, parent_event],
                      evidence=[Evidence(source_api='eidos2')])
    st3 = Association([parent_event, child_event],
                      evidence=[Evidence(source_api='eidos3')])
    st4 = Association([unrelated_event, child_event],
                      evidence=[Evidence(source_api='eidos4')])
    pa = Preassembler(world_ontology, [st1, st2, st3, st4])
    unique_stmts = pa.combine_duplicates()
    assert len(unique_stmts) == 3
    top_level_stmts = pa.combine_related()
    assert len(top_level_stmts) == 2, top_level_stmts

    names = {
        tuple(sorted(e.concept.name for e in stmt.members)): stmt
        for stmt in top_level_stmts
    }
    stmt = names[('child', 'unrelated')]
    assert len(stmt.supported_by) == 1
    assert {e.concept.name for e in stmt.supported_by[0].members} == \
           {'parent', 'unrelated'}
Example #6
0
def test_combine_duplicates():
    raf = Agent('RAF1')
    mek = Agent('MEK1')
    erk = Agent('ERK2')
    p1 = Phosphorylation(raf, mek, evidence=Evidence(text='foo'))
    p2 = Phosphorylation(raf, mek, evidence=Evidence(text='bar'))
    p3 = Phosphorylation(raf, mek, evidence=Evidence(text='baz'))
    p4 = Phosphorylation(raf, mek, evidence=Evidence(text='beep'))
    p5 = Phosphorylation(mek, erk, evidence=Evidence(text='foo2'))
    p6 = Dephosphorylation(mek, erk, evidence=Evidence(text='bar2'))
    p7 = Dephosphorylation(mek, erk, evidence=Evidence(text='baz2'))
    p8 = Dephosphorylation(mek, erk, evidence=Evidence(text='beep2'))
    p9 = Dephosphorylation(Agent('SRC'),
                           Agent('KRAS'),
                           evidence=Evidence(text='beep'))
    stmts = [p1, p2, p3, p4, p5, p6, p7, p8, p9]
    pa = Preassembler(hierarchies, stmts=stmts)
    pa.combine_duplicates()
    # The statements come out sorted by their matches_key
    assert (len(pa.unique_stmts) == 4)
    assert (pa.unique_stmts[0].matches(p6))  # MEK dephos ERK
    assert (len(pa.unique_stmts[0].evidence) == 3)
    assert (pa.unique_stmts[1].matches(p9))  # SRC dephos KRAS
    assert (len(pa.unique_stmts[1].evidence) == 1)
    assert (pa.unique_stmts[2].matches(p5))  # MEK phos ERK
    assert (len(pa.unique_stmts[2].evidence) == 1)
    assert (pa.unique_stmts[3].matches(p1))  # RAF phos MEK
    assert (len(pa.unique_stmts[3].evidence) == 4)
Example #7
0
def test_pathsfromto():
    bp = biopax.process_pc_pathsfromto(['MAP2K1'], ['MAPK1'])
    bp.get_phosphorylation()
    assert_pmids(bp.statements)
    pre = Preassembler(hierarchies, bp.statements)
    pre.combine_related()
    assert unicode_strs(pre.unique_stmts)
Example #8
0
def test_translocation():
    st1 = Translocation(Agent('AKT'), None, None)
    st2 = Translocation(Agent('AKT'), None, 'plasma membrane')
    st3 = Translocation(Agent('AKT'), None, 'nucleus')
    pa = Preassembler(bio_ontology, stmts=[st1, st2, st3])
    pa.combine_related()
    assert len(pa.related_stmts) == 2, pa.related_stmts
Example #9
0
def test_modification_refinement_noenz2():
    """A more specific modification statement should be supported by a more
    generic modification statement.

    Similar to test_modification_refinement_noenz for statements where one
    argument is associated with a component in the hierarchy (SIRT1 in this
    case) but the other is not (BECN1).
    """
    sirt1 = Agent('SIRT1',
                  db_refs={
                      'HGNC': '14929',
                      'UP': 'Q96EB6',
                      'TEXT': 'SIRT1'
                  })
    becn1 = Agent('BECN1',
                  db_refs={
                      'HGNC': '1034',
                      'UP': 'Q14457',
                      'TEXT': 'Beclin 1'
                  })
    st1 = Deacetylation(sirt1, becn1)
    st2 = Deacetylation(None, becn1)
    pa = Preassembler(bio_ontology, stmts=[st1, st2])
    stmts = pa.combine_related()
    # The top-level list should contain only one statement, the more specific
    # modification, supported by the less-specific modification.
    assert (len(stmts) == 1)
    assert (stmts[0].equals(st1))
    assert (len(stmts[0].supported_by) == 1)
    assert (stmts[0].supported_by[0].equals(st2))
    assert (stmts[0].supported_by[0].supports[0].equals(st1))
Example #10
0
def test_flatten_evidence_hierarchy():
    braf = Agent('BRAF')
    mek = Agent('MAP2K1')
    st1 = Phosphorylation(braf, mek, evidence=[Evidence(text='foo')])
    st2 = Phosphorylation(braf,
                          mek,
                          'S',
                          '218',
                          evidence=[Evidence(text='bar')])
    pa = Preassembler(bio_ontology, stmts=[st1, st2])
    pa.combine_related()
    assert len(pa.related_stmts) == 1
    flattened = flatten_evidence(pa.related_stmts)
    assert len(flattened) == 1
    top_stmt = flattened[0]
    assert len(top_stmt.evidence) == 2
    assert 'bar' in [e.text for e in top_stmt.evidence]
    assert 'foo' in [e.text for e in top_stmt.evidence]
    assert len(top_stmt.supported_by) == 1
    supporting_stmt = top_stmt.supported_by[0]
    assert len(supporting_stmt.evidence) == 1
    assert supporting_stmt.evidence[0].text == 'foo'
    supporting_stmt.evidence[0].text = 'changed_foo'
    assert supporting_stmt.evidence[0].text == 'changed_foo'
    assert 'changed_foo' not in [e.text for e in top_stmt.evidence]
    assert 'foo' in [e.text for e in top_stmt.evidence]
    assert {ev.annotations.get('support_type') for ev in top_stmt.evidence} \
        == {'direct', 'supported_by'}
 def __init__(self, n_proc=1, batch_size=10000, print_logs=False):
     self.n_proc = n_proc
     self.batch_size = batch_size
     self.pa = Preassembler(hierarchies)
     self.__tag = 'Unpurposed'
     self.__print_logs = print_logs
     return
Example #12
0
def test_modification_refinement_residue_noenz():
    erbb3 = Agent('Erbb3')
    st1 = Phosphorylation(None, erbb3)
    st2 = Phosphorylation(None, erbb3, 'Y')
    pa = Preassembler(bio_ontology, stmts=[st1, st2])
    pa.combine_related()
    assert len(pa.related_stmts) == 1
Example #13
0
def test_combine_duplicates():
    raf = Agent('RAF1')
    mek = Agent('MEK1')
    erk = Agent('ERK2')
    p1 = Phosphorylation(raf, mek, evidence=Evidence(text='foo'))
    p2 = Phosphorylation(raf, mek, evidence=Evidence(text='bar'))
    p3 = Phosphorylation(raf, mek, evidence=Evidence(text='baz'))
    p4 = Phosphorylation(raf, mek, evidence=Evidence(text='beep'))
    p5 = Phosphorylation(mek, erk, evidence=Evidence(text='foo2'))
    p6 = Dephosphorylation(mek, erk, evidence=Evidence(text='bar2'))
    p7 = Dephosphorylation(mek, erk, evidence=Evidence(text='baz2'))
    p8 = Dephosphorylation(mek, erk, evidence=Evidence(text='beep2'))
    p9 = Dephosphorylation(Agent('SRC'),
                           Agent('KRAS'),
                           evidence=Evidence(text='beep'))
    stmts = [p1, p2, p3, p4, p5, p6, p7, p8, p9]
    pa = Preassembler(bio_ontology, stmts=stmts)
    pa.combine_duplicates()
    # The statements come out sorted by their matches_key
    assert len(pa.unique_stmts) == 4, len(pa.unique_stmts)
    num_evs = [len(s.evidence) for s in pa.unique_stmts]
    assert pa.unique_stmts[0].matches(p6)  # MEK dephos ERK
    assert num_evs[0] == 3, num_evs[0]
    assert pa.unique_stmts[1].matches(p9)  # SRC dephos KRAS
    assert num_evs[1] == 1, num_evs[1]
    assert pa.unique_stmts[2].matches(p5)  # MEK phos ERK
    assert num_evs[2] == 1, num_evs[2]
    assert pa.unique_stmts[3].matches(p1)  # RAF phos MEK
    assert num_evs[3] == 4, num_evs[3]
Example #14
0
def test_association_refinement():
    health = 'UN/entities/human/health'
    food = 'UN/entities/human/food'
    food_security = 'UN/entities/human/food/food_security'
    eh = Event(Concept('health', db_refs={'UN': [(health, 1.0)]}))
    ef = Event(Concept('food', db_refs={'UN': [(food, 1.0)]}))
    efs = Event(
        Concept('food security', db_refs={'UN': [(food_security, 1.0)]}))
    st1 = Association([eh, ef], evidence=[Evidence(source_api='eidos1')])
    st2 = Association([ef, eh], evidence=[Evidence(source_api='eidos2')])
    st3 = Association([eh, efs], evidence=[Evidence(source_api='eidos3')])
    st4 = Association([ef, efs], evidence=[Evidence(source_api='eidos4')])
    eidos_ont = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             '../sources/eidos/eidos_ontology.rdf')
    hm = HierarchyManager(eidos_ont, True, True)
    hierarchies = {'entity': hm}
    pa = Preassembler(hierarchies, [st1, st2, st3, st4])
    unique_stmts = pa.combine_duplicates()  # debugging
    assert len(unique_stmts) == 3
    rel_stmts = pa.combine_related()
    assert len(rel_stmts) == 2
    eh_efs_stmt = [
        st for st in rel_stmts
        if (st.members[0].concept.name in {'health', 'food security'}
            and st.members[1].concept.name in {'health', 'food security'})
    ][0]
    assert len(eh_efs_stmt.supported_by) == 1
    assert (eh_efs_stmt.supported_by[0].members[0].concept.name
            in {'food', 'health'})
    assert (eh_efs_stmt.supported_by[0].members[1].concept.name
            in {'food', 'health'})
Example #15
0
def test_render_stmt_graph():
    braf = Agent('BRAF', db_refs={'HGNC': '1097'})
    mek1 = Agent('MAP2K1', db_refs={'HGNC': '6840'})
    mek = Agent('MEK', db_refs={'FPLX': 'MEK'})
    # Statements
    p0 = Phosphorylation(braf, mek)
    p1 = Phosphorylation(braf, mek1)
    p2 = Phosphorylation(braf, mek1, position='218')
    p3 = Phosphorylation(braf, mek1, position='222')
    p4 = Phosphorylation(braf, mek1, 'serine')
    p5 = Phosphorylation(braf, mek1, 'serine', '218')
    p6 = Phosphorylation(braf, mek1, 'serine', '222')
    stmts = [p0, p1, p2, p3, p4, p5, p6]
    pa = Preassembler(bio_ontology, stmts=stmts)
    pa.combine_related()
    graph = render_stmt_graph(pa.related_stmts, reduce=False)
    # One node for each statement
    assert len(graph.nodes()) == 7
    # Edges:
    # p0 supports p1-p6 = 6 edges
    # p1 supports p2-p6 = 5 edges
    # p2 supports p5 = 1 edge
    # p3 supports p6 = 1 edge
    # p4 supports p5-p6 = 2 edges
    # (p5 and p6 support none--they are top-level)
    # 6 + 5 + 1 + 1 + 2 = 15 edges
    assert len(graph.edges()) == 15
Example #16
0
def test_split_idx():
    ras = Agent('RAS', db_refs={'FPLX': 'RAS'})
    kras = Agent('KRAS', db_refs={'HGNC': '6407'})
    hras = Agent('HRAS', db_refs={'HGNC': '5173'})
    st1 = Phosphorylation(Agent('x'), ras)
    st2 = Phosphorylation(Agent('x'), kras)
    st3 = Phosphorylation(Agent('x'), hras)
    pa = Preassembler(bio_ontology)
    maps = pa._generate_id_maps([st1, st2, st3])
    assert (1, 0) in maps, maps
    assert (2, 0) in maps, maps
    assert pa._comparison_counter == 2
    pa = Preassembler(bio_ontology)
    maps = pa._generate_id_maps([st1, st2, st3], split_idx=1)
    assert (2, 0) in maps, maps
    assert (1, 0) not in maps, maps
    assert pa._comparison_counter == 1
Example #17
0
def test_uppro_assembly():
    ag1 = Agent('x', db_refs={'UP': 'P01019', 'UPPRO': 'PRO_0000032457'})
    ag2 = Agent('y', db_refs={'UP': 'P01019', 'UPPRO': 'PRO_0000032458'})
    assert ag1.get_grounding() == ('UPPRO', ag1.db_refs['UPPRO'])
    assert ag2.get_grounding() == ('UPPRO', ag2.db_refs['UPPRO'])
    stmt1 = Phosphorylation(None, ag1)
    stmt2 = Phosphorylation(None, ag2)
    assert stmt1.matches_key() != stmt2.matches_key()
    pa = Preassembler(bio_ontology, [stmt1, stmt2])
    unique_stmts = pa.combine_duplicates()
    assert len(unique_stmts) == 2, unique_stmts

    from indra.tools import assemble_corpus as ac
    stmts = ac.map_grounding([stmt1, stmt2])
    pa = Preassembler(bio_ontology, stmts)
    unique_stmts = pa.combine_duplicates()
    assert len(unique_stmts) == 2
Example #18
0
def test_duplicates():
    src = Agent('SRC', db_refs={'HGNC': '11283'})
    ras = Agent('RAS', db_refs={'FA': '03663'})
    st1 = Phosphorylation(src, ras)
    st2 = Phosphorylation(src, ras)
    pa = Preassembler(bio_ontology, stmts=[st1, st2])
    pa.combine_duplicates()
    assert len(pa.unique_stmts) == 1
Example #19
0
def process_statements(stmts, **generate_id_map_kwargs):
    stmts = ac.map_grounding(stmts)
    stmts = ac.map_sequence(stmts)
    pa = Preassembler(hierarchies)
    unique_stmts = make_unique_statement_set(pa, stmts)
    match_key_maps = get_match_key_maps(pa, unique_stmts,
                                        **generate_id_map_kwargs)
    return unique_stmts, match_key_maps
Example #20
0
 def __init__(self, n_proc=1, batch_size=10000, print_logs=False):
     self.n_proc = n_proc
     self.batch_size = batch_size
     self.pa = Preassembler(bio_ontology)
     self.__tag = 'Unpurposed'
     self.__print_logs = print_logs
     self.pickle_stashes = None
     return
Example #21
0
def analyze(filename, plot=False):
    # Load the file
    results = load_file(filename)

    # Put together a list of all statements
    all_stmts = [stmt for paper_stmts in results.values()
                      for stmt in paper_stmts]

    # Map grounding
    logger.info('Mapping grounding...')
    gmap = gm.GroundingMapper(gm.default_grounding_map)
    map_stmts = gmap.map_agents(all_stmts)
    map_stmts = gmap.rename_agents(map_stmts)

    # Combine duplicates
    logger.info('Removing duplicates...')
    pa = Preassembler(hierarchies, map_stmts)
    pa.combine_duplicates()

    # Map GO IDs to genes and associated statements
    logger.info('Building map from GO IDs to stmts')
    go_gene_map = {}
    go_name_map = {}
    for stmt in pa.unique_stmts:
        (bp_name, go, gene) = go_gene_pair(stmt)
        if bp_name is None and go is None and gene is None:
            continue
        go_gene_list = go_gene_map.get(go, [])
        go_gene_list.append((gene, stmt))
        go_gene_map[go] = go_gene_list
        go_name_set = go_name_map.get(go, set([]))
        go_name_set.add(bp_name)
        go_name_map[go] = go_name_set

    # Iterate over all of the GO IDs and compare the annotated genes in GO
    # to the ones from the given statements
    go_stmt_map = {}
    for ix, go_id in enumerate(go_gene_map.keys()):
        logger.info('Getting genes for %s (%s) from GO (%d of %d)' %
                    (go_id, ','.join(list(go_name_map[go_id])),
                     ix+1, len(go_gene_map.keys())))
        genes_from_go = get_genes_for_go_id(go_id)
        gene_stmt_list = go_gene_map[go_id]
        in_go = []
        not_in_go = []
        for (gene, stmt) in gene_stmt_list:
            if gene in genes_from_go:
                in_go.append(stmt)
            else:
                not_in_go.append(stmt)
        go_stmt_map[go_id] = {'names': list(go_name_map[go_id]),
                              'in_go': in_go, 'not_in_go': not_in_go}

    with open('go_stmt_map.pkl', 'wb') as f:
        pickle.dump(go_stmt_map, f, protocol=2)

    if plot:
        plot_stmt_counts(go_stmt_map, 'go_stmts.pdf')
Example #22
0
def test_grounding_aggregation():
    braf1 = Agent('BRAF', db_refs={'TEXT': 'braf', 'HGNC': '1097'})
    braf2 = Agent('BRAF', db_refs={'TEXT': 'BRAF'})
    braf3 = Agent('BRAF', db_refs={'TEXT': 'Braf', 'UP': 'P15056'})
    st1 = Phosphorylation(None, braf1)
    st2 = Phosphorylation(None, braf2)
    st3 = Phosphorylation(None, braf3)
    pa = Preassembler(hierarchies, stmts=[st1, st2, st3])
    unique_stmts = pa.combine_duplicates()
    assert len(unique_stmts) == 3
Example #23
0
def test_agent_coordinates():
    path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                        'reach_coordinates.json')
    stmts = reach.process_json_file(path).statements
    pa = Preassembler(bio_ontology, stmts)
    unique_stmt = pa.combine_duplicates()[0]
    agent_annots = [ev.annotations['agents'] for ev in unique_stmt.evidence]
    assert all(a['raw_text'] == ['MEK1', 'ERK2'] for a in agent_annots)
    assert {tuple(a['coords'])
            for a in agent_annots} == {((21, 25), (0, 4)), ((0, 4), (15, 19))}
Example #24
0
def test_homodimer_refinement():
    egfr = Agent('EGFR')
    erbb = Agent('ERBB2')
    st1 = Complex([erbb, erbb])
    st2 = Complex([erbb, egfr])
    pa = Preassembler(bio_ontology, stmts=[st1, st2])
    pa.combine_duplicates()
    assert len(pa.unique_stmts) == 2
    pa.combine_related()
    assert len(pa.related_stmts) == 2
Example #25
0
def test_complex_refinement_order():
    st1 = Complex([Agent('MED23'), Agent('ELK1')])
    st2 = Complex([
        Agent('ELK1', mods=[ModCondition('phosphorylation')]),
        Agent('MED23')
    ])
    pa = Preassembler(bio_ontology, stmts=[st1, st2])
    pa.combine_duplicates()
    pa.combine_related()
    assert len(pa.related_stmts) == 1
Example #26
0
def test_complex_refinement():
    ras = Agent('RAS')
    raf = Agent('RAF')
    mek = Agent('MEK')
    st1 = Complex([ras, raf])
    st2 = Complex([mek, ras, raf])
    pa = Preassembler(bio_ontology, stmts=[st1, st2])
    pa.combine_related()
    assert len(pa.unique_stmts) == 2
    assert len(pa.related_stmts) == 2
Example #27
0
def test_find_contradicts():
    st1 = Inhibition(Agent('a'), Agent('b'))
    st2 = Activation(Agent('a'), Agent('b'))
    st3 = IncreaseAmount(Agent('a'), Agent('b'))
    st4 = DecreaseAmount(Agent('a'), Agent('b'))
    pa = Preassembler(hierarchies, [st1, st2, st3, st4])
    contradicts = pa.find_contradicts()
    assert len(contradicts) == 2
    for s1, s2 in contradicts:
        assert {s1.uuid, s2.uuid} in ({st1.uuid,
                                       st2.uuid}, {st3.uuid, st4.uuid})
Example #28
0
def test_grounding_aggregation_complex():
    mek = Agent('MEK')
    braf1 = Agent('BRAF', db_refs={'TEXT': 'braf', 'HGNC': '1097'})
    braf2 = Agent('BRAF', db_refs={'TEXT': 'BRAF', 'dummy': 'dummy'})
    braf3 = Agent('BRAF', db_refs={'TEXT': 'Braf', 'UP': 'P15056'})
    st1 = Complex([mek, braf1])
    st2 = Complex([braf2, mek])
    st3 = Complex([mek, braf3])
    pa = Preassembler(bio_ontology, stmts=[st1, st2, st3])
    unique_stmts = pa.combine_duplicates()
    assert len(unique_stmts) == 3, unique_stmts
Example #29
0
def test_normalize_opposites_influence():
    concept1 = 'wm/concept/causal_factor/food_security/food_stability'
    concept2 = 'wm/concept/causal_factor/food_insecurity/food_instability'
    dbr1 = {'WM': [(concept1, 1.0), (concept2, 0.5)]}
    dbr2 = {'WM': [(concept2, 1.0), (concept1, 0.5)]}
    stmt = Influence(
        Event(Concept('x', db_refs=dbr1), delta=QualitativeDelta(polarity=1)),
        Event(Concept('y', db_refs=dbr2), delta=QualitativeDelta(polarity=-1)))
    pa = Preassembler(world_ontology, stmts=[stmt])
    pa.normalize_opposites(ns='WM')
    assert pa.stmts[0].subj.delta.polarity == 1
    assert pa.stmts[0].obj.delta.polarity == 1
Example #30
0
def test_conversion_refinement():
    ras = Agent('RAS', db_refs={'FPLX': 'RAS'})
    hras = Agent('HRAS', db_refs={'HGNC': '5173'})
    gtp = Agent('GTP')
    gdp = Agent('GDP')
    st1 = Conversion(ras, gtp, gdp)
    st2 = Conversion(hras, gtp, gdp)
    st3 = Conversion(hras, [gtp, gdp], gdp)
    st4 = Conversion(hras, [gdp, gtp], gdp)
    pa = Preassembler(bio_ontology, stmts=[st1, st2, st3, st4])
    toplevel_stmts = pa.combine_related()
    assert len(toplevel_stmts) == 2