Skip to content

Commit

Permalink
couple tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
glass-ships committed Dec 6, 2023
1 parent 477c19a commit 3c8348e
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ install-frontend:

.PHONY: model
model: install-backend
$(RUN) gen-pydantic --pydantic-version 2 --extra-fields ignore $(SCHEMADIR)/model.yaml > $(SCHEMADIR)/model.py
$(RUN) gen-pydantic --pydantic-version 2 --extra-fields allow $(SCHEMADIR)/model.yaml > $(SCHEMADIR)/model.py
$(RUN) gen-typescript $(SCHEMADIR)/model.yaml > frontend/src/api/model.ts
make format

Expand Down
2 changes: 1 addition & 1 deletion backend/src/monarch_py/datamodels/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ConfiguredBaseModel(BaseModel):
model_config = ConfigDict(
validate_assignment=True,
validate_default=True,
extra="ignore",
extra="allow",
arbitrary_types_allowed=True,
use_enum_values=True,
)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/monarch_py/datamodels/solr.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def add_filter_query(self, filter_query):

def query_string(self):
return urllib.parse.urlencode(
{self._solrize(k): self._solrize(v) for k, v in self.dict().items() if v is not None},
{self._solrize(k): self._solrize(v) for k, v in self..model_dump().items() if v is not None},
doseq=True,
)

Expand Down
8 changes: 4 additions & 4 deletions backend/src/monarch_py/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def to_json(obj: Union[ConfiguredBaseModel, Dict, List[ConfiguredBaseModel]], fi
elif isinstance(obj, dict):
json_value = json.dumps(obj, indent=4)
elif isinstance(obj, list):
json_value = json.dumps({"items": [o.dict() for o in obj]}, indent=4)
json_value = json.dumps({"items": [o.model_dump() for o in obj]}, indent=4)
if file:
with open(file, "w") as f:
f.write(json_value)
Expand All @@ -135,8 +135,8 @@ def to_tsv(obj: ConfiguredBaseModel, file: str) -> str:
headers = get_headers_from_obj(obj)
rows = []
else:
headers = obj.items[0].dict().keys()
rows = [list(item.dict().values()) for item in obj.items]
headers = obj.items[0].model_dump().keys()
rows = [list(item.model_dump().values()) for item in obj.items]
else:
console.print(f"\n[bold red]{FMT_INPUT_ERROR_MSG}[/]\n")
raise typer.Exit(1)
Expand Down Expand Up @@ -200,7 +200,7 @@ def to_yaml(obj: ConfiguredBaseModel, file: str):
if isinstance(obj, Entity):
yaml.dump(obj.model_dump(), fh, indent=4)
elif isinstance(obj, Results) or isinstance(obj, HistoPheno) or isinstance(obj, AssociationCountList):
yaml.dump([item.dict() for item in obj.items], fh, indent=4)
yaml.dump([item.model_dump() for item in obj.items], fh, indent=4)
else:
console.print(f"\n[bold red]{FMT_INPUT_ERROR_MSG}[/]\n")
raise typer.Exit(1)
Expand Down
12 changes: 6 additions & 6 deletions backend/tests/fixtures/phenotype_explorer_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
def phenotype_explorer_compare():
return {
"subject_termset": {
"MP:0010771": {"id": "MP:0010771", "label": "integument phenotype (MPO)"},
"MP:0002169": {"id": "MP:0002169", "label": "no abnormal phenotype detected (MPO)"},
"MP:0010771": {"id": "MP:0010771", "label": "integument phenotype (MPO)"},
},
"object_termset": {"HP:0004325": {"id": "HP:0004325", "label": "Decreased body weight (HPO)"}},
"subject_best_matches": {
Expand Down Expand Up @@ -69,16 +69,16 @@ def phenotype_explorer_compare():
"HP:0004325": {
"match_source": "HP:0004325",
"match_source_label": "Decreased body weight (HPO)",
"match_target": "MP:0010771",
"match_target_label": "integument phenotype (MPO)",
"match_target": "MP:0002169",
"match_target_label": "no abnormal phenotype detected (MPO)",
"score": 1.4431977534690428,
"match_subsumer": None,
"match_subsumer_label": None,
"similarity": {
"subject_id": "HP:0004325",
"subject_label": None,
"subject_source": None,
"object_id": "MP:0010771",
"object_id": "MP:0002169",
"object_label": None,
"object_source": None,
"ancestor_id": "UPHENO:0001003",
Expand All @@ -87,10 +87,10 @@ def phenotype_explorer_compare():
"object_information_content": None,
"subject_information_content": None,
"ancestor_information_content": 1.4431977534690428,
"jaccard_similarity": 0.3333333333333333,
"jaccard_similarity": 0.16216216216216217,
"cosine_similarity": None,
"dice_similarity": None,
"phenodigm_score": 0.6935891563620457,
"phenodigm_score": 0.48376861011243283,
},
}
},
Expand Down
12 changes: 3 additions & 9 deletions backend/tests/unit/test_solr_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ def test_parse_histopheno(histopheno_response, histopheno, node):
histopheno_response["response"]["numFound"] = histopheno_response["response"].pop("num_found")
solr_response = SolrQueryResult(**histopheno_response)
parsed = parse_histopheno(solr_response, subject_closure=Node(**node).id).model_dump()
assert (
parsed == histopheno
), f"Parsed result is not as expected. Difference: {dict_diff(parsed, histopheno)}"
assert parsed == histopheno, f"Parsed result is not as expected. Difference: {dict_diff(parsed, histopheno)}"


def test_parse_search(search_response, search):
Expand All @@ -63,15 +61,11 @@ def test_parse_autocomplete(autocomplete_response, autocomplete):
autocomplete_response["response"]["numFound"] = autocomplete_response["response"].pop("num_found")
solr_response = SolrQueryResult(**autocomplete_response)
parsed = parse_autocomplete(solr_response).model_dump()
assert (
parsed == autocomplete
), f"Parsed result is not as expected. Difference: {dict_diff(parsed, autocomplete)}"
assert parsed == autocomplete, f"Parsed result is not as expected. Difference: {dict_diff(parsed, autocomplete)}"


def test_parse_mappings(mapping_response, mappings):
mapping_response["response"]["numFound"] = mapping_response["response"].pop("num_found")
solr_response = SolrQueryResult(**mapping_response)
parsed = parse_mappings(solr_response).model_dump()
assert (
parsed == mappings
), f"Parsed result is not as expected. Difference: {dict_diff(parsed, mappings)}"
assert parsed == mappings, f"Parsed result is not as expected. Difference: {dict_diff(parsed, mappings)}"
12 changes: 6 additions & 6 deletions backend/tests/unit/test_solr_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_build_association_query(
direct=direct,
facet_fields=facet_fields,
facet_queries=facet_queries,
).dict()
).model_dump()
expected = association_query_direct if direct else association_query_indirect
if facet_fields:
expected["facet_fields"] = facet_fields
Expand Down Expand Up @@ -91,30 +91,30 @@ def test_build_association_multiple_objects():


def test_build_association_counts_query(association_counts_query, node):
query = build_association_counts_query(entity=Node(**node).id).dict()
query = build_association_counts_query(entity=Node(**node).id).model_dump()
expected = association_counts_query
assert compare_dicts(query, expected), f"Query is not as expected. Difference: {dict_diff(query, expected)}"


def test_build_histopheno_query(histopheno_query):
query = build_histopheno_query("MONDO:0020121").dict()
query = build_histopheno_query("MONDO:0020121").model_dump()
expected = histopheno_query
assert compare_dicts(query, expected), f"Query is not as expected. Difference: {dict_diff(query, expected)}"


def test_build_search_query(search_query):
query = build_search_query(q="fanconi").dict()
query = build_search_query(q="fanconi").model_dump()
expected = search_query
assert compare_dicts(query, expected), f"Query is not as expected. Difference: {dict_diff(query, expected)}"


def test_build_autocomplete_query(autocomplete_query):
query = build_autocomplete_query(q="fanc").dict()
query = build_autocomplete_query(q="fanc").model_dump()
expected = autocomplete_query
assert compare_dicts(query, expected), f"Query is not as expected. Difference: {dict_diff(query, expected)}"


def test_build_mappings_query(mapping_query):
query = build_mapping_query(entity_id=["MONDO:0020121"]).dict()
query = build_mapping_query(entity_id=["MONDO:0020121"]).model_dump()
expected = mapping_query
assert compare_dicts(query, expected), f"Query is not as expected. Difference: {dict_diff(query, expected)}"
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 (MPO)"
},
"MP:0002169": {
"id": "MP:0002169",
"label": "no abnormal phenotype detected (MPO)"
},
"MP:0010771": {
"id": "MP:0010771",
"label": "integument phenotype (MPO)"
}
},
"object_termset": {
Expand Down Expand Up @@ -75,16 +75,16 @@
"HP:0004325": {
"match_source": "HP:0004325",
"match_source_label": "Decreased body weight (HPO)",
"match_target": "MP:0010771",
"match_target_label": "integument phenotype (MPO)",
"match_target": "MP:0002169",
"match_target_label": "no abnormal phenotype detected (MPO)",
"score": 1.4431977534690428,
"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 @@ -93,10 +93,10 @@
"object_information_content": null,
"subject_information_content": null,
"ancestor_information_content": 1.4431977534690428,
"jaccard_similarity": 0.3333333333333333,
"jaccard_similarity": 0.16216216216216217,
"cosine_similarity": null,
"dice_similarity": null,
"phenodigm_score": 0.6935891563620457
"phenodigm_score": 0.48376861011243283
}
}
},
Expand Down

0 comments on commit 3c8348e

Please sign in to comment.