Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_bel_script() invokes a TypeError: make_knowledge_header() missing 1 required positional argument: 'name' #436

Open
djinnome opened this issue May 13, 2020 · 4 comments

Comments

@djinnome
Copy link
Contributor

Hi @cthoyt

When I try to run
pybel.to_bel_script() I get the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-55-6e2178fff4cb> in <module>
      2 
      3 mars_graph = get_subgraph_by_pubmed( emmaa_covid_graph, pmids)
----> 4 pybel.to_bel_script(mars_graph,os.path.join(curation_dir,'mars_indra.bel'))

</Users/zuck016/.pyenv/versions/anaconda3-2019.10/lib/python3.7/site-packages/decorator.py:decorator-gen-803> in to_bel_script(graph, path, use_identifiers)

~/.pyenv/versions/anaconda3-2019.10/lib/python3.7/site-packages/networkx/utils/decorators.py in _open_file(func_to_be_decorated, *args, **kwargs)
    238         # Finally, we call the original function, making sure to close the fobj
    239         try:
--> 240             result = func_to_be_decorated(*new_args, **kwargs)
    241         finally:
    242             if close_fobj:

~/.pyenv/versions/anaconda3-2019.10/lib/python3.7/site-packages/pybel/canonicalize.py in to_bel_script(graph, path, use_identifiers)
     46     :param use_identifiers: Enables extended `BEP-0008 <http://bep.bel.bio/published/BEP-0008.html>`_ syntax
     47     """
---> 48     for line in to_bel_script_lines(graph, use_identifiers=use_identifiers):
     49         print(line, file=path)
     50 

~/.pyenv/versions/anaconda3-2019.10/lib/python3.7/site-packages/pybel/canonicalize.py in _to_bel_lines_header(graph)
    263         annotation_patterns=graph.annotation_pattern,
    264         annotation_list=graph.annotation_list,
--> 265         **graph.document,
    266     )
    267 

TypeError: make_knowledge_header() missing 1 required positional argument: 'name'

According to:
https://github.com/pybel/bel-resources/blob/master/src/bel_resources/write_document.py#L17

make_knowledge_header() requires a positional name parameter
However,

yield from make_knowledge_header(
namespace_url=graph.namespace_url,
namespace_patterns=graph.namespace_pattern,
annotation_url=graph.annotation_url,
annotation_patterns=graph.annotation_pattern,
annotation_list=graph.annotation_list,
**graph.document,
)

attempts to call make_knowledge_header() without calling the name parameter.

@cthoyt
Copy link
Member

cthoyt commented May 13, 2020

It should give nicer output but to write to bel script you need to set the name of the graph. I think the version as well.

@djinnome
Copy link
Contributor Author

Thanks! Now I am getting this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-59-999f6b46130e> in <module>
      4 mars_graph.name = 'MARS_Indra'
      5 mars_graph.version = emmaa_covid_graph.version
----> 6 pybel.to_bel_script(mars_graph,os.path.join(curation_dir,'mars_indra.bel'))

</Users/zuck016/.pyenv/versions/anaconda3-2019.10/lib/python3.7/site-packages/decorator.py:decorator-gen-803> in to_bel_script(graph, path, use_identifiers)

~/.pyenv/versions/anaconda3-2019.10/lib/python3.7/site-packages/networkx/utils/decorators.py in _open_file(func_to_be_decorated, *args, **kwargs)
    238         # Finally, we call the original function, making sure to close the fobj
    239         try:
--> 240             result = func_to_be_decorated(*new_args, **kwargs)
    241         finally:
    242             if close_fobj:

~/.pyenv/versions/anaconda3-2019.10/lib/python3.7/site-packages/pybel/canonicalize.py in to_bel_script(graph, path, use_identifiers)
     46     :param use_identifiers: Enables extended `BEP-0008 <http://bep.bel.bio/published/BEP-0008.html>`_ syntax
     47     """
---> 48     for line in to_bel_script_lines(graph, use_identifiers=use_identifiers):
     49         print(line, file=path)
     50 

~/.pyenv/versions/anaconda3-2019.10/lib/python3.7/site-packages/pybel/canonicalize.py in _to_bel_lines_body(graph, use_identifiers)
    296                 keys = sorted(annotations_data) if annotations_data is not None else tuple()
    297                 for key in keys:
--> 298                     yield _set_annotation_to_str(annotations_data, key)
    299 
    300                 yield graph.edge_to_bel(u, v, data, use_identifiers=use_identifiers)

~/.pyenv/versions/anaconda3-2019.10/lib/python3.7/site-packages/pybel/canonicalize.py in _set_annotation_to_str(annotation_data, key)
    233     value = annotation_data[key]
    234 
--> 235     if len(value) == 1:
    236         return 'SET {} = "{}"'.format(key, list(value)[0])
    237 

TypeError: object of type 'NoneType' has no len()

@djinnome
Copy link
Contributor Author

Weirdly, when I try this:

from pybel.canonicalize import _set_annotation_to_str
for u,v,data in mars_graph.edges(data=True):
                annotations_data = data.get("ANNOTATIONS")

                keys = sorted(annotations_data) if annotations_data is not None else tuple()
                for key in keys:
                    print(_set_annotation_to_str(annotations_data, key))
print("No keys found")

I just get:

No keys found

So I am not sure how to reproduce this error.

@cthoyt
Copy link
Member

cthoyt commented May 13, 2020

Quite strange, maybe you could try and figure out for which annotation there's a None as the value (that shouldn't happen...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants