Skip to content

Commit

Permalink
Add histopheno bar graph to gene pages (#630)
Browse files Browse the repository at this point in the history
Use UPHENO to drive the Histopheno bar chart, then show the
visualization on gene pages (likely limited to a subset of species, due
to both the content of the list and the presence or absense of upheno
connectivity)
  • Loading branch information
kevinschaper authored Apr 19, 2024
1 parent accf783 commit fbdda4c
Show file tree
Hide file tree
Showing 17 changed files with 363 additions and 359 deletions.
40 changes: 20 additions & 20 deletions backend/src/monarch_py/datamodels/solr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ class core(Enum):


class HistoPhenoKeys(Enum):
skeletal_system = "HP:0000924"
nervous_system = "HP:0000707"
head_neck = "HP:0000152"
integument = "HP:0001574"
eye = "HP:0000478"
cardiovascular_system = "HP:0001626"
metabolism_homeostasis = "HP:0001939"
genitourinary_system = "HP:0000119"
digestive_system = "HP:0025031"
neoplasm = "HP:0002664"
blood = "HP:0001871"
immune_system = "HP:0002715"
endocrine = "HP:0000818"
musculature = "HP:0003011"
respiratory = "HP:0002086"
ear = "HP:0000598"
connective_tissue = "HP:0003549"
prenatal_or_birth = "HP:0001197"
growth = "HP:0001507"
breast = "HP:0000769"
skeletal_system = "UPHENO:0002964" # "HP:0000924"
nervous_system = "UPHENO:0004523" # "HP:0000707"
head_neck = "UPHENO:0002764" # "HP:0000152"
integument = "UPHENO:0002635" # "HP:0001574"
eye = "UPHENO:0003020" # "HP:0000478"
cardiovascular_system = "UPHENO:0080362" # "HP:0001626"
metabolism_homeostasis = "HP:0001939" # ??? No uPheno parent
genitourinary_system = "UPHENO:0002642" # "HP:0000119"
digestive_system = "UPHENO:0002833" # "HP:0025031"
neoplasm = "HP:0002664" # ??? No uPheno parent
blood = "UPHENO:0004459" # "HP:0001871"
immune_system = "UPHENO:0002948" # "HP:0002715"
endocrine = "UPHENO:0003116" # "HP:0000818"
musculature = "UPHENO:0002816" # "HP:0003011"
respiratory = "UPHENO:0004536" # "HP:0002086"
ear = "HP:0000598" # UPHENO:0002903
connective_tissue = "UPHENO:0002712" # "HP:0003549"
prenatal_or_birth = "UPHENO:0075949" # "HP:0001197"
growth = "UPHENO:0049874" # "HP:0001507"
breast = "UPHENO:0003013" # "HP:0000769"


class SolrQuery(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,12 @@ def get_associations(
associations = parse_associations(query_result, compact, offset, limit)
return associations

def get_histopheno(self, subject_closure: Optional[str] = None) -> HistoPheno:
def get_histopheno(self, subject: Optional[str] = None) -> HistoPheno:
"""Get histopheno counts for a given subject_closure"""
solr = SolrService(base_url=self.base_url, core=core.ASSOCIATION)
query = build_histopheno_query(subject_closure)
query = build_histopheno_query(subject)
query_result = solr.query(query)
histopheno = parse_histopheno(query_result, subject_closure)
histopheno = parse_histopheno(query_result, subject)
return histopheno

def get_multi_entity_associations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ def build_association_counts_query(entity: str) -> SolrQuery:
return query


def build_histopheno_query(subject_closure: str) -> SolrQuery:
def build_histopheno_query(subject: str) -> SolrQuery:
query = build_association_query(
subject_closure=subject_closure,
subject=[subject],
offset=0,
limit=0,
)
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": 0,
"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": 1,
"QTime": 0,
"params": {
"mm": "100%",
"q": "*:*",
Expand Down
34 changes: 17 additions & 17 deletions backend/tests/fixtures/histopheno.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ def histopheno():
return {
"id": "MONDO:0020121",
"items": [
{"label": "musculature", "count": 1677, "id": "HP:0003011"},
{"label": "nervous_system", "count": 1071, "id": "HP:0000707"},
{"label": "head_neck", "count": 577, "id": "HP:0000152"},
{"label": "skeletal_system", "count": 471, "id": "HP:0000924"},
{"label": "eye", "count": 287, "id": "HP:0000478"},
{"label": "musculature", "count": 1677, "id": "UPHENO:0002816"},
{"label": "nervous_system", "count": 1071, "id": "UPHENO:0004523"},
{"label": "head_neck", "count": 577, "id": "UPHENO:0002764"},
{"label": "skeletal_system", "count": 471, "id": "UPHENO:0002964"},
{"label": "eye", "count": 287, "id": "UPHENO:0003020"},
{"label": "metabolism_homeostasis", "count": 213, "id": "HP:0001939"},
{"label": "cardiovascular_system", "count": 177, "id": "HP:0001626"},
{"label": "blood", "count": 175, "id": "HP:0001871"},
{"label": "connective_tissue", "count": 161, "id": "HP:0003549"},
{"label": "respiratory", "count": 150, "id": "HP:0002086"},
{"label": "cardiovascular_system", "count": 177, "id": "UPHENO:0080362"},
{"label": "blood", "count": 175, "id": "UPHENO:0004459"},
{"label": "connective_tissue", "count": 161, "id": "UPHENO:0002712"},
{"label": "respiratory", "count": 150, "id": "UPHENO:0004536"},
{"label": "neoplasm", "count": 148, "id": "HP:0002664"},
{"label": "digestive_system", "count": 142, "id": "HP:0025031"},
{"label": "integument", "count": 47, "id": "HP:0001574"},
{"label": "genitourinary_system", "count": 44, "id": "HP:0000119"},
{"label": "growth", "count": 32, "id": "HP:0001507"},
{"label": "digestive_system", "count": 142, "id": "UPHENO:0002833"},
{"label": "integument", "count": 47, "id": "UPHENO:0002635"},
{"label": "genitourinary_system", "count": 44, "id": "UPHENO:0002642"},
{"label": "growth", "count": 32, "id": "UPHENO:0049874"},
{"label": "ear", "count": 28, "id": "HP:0000598"},
{"label": "endocrine", "count": 25, "id": "HP:0000818"},
{"label": "immune_system", "count": 22, "id": "HP:0002715"},
{"label": "prenatal_or_birth", "count": 21, "id": "HP:0001197"},
{"label": "breast", "count": 1, "id": "HP:0000769"},
{"label": "endocrine", "count": 25, "id": "UPHENO:0003116"},
{"label": "immune_system", "count": 22, "id": "UPHENO:0002948"},
{"label": "prenatal_or_birth", "count": 21, "id": "UPHENO:0075949"},
{"label": "breast", "count": 1, "id": "UPHENO:0003013"},
],
}
36 changes: 18 additions & 18 deletions backend/tests/fixtures/histopheno_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ def histopheno_query():
"facet_min_count": 1,
"facet_fields": [],
"facet_queries": [
'object_closure:"HP:0000924"',
'object_closure:"HP:0000707"',
'object_closure:"HP:0000152"',
'object_closure:"HP:0001574"',
'object_closure:"HP:0000478"',
'object_closure:"HP:0001626"',
'object_closure:"UPHENO:0002964"',
'object_closure:"UPHENO:0004523"',
'object_closure:"UPHENO:0002764"',
'object_closure:"UPHENO:0002635"',
'object_closure:"UPHENO:0003020"',
'object_closure:"UPHENO:0080362"',
'object_closure:"HP:0001939"',
'object_closure:"HP:0000119"',
'object_closure:"HP:0025031"',
'object_closure:"UPHENO:0002642"',
'object_closure:"UPHENO:0002833"',
'object_closure:"HP:0002664"',
'object_closure:"HP:0001871"',
'object_closure:"HP:0002715"',
'object_closure:"HP:0000818"',
'object_closure:"HP:0003011"',
'object_closure:"HP:0002086"',
'object_closure:"UPHENO:0004459"',
'object_closure:"UPHENO:0002948"',
'object_closure:"UPHENO:0003116"',
'object_closure:"UPHENO:0002816"',
'object_closure:"UPHENO:0004536"',
'object_closure:"HP:0000598"',
'object_closure:"HP:0003549"',
'object_closure:"HP:0001197"',
'object_closure:"HP:0001507"',
'object_closure:"HP:0000769"',
'object_closure:"UPHENO:0002712"',
'object_closure:"UPHENO:0075949"',
'object_closure:"UPHENO:0049874"',
'object_closure:"UPHENO:0003013"',
],
"filter_queries": ["subject_closure:MONDO\\:0020121"],
"filter_queries": ['subject:"MONDO:0020121" OR subject_closure:"MONDO:0020121"'],
"query_fields": None,
"def_type": "edismax",
"q_op": "AND",
Expand Down
70 changes: 35 additions & 35 deletions backend/tests/fixtures/histopheno_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@ def histopheno_response():
"QTime": 1,
"params": {
"facet.query": [
'object_closure:"HP:0000924"',
'object_closure:"HP:0000707"',
'object_closure:"HP:0000152"',
'object_closure:"HP:0001574"',
'object_closure:"HP:0000478"',
'object_closure:"HP:0001626"',
'object_closure:"UPHENO:0002964"',
'object_closure:"UPHENO:0004523"',
'object_closure:"UPHENO:0002764"',
'object_closure:"UPHENO:0002635"',
'object_closure:"UPHENO:0003020"',
'object_closure:"UPHENO:0080362"',
'object_closure:"HP:0001939"',
'object_closure:"HP:0000119"',
'object_closure:"HP:0025031"',
'object_closure:"UPHENO:0002642"',
'object_closure:"UPHENO:0002833"',
'object_closure:"HP:0002664"',
'object_closure:"HP:0001871"',
'object_closure:"HP:0002715"',
'object_closure:"HP:0000818"',
'object_closure:"HP:0003011"',
'object_closure:"HP:0002086"',
'object_closure:"UPHENO:0004459"',
'object_closure:"UPHENO:0002948"',
'object_closure:"UPHENO:0003116"',
'object_closure:"UPHENO:0002816"',
'object_closure:"UPHENO:0004536"',
'object_closure:"HP:0000598"',
'object_closure:"HP:0003549"',
'object_closure:"HP:0001197"',
'object_closure:"HP:0001507"',
'object_closure:"HP:0000769"',
'object_closure:"UPHENO:0002712"',
'object_closure:"UPHENO:0075949"',
'object_closure:"UPHENO:0049874"',
'object_closure:"UPHENO:0003013"',
],
"mm": "100%",
"q": "*:*",
"defType": "edismax",
"facet_min_count": "1",
"start": "0",
"q.op": "AND",
"fq": "subject_closure:MONDO\\:0020121",
"fq": 'subject:"MONDO:0020121" OR subject_closure:"MONDO:0020121"',
"rows": "0",
"facet": "true",
},
Expand All @@ -44,26 +44,26 @@ def histopheno_response():
"facet_counts": {
"facet_fields": {},
"facet_queries": {
'object_closure:"HP:0000924"': 471,
'object_closure:"HP:0000707"': 1071,
'object_closure:"HP:0000152"': 577,
'object_closure:"HP:0001574"': 47,
'object_closure:"HP:0000478"': 287,
'object_closure:"HP:0001626"': 177,
'object_closure:"UPHENO:0002964"': 471,
'object_closure:"UPHENO:0004523"': 1071,
'object_closure:"UPHENO:0002764"': 577,
'object_closure:"UPHENO:0002635"': 47,
'object_closure:"UPHENO:0003020"': 287,
'object_closure:"UPHENO:0080362"': 177,
'object_closure:"HP:0001939"': 213,
'object_closure:"HP:0000119"': 44,
'object_closure:"HP:0025031"': 142,
'object_closure:"UPHENO:0002642"': 44,
'object_closure:"UPHENO:0002833"': 142,
'object_closure:"HP:0002664"': 148,
'object_closure:"HP:0001871"': 175,
'object_closure:"HP:0002715"': 22,
'object_closure:"HP:0000818"': 25,
'object_closure:"HP:0003011"': 1677,
'object_closure:"HP:0002086"': 150,
'object_closure:"UPHENO:0004459"': 175,
'object_closure:"UPHENO:0002948"': 22,
'object_closure:"UPHENO:0003116"': 25,
'object_closure:"UPHENO:0002816"': 1677,
'object_closure:"UPHENO:0004536"': 150,
'object_closure:"HP:0000598"': 28,
'object_closure:"HP:0003549"': 161,
'object_closure:"HP:0001197"': 21,
'object_closure:"HP:0001507"': 32,
'object_closure:"HP:0000769"': 1,
'object_closure:"UPHENO:0002712"': 161,
'object_closure:"UPHENO:0075949"': 21,
'object_closure:"UPHENO:0049874"': 32,
'object_closure:"UPHENO:0003013"': 1,
},
},
}
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": 2,
"QTime": 0,
"params": {
"mm": "100%",
"q": "fanconi",
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/integration/test_solr_histopheno.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ def test_histopheno():
for k in hp.items:
total += k.count

assert hp.items[0].id == "HP:0003011"
assert hp.items[0].id == "UPHENO:0002816"
6 changes: 3 additions & 3 deletions backend/tests/unit/test_solr_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
build_search_query,
obsolete_unboost,
entity_predicate_boost,
category_boost, blank_search_boost,
category_boost,
blank_search_boost,
)
from monarch_py.utils.utils import compare_dicts, dict_diff

Expand Down Expand Up @@ -164,5 +165,4 @@ def test_blank_search_boost():
boost = blank_search_boost()
assert boost.startswith("product(")
assert boost.endswith(")")
assert "if(termfreq(id,\"MONDO:0007523\"),12,1)" in boost

assert 'if(termfreq(id,"MONDO:0007523"),12,1)' in boost
Loading

0 comments on commit fbdda4c

Please sign in to comment.