Пример #1
0
    def run_assembly(self):
        """Run INDRA's assembly pipeline on the Statements."""
        self.eliminate_copies()
        stmts = self.get_indra_stmts()
        stmts = self.filter_event_association(stmts)
        stmts = ac.filter_no_hypothesis(stmts)
        if not self.assembly_config.get('skip_map_grounding'):
            stmts = ac.map_grounding(stmts)
        if self.assembly_config.get('standardize_names'):
            ac.standardize_names_groundings(stmts)
        if self.assembly_config.get('filter_ungrounded'):
            score_threshold = self.assembly_config.get('score_threshold')
            stmts = ac.filter_grounded_only(stmts,
                                            score_threshold=score_threshold)
        if self.assembly_config.get('merge_groundings'):
            stmts = ac.merge_groundings(stmts)
        if self.assembly_config.get('merge_deltas'):
            stmts = ac.merge_deltas(stmts)
        relevance_policy = self.assembly_config.get('filter_relevance')
        if relevance_policy:
            stmts = self.filter_relevance(stmts, relevance_policy)
        if not self.assembly_config.get('skip_filter_human'):
            stmts = ac.filter_human_only(stmts)
        if not self.assembly_config.get('skip_map_sequence'):
            stmts = ac.map_sequence(stmts)
        # Use WM hierarchies and belief scorer for WM preassembly
        preassembly_mode = self.assembly_config.get('preassembly_mode')
        if preassembly_mode == 'wm':
            hierarchies = get_wm_hierarchies()
            belief_scorer = get_eidos_scorer()
            stmts = ac.run_preassembly(stmts,
                                       return_toplevel=False,
                                       belief_scorer=belief_scorer,
                                       hierarchies=hierarchies)
        else:
            stmts = ac.run_preassembly(stmts, return_toplevel=False)
        belief_cutoff = self.assembly_config.get('belief_cutoff')
        if belief_cutoff is not None:
            stmts = ac.filter_belief(stmts, belief_cutoff)
        stmts = ac.filter_top_level(stmts)

        if self.assembly_config.get('filter_direct'):
            stmts = ac.filter_direct(stmts)
            stmts = ac.filter_enzyme_kinase(stmts)
            stmts = ac.filter_mod_nokinase(stmts)
            stmts = ac.filter_transcription_factor(stmts)

        if self.assembly_config.get('mechanism_linking'):
            ml = MechLinker(stmts)
            ml.gather_explicit_activities()
            ml.reduce_activities()
            ml.gather_modifications()
            ml.reduce_modifications()
            ml.gather_explicit_activities()
            ml.replace_activations()
            ml.require_active_forms()
            stmts = ml.statements

        self.assembled_stmts = stmts
Пример #2
0
def test_reduce_mods1():
    phos1 = Phosphorylation(Agent('b'), Agent('a'))
    phos2 = Phosphorylation(Agent('c'), Agent('a'), 'T')
    phos3 = Phosphorylation(Agent('d'), Agent('a'), 'T', '143')
    ml = MechLinker([phos1, phos2, phos3])
    ml.gather_modifications()
    ml.reduce_modifications()
    assert len(ml.statements) == 3
    for st in ml.statements:
        assert st.residue == 'T'
        assert st.position == '143'
Пример #3
0
def test_reduce_mods1():
    phos1 = Phosphorylation(Agent('b'), Agent('a'))
    phos2 = Phosphorylation(Agent('c'), Agent('a'), 'T')
    phos3 = Phosphorylation(Agent('d'), Agent('a'), 'T', '143')
    ml = MechLinker([phos1, phos2, phos3])
    ml.gather_modifications()
    ml.reduce_modifications()
    assert len(ml.statements) == 3
    for st in ml.statements:
        assert st.residue == 'T'
        assert st.position == '143'
