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

Error while trying to write ncbigene.obo via pyobo #179

Closed
hrshdhgd opened this issue Apr 9, 2024 · 1 comment
Closed

Error while trying to write ncbigene.obo via pyobo #179

hrshdhgd opened this issue Apr 9, 2024 · 1 comment

Comments

@hrshdhgd
Copy link
Contributor

hrshdhgd commented Apr 9, 2024

pyobo call made via code:

from pyobo.sources.ncbigene import get_obo

def get_obo_file(output_path: str):
    """Get the obo file."""
    obo_file = get_obo()
    obo_file.write_obo(output_path, use_tqdm=True)

This resulted in the following error:

Traceback (most recent call last):
....
  /src/ncbi_gene_pyobo/cli.py", line 57, in get_obo_file
    obo_file.write_obo(output_path, use_tqdm=True)
  File "/opt/anaconda3/envs/ncbi-gene-pyobo/lib/python3.10/site-packages/pyobo/struct/struct.py", line 711, in write_obo
    self._write_lines(it, fh)
  File "/opt/anaconda3/envs/ncbi-gene-pyobo/lib/python3.10/site-packages/pyobo/struct/struct.py", line 717, in _write_lines
    for line in it:
  File "/opt/anaconda3/envs/ncbi-gene-pyobo/lib/python3.10/site-packages/pyobo/struct/struct.py", line 700, in iterate_obo_lines
    yield from term.iterate_obo_lines(ontology=self.ontology, typedefs=self.typedefs)
  File "/opt/anaconda3/envs/ncbi-gene-pyobo/lib/python3.10/site-packages/pyobo/struct/struct.py", line 429, in iterate_obo_lines
    yield f"def: {self._definition_fp()}"
  File "/opt/anaconda3/envs/ncbi-gene-pyobo/lib/python3.10/site-packages/pyobo/struct/struct.py", line 400, in _definition_fp
    return f'"{obo_escape_slim(self.definition)}" [{comma_separate(self.provenance)}]'
  File "/opt/anaconda3/envs/ncbi-gene-pyobo/lib/python3.10/site-packages/pyobo/struct/utils.py", line 24, in obo_escape_slim
    rv = "".join(OBO_ESCAPE_SLIM.get(character, character) for character in string)
TypeError: 'float' object is not iterable

The error points to line 24 below.

def obo_escape_slim(string: str) -> str:
"""Escape all funny characters for OBO."""
rv = "".join(OBO_ESCAPE_SLIM.get(character, character) for character in string)
rv = rv.replace("\n", "\\n")
return rv

Reran it by casting string in join() [str(string)]

    rv = "".join(OBO_ESCAPE_SLIM.get(character, character) for character in str(string))

fixed the issue.

@cthoyt
Copy link
Member

cthoyt commented Apr 9, 2024

stringifying a NAN from pandas isn't the right solution - this would introduce incorrect characters. This might have already been fixed in cc2f27b

@cthoyt cthoyt closed this as completed Dec 12, 2024
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

Successfully merging a pull request may close this issue.

2 participants