Skip to content

Commit

Permalink
Add direct only option to association table on node pages (#766)
Browse files Browse the repository at this point in the history
fixes #763

Adds support for viewing direct associations only using a select box
after the association table "sentence" giving the options of "directly"
or "including sub-classes", and this select-box only appears if the node
actually has subclasses. I think this also sets up a nice pattern to
solve #626, since it can show as a select box in the exact same spot,
but will show on genes, which won't have subclasses.

(Not really deploy previewable, since it relies on a backend change as
well)
  • Loading branch information
kevinschaper authored Jul 26, 2024
1 parent 203573d commit b953722
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 164 deletions.
6 changes: 6 additions & 0 deletions backend/src/monarch_py/api/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ def _association_table(
title="Download the results as a file",
examples=[True, False],
),
direct: bool = Query(
default=False,
title="Only return direct associations",
examples=[True, False],
),
) -> Union[AssociationTableResults, str]:
"""
Retrieves association table data for a given entity and association type
Expand All @@ -99,6 +104,7 @@ def _association_table(
category=category,
q=query,
traverse_orthologs=traverse_orthologs,
direct=direct,
sort=sort,
offset=pagination.offset,
limit=pagination.limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ def get_association_table(
entity: str,
category: AssociationCategory,
traverse_orthologs: bool = False,
direct: bool = False,
q: Optional[str] = None,
sort: Optional[List[str]] = None,
offset: int = 0,
Expand All @@ -480,6 +481,7 @@ def get_association_table(
query = build_association_table_query(
entity=entities,
category=category.value,
direct=direct,
q=q,
sort=sort,
offset=offset,
Expand Down
10 changes: 8 additions & 2 deletions backend/src/monarch_py/implementations/solr/solr_query_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ def build_association_query(


def build_association_table_query(
entity: List[str], category: str, q: Optional[str] = None, offset: int = 0, limit: int = 5, sort: List[str] = None
entity: List[str],
category: str,
direct: bool = False,
q: Optional[str] = None,
offset: int = 0,
limit: int = 5,
sort: List[str] = None,
) -> SolrQuery:
if sort is None:
sort = [
Expand All @@ -88,7 +94,7 @@ def build_association_table_query(
]

query = build_association_query(
entity=entity, category=[category], q=q, sort=sort, offset=offset, limit=limit, direct=False
entity=entity, category=[category], q=q, sort=sort, offset=offset, limit=limit, direct=direct
)
return query

Expand Down
1 change: 1 addition & 0 deletions backend/tests/api/test_entity_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_association_table(mock_get_assoc_table):
category=AssociationCategory.DISEASE_TO_PHENOTYPIC_FEATURE_ASSOCIATION,
q=None,
traverse_orthologs=False,
direct=False,
sort=None,
offset=0,
limit=20,
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/fixtures/association_counts_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def association_counts_response():
return {
"responseHeader": {
"QTime": 1,
"QTime": 2,
"params": {
"facet.query": [
'(category:"biolink:DiseaseToPhenotypicFeatureAssociation") AND (subject:"MONDO:0020121" OR subject_closure:"MONDO:0020121")',
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/fixtures/association_table_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def association_table_response():
return {
"responseHeader": {
"QTime": 0,
"QTime": 1,
"params": {
"mm": "100%",
"q": "*:*",
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/fixtures/autocomplete_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def autocomplete_response():
return {
"responseHeader": {
"QTime": 0,
"QTime": 1,
"params": {
"mm": "100%",
"q": "fanc",
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/fixtures/search_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def search_response():
return {
"responseHeader": {
"QTime": 0,
"QTime": 4,
"params": {
"mm": "100%",
"q": "fanconi",
Expand Down
18 changes: 9 additions & 9 deletions frontend/fixtures/phenotype-explorer-compare.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"subject_termset": {
"MP:0010771": {
"id": "MP:0010771",
"label": "integument phenotype"
},
"MP:0002169": {
"id": "MP:0002169",
"label": "no abnormal phenotype detected"
},
"MP:0010771": {
"id": "MP:0010771",
"label": "integument phenotype"
}
},
"object_termset": {
Expand Down Expand Up @@ -77,16 +77,16 @@
"HP:0004325": {
"match_source": "HP:0004325",
"match_source_label": "Decreased body weight",
"match_target": "MP:0010771",
"match_target_label": "integument phenotype",
"match_target": "MP:0002169",
"match_target_label": "no abnormal phenotype detected",
"score": 1.5518735174643892,
"match_subsumer": null,
"match_subsumer_label": null,
"similarity": {
"subject_id": "HP:0004325",
"subject_label": null,
"subject_source": null,
"object_id": "MP:0010771",
"object_id": "MP:0002169",
"object_label": null,
"object_source": null,
"ancestor_id": "UPHENO:0001003",
Expand All @@ -95,10 +95,10 @@
"object_information_content": null,
"subject_information_content": null,
"ancestor_information_content": 1.5518735174643892,
"jaccard_similarity": 0.24,
"jaccard_similarity": 0.23076923076923078,
"cosine_similarity": null,
"dice_similarity": null,
"phenodigm_score": 0.6102865263066631
"phenodigm_score": 0.5984351743308522
},
"score_metric": "ancestor_information_content"
}
Expand Down
Loading

0 comments on commit b953722

Please sign in to comment.