r3fang / SnapTools

A module for working with snap files in Python
Apache License 2.0
35 stars 21 forks source link

Error creating a snap file from Cellranger's fragment bed.gz file #37

Open pabloswfly opened 3 years ago

pabloswfly commented 3 years ago

Hi,

When trying to generate a .snap file from a .bed.gz-converted Cellranger fragment file, I was encountering the following error:

Traceback (most recent call last):
  File "/home/pab/miniconda3/envs/csg.p/bin/snaptools", line 38, in <module>
    parse_args()    
  File "/home/pab/miniconda3/envs/csg.p/lib/python3.9/site-packages/snaptools/parser.py", line 127, in parse_args
    snap_pre(input_file=args.input_file,
  File "/home/pab/miniconda3/envs/csg.p/lib/python3.9/site-packages/snaptools/snap_pre.py", line 224, in snap_pre
    barcode_dict = snaptools.snap.getBarcodesFromInput(input_file, file_format);
  File "/home/pab/miniconda3/envs/csg.p/lib/python3.9/site-packages/snaptools/snap.py", line 177, in getBarcodesFromInput
    return getBarcodesFromBed(fname);
  File "/home/pab/miniconda3/envs/csg.p/lib/python3.9/site-packages/snaptools/snap.py", line 260, in getBarcodesFromBed
    barcode = _read.split()[3].split(":")[0].upper();
IndexError: list index out of range

Investigating the source code, I realized the parsing function was not accounting for the header section of the .bed file (lines commented out with #). This simple fix did the trick but needs to be incorporated each time that the bed file is read, on snap.py at line 257 and 443:

if _read.startswith('#'):
    continue

and line 348 (as the read line is not previously converted into str):

if _read.startswith(b'#'):
    continue

Hope you can incorporate it into the code to avoid future conflicts.

Regards, Pablo

ldudley7 commented 3 years ago

Could you possibly give the specifics of which functions you commented out? I attempted to recreate this fix and it is now saying snaptools is not installed even though when I run snaptools --version I get an output