biosimulators / Biosimulators_utils

Utilities for building standardized command-line interfaces for biosimulation software packages
https://docs.biosimulators.org/Biosimulators_utils
MIT License
4 stars 6 forks source link

`TripleOmexMetaWriter` receives a `Tuple` instead of `Triple` if `license` is provided #80

Closed bilalshaikh42 closed 2 years ago

bilalshaikh42 commented 2 years ago

I am a bit lost tracing this and trying to find the error. I have the following code:

    omex_metadata=[{
        'uri': '.',
        "combine_archive_uri": BIOSIMULATIONS_ROOT_URI_FORMAT.format(metadata["identifier"]),
        "title": metadata["title"],
        "abstract": None,
        "keywords": [tag[-1] for tag in (metadata["tags"] or []) if tag is not None and len(tag) > 1],
        "description": metadata["description"],
        "license": {
            "uri": "https://creativecommons.org/licenses/by/3.0/",
            "label": "ccby",
        },
        "contributors": [],
        "creators": [],
        # 'sources': [{
        #     "label": "PMR workspace",
        #     # TODO add PMR workspace url when importing projects
        #     "uri": metadata.get("source", "None")
        # }],
        'predecessors': [],
        'successors': [],
        'see_also': [],
        'funders': [],
        'other':[],

    }]   
    write_metadata(omex_metadata, project_out_dir)

def write_metadata(metadata, project_out_dir):

    config = Config(OMEX_METADATA_OUTPUT_FORMAT=OmexMetadataOutputFormat.rdfxml)
    BiosimulationsOmexMetaWriter().run(metadata, project_out_dir+"/metadata.rdf", config=config)
    _, errors, warnings = BiosimulationsOmexMetaReader().run(project_out_dir+"/metadata.rdf")
    print(errors)
    if(errors):
        with open(project_out_dir+"/errors.txt", "w") as f:
            f.write(str(errors))

This gives the following error trace:

Traceback (most recent call last):
  File "/home/bilal/env/python/physiome/bin/biosimulations-physiome", line 33, in <module>
    sys.exit(load_entry_point('biosimulations-physiome', 'console_scripts', 'biosimulations-physiome')())
  File "/home/bilal/Projects/work/biosimulations-physiome/biosimulations_physiome/__main__.py", line 72, in main
    fire.Fire(BiosimulationsPhysiome)
  File "/home/bilal/env/python/physiome/lib/python3.9/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/bilal/env/python/physiome/lib/python3.9/site-packages/fire/core.py", line 466, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/home/bilal/env/python/physiome/lib/python3.9/site-packages/fire/core.py", line 681, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/home/bilal/Projects/work/biosimulations-physiome/biosimulations_physiome/__main__.py", line 66, in process
    process_projects.process(project, project_dir)
  File "/home/bilal/Projects/work/biosimulations-physiome/biosimulations_physiome/process_projects.py", line 127, in process
    write_metadata(omex_metadata, project_out_dir)
  File "/home/bilal/Projects/work/biosimulations-physiome/biosimulations_physiome/process_projects.py", line 134, in write_metadata
    BiosimulationsOmexMetaWriter().run(metadata, project_out_dir+"/metadata.rdf", config=config)
  File "/home/bilal/env/python/physiome/lib/python3.9/site-packages/biosimulators_utils/omex_meta/io.py", line 904, in run
    TriplesOmexMetaWriter().run(triples, filename, namespaces=namespaces, config=config)
  File "/home/bilal/env/python/physiome/lib/python3.9/site-packages/biosimulators_utils/omex_meta/io.py", line 401, in run
    namespace, _ = get_uri_namespace_id(str(triple.predicate))
AttributeError: 'tuple' object has no attribute 'predicate'

Going into the TriplesOmexMetaWriter and printing out the triples objects as they appear gives the following:

<biosimulators_utils.omex_meta.data_model.Triple object at 0x7f2751d27250>
<biosimulators_utils.omex_meta.data_model.Triple object at 0x7f2751d27340>
<biosimulators_utils.omex_meta.data_model.Triple object at 0x7f2751d27220>
<biosimulators_utils.omex_meta.data_model.Triple object at 0x7f2751d95c40>
<biosimulators_utils.omex_meta.data_model.Triple object at 0x7f2751d95b20>
<biosimulators_utils.omex_meta.data_model.Triple object at 0x7f2751d95a60>
<biosimulators_utils.omex_meta.data_model.Triple object at 0x7f2751d84bb0>
<biosimulators_utils.omex_meta.data_model.Triple object at 0x7f2751d846a0>
(rdflib.term.URIRef('http://omex-library.org/105.omex'), rdflib.term.URIRef('http://dublincore.org/specifications/dublin-core/dcmi-terms/license'), rdflib.term.URIRef('local:00001'))

As you can see, for some reason the "license" term is being passed is as a Tuple instead of a Triple Removing the license field from the metadata passed in prevents the error @jonrkarr any guesses as to what is causing this?

bilalshaikh42 commented 2 years ago

I found the issue. In my site-packages https://github.com/biosimulators/Biosimulators_utils/blob/dd6d3477ebe7efa9137fb325e8d0dc3a3a035c23/biosimulators_utils/omex_meta/io.py#L806 is followed by a line that adds the tuple to the list of triples. This is not present in the latest code

jonrkarr commented 2 years ago

Which version/revision are you using?

bilalshaikh42 commented 2 years ago

Sorry, I didn't check. Updating the packaged fixed this