view discriminant.xml @ 0:fd945dcf14dc draft

planemo upload for repository https://github.com/bgruening/galaxytools/tools/sklearn commit a6e80305ed0892c8163d690a2d376d6b454824de-dirty
author bgruening
date Mon, 02 May 2016 16:15:00 -0400
parents
children 51c38dd43e2b
line wrap: on
line source

<tool id="sklearn_discriminant_classifier" name="Discriminant Analysis" version="@VERSION@">
    <description></description>
    <macros>
        <import>main_macros.xml</import>
        <!--macro name="priors"-->
    </macros>
    <expand macro="python_requirements"/>
    <expand macro="macro_stdio"/>
    <version_command>echo "@VERSION@"</version_command>
    <command><![CDATA[
    python "$discriminant_script" '$inputs'
]]>
    </command>
    <configfiles>
        <inputs name="inputs"/>
        <configfile name="discriminant_script">
<![CDATA[
import sys
import json
import numpy as np
import sklearn.discriminant_analysis
import pandas
import pickle

input_json_path = sys.argv[1]
params = json.load(open(input_json_path, "r"))


#if $selected_tasks.selected_task == "load":

classifier_object = pickle.load(open("$infile_model", 'r'))

data = pandas.read_csv("$selected_tasks.infile_data", sep='\t', header=0, index_col=None, parse_dates=True, encoding=None, tupleize_cols=False )
prediction = classifier_object.predict(data)
prediction_df = pandas.DataFrame(prediction)
res = pandas.concat([data, prediction_df], axis=1)
res.to_csv(path_or_buf = "$outfile", sep="\t", index=False)

#else:

data_train = pandas.read_csv("$selected_tasks.infile_train", sep='\t', header=0, index_col=None, parse_dates=True, encoding=None, tupleize_cols=False )

data = data_train.ix[:,0:len(data_train.columns)-1]
labels = np.array(data_train[data_train.columns[len(data_train.columns)-1]])

options = params["selected_tasks"]["selected_algorithms"]["options"]
selected_algorithm = params["selected_tasks"]["selected_algorithms"]["selected_algorithm"]

my_class = getattr(sklearn.discriminant_analysis, selected_algorithm)
classifier_object = my_class(**options)
classifier_object.fit(data,labels)
pickle.dump(classifier_object,open("$outfile", 'w+'), pickle.HIGHEST_PROTOCOL)

#end if
]]>
        </configfile>
    </configfiles>
    <inputs>
        <expand macro="train_loadConditional" model="zip">
            <param name="selected_algorithm" type="select" label="Classifier type">
                <option value="LinearDiscriminantAnalysis" selected="true">Linear Discriminant Classifier</option>
                <option value="QuadraticDiscriminantAnalysis">Quadratic Discriminant Classifier</option>
            </param>
            <when value="LinearDiscriminantAnalysis">
                <section name="options" title="Advanced Options" expanded="False">
                    <param argument="solver" type="select" optional="true" label="Solver" help="">
                        <option value="svd" selected="true">Singular Value Decomposition</option>
                        <option value="lsqr">Least Squares Solution</option>
                        <option value="eigen">Eigenvalue Decomposition</option>
                    </param>
                    <!--param name="shrinkage"--> 
                    <!--expand macro="priors"/-->
                    <param argument="n_components" type="integer" optional="true" value="" label="Number of components" help="Number of components for dimensionality reduction. ( always less than  n_classes - 1 )"/>
                    <expand macro="tol" default_value="0.0001" help_text="Rank estimation threshold used in SVD solver."/>
                    <param argument="store_covariance" type="boolean" optional="true" truevalue="booltrue" falsevalue="boolflase" checked="false" label="Store covariance" help="Compute class covariance matrix."/>
                </section>
            </when>
            <when value="QuadraticDiscriminantAnalysis">
                <section name="options" title="Advanced Options" expanded="False">
                    <!--expand macro="priors"/-->
                    <param argument="reg_param" type="float" optional="true" value="0.0" label="Regularization coefficient" help="Covariance estimate regularizer."/>
                    <expand macro="tol" default_value="0.00001" help_text="Rank estimation threshold used in SVD solver."/>
                    <param argument="store_covariances" type="boolean" optional="true" truevalue="booltrue" falsevalue="boolflase" checked="false" label="Store covariances" help="Compute class covariance matrixes."/>
                </section>
            </when>
        </expand>
    </inputs>
    <outputs>
        <data name="outfile"/>
    </outputs>
    <tests>
        <test>
            <param name="infile_train" value="train.tabular" ftype="tabular"/>
            <param name="selected_task" value="train"/>
            <param name="selected_algorithm" value="LinearDiscriminantAnalysis"/>
            <param name="solver" value="svd" />
            <param name="store_covariances" value="True"/>
            <output name="outfile" file="lda_model01" compare="sim_size" delta="500"/>
        </test>
        <test>
            <param name="infile_train" value="train.tabular" ftype="tabular"/>
            <param name="selected_task" value="train"/>
            <param name="selected_algorithm" value="LinearDiscriminantAnalysis"/>
            <param name="solver" value="lsqr"/>
            <output name="outfile" file="lda_model02" compare="sim_size" delta="500"/>
        </test>
        <test>
            <param name="infile_train" value="train.tabular" ftype="tabular"/>
            <param name="selected_task" value="train"/>
            <param name="selected_algorithm" value="QuadraticAnalysis"/>
            <output name="outfile" file="qda_model01" compare="sim_size" delta="500"/>
        </test>
        <test>
            <param name="infile_model" value="lda_model01" ftype="zip"/>
            <param name="infile_data" value="test.tabular" ftype="tabular"/>
            <param name="selected_task" value="load"/>
            <output name="outfile" file="lda_prediction_result01.tabular"/>
        </test>
        <test>
            <param name="infile_model" value="lda_model02" ftype="zip"/>
            <param name="infile_data" value="test.tabular" ftype="tabular"/>
            <param name="selected_task" value="load"/>
            <output name="outfile" file="lda_prediction_result02.tabular"/>
        </test>
        <test>
            <param name="infile_model" value="qda_model01" ftype="zip"/>
            <param name="infile_data" value="test.tabular" ftype="tabular"/>
            <param name="selected_task" value="load"/>
            <output name="outfile" file="qda_prediction_result01.tabular"/>
        </test>
    </tests>
    <help><![CDATA[
**What it does**
Linear Discriminant Analysis and Quadratic Discriminant Analysis are two classic classifiers, with, as their names suggest, a linear and a quadratic decision surface, respectively. This module uses sklearn.discriminant_analysis package to implement Discriminant Analysis classification.


    ]]></help>
    <expand macro="sklearn_citation"/>
</tool>