<commit_before><tool id="rsem" name="RSEM" version="0.1.0">
  <description></description>
    <macros>
        <import>macros.xml</import>
    </macros>
  <requirements>
    <requirement type="package" version="1.3.0">rsem</requirement>
    <requirement type="package" version="1.1.2=py27_0">bowtie</requirement>
  </requirements>
    <stdio>
        <exit_code range="1:" level="warning" description="Tool exception" />
    </stdio>
  <command detect_errors="exit_code"><![CDATA[
    #if $job.select_job == "index":
      echo ${job.reference_name} " " | tee $reference_file &&
      mkdir $reference_file.files_path &&
      rsem-prepare-reference 
      #if $job.polya.polya_use == 'add':
        #if $job.polya.polya_length:
          --polyA-length $job.polya.polya_length
        #end if
      #elif $job.polya.polya_use == 'subset':
        --no-polyA-subset $job.polya.no_polya_subset
        #if $job.polya.polya_length:
          --polyA-length $job.polya.polya_length
        #end if
      #elif $job.polya.polya_use == 'none':
        --no-polyA
      #end if
      $job.ntog
      #if $job.transcript_to_gene_map:
        --transcript-to-gene-map $job.transcript_to_gene_map
      #end if
      --bowtie
      #if $job.self_reference.ref_type == 'transcripts':
        $job.self_reference.reference_fasta_file
      #else:
        --gtf $job.self_reference.gtf
        $job.self_reference.reference_fasta_file
      #end if
      ${reference_file.files_path}/${job.reference_name}
      > ${reference_file.files_path}/${job.reference_name}.log
    #end if
    
    #if $job.select_job == "index" and $run_rsem.select == "Yes":
      &&
    #end if

    #if $run_rsem.select == "Yes":
      rsem-calculate-expression 
      ## --tag string
      #if $run_rsem.seedlength:
        --seed-length $run_rsem.seedlength 
      #end if
      --forward-prob $run_rsem.forward_prob
      #if $run_rsem.rsem_options.fullparams == 'fullset':
        ## Fragment info
        #if $run_rsem.rsem_options.fragment_length_mean:
          --fragment-length-mean $run_rsem.rsem_options.fragment_length_mean
        #end if
        #if $run_rsem.rsem_options.fragment_length_min:
          --fragment-length-min $run_rsem.rsem_options.fragment_length_min
        #end if
        #if $run_rsem.rsem_options.fragment_length_sd:
          --fragment-length-sd $run_rsem.rsem_options.fragment_length_sd
        #end if
        #if $run_rsem.rsem_options.fragment_length_max:
          --fragment-length-max $run_rsem.rsem_options.fragment_length_max
        #end if
        ## RSPD
        #if $run_rsem.rsem_options.rspd.estimate == 'yes':
          --estimate-rspd
          #if $run_rsem.rsem_options.rspd.num_rspd_bins:
            --num-rspd-bins $run_rsem.rsem_options.rspd.num_rspd_bins
          #end if
        #end if
        ## Calculate 95% credibility intervals and posterior mean estimates. 
        #if $run_rsem.rsem_options.useci.ci == 'yes':
          --calc-ci
          #if $run_rsem.rsem_options.useci.cimem:
            --ci-memory $run_rsem.rsem_options.useci.cimem
          #end if
        #end if
      #end if
      --num-threads \${GALAXY_SLOTS:-4}
      #if $run_rsem.input.format == 'fasta' and $run_rsem.input.bowtie_options.fullparams == 'fullset':
        ## Bowtie params
        #if $run_rsem.input.bowtie_options.bowtie_e:
        --bowtie-e $run_rsem.input.bowtie_options.bowtie_e
        #end if
        #if $run_rsem.input.bowtie_options.bowtie_m:
        --bowtie-m $run_rsem.input.bowtie_options.bowtie_m
        #end if
        --bowtie-n $run_rsem.input.bowtie_options.bowtie_n
      #end if
      #if $run_rsem.input.format == 'fastq' and $run_rsem.input.bowtie_options.fullparams == 'fullset':
        ## Bowtie params
        #if $run_rsem.input.bowtie_options.bowtie_e:
        --bowtie-e $run_rsem.input.bowtie_options.bowtie_e
        #end if
        #if $run_rsem.input.bowtie_options.bowtie_m:
        --bowtie-m $run_rsem.input.bowtie_options.bowtie_m
        #end if
        --bowtie-n $run_rsem.input.bowtie_options.bowtie_n
      #end if
      ## Outputs
      #if $run_rsem.rsem_outputs.result_bams == 'none':
        --no-bam-output
      #else
        --sort-bam-by-coordinate
        --output-genome-bam
        $run_rsem.rsem_outputs.sampling_for_bam
      #end if
      ## Input data
      #if $run_rsem.input.format=="fastq"
        $run_rsem.input.fastq_select
        #if $run_rsem.input.fastq.matepair=="single": 
          $run_rsem.input.fastq.singlefastq
        #elif $run_rsem.input.fastq.matepair=="paired":
          --paired-end
          $run_rsem.input.fastq.fastq1
          $run_rsem.input.fastq.fastq2
        #end if
      #elif $run_rsem.input.format=="fasta"
        --no-qualities
        #if $run_rsem.input.fasta.matepair=="single": 
          $run_rsem.input.fasta.singlefasta
        #elif $run_rsem.input.fasta.matepair=="paired":
          --paired-end
          $run_rsem.input.fasta.fasta1
          $run_rsem.input.fasta.fasta2
        #end if
      #elif $run_rsem.input.format=="sam"
        #if $run_rsem.input.matepair=="paired":
          --paired-end
        #end if
        #if $run_rsem.input.rsem_sam._extension == 'sam':
          --sam
        #elif $run_rsem.input.rsem_sam._extension == 'bam':
          --bam
        #end if
        $run_rsem.input.rsem_sam
      #end if
      ## RSEM reference
      #if $run_rsem.reference.refSrc == 'history':
        ${run_rsem.reference.rsem_ref.extra_files_path}/${run_rsem.reference.rsem_ref.metadata.reference_name}
      #elif $run_rsem.reference.refSrc == 'self':
        ${reference_file.files_path}/${job.reference_name}
      #end if
      ## sample_name: use a hard coded name so we can pull out galaxy outputs
      rsem_output
      ## direct output into logfile
      > $log
    #end if
  ]]></command>

  <inputs>
    <conditional name="job">
      <param name="select_job" type="select" label="rsem reference">
        <option value="index">Build rsem reference</option>
        <option value="no-index" selected="true">rsem reference available from history</option>
      </param>
      <when value="index">
        <conditional name="self_reference">
          <param name="ref_type" type="select" label="Reference transcript source">
            <option value="transcripts">transcript fasta</option>
            <option value="genomic">reference genome and gtf</option>
          </param>
          <when value="transcripts">
            <param name="reference_fasta_file" type="data" format="fasta" label="reference fasta file" 
                   help="The files should contain the sequences of transcripts."/>
          </when>
          <when value="genomic">
            <param name="reference_fasta_file" type="data" format="fasta" label="reference fasta file" 
                   help="The file should contain the sequence of an entire genome."/>
            <param name="gtf" type="data" format="gtf" label="gtf" 
                   help="extract transcript reference sequences using the gene annotations specified in this GTF" />
          </when>
        </conditional>
        <param name="transcript_to_gene_map" type="data" format="tabular" optional="true" label="Map of gene ids to transcript (isoform) ids" >
          <help>
            Each line of should be of the form: gene_id transcript_id ( with the two fields separated by a tab character )
            The map can be obtained from the UCSC table browser  
              group: Genes and Gene Prediction Tracks 
              table: knownIsoforms
            Without a map:
              If a reference genome and gtf is used, then RSEM uses the "gene_id" and "transcript_id" attributes in the GTF file. 
              Otherwise, RSEM assumes that each sequence in the reference sequence files is a separate gene.
          </help>
        </param>
        <param name="reference_name" type="text" value="rsem_ref_name" label="reference name">
          <help>A one word name for this RSEM reference containing only letters, digits, and underscore characters</help>
          <validator type="regex" message="Use only letters, digits, and underscore characters">^\w+$</validator>
        </param>
        <conditional name="polya">
          <param name="polya_use" type="select" label="PolyA ">
            <option value="add" selected="true">Add poly(A) tails to all transcripts</option>
            <option value="subset">Exclude poly(A) tails from selected transcripts</option>
            <option value="none">Do not add poly(A) tails to any transcripts</option>
          </param>
          <when value="add">
            <param name="polya_length" type="integer" value="125" optional="true" label="The length of the poly(A) tails to be added. (Default: 125)">
              <validator type="in_range" message="must be positive " min="1"/>
            </param>
          </when>
          <when value="subset">
            <param name="no_polya_subset" type="data" format="tabular" optional="true" label="List of transcript IDs (one per line) that should should not have polyA tails added."/> 
            <param name="polya_length" type="integer" value="125" optional="true" label="The length of the poly(A) tails to be added. (Default: 125)">
              <validator type="in_range" message="must be positive " min="1"/>
            </param>
          </when>
          <when value="none"/>
        </conditional>
        <param name="ntog" type="boolean" truevalue="--no-ntog" falsevalue="" checked="false" label="Disable the conversion of 'N' characters to 'G' characters in the reference sequences" help="Bowtie uses the automatic N to G conversion to align against all positions in the reference."/>
      </when>
      <when value="no-index">
      </when>
    </conditional>

    <conditional name="run_rsem">
      <param name="select" type="select" label="calculate expression with rsem">
        <option value="No">Just build rsem reference for latter rsem profiling</option>
        <option value="Yes" selected="true">profile expression with rsem</option>
      </param>
      <when value="Yes">
        <param name="sample" type="text" value="rsem_sample" label="Sample name" />
        <conditional name="reference">
          <param name="refSrc" type="select" label="RSEM Reference Source">
            <option value="history">From your history</option>
            <option value="self">Prepare RSEM Reference with this tool</option>
          </param>
          <when value="history">
            <param name="rsem_ref" type="data" format="rsem_ref" label="RSEM reference" />
          </when>
          <when value="self">
          </when>
        </conditional>
        <conditional name="input">
          <param name="format" type="select" label="RSEM Input file type">
            <option value="fastq">FASTQ</option>
            <option value="fasta">FASTA</option>
            <option value="sam">SAM/BAM</option>
          </param>
          <when value="fastq">
            <param name="fastq_select" size="15" type="select" label="FASTQ type" >
              <option value="--phred33-quals" selected="true">phred33 qualities (default for sanger)</option>
              <option value="--solexa-quals">solexa qualities</option>
              <option value="--phred64-quals">phred64 qualities</option>
            </param>
            <conditional name="fastq">
              <param name="matepair" type="select" label="Library type">
                <option value="single">Single End Reads</option>
                <option value="paired">Paired End Reads</option>
              </param>
              <when value="single">
                <param name="singlefastq" type="data" format="fastq" label="FASTQ file" />
              </when>
              <when value="paired">
                <param name="fastq1" type="data" format="fastq" label="Read 1 fastq file" />
                <param name="fastq2" type="data" format="fastq" label="Read 2 fastq file" />
              </when>
            </conditional>
            <expand macro="bowtie_options"/>
          </when>
          <when value="fasta">
            <conditional name="fasta">
              <param name="matepair" type="select" label="Library Type">
                <option value="single">Single End Reads</option>
                <option value="paired">Paired End Reads</option>
              </param>
              <when value="single">
                <param name="singlefasta" type="data" format="fasta" label="fasta file" />
              </when>
              <when value="paired">
                <param name="fasta1" type="data" format="fasta" label="Read 1 fasta file" />
                <param name="fasta2" type="data" format="fasta" label="Read 2 fasta file" />
              </when>
            </conditional>
            <expand macro="bowtie_options"/>
          </when>
          <when value="sam">
              <!-- convert-sam-for-rsem /ref/mouse_125 input.sam -o input_for_rsem.sam -->
              <param name="matepair" type="select" label="Library Type">
                <option value="single">Single End Reads</option>
                <option value="paired">Paired End Reads</option>
              </param>
              <param name="rsem_sam" type="data" format="rsem_sam" label="RSEM formatted SAM file" />
          </when>
        </conditional>
        <expand macro="rsem_options"/>
        <conditional name="rsem_outputs">
          <param name="result_bams" type="select" label="Create bam results files" 
                 help="In addition to the transcript-coordinate-based BAM file output, also output a BAM file with the read alignments in genomic coordinates" >
            <option value="none">No BAM results files</option>
            <option value="default" selected="true">Transcript BAM results file</option>
            <option value="both">Transcript and genome BAM results files</option>
          </param>
          <when value="none"/>
          <when value="default">
            <expand macro="sampling_for_bam"/>
          </when>
          <when value="both">
            <expand macro="sampling_for_bam"/>
          </when>
        </conditional>
      </when>
      <when value="No">
      </when>
    </conditional>
  </inputs>

  <outputs>
    <data format="rsem_ref" name="reference_file" label="RSEM ${job.reference_name} reference">
      <filter>job['select_job'] == "index"</filter>
    </data>
    <data format="tabular" name="gene_abundances" label="${run_rsem.sample}.gene_abundances" from_work_dir="rsem_output.genes.results">
      <filter>run_rsem['select'] == "Yes"</filter>
    </data>
    <data format="tabular" name="isoform_abundances" label="${run_rsem.sample}.isoform_abundances" from_work_dir="rsem_output.isoforms.results">
      <filter>run_rsem['select'] == "Yes"</filter>
    </data>
    <data format="bam" name="transcript_sorted_bam" label="${run_rsem.sample}.transcript.bam" from_work_dir="rsem_output.transcript.sorted.bam" >
      <filter>run_rsem['select'] == "Yes"</filter>
      <filter>rsem_outputs['result_bams'] != "none"</filter>
    </data>
    <data format="bam" name="genome_sorted_bam" label="${run_rsem.sample}.genome.bam" from_work_dir="rsem_output.genome.sorted.bam">
      <filter>run_rsem['select'] == "Yes"</filter>
      <filter>rsem_outputs['result_bams'] == "both"</filter>
    </data>
    <data format="txt" name="log" label="${run_rsem.sample}.rsem_log">
      <filter>run_rsem['select'] == "Yes"</filter>
    </data>
  </outputs>

  <tests>
    <test>
      <param name="select_job" value="index"/>
      <param name="ref_type" value="genomic"/>
      <param name="reference_fasta_file" value="ref.fasta" ftype="fasta"/>
      <param name="gtf" value="ref.gtf" ftype="gtf"/>
      <param name="reference_name" value="ref"/>
      <param name="select" value="Yes"/>
      <param name="sample" value="rsem_sample"/>
      <param name="refSrc" value="self"/>
      <param name="format" value="fastq"/>
      <param name="matepair" value="single"/>
      <param name="singlefastq" value="test.fq" ftype="fastqsanger"/>
      <param name="result_bams" value="none"/>
      <output name="reference_file">
        <assert_contents>
          <has_text text="ref" />
        </assert_contents>
      </output>
      <output name="gene_abundances" value="gene_abundances.tab"/> 
      <output name="isoform_abundances" value="isoform_abundances.tab" /> 
      <output name="log"> 
        <assert_contents>
          <has_text text="Expression Results are written" />
        </assert_contents>
      </output>
    </test>
    <test>
      <param name="select_job" value="index"/>
      <param name="ref_type" value="genomic"/>
      <param name="reference_fasta_file" value="ref.fasta" ftype="fasta"/>
      <param name="gtf" value="ref.gtf" ftype="gtf"/>
      <param name="reference_name" value="ref"/>
      <param name="select" value="No"/>
      <output name="reference_file">
        <assert_contents>
          <has_text text="ref" />
        </assert_contents>
      </output>
    </test>
  </tests>

  <help>

