annotate column_maker.py @ 4:6e8d94597139 draft

"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 0cb87d8f454f205af021d653d7f7d5a7c14c7718"
author devteam
date Wed, 15 Jul 2020 10:38:50 -0400
parents be25c075ed54
children 9cd341095afd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
1 #!/usr/bin/env python
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
2 """
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
3 This tool takes a tab-delimited textfile as input and creates another column in
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
4 the file which is the result of a computation performed on every row in the
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
5 original file. The tool will skip over invalid lines within the file,
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
6 informing the user about the number of lines skipped.
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
7 """
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
8 from __future__ import print_function
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
9
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
10 import re
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
11 import sys
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
12
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
13 assert sys.version_info[:2] >= (2, 4)
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
14
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
15 inp_file = sys.argv[1]
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
16 out_file = sys.argv[2]
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
17 expr = sys.argv[3]
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
18 round_result = sys.argv[4]
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
19 try:
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
20 in_columns = int(sys.argv[5])
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
21 except Exception:
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
22 exit("Missing or invalid 'columns' metadata value, click the pencil icon in the history item and select the Auto-detect option to correct it. This tool can only be used with tab-delimited data.")
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
23 if in_columns < 2:
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
24 # To be considered tabular, data must fulfill requirements of the sniff.is_column_based() method.
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
25 exit("Missing or invalid 'columns' metadata value, click the pencil icon in the history item and select the Auto-detect option to correct it. This tool can only be used with tab-delimited data.")
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
26 try:
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
27 in_column_types = sys.argv[6].split(',')
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
28 except Exception:
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
29 exit("Missing or invalid 'column_types' metadata value, click the pencil icon in the history item and select the Auto-detect option to correct it. This tool can only be used with tab-delimited data.")
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
30 if len(in_column_types) != in_columns:
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
31 exit("The 'columns' metadata setting does not conform to the 'column_types' metadata setting, click the pencil icon in the history item and select the Auto-detect option to correct it. This tool can only be used with tab-delimited data.")
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
32 avoid_scientific_notation = sys.argv[7]
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
33
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
34 # Unescape if input has been escaped
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
35 mapped_str = {
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
36 '__lt__': '<',
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
37 '__le__': '<=',
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
38 '__eq__': '==',
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
39 '__ne__': '!=',
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
40 '__gt__': '>',
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
41 '__ge__': '>=',
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
42 '__sq__': '\'',
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
43 '__dq__': '"',
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
44 }
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
45 for key, value in mapped_str.items():
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
46 expr = expr.replace(key, value)
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
47
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
48 operators = 'is|not|or|and'
4
6e8d94597139 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 0cb87d8f454f205af021d653d7f7d5a7c14c7718"
devteam
parents: 3
diff changeset
49 builtin_and_math_functions = 'abs|all|any|bin|chr|cmp|complex|divmod|float|bool|hex|int|len|long|max|min|oct|ord|pow|range|reversed|round|sorted|str|sum|type|unichr|unicode|log|log10|exp|sqrt|ceil|floor'
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
50 string_and_list_methods = [name for name in dir('') + dir([]) if not name.startswith('_')]
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
51 whitelist = r"^([c0-9\+\-\*\/\(\)\.\'\"><=,:! ]|%s|%s|%s)*$" % (operators, builtin_and_math_functions, '|'.join(string_and_list_methods))
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
52 if not re.compile(whitelist).match(expr):
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
53 exit("Invalid expression")
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
54 if avoid_scientific_notation == "yes":
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
55 expr = "format_float_positional(%s)" % expr
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
56
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
57 # Prepare the column variable names and wrappers for column data types
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
58 cols, type_casts = [], []
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
59 for col in range(1, in_columns + 1):
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
60 col_name = "c%d" % col
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
61 cols.append(col_name)
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
62 col_type = in_column_types[col - 1].strip()
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
63 if round_result == 'no' and col_type == 'int':
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
64 col_type = 'float'
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
65 type_cast = "%s(%s)" % (col_type, col_name)
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
66 type_casts.append(type_cast)
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
67
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
68 col_str = ', '.join(cols) # 'c1, c2, c3, c4'
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
69 type_cast_str = ', '.join(type_casts) # 'str(c1), int(c2), int(c3), str(c4)'
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
70 assign = "%s = line.split('\\t')" % col_str
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
71 wrap = "%s = %s" % (col_str, type_cast_str)
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
72 skipped_lines = 0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
73 first_invalid_line = 0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
74 invalid_line = None
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
75 lines_kept = 0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
76 total_lines = 0
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
77 out = open(out_file, 'wt')
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
78
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
79 # Read input file, skipping invalid lines, and perform computation that will result in a new column
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
80 code = '''
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
81 # import here since flake8 complains otherwise
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
82 from math import (
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
83 ceil,
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
84 exp,
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
85 floor,
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
86 log,
4
6e8d94597139 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 0cb87d8f454f205af021d653d7f7d5a7c14c7718"
devteam
parents: 3
diff changeset
87 log10,
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
88 sqrt
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
89 )
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
90 from numpy import format_float_positional
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
91
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
92 fh = open(inp_file)
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
93 for i, line in enumerate(fh):
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
94 total_lines += 1
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
95 line = line.rstrip('\\r\\n')
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
96 if not line or line.startswith('#'):
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
97 skipped_lines += 1
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
98 if not invalid_line:
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
99 first_invalid_line = i + 1
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
100 invalid_line = line
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
101 continue
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
102 try:
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
103 %s
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
104 %s
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
105 new_val = %s
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
106 if round_result == "yes":
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
107 new_val = int(round(new_val))
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
108 new_line = line + '\\t' + str(new_val) + "\\n"
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
109 out.write(new_line)
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
110 lines_kept += 1
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
111 except Exception:
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
112 skipped_lines += 1
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
113 if not invalid_line:
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
114 first_invalid_line = i + 1
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
115 invalid_line = line
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
116 fh.close()
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
117 ''' % (assign, wrap, expr)
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
118
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
119 valid_expr = True
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
120 try:
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
121 exec(code)
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
122 except Exception as e:
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
123 out.close()
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
124 if str(e).startswith('invalid syntax'):
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
125 valid_expr = False
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
126 exit('Expression "%s" likely invalid. See tool tips, syntax and examples.' % expr)
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
127 else:
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
128 exit(str(e))
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
129
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
130 if valid_expr:
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
131 out.close()
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
132 valid_lines = total_lines - skipped_lines
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
133 print('Creating column %d with expression %s' % (in_columns + 1, expr))
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
134 if valid_lines > 0:
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
135 print('kept %4.2f%% of %d lines.' % (100.0 * lines_kept / valid_lines,
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
136 total_lines))
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
137 else:
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
138 print('Possible invalid expression "%s" or non-existent column referenced. See tool tips, syntax and examples.' % expr)
0
08a01b2ce4cd Imported from capsule None
devteam
parents:
diff changeset
139 if skipped_lines > 0:
3
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
140 print('Skipped %d invalid lines starting at line #%d: "%s"' %
be25c075ed54 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
141 (skipped_lines, first_invalid_line, invalid_line))