<commit_before><tool name="SamToFastq" id="picard_SamToFastq" version="@TOOL_VERSION@.@WRAPPER_VERSION@">
  <description>extract reads and qualities from SAM/BAM dataset and convert to fastq</description>
  <macros>
    <import>picard_macros.xml</import>
    <token name="@WRAPPER_VERSION@">1</token>
  </macros>
  <expand macro="requirements" />
  <command detect_errors="exit_code"><![CDATA[

    echo "BAM" > $report &&    ## This is necessary for output dataset detection (see output tags below)

    @java_options@
    @symlink_element_identifier@

    picard
    SamToFastq

    INPUT='$escaped_element_identifier'

    #if str( $output_per_rg ) == "true":
      OUTPUT_PER_RG=true
      OUTPUT_DIR=.
    #elif str( $output_per_rg ) == "false" and str( $interleave ) == "false":
      FASTQ=READ1.fastq
      SECOND_END_FASTQ=READ2.fastq
      UNPAIRED_FASTQ=UNPAIRED_READS.fastq
    #elif str( $output_per_rg ) == "false" and str( $interleave ) == "true":
      FASTQ=INTERLEAVED.fastq
    #end if

    RE_REVERSE="${re_reverse}"
    INTERLEAVE="${interleave}"
    INCLUDE_NON_PF_READS="${include_non_pf_reads}"
    CLIPPING_ATTRIBUTE="${clipping_attribute}"
    CLIPPING_ACTION="${clipping_action}"
    READ1_TRIM="${read1_trim}"

    #if int($read1_max_bases_to_write) > -1:
      READ1_MAX_BASES_TO_WRITE="${read1_max_bases_to_write}"
    #end if

    READ2_TRIM="${read2_trim}"

    #if int($read2_max_bases_to_write) > -1:
      READ2_MAX_BASES_TO_WRITE="${read2_max_bases_to_write}"
    #end if

    INCLUDE_NON_PRIMARY_ALIGNMENTS="${include_non_primary_alignments}"


    VALIDATION_STRINGENCY="${validation_stringency}"
    QUIET=true
    VERBOSITY=ERROR
    @TMPDIR_OPTION@

  ]]></command>
  <inputs>

    <param format="sam,bam" name="inputFile" type="data" label="Select SAM/BAM dataset or dataset collection" help="If empty, upload or import a SAM/BAM dataset"/>
    <param name="output_per_rg" type="boolean" checked="False" label="Do you want to output a fastq file per read group (two fastq files per read group if the group is paired)" help="OUTPUT_PER_RG; default=False"/>
    <param name="re_reverse" type="boolean" checked="True" label="Re-reverse bases and qualities of reads with negative strand flag set before writing them to fastq" help="RE_REVERSE; default=True"/>
    <param name="interleave" type="boolean" label="Will generate an interleaved fastq if paired, each line will have /1 or /2 to describe which end it came from" help="INTERLEAVE; default=False"/>
    <param name="include_non_pf_reads" type="boolean" label="Include non-PF reads from the SAM/BAM dataset into the output FASTQ" help="INCLUDE_NON_PF_READS; PF means 'passes filtering'. Reads whose 'not passing quality controls' flag is set are non-PF reads; default=False"/>
    <param name="clipping_attribute" type="text" value="null" label="The attribute that stores the position at which the SAM/BAM record should be clipped" help="CLIPPING_ATTRIBUTE; default=null"/>
    <param name="clipping_action" type="text" value="null" label="The action that should be taken with clipped reads: 'X' means the reads and qualities should be trimmed at the clipped position; 'N' means the bases should be changed to Ns in the clipped region; and any integer means that the base qualities should be set to that value in the clipped region" help="CLIPPING_ACTION; default=null"/>
    <param name="read1_trim" type="integer" value="0" min="0" label="The number of bases to trim from the beginning of read 1" help="READ1_TRIM; default=0"/>
    <param name="read1_max_bases_to_write" type="integer" value="-1" label="The maximum number of bases to write from read 1 after trimming" help="READ1_MAX_BASES_TO_WRITE; If there are fewer than this many bases left after trimming, all will be written. If this value is null then all bases left after trimming will be written; default=null (-1)"/>
    <param name="read2_trim" type="integer" value="0" min="0" label="The number of bases to trim from the beginning of read 2" help="READ2_TRIM; default=0"/>
    <param name="read2_max_bases_to_write" type="integer" value="-1" label="The maximum number of bases to write from read 2 after trimming" help="READ2_MAX_BASES_TO_WRITE; If there are fewer than this many bases left after trimming, all will be written. If this value is null then all bases left after trimming will be written; default=null (-1)"/>
    <param name="include_non_primary_alignments" type="boolean" label="If true, include non-primary alignments in the output" help="INCLUDE_NON_PRIMARY_ALIGNMENTS; Support of non-primary alignments in SamToFastq is not comprehensive, so there may be exceptions if this is set to true and there are paired reads with non-primary alignments; default=False"/>

    <expand macro="VS" />

  </inputs>

  <outputs>
    <!-- here dataset discovery is based on fact that if OUTPUT_PER_RG=true this tool automatically adds .fastq extension to emitted files -->
    <data format="txt" name="report" label="SamToFastq run" hidden="true">
      <discover_datasets pattern="(?P&lt;designation&gt;.+)\.fastq" ext="fastqsanger" visible="true"/>
    </data>
  </outputs>

  <tests>
    <test>
      <param name="inputFile" value="picard_SamToFastq.bam" ftype="bam"/>
      <param name="output_per_rg" value="false"/>
      <param name="re_reverse" value="true"/>
      <param name="interleave" value="true"/>
      <param name="include_non_pf_reads" value="false"/>
      <param name="clipping_attribute" value="null" />
      <param name="clipping_action" value="null" />
      <param name="read1_trim" value="0" />
      <param name="read1_max_bases_to_write" value="-1"/>
      <param name="read2_trim" value="0" />
      <param name="read2_max_bases_to_write" value="-1"/>
      <param name="include_non_primary_alignments" value="false"/>
      <output name="report">
        <assert_contents>
          <has_line line="BAM" />
        </assert_contents>
        <discovered_dataset designation="INTERLEAVED" file="picard_SamToFastq_test1.fq" ftype="fastqsanger"/>
      </output>
    </test>
  </tests>


  <help>

