pybel icon indicating copy to clipboard operation
pybel copied to clipboard

Troubles with loading .json files created with pybel 14.0.8

Open leon-k-martin opened this issue 3 years ago • 4 comments

Bildschirmfoto 2021-04-29 um 13 37 34

when trying to load a neurommsig subgraph (.json extension) I get the following message: "Invalid extension for file: .json"

The image shows the first lines of the .json file

Is there a way to convert the old files into a format supported by pybel?

Thank you in advance!

Best Leon

leon-k-martin avatar Apr 29 '21 12:04 leon-k-martin

I was pretty careful to make sure old files could be loaded. However, there are many flavors of JSON (nodelink JSON, SBEL JSON, GraphDati JSON) so you have to make sure to use the file extension bel.nodelink.json if you're using pybel.load. If you don't want to worry about automatic inference of the data type, you can try pybel.from_nodelink_file

cthoyt avatar Apr 29 '21 13:04 cthoyt

Thank you for the quick reply!

I tried the import with the pybel.from_nodelink_file but get a new error unfortunately:

  File "/opt/anaconda3/lib/python3.8/site-packages/pybel/struct/graph.py", line 932, in <dictcomp>
    key: sorted(self._clean_value(key, values), key=lambda e: (e.namespace, e.identifier, e.name))

  File "/opt/anaconda3/lib/python3.8/site-packages/pybel/struct/graph.py", line 969, in _clean_value
    raise NotImplementedError(f'where is key {key}?')

NotImplementedError: where is key NeuroMMSig-Disease?

Am I doing sth wrong or are the json-files I am trying to load exported incorrectly?

leon-k-martin avatar Apr 29 '21 13:04 leon-k-martin

This is happening because there is an underlying semantic error in the BEL document -there is no annotation definition for "NeuroMMSig-Disease".

I agree that this isn't a very informative message, and it should probably give a warning instead of crashing the whole program. I might have to take care of this one with an update to the underlying code since I don't think there's an option to disable this check.

You could add an annotation definition in the JSON file (in the "annotations" key) before processing with PyBEL and that should be a quick fix. Let me know if you run into any issues doing that. Are you getting these files from the NeuroMMSig service? Or did daniel send you a dump?

cthoyt avatar Apr 29 '21 13:04 cthoyt

Great, thank you! Adding the key to the annotation_list let's me importing the subgraph with pybel.

leon-k-martin avatar Apr 29 '21 15:04 leon-k-martin