# HG changeset patch # User devteam # Date 1614144007 0 # Node ID 427903d4702679331f244c0aae67ac71593aecda # Parent 13b6f0007d9e2c7a4fd18e8f49f008fcc05c5ce3 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit c623e4b9f6dd6ff4b88d9386f3b0a0cb497e0a0e" diff -r 13b6f0007d9e -r 427903d47026 column_maker.py --- 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') diff -r 13b6f0007d9e -r 427903d47026 column_maker.xml --- a/column_maker.xml Mon Jan 25 10:00:12 2021 +0000 +++ b/column_maker.xml Wed Feb 24 05:20:07 2021 +0000 @@ -1,4 +1,4 @@ - + an expression on every row python @@ -88,6 +88,13 @@ + + + + + + + @@ -112,11 +119,11 @@ - + Convert* ----- @@ -168,6 +175,6 @@ round | sorted | sqrt | str | sum | type | unichr | unicode | - + ]]> diff -r 13b6f0007d9e -r 427903d47026 test-data/1.tab --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/1.tab Wed Feb 24 05:20:07 2021 +0000 @@ -0,0 +1,10 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 diff -r 13b6f0007d9e -r 427903d47026 test-data/column_maker_out4.tab --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/column_maker_out4.tab Wed Feb 24 05:20:07 2021 +0000 @@ -0,0 +1,10 @@ +1 0.1 +2 0.2 +3 0.3 +4 0.4 +5 0.5 +6 0.6 +7 0.7 +8 0.8 +9 0.9 +10 1.0