annotate tabular_edit.xml @ 0:01454ded8907 draft default tip

Uploaded
author kellrott
date Wed, 31 Oct 2012 19:50:16 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
01454ded8907 Uploaded
kellrott
parents:
diff changeset
1 <tool id="tabular_edit" name="Tabular Edit" version="1.0.0">
01454ded8907 Uploaded
kellrott
parents:
diff changeset
2 <description>Edit the contents and row/column labels of a tabular file using python statements</description>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
3 <command interpreter="python">$script_file</command>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
4 <inputs>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
5 <param name="row_txt" type="text" area="True" size="5x35" label="Row Eval Code" optional="True">
01454ded8907 Uploaded
kellrott
parents:
diff changeset
6 <sanitizer>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
7 <valid initial="string.printable">
01454ded8907 Uploaded
kellrott
parents:
diff changeset
8 <remove value="&quot;"/>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
9 </valid>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
10 <mapping initial="none">
01454ded8907 Uploaded
kellrott
parents:
diff changeset
11 <add source="&quot;" target="\&quot;"/>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
12 <add source="\" target="\\"/>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
13 </mapping>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
14 </sanitizer>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
15 </param>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
16 <param name="col_txt" type="text" area="True" size="5x35" label="Column Eval Code" optional="True">
01454ded8907 Uploaded
kellrott
parents:
diff changeset
17 <sanitizer>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
18 <valid initial="string.printable">
01454ded8907 Uploaded
kellrott
parents:
diff changeset
19 <remove value="&quot;"/>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
20 </valid>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
21 <mapping initial="none">
01454ded8907 Uploaded
kellrott
parents:
diff changeset
22 <add source="&quot;" target="\&quot;"/>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
23 </mapping>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
24 </sanitizer>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
25 </param>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
26 <param name="cell_txt" type="text" area="True" size="5x35" label="Cell Eval Code" optional="True">
01454ded8907 Uploaded
kellrott
parents:
diff changeset
27 <sanitizer>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
28 <valid initial="string.printable">
01454ded8907 Uploaded
kellrott
parents:
diff changeset
29 <remove value="&quot;"/>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
30 </valid>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
31 <mapping initial="none">
01454ded8907 Uploaded
kellrott
parents:
diff changeset
32 <add source="&quot;" target="\&quot;"/>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
33 </mapping>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
34 </sanitizer>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
35 </param>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
36
01454ded8907 Uploaded
kellrott
parents:
diff changeset
37 <param name="matrix" type="data" format="tabular" label="Matrix"/>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
38 </inputs>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
39 <outputs>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
40 <data format="tabular" name="outfile" />
01454ded8907 Uploaded
kellrott
parents:
diff changeset
41 </outputs>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
42 <configfiles>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
43 <configfile name="script_file"><![CDATA[#!/usr/bin/env python
01454ded8907 Uploaded
kellrott
parents:
diff changeset
44 import os
01454ded8907 Uploaded
kellrott
parents:
diff changeset
45 import sys
01454ded8907 Uploaded
kellrott
parents:
diff changeset
46 import csv
01454ded8907 Uploaded
kellrott
parents:
diff changeset
47 import re
01454ded8907 Uploaded
kellrott
parents:
diff changeset
48 import math
01454ded8907 Uploaded
kellrott
parents:
diff changeset
49
01454ded8907 Uploaded
kellrott
parents:
diff changeset
50 def value_eval(code, value):
01454ded8907 Uploaded
kellrott
parents:
diff changeset
51 funcmap = {
01454ded8907 Uploaded
kellrott
parents:
diff changeset
52 "len":len,
01454ded8907 Uploaded
kellrott
parents:
diff changeset
53 "value" : value,
01454ded8907 Uploaded
kellrott
parents:
diff changeset
54 "re" : re,
01454ded8907 Uploaded
kellrott
parents:
diff changeset
55 "math" : math,
01454ded8907 Uploaded
kellrott
parents:
diff changeset
56 "float" : float
01454ded8907 Uploaded
kellrott
parents:
diff changeset
57 }
01454ded8907 Uploaded
kellrott
parents:
diff changeset
58 return str(eval(code,{"__builtins__":None},funcmap))
01454ded8907 Uploaded
kellrott
parents:
diff changeset
59
01454ded8907 Uploaded
kellrott
parents:
diff changeset
60
01454ded8907 Uploaded
kellrott
parents:
diff changeset
61 row_text = """${row_txt}"""
01454ded8907 Uploaded
kellrott
parents:
diff changeset
62 col_text = """${col_txt}"""
01454ded8907 Uploaded
kellrott
parents:
diff changeset
63 cell_text = """${cell_txt}"""
01454ded8907 Uploaded
kellrott
parents:
diff changeset
64
01454ded8907 Uploaded
kellrott
parents:
diff changeset
65 in_path = """${matrix}"""
01454ded8907 Uploaded
kellrott
parents:
diff changeset
66 out_path = """${outfile}"""
01454ded8907 Uploaded
kellrott
parents:
diff changeset
67
01454ded8907 Uploaded
kellrott
parents:
diff changeset
68
01454ded8907 Uploaded
kellrott
parents:
diff changeset
69 ohandle = open(out_path, "w")
01454ded8907 Uploaded
kellrott
parents:
diff changeset
70 ihandle = open(in_path)
01454ded8907 Uploaded
kellrott
parents:
diff changeset
71 reader = csv.reader(ihandle, delimiter="\t")
01454ded8907 Uploaded
kellrott
parents:
diff changeset
72 writer = csv.writer(ohandle, delimiter="\t", lineterminator="\n")
01454ded8907 Uploaded
kellrott
parents:
diff changeset
73
01454ded8907 Uploaded
kellrott
parents:
diff changeset
74 header = True
01454ded8907 Uploaded
kellrott
parents:
diff changeset
75 for row in reader:
01454ded8907 Uploaded
kellrott
parents:
diff changeset
76 if header:
01454ded8907 Uploaded
kellrott
parents:
diff changeset
77 if len(col_text):
01454ded8907 Uploaded
kellrott
parents:
diff changeset
78 for i, val in enumerate(row[1:]):
01454ded8907 Uploaded
kellrott
parents:
diff changeset
79 row[i+1] = value_eval(col_text, val)
01454ded8907 Uploaded
kellrott
parents:
diff changeset
80 header = False
01454ded8907 Uploaded
kellrott
parents:
diff changeset
81 else:
01454ded8907 Uploaded
kellrott
parents:
diff changeset
82 if len(row_text):
01454ded8907 Uploaded
kellrott
parents:
diff changeset
83 row[0] = value_eval(row_text, row[0])
01454ded8907 Uploaded
kellrott
parents:
diff changeset
84 if len(cell_text):
01454ded8907 Uploaded
kellrott
parents:
diff changeset
85 for i in range(1,len(row)):
01454ded8907 Uploaded
kellrott
parents:
diff changeset
86 row[i] = value_eval(cell_text,row[i])
01454ded8907 Uploaded
kellrott
parents:
diff changeset
87 writer.writerow(row)
01454ded8907 Uploaded
kellrott
parents:
diff changeset
88
01454ded8907 Uploaded
kellrott
parents:
diff changeset
89 ihandle.close()
01454ded8907 Uploaded
kellrott
parents:
diff changeset
90 ohandle.close()
01454ded8907 Uploaded
kellrott
parents:
diff changeset
91
01454ded8907 Uploaded
kellrott
parents:
diff changeset
92
01454ded8907 Uploaded
kellrott
parents:
diff changeset
93 ]]></configfile>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
94 </configfiles>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
95 <help>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
96 This is a utility to perform editing operations on the contents and column/row labels of a tabular file.
01454ded8907 Uploaded
kellrott
parents:
diff changeset
97
01454ded8907 Uploaded
kellrott
parents:
diff changeset
98 - The 'Column Eval Code' operations occur on the first line.
01454ded8907 Uploaded
kellrott
parents:
diff changeset
99 - The 'Row Eval Code' operations occur on the first cell of every line
01454ded8907 Uploaded
kellrott
parents:
diff changeset
100 - The 'Cell Eval Code' operations occur on every non-label cell
01454ded8907 Uploaded
kellrott
parents:
diff changeset
101 - If any of the code blocks are empty, the operation is skipped
01454ded8907 Uploaded
kellrott
parents:
diff changeset
102
01454ded8907 Uploaded
kellrott
parents:
diff changeset
103 Example
01454ded8907 Uploaded
kellrott
parents:
diff changeset
104
01454ded8907 Uploaded
kellrott
parents:
diff changeset
105 Remove the '.CEL' string from sample names::
01454ded8907 Uploaded
kellrott
parents:
diff changeset
106
01454ded8907 Uploaded
kellrott
parents:
diff changeset
107 re.sub(r'.CEL$', '', value)
01454ded8907 Uploaded
kellrott
parents:
diff changeset
108
01454ded8907 Uploaded
kellrott
parents:
diff changeset
109 Log Transform the matrix cells::
01454ded8907 Uploaded
kellrott
parents:
diff changeset
110
01454ded8907 Uploaded
kellrott
parents:
diff changeset
111 math.log(float(value))
01454ded8907 Uploaded
kellrott
parents:
diff changeset
112
01454ded8907 Uploaded
kellrott
parents:
diff changeset
113
01454ded8907 Uploaded
kellrott
parents:
diff changeset
114 </help>
01454ded8907 Uploaded
kellrott
parents:
diff changeset
115 </tool>