Beispiel #1
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})
Beispiel #2
0
def test_find_contradicts_refinement():
    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 = Dephosphorylation(Agent('x'), kras)
    st3 = Dephosphorylation(Agent('x'), hras)
    pa = Preassembler(bio_ontology, [st1, st2, st3])
    contradicts = pa.find_contradicts()
    assert len(contradicts) == 2
    for s1, s2 in contradicts:
        assert {s1.uuid, s2.uuid} in ({st1.uuid,
                                       st2.uuid}, {st1.uuid, st3.uuid})
Beispiel #3
0
def test_find_contradicts_refinement():
    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 = Dephosphorylation(Agent('x'), kras)
    st3 = Dephosphorylation(Agent('x'), hras)
    pa = Preassembler(hierarchies, [st1, st2, st3])
    contradicts = pa.find_contradicts()
    assert len(contradicts) == 2
    for s1, s2 in contradicts:
        assert {s1.uuid, s2.uuid} in ({st1.uuid, st2.uuid},
                                      {st1.uuid, st3.uuid})
Beispiel #4
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'))
    st5 = ActiveForm(Agent('a',
            mods=[ModCondition('phosphorylation', None, None, True)]),
            'kinase', True)
    st6 = ActiveForm(Agent('a',
            mods=[ModCondition('phosphorylation', None, None, True)]),
            'kinase', False)
    pa = Preassembler(hierarchies, [st1, st2, st3, st4, st5, st6])
    contradicts = pa.find_contradicts()
    assert len(contradicts) == 3
    for s1, s2 in contradicts:
        assert {s1.uuid, s2.uuid} in ({st1.uuid, st2.uuid},
                                      {st3.uuid, st4.uuid},
                                      {st5.uuid, st6.uuid})
Beispiel #5
0
def run_preassembly(statements, hierarchies):
    print('%d total statements' % len(statements))
    # Filter to grounded only
    statements = map_onto(statements)
    ac.dump_statements(statements, 'pi_mtg_demo_unfiltered.pkl')
    statements = ac.filter_grounded_only(statements, score_threshold=0.7)

    #statements = ac.filter_by_db_refs(statements, 'UN',
    #    ['conflict', 'food_security', 'precipitation'], policy='one',
    #    match_suffix=True)
    statements = ac.filter_by_db_refs(
        statements,
        'UN', [
            'conflict', 'food_security', 'flooding', 'food_production',
            'human_migration', 'drought', 'food_availability', 'market',
            'food_insecurity'
        ],
        policy='all',
        match_suffix=True)
    assume_polarity(statements)
    statements = filter_has_polarity(statements)

    # Make a Preassembler with the Eidos and TRIPS ontology
    pa = Preassembler(hierarchies, statements)
    # Make a BeliefEngine and run combine duplicates
    be = BeliefEngine()
    unique_stmts = pa.combine_duplicates()
    print('%d unique statements' % len(unique_stmts))
    be.set_prior_probs(unique_stmts)
    # Run combine related
    related_stmts = pa.combine_related(return_toplevel=False)
    be.set_hierarchy_probs(related_stmts)
    #related_stmts = ac.filter_belief(related_stmts, 0.8)
    # Filter to top-level Statements
    top_stmts = ac.filter_top_level(related_stmts)

    pa.stmts = top_stmts
    print('%d top-level statements' % len(top_stmts))
    conflicts = pa.find_contradicts()
    top_stmts = remove_contradicts(top_stmts, conflicts)

    ac.dump_statements(top_stmts, 'pi_mtg_demo.pkl')

    return top_stmts
Beispiel #6
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'))
    st5 = ActiveForm(
        Agent('a', mods=[ModCondition('phosphorylation', None, None, True)]),
        'kinase', True)
    st6 = ActiveForm(
        Agent('a', mods=[ModCondition('phosphorylation', None, None, True)]),
        'kinase', False)
    pa = Preassembler(bio_ontology, [st1, st2, st3, st4, st5, st6])
    contradicts = pa.find_contradicts()
    assert len(contradicts) == 3
    for s1, s2 in contradicts:
        assert {s1.uuid,
                s2.uuid} in ({st1.uuid,
                              st2.uuid}, {st3.uuid,
                                          st4.uuid}, {st5.uuid, st6.uuid})
#!/usr/bin/env python3
import pickle
from argparse import ArgumentParser
from os import path
from indra.preassembler import Preassembler
from indra.preassembler.hierarchy_manager import hierarchies

if __name__ == "__main__":
    description = ("find pairs of contradicting statements within a list "
                   "of statements")
    epilog = ("creates a pickle file containing a list of pairs of"
              "contradicting statements.")
    parser = ArgumentParser(description=description, epilog=epilog)
    help_text = "pickle file containing a list of statements."
    parser.add_argument("infile", help=help_text)
    args = parser.parse_args()

    infile = args.infile
    filename, file_extension = path.splitext(infile)
    outfile = filename + "_contradictions" + file_extension
    with open(infile, "rb") as f:
        stmts = pickle.load(f)

    preassembler = Preassembler(stmts=stmts, hierarchies=hierarchies)
    contra = preassembler.find_contradicts()

    with open(outfile, 'wb') as f:
        pickle.dump(contra, f)