RSEM HOME PAGE - http://deweylab.biostat.wisc.edu/rsem/

NAME
    rsem-prepare-reference

SYNOPSIS
    rsem-prepare-reference [options] reference_fasta_file(s) reference_name

DESCRIPTION
    The rsem-prepare-reference program extracts/preprocesses the reference sequences and builds Bowtie indices using default parameters. 
    This program is used in conjunction with the 'rsem-calculate-expression' program.

INPUTS
    A fasta file of transcripts
    or
    A genome sequence fasta file and a GTF gene annotation file.  (When using UCSC data, include the related knownIsoforms.txt)
<commit_msg>add <is_valid_xml /> for additional testing of the rsem_ref<commit_after><tool id="rsem" name="RSEM" version="0.1.0">
  <description></description>
    <macros>
        <import>macros.xml</import>
    </macros>
  <requirements>
    <requirement type="package" version="1.3.0">rsem</requirement>
    <requirement type="package" version="1.1.2=py27_0">bowtie</requirement>
  </requirements>
    <stdio>
        <exit_code range="1:" level="warning" description="Tool exception" />
    </stdio>
  <command detect_errors="exit_code"><![CDATA[
    #if $job.select_job == "index":
      echo ${job.reference_name} " " | tee $reference_file &&
      mkdir $reference_file.files_path &&
      rsem-prepare-reference 
      #if $job.polya.polya_use == 'add':
        #if $job.polya.polya_length:
          --polyA-length $job.polya.polya_length
        #end if
      #elif $job.polya.polya_use == 'subset':
        --no-polyA-subset $job.polya.no_polya_subset
        #if $job.polya.polya_length:
          --polyA-length $job.polya.polya_length
        #end if
      #elif $job.polya.polya_use == 'none':
        --no-polyA
      #end if
      $job.ntog
      #if $job.transcript_to_gene_map:
        --transcript-to-gene-map $job.transcript_to_gene_map
      #end if
      --bowtie
      #if $job.self_reference.ref_type == 'transcripts':
        $job.self_reference.reference_fasta_file
      #else:
        --gtf $job.self_reference.gtf
        $job.self_reference.reference_fasta_file
      #end if
      ${reference_file.files_path}/${job.reference_name}
      > ${reference_file.files_path}/${job.reference_name}.log
    #end if
    
    #if $job.select_job == "index" and $run_rsem.select == "Yes":
      &&
    #end if

    #if $run_rsem.select == "Yes":
      rsem-calculate-expression 
      ## --tag string
      #if $run_rsem.seedlength:
        --seed-length $run_rsem.seedlength 
      #end if
      --forward-prob $run_rsem.forward_prob
      #if $run_rsem.rsem_options.fullparams == 'fullset':
        ## Fragment info
        #if $run_rsem.rsem_options.fragment_length_mean:
          --fragment-length-mean $run_rsem.rsem_options.fragment_length_mean
        #end if
        #if $run_rsem.rsem_options.fragment_length_min:
          --fragment-length-min $run_rsem.rsem_options.fragment_length_min
        #end if
        #if $run_rsem.rsem_options.fragment_length_sd:
          --fragment-length-sd $run_rsem.rsem_options.fragment_length_sd
        #end if
        #if $run_rsem.rsem_options.fragment_length_max:
          --fragment-length-max $run_rsem.rsem_options.fragment_length_max
        #end if
        ## RSPD
        #if $run_rsem.rsem_options.rspd.estimate == 'yes':
          --estimate-rspd
          #if $run_rsem.rsem_options.rspd.num_rspd_bins:
            --num-rspd-bins $run_rsem.rsem_options.rspd.num_rspd_bins
          #end if
        #end if
        ## Calculate 95% credibility intervals and posterior mean estimates. 
        #if $run_rsem.rsem_options.useci.ci == 'yes':
          --calc-ci
          #if $run_rsem.rsem_options.useci.cimem:
            --ci-memory $run_rsem.rsem_options.useci.cimem
          #end if
        #end if
      #end if
      --num-threads \${GALAXY_SLOTS:-4}
      #if $run_rsem.input.format == 'fasta' and $run_rsem.input.bowtie_options.fullparams == 'fullset':
        ## Bowtie params
        #if $run_rsem.input.bowtie_options.bowtie_e:
        --bowtie-e $run_rsem.input.bowtie_options.bowtie_e
        #end if
        #if $run_rsem.input.bowtie_options.bowtie_m:
        --bowtie-m $run_rsem.input.bowtie_options.bowtie_m
        #end if
        --bowtie-n $run_rsem.input.bowtie_options.bowtie_n
      #end if
      #if $run_rsem.input.format == 'fastq' and $run_rsem.input.bowtie_options.fullparams == 'fullset':
        ## Bowtie params
        #if $run_rsem.input.bowtie_options.bowtie_e:
        --bowtie-e $run_rsem.input.bowtie_options.bowtie_e
        #end if
        #if $run_rsem.input.bowtie_options.bowtie_m:
        --bowtie-m $run_rsem.input.bowtie_options.bowtie_m
        #end if
        --bowtie-n $run_rsem.input.bowtie_options.bowtie_n
      #end if
      ## Outputs
      #if $run_rsem.rsem_outputs.result_bams == 'none':
        --no-bam-output
      #else
        --sort-bam-by-coordinate
        --output-genome-bam
        $run_rsem.rsem_outputs.sampling_for_bam
      #end if
      ## Input data
      #if $run_rsem.input.format=="fastq"
        $run_rsem.input.fastq_select
        #if $run_rsem.input.fastq.matepair=="single": 
          $run_rsem.input.fastq.singlefastq
        #elif $run_rsem.input.fastq.matepair=="paired":
          --paired-end
          $run_rsem.input.fastq.fastq1
          $run_rsem.input.fastq.fastq2
        #end if
      #elif $run_rsem.input.format=="fasta"
        --no-qualities
        #if $run_rsem.input.fasta.matepair=="single": 
          $run_rsem.input.fasta.singlefasta
        #elif $run_rsem.input.fasta.matepair=="paired":
          --paired-end
          $run_rsem.input.fasta.fasta1
          $run_rsem.input.fasta.fasta2
        #end if
      #elif $run_rsem.input.format=="sam"
        #if $run_rsem.input.matepair=="paired":
          --paired-end
        #end if
        #if $run_rsem.input.rsem_sam._extension == 'sam':
          --sam
        #elif $run_rsem.input.rsem_sam._extension == 'bam':
          --bam
        #end if
        $run_rsem.input.rsem_sam
      #end if
      ## RSEM reference
      #if $run_rsem.reference.refSrc == 'history':
        ${run_rsem.reference.rsem_ref.extra_files_path}/${run_rsem.reference.rsem_ref.metadata.reference_name}
      #elif $run_rsem.reference.refSrc == 'self':
        ${reference_file.files_path}/${job.reference_name}
      #end if
      ## sample_name: use a hard coded name so we can pull out galaxy outputs
      rsem_output
      ## direct output into logfile
      > $log
    #end if
  ]]></command>

  <inputs>
    <conditional name="job">
      <param name="select_job" type="select" label="rsem reference">
        <option value="index">Build rsem reference</option>
        <option value="no-index" selected="true">rsem reference available from history</option>
      </param>
      <when value="index">
        <conditional name="self_reference">
          <param name="ref_type" type="select" label="Reference transcript source">
            <option value="transcripts">transcript fasta</option>
            <option value="genomic">reference genome and gtf</option>
          </param>
          <when value="transcripts">
            <param name="reference_fasta_file" type="data" format="fasta" label="reference fasta file" 
                   help="The files should contain the sequences of transcripts."/>
          </when>
          <when value="genomic">
            <param name="reference_fasta_file" type="data" format="fasta" label="reference fasta file" 
                   help="The file should contain the sequence of an entire genome."/>
            <param name="gtf" type="data" format="gtf" label="gtf" 
                   help="extract transcript reference sequences using the gene annotations specified in this GTF" />
          </when>
        </conditional>
        <param name="transcript_to_gene_map" type="data" format="tabular" optional="true" label="Map of gene ids to transcript (isoform) ids" >
          <help>
            Each line of should be of the form: gene_id transcript_id ( with the two fields separated by a tab character )
            The map can be obtained from the UCSC table browser  
              group: Genes and Gene Prediction Tracks 
              table: knownIsoforms
            Without a map:
              If a reference genome and gtf is used, then RSEM uses the "gene_id" and "transcript_id" attributes in the GTF file. 
              Otherwise, RSEM assumes that each sequence in the reference sequence files is a separate gene.
          </help>
        </param>
        <param name="reference_name" type="text" value="rsem_ref_name" label="reference name">
          <help>A one word name for this RSEM reference containing only letters, digits, and underscore characters</help>
          <validator type="regex" message="Use only letters, digits, and underscore characters">^\w+$</validator>
        </param>
        <conditional name="polya">
          <param name="polya_use" type="select" label="PolyA ">
            <option value="add" selected="true">Add poly(A) tails to all transcripts</option>
            <option value="subset">Exclude poly(A) tails from selected transcripts</option>
            <option value="none">Do not add poly(A) tails to any transcripts</option>
          </param>
          <when value="add">
            <param name="polya_length" type="integer" value="125" optional="true" label="The length of the poly(A) tails to be added. (Default: 125)">
              <validator type="in_range" message="must be positive " min="1"/>
            </param>
          </when>
          <when value="subset">
            <param name="no_polya_subset" type="data" format="tabular" optional="true" label="List of transcript IDs (one per line) that should should not have polyA tails added."/> 
            <param name="polya_length" type="integer" value="125" optional="true" label="The length of the poly(A) tails to be added. (Default: 125)">
              <validator type="in_range" message="must be positive " min="1"/>
            </param>
          </when>
          <when value="none"/>
        </conditional>
        <param name="ntog" type="boolean" truevalue="--no-ntog" falsevalue="" checked="false" label="Disable the conversion of 'N' characters to 'G' characters in the reference sequences" help="Bowtie uses the automatic N to G conversion to align against all positions in the reference."/>
      </when>
      <when value="no-index">
      </when>
    </conditional>

    <conditional name="run_rsem">
      <param name="select" type="select" label="calculate expression with rsem">
        <option value="No">Just build rsem reference for latter rsem profiling</option>
        <option value="Yes" selected="true">profile expression with rsem</option>
      </param>
      <when value="Yes">
        <param name="sample" type="text" value="rsem_sample" label="Sample name" />
        <conditional name="reference">
          <param name="refSrc" type="select" label="RSEM Reference Source">
            <option value="history">From your history</option>
            <option value="self">Prepare RSEM Reference with this tool</option>
          </param>
          <when value="history">
            <param name="rsem_ref" type="data" format="rsem_ref" label="RSEM reference" />
          </when>
          <when value="self">
          </when>
        </conditional>
        <conditional name="input">
          <param name="format" type="select" label="RSEM Input file type">
            <option value="fastq">FASTQ</option>
            <option value="fasta">FASTA</option>
            <option value="sam">SAM/BAM</option>
          </param>
          <when value="fastq">
            <param name="fastq_select" size="15" type="select" label="FASTQ type" >
              <option value="--phred33-quals" selected="true">phred33 qualities (default for sanger)</option>
              <option value="--solexa-quals">solexa qualities</option>
              <option value="--phred64-quals">phred64 qualities</option>
            </param>
            <conditional name="fastq">
              <param name="matepair" type="select" label="Library type">
                <option value="single">Single End Reads</option>
                <option value="paired">Paired End Reads</option>
              </param>
              <when value="single">
                <param name="singlefastq" type="data" format="fastq" label="FASTQ file" />
              </when>
              <when value="paired">
                <param name="fastq1" type="data" format="fastq" label="Read 1 fastq file" />
                <param name="fastq2" type="data" format="fastq" label="Read 2 fastq file" />
              </when>
            </conditional>
            <expand macro="bowtie_options"/>
          </when>
          <when value="fasta">
            <conditional name="fasta">
              <param name="matepair" type="select" label="Library Type">
                <option value="single">Single End Reads</option>
                <option value="paired">Paired End Reads</option>
              </param>
              <when value="single">
                <param name="singlefasta" type="data" format="fasta" label="fasta file" />
              </when>
              <when value="paired">
                <param name="fasta1" type="data" format="fasta" label="Read 1 fasta file" />
                <param name="fasta2" type="data" format="fasta" label="Read 2 fasta file" />
              </when>
            </conditional>
            <expand macro="bowtie_options"/>
          </when>
          <when value="sam">
              <!-- convert-sam-for-rsem /ref/mouse_125 input.sam -o input_for_rsem.sam -->
              <param name="matepair" type="select" label="Library Type">
                <option value="single">Single End Reads</option>
                <option value="paired">Paired End Reads</option>
              </param>
              <param name="rsem_sam" type="data" format="rsem_sam" label="RSEM formatted SAM file" />
          </when>
        </conditional>
        <expand macro="rsem_options"/>
        <conditional name="rsem_outputs">
          <param name="result_bams" type="select" label="Create bam results files" 
                 help="In addition to the transcript-coordinate-based BAM file output, also output a BAM file with the read alignments in genomic coordinates" >
            <option value="none">No BAM results files</option>
            <option value="default" selected="true">Transcript BAM results file</option>
            <option value="both">Transcript and genome BAM results files</option>
          </param>
          <when value="none"/>
          <when value="default">
            <expand macro="sampling_for_bam"/>
          </when>
          <when value="both">
            <expand macro="sampling_for_bam"/>
          </when>
        </conditional>
      </when>
      <when value="No">
      </when>
    </conditional>
  </inputs>

  <outputs>
    <data format="rsem_ref" name="reference_file" label="RSEM ${job.reference_name} reference">
      <filter>job['select_job'] == "index"</filter>
    </data>
    <data format="tabular" name="gene_abundances" label="${run_rsem.sample}.gene_abundances" from_work_dir="rsem_output.genes.results">
      <filter>run_rsem['select'] == "Yes"</filter>
    </data>
    <data format="tabular" name="isoform_abundances" label="${run_rsem.sample}.isoform_abundances" from_work_dir="rsem_output.isoforms.results">
      <filter>run_rsem['select'] == "Yes"</filter>
    </data>
    <data format="bam" name="transcript_sorted_bam" label="${run_rsem.sample}.transcript.bam" from_work_dir="rsem_output.transcript.sorted.bam" >
      <filter>run_rsem['select'] == "Yes"</filter>
      <filter>rsem_outputs['result_bams'] != "none"</filter>
    </data>
    <data format="bam" name="genome_sorted_bam" label="${run_rsem.sample}.genome.bam" from_work_dir="rsem_output.genome.sorted.bam">
      <filter>run_rsem['select'] == "Yes"</filter>
      <filter>rsem_outputs['result_bams'] == "both"</filter>
    </data>
    <data format="txt" name="log" label="${run_rsem.sample}.rsem_log">
      <filter>run_rsem['select'] == "Yes"</filter>
    </data>
  </outputs>

  <tests>
    <test>
      <param name="select_job" value="index"/>
      <param name="ref_type" value="genomic"/>
      <param name="reference_fasta_file" value="ref.fasta" ftype="fasta"/>
      <param name="gtf" value="ref.gtf" ftype="gtf"/>
      <param name="reference_name" value="ref"/>
      <param name="select" value="Yes"/>
      <param name="sample" value="rsem_sample"/>
      <param name="refSrc" value="self"/>
      <param name="format" value="fastq"/>
      <param name="matepair" value="single"/>
      <param name="singlefastq" value="test.fq" ftype="fastqsanger"/>
      <param name="result_bams" value="none"/>
      <output name="reference_file">
        <assert_contents>
          <has_text text="ref" />
          <is_valid_xml />
        </assert_contents>
      </output>
      <output name="gene_abundances" value="gene_abundances.tab"/> 
      <output name="isoform_abundances" value="isoform_abundances.tab" /> 
      <output name="log"> 
        <assert_contents>
          <has_text text="Expression Results are written" />
        </assert_contents>
      </output>
    </test>
    <test>
      <param name="select_job" value="index"/>
      <param name="ref_type" value="genomic"/>
      <param name="reference_fasta_file" value="ref.fasta" ftype="fasta"/>
      <param name="gtf" value="ref.gtf" ftype="gtf"/>
      <param name="reference_name" value="ref"/>
      <param name="select" value="No"/>
      <output name="reference_file">
        <assert_contents>
          <has_text text="ref" />
          <is_valid_xml />
        </assert_contents>
      </output>
    </test>
  </tests>

  <help>

RSEM HOME PAGE - http://deweylab.biostat.wisc.edu/rsem/

NAME
    rsem-prepare-reference

SYNOPSIS
    rsem-prepare-reference [options] reference_fasta_file(s) reference_name

DESCRIPTION
    The rsem-prepare-reference program extracts/preprocesses the reference sequences and builds Bowtie indices using default parameters. 
    This program is used in conjunction with the 'rsem-calculate-expression' program.

INPUTS
    A fasta file of transcripts
    or
    A genome sequence fasta file and a GTF gene annotation file.  (When using UCSC data, include the related knownIsoforms.txt)

{'fraction_non_alphanumeric': 0.13566610455311973, 'fraction_numerical': 0.0030916245081506464, 'mean_word_length': 2.538989456932564, 'pattern_counts': {'":': 16, '<': 528, '<?xml version=': 0, '>': 532, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7349618', 'n_tokens_mistral': 11295, 'n_tokens_neox': 10844, 'n_words': 2387}