mapping-commons / sssom-py

Python toolkit for SSSOM mapping format
https://mapping-commons.github.io/sssom-py/index.html#
MIT License
49 stars 12 forks source link

sssom invert chokes on `UnboundLocalError` #493

Closed matentzn closed 6 months ago

matentzn commented 7 months ago

Eventually we will deprecated sssom invert, but for now we need it to work:

sssom invert mondo_exactmatch_omim.sssom.tsv -o test.sssom.tsv

results in:

/Users/matentzn/.pyenv/versions/3.11.7/lib/python3.11/site-packages/sssom/util.py:156: FutureWarning: Downcasting behavior in `replace` is deprecated and will be removed in a future version. To retain the old behavior, explicitly call `result.infer_objects(copy=False)`. To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)`
  df.replace("", np.nan, inplace=True)
Traceback (most recent call last):
  File "/Users/matentzn/.pyenv/versions/3.11.7/bin/sssom", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/matentzn/.pyenv/versions/3.11.7/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matentzn/.pyenv/versions/3.11.7/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/matentzn/.pyenv/versions/3.11.7/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matentzn/.pyenv/versions/3.11.7/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matentzn/.pyenv/versions/3.11.7/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matentzn/.pyenv/versions/3.11.7/lib/python3.11/site-packages/sssom/cli.py", line 758, in invert
    inverse_dictionary["inverse_predicate_map"],
    ^^^^^^^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'inverse_dictionary' where it is not associated with a value

Testfile:

# comment: The latest OMIM is integrated with every Mondo release.
# curie_map:
#   MONDO: http://purl.obolibrary.org/obo/MONDO_
#   OMIM: https://omim.org/entry/
#   owl: http://www.w3.org/2002/07/owl#
#   rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
#   rdfs: http://www.w3.org/2000/01/rdf-schema#
#   semapv: https://w3id.org/semapv/vocab/
#   skos: http://www.w3.org/2004/02/skos/core#
#   sssom: https://w3id.org/sssom/
# license: https://creativecommons.org/publicdomain/zero/1.0/
# mapping_date: '2022-02-11'
# mapping_set_id: http://purl.obolibrary.org/obo/mondo/mappings/mondo_exactmatch_omim.sssom.tsv
# mapping_set_version: http://purl.obolibrary.org/obo/mondo/releases/2024-01-03/mappings/mondo_exactmatch_omim.sssom.tsv
# object_source: https://www.omim.org/
# object_source_version: http://www.orphadata.org/data/ORDO/ordo_orphanet_3.1.owl
# subject_source: http://purl.obolibrary.org/obo/mondo.owl
subject_id  subject_label   predicate_id    object_id   object_label    mapping_justification
MONDO:0000208   microcephaly, short stature, and impaired glucose metabolism 1  skos:exactMatch OMIM:616033 microcephaly, short stature, and impaired glucose metabolism 1  semapv:ManualMappingCuration
MONDO:0000902   agenesis of the corpus callosum with peripheral neuropathy  skos:exactMatch OMIM:218000 agenesis of the corpus callosum with peripheral neuropathy  semapv:ManualMappingCuration

Problem 2: Inversion does not do anything

sssom invert mondo_exactmatch_omim.sssom.tsv -o test.sssom.tsv --inverse-map inverse-predicates.yaml

Does not throw an error, but no inversion occurs (input and output file are the same). By default, inversion should invert everything.

hrshdhgd commented 7 months ago

What does inverse-predicates.yaml look like?

matentzn commented 7 months ago

You can see it in src/sssom

hrshdhgd commented 6 months ago

ran this and it works for me just fine. Your PR needed a variable name change but it doesn't make a difference.

matentzn commented 6 months ago

Thank you! Fixed by #503