bgruening / galaxytools

:microscope::books: Galaxy Tool wrappers
MIT License
115 stars 220 forks source link

Fix two bugs with `split_file_to_collection` #1358

Closed simonbray closed 7 months ago

simonbray commented 7 months ago

Allow chunksize to be greater than the number of records in the input file without raising the following error:

Traceback (most recent call last):
  File "/srv/galaxy/var/shed_tools/toolshed.g2.bx.psu.edu/repos/bgruening/split_file_to_collection/6cbe2f30c2d7/split_file_to_collection/split_file_to_collection.py", line 281, in <module>
    main()
  File "/srv/galaxy/var/shed_tools/toolshed.g2.bx.psu.edu/repos/bgruening/split_file_to_collection/6cbe2f30c2d7/split_file_to_collection/split_file_to_collection.py", line 52, in main
    split_by_record(args, in_file, out_dir, top, ftype)
  File "/srv/galaxy/var/shed_tools/toolshed.g2.bx.psu.edu/repos/bgruening/split_file_to_collection/6cbe2f30c2d7/split_file_to_collection/split_file_to_collection.py", line 169, in split_by_record
    new_file = open(newfile_names[new_file_counter], "a")
IndexError: list index out of range

Allow an empty file to be split without raising the following error:

Traceback (most recent call last):
  File "/srv/galaxy/var/shed_tools/toolshed.g2.bx.psu.edu/repos/bgruening/split_file_to_collection/6cbe2f30c2d7/split_file_to_collection/split_file_to_collection.py", line 281, in <module>
    main()
  File "/srv/galaxy/var/shed_tools/toolshed.g2.bx.psu.edu/repos/bgruening/split_file_to_collection/6cbe2f30c2d7/split_file_to_collection/split_file_to_collection.py", line 52, in main
    split_by_record(args, in_file, out_dir, top, ftype)
  File "/srv/galaxy/var/shed_tools/toolshed.g2.bx.psu.edu/repos/bgruening/split_file_to_collection/6cbe2f30c2d7/split_file_to_collection/split_file_to_collection.py", line 141, in split_by_record
    if sep_at_end and not last_line_matched:
UnboundLocalError: local variable 'last_line_matched' referenced before assignment