Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BF: do allow for user to specify a proper full name for "species" in metadata #1547

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading