Skip to content

python problems with gff3_fix #142

@jd3234

Description

@jd3234

When I am trying to run gff3_fix I am getting the following error:

Traceback (most recent call last):
File "./gff3toolkit_env/bin/gff3_fix", line 7, in <module>
sys.exit(script_main())
~~~~~~~~~~~^^
File ./gff3toolkit_env/lib/python3.14/site-packages/gff3tool/bin/gff3_fix.py", line 95, in script_main
gff3_fix.fix.main(gff3=gff3, output_gff=args.output_gff, error_dict=error_dict, line_num_dict=line_num_dict, logger=logger_stderr)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "./gff3toolkit_env/lib/python3.14/site-packages/gff3tool/lib/gff3_fix/fix.py", line 686, in main
fix_phase(gff3=gff3, error_list=error_dict[error_code], line_num_dict=line_num_dict, logger=logger)
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "./gff3toolkit_env/lib/python3.14/site-packages/gff3tool/lib/gff3_fix/fix.py", line 424, in fix_phase
phase = list(map(int,re.findall(r'\d',line_num_dict[sorted_CDS_list[0]['line_index']+1]['Ema0006']))[1])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
TypeError: 'map' object is not subscriptable

This seems to be related to a parathesis placement and can be fixed like this:

# line 424
# phase = list(map(int,re.findall(r'\d',line_num_dict[sorted_CDS_list[0]['line_index']+1]['Ema0006']))[1])
phase = list(map(int,re.findall(r'\d',line_num_dict[sorted_CDS_list[0]['line_index']+1]['Ema0006'])))[1]

When that is fixed I ran into an other error (same line 424, so previous fix didn't fix everything):

Traceback (most recent call last):
  File "./gff3toolkit_env/bin/gff3_fix", line 7, in <module>
    sys.exit(script_main())
             ~~~~~~~~~~~^^
  File "./gff3toolkit_env/lib/python3.14/site-packages/gff3tool/bin/gff3_fix.py", line 95, in script_main
    gff3_fix.fix.main(gff3=gff3, output_gff=args.output_gff, error_dict=error_dict, line_num_dict=line_num_dict, logger=logger_stderr)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./gff3toolkit_env/lib/python3.14/site-packages/gff3tool/lib/gff3_fix/fix.py", line 686, in main
    fix_phase(gff3=gff3, error_list=error_dict[error_code], line_num_dict=line_num_dict, logger=logger)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./gff3toolkit_env/lib/python3.14/site-packages/gff3tool/lib/gff3_fix/fix.py", line 424, in fix_phase
    phase = list(map(int,re.findall(r'\d',line_num_dict[sorted_CDS_list[0]['line_index']+1]['Ema0006'])))[1]
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

This seems to be a regex problem and could be fixed like this:

#phase = list(map(int,re.findall(r'\d',line_num_dict[sorted_CDS_list[0]['line_index']+1]['Ema0006'])))[1]
digits = list(map(int, re.findall(r'\d+', str(line_num_dict.get(sorted_CDS_list[0]['line_index']+1, {}).get('Ema0006', '0 0'))))); phase = digits[1] if len(digits) >= 2 else (digits[0] if digits else 0)

or more stable

if 'Ema0006' in line_num_dict[sorted_CDS_list[0]['line_index']+1]:
    error_msg = line_num_dict[sorted_CDS_list[0]['line_index']+1]['Ema0006']
    should_be_match = re.search(r'should be (\d+)', error_msg)
    if should_be_match:
        phase = int(should_be_match.group(1))
    else:
        # Fallback: try to get second digit from message
        digits = list(map(int, re.findall(r'\d+', error_msg)))
        if len(digits) >= 2:
            phase = digits[1]
        else:
            phase = 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions