<commit_before><tool id="edger" name="edgeR" version="3.20.7.1">
    <description>
        Perform differential expression of count data
    </description>

    <requirements>
        <requirement type="package" version="3.20.7">bioconductor-edger</requirement>
        <requirement type="package" version="3.34.9">bioconductor-limma</requirement>
        <requirement type="package" version="0.2.15">r-rjson</requirement>
        <requirement type="package" version="1.20.0">r-getopt</requirement>
        <requirement type="package" version="1.4.30">r-statmod</requirement>
        <!-- required for alpha function used with plotMD -->
        <requirement type="package" version="0.5.0">r-scales</requirement>
    </requirements>

    <version_command><![CDATA[
echo $(R --version | grep version | grep -v GNU)", edgeR version" $(R --vanilla --slave -e "library(edgeR); cat(sessionInfo()\$otherPkgs\$edgeR\$Version)" 2> /dev/null | grep -v -i "WARNING: ")", limma version" $(R --vanilla --slave -e "library(limma); cat(sessionInfo()\$otherPkgs\$limma\$Version)" 2> /dev/null | grep -v -i "WARNING: ")", scales version" $(R --vanilla --slave -e "library(scales); cat(sessionInfo()\$otherPkgs\$scales\$Version)" 2> /dev/null | grep -v -i "WARNING: ")", rjson version" $(R --vanilla --slave -e "library(rjson); cat(sessionInfo()\$otherPkgs\$rjson\$Version)" 2> /dev/null | grep -v -i "WARNING: ")", getopt version" $(R --vanilla --slave -e "library(getopt); cat(sessionInfo()\$otherPkgs\$getopt\$Version)" 2> /dev/null | grep -v -i "WARNING: ")
    ]]></version_command>

    <command detect_errors="exit_code"><![CDATA[
#import json
Rscript '$__tool_directory__/edger.R'

-R '$outReport'
-o '$outReport.files_path'

#if $input.format=="files":

    ## Adapted from DESeq2 wrapper
    #set $temp_factor_names = list()
    #for $fact in $input.rep_factor:
        #set $temp_factor = list()
        #for $g in $fact.rep_group:
            #set $count_files = list()
            #for $file in $g.countsFile:
                $count_files.append(str($file))
            #end for
            $temp_factor.append( {str($g.groupName): $count_files} )
        #end for

        $temp_factor.reverse()
        $temp_factor_names.append([str($fact.factorName), $temp_factor])
    #end for
    -j '#echo json.dumps(temp_factor_names)#'

#elif $input.format=="matrix":
    -m '$input.counts'
    #if $input.fact.ffile=='yes':
        -f '$input.fact.finfo'
    #else:
        -i '${ '|'.join( ['%s::%s' % ($x.factorName, $x.groupNames) for x in $input.fact.rep_factor] ) }'
    #end if
#end if

#if $anno.annoOpt=='yes':
    -a '$anno.geneanno'
#end if

-C '${ ','.join( ['%s' % $x.contrast for x in $rep_contrast] ) }'

#if $f.filt.filt_select == 'yes':
    #if $f.filt.cformat.format_select == 'cpm':
        -c '$f.filt.cformat.cpmReq'
        -s '$f.filt.cformat.cpmSampleReq'
    #elif $f.filt.cformat.format_select == 'counts':
            -z '$f.filt.cformat.cntReq'
        #if $f.filt.cformat.samples.count_select == 'total':
            -y
        #elif $f.filt.cformat.samples.count_select == 'sample':
            -s '$f.filt.cformat.samples.cntSampleReq'
        #end if
    #end if
#end if

#if $out.normCounts:
    -x
#end if
#if $out.rdaOption:
    -r
#end if

-l '$adv.lfc'
-p '$adv.pVal'
-d '$adv.pAdjust'
-n '$adv.normalisationOption'
#if $adv.robOption:
    -b
#end if
#if $adv.lrtOption:
    -t
#end if

&&
mkdir ./output_dir

&&
cp '$outReport.files_path'/*.tsv output_dir/

#if $out.rscript:
    && cp '$__tool_directory__/edger.R' '$rscript'
#end if
    ]]></command>

    <inputs>

        <!-- Counts and Factors -->
        <conditional name="input">
            <param name="format" type="select" label="Count Files or Matrix?"
                help="You can choose to input either separate count files (one per sample) or a single count matrix">
                <option value="files">Separate Count Files</option>
                <option value="matrix">Single Count Matrix</option>
            </param>

            <when value="files">
                <repeat name="rep_factor" title="Factor" min="1">
                    <param name="factorName" type="text" label="Name" help="Name of experiment factor of interest (e.g. Genotype). One factor must be entered and there must be two or more groups per factor. Optional additional factors (e.g. Batch) can be entered using the Insert Factor button below, see Help section for more information. NOTE: Please only use letters, numbers or underscores.">
                    <sanitizer>
                        <valid initial="string.letters,string.digits"><add value="_" /></valid>
                    </sanitizer>
                    </param>
                    <repeat name="rep_group" title="Group" min="2" default="2">
                        <param name="groupName" type="text" label="Name"
                        help="Name of group that the counts files(s) belong to (e.g. WT or Mut). NOTE: Please only use letters, numbers or underscores (case sensitive).">
                        <sanitizer>
                            <valid initial="string.letters,string.digits"><add value="_" /></valid>
                        </sanitizer>
                        </param>
                        <param name="countsFile" type="data" format="tabular" multiple="true" label="Counts file(s)"/>
                    </repeat>
                </repeat>
            </when>

            <when value="matrix">
                <param name="counts" type="data" format="tabular" label="Count Matrix"/>

                <conditional name="fact">
                    <param name="ffile" type="select" label="Input factor information from file?"
                        help="You can choose to input the factor and group information for the samples from a file or manually enter below.">
                        <option value="no">No</option>
                        <option value="yes">Yes</option>
                    </param>
                    <when value="yes">
                        <param name="finfo" type="data" format="tabular" label="Factor File"/>
                    </when>
                    <when value="no" >
                        <repeat name="rep_factor" title="Factor" min="1">
                            <param name="factorName" type="text" label="Factor Name"
                                help="Name of experiment factor of interest (e.g. Genotype). One factor must be entered and there must be two or more groups per factor. Additional factors (e.g. Batch) can be entered using the Insert Factor button below, see Help section below. NOTE: Please only use letters, numbers or underscores.">
                                <validator type="empty_field" />
                                <validator type="regex" message="Please only use letters, numbers or underscores">^[\w]+$</validator>
                            </param>
                            <param name="groupNames" type="text" label="Groups"
                                help="Enter the group names for the samples separated with commas e.g. WT,WT,WT,Mut,Mut,Mut. The order of the names must match the order of the samples in the columns of the count matrix. NOTE: Please only use letters, numbers or underscores (case sensitive).">
                                <validator type="empty_field" />
                                <validator type="regex" message="Please only use letters, numbers or underscores, and separate levels by commas">^[\w,]+$</validator>
                            </param>
                        </repeat>
                    </when>
                </conditional>
            </when>
        </conditional>

        <!-- Gene Annotations -->
        <conditional name="anno">
            <param name="annoOpt" type="select" label="Use Gene Annotations?"
                    help="If you provide an annotation file, annotations will be added to the table(s) of differential expression results to provide descriptions for each gene. See Help section below.">
                <option value="no">No</option>
                <option value="yes">Yes</option>
            </param>
            <when value="yes">
                <param name="geneanno" type="data" format="tabular" label="Gene Annotations"/>
            </when>
            <when value="no" />
        </conditional>

        <!-- Contrasts -->
        <repeat name="rep_contrast" title="Contrast" min="1" default="1">
            <param name="contrast" type="text" label="Contrast of Interest" help="Names of two groups to compare separated by a hyphen e.g. Mut-WT. If the order is Mut-WT the fold changes in the results will be up/down in Mut relative to WT. If you have more than one contrast enter each separately using the Insert Contrast button below. For more info, see Chapter 8 in the limma User's guide: https://www.bioconductor.org/packages/release/bioc/vignettes/limma/inst/doc/usersguide.pdf">
                <validator type="empty_field" />
                <validator type="regex" message="Please only use letters, numbers or underscores">^[\w-]+$</validator>
            </param>
        </repeat>

        <!-- Filter Options -->
        <section name="f" expanded="false" title="Filter Low Counts">
            <conditional name="filt">
                <param name="filt_select" type="select" label="Filter lowly expressed genes?" help="Treat genes with very low expression as unexpressed and filter out. See the Filter Low Counts section below for more information. Default: No">
                    <option value="no" selected="true">No</option>
                    <option value="yes">Yes</option>
                </param>
                <when value="yes">
                    <conditional name="cformat">
                        <param name="format_select" type="select" label="Filter on CPM or Count values?" help="It is slightly better to base the filtering on count-per-million (CPM) rather than the raw count values so as to avoid favoring genes expressed in samples sequenced to a higher depth. ">
                            <option value="cpm">CPM</option>
                            <option value="counts">Counts</option>
                        </param>
                        <when value="cpm">
                            <param name="cpmReq" type="float" value="1" min="0" label="Minimum CPM" help="Treat genes with CPM below this value as unexpressed and filter out. See the Filter Low Counts section below for more information."/>
                             <param name="cpmSampleReq" type="integer" value="0" min="0" label="Minimum Samples"
                             help="Filter out all genes that do not meet the Minimum CPM in at least this many samples. See the Filter Low Counts section below for more information."/>
                        </when>
                        <when value="counts">
                            <param name="cntReq" type="integer" value="0" min="0" label="Minimum Count" help="Filter out all genes that do not meet this minimum count. You can choose below to apply this filter to the total count for all samples or specify the number of samples under Minimum Samples. See the Filter Low Counts section below for more information." />
                            <conditional name="samples">
                                <param name="count_select" type="select" label="Filter on Total Count or per Sample Count values?" >
                                    <option value="total">Total</option>
                                    <option value="sample">Sample</option>
                                </param>
                                <when value="total">
                                    <param name="totReq" type="boolean" truevalue="1" falsevalue="0" checked="false" label="Filter on Total Count" help="Apply the Minimum Count filter to genes after summing counts for all samples. See the Filter Low Counts section below for more information." />
                                </when>
                                <when value="sample">
                                    <param name="cntSampleReq" type="integer" value="0" min="0" label="Minimum Samples"
                                    help="Filter out all genes that do not meet the Minimum Count in at least this many samples. See the Filter Low Counts section below for more information."/>
                                </when>
                            </conditional>
                        </when>
                    </conditional>
                </when>
                <when value="no" />
            </conditional>
        </section>

        <!-- Output Options -->
        <section name="out" expanded="false" title="Output Options">
            <param name="normCounts" type="boolean" truevalue="1" falsevalue="0" checked="false"
                label="Output Normalised Counts Table?"
                help="Output a file containing the normalised counts, these are in log2 counts per million (logCPM). Default: No">
            </param>
            <param name="rscript" type="boolean" truevalue="True" falsevalue="False" checked="False" label="Output Rscript?" help="If this option is set to Yes, the Rscript used will be provided as a text file in the output. Default: No"/>
            <param name="rdaOption" type="boolean" truevalue="1" falsevalue="0" checked="false"
                label="Output RData file?"
                help="Output all the data used by R to construct the plots and tables, can be loaded into R. A link to the RData file will be provided in the HTML report. Default: No">
            </param>
        </section>

        <!-- Advanced Options -->
        <section name="adv" expanded="false" title="Advanced Options">
            <param name="lfc" type="float" value="0" min="0"
                label="Minimum Log2 Fold Change"
                help="Genes above this threshold and below the p-value threshold are considered significant and highlighted in the MD plot. Default: 0."/>
            <param name="pVal" type="float" value="0.05" min="0" max="1"
                label="P-Value Adjusted Threshold"
                help="Genes below this threshold are considered significant and highlighted in the MD plot. If either BH(1995) or BY(2001) are selected then this value is a false-discovery-rate control. If Holm(1979) is selected then this is an adjusted p-value for family-wise error rate. Default: 0.05."/>
            <param name="pAdjust" type="select" label="P-Value Adjustment Method" help="Default: BH">
                <option value="BH" selected="true">Benjamini and Hochberg (1995)</option>
                <option value="BY">Benjamini and Yekutieli (2001)</option>
                <option value="holm">Holm (1979)</option>
                <option value="none">None</option>
            </param>
            <param name="normalisationOption" type="select" label="Normalisation Method" help="Default: TMM">
                <option value="TMM" selected="true">TMM</option>
                <option value="RLE">RLE</option>
                <option value="upperquartile">Upperquartile</option>
                <option value="none">None (Don't normalise)</option>
            </param>
            <param name="robOption" type="boolean" truevalue="1" falsevalue="0" checked="true" label="Use Robust Settings?" help="Using robust settings is usually recommended to protect against outlier genes. Default: Yes" />
            <param name="lrtOption" type="boolean" truevalue="1" falsevalue="0" checked="false" label="Use Likelihood Ratio Test?" help="Use likelihood ratio test instead of quasi-likelihood F-test. Default: No"/>
        </section>

    </inputs>

    <outputs>
        <data name="outReport" format="html" label="${tool.name} on ${on_string}: Report" />
        <collection name="outTables" type="list" label="${tool.name} on ${on_string}: Tables">
            <discover_datasets pattern="(?P&lt;name&gt;.+)\.tsv$" format="tabular" directory="output_dir" visible="false" />
        </collection>
        <data name="rscript" format="txt" label="${tool.name} on ${on_string}: Rscript">
            <filter>out['rscript']</filter>
        </data>
    </outputs>

    <tests>
        <!-- Ensure report is output -->
        <test>
            <param name="format" value="matrix" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="WT-Mut" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <output_collection name="outTables" count="2">
                <element name="edgeR_Mut-WT" ftype="tabular" file="edgeR_Mut-WT.tsv" />
                <element name="edgeR_WT-Mut" ftype="tabular" file="edgeR_WT-Mut.tsv" />
            </output_collection>
            <output name="outReport" >
                <assert_contents>
                    <has_text text="edgeR Analysis Output" />
                    <has_text text="quasi-likelihood" />
                    <not_has_text text="likelihood ratio" />
                    <not_has_text text="RData" />
                </assert_contents>
            </output>
        </test>
        <!-- Ensure annotation file input works -->
        <test>
            <param name="format" value="matrix" />
            <param name="annoOpt" value="yes" />
            <param name="geneanno" value="anno.txt" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <output_collection name="outTables" count="1">
                <element name="edgeR_Mut-WT" ftype="tabular" file="edgeR_Mut-WT_anno.tsv" />
            </output_collection>
        </test>
        <!-- Ensure RScript and RData file can be output -->
        <test>
            <param name="format" value="matrix" />
            <param name="rscript" value="True"/>
            <param name="rdaOption" value="true" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <output name="outReport" >
                <assert_contents>
                    <has_text text="RData" />
                </assert_contents>
            </output>
            <output name="rscript" value="out_rscript.txt"/>
        </test>
        <!-- Ensure secondary factors work -->
        <test>
            <param name="format" value="matrix" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_factor">
                <param name="factorName" value="Batch"/>
                <param name="groupNames" value="b1,b2,b3,b1,b2,b3"/>
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <output_collection name="outTables" count="1" >
                <element name="edgeR_Mut-WT" ftype="tabular" file="edgeR_Mut-WT_2fact.tsv" />
            </output_collection>
        </test>
        <!-- Ensure factors file input works -->
        <test>
            <param name="format" value="matrix" />
            <param name="ffile" value="yes" />
            <param name="finfo" value="factorinfo.txt" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <output_collection name="outTables" count="1">
                <element name="edgeR_Mut-WT" ftype="tabular" file="edgeR_Mut-WT_2fact.tsv" />
            </output_collection>
        </test>
        <!-- Ensure normalised counts file output works-->
        <test>
            <param name="format" value="matrix" />
            <param name="normCounts" value="true" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <output_collection name="outTables" count="2">
                <element name="edgeR_Mut-WT" ftype="tabular" file="edgeR_Mut-WT.tsv" />
                <element name="edgeR_normcounts" ftype="tabular" file="edgeR_normcounts.tsv" />
            </output_collection>
        </test>
        <!-- Ensure likelihood ratio option works -->
        <test>
            <param name="format" value="matrix" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <param name="lrtOption" value="true" />
            <output name="outReport" >
                <assert_contents>
                    <has_text text="likelihood ratio" />
                    <not_has_text text="quasi-likelihood" />
                </assert_contents>
            </output>
        </test>
        <!-- Ensure multiple counts files input works -->
        <test>
            <param name="format" value="files" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <repeat name="rep_group">
                    <param name="groupName" value="WT"/>
                    <param name="countsFile" value="WT1.counts,WT2.counts,WT3.counts"/>
                </repeat>
                <repeat name="rep_group">
                    <param name="groupName" value="Mut"/>
                    <param name="countsFile" value="Mut1.counts,Mut2.counts,Mut3.counts"/>
                </repeat>
            </repeat>
            <repeat name="rep_factor">
                <param name="factorName" value="Batch"/>
                <repeat name="rep_group">
                    <param name="groupName" value="b1"/>
                    <param name="countsFile" value="WT1.counts,Mut1.counts"/>
                </repeat>
                <repeat name="rep_group">
                    <param name="groupName" value="b2"/>
                    <param name="countsFile" value="WT2.counts,Mut2.counts"/>
                </repeat>
                <repeat name="rep_group">
                    <param name="groupName" value="b3"/>
                    <param name="countsFile" value="WT3.counts,Mut3.counts"/>
                </repeat>
            </repeat>
            <param name="annoOpt" value="yes" />
            <param name="geneanno" value="anno.txt" />
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="WT-Mut" />
            </repeat>
            <param name="normCounts" value="true" />
            <output_collection name="outTables" count="3">
                <element name="edgeR_Mut-WT" ftype="tabular" file="edgeR_Mut-WT_2fact_anno.tsv" />
                <element name="edgeR_WT-Mut" ftype="tabular" file="edgeR_WT-Mut_2fact_anno.tsv" />
                <element name="edgeR_normcounts" ftype="tabular" file="edgeR_normcounts_anno.tsv" />
            </output_collection>
        </test>
        <!-- Ensure filtering on CPM in Mnimum Samples works -->
        <test>
            <param name="format" value="matrix" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <param name="filt_select" value="yes" />
            <param name="format_select" value="cpm" />
            <!-- real cpmReq values would be a lot lower
                 this is just for this tiny test dataset -->
            <param name="cpmReq" value="1000" />
            <param name="cpmSampleReq" value="3" />
            <output name="outReport" >
                <assert_contents>
                    <has_text text="CPM in at least" />
                    <not_has_text text="after summing counts for all samples" />
                    <not_has_text text="counts in at least" />
                </assert_contents>
            </output>
            <output_collection name="outTables" count="1" >
                <element name="edgeR_Mut-WT" ftype="tabular" file="edgeR_Mut-WT_filt.tsv" />
            </output_collection>
        </test>
        <!-- Ensure filtering on Count in Minmum Samples works -->
        <test>
            <param name="format" value="matrix" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <param name="filt_select" value="yes" />
            <param name="format_select" value="counts" />
            <param name="cntReq" value="10" />
            <param name="count_select" value="sample" />
            <param name="cntSampleReq" value="3" />
            <output name="outReport" >
                <assert_contents>
                    <has_text text="counts in at least" />
                    <not_has_text text="after summing counts for all samples" />
                    <not_has_text text="CPM in at least" />
                </assert_contents>
            </output>
            <output_collection name="outTables" count="1" >
                <element name="edgeR_Mut-WT" ftype="tabular" file="edgeR_Mut-WT_filt.tsv" />
            </output_collection>
        </test>
        <!-- Ensure filtering on Total Count works -->
        <test>
            <param name="format" value="matrix" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <param name="filt_select" value="yes" />
            <param name="format_select" value="counts" />
            <!-- real cntReq values would be a lot lower
                 this is just for this tiny test dataset -->
            <param name="cntReq" value="1000" />
            <param name="count_select" value="total" />
            <param name="totReq" value="true" />
            <output name="outReport" >
                <assert_contents>
                    <has_text text="after summing counts for all samples" />
                    <not_has_text text="counts in at least" />
                    <not_has_text text="CPM in at least" />
                </assert_contents>
            </output>
            <output_collection name="outTables" count="1" >
                <element name="edgeR_Mut-WT" ftype="tabular" file="edgeR_Mut-WT_filt.tsv" />
            </output_collection>
        </test>
    </tests>

    <help><![CDATA[
.. class:: infomark

**What it does**
<commit_msg>Use assert_contents in tests for floating point diffs<commit_after><tool id="edger" name="edgeR" version="3.20.7.1">
    <description>
        Perform differential expression of count data
    </description>

    <requirements>
        <requirement type="package" version="3.20.7">bioconductor-edger</requirement>
        <requirement type="package" version="3.34.9">bioconductor-limma</requirement>
        <requirement type="package" version="0.2.15">r-rjson</requirement>
        <requirement type="package" version="1.20.0">r-getopt</requirement>
        <requirement type="package" version="1.4.30">r-statmod</requirement>
        <!-- required for alpha function used with plotMD -->
        <requirement type="package" version="0.5.0">r-scales</requirement>
    </requirements>

    <version_command><![CDATA[
echo $(R --version | grep version | grep -v GNU)", edgeR version" $(R --vanilla --slave -e "library(edgeR); cat(sessionInfo()\$otherPkgs\$edgeR\$Version)" 2> /dev/null | grep -v -i "WARNING: ")", limma version" $(R --vanilla --slave -e "library(limma); cat(sessionInfo()\$otherPkgs\$limma\$Version)" 2> /dev/null | grep -v -i "WARNING: ")", scales version" $(R --vanilla --slave -e "library(scales); cat(sessionInfo()\$otherPkgs\$scales\$Version)" 2> /dev/null | grep -v -i "WARNING: ")", rjson version" $(R --vanilla --slave -e "library(rjson); cat(sessionInfo()\$otherPkgs\$rjson\$Version)" 2> /dev/null | grep -v -i "WARNING: ")", getopt version" $(R --vanilla --slave -e "library(getopt); cat(sessionInfo()\$otherPkgs\$getopt\$Version)" 2> /dev/null | grep -v -i "WARNING: ")
    ]]></version_command>

    <command detect_errors="exit_code"><![CDATA[
#import json
Rscript '$__tool_directory__/edger.R'

-R '$outReport'
-o '$outReport.files_path'

#if $input.format=="files":

    ## Adapted from DESeq2 wrapper
    #set $temp_factor_names = list()
    #for $fact in $input.rep_factor:
        #set $temp_factor = list()
        #for $g in $fact.rep_group:
            #set $count_files = list()
            #for $file in $g.countsFile:
                $count_files.append(str($file))
            #end for
            $temp_factor.append( {str($g.groupName): $count_files} )
        #end for

        $temp_factor.reverse()
        $temp_factor_names.append([str($fact.factorName), $temp_factor])
    #end for
    -j '#echo json.dumps(temp_factor_names)#'

#elif $input.format=="matrix":
    -m '$input.counts'
    #if $input.fact.ffile=='yes':
        -f '$input.fact.finfo'
    #else:
        -i '${ '|'.join( ['%s::%s' % ($x.factorName, $x.groupNames) for x in $input.fact.rep_factor] ) }'
    #end if
#end if

#if $anno.annoOpt=='yes':
    -a '$anno.geneanno'
#end if

-C '${ ','.join( ['%s' % $x.contrast for x in $rep_contrast] ) }'

#if $f.filt.filt_select == 'yes':
    #if $f.filt.cformat.format_select == 'cpm':
        -c '$f.filt.cformat.cpmReq'
        -s '$f.filt.cformat.cpmSampleReq'
    #elif $f.filt.cformat.format_select == 'counts':
            -z '$f.filt.cformat.cntReq'
        #if $f.filt.cformat.samples.count_select == 'total':
            -y
        #elif $f.filt.cformat.samples.count_select == 'sample':
            -s '$f.filt.cformat.samples.cntSampleReq'
        #end if
    #end if
#end if

#if $out.normCounts:
    -x
#end if
#if $out.rdaOption:
    -r
#end if

-l '$adv.lfc'
-p '$adv.pVal'
-d '$adv.pAdjust'
-n '$adv.normalisationOption'
#if $adv.robOption:
    -b
#end if
#if $adv.lrtOption:
    -t
#end if

&&
mkdir ./output_dir

&&
cp '$outReport.files_path'/*.tsv output_dir/

#if $out.rscript:
    && cp '$__tool_directory__/edger.R' '$rscript'
#end if
    ]]></command>

    <inputs>

        <!-- Counts and Factors -->
        <conditional name="input">
            <param name="format" type="select" label="Count Files or Matrix?"
                help="You can choose to input either separate count files (one per sample) or a single count matrix">
                <option value="files">Separate Count Files</option>
                <option value="matrix">Single Count Matrix</option>
            </param>

            <when value="files">
                <repeat name="rep_factor" title="Factor" min="1">
                    <param name="factorName" type="text" label="Name" help="Name of experiment factor of interest (e.g. Genotype). One factor must be entered and there must be two or more groups per factor. Optional additional factors (e.g. Batch) can be entered using the Insert Factor button below, see Help section for more information. NOTE: Please only use letters, numbers or underscores.">
                    <sanitizer>
                        <valid initial="string.letters,string.digits"><add value="_" /></valid>
                    </sanitizer>
                    </param>
                    <repeat name="rep_group" title="Group" min="2" default="2">
                        <param name="groupName" type="text" label="Name"
                        help="Name of group that the counts files(s) belong to (e.g. WT or Mut). NOTE: Please only use letters, numbers or underscores (case sensitive).">
                        <sanitizer>
                            <valid initial="string.letters,string.digits"><add value="_" /></valid>
                        </sanitizer>
                        </param>
                        <param name="countsFile" type="data" format="tabular" multiple="true" label="Counts file(s)"/>
                    </repeat>
                </repeat>
            </when>

            <when value="matrix">
                <param name="counts" type="data" format="tabular" label="Count Matrix"/>

                <conditional name="fact">
                    <param name="ffile" type="select" label="Input factor information from file?"
                        help="You can choose to input the factor and group information for the samples from a file or manually enter below.">
                        <option value="no">No</option>
                        <option value="yes">Yes</option>
                    </param>
                    <when value="yes">
                        <param name="finfo" type="data" format="tabular" label="Factor File"/>
                    </when>
                    <when value="no" >
                        <repeat name="rep_factor" title="Factor" min="1">
                            <param name="factorName" type="text" label="Factor Name"
                                help="Name of experiment factor of interest (e.g. Genotype). One factor must be entered and there must be two or more groups per factor. Additional factors (e.g. Batch) can be entered using the Insert Factor button below, see Help section below. NOTE: Please only use letters, numbers or underscores.">
                                <validator type="empty_field" />
                                <validator type="regex" message="Please only use letters, numbers or underscores">^[\w]+$</validator>
                            </param>
                            <param name="groupNames" type="text" label="Groups"
                                help="Enter the group names for the samples separated with commas e.g. WT,WT,WT,Mut,Mut,Mut. The order of the names must match the order of the samples in the columns of the count matrix. NOTE: Please only use letters, numbers or underscores (case sensitive).">
                                <validator type="empty_field" />
                                <validator type="regex" message="Please only use letters, numbers or underscores, and separate levels by commas">^[\w,]+$</validator>
                            </param>
                        </repeat>
                    </when>
                </conditional>
            </when>
        </conditional>

        <!-- Gene Annotations -->
        <conditional name="anno">
            <param name="annoOpt" type="select" label="Use Gene Annotations?"
                    help="If you provide an annotation file, annotations will be added to the table(s) of differential expression results to provide descriptions for each gene. See Help section below.">
                <option value="no">No</option>
                <option value="yes">Yes</option>
            </param>
            <when value="yes">
                <param name="geneanno" type="data" format="tabular" label="Gene Annotations"/>
            </when>
            <when value="no" />
        </conditional>

        <!-- Contrasts -->
        <repeat name="rep_contrast" title="Contrast" min="1" default="1">
            <param name="contrast" type="text" label="Contrast of Interest" help="Names of two groups to compare separated by a hyphen e.g. Mut-WT. If the order is Mut-WT the fold changes in the results will be up/down in Mut relative to WT. If you have more than one contrast enter each separately using the Insert Contrast button below. For more info, see Chapter 8 in the limma User's guide: https://www.bioconductor.org/packages/release/bioc/vignettes/limma/inst/doc/usersguide.pdf">
                <validator type="empty_field" />
                <validator type="regex" message="Please only use letters, numbers or underscores">^[\w-]+$</validator>
            </param>
        </repeat>

        <!-- Filter Options -->
        <section name="f" expanded="false" title="Filter Low Counts">
            <conditional name="filt">
                <param name="filt_select" type="select" label="Filter lowly expressed genes?" help="Treat genes with very low expression as unexpressed and filter out. See the Filter Low Counts section below for more information. Default: No">
                    <option value="no" selected="true">No</option>
                    <option value="yes">Yes</option>
                </param>
                <when value="yes">
                    <conditional name="cformat">
                        <param name="format_select" type="select" label="Filter on CPM or Count values?" help="It is slightly better to base the filtering on count-per-million (CPM) rather than the raw count values so as to avoid favoring genes expressed in samples sequenced to a higher depth. ">
                            <option value="cpm">CPM</option>
                            <option value="counts">Counts</option>
                        </param>
                        <when value="cpm">
                            <param name="cpmReq" type="float" value="1" min="0" label="Minimum CPM" help="Treat genes with CPM below this value as unexpressed and filter out. See the Filter Low Counts section below for more information."/>
                             <param name="cpmSampleReq" type="integer" value="0" min="0" label="Minimum Samples"
                             help="Filter out all genes that do not meet the Minimum CPM in at least this many samples. See the Filter Low Counts section below for more information."/>
                        </when>
                        <when value="counts">
                            <param name="cntReq" type="integer" value="0" min="0" label="Minimum Count" help="Filter out all genes that do not meet this minimum count. You can choose below to apply this filter to the total count for all samples or specify the number of samples under Minimum Samples. See the Filter Low Counts section below for more information." />
                            <conditional name="samples">
                                <param name="count_select" type="select" label="Filter on Total Count or per Sample Count values?" >
                                    <option value="total">Total</option>
                                    <option value="sample">Sample</option>
                                </param>
                                <when value="total">
                                    <param name="totReq" type="boolean" truevalue="1" falsevalue="0" checked="false" label="Filter on Total Count" help="Apply the Minimum Count filter to genes after summing counts for all samples. See the Filter Low Counts section below for more information." />
                                </when>
                                <when value="sample">
                                    <param name="cntSampleReq" type="integer" value="0" min="0" label="Minimum Samples"
                                    help="Filter out all genes that do not meet the Minimum Count in at least this many samples. See the Filter Low Counts section below for more information."/>
                                </when>
                            </conditional>
                        </when>
                    </conditional>
                </when>
                <when value="no" />
            </conditional>
        </section>

        <!-- Output Options -->
        <section name="out" expanded="false" title="Output Options">
            <param name="normCounts" type="boolean" truevalue="1" falsevalue="0" checked="false"
                label="Output Normalised Counts Table?"
                help="Output a file containing the normalised counts, these are in log2 counts per million (logCPM). Default: No">
            </param>
            <param name="rscript" type="boolean" truevalue="True" falsevalue="False" checked="False" label="Output Rscript?" help="If this option is set to Yes, the Rscript used will be provided as a text file in the output. Default: No"/>
            <param name="rdaOption" type="boolean" truevalue="1" falsevalue="0" checked="false"
                label="Output RData file?"
                help="Output all the data used by R to construct the plots and tables, can be loaded into R. A link to the RData file will be provided in the HTML report. Default: No">
            </param>
        </section>

        <!-- Advanced Options -->
        <section name="adv" expanded="false" title="Advanced Options">
            <param name="lfc" type="float" value="0" min="0"
                label="Minimum Log2 Fold Change"
                help="Genes above this threshold and below the p-value threshold are considered significant and highlighted in the MD plot. Default: 0."/>
            <param name="pVal" type="float" value="0.05" min="0" max="1"
                label="P-Value Adjusted Threshold"
                help="Genes below this threshold are considered significant and highlighted in the MD plot. If either BH(1995) or BY(2001) are selected then this value is a false-discovery-rate control. If Holm(1979) is selected then this is an adjusted p-value for family-wise error rate. Default: 0.05."/>
            <param name="pAdjust" type="select" label="P-Value Adjustment Method" help="Default: BH">
                <option value="BH" selected="true">Benjamini and Hochberg (1995)</option>
                <option value="BY">Benjamini and Yekutieli (2001)</option>
                <option value="holm">Holm (1979)</option>
                <option value="none">None</option>
            </param>
            <param name="normalisationOption" type="select" label="Normalisation Method" help="Default: TMM">
                <option value="TMM" selected="true">TMM</option>
                <option value="RLE">RLE</option>
                <option value="upperquartile">Upperquartile</option>
                <option value="none">None (Don't normalise)</option>
            </param>
            <param name="robOption" type="boolean" truevalue="1" falsevalue="0" checked="true" label="Use Robust Settings?" help="Using robust settings is usually recommended to protect against outlier genes. Default: Yes" />
            <param name="lrtOption" type="boolean" truevalue="1" falsevalue="0" checked="false" label="Use Likelihood Ratio Test?" help="Use likelihood ratio test instead of quasi-likelihood F-test. Default: No"/>
        </section>

    </inputs>

    <outputs>
        <data name="outReport" format="html" label="${tool.name} on ${on_string}: Report" />
        <collection name="outTables" type="list" label="${tool.name} on ${on_string}: Tables">
            <discover_datasets pattern="(?P&lt;name&gt;.+)\.tsv$" format="tabular" directory="output_dir" visible="false" />
        </collection>
        <data name="rscript" format="txt" label="${tool.name} on ${on_string}: Rscript">
            <filter>out['rscript']</filter>
        </data>
    </outputs>

    <tests>
        <!-- Ensure report is output -->
        <test>
            <param name="format" value="matrix" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="WT-Mut" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <output_collection name="outTables" count="2">
                <element name="edgeR_Mut-WT" ftype="tabular" >
                    <assert_contents>
                       <has_text_matching expression="11304.*0.4582" />
                   </assert_contents>
               </element>
                <element name="edgeR_WT-Mut" ftype="tabular" >
                    <assert_contents>
                       <has_text_matching expression="11304.*-0.4582" />
                   </assert_contents>
               </element>
            </output_collection>
            <output name="outReport" >
                <assert_contents>
                    <has_text text="edgeR Analysis Output" />
                    <has_text text="quasi-likelihood" />
                    <not_has_text text="likelihood ratio" />
                    <not_has_text text="RData" />
                </assert_contents>
            </output>
        </test>
        <!-- Ensure annotation file input works -->
        <test>
            <param name="format" value="matrix" />
            <param name="annoOpt" value="yes" />
            <param name="geneanno" value="anno.txt" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <output_collection name="outTables" count="1">
                <element name="edgeR_Mut-WT" ftype="tabular" >
                    <assert_contents>
                       <has_text_matching expression="11304.*Abca4.*0.4582" />
                   </assert_contents>
               </element>
            </output_collection>
        </test>
        <!-- Ensure RScript and RData file can be output -->
        <test>
            <param name="format" value="matrix" />
            <param name="rscript" value="True"/>
            <param name="rdaOption" value="true" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <output name="outReport" >
                <assert_contents>
                    <has_text text="RData" />
                </assert_contents>
            </output>
            <output name="rscript" value="out_rscript.txt"/>
        </test>
        <!-- Ensure secondary factors work -->
        <test>
            <param name="format" value="matrix" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_factor">
                <param name="factorName" value="Batch"/>
                <param name="groupNames" value="b1,b2,b3,b1,b2,b3"/>
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <output_collection name="outTables" count="1" >
                <element name="edgeR_Mut-WT" ftype="tabular" >
                    <assert_contents>
                       <has_text_matching expression="11304.*0.4584" />
                   </assert_contents>
               </element>
            </output_collection>
        </test>
        <!-- Ensure factors file input works -->
        <test>
            <param name="format" value="matrix" />
            <param name="ffile" value="yes" />
            <param name="finfo" value="factorinfo.txt" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <output_collection name="outTables" count="1">
                <element name="edgeR_Mut-WT" ftype="tabular" >
                    <assert_contents>
                       <has_text_matching expression="11304.*0.4584" />
                   </assert_contents>
               </element>
            </output_collection>
        </test>
        <!-- Ensure normalised counts file output works-->
        <test>
            <param name="format" value="matrix" />
            <param name="normCounts" value="true" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <output_collection name="outTables" count="2">
                <element name="edgeR_Mut-WT" ftype="tabular" >
                    <assert_contents>
                       <has_text_matching expression="11304.*0.4582" />
                   </assert_contents>
               </element>
                <element name="edgeR_normcounts" ftype="tabular" >
                    <assert_contents>
                       <has_text_matching expression="11304.*15.7535" />
                   </assert_contents>
               </element>
            </output_collection>
        </test>
        <!-- Ensure likelihood ratio option works -->
        <test>
            <param name="format" value="matrix" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <param name="lrtOption" value="true" />
            <output name="outReport" >
                <assert_contents>
                    <has_text text="likelihood ratio" />
                    <not_has_text text="quasi-likelihood" />
                </assert_contents>
            </output>
        </test>
        <!-- Ensure multiple counts files input works -->
        <test>
            <param name="format" value="files" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <repeat name="rep_group">
                    <param name="groupName" value="WT"/>
                    <param name="countsFile" value="WT1.counts,WT2.counts,WT3.counts"/>
                </repeat>
                <repeat name="rep_group">
                    <param name="groupName" value="Mut"/>
                    <param name="countsFile" value="Mut1.counts,Mut2.counts,Mut3.counts"/>
                </repeat>
            </repeat>
            <repeat name="rep_factor">
                <param name="factorName" value="Batch"/>
                <repeat name="rep_group">
                    <param name="groupName" value="b1"/>
                    <param name="countsFile" value="WT1.counts,Mut1.counts"/>
                </repeat>
                <repeat name="rep_group">
                    <param name="groupName" value="b2"/>
                    <param name="countsFile" value="WT2.counts,Mut2.counts"/>
                </repeat>
                <repeat name="rep_group">
                    <param name="groupName" value="b3"/>
                    <param name="countsFile" value="WT3.counts,Mut3.counts"/>
                </repeat>
            </repeat>
            <param name="annoOpt" value="yes" />
            <param name="geneanno" value="anno.txt" />
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="WT-Mut" />
            </repeat>
            <param name="normCounts" value="true" />
            <output_collection name="outTables" count="3">
                <element name="edgeR_Mut-WT" ftype="tabular" >
                    <assert_contents>
                       <has_text_matching expression="11304.*Abca4.*0.4584" />
                   </assert_contents>
               </element>
                <element name="edgeR_WT-Mut" ftype="tabular" >
                    <assert_contents>
                       <has_text_matching expression="11304.*Abca4.*-0.4584" />
                   </assert_contents>
               </element>
                <element name="edgeR_normcounts" ftype="tabular" >
                    <assert_contents>
                       <has_text_matching expression="11304.*Abca4.*15.7535" />
                   </assert_contents>
               </element>
            </output_collection>
        </test>
        <!-- Ensure filtering on CPM in Mnimum Samples works -->
        <test>
            <param name="format" value="matrix" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <param name="filt_select" value="yes" />
            <param name="format_select" value="cpm" />
            <!-- real cpmReq values would be a lot lower
                 this is just for this tiny test dataset -->
            <param name="cpmReq" value="1000" />
            <param name="cpmSampleReq" value="3" />
            <output name="outReport" >
                <assert_contents>
                    <has_text text="CPM in at least" />
                    <not_has_text text="after summing counts for all samples" />
                    <not_has_text text="counts in at least" />
                </assert_contents>
            </output>
            <output_collection name="outTables" count="1" >
                <element name="edgeR_Mut-WT" ftype="tabular" >
                    <assert_contents>
                        <has_text_matching expression="11304.*0.4582" />
                        <not_has_text text="-0.0682" />
                   </assert_contents>
               </element>
            </output_collection>
        </test>
        <!-- Ensure filtering on Count in Minmum Samples works -->
        <test>
            <param name="format" value="matrix" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <param name="filt_select" value="yes" />
            <param name="format_select" value="counts" />
            <param name="cntReq" value="10" />
            <param name="count_select" value="sample" />
            <param name="cntSampleReq" value="3" />
            <output name="outReport" >
                <assert_contents>
                    <has_text text="counts in at least" />
                    <not_has_text text="after summing counts for all samples" />
                    <not_has_text text="CPM in at least" />
                </assert_contents>
            </output>
            <output_collection name="outTables" count="1" >
                <element name="edgeR_Mut-WT" ftype="tabular" >
                    <assert_contents>
                        <has_text_matching expression="11304.*0.4582" />
                        <not_has_text text="-0.0682" />
                   </assert_contents>
               </element>

            </output_collection>
        </test>
        <!-- Ensure filtering on Total Count works -->
        <test>
            <param name="format" value="matrix" />
            <param name="counts" value="matrix.txt" />
            <repeat name="rep_factor">
                <param name="factorName" value="Genotype"/>
                <param name="groupNames" value="Mut,Mut,Mut,WT,WT,WT" />
            </repeat>
            <repeat name="rep_contrast">
                <param name="contrast" value="Mut-WT" />
            </repeat>
            <param name="normalisationOption" value="TMM" />
            <param name="filt_select" value="yes" />
            <param name="format_select" value="counts" />
            <!-- real cntReq values would be a lot lower
                 this is just for this tiny test dataset -->
            <param name="cntReq" value="1000" />
            <param name="count_select" value="total" />
            <param name="totReq" value="true" />
            <output name="outReport" >
                <assert_contents>
                    <has_text text="after summing counts for all samples" />
                    <not_has_text text="counts in at least" />
                    <not_has_text text="CPM in at least" />
                </assert_contents>
            </output>
            <output_collection name="outTables" count="1" >
                <element name="edgeR_Mut-WT" ftype="tabular" >
                    <assert_contents>
                        <has_text_matching expression="11304.*0.4582" />
                        <not_has_text text="-0.0682" />
                   </assert_contents>
               </element>
            </output_collection>
        </test>
    </tests>

    <help><![CDATA[
.. class:: infomark

**What it does**

{'fraction_non_alphanumeric': 0.1346344526705447, 'fraction_numerical': 0.007122554204124802, 'mean_word_length': 1.8851435110136359, 'pattern_counts': {'":': 4, '<': 988, '<?xml version=': 0, '>': 996, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3704334', 'n_tokens_mistral': 16745, 'n_tokens_neox': 15859, 'n_words': 4273}