Mercurial > repos > devteam > column_maker
comparison column_maker.py @ 10:aff5135563c6 draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit 06a92568f3409b035fd8a08725db20933d8d15e6
| author | iuc |
|---|---|
| date | Thu, 22 Aug 2024 08:25:44 +0000 |
| parents | 6595517c2dd8 |
| children |
comparison
equal
deleted
inserted
replaced
| 9:6595517c2dd8 | 10:aff5135563c6 |
|---|---|
| 11 import enum | 11 import enum |
| 12 import re | 12 import re |
| 13 import sys | 13 import sys |
| 14 # Functions that may be used in the compute expression | 14 # Functions that may be used in the compute expression |
| 15 from math import ( # noqa: F401 | 15 from math import ( # noqa: F401 |
| 16 acos, | |
| 17 acosh, | |
| 18 asin, | |
| 19 asinh, | |
| 20 atan, | |
| 21 atan2, | |
| 22 atanh, | |
| 23 cbrt, | |
| 16 ceil, | 24 ceil, |
| 25 comb, | |
| 26 copysign, | |
| 27 cos, | |
| 28 cosh, | |
| 29 degrees, | |
| 30 dist, | |
| 31 erf, | |
| 32 erfc, | |
| 17 exp, | 33 exp, |
| 34 exp2, | |
| 35 expm1, | |
| 36 fabs, | |
| 37 factorial, | |
| 18 floor, | 38 floor, |
| 39 fmod, | |
| 40 frexp, | |
| 41 fsum, | |
| 42 gamma, | |
| 43 gcd, | |
| 44 hypot, | |
| 45 inf, | |
| 46 isclose, | |
| 47 isfinite, | |
| 48 isinf, | |
| 49 isnan, | |
| 50 isqrt, | |
| 51 ldexp, | |
| 52 lgamma, | |
| 19 log, | 53 log, |
| 20 log10, | 54 log10, |
| 55 log1p, | |
| 56 log2, | |
| 57 modf, | |
| 58 nextafter, | |
| 59 perm, | |
| 60 pi, | |
| 61 pow, | |
| 62 prod, | |
| 63 remainder, | |
| 64 sin, | |
| 21 sqrt, | 65 sqrt, |
| 66 tan, | |
| 67 tanh, | |
| 68 tau, | |
| 69 trunc, | |
| 70 ulp, | |
| 22 ) | 71 ) |
| 23 | 72 |
| 24 from numpy import format_float_positional | 73 from numpy import format_float_positional |
| 25 | 74 |
| 26 | 75 |
| 119 try: | 168 try: |
| 120 cast_types = eval( | 169 cast_types = eval( |
| 121 'lambda fields: [from_str(s, t) for s, t in zip(fields, [%s])]' | 170 'lambda fields: [from_str(s, t) for s, t in zip(fields, [%s])]' |
| 122 % args.column_types | 171 % args.column_types |
| 123 ) | 172 ) |
| 124 except Exception as e: | 173 except Exception as err: |
| 125 sys.exit( | 174 sys.exit( |
| 126 'While parsing column types, the following problem occured: "%s"' | 175 'While parsing column types, the following problem occured: "%s"' |
| 127 % e | 176 % err |
| 128 ) | 177 ) |
| 129 | 178 |
| 130 # Get and parse actions | 179 # Get and parse actions |
| 131 if args.file: | 180 if args.file: |
| 132 actions = [] | 181 actions = [] |
| 148 # a missing COL_ADD_SPEC is interpreted as mode A (append new column at the | 197 # a missing COL_ADD_SPEC is interpreted as mode A (append new column at the |
| 149 # end of the row). | 198 # end of the row). |
| 150 # COL_NAME is required with the --header option and specifies the name of the | 199 # COL_NAME is required with the --header option and specifies the name of the |
| 151 # new column; without --header, any COL_NAME gets ignored. | 200 # new column; without --header, any COL_NAME gets ignored. |
| 152 operators = 'is|not|or|and' | 201 operators = 'is|not|or|and' |
| 153 builtin_and_math_functions = ( | 202 builtin_functions = ( |
| 154 'abs|all|any|ascii|bin|bool|chr|complex|divmod|float|format|hex|int|len|' | 203 'abs|all|any|ascii|bin|bool|chr|complex|divmod|float|format|hex|int|len|' |
| 155 'list|map|max|min|oct|ord|pow|range|reversed|round|set|sorted|str|sum|type|' | 204 'list|map|max|min|oct|ord|pow|range|reversed|round|set|sorted|str|sum|type' |
| 156 'log|log10|exp|sqrt|ceil|floor' | 205 ) |
| 157 ) | 206 |
| 207 math_functions = ( | |
| 208 'acos|acosh|asin|asinh|atan|atan2|atanh|cbrt|ceil|comb|copysign|cos|cosh|degrees|' | |
| 209 'dist|erf|erfc|exp|exp2|expm1|fabs|factorial|floor|fmod|frexp|fsum|gamma|gcd|' | |
| 210 'hypot|inf|isclose|isfinite|isinf|isnan|isqrt|ldexp|lgamma|log|log10|log1p|' | |
| 211 'log2|modf|nextafter|perm|pi|pow|prod|remainder|sin|' | |
| 212 'sqrt|tan|tanh|tau|trunc|ulp' | |
| 213 ) | |
| 214 builtin_and_math_functions = builtin_functions + '|' + math_functions | |
| 158 imported_numpy_function = 'format_float_positional' | 215 imported_numpy_function = 'format_float_positional' |
| 159 string_and_list_methods = [ | 216 string_and_list_methods = [ |
| 160 name for name in dir('') + dir([]) if not name.startswith('_') | 217 name for name in dir('') + dir([]) if not name.startswith('_') |
| 161 ] | 218 ] |
| 162 whitelist = r"^([c0-9\+\-\*\/\(\)\.\'\"><=,:! ]|%s|%s|%s|%s)*$" % ( | 219 whitelist = r"^([c0-9\+\-\*\/\(\)\.\'\"><=,:! ]|%s|%s|%s|%s)*$" % ( |
| 169 ops = [] | 226 ops = [] |
| 170 num_cols = in_columns | 227 num_cols = in_columns |
| 171 for ac in actions: | 228 for ac in actions: |
| 172 try: | 229 try: |
| 173 expr_string, col_add_spec, new_col_name = ac.split(';') | 230 expr_string, col_add_spec, new_col_name = ac.split(';') |
| 231 print(expr_string) | |
| 174 except ValueError: | 232 except ValueError: |
| 175 sys.exit( | 233 sys.exit( |
| 176 'Invalid Action: "%s". ' | 234 'Invalid Action: "%s". ' |
| 177 'Required format: EXPR;[COL_ADD_SPEC];[COL_NAME]' % ac | 235 'Required format: EXPR;[COL_ADD_SPEC];[COL_NAME]' % ac |
| 178 ) | 236 ) |