Пример #4
0
def test_reduce_mods2():
    mc1 = ModCondition('phosphorylation', 'S', '123', False)
    mc2 = ModCondition('phosphorylation', 'S', None, True)
    mc3 = ModCondition('phosphorylation', 'T')
    mc4 = ModCondition('phosphorylation', 'T', '111')
    mc5 = ModCondition('phosphorylation', 'T', '999')
    mc6 = ModCondition('phosphorylation')
    mc7 = ModCondition('phosphorylation', None, '999')
    st1 = Activation(Agent('KRAS'), Agent('BRAF', mods=[mc1]))
    st2 = Activation(Agent('KRAS'), Agent('BRAF', mods=[mc2]))
    st3 = Activation(Agent('KRAS'), Agent('BRAF', mods=[mc3]))
    st4 = Activation(Agent('KRAS'), Agent('BRAF', mods=[mc4]))
    st5 = Activation(Agent('KRAS'), Agent('BRAF', mods=[mc5]))
    st6 = Activation(Agent('KRAS'), Agent('BRAF', mods=[mc6]))
    st7 = Activation(Agent('KRAS'), Agent('BRAF', mods=[mc7]))
    ml = MechLinker([st1, st2, st3, st4, st5, st6, st7])
    ml.gather_modifications()
    ml.reduce_modifications()
    assert len(ml.statements) == 7
    mc_red1 = ml.statements[0].obj.mods[0]
    mc_red2 = ml.statements[1].obj.mods[0]
    mc_red3 = ml.statements[2].obj.mods[0]
    mc_red4 = ml.statements[3].obj.mods[0]
    mc_red5 = ml.statements[4].obj.mods[0]
    mc_red6 = ml.statements[5].obj.mods[0]
    mc_red7 = ml.statements[6].obj.mods[0]
    # These ones stay the same because they shouldn't be reduced
    assert mc_red1.__dict__ == mc1.__dict__
    assert mc_red3.__dict__ == mc3.__dict__
    assert mc_red4.__dict__ == mc4.__dict__
    assert mc_red5.__dict__ == mc5.__dict__
    assert mc_red6.__dict__ == mc6.__dict__
    # mc2 has to be reduced to have position '123'
    assert mc_red2.mod_type == 'phosphorylation'
    assert mc_red2.residue == 'S'
    assert mc_red2.position == '123'
    assert mc_red2.is_modified == True
    # mc7 has to be reduced to have residue 'T'
    assert mc_red7.mod_type == 'phosphorylation'
    assert mc_red7.residue == 'T'
    assert mc_red7.position == '999'
    assert mc_red7.is_modified == True
Пример #5
0
def test_reduce_mods2():
    mc1 = ModCondition('phosphorylation', 'S', '123', False)
    mc2 = ModCondition('phosphorylation', 'S', None, True)
    mc3 = ModCondition('phosphorylation', 'T')
    mc4 = ModCondition('phosphorylation', 'T', '111')
    mc5 = ModCondition('phosphorylation', 'T', '999')
    mc6 = ModCondition('phosphorylation')
    mc7 = ModCondition('phosphorylation', None, '999')
    st1 = Activation(Agent('KRAS'), Agent('BRAF', mods=[mc1]))
    st2 = Activation(Agent('KRAS'), Agent('BRAF', mods=[mc2]))
    st3 = Activation(Agent('KRAS'), Agent('BRAF', mods=[mc3]))
    st4 = Activation(Agent('KRAS'), Agent('BRAF', mods=[mc4]))
    st5 = Activation(Agent('KRAS'), Agent('BRAF', mods=[mc5]))
    st6 = Activation(Agent('KRAS'), Agent('BRAF', mods=[mc6]))
    st7 = Activation(Agent('KRAS'), Agent('BRAF', mods=[mc7]))
    ml = MechLinker([st1, st2, st3, st4, st5, st6, st7])
    ml.gather_modifications()
    ml.reduce_modifications()
    assert len(ml.statements) == 7
    mc_red1 = ml.statements[0].obj.mods[0]
    mc_red2 = ml.statements[1].obj.mods[0]
    mc_red3 = ml.statements[2].obj.mods[0]
    mc_red4 = ml.statements[3].obj.mods[0]
    mc_red5 = ml.statements[4].obj.mods[0]
    mc_red6 = ml.statements[5].obj.mods[0]
    mc_red7 = ml.statements[6].obj.mods[0]
    # These ones stay the same because they shouldn't be reduced
    assert mc_red1.__dict__ == mc1.__dict__
    assert mc_red3.__dict__ == mc3.__dict__
    assert mc_red4.__dict__ == mc4.__dict__
    assert mc_red5.__dict__ == mc5.__dict__
    assert mc_red6.__dict__ == mc6.__dict__
    # mc2 has to be reduced to have position '123'
    assert mc_red2.mod_type == 'phosphorylation'
    assert mc_red2.residue == 'S'
    assert mc_red2.position == '123'
    assert mc_red2.is_modified == True
    # mc7 has to be reduced to have residue 'T'
    assert mc_red7.mod_type == 'phosphorylation'
    assert mc_red7.residue == 'T'
    assert mc_red7.position == '999'
    assert mc_red7.is_modified == True
