Skip to content
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: 3 additions & 3 deletions src/sssom/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from linkml_runtime.loaders.rdflib_loader import RDFLibLoader
from pandas.errors import EmptyDataError
from rdflib import Graph
from sssom_schema import Mapping, MappingSet
from sssom_schema import EntityTypeEnum, Mapping, MappingSet
from typing_extensions import Literal, TypeAlias

from sssom.constants import (
Expand Down Expand Up @@ -1187,12 +1187,12 @@ def _ensure_valid_mapping_from_dict(mdict: Dict[str, Any]) -> Optional[Mapping]:

try:
m = Mapping(**mdict)
if m.subject_type == "rdfs literal":
if m.subject_type == EntityTypeEnum(EntityTypeEnum["rdfs literal"]):
Copy link
Contributor Author

@gouttegd gouttegd Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: As strange as it may look like, this is the normal way of comparing LinkML-defined enum values.

A comparison like this:

m.subject_type == EntityTypeEnum["rdfs literal"]

would not work because EntityTypeEnum["rdfs literal"] is not the actual enum value, it is the LinkML PermissibleValue object that represents the enum value (that’s not the same thing!). We must give that value to the EntityTypeEnum constructor to obtain an actual enum value that we can compare to the value of the slot.

See here for details, and here for a request for an easier way of working with LinkML enums.

(Of course in our case this is make even weirder by the fact that our enum values contain space characters, and LinkML does not allow to distinguish between the actual value to be used in data and the symbol used in Python code.)

if m.subject_label is None:
raise ValueError("Missing subject_label")
elif m.subject_id is None:
raise ValueError("Missing subject_id")
if m.object_type == "rdfs literal":
if m.object_type == EntityTypeEnum(EntityTypeEnum["rdfs literal"]):
if m.object_label is None:
raise ValueError("Missing object_label")
elif m.object_id is None:
Expand Down
19 changes: 19 additions & 0 deletions tests/data/literals.sssom.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#curie_map:
# FBcv: http://purl.obolibrary.org/obo/FBcv_
# ORCID: https://orcid.org/
# obo: http://purl.obolibrary.org/obo/
#mapping_set_id: http://purl.obolibrary.org/obo/fbcv/agr-vocabs.sssom.tsv
#mapping_set_description: Mappings between the FlyBase Controlled Vocabulary (FBcv) and vocabulary terms from the Alliance of Genome Resources.
#creator_id:
# - ORCID:0000-0002-6095-8718
#license: https://creativecommons.org/licenses/by/4.0/
subject_id subject_label predicate_id object_label object_category mapping_justification subject_source object_type
FBcv:0000222 male skos:exactMatch male Genetic Sex semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
FBcv:0000334 female skos:exactMatch female Genetic Sex semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
FBcv:0003124 species study skos:exactMatch species Data Set Category Tags semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
FBcv:0003125 strain study skos:exactMatch genome variation Data Set Category Tags semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
FBcv:0003127 developmental stage study skos:exactMatch developmental stage Data Set Category Tags semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
FBcv:0003128 circadian rhythm study skos:narrowMatch time of day Data Set Category Tags semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
FBcv:0003129 cell cycle study skos:exactMatch cell cycle Data Set Category Tags semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
FBcv:0003130 tissue type study skos:narrowMatch anatomical structure Data Set Category Tags semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
FBcv:0003131 cell type study skos:exactMatch cell type Data Set Category Tags semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
5 changes: 5 additions & 0 deletions tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ def test_parse_tsv(self) -> None:
f"{self.df_file} has the wrong number of mappings.",
)

def test_parse_tsv_with_literal_mappings(self) -> None:
"""Test parsing a SSSOM/TSV file containing literal mappings."""
msdf = parse_sssom_table(f"{test_data_dir}/literals.sssom.tsv")
self.assertEqual(len(msdf.df), 9, "literals.sssom.tsv has the wrong number of mappings.")

def test_parse_alignment_minidom(self) -> None:
"""Test parsing an alignment XML."""
msdf = from_alignment_minidom(
Expand Down
Loading