raphael-group/wext

Empty results produces error

Closed this issue · 1 comments

An empty rows list in "i_o.py" causes the following error:

Traceback (most recent call last):
  File "wext/find_sets.py", line 158, in <module>
    if __name__ == '__main__': run( get_parser().parse_args(sys.argv[1:]) )
  File "wext/find_sets.py", line 156, in run
    output_enumeration_table( args, k, setToPval, setToRuntime, setToFDR, setToObs, args.fdr_threshold )
  File "/n/data2/bidmc/medicine/haigis/Cook/KrasComutation/Pathway/WExT/wext/wext/i_o.py", line 71, in output
    k = len(rows[0][0].split(', '))
IndexError: list index out of range

I inserted a quick print statement of rows just before line 71 (it is normally line 67, I believe) and it produced:

[]

Let me know if you need any more information for this small bug. Thank you for putting this package together for the community and being responsive to issues,
Josh Cook

Josh,

Thank you for raising this issue. As you noticed, an error occurs when the results are empty, which can happen if no gene set meets the given FDR threshold (-fdr/-fdr_threshold in the find_sets.py script, which is 0.5 by default). We will update the code to fix this, but for an immediate solution, please indent line 66 through line 73 and add if rows: before line 66 in the i_o.py script, i.e., replace

k = len(rows[0][0].split(', '))
tbl_header = create_tbl_header( k )
header = 'Gene set\t{0}{1} P-value\t{0}{1} FDR\t{0}{1} '\
         'Runtime\tT\tZ\t{2}'.format(args.test, method_paren, tbl_header)

# Output to file
OUT.write('#{}\n'.format(header))
OUT.write( '\n'.join([ '\t'.join(map(str, row)) for row in rows ]) )

with

if rows:
    k = len(rows[0][0].split(', '))
    tbl_header = create_tbl_header( k )
    header = 'Gene set\t{0}{1} P-value\t{0}{1} FDR\t{0}{1} '\
             'Runtime\tT\tZ\t{2}'.format(args.test, method_paren, tbl_header)

    # Output to file
    OUT.write('#{}\n'.format(header))
    OUT.write( '\n'.join([ '\t'.join(map(str, row)) for row in rows ]) )

Best,
Matt