From a87075ac9c99346e9d3233a577cba7d59d2d6c7e Mon Sep 17 00:00:00 2001 From: nayib-jose-gloria Date: Wed, 20 Sep 2023 14:55:05 -0400 Subject: [PATCH] fix: clean-up error message if only 1 ancestor is valid for ontology term --- cellxgene_schema_cli/cellxgene_schema/validate.py | 7 +++++-- cellxgene_schema_cli/tests/test_schema_compliance.py | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cellxgene_schema_cli/cellxgene_schema/validate.py b/cellxgene_schema_cli/cellxgene_schema/validate.py index 8dbe3ab0c..405d36525 100644 --- a/cellxgene_schema_cli/cellxgene_schema/validate.py +++ b/cellxgene_schema_cli/cellxgene_schema/validate.py @@ -147,8 +147,11 @@ def _validate_curie_ancestors( if True not in checks: if errors: - all_ancestors = list(allowed_ancestors.values()) - self.errors.append(f"'{term_id}' in '{column_name}' is not a child term id of '{all_ancestors}'.") + all_ancestors = [ancestor for ancestors in allowed_ancestors.values() for ancestor in ancestors] + # print ancestor as string with single-quotes if only 1 entry + if len(all_ancestors) == 1: + all_ancestors = f"'{all_ancestors[0]}'" + self.errors.append(f"'{term_id}' in '{column_name}' is not a child term id of {all_ancestors}.") return False return True diff --git a/cellxgene_schema_cli/tests/test_schema_compliance.py b/cellxgene_schema_cli/tests/test_schema_compliance.py index c1ea15edb..351cbb4e6 100644 --- a/cellxgene_schema_cli/tests/test_schema_compliance.py +++ b/cellxgene_schema_cli/tests/test_schema_compliance.py @@ -264,7 +264,7 @@ def test_assay_ontology_term_id(self): self.validator.errors, [ "ERROR: 'EFO:0000001' in 'assay_ontology_term_id' is not a " - "child term id of '[['EFO:0002772', 'EFO:0010183']]'." + "child term id of ['EFO:0002772', 'EFO:0010183']." ], ) @@ -603,7 +603,7 @@ def test_tissue_ontology_term_id_child_of_anatomical_entity(self): self.validator.errors, [ "ERROR: 'UBERON:0001062' in 'tissue_ontology_term_id' is not a child term id of " - "'[['UBERON:0001062']]'. When 'tissue_type' is 'tissue' or 'organoid', 'tissue_ontology_term_id' " + "'UBERON:0001062'. When 'tissue_type' is 'tissue' or 'organoid', 'tissue_ontology_term_id' " "MUST be a child term id of 'UBERON:0001062' (anatomical entity)." ], ) @@ -616,7 +616,7 @@ def test_tissue_ontology_term_id_child_of_anatomical_entity(self): self.validator.errors, [ "ERROR: 'UBERON:0001062' in 'tissue_ontology_term_id' is not a child term id of " - "'[['UBERON:0001062']]'. When 'tissue_type' is 'tissue' or 'organoid', 'tissue_ontology_term_id' " + "'UBERON:0001062'. When 'tissue_type' is 'tissue' or 'organoid', 'tissue_ontology_term_id' " "MUST be a child term id of 'UBERON:0001062' (anatomical entity)." ], )