annotate scripts/table_compute.py @ 3:60ff16842fcd draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 5c7c463baf40edda673a569e91b2c2a5e3b6b4f8"
author iuc
date Fri, 18 Oct 2019 06:22:51 -0400
parents 02c3e335a695
children 93a3ce78ce55
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
1
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
6
2
02c3e335a695 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit d00a518202228b990aeeea2ec3f842501fd2ec09"
iuc
parents: 1
diff changeset
7 __version__ = "0.9.2"
0
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
8
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
9 import csv
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
10 import math
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
11 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
12
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
13 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
14 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
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
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
17 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
18 print(__version__)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
19 exit(-1)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
20
1
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
21 # The import below should be generated in the same directory as
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
22 # the table_compute.py script.
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
23 # It is placed here so that the --version switch does not fail
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
24 import userconfig as uc # noqa: I100,I202
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
25
0
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
26
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
27 class Utils:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
28 @staticmethod
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
29 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
30 "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
31 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
32
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
33 @staticmethod
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
34 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
35 "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
36 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
37
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
38 @staticmethod
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
39 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
40 "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
41 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
42
1
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
43 @staticmethod
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
44 def readcsv(filedict, narm):
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
45 data = pd.read_csv(
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
46 filedict["file"],
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
47 header=filedict["header"],
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
48 index_col=filedict["row_names"],
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
49 keep_default_na=narm,
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
50 nrows=filedict["nrows"],
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
51 skipfooter=filedict["skipfooter"],
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
52 skip_blank_lines=filedict["skip_blank_lines"],
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
53 sep='\t'
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
54 )
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
55 # Fix whitespace issues in index or column names
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
56 data.columns = [col.strip() if type(col) is str else col
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
57 for col in data.columns]
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
58 data.index = [row.strip() if type(row) is str else row
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
59 for row in data.index]
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
60 return(data)
0
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
61
1
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
62 @staticmethod
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
63 def rangemaker(tab):
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
64 # e.g. "1:3,2:-2" specifies "1,2,3,2,1,0,-1,-2" to give [0,1,2,1,0,-1,-2]
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
65 # Positive indices are decremented by 1 to reference 0-base numbering
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
66 # Negative indices are unaltered, so that -1 refers to the last column
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
67 out = []
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
68 err_mess = None
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
69 for ranges in tab.split(","):
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
70 nums = ranges.split(":")
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
71 if len(nums) == 1:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
72 numb = int(nums[0])
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
73 # Positive numbers get decremented.
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
74 # i.e. column "3" refers to index 2
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
75 # column "-1" still refers to index -1
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
76 if numb != 0:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
77 out.append(numb if (numb < 0) else (numb - 1))
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
78 else:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
79 err_mess = "Please do not use 0 as an index"
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
80 elif len(nums) == 2:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
81 left, right = map(int, nums)
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
82 if 0 in (left, right):
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
83 err_mess = "Please do not use 0 as an index"
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
84 elif left < right:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
85 if left > 0: # and right > 0 too
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
86 # 1:3 to 0,1,2
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
87 out.extend(range(left - 1, right))
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
88 elif right < 0: # and left < 0 too
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
89 # -3:-1 to -3,-2,-1
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
90 out.extend(range(left, right + 1))
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
91 elif left < 0 and right > 0:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
92 # -2:2 to -2,-1,0,1
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
93 out.extend(range(left, 0))
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
94 out.extend(range(0, right))
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
95 elif right < left:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
96 if right > 0: # and left > 0
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
97 # 3:1 to 2,1,0
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
98 out.extend(range(left - 1, right - 2, -1))
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
99 elif left < 0: # and right < 0
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
100 # -1:-3 to -1,-2,-3
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
101 out.extend(range(left, right - 1, -1))
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
102 elif right < 0 and left > 0:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
103 # 2:-2 to 1,0,-1,-2
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
104 out.extend(range(left - 1, right - 1, -1))
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
105 else:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
106 err_mess = "%s should not be equal or contain a zero" % nums
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
107 if err_mess:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
108 print(err_mess)
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
109 return(None)
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
110 return(out)
0
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
111
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
112
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
113 # 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
114 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
115
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
116 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
117 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
118 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
119 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
120
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
121 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
122 # Read in TSV file
1
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
123 data = Utils.readcsv(uc.Data["tables"][0], uc.Default["narm"])
0
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
124 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
125
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
126 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
127 # 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
128 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
129
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
130 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
131 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
132 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
133
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
134 # Select all indexes if empty array of values
1
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
135 if cols_specified:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
136 cols_specified = Utils.rangemaker(cols_specified)
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
137 else:
0
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
138 cols_specified = range(len(data.columns))
1
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
139 if rows_specified:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
140 rows_specified = Utils.rangemaker(rows_specified)
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
141 else:
0
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
142 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
143
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
144 # 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
145 # 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
146 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
147 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
148
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
149 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
150 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
151 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
152 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
153 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
154 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
155
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
156 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
157
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
158 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
159 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
160 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
161 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
162 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
163 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
164 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
165
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
166 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
167 # 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
168 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
169 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
170 # 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
171 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
172 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
173 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
174 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
175
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
176 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
177 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
178 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
179 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
180 # 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
181 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
182 else:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
183 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
184
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
185 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
186 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
187 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
188
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
189 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
190
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
191 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
192 # 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
193 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
194 # 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
195 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
196
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
197 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
198 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
199 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
200 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
201
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
202 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
203 """Dummy Function"""
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
204 return vec
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
205
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
206 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
207 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
208 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
209
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
210 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
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 operation given")
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 else:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
215 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
216 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
217
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
218 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
219 # 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
220 operation = params["element_op"]
1
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
221 bool_mat = None
0
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
222 if operation is not None:
1
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
223 if operation == "rowcol":
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
224 # Select all indexes if empty array of values
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
225 if "element_cols" in params:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
226 cols_specified = Utils.rangemaker(params["element_cols"])
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
227 else:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
228 cols_specified = range(len(data.columns))
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
229 if "element_rows" in params:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
230 rows_specified = Utils.rangemaker(params["element_rows"])
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
231 else:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
232 rows_specified = range(len(data))
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
233
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
234 # Inclusive selection:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
235 # - True: Giving a row or column will match all elements in that row or column
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
236 # - False: Give a row or column will match only elements in both those rows or columns
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
237 inclusive = params["element_inclusive"]
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
238
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
239 # Create a bool matrix (intialised to False) with selected
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
240 # rows and columns set to True
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
241 bool_mat = data.copy()
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
242 bool_mat[:] = False
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
243 if inclusive:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
244 bool_mat.iloc[rows_specified, :] = True
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
245 bool_mat.iloc[:, cols_specified] = True
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
246 else:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
247 bool_mat.iloc[rows_specified, cols_specified] = True
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
248
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
249 else:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
250 op = Utils.getTwoValuePandaOp(operation, data)
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
251 value = params["element_value"]
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
252 try:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
253 # Could be numeric
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
254 value = float(value)
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
255 except ValueError:
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
256 pass
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
257 # generate filter matrix of True/False values
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
258 bool_mat = op(data, value)
0
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
259 else:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
260 # 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
261 # True values.
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
262 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
263
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
264 # 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
265 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
266 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
267 replacement_val = params["element_replace"]
2
02c3e335a695 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit d00a518202228b990aeeea2ec3f842501fd2ec09"
iuc
parents: 1
diff changeset
268 out_table = data.mask(
02c3e335a695 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit d00a518202228b990aeeea2ec3f842501fd2ec09"
iuc
parents: 1
diff changeset
269 bool_mat,
02c3e335a695 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit d00a518202228b990aeeea2ec3f842501fd2ec09"
iuc
parents: 1
diff changeset
270 data.where(bool_mat).applymap(
02c3e335a695 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit d00a518202228b990aeeea2ec3f842501fd2ec09"
iuc
parents: 1
diff changeset
271 lambda x: replacement_val.format(elem=x)
02c3e335a695 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit d00a518202228b990aeeea2ec3f842501fd2ec09"
iuc
parents: 1
diff changeset
272 )
02c3e335a695 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit d00a518202228b990aeeea2ec3f842501fd2ec09"
iuc
parents: 1
diff changeset
273 )
0
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
274 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
275 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
276 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
277 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
278 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
279 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
280 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
281 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
282 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
283 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
284 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
285 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
286 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
287 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
288 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
289
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
290 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
291 """Dummy Function"""
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
292 return elem
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
293
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
294 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
295 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
296 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
297
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
298 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
299 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
300 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
301 else:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
302 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
303 exit(-1)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
304
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
305 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
306 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
307
2
02c3e335a695 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit d00a518202228b990aeeea2ec3f842501fd2ec09"
iuc
parents: 1
diff changeset
308 if general_mode == "transpose":
02c3e335a695 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit d00a518202228b990aeeea2ec3f842501fd2ec09"
iuc
parents: 1
diff changeset
309 out_table = data.T
02c3e335a695 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit d00a518202228b990aeeea2ec3f842501fd2ec09"
iuc
parents: 1
diff changeset
310 elif general_mode == "melt":
0
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
311 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
312 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
313
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
314 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
315 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
316 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
317 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
318 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
319
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
320 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
321 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
322 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
323 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
324 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
325
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
326 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
327 """Dummy Function"""
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
328 return tableau
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
329
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
330 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
331 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
332 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
333
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
334 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
335
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
336 else:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
337 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
338 exit(-1)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
339
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
340
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
341 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
342
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
343 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
344
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
345 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
346 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
347 exit(-1)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
348
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
349 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
350
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
351 # Data
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
352 table = []
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
353 # 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
354 table_names = []
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
355 # 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
356 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
357
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
358 # 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
359 for x, t_sect in enumerate(table_sections):
1
dddadbbac949 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 6820ec9431a22576f3716c40feeb27f0b8cf5e83"
iuc
parents: 0
diff changeset
360 tmp = Utils.readcsv(t_sect, uc.Default["narm"])
0
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
361 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
362 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
363 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
364
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
365 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
366 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
367 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
368 # 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
369 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
370 # 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
371 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
372 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
373
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
374 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
375 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
376 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
377
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
378 else:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
379 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
380 exit(-1)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
381
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
382 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
383 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
384 raise RuntimeError(
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
385 '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
386 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
387 out_parameters = {
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
388 "sep": "\t",
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
389 "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
390 "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
391 "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
392 }
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
393 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
394 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
395
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
396 out_table.to_csv(uc.Default["outtable"], **out_parameters)