view average_scores.xml @ 1:7fd65542efc2 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/damidseq_average_score commit 14ffe107199084dcb9f4a9f693ef7b6be097a87b
author mvdbeek
date Sat, 28 Apr 2018 13:51:18 -0400
parents 427f5dda8854
children
line wrap: on
line source

<tool id="average_score" name="Calculate average scores" version="0.1.3">
    <description>for fixed step interval files</description>
    <requirements>
        <requirement type="package" version="0.22">pandas</requirement>
    </requirements>
    <command detect_errors="exit_code"><![CDATA[
python '$average_script'
    ]]></command>
<configfiles>
    <configfile name="average_script">
import pandas as pd

#set files = [str(f) for f in $input_files]
#set column = {'bed': 4, 'bedgraph': 3, 'gff': 5, 'gff3': 5, 'gtf': 5}[$input_files[0].ext]
skiprows = 0
with open('$files[0]') as first_file:
    for i, line in enumerate(first_file):
        if not line.startswith(('track', 'browser', '#')):
            skiprows = i
            break
d = {}
#for f in $files:
d['$f'] = pd.read_csv('$f', usecols=[$column], sep="\t", skiprows=skiprows, header=None, squeeze=True)
#end for
df = pd.DataFrame.from_dict(d)
mean = df.mean(axis=1)
with open('$averaged_output', 'w') as out, open('$files[0]') as first_file:
    for i, line in enumerate(first_file):
        fields = line.strip().split("\t")
        if i >= skiprows:
            fields[$column] = str(mean[i - skiprows])
        out.write("%s\n" % "\t".join(fields))
    </configfile>
</configfiles>
    <inputs>
        <param name="input_files" type="data" multiple="true" format="bed,bedgraph,gff" label="Select the files for which to average the score"/>
    </inputs>
    <outputs>
        <data name="averaged_output" format_source="input_files" label="${tool.name} on ${on_string}"/>
    </outputs>
    <tests>
        <test>
            <param name="input_files" value="1.bed,2.bed" ftype="bedgraph"/>
            <output name="averaged_output" value="averaged.bed" ftype="bedgraph"/>
        </test>
    </tests>
    <help><![CDATA[
What it does
------------

This tool calculates the average value for the score column across many datasets.

        ]]></help>
</tool>