Skip to content

Commit

Permalink
Simplify fixing local curations
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Dec 18, 2024
1 parent b5fdc02 commit 3d18161
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
18 changes: 15 additions & 3 deletions src/biomappings/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class MappingTuple(NamedTuple):
prediction_source: Optional[str]
prediction_confidence: Optional[float]

def as_dict(self) -> Mapping[str, Any]:
def as_dict(self) -> dict[str, Any]:
"""Get the mapping tuple as a dictionary."""
return dict(zip(MAPPINGS_HEADER, self)) # type:ignore

Expand Down Expand Up @@ -161,7 +161,7 @@ class PredictionTuple(NamedTuple):
or can be based off of them.
"""

def as_dict(self) -> Mapping[str, Any]:
def as_dict(self) -> dict[str, Any]:
"""Get the prediction tuple as a dictionary."""
return dict(zip(PREDICTIONS_HEADER, self)) # type:ignore

Expand Down Expand Up @@ -218,7 +218,7 @@ def target_curie(self) -> str:
return f"{self.target_prefix}:{self.target_identifier}"


Mappings = Iterable[Mapping[str, str]]
Mappings = Iterable[dict[str, str]]


def get_resource_file_path(fname) -> Path:
Expand Down Expand Up @@ -320,6 +320,7 @@ def _lint_curated_mappings(path: Path, *, standardize: bool = False) -> None:
"""Lint the true mappings file."""
mapping_list = _load_table(path)
mappings = _remove_redundant(mapping_list, standardize=standardize)
mappings = _replace_local_curation_source(mapping_list)
_write_helper(MAPPINGS_HEADER, mappings, path, mode="w")


Expand Down Expand Up @@ -496,6 +497,17 @@ def _remove_redundant(mappings: Mappings, *, standardize: bool = False) -> Mappi
return (max(mappings, key=_pick_best) for mappings in dd.values())


def _replace_local_curation_source(mappings: Mappings) -> Mappings:
"""Find `web-` prefixed sources that can be replaced with ORCID CURIEs."""
user_to_contributors = {c["user"]: c["orcid"] for c in load_curators()}
for mapping in mappings:
source = mapping["source"]
orcid = user_to_contributors.get(source.removeprefix("web-"))
if orcid:
mapping["source"] = f"orcid:{orcid}"
yield mapping


def _pick_best(mapping: Mapping[str, str]) -> int:
"""Assign a value for this mapping.
Expand Down
3 changes: 1 addition & 2 deletions src/biomappings/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ def test_contributors(self) -> None:
There are some curations that don't have the right metadata
in {path}.
You can fix this by doing searching for
"{source}" and replacing it with "orcid:{orcid}"
You can fix this by running `biomappings lint` from the console
""").rstrip()
)
else:
Expand Down

0 comments on commit 3d18161

Please sign in to comment.