title: Adding auto-QC to Snakemake pipeline to filter out samples with bad quality in the middle of the pipeline steps
body: <p>My question is similar to this one: <a href="https://stackoverflow.com/questions/56024818/conditional-execution-of-multiplexed-analysis-with-snakemake">Conditional execution of multiplexed analysis with snakemake</a></p>
  <p>I tried the dariober's gist answer with &quot;if-else&quot; in shell, but the else sentence output empty file or folder would always been deleted by snakemake and snakemake would report error (I even added &quot;|| true&quot; for each shell command to prevent non-zero exit code but still doesn't help). If I run the if-else shell outside of snakemake, files and folders would be generated though.</p>
  <p>I then tried to write python script instead of shell in &quot;run&quot; section, something like:</p>
  <pre><code>rule G_move_7:
      input: 
          passORnot_file = '{sample}/XXX_RData/{sample}.passORnot.txt',
          sample_folder = '{sample}',
          filtered_bam = '{sample}.Aligned.out.filtered.bam',
      output: 
          move_log = '{sample}.log',
      output
      run:
          with checkpoints.F_XXX_withCheck_6.get(sample=wildcards.sample).output[2].open() as f:
              if f.read().strip() == &quot;PASS&quot;:
                  os.system(&quot;mv -f&quot; + input.filtered_bam + &quot; ./PASS/ &gt; &quot; + output.move_log)
                  os.system(&quot;mv -f&quot; + input.sample_folder + &quot; ./PASS/ &gt;&gt; &quot; + output.move_log)
                  os.system(&quot;echo &quot; + input.sample_folder + &quot; ./PASS/ &gt;&gt; &quot; + output.move_log)
              else:
                  os.system(&quot;mv -f&quot; + input.filtered_bam + &quot; ./NOT_PASS/ &gt; &quot; + output.move_log)
                  os.system(&quot;mv -f&quot; + input.sample_folder + &quot; ./NOT_PASS/ &gt;&gt; &quot; + output.move_log)
                  os.system(&quot;echo &quot; + input.sample_folder + &quot; ./NOT_PASS/ &gt;&gt; &quot; + output.move_log)
  </code></pre>
  <p>This works but after getting all the passed sample to the folder &quot;PASS&quot;, I have to run the downstream steps with a new snakemake file to use wildcards for each samples in the PASS folder. So now my pipeline was cut to two parts. I have to run first piece and then the second snakemake file. This is fine with only one &quot;pass or not&quot; conditions, but if we add more quality check steps, this would become endless and not doable.</p>
  <p>Just wonder is there any more efficient and elegant way to do such auto-QC and filtering-out bad samples in snakemake? (or any other alternatives?) It's better that it can write all QC and filtering within one
  pipeline files. Thanks.</p>