def test_filter_concept_names(): stmts = [ Influence(Event(Concept('a')), Event(Concept('b'))), Influence(Event(Concept('a')), Event(Concept('c'))), Influence(Event(Concept('a')), Event(Concept('d'))), Influence(Event(Concept('c')), Event(Concept('d'))) ] stmts_out = ac.filter_concept_names(stmts, ['a'], 'one') assert len(stmts_out) == 3, stmts_out stmts_out = ac.filter_concept_names(stmts, ['a', 'b', 'c'], 'all') assert len(stmts_out) == 2, stmts_out stmts_out = ac.filter_concept_names(stmts, ['a', 'd'], 'one') assert len(stmts_out) == 4, stmts_out stmts_out = ac.filter_concept_names(stmts, ['a', 'b'], 'one', invert=True) assert len(stmts_out) == 1, stmts_out
def get_evidence_for_stmts(): if request.method == 'OPTIONS': return {} req = request.body.read().decode('utf-8') body = json.loads(req) stmt_json = body.get('statement') stmt = Statement._from_json(stmt_json) def _get_agent_ref(agent): """Get the preferred ref for an agent for db web api.""" if agent is None: return None ag_hgnc_id = hgnc_client.get_hgnc_id(agent.name) if ag_hgnc_id is not None: return ag_hgnc_id + "@HGNC" db_refs = agent.db_refs for namespace in ['HGNC', 'FPLX', 'CHEBI', 'TEXT']: if namespace in db_refs.keys(): return '%s@%s' % (db_refs[namespace], namespace) return '%s@%s' % (agent.name, 'TEXT') def _get_matching_stmts(stmt_ref): # Filter by statement type. stmt_type = stmt_ref.__class__.__name__ agent_name_list = [_get_agent_ref(ag) for ag in stmt_ref.agent_list()] non_binary_statements = (Complex, SelfModification, ActiveForm) # TODO: We should look at more than just the agent name. # Doing so efficiently may require changes to the web api. if isinstance(stmt_ref, non_binary_statements): agent_list = [ ag_name for ag_name in agent_name_list if ag_name is not None ] kwargs = {} else: agent_list = [] kwargs = { k: v for k, v in zip(['subject', 'object'], agent_name_list) } if not any(kwargs.values()): return [] print(agent_list) stmts = get_statements(agents=agent_list, stmt_type=stmt_type, simple_response=True, **kwargs) return stmts stmts_out = _get_matching_stmts(stmt) agent_name_list = [ag.name for ag in stmt.agent_list()] stmts_out = stmts = ac.filter_concept_names(stmts_out, agent_name_list, 'all') return _return_stmts(stmts_out)
def get_evidence_for_stmts(): if request.method == 'OPTIONS': return {} req = request.body.read().decode('utf-8') body = json.loads(req) stmt_json = body.get('statement') stmt = Statement._from_json(stmt_json) def _get_agent_ref(agent): """Get the preferred ref for an agent for db web api.""" if agent is None: return None ag_hgnc_id = hgnc_client.get_hgnc_id(agent.name) if ag_hgnc_id is not None: return ag_hgnc_id + "@HGNC" db_refs = agent.db_refs for namespace in ['HGNC', 'FPLX', 'CHEBI', 'TEXT']: if namespace in db_refs.keys(): return '%s@%s' % (db_refs[namespace], namespace) return '%s@%s' % (agent.name, 'TEXT') def _get_matching_stmts(stmt_ref): # Filter by statement type. stmt_type = stmt_ref.__class__.__name__ agent_name_list = [_get_agent_ref(ag) for ag in stmt_ref.agent_list()] non_binary_statements = (Complex, SelfModification, ActiveForm) # TODO: We should look at more than just the agent name. # Doing so efficiently may require changes to the web api. if isinstance(stmt_ref, non_binary_statements): agent_list = [ag_name for ag_name in agent_name_list if ag_name is not None] kwargs = {} else: agent_list = [] kwargs = {k: v for k, v in zip(['subject', 'object'], agent_name_list)} if not any(kwargs.values()): return [] print(agent_list) stmts = get_statements(agents=agent_list, stmt_type=stmt_type, simple_response=True, **kwargs) return stmts stmts_out = _get_matching_stmts(stmt) agent_name_list = [ag.name for ag in stmt.agent_list()] stmts_out = stmts = ac.filter_concept_names(stmts_out, agent_name_list, 'all') return _return_stmts(stmts_out)