annotate scripts/table_compute.py @ 0:1b0f96ed73f2 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
author iuc
date Sat, 17 Aug 2019 16:25:37 -0400
parents
children dddadbbac949
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
1 #!/usr/bin/env python3
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
2 """
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
3 Table Compute tool - a wrapper around pandas with parameter input validation.
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
4 """
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
5
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
6 __version__ = "0.8"
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
7
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
8 import csv
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
9 import math
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
10 from sys import argv
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
11
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
12 import numpy as np
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
13 import pandas as pd
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
14 import userconfig as uc
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
15 from safety import Safety
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
16 # This should be generated in the same directory
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
17
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
18 # Version command should not need to copy the config
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
19 if len(argv) == 2 and argv[1] == "--version":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
20 print(__version__)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
21 exit(-1)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
22
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
23
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
24 class Utils:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
25 @staticmethod
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
26 def getOneValueMathOp(op_name):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
27 "Returns a simple one value math operator such as log, sqrt, etc"
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
28 return getattr(math, op_name)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
29
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
30 @staticmethod
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
31 def getVectorPandaOp(op_name):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
32 "Returns a valid DataFrame vector operator"
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
33 return getattr(pd.DataFrame, op_name)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
34
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
35 @staticmethod
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
36 def getTwoValuePandaOp(op_name, pd_obj):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
37 "Returns a valid two value DataFrame or Series operator"
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
38 return getattr(type(pd_obj), "__" + op_name + "__")
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
39
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
40
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
41 # Math is imported but not directly used because users
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
42 # may specify a "math.<function>" when inserting a custom
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
43 # function. To remove linting errors, which break CI testing
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
44 # we will just use an arbitrary math statement here.
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
45 __ = math.log
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
46
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
47
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
48 # Set decimal precision
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
49 pd.options.display.precision = uc.Default["precision"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
50
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
51 user_mode = uc.Default["user_mode"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
52 user_mode_single = None
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
53 out_table = None
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
54 params = uc.Data["params"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
55
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
56 if user_mode == "single":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
57 # Read in TSV file
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
58 data = pd.read_csv(
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
59 uc.Data["tables"][0]["reader_file"],
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
60 header=uc.Data["tables"][0]["reader_header"],
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
61 index_col=uc.Data["tables"][0]["reader_row_col"],
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
62 keep_default_na=uc.Default["narm"],
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
63 sep='\t'
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
64 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
65 # Fix whitespace issues in index or column names
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
66 data.columns = [col.strip() if type(col) is str else col
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
67 for col in data.columns]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
68 data.index = [row.strip() if type(row) is str else row
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
69 for row in data.index]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
70
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
71 user_mode_single = params["user_mode_single"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
72
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
73 if user_mode_single == "precision":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
74 # Useful for changing decimal precision on write out
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
75 out_table = data
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
76
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
77 elif user_mode_single == "select":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
78 cols_specified = params["select_cols_wanted"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
79 rows_specified = params["select_rows_wanted"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
80
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
81 # Select all indexes if empty array of values
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
82 if not cols_specified:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
83 cols_specified = range(len(data.columns))
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
84 if not rows_specified:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
85 rows_specified = range(len(data))
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
86
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
87 # do not use duplicate indexes
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
88 # e.g. [2,3,2,5,5,4,2] to [2,3,5,4]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
89 nodupes_col = not params["select_cols_unique"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
90 nodupes_row = not params["select_rows_unique"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
91
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
92 if nodupes_col:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
93 cols_specified = [x for i, x in enumerate(cols_specified)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
94 if x not in cols_specified[:i]]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
95 if nodupes_row:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
96 rows_specified = [x for i, x in enumerate(rows_specified)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
97 if x not in rows_specified[:i]]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
98
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
99 out_table = data.iloc[rows_specified, cols_specified]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
100
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
101 elif user_mode_single == "filtersumval":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
102 mode = params["filtersumval_mode"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
103 axis = params["filtersumval_axis"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
104 operation = params["filtersumval_op"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
105 compare_operation = params["filtersumval_compare"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
106 value = params["filtersumval_against"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
107 minmatch = params["filtersumval_minmatch"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
108
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
109 if mode == "operation":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
110 # Perform axis operation
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
111 summary_op = Utils.getVectorPandaOp(operation)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
112 axis_summary = summary_op(data, axis=axis)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
113 # Perform vector comparison
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
114 compare_op = Utils.getTwoValuePandaOp(
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
115 compare_operation, axis_summary
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
116 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
117 axis_bool = compare_op(axis_summary, value)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
118
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
119 elif mode == "element":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
120 if operation.startswith("str_"):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
121 data = data.astype("str")
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
122 value = str(value)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
123 # Convert str_eq to eq
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
124 operation = operation[4:]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
125 else:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
126 value = float(value)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
127
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
128 op = Utils.getTwoValuePandaOp(operation, data)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
129 bool_mat = op(data, value)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
130 axis_bool = np.sum(bool_mat, axis=axis) >= minmatch
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
131
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
132 out_table = data.loc[:, axis_bool] if axis == 0 else data.loc[axis_bool, :]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
133
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
134 elif user_mode_single == "matrixapply":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
135 # 0 - column, 1 - row
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
136 axis = params["matrixapply_dimension"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
137 # sd, mean, max, min, sum, median, summary
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
138 operation = params["matrixapply_op"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
139
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
140 if operation is None:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
141 use_custom = params["matrixapply_custom"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
142 if use_custom:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
143 custom_func = params["matrixapply_custom_func"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
144
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
145 def fun(vec):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
146 """Dummy Function"""
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
147 return vec
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
148
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
149 ss = Safety(custom_func, ['vec'], 'pd.Series')
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
150 fun_string = ss.generateFunction()
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
151 exec(fun_string) # SUPER DUPER SAFE...
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
152
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
153 out_table = data.apply(fun, axis)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
154 else:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
155 print("No operation given")
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
156 exit(-1)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
157 else:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
158 op = getattr(pd.DataFrame, operation)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
159 out_table = op(data, axis)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
160
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
161 elif user_mode_single == "element":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
162 # lt, gt, ge, etc.
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
163 operation = params["element_op"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
164 if operation is not None:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
165 op = Utils.getTwoValuePandaOp(operation, data)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
166 value = params["element_value"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
167 try:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
168 # Could be numeric
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
169 value = float(value)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
170 except ValueError:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
171 pass
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
172 # generate filter matrix of True/False values
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
173 bool_mat = op(data, value)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
174 else:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
175 # implement no filtering through a filter matrix filled with
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
176 # True values.
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
177 bool_mat = np.full(data.shape, True)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
178
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
179 # Get the main processing mode
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
180 mode = params["element_mode"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
181 if mode == "replace":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
182 replacement_val = params["element_replace"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
183 out_table = data.mask(bool_mat, replacement_val)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
184 elif mode == "modify":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
185 mod_op = Utils.getOneValueMathOp(params["element_modify_op"])
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
186 out_table = data.mask(
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
187 bool_mat, data.where(bool_mat).applymap(mod_op)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
188 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
189 elif mode == "scale":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
190 scale_op = Utils.getTwoValuePandaOp(
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
191 params["element_scale_op"], data
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
192 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
193 scale_value = params["element_scale_value"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
194 out_table = data.mask(
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
195 bool_mat, scale_op(data.where(bool_mat), scale_value)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
196 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
197 elif mode == "custom":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
198 element_customop = params["element_customop"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
199
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
200 def fun(elem):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
201 """Dummy Function"""
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
202 return elem
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
203
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
204 ss = Safety(element_customop, ['elem'])
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
205 fun_string = ss.generateFunction()
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
206 exec(fun_string) # SUPER DUPER SAFE...
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
207
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
208 out_table = data.mask(
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
209 bool_mat, data.where(bool_mat).applymap(fun)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
210 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
211 else:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
212 print("No such element mode!", mode)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
213 exit(-1)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
214
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
215 elif user_mode_single == "fulltable":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
216 general_mode = params["mode"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
217
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
218 if general_mode == "melt":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
219 melt_ids = params["MELT"]["melt_ids"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
220 melt_values = params["MELT"]["melt_values"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
221
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
222 out_table = pd.melt(data, id_vars=melt_ids, value_vars=melt_values)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
223 elif general_mode == "pivot":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
224 pivot_index = params["PIVOT"]["pivot_index"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
225 pivot_column = params["PIVOT"]["pivot_column"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
226 pivot_values = params["PIVOT"]["pivot_values"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
227
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
228 out_table = data.pivot(
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
229 index=pivot_index, columns=pivot_column, values=pivot_values
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
230 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
231 elif general_mode == "custom":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
232 custom_func = params["fulltable_customop"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
233
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
234 def fun(tableau):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
235 """Dummy Function"""
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
236 return tableau
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
237
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
238 ss = Safety(custom_func, ['table'], 'pd.DataFrame')
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
239 fun_string = ss.generateFunction()
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
240 exec(fun_string) # SUPER DUPER SAFE...
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
241
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
242 out_table = fun(data)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
243
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
244 else:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
245 print("No such mode!", user_mode_single)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
246 exit(-1)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
247
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
248
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
249 elif user_mode == "multiple":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
250
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
251 table_sections = uc.Data["tables"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
252
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
253 if not table_sections:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
254 print("Multiple table sets not given!")
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
255 exit(-1)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
256
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
257 reader_skip = uc.Default["reader_skip"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
258
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
259 # Data
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
260 table = []
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
261 # 1-based handlers for users "table1", "table2", etc.
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
262 table_names = []
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
263 # Actual 0-based references "table[0]", "table[1]", etc.
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
264 table_names_real = []
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
265
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
266 # Read and populate tables
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
267 for x, t_sect in enumerate(table_sections):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
268 tmp = pd.read_csv(
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
269 t_sect["file"],
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
270 header=t_sect["header"],
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
271 index_col=t_sect["row_names"],
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
272 keep_default_na=uc.Default["narm"],
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
273 sep="\t"
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
274 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
275 table.append(tmp)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
276 table_names.append("table" + str(x + 1))
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
277 table_names_real.append("table[" + str(x) + "]")
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
278
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
279 custom_op = params["fulltable_customop"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
280 ss = Safety(custom_op, table_names, 'pd.DataFrame')
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
281 fun_string = ss.generateFunction()
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
282 # Change the argument to table
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
283 fun_string = fun_string.replace("fun(table1):", "fun():")
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
284 # table1 to table[1]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
285 for name, name_real in zip(table_names, table_names_real):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
286 fun_string = fun_string.replace(name, name_real)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
287
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
288 fun_string = fun_string.replace("fun():", "fun(table):")
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
289 exec(fun_string) # SUPER DUPER SAFE...
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
290 out_table = fun(table)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
291
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
292 else:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
293 print("No such mode!", user_mode)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
294 exit(-1)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
295
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
296 if not isinstance(out_table, (pd.DataFrame, pd.Series)):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
297 print('The specified operation did not result in a table to return.')
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
298 raise RuntimeError(
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
299 'The operation did not generate a pd.DataFrame or pd.Series to return.'
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
300 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
301 out_parameters = {
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
302 "sep": "\t",
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
303 "float_format": "%%.%df" % pd.options.display.precision,
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
304 "header": uc.Default["out_headers_col"],
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
305 "index": uc.Default["out_headers_row"]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
306 }
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
307 if user_mode_single not in ('matrixapply', None):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
308 out_parameters["quoting"] = csv.QUOTE_NONE
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
309
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
310 out_table.to_csv(uc.Default["outtable"], **out_parameters)