Пример #6
0
def preprocess_stmts(stmts, data_genes):
    # Filter the INDRA Statements to be put into the model
    stmts = ac.filter_mutation_status(stmts,
                                      {'BRAF': [('V', '600', 'E')]}, ['PTEN'])
    stmts = ac.filter_by_type(stmts, Complex, invert=True)
    stmts = ac.filter_direct(stmts)
    stmts = ac.filter_belief(stmts, 0.95)
    stmts = ac.filter_top_level(stmts)
    stmts = ac.filter_gene_list(stmts, data_genes, 'all')
    stmts = ac.filter_enzyme_kinase(stmts)
    stmts = ac.filter_mod_nokinase(stmts)
    stmts = ac.filter_transcription_factor(stmts)
    # Simplify activity types
    ml = MechLinker(stmts)
    ml.gather_explicit_activities()
    ml.reduce_activities()
    ml.gather_modifications()
    ml.reduce_modifications()
    af_stmts = ac.filter_by_type(ml.statements, ActiveForm)
    non_af_stmts = ac.filter_by_type(ml.statements, ActiveForm, invert=True)
    af_stmts = ac.run_preassembly(af_stmts)
    stmts = af_stmts + non_af_stmts
    # Replace activations when possible
    ml = MechLinker(stmts)
    ml.gather_explicit_activities()
    ml.replace_activations()
    # Require active forms
    ml.require_active_forms()
    num_stmts = len(ml.statements)
    while True:
        # Remove inconsequential PTMs
        ml.statements = ac.filter_inconsequential_mods(ml.statements,
                                                       get_mod_whitelist())
        ml.statements = ac.filter_inconsequential_acts(ml.statements,
                                                       get_mod_whitelist())
        if num_stmts <= len(ml.statements):
            break
        num_stmts = len(ml.statements)
    stmts = ml.statements
    return stmts
Пример #7
0
def assemble_pysb(stmts, data_genes, contextualize=False):
    # Filter the INDRA Statements to be put into the model
    stmts = ac.filter_by_type(stmts, Complex, invert=True)
    stmts = ac.filter_direct(stmts)
    stmts = ac.filter_belief(stmts, 0.95)
    stmts = ac.filter_top_level(stmts)
    # Strip the extraneous supports/supported by here
    strip_supports(stmts)
    stmts = ac.filter_gene_list(stmts, data_genes, 'all')
    stmts = ac.filter_enzyme_kinase(stmts)
    stmts = ac.filter_mod_nokinase(stmts)
    stmts = ac.filter_transcription_factor(stmts)
    # Simplify activity types
    ml = MechLinker(stmts)
    ml.gather_explicit_activities()
    ml.reduce_activities()
    ml.gather_modifications()
    ml.reduce_modifications()
    stmts = normalize_active_forms(ml.statements)
    # Replace activations when possible
    ml = MechLinker(stmts)
    ml.gather_explicit_activities()
    ml.replace_activations()
    # Require active forms
    ml.require_active_forms()
    num_stmts = len(ml.statements)
    while True:
        # Remove inconsequential PTMs
        ml.statements = ac.filter_inconsequential_mods(ml.statements,
                                                       get_mod_whitelist())
        ml.statements = ac.filter_inconsequential_acts(ml.statements,
                                                       get_mod_whitelist())
        if num_stmts <= len(ml.statements):
            break
        num_stmts = len(ml.statements)
    stmts = ml.statements
    # Save the Statements here
    ac.dump_statements(stmts, prefixed_pkl('pysb_stmts'))


    # Add drug target Statements
    drug_target_stmts = get_drug_target_statements()
    stmts += drug_target_stmts

    # Just generate the generic model
    pa = PysbAssembler()
    pa.add_statements(stmts)
    model = pa.make_model()
    with open(prefixed_pkl('pysb_model'), 'wb') as f:
        pickle.dump(model, f)

    # Run this extra part only if contextualize is set to True
    if not contextualize:
        return

    cell_lines_no_data = ['COLO858', 'K2', 'MMACSF', 'MZ7MEL', 'WM1552C']
    for cell_line in cell_lines:
        if cell_line not in cell_lines_no_data:
            stmtsc = contextualize_stmts(stmts, cell_line, data_genes)
        else:
            stmtsc = stmts
        pa = PysbAssembler()
        pa.add_statements(stmtsc)
        model = pa.make_model()
        if cell_line not in cell_lines_no_data:
            contextualize_model(model, cell_line, data_genes)
        ac.dump_statements(stmtsc, prefixed_pkl('pysb_stmts_%s' % cell_line))
        with open(prefixed_pkl('pysb_model_%s' % cell_line), 'wb') as f:
            pickle.dump(model, f)