Skip to content

Commit

Permalink
Merge pull request #865 from dandi/fix/species-url-case
Browse files Browse the repository at this point in the history
species url is case sensitive
  • Loading branch information
yarikoptic committed Jan 18, 2022
2 parents 07b0348 + 3a494cf commit 46d1ea2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 4 additions & 2 deletions dandi/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ def parse_purlobourl(url: str, lookup: ty.Optional[ty.Tuple[str, ...]] = None):
"""

req = requests.get(url, allow_redirects=True)
req.raise_for_status()
doc = parseString(req.text)
for elfound in doc.getElementsByTagName("Class"):
if (
Expand Down Expand Up @@ -432,7 +433,7 @@ def extract_species(metadata):
value_id = value_orig
lookup = ("rdfs:label", "oboInOwl:hasExactSynonym")
try:
result = parse_purlobourl(value, lookup=lookup)
result = parse_purlobourl(value_orig, lookup=lookup)
except ConnectionError:
value = None
else:
Expand All @@ -457,7 +458,8 @@ def extract_species(metadata):
"(http://www.ontobee.org/ontology/NCBITaxon) into "
"your species field in your NWB file. For example: "
"http://purl.obolibrary.org/obo/NCBITaxon_9606 is the "
"url for the species Homo sapiens."
"url for the species Homo sapiens. Please note that "
"this url is case sensitive."
)
return models.SpeciesType(identifier=value_id, name=value)
else:
Expand Down
3 changes: 2 additions & 1 deletion dandi/tests/data/metadata/metadata2asset_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
"genotype": "Typical",
"species": {
"schemaKey": "SpeciesType",
"identifier": "http://purl.obolibrary.org/obo/NCBITaxon_1234175"
"identifier": "http://purl.obolibrary.org/obo/NCBITaxon_1234175",
"name": "Cyperus bulbosus"
}
}
]
Expand Down
16 changes: 16 additions & 0 deletions dandi/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .skip import mark
from ..metadata import (
extract_age,
extract_species,
get_metadata,
metadata2asset,
parse_age,
Expand Down Expand Up @@ -338,7 +339,22 @@ def test_time_extract_gest():
"oboInOwl:hasExactSynonym": "Norway rat",
},
),
(
"http://purl.obolibrary.org/obo/NCBITaxon_28584",
{
"rdfs:label": "Drosophila suzukii",
},
),
],
)
def test_parseobourl(url, value):
assert parse_purlobourl(url) == value


def test_species():
m = {"species": "http://purl.obolibrary.org/obo/NCBITaxon_28584"}
assert extract_species(m).json_dict() == {
"identifier": "http://purl.obolibrary.org/obo/NCBITaxon_28584",
"schemaKey": "SpeciesType",
"name": "Drosophila suzukii",
}

0 comments on commit 46d1ea2

Please sign in to comment.