Skip to content

Commit

Permalink
Removed get_stmts_for_agent_type get_stmts_for_source get_stmts_for_r…
Browse files Browse the repository at this point in the history
…el_types
  • Loading branch information
haohangyan committed Nov 14, 2024
1 parent 22c69e3 commit bc67c87
Showing 1 changed file with 0 additions and 175 deletions.
175 changes: 0 additions & 175 deletions src/indra_cogex/client/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
"get_stmts_meta_for_stmt_hashes",
"get_stmts_for_stmt_hashes",
"get_statements",
"get_stmts_for_agent_type",
"get_stmts_for_source",
"get_stmts_for_rel_types",
"is_gene_mutated",
"get_mutated_genes",
"get_drugs_for_target",
Expand Down Expand Up @@ -1295,178 +1292,6 @@ def get_statements(

return stmts, evidence_counts

@autoclient()
def get_stmts_for_agent_type(
agent_name: str,
agent_role: Optional[str] = None,
limit: Optional[int] = 10,
*,
client: Neo4jClient,
evidence_limit: Optional[int] = None
) -> List[Statement]:
"""Return the statements for a given agent based on its role
Parameters
----------
agent_name : str
The name of the agent (e.g.,"MEK").
agent_role : Optional[str], default: None
The role of the agent in the interaction, either "subject" or "object".
limit : Optional[int], default: 10
The maximum number of statements returned
client : Neo4jClient
The Neo4j client to use for querying.
evidence_limit : Optional[int], default: None
The optional limit for the number of evidence entries per statement.
Returns
-------
List[Statement]
A list of statements where the given agent acts as the subject or object.
"""

# Construct the query based on the role of the agent
if agent_role.lower() == "subject":
query = """
MATCH p = (a:BioEntity {name: $agent_name})-[r:indra_rel]->(b:BioEntity)
RETURN p LIMIT $limit
"""
elif agent_role.lower() == "object":
query = """
MATCH p = (a:BioEntity)-[r:indra_rel]->(b:BioEntity {name: $agent_name})
RETURN p LIMIT $limit
"""
else:
query = """
MATCH p = (a:BioEntity {name: $agent_name})-[r:indra_rel]-(b:BioEntity)
RETURN p LIMIT $limit
"""

params = {
"agent_name": agent_name,
"limit": limit
}

logger.info(f"Getting statements for agent '{agent_name}' with limit {limit}")
rels = client.query_relations(query, **params)
stmts = indra_stmts_from_relations(rels, deduplicate=True)
if evidence_limit and evidence_limit > 1:
stmts = enrich_statements(
stmts,
client=client,
evidence_limit=evidence_limit,
)
return stmts

@autoclient()
def get_stmts_for_source(
stmt_sources: Union[str, List[str]],
limit: Optional[int] = 10,
*,
client: Neo4jClient,
evidence_limit: Optional[int] = None
) -> List[Statement]:
"""Return the statements for the given source(s).
Parameters
----------
stmt_sources : Union[str, List[str]]
The source or list of sources to query for (e.g., "reach" or ["reach", "sparser"]).
limit : Optional[int], default: 10
The maximum number of statements to return.
client : Neo4jClient
The Neo4j client to use for querying.
evidence_limit : Optional[int], default: None
The optional limit for the number of evidence entries per statement.
Returns
-------
List[Statement]
A list of statements filtered by the given sources.
"""
if isinstance(stmt_sources, str):
stmt_sources = [stmt_sources]

source_conditions = " OR ".join(
[f'r.source_counts CONTAINS \'"{source}":\'' for source in stmt_sources]
)

query = f"""
MATCH p = (a:BioEntity)-[r:indra_rel]->(b:BioEntity)
WHERE {source_conditions}
RETURN p LIMIT $limit
"""

params = {
"limit": limit
}

logger.info(
f"Getting statements for sources '{stmt_sources}' with limit {limit}")
rels = client.query_relations(query, **params)
stmts = indra_stmts_from_relations(rels, deduplicate=True)
if evidence_limit and evidence_limit > 1:
stmts = enrich_statements(
stmts,
client=client,
evidence_limit=evidence_limit,
)
return stmts


@autoclient()
def get_stmts_for_rel_types(
rel_types: Union[str, List[str]],
limit: Optional[int] = 10,
*,
client: Neo4jClient,
evidence_limit: Optional[int] = None
) -> List[Statement]:
"""Return the statements for the given relationship types.
Parameters
----------
rel_types : Union[str, List[str]]
The relationship types to query for (e.g., ["Phosphorylation", "Activation"]).
limit : Optional[int], default: 10
The maximum number of statements returned.
client : Neo4jClient
The Neo4j client to use for querying.
evidence_limit : Optional[int], default: None
The optional limit for the number of evidence entries per statement.
Returns
-------
List[Statement]
A list of statements filtered by the given relationship types.
"""
if isinstance(rel_types, str):
rel_types = [rel_types]

query = """
MATCH p = (a:BioEntity)-[r:indra_rel]->(b:BioEntity)
WHERE r.stmt_type IN $rel_types
RETURN p LIMIT $limit
"""

params = {
"rel_types": rel_types,
"limit": limit
}

logger.info(
f"Getting statements for relationship types '{rel_types}' with limit {limit}")
rels = client.query_relations(query, **params)
stmts = indra_stmts_from_relations(rels, deduplicate=True)
if evidence_limit and evidence_limit > 1:
stmts = enrich_statements(
stmts,
client=client,
evidence_limit=evidence_limit,
)

return stmts

@autoclient()
def enrich_statements(
stmts: Sequence[Statement],
Expand Down

0 comments on commit bc67c87

Please sign in to comment.