annotate column_maker.py @ 9:33b81f9ea109 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
author iuc
date Thu, 28 Jul 2022 15:27:54 +0000
parents 227e82286a0e
children beec6ecc7d3c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4dadd821722f Imported from capsule None
devteam
parents:
diff changeset
1 #!/usr/bin/env python
4
3335c0d583d8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
2 """
9
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
3 This tool takes a tab-delimited textfile as input and creates new columns in
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
4 the file which are the result of a computation performed on every row in the
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
5 original file. The tool will skip over empty and comment (starting with a #)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
6 lines within the file. It does not change the formatting of any original,
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
7 retained columns.
4
3335c0d583d8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
8 """
0
4dadd821722f Imported from capsule None
devteam
parents:
diff changeset
9
6
0aeda7a81b46 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit a993d43d9d1702a6cf584683cf72527a3f999236"
devteam
parents: 5
diff changeset
10 import argparse
9
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
11 import enum
4
3335c0d583d8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
12 import re
7
e7c273e8d4d6 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 35c79ccee143e8d178ebd24f6317888de3ca0187"
devteam
parents: 6
diff changeset
13 import sys
9
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
14 # Functions that may be used in the compute expression
8
227e82286a0e "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit c623e4b9f6dd6ff4b88d9386f3b0a0cb497e0a0e"
devteam
parents: 7
diff changeset
15 from math import ( # noqa: F401
227e82286a0e "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit c623e4b9f6dd6ff4b88d9386f3b0a0cb497e0a0e"
devteam
parents: 7
diff changeset
16 ceil,
227e82286a0e "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit c623e4b9f6dd6ff4b88d9386f3b0a0cb497e0a0e"
devteam
parents: 7
diff changeset
17 exp,
227e82286a0e "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit c623e4b9f6dd6ff4b88d9386f3b0a0cb497e0a0e"
devteam
parents: 7
diff changeset
18 floor,
227e82286a0e "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit c623e4b9f6dd6ff4b88d9386f3b0a0cb497e0a0e"
devteam
parents: 7
diff changeset
19 log,
227e82286a0e "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit c623e4b9f6dd6ff4b88d9386f3b0a0cb497e0a0e"
devteam
parents: 7
diff changeset
20 log10,
9
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
21 sqrt,
8
227e82286a0e "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit c623e4b9f6dd6ff4b88d9386f3b0a0cb497e0a0e"
devteam
parents: 7
diff changeset
22 )
227e82286a0e "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit c623e4b9f6dd6ff4b88d9386f3b0a0cb497e0a0e"
devteam
parents: 7
diff changeset
23
9
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
24 from numpy import format_float_positional
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
25
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
26
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
27 class Mode(enum.Enum):
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
28 APPEND = ''
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
29 INSERT = 'I'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
30 REPLACE = 'R'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
31
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
32
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
33 def from_str(s, to_type):
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
34 if to_type is list:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
35 return [part.strip(' ') for part in s.split(',')]
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
36 else:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
37 return to_type(s)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
38
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
39
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
40 def to_str(obj):
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
41 if type(obj) is list:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
42 return ','.join([to_str(i) for i in obj])
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
43 if args.avoid_scientific_notation and type(obj) is float:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
44 return format_float_positional(obj)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
45 return str(obj)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
46
0
4dadd821722f Imported from capsule None
devteam
parents:
diff changeset
47
6
0aeda7a81b46 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit a993d43d9d1702a6cf584683cf72527a3f999236"
devteam
parents: 5
diff changeset
48 parser = argparse.ArgumentParser()
9
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
49 parser.add_argument('input', type=str, help='input file')
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
50 parser.add_argument('output', type=str, help='output file')
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
51 parser.add_argument(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
52 '-t', '--column-types', nargs='?', required=True,
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
53 help='A comma-separated list of column types in the input file'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
54 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
55 parser.add_argument(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
56 '--avoid-scientific-notation', action='store_true',
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
57 help='avoid scientific notation'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
58 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
59 parser.add_argument(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
60 '--header', action='store_true',
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
61 help='The input has a header line with column names. '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
62 'Actions must specify names of newly calculated columns.'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
63 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
64 parser.add_argument(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
65 '--fail-on-non-existent-columns', action='store_true',
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
66 help='If an action references a column number that is not existent '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
67 'when the expression gets computed, the default behavior is to treat '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
68 'this as a case of rows for which the expression cannot be computed. '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
69 'The behavior of the tool will then depend on which of the '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
70 'non-computable switches is in effect. With this flag, in contrast, '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
71 'the tool will fail directly upon encountering a non-existing column.'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
72 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
73 non_computable = parser.add_mutually_exclusive_group()
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
74 non_computable.add_argument('--fail-on-non-computable', action='store_true')
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
75 non_computable.add_argument('--skip-non-computable', action='store_true')
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
76 non_computable.add_argument('--keep-non-computable', action='store_true')
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
77 non_computable.add_argument('--non-computable-blank', action='store_true')
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
78 non_computable.add_argument('--non-computable-default')
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
79
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
80 group = parser.add_mutually_exclusive_group(required=True)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
81 group.add_argument(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
82 '-a', '--actions', nargs='*', type=str,
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
83 help='One or more action(s) of the format EXPR;[COL_ADD_SPEC];[COL_NAME]'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
84 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
85 group.add_argument(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
86 '-f', '--file', type=str,
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
87 help='File to read actions from (mutually exclusive with -a)'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
88 )
6
0aeda7a81b46 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit a993d43d9d1702a6cf584683cf72527a3f999236"
devteam
parents: 5
diff changeset
89 args = parser.parse_args()
0aeda7a81b46 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit a993d43d9d1702a6cf584683cf72527a3f999236"
devteam
parents: 5
diff changeset
90
9
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
91 if not args.column_types:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
92 with open(args.input) as fh:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
93 if not fh.readline():
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
94 # Generally, the input must have at least one column to be
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
95 # considered tabular, but empty files are ok and should produce
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
96 # empty output.
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
97 with open(args.output, 'w') as out:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
98 pass
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
99 sys.exit()
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
100 sys.exit(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
101 "Missing column types. "
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
102 "In Galaxy, click the pencil icon on the history item and "
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
103 "select the Auto-detect option to correct it. "
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
104 "This tool can only be used with tab-delimited data."
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
105 )
7
e7c273e8d4d6 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 35c79ccee143e8d178ebd24f6317888de3ca0187"
devteam
parents: 6
diff changeset
106
9
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
107 in_column_types = [t.strip() for t in args.column_types.split(',')]
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
108 in_columns = len(in_column_types)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
109
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
110 # Prepare initial column variable names and type cast representations
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
111 # for column data types
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
112 cols, type_casts = [], []
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
113 for n, col_type in enumerate(in_column_types, start=1):
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
114 col_name = "c%d" % n
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
115 cols.append(col_name)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
116 col_str = ', '.join(cols) # 'c1, c2, c3, c4'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
117
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
118 # Define lambda for type-casting of original row fields
0
4dadd821722f Imported from capsule None
devteam
parents:
diff changeset
119 try:
9
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
120 cast_types = eval(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
121 'lambda fields: [from_str(s, t) for s, t in zip(fields, [%s])]'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
122 % args.column_types
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
123 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
124 except Exception as e:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
125 sys.exit(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
126 'While parsing column types, the following problem occured: "%s"'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
127 % e
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
128 )
0
4dadd821722f Imported from capsule None
devteam
parents:
diff changeset
129
9
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
130 # Get and parse actions
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
131 if args.file:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
132 actions = []
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
133 with open(args.file) as i:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
134 for line in i:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
135 line = line.strip()
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
136 if line:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
137 actions.append(line)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
138 else:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
139 actions = args.actions
0
4dadd821722f Imported from capsule None
devteam
parents:
diff changeset
140
9
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
141 # each action must be a full data row manipulation instruction of the form:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
142 # EXPR;[COL_ADD_SPEC];[COL_NAME]
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
143 # where EXPR is the actual expression to compute on the row,
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
144 # COL_ADD_SPEC consists of a column index and a mode identifier for how the
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
145 # new column should be added.
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
146 # Examples: 3I (insert new col before current column 3),
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
147 # 2R (replace current column 2 with new column);
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
148 # a missing COL_ADD_SPEC is interpreted as mode A (append new column at the
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
149 # end of the row).
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
150 # COL_NAME is required with the --header option and specifies the name of the
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
151 # new column; without --header, any COL_NAME gets ignored.
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
152 operators = 'is|not|or|and'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
153 builtin_and_math_functions = (
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
154 'abs|all|any|ascii|bin|bool|chr|complex|divmod|float|format|hex|int|len|'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
155 'list|map|max|min|oct|ord|pow|range|reversed|round|set|sorted|str|sum|type|'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
156 'log|log10|exp|sqrt|ceil|floor'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
157 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
158 imported_numpy_function = 'format_float_positional'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
159 string_and_list_methods = [
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
160 name for name in dir('') + dir([]) if not name.startswith('_')
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
161 ]
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
162 whitelist = r"^([c0-9\+\-\*\/\(\)\.\'\"><=,:! ]|%s|%s|%s|%s)*$" % (
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
163 operators,
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
164 builtin_and_math_functions,
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
165 imported_numpy_function,
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
166 '|'.join(string_and_list_methods)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
167 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
168 valid_pat = re.compile(whitelist)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
169 ops = []
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
170 num_cols = in_columns
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
171 for ac in actions:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
172 try:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
173 expr_string, col_add_spec, new_col_name = ac.split(';')
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
174 except ValueError:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
175 sys.exit(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
176 'Invalid Action: "%s". '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
177 'Required format: EXPR;[COL_ADD_SPEC];[COL_NAME]' % ac
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
178 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
179 if not valid_pat.match(expr_string):
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
180 sys.exit('Invalid expression: "%s"' % expr_string)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
181 try:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
182 expr_lambda = eval('lambda %s: %s' % (col_str, expr_string))
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
183 except Exception as e:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
184 if str(e).startswith('invalid syntax'):
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
185 sys.exit(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
186 'Expression "%s" caused a syntax error during parsing.'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
187 % expr_string
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
188 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
189 else:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
190 sys.exit(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
191 'While parsing expression "%s" the following problem occured: '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
192 '"%s"' % (expr_string, str(e))
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
193 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
194 try:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
195 new_col_idx = int(col_add_spec[:-1] or '0') - 1
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
196 except ValueError:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
197 sys.exit(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
198 'COL_ADD_SPECS need to start with a (1-based) column index. '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
199 'Could not parse a column index from "%s"' % col_add_spec
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
200 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
201 try:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
202 mode = Mode(col_add_spec[-1:])
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
203 except ValueError:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
204 sys.exit(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
205 'COL_ADD_SPECS need to end in a single-character mode identifier '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
206 '("I", or "R"), or be empty (for Append mode). '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
207 'Could not parse a valid identifier from "%s"' % col_add_spec
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
208 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
209 if mode is Mode.REPLACE:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
210 if new_col_idx < 0 or new_col_idx >= num_cols:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
211 sys.exit(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
212 'Cannot replace the contents of column %d as specified by '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
213 'action "%s". No such column at this point of the '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
214 'computation' % (new_col_idx + 1, ac)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
215 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
216 if not new_col_name and args.header:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
217 sys.exit(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
218 'A name is required for any new columns when using an existing '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
219 'header line (--header option), but found none in action: '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
220 '"%s"' % ac
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
221 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
222 # Successfully parsed the instruction
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
223 # Store the expression lambda, the index and name of the new column, and
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
224 # the original string representation of the expression (for use in
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
225 # potential later error messages).
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
226 ops.append([expr_lambda, new_col_idx, mode, new_col_name, expr_string])
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
227 if mode is Mode.APPEND or mode is Mode.INSERT:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
228 # If the current expression results in an additional column,
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
229 # we need to handle the new field in subsequent lambda functions.
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
230 num_cols += 1
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
231 col_str += ', c%d' % num_cols
4
3335c0d583d8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit 2b17bdfc47ca4d7f1a584216c4bd61a7050df7ea"
devteam
parents: 2
diff changeset
232
9
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
233
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
234 # ready to start parsing the input file
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
235 print(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
236 'Computing %d new columns with instructions %s'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
237 % (num_cols - in_columns, actions)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
238 )
0
4dadd821722f Imported from capsule None
devteam
parents:
diff changeset
239 skipped_lines = 0
4dadd821722f Imported from capsule None
devteam
parents:
diff changeset
240 first_invalid_line = 0
4dadd821722f Imported from capsule None
devteam
parents:
diff changeset
241 invalid_line = None
9
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
242 lines_computed = 0
0
4dadd821722f Imported from capsule None
devteam
parents:
diff changeset
243 total_lines = 0
9
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
244 non_existent_col_pat = re.compile(r"name 'c\d+' is not defined")
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
245
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
246 with open(args.input, encoding='utf-8') as fh, \
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
247 open(args.output, 'w', encoding='utf-8') as out:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
248 if args.header:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
249 # compute new header line from original
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
250 header_cols = fh.readline().strip('\n').split('\t')
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
251 for _, col_idx, mode, col_name, _ in ops:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
252 if mode is Mode.INSERT:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
253 header_cols.insert(col_idx, col_name)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
254 elif mode is Mode.REPLACE:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
255 header_cols[col_idx] = col_name
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
256 else:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
257 header_cols.append(col_name)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
258 out.write('\t'.join(header_cols) + '\n')
0
4dadd821722f Imported from capsule None
devteam
parents:
diff changeset
259
9
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
260 # read data, skipping empty and comment lines, and perform computations
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
261 # that will result in new columns
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
262 for i, line in enumerate(fh):
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
263 total_lines += 1
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
264 line = line.rstrip('\n')
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
265 if not line or line.startswith('#'):
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
266 skipped_lines += 1
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
267 if not invalid_line:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
268 first_invalid_line = i + 1
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
269 invalid_line = line
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
270 continue
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
271 fields = line.split('\t')
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
272 if len(fields) == in_columns:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
273 try:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
274 typed_fields = cast_types(fields)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
275 except ValueError as e:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
276 sys.exit(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
277 'Failed to convert some of the columns in line #%d to their '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
278 'expected types. The error was: "%s" for the line: "%s"'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
279 % (i, str(e), line)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
280 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
281 else:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
282 # A "suspicious" line with less or more fields than expected
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
283 # Type-casting for it might fail or not, but it is pointless to
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
284 # even try because subsequent computation of any expression will
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
285 # fail anyway as expression lambdas expect a fixed number of
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
286 # arguments.
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
287 # Lets pass in a copy of the original string fields, let
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
288 # the computation of the first expression fail, then have that
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
289 # situation handled according to the non-computable settings in
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
290 # effect.
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
291 typed_fields = fields[:]
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
292 for fun, col_idx, mode, col_name, ex in ops:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
293 try:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
294 try:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
295 new_val = fun(*typed_fields)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
296 except NameError as e:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
297 # Python 3.10+ would have the problematic name
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
298 # available as e.name
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
299 if non_existent_col_pat.fullmatch(str(e)) and (
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
300 not args.fail_on_non_existent_columns
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
301 ):
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
302 # Looks like a reference to a non-existent column
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
303 # and we are not supposed to fail on it directly.
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
304 # Reraise and have it handled as a non-computable
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
305 # row.
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
306 raise
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
307 # NameErrors are not row-specific, but indicate a
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
308 # general problem with the user-supplied expression.
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
309 sys.exit(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
310 'While parsing expression "%s" the following '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
311 'problem occured: "%s"' % (ex, str(e))
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
312 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
313 except Exception as e:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
314 if args.skip_non_computable:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
315 # log that a line got skipped, then stop computing
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
316 # for this line
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
317 skipped_lines += 1
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
318 if not invalid_line:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
319 first_invalid_line = i + 1
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
320 invalid_line = line
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
321 break
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
322 if args.keep_non_computable:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
323 # write the original line unchanged and stop computing
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
324 # for this line
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
325 out.write(line + '\n')
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
326 break
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
327 if args.non_computable_blank:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
328 new_val = ''
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
329 elif args.non_computable_default is not None:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
330 new_val = args.non_computable_default
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
331 else:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
332 # --fail_on_non_computable
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
333 # (which is default behavior, too)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
334 sys.exit(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
335 'Could not compute a new column value using "%s" on '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
336 'line #%d: "%s". Error was "%s"'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
337 % (ex, i, line, str(e))
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
338 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
339 if mode is Mode.INSERT:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
340 fields.insert(col_idx, new_val)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
341 typed_fields.insert(col_idx, new_val)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
342 elif mode is Mode.REPLACE:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
343 if col_idx > len(fields):
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
344 # Intentionally allow "replacing" one column beyond
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
345 # current fields since this can be used to fix
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
346 # short lines in the input.
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
347 sys.exit(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
348 'Cannot replace column #%d in line with %d columns: '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
349 '"%s"' % (col_idx + 1, len(fields), line)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
350 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
351 fields[col_idx:col_idx + 1] = [new_val]
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
352 typed_fields[col_idx:col_idx + 1] = [new_val]
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
353 else:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
354 fields.append(new_val)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
355 typed_fields.append(new_val)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
356 else:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
357 fields = [to_str(field) for field in fields]
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
358 out.write('\t'.join(fields) + '\n')
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
359 lines_computed += 1
0
4dadd821722f Imported from capsule None
devteam
parents:
diff changeset
360
4dadd821722f Imported from capsule None
devteam
parents:
diff changeset
361
9
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
362 valid_lines = total_lines - skipped_lines
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
363 if valid_lines > 0:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
364 print(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
365 'Computed new column values for %4.2f%% of %d lines written.'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
366 % (100.0 * lines_computed / valid_lines, valid_lines)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
367 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
368 elif args.fail_on_non_existent_columns:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
369 # Warn the user that there could be an issue with an expression.
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
370 print(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
371 'Could not compute a new column for any input row! '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
372 'Please check your expression(s) "%s" for problems.'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
373 % actions
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
374 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
375 else:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
376 # Same, but the problem could also be a reference to a non-existent
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
377 # column.
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
378 print(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
379 'Could not compute a new column for any input row! '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
380 'Please check your expression(s) "%s" for references to non-existent '
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
381 'columns or other problems.'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
382 % actions
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
383 )
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
384 if skipped_lines > 0:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
385 print('Skipped %d invalid lines starting at line #%d: "%s"' %
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
386 (skipped_lines, first_invalid_line, invalid_line))
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
387 if lines_computed < valid_lines:
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
388 print(
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
389 'Rewrote %d lines unmodified because computation of a new value failed'
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
390 % (valid_lines - lines_computed)
33b81f9ea109 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/column_maker commit fe76077775aaca531f6a563fdfcbd73fbf1528e7
iuc
parents: 8
diff changeset
391 )