Mercurial > repos > iuc > table_compute
comparison scripts/table_compute.py @ 2:02c3e335a695 draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit d00a518202228b990aeeea2ec3f842501fd2ec09"
author | iuc |
---|---|
date | Fri, 13 Sep 2019 14:54:41 -0400 |
parents | dddadbbac949 |
children | 93a3ce78ce55 |
comparison
equal
deleted
inserted
replaced
1:dddadbbac949 | 2:02c3e335a695 |
---|---|
2 """ | 2 """ |
3 Table Compute tool - a wrapper around pandas with parameter input validation. | 3 Table Compute tool - a wrapper around pandas with parameter input validation. |
4 """ | 4 """ |
5 | 5 |
6 | 6 |
7 __version__ = "0.9.1" | 7 __version__ = "0.9.2" |
8 | 8 |
9 import csv | 9 import csv |
10 import math | 10 import math |
11 from sys import argv | 11 from sys import argv |
12 | 12 |
263 | 263 |
264 # Get the main processing mode | 264 # Get the main processing mode |
265 mode = params["element_mode"] | 265 mode = params["element_mode"] |
266 if mode == "replace": | 266 if mode == "replace": |
267 replacement_val = params["element_replace"] | 267 replacement_val = params["element_replace"] |
268 out_table = data.mask(bool_mat, replacement_val) | 268 out_table = data.mask( |
269 bool_mat, | |
270 data.where(bool_mat).applymap( | |
271 lambda x: replacement_val.format(elem=x) | |
272 ) | |
273 ) | |
269 elif mode == "modify": | 274 elif mode == "modify": |
270 mod_op = Utils.getOneValueMathOp(params["element_modify_op"]) | 275 mod_op = Utils.getOneValueMathOp(params["element_modify_op"]) |
271 out_table = data.mask( | 276 out_table = data.mask( |
272 bool_mat, data.where(bool_mat).applymap(mod_op) | 277 bool_mat, data.where(bool_mat).applymap(mod_op) |
273 ) | 278 ) |
298 exit(-1) | 303 exit(-1) |
299 | 304 |
300 elif user_mode_single == "fulltable": | 305 elif user_mode_single == "fulltable": |
301 general_mode = params["mode"] | 306 general_mode = params["mode"] |
302 | 307 |
303 if general_mode == "melt": | 308 if general_mode == "transpose": |
309 out_table = data.T | |
310 elif general_mode == "melt": | |
304 melt_ids = params["MELT"]["melt_ids"] | 311 melt_ids = params["MELT"]["melt_ids"] |
305 melt_values = params["MELT"]["melt_values"] | 312 melt_values = params["MELT"]["melt_values"] |
306 | 313 |
307 out_table = pd.melt(data, id_vars=melt_ids, value_vars=melt_values) | 314 out_table = pd.melt(data, id_vars=melt_ids, value_vars=melt_values) |
308 elif general_mode == "pivot": | 315 elif general_mode == "pivot": |