Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Oct 9, 2023
1 parent 23eb5a5 commit 296b486
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/sssom/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def parse_file(
# else:
# doc = parse_func(
# input_path,
# prefix_map=metadata.prefix_map,
# meta=metadata.metadata,
# prefix_map=converter,
# meta=meta,
# )
if clean_prefixes:
# We do this because we got a lot of prefixes from the default SSSOM prefixes!
Expand Down
10 changes: 5 additions & 5 deletions src/sssom/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,11 @@ def _address_multivalued_slot(k: str, v: Any) -> Union[str, List[str]]:

def _init_mapping_set(meta: Optional[MetadataType] = None) -> MappingSet:
_metadata = dict(ChainMap(meta or {}, get_default_metadata()))
return MappingSet(mapping_set_id=_metadata["mapping_set_id"], license=_metadata["license"])
mapping_set = MappingSet(
mapping_set_id=_metadata["mapping_set_id"], license=_metadata["license"]
)
_set_metadata_in_mapping_set(mapping_set=mapping_set, metadata=meta)
return mapping_set


def _get_mapping_dict(row: pd.Series, bad_attrs: Counter) -> Dict[str, Any]:
Expand Down Expand Up @@ -451,7 +455,6 @@ def from_sssom_rdf(
_add_valid_mapping_to_list(mdict, mlist, flip_superclass_assertions=True)

ms.mappings = mlist # type: ignore
_set_metadata_in_mapping_set(mapping_set=ms, metadata=meta)
mdoc = MappingSetDocument(mapping_set=ms, converter=converter)
return to_mapping_set_dataframe(mdoc)

Expand Down Expand Up @@ -527,7 +530,6 @@ def from_alignment_minidom(
ms[OBJECT_SOURCE] = e.firstChild.nodeValue

ms.mappings = mlist # type: ignore
_set_metadata_in_mapping_set(mapping_set=ms, metadata=meta)
mapping_set_document = MappingSetDocument(mapping_set=ms, converter=converter)
return to_mapping_set_dataframe(mapping_set_document)

Expand Down Expand Up @@ -662,7 +664,6 @@ def from_obographs(
raise Exception("No graphs element in obographs file, wrong format?")

ms.mappings = mlist # type: ignore
_set_metadata_in_mapping_set(mapping_set=ms, metadata=meta)
mdoc = MappingSetDocument(mapping_set=ms, converter=converter)
return to_mapping_set_dataframe(mdoc)

Expand Down Expand Up @@ -799,7 +800,6 @@ def _get_mapping_set_from_df(df: pd.DataFrame, meta: Optional[MetadataType] = No
_add_valid_mapping_to_list(mapping_dict, mapping_set.mappings)
for k, v in bad_attrs.items():
logging.warning(f"No attr for {k} [{v} instances]")
_set_metadata_in_mapping_set(mapping_set=mapping_set, metadata=meta)
return mapping_set


Expand Down
2 changes: 1 addition & 1 deletion src/sssom/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ def get_file_extension(file: Union[str, Path, TextIO]) -> str:
return "tsv"


def _extract_global_metadata(msdoc: MappingSetDocument):
def _extract_global_metadata(msdoc: MappingSetDocument) -> MetadataType:
"""Extract metadata.
:param msdoc: MappingSetDocument object
Expand Down
17 changes: 10 additions & 7 deletions tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import numpy as np
import pandas as pd
import yaml
from curies import Converter
from rdflib import Graph

from sssom.constants import CURIE_MAP, DEFAULT_LICENSE, SSSOM_URI_PREFIX, get_default_metadata
Expand Down Expand Up @@ -64,7 +65,7 @@ def setUp(self) -> None:

with open(f"{test_data_dir}/basic-meta-external.yml") as file:
df_meta = yaml.safe_load(file)
self.df_prefix_map = df_meta.pop(CURIE_MAP)
self.df_converter = Converter.from_prefix_map(df_meta.pop(CURIE_MAP))
self.df_meta = df_meta

self.alignmentxml_file = f"{test_data_dir}/oaei-ordo-hp.rdf"
Expand Down Expand Up @@ -117,21 +118,23 @@ def test_parse_obographs(self):
"""Test parsing OBO Graph JSON."""
msdf = from_obographs(
jsondoc=self.obographs,
prefix_map=self.converter.bimap,
prefix_map=self.converter,
meta=self.metadata,
)
path = os.path.join(test_out_dir, "test_parse_obographs.tsv")
with open(path, "w") as file:
write_table(msdf, file)
self.assertEqual(
# this number went up from 8099 when the curies.Converter was introduced
# since it was able to handle CURIE prefix and URI prefix synonyms
8488,
len(msdf.df),
8099,
f"{self.obographs_file} has the wrong number of mappings.",
)

def test_parse_tsv(self):
"""Test parsing TSV."""
msdf = from_sssom_dataframe(df=self.df, prefix_map=self.df_prefix_map, meta=self.df_meta)
msdf = from_sssom_dataframe(df=self.df, prefix_map=self.df_converter, meta=self.df_meta)
path = os.path.join(test_out_dir, "test_parse_tsv.tsv")
with open(path, "w") as file:
write_table(msdf, file)
Expand All @@ -145,7 +148,7 @@ def test_parse_alignment_minidom(self):
"""Test parsing an alignment XML."""
msdf = from_alignment_minidom(
dom=self.alignmentxml,
prefix_map=self.converter.bimap,
prefix_map=self.converter,
meta=self.metadata,
)
path = os.path.join(test_out_dir, "test_parse_alignment_minidom.tsv")
Expand Down Expand Up @@ -244,7 +247,7 @@ def test_parse_alignment_xml(self):

def test_parse_sssom_rdf(self):
"""Test parsing RDF."""
msdf = from_sssom_rdf(g=self.rdf_graph, prefix_map=self.df_prefix_map, meta=self.metadata)
msdf = from_sssom_rdf(g=self.rdf_graph, prefix_map=self.df_converter, meta=self.metadata)
path = os.path.join(test_out_dir, "test_parse_sssom_rdf.tsv")
with open(path, "w") as file:
write_table(msdf, file)
Expand All @@ -258,7 +261,7 @@ def test_parse_sssom_json(self):
"""Test parsing JSON."""
msdf = from_sssom_json(
jsondoc=self.json,
prefix_map=self.df_prefix_map,
prefix_map=self.df_converter,
meta=self.metadata,
)
path = os.path.join(test_out_dir, "test_parse_sssom_json.tsv")
Expand Down

0 comments on commit 296b486

Please sign in to comment.