comparison pandas_rolling.xml @ 0:a06f7b5c4dc7 draft default tip

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/pandas_rolling_window commit bdbedf42854d16bb00c396045007d4baece0a869
author bgruening
date Mon, 20 May 2019 08:42:54 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a06f7b5c4dc7
1 <tool id="pandas_rolling_window" name="Rolling window" version="0.1">
2 <description>over a dataframe (e.g. for data smoothing)</description>
3 <requirements>
4 <requirement type="package" version="1.16.3">numpy</requirement>
5 <requirement type="package" version="1.2.1">scipy</requirement>
6 <requirement type="package" version="0.24.2">pandas</requirement>
7 </requirements>
8 <command>
9 <![CDATA[
10
11 cat '$pandas_script' &&
12 python '$pandas_script'
13
14 ]]>
15 </command>
16 <configfiles>
17 <configfile name="pandas_script"><![CDATA[
18 import argparse
19 import sys
20
21 import pandas as pd
22
23 kwargs = dict()
24 window_type = '$smooth_function.smooth_function_opts_selector'
25
26 #if $smooth_function.smooth_function_opts_selector == 'gaussian':
27 kwargs.update({'std': $smooth_function.gaussian_std})
28 #elif $smooth_function.smooth_function_opts_selector == 'general_gaussian':
29 kwargs = ({'power': $smooth_function.ggaussian_power, 'width': $smooth_function.ggaussian_width})
30 #elif $smooth_function.smooth_function_opts_selector == 'kaiser':
31 kwargs.update({'beta': $smooth_function.kaiser_beta})
32 #elif $smooth_function.smooth_function_opts_selector == 'slepian':
33 kwargs.update({'width': $smooth_function.slepian_width})
34 #end if
35
36 df = pd.read_csv('${infile}', sep='\t', index_col=None, header=None, dtype={'strand': object} )
37
38 #if $group_column:
39 df['aggregate'] = df.groupby( int($group_column)-1, sort=False )[int($value_column)-1].rolling(${window_len}, win_type=window_type, center=$centering ).${statistics}(**kwargs).reset_index(drop=True)
40 #else:
41 df['aggregate'] = df[int($value_column)-1].rolling(${window_len}, win_type=window_type, center=$centering ).${statistics}(**kwargs).reset_index(drop=True)
42 #end if
43
44 df.to_csv('${outfile}', index=False, header=False, sep='\t', na_rep='0', float_format='%.2f')
45 ]]> </configfile>
46 </configfiles>
47 <inputs>
48 <param name="infile" type="data" format="tabular,bed.interval" label="Select input file in tabular or BED format"/>
49 <param name="group_column" type="data_column" data_ref="infile" optional="true" label="Optional column to group"
50 help="For example if you have a chromosome column you probably want to group each chromosome before you apply any function." />
51
52 <param name="value_column" type="data_column" data_ref="infile" label="Column with the value of interest"
53 help="" />
54
55 <conditional name="smooth_function">
56 <param name="smooth_function_opts_selector" type="select" label="Provide a window type"
57 help="For more information please see https://en.wikipedia.org/wiki/Window_function">
58 <option value="boxcar" selected="True">Boxcar or Dirichlet, all points are evenly weighted</option>
59 <option value="triang">triang</option>
60 <option value="blackman">blackman</option>
61 <option value="hamming">hamming</option>
62 <option value="bartlett">bartlett</option>
63 <option value="parzen">parzen</option>
64 <option value="bohman">bohman</option>
65 <option value="blackmanharris">blackmanharris</option>
66 <option value="nuttall">nuttall</option>
67 <option value="barthann">barthann</option>
68 <!--option value="kaiser">kaiser</option>
69 <option value="gaussian">gaussian</option>
70 <option value="general_gaussian">general gaussian</option>
71 <option value="slepian">slepian</option-->
72 </param>
73 <when value="boxcar" />
74 <when value="triang" />
75 <when value="blackman" />
76 <when value="hamming" />
77 <when value="bartlett" />
78 <when value="parzen" />
79 <when value="bohman" />
80 <when value="blackmanharris" />
81 <when value="nuttall" />
82 <when value="barthann" />
83 <when value="kaiser">
84 <param name="kaiser_beta" type="float" value="0.1" min='0.0' label="beta" />
85 </when>
86 <when value="gaussian">
87 <param name="gaussian_std" type="float" value="0.1" min='0.0' label="std" />
88 </when>
89 <when value="general_gaussian">
90 <param name="ggaussian_power" type="integer" value="2" min='1' label="power" />
91 <param name="ggaussian_width" type="integer" value="2" min="1" label="width" />
92 </when>
93 <when value="slepian">
94 <param name="slepian_width" type="integer" value="2" min="1" label="width" />
95 </when>
96 </conditional>
97
98 <param name="statistics" type="select" label="Provide a statistical function">
99 <option value="count">Number of non-null observations (count)</option>
100 <option value="sum">Sum of values (sum)</option>
101 <option value="mean" selected="true">Mean of values (mean)</option>
102 <option value="median">Arithmetic median of values (median)</option>
103 <option value="min">Minimum (min)</option>
104 <option value="max">max (max)</option>
105 <option value="std">Bessel-corrected sample standard deviation (std)</option>
106 <option value="var">Unbiased variance (var)</option>
107 <option value="skew">Sample skewness (3rd moment)</option>
108 <option value="kurt">Sample kurtosis (4th moment)</option>
109 <option value="quantil">Sample quantile (value at %)</option>
110 <option value="cov">Unbiased covariance (binary) (cov)</option>
111 <option value="corr">Correlation (corr)</option>
112 </param>
113
114 <param name="centering" type="boolean" truevalue="True" falsevalue="False" label="center smoothed values"
115 help="By default the labels are set to the right edge of the window. Here you can change that to the center." />
116 <!-- Options for all formats.-->
117 <param name="window_len" type="integer" value="3" min="2" label="Window length"/>
118 </inputs>
119 <outputs>
120 <data name="outfile" format_source="infile" />
121 </outputs>
122 <tests>
123 <test>
124 <param name="infile" value="1.bedgraph"/>
125 <param name="group_column" value="1"/>
126 <param name="value_column" value="5"/>
127 <conditional name="smooth_function">
128 <param name="smooth_function_opts_selector" value="boxcar"/>
129 </conditional>
130 <param name="window_len" value="3"/>
131 <output name="outfile" value="1_boxcar.bedgraph"/>
132 </test>
133 <test>
134 <!-- None test -->
135 <param name="infile" value="1.bedgraph"/>
136 <param name="value_column" value="5"/>
137 <conditional name="smooth_function">
138 <param name="smooth_function_opts_selector" value="boxcar"/>
139 </conditional>
140 <param name="window_len" value="3"/>
141 <output name="outfile" value="2_boxcar.bedgraph"/>
142 </test>
143 <test>
144 <param name="infile" value="1.bedgraph"/>
145 <param name="group_column" value="1"/>
146 <param name="value_column" value="5"/>
147 <conditional name="smooth_function">
148 <param name="smooth_function_opts_selector" value="hamming"/>
149 </conditional>
150 <param name="window_len" value="3"/>
151 <param name="statistics" value="sum"/>
152 <output name="outfile" value="1_hamming.bedgraph"/>
153 </test>
154 <test>
155 <param name="infile" value="1.bedgraph"/>
156 <param name="value_column" value="5"/>
157 <conditional name="smooth_function">
158 <param name="smooth_function_opts_selector" value="hamming"/>
159 </conditional>
160 <param name="window_len" value="3"/>
161 <param name="statistics" value="sum"/>
162 <output name="outfile" value="2_hamming.bedgraph"/>
163 </test>
164 </tests>
165 <help>
166 <![CDATA[
167
168 **What it does**
169
170 Provides rolling window calculations, e.g. for smoothing values.
171
172
173 ]]>
174 </help>
175 </tool>