diff column_maker.py @ 7:427903d47026 draft

"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit c623e4b9f6dd6ff4b88d9386f3b0a0cb497e0a0e"
author devteam
date Wed, 24 Feb 2021 05:20:07 +0000
parents 13b6f0007d9e
children 02026300aa45
line wrap: on
line diff
--- a/column_maker.py	Mon Jan 25 10:00:12 2021 +0000
+++ b/column_maker.py	Wed Feb 24 05:20:07 2021 +0000
@@ -10,6 +10,17 @@
 import json
 import re
 import sys
+# functions that may be used in the compute expression
+from math import (  # noqa: F401
+    ceil,
+    exp,
+    floor,
+    log,
+    log10,
+    sqrt
+)
+
+from numpy import format_float_positional  # noqa: F401
 
 parser = argparse.ArgumentParser()
 parser.add_argument('input', type=argparse.FileType('r'), help="input file")
@@ -49,8 +60,8 @@
     )
 try:
     in_columns = int(argparse_dict['columns'])
-    if in_columns < 2:
-        # To be considered tabular, data must fulfill requirements of the sniff.is_column_based() method.
+    if in_columns < 1:
+        # To be considered tabular, data must have at least one column.
         raise ValueError
 except Exception:
     if not fh.readline():
@@ -88,6 +99,9 @@
 col_str = ', '.join(cols)    # 'c1, c2, c3, c4'
 type_cast_str = ', '.join(type_casts)  # 'str(c1), int(c2), int(c3), str(c4)'
 assign = "%s = line.split('\\t')" % col_str
+if len(cols) == 1:
+    # Single column, unpacking by assignment won't work
+    assign += '[0]'
 wrap = "%s = %s" % (col_str, type_cast_str)
 skipped_lines = 0
 first_invalid_line = 0
@@ -97,17 +111,6 @@
 
 # Read input file, skipping invalid lines, and perform computation that will result in a new column
 code = '''
-# import here since flake8 complains otherwise
-from math import (
-    ceil,
-    exp,
-    floor,
-    log,
-    log10,
-    sqrt
-)
-from numpy import format_float_positional
-
 for i, line in enumerate(fh):
     total_lines += 1
     line = line.rstrip('\\r\\n')