title: Is it possible to have an optional output file in Snakemake?
body: <p>I'm writing a snakemake rule that will handle performing fastq trimming on either single or paired end sequencing data. If the data is paired end there should be two output files, if single end, there should be one. </p>
  
  <p>The rule I have written works so far, however, I don't have it that the second pair of the trimmed is an output file. This means that snakemake is not checking to see if that file exists. It will output, but it's not checking, is it possible to have an optional output?</p>
  
  <pre><code>    input:
      #get the value in the fast1 column
          fastq_file = lambda wildcards: return_fastq(wildcards.fastq_name,wildcards.unit,first_pair = True)
      output:
          out_fastqc = config["fastp_trimmed_output_folder"] + "{unit}/{fastq_name}_trimmed.fastq.gz",
          fastpjson = config["fastp_trimmed_output_folder"] + "{unit}/{fastq_name}_fastp.json",
          fastphtml = config["fastp_trimmed_output_folder"] + "{unit}/{fastq_name}_fastp.html"
      params:
          fastp_parameters = return_parsed_extra_params(config['fastp_parameters']),
          fastq_file2 = lambda wildcards: return_fastq(wildcards.fastq_name,wildcards.unit,first_pair = False),
          out_fastqc2 = lambda wildcards: return_fastq2_name(wildcards.fastq_name,wildcards.unit),
          fastpjson = config["fastp_trimmed_output_folder"] + "{unit}/{fastq_name}_fastp.json",
          fastphtml = config["fastp_trimmed_output_folder"] + "{unit}/{fastq_name}_fastp.html"
      run:
          if config["end_type"] == "se":
              shell("{config[fastp_path]} -i {input.fastq_file} -o {output.out_fastqc} --json {output.fastpjson} --html {output.fastphtml} {params.fastp_parameters}")
          if config["end_type"] == "pe":
              shell("{config[fastp_path]} --in1 {input.fastq_file} --in2 {params.fastq_file2} --out1 {output.out_fastqc} --out2  {params.out_fastqc2} --json {output.fastpjson} --html {output.fastphtml} {params.fastp_parameters}")
  </code></pre>
  
  <p>The goal is that the out_fastqc2 would be includes as an optional output of the rule so that snakemake will check if it exists and appropiately give me an error if it doesn't. </p>
  
  <p>If Snakemake doesn't allow optional outputs, I could just split into two rules, but that's not quite what I'd like.</p>