Skip to content

Commit

Permalink
Merge pull request #1547 from dandi/bf-species
Browse files Browse the repository at this point in the history
BF: do allow for user to specify a proper full name for "species" in metadata
  • Loading branch information
kabilar authored Dec 4, 2024
2 parents e6ed3ae + 33903e7 commit 874502e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dandi/metadata/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,10 @@ def extract_species(metadata: dict) -> models.SpeciesType | None:
else:
lower_value = value_orig.lower()
for common_names, prefix, uri, name in species_map:
if any(key in lower_value for key in common_names) or (
prefix is not None and lower_value.startswith(prefix)
if (
lower_value == name.lower()
or any(key in lower_value for key in common_names)
or (prefix is not None and lower_value.startswith(prefix))
):
value_id = uri
value = name
Expand Down
24 changes: 24 additions & 0 deletions dandi/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,30 @@ def test_species():
}


# all of them should match the same record
# There should be no network access -- just matching records
@pytest.mark.parametrize(
"species",
[
"mongolian gerbil",
"mongolian jird",
"Mongolian jird",
"http://purl.obolibrary.org/obo/NCBITaxon_10047",
"Meriones unguiculatus",
"Meriones Unguiculatus",
"meriones Unguiculatus",
],
)
def test_species_all_possible(species: str) -> None:
species_rec = extract_species({"species": species})
assert species_rec
assert species_rec.model_dump(mode="json", exclude_none=True) == {
"identifier": "http://purl.obolibrary.org/obo/NCBITaxon_10047",
"schemaKey": "SpeciesType",
"name": "Meriones unguiculatus",
}


def test_extract_unknown_species():
with pytest.raises(ValueError) as excinfo:
extract_species({"species": "mumba-jumba"})
Expand Down

0 comments on commit 874502e

Please sign in to comment.