def test_filter_mutation_status(): braf_mut = Agent('BRAF', mutations=MutCondition('600', 'V', 'E')) braf_other_mut = Agent('BRAF', mutations=MutCondition('555', 'K', 'G')) st1 = Phosphorylation(braf_mut, Agent('a')) st2 = Phosphorylation(braf_other_mut, Agent('a')) mutations = {'BRAF': [('V', '600', 'E')]} deletions = [] st_out = ac.filter_mutation_status([st1, st2], mutations, deletions) assert(len(st_out) == 1) mutations = {} deletions = ['a'] st_out = ac.filter_mutation_status([st1, st2], mutations, deletions) assert(len(st_out) == 0)
def contextualize_stmts(stmts, cell_line, genes): """Contextualize model at the level of INDRA Statements.""" to_remove = [] cell_line_ccle = cell_line + '_SKIN' # Remove genes with CNA = -2 print('Contextualize by CNA') cna = cbio_client.get_ccle_cna(genes, [cell_line_ccle])[cell_line_ccle] for gene in genes: if cna.get(gene) == -2: to_remove.append(gene) print('To remove CNA: %s' % gene) # Remove genes with transcripts in bottom 5% print('Contextualize by mRNA') mrna = cbio_client.get_ccle_mrna(genes, [cell_line_ccle])[cell_line_ccle] mrna_vals = [v for v in mrna.values() if v] if mrna_vals: thresh = numpy.percentile(mrna_vals, 5.0) for gene, val in mrna.items(): if val and val < thresh: to_remove.append(gene) print('To remove mRNA: %s' % gene) # Remove genes with nonsense mutations print('Contextualize by nonsense mutations') variants = read_ccle_variants(genes) to_remove_nonsense = list(variants['nonsense'][cell_line_ccle].keys()) if to_remove_nonsense: print('To remove nonsense: %s' % ', '.join(to_remove_nonsense)) to_remove += to_remove_nonsense # Remove Statements for these genes new_stmts = [] for stmt in stmts: any_to_remove = False for agent in stmt.agent_list(): if agent is not None and agent.name in to_remove: any_to_remove = True break if not any_to_remove: new_stmts.append(stmt) # Remove Statements with irrelevant mutations print('Contextualize by missense mutations') mutations = variants['missense'][cell_line_ccle] muts_to_use = {} for gene, mut_list in mutations.items(): muts_to_use[gene] = [] for mut in mut_list: muts_to_use[gene].append(mut) stmts = ac.filter_mutation_status(new_stmts, mutations, []) return stmts
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
def test_filter_mutation_status(): braf_mut = Agent('BRAF', mutations=MutCondition('600', 'V', 'E')) braf_other_mut = Agent('BRAF', mutations=MutCondition('555', 'K', 'G')) st1 = Phosphorylation(braf_mut, Agent('a')) st2 = Phosphorylation(braf_other_mut, Agent('a')) mutations = {'BRAF': [('V', '600', 'E')]} deletions = [] st_out = ac.filter_mutation_status([st1, st2], mutations, deletions) assert len(st_out) == 1 mutations = {} deletions = ['a'] st_out = ac.filter_mutation_status([st1, st2], mutations, deletions) assert len(st_out) == 0 # Can we filter statements out based on bound conditions? mutations = {'BRAF': [('V', '600', 'E')]} deletions = [] braf_good_bound = deepcopy(braf_mut) braf_good_bound.bound_conditions = [BoundCondition(braf_mut)] # braf_bad_bound = deepcopy(braf_mut) braf_bad_bound.bound_conditions = [BoundCondition(braf_other_mut)] # st3 = Phosphorylation(braf_good_bound, Agent('a')) st4 = Phosphorylation(braf_bad_bound, Agent('a')) # st_out = ac.filter_mutation_status([st3], mutations, deletions) assert len(st_out) == 1 # st_out = ac.filter_mutation_status([st4], mutations, deletions) assert len(st_out) == 0 # Can we remove bound conditions based on our filter? st_out = ac.filter_mutation_status([st3], mutations, deletions, remove_bound=True) assert len(st_out[0].enz.bound_conditions) == 1 # st_out = ac.filter_mutation_status([st4], mutations, deletions, remove_bound=True) assert len(st_out[0].enz.bound_conditions) == 0
def test_filter_mutation_status(): braf_mut = Agent('BRAF', mutations=MutCondition('600', 'V', 'E')) braf_other_mut = Agent('BRAF', mutations=MutCondition('555', 'K', 'G')) st1 = Phosphorylation(braf_mut, Agent('a')) st2 = Phosphorylation(braf_other_mut, Agent('a')) mutations = {'BRAF': [('V', '600', 'E')]} deletions = [] st_out = ac.filter_mutation_status([st1, st2], mutations, deletions) assert len(st_out) == 1 mutations = {} deletions = ['a'] st_out = ac.filter_mutation_status([st1, st2], mutations, deletions) assert len(st_out) == 0 # Can we filter statements out based on bound conditions? mutations = {'BRAF': [('V', '600', 'E')]} deletions = [] braf_good_bound = deepcopy(braf_mut) braf_good_bound.bound_conditions = [BoundCondition(braf_mut)] # braf_bad_bound = deepcopy(braf_mut) braf_bad_bound.bound_conditions = [BoundCondition(braf_other_mut)] # st3 = Phosphorylation(braf_good_bound, Agent('a')) st4 = Phosphorylation(braf_bad_bound, Agent('a')) # st_out = ac.filter_mutation_status([st3], mutations, deletions) assert len(st_out) == 1 # st_out = ac.filter_mutation_status([st4], mutations, deletions) assert len(st_out) == 0 # Can we remove bound conditions based on our filter? st_out = ac.filter_mutation_status([st3], mutations, deletions, remove_bound=True) assert len(st_out[0].enz.bound_conditions) == 1 # st_out = ac.filter_mutation_status([st4], mutations, deletions, remove_bound=True) assert len(st_out[0].enz.bound_conditions) == 0