chapmanb / bcbb

Incubator for useful bioinformatics code, primarily in Python and R
http://bcbio.wordpress.com
603 stars 243 forks source link

TypeError: 'FakeHandle' object is not iterable #120

Closed Rhinogradentia closed 5 years ago

Rhinogradentia commented 5 years ago

Hi, I know that you advise to use gffutils, but only for completeness - it seems that changes made to python lately had an influence on the functionality of GFFParser.py:

in_handle = open(args.gffIn)
gffIn = GFF.parse(in_handle) 
for rec in GFF.parse(gffIn):
        print(rec)

I used a file handle of an gff file as parameter for GFF.parse and got following error:

Traceback (most recent call last):
  File "ExchangeIDsInGFF.py", line 51, in <module>
    main(args)
  File "ExchangeIDsInGFF.py", line 33, in main
    for rec in GFF.parse(gffIn):
  File "/usr/lib/python3.7/site-packages/BCBio/GFF/GFFParser.py", line 742, in parse
    target_lines):
  File "/usr/lib/python3.7/site-packages/BCBio/GFF/GFFParser.py", line 322, in parse_in_parts
    for results in self.parse_simple(gff_files, limit_info, target_lines):
  File "/usr/lib/python3.7/site-packages/BCBio/GFF/GFFParser.py", line 343, in parse_simple
    for results in self._gff_process(gff_files, limit_info, target_lines):
  File "/usr/lib/python3.7/site-packages/BCBio/GFF/GFFParser.py", line 637, in _gff_process
    for out in self._lines_to_out_info(line_gen, limit_info, target_lines):
  File "/usr/lib/python3.7/site-packages/BCBio/GFF/GFFParser.py", line 666, in _lines_to_out_info
    for line in line_iter:
  File "/usr/lib/python3.7/site-packages/BCBio/GFF/GFFParser.py", line 649, in _file_line_generator
    in_handle = open(gff_file)
TypeError: expected str, bytes or os.PathLike object, not generator

This also happens with a script (also in the bcbb repository - gff_to_genbank.py) which I use to convert gff into GenBank.

It is a pity that this library isn't maintained this much anymore, because sometimes it is more convenient to use instead of gffutils.

Best Regards, Nadine

chapmanb commented 5 years ago

Nadine; Thanks much for the report and apologies about the issues with Python 3.7 compatibility. I pushed a new release (0.6.5) of bcbio.GFF that fixes this issue and should hopefully work cleanly for you. Please let us know if you run into any other problems.

Rhinogradentia commented 5 years ago

Thank you very much! I will try it.