**Purpose**

Extracts read sequences and qualities from the input SAM/BAM dataset and outputs them in Sanger fastq format. In the RE_REVERSE=True mode (default behavior), if the read is aligned and the alignment is to the reverse strand on the genome, the read's sequence from input SAM.BAM dataset will be reverse-complemented prior to writing it to fastq in order restore correctly the original read sequence as it was generated by the sequencer.

-----

.. class:: warningmark

**DANGER: Multiple Outputs**

Generating per readgroup fastq (setting **OUTPUT_PER_RG** to True) may produce very large numbers of outputs. Know what you are doing!

@dataset_collections@

@description@

  FASTQ=File
  F=File                        Output fastq file (single-end fastq or, if paired, first end of the pair fastq).
                                Required.  Cannot be used in conjuction with option(s) OUTPUT_PER_RG (OPRG)<commit_msg>removes discovered dataset bits (does not work in workflows), switches null -> "" to avoid tool breakage<commit_after><tool name="SamToFastq" id="picard_SamToFastq" version="@TOOL_VERSION@.@WRAPPER_VERSION@">
  <description>extract reads and qualities from SAM/BAM dataset and convert to fastq</description>
  <macros>
    <import>picard_macros.xml</import>
    <token name="@WRAPPER_VERSION@">2</token>
  </macros>
  <expand macro="requirements" />
  <command detect_errors="exit_code"><![CDATA[


    @java_options@
    @symlink_element_identifier@

    picard
    SamToFastq

    INPUT='$escaped_element_identifier'

    FASTQ='${interleaved_fastq}'

    RE_REVERSE="${re_reverse}"
    INTERLEAVE=TRUE
    INCLUDE_NON_PF_READS="${include_non_pf_reads}"
    #if len(str($clipping_attribute)) > 0:
       CLIPPING_ATTRIBUTE="${clipping_attribute}"
    #end if
    #if len(str($clipping_action)) > 0:
       CLIPPING_ACTION="${clipping_action}"
    #end if
    READ1_TRIM="${read1_trim}"

    #if int($read1_max_bases_to_write) > -1:
      READ1_MAX_BASES_TO_WRITE="${read1_max_bases_to_write}"
    #end if

    READ2_TRIM="${read2_trim}"

    #if int($read2_max_bases_to_write) > -1:
      READ2_MAX_BASES_TO_WRITE="${read2_max_bases_to_write}"
    #end if

    INCLUDE_NON_PRIMARY_ALIGNMENTS="${include_non_primary_alignments}"


    VALIDATION_STRINGENCY="${validation_stringency}"
    QUIET=true
    VERBOSITY=ERROR
    @TMPDIR_OPTION@

  ]]></command>
  <inputs>

    <param format="sam,bam" name="inputFile" type="data" label="Select SAM/BAM dataset or dataset collection" help="If empty, upload or import a SAM/BAM dataset"/>
    <param name="re_reverse" type="boolean" checked="True" label="Re-reverse bases and qualities of reads with negative strand flag set before writing them to fastq" help="RE_REVERSE; default=True"/>
    <param name="include_non_pf_reads" type="boolean" label="Include non-PF reads from the SAM/BAM dataset into the output FASTQ" help="INCLUDE_NON_PF_READS; PF means 'passes filtering'. Reads whose 'not passing quality controls' flag is set are non-PF reads; default=False"/>
    <param name="clipping_attribute" type="text" value="" label="The attribute that stores the position at which the SAM/BAM record should be clipped" help="CLIPPING_ATTRIBUTE; default=null"/>
    <param name="clipping_action" type="text" value="" label="The action that should be taken with clipped reads: 'X' means the reads and qualities should be trimmed at the clipped position; 'N' means the bases should be changed to Ns in the clipped region; and any integer means that the base qualities should be set to that value in the clipped region" help="CLIPPING_ACTION; default=null"/>
    <param name="read1_trim" type="integer" value="0" min="0" label="The number of bases to trim from the beginning of read 1" help="READ1_TRIM; default=0"/>
    <param name="read1_max_bases_to_write" type="integer" value="-1" label="The maximum number of bases to write from read 1 after trimming" help="READ1_MAX_BASES_TO_WRITE; If there are fewer than this many bases left after trimming, all will be written. If this value is null then all bases left after trimming will be written; default=null (-1)"/>
    <param name="read2_trim" type="integer" value="0" min="0" label="The number of bases to trim from the beginning of read 2" help="READ2_TRIM; default=0"/>
    <param name="read2_max_bases_to_write" type="integer" value="-1" label="The maximum number of bases to write from read 2 after trimming" help="READ2_MAX_BASES_TO_WRITE; If there are fewer than this many bases left after trimming, all will be written. If this value is null then all bases left after trimming will be written; default=null (-1)"/>
    <param name="include_non_primary_alignments" type="boolean" label="If true, include non-primary alignments in the output" help="INCLUDE_NON_PRIMARY_ALIGNMENTS; Support of non-primary alignments in SamToFastq is not comprehensive, so there may be exceptions if this is set to true and there are paired reads with non-primary alignments; default=False"/>

    <expand macro="VS" />

  </inputs>

  <outputs>
    <data format="fastqsanger" name="interleaved_fastq" label="${tool.name} on ${on_string}: reads as interleaved fastq"/>
  </outputs>

  <tests>
    <test>
      <param name="inputFile" value="picard_SamToFastq.bam" ftype="bam"/>
      <param name="output_per_rg" value="false"/>
      <param name="re_reverse" value="true"/>
      <param name="interleave" value="true"/>
      <param name="include_non_pf_reads" value="false"/>
      <param name="clipping_attribute" value="" />
      <param name="clipping_action" value="" />
      <param name="read1_trim" value="0" />
      <param name="read1_max_bases_to_write" value="-1"/>
      <param name="read2_trim" value="0" />
      <param name="read2_max_bases_to_write" value="-1"/>
      <param name="include_non_primary_alignments" value="false"/>
      <output name="interleaved_fastq" file="picard_SamToFastq_test1.fq" ftype="fastqsanger"/>
    </test>
  </tests>


  <help>

**Purpose**

Extracts read sequences and qualities from the input SAM/BAM dataset and outputs them in Sanger fastq format. In the RE_REVERSE=True mode (default behavior), if the read is aligned and the alignment is to the reverse strand on the genome, the read's sequence from input SAM.BAM dataset will be reverse-complemented prior to writing it to fastq in order restore correctly the original read sequence as it was generated by the sequencer.

-----

.. class:: warningmark

**DANGER: Multiple Outputs**

Generating per readgroup fastq (setting **OUTPUT_PER_RG** to True) may produce very large numbers of outputs. Know what you are doing!

@dataset_collections@

@description@

  FASTQ=File
  F=File                        Output fastq file (single-end fastq or, if paired, first end of the pair fastq).
                                Required.  Cannot be used in conjuction with option(s) OUTPUT_PER_RG (OPRG)
{'fraction_non_alphanumeric': 0.11076899391886691, 'fraction_numerical': 0.007235778615964899, 'mean_word_length': 4.530864197530864, 'pattern_counts': {'":': 3, '<': 107, '<?xml version=': 0, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6700501', 'n_tokens_mistral': 4085, 'n_tokens_neox': 3922, 'n_words': 1281}