text: user8630: I am creating a bioinformatics pipeline using Snakemake doing everying from adapter trimming of raw sequencing data in .fq to mapping, SNP calling and SNP filtering.
  The issue i am having is when i try to filter specific chromosomes of the bcf files, using the --regions. The rule i have created below works and does create a filtered bcf file.
  rule bcftools_filter:
      input:
          bcf = "/dir/{sample}_aligned_call.bcf",
      output:
          "/dir/{sample}_aligned_call_filter.bcf"
      threads: 20
      shell:
          "bcftools view -Ob --threads {threads} -m2 -M2 -v snps {input.bcf} -o {output}"
  
  However i would like to add the --regions parameter to the bcftools command. I have tried the shell part of the rule to several things
  bcftools view -Ob --threads {threads} -m2 -M2 -v snps {input.bcf} --regions <chr1,chr2> -o {output}
  bcftools view -Ob --threads {threads} -m2 -M2 -v snps {input.bcf} --regions {chr1,chr2} -o {output}
  bcftools view -Ob --threads {threads} -m2 -M2 -v snps {input.bcf} --regions {{chr1,chr2}} -o {output}
  bcftools view -Ob --threads {threads} -m2 -M2 -v snps {input.bcf} --regions {{chr1} {chr2}} 
   {{chr2}} -o {output}
  bcftools view -Ob --threads {threads} -m2 -M2 -v snps {input.bcf} --regions ['chr1','chr2'] -o {output}
  
  But it doesn't work, and i am having trouble finding any suggestions to this specific issue.
  I know it works if i just run bcftools filter in my command line, so using --regions should work.
  Could anyone have any suggestions how to add --regions to the snakemake rule?
  
  user77: Something like the following would work:
  rule bcftools_filter:
      input:
          bcf = "/dir/{sample}_aligned_call.bcf",
      output:
          "/dir/{sample}_aligned_call_filter.bcf"
      params:
          regions="chr1,chr2"
      threads: 20
      shell:
          "bcftools view -Ob --threads {threads} -m2 -M2 --regions {params.regions} -v snps {input.bcf} -o {output}"
  
  You could also include the regions as part of the output file name, rather than specifying it as a param.
  
original_text: 8630: <p>I am creating a bioinformatics pipeline using Snakemake doing everying from adapter trimming of raw sequencing data in .fq to mapping, SNP calling and SNP filtering.</p>
  <p>The issue i am having is when i try to filter specific chromosomes of the bcf files, using the --regions. The rule i have created below works and does create a filtered bcf file.</p>
  <pre><code>rule bcftools_filter:
      input:
          bcf = &quot;/dir/{sample}_aligned_call.bcf&quot;,
      output:
          &quot;/dir/{sample}_aligned_call_filter.bcf&quot;
      threads: 20
      shell:
          &quot;bcftools view -Ob --threads {threads} -m2 -M2 -v snps {input.bcf} -o {output}&quot;
  </code></pre>
  <p>However i would like to add the --regions parameter to the bcftools command. I have tried the shell part of the rule to several things</p>
  <pre><code>bcftools view -Ob --threads {threads} -m2 -M2 -v snps {input.bcf} --regions &lt;chr1,chr2&gt; -o {output}
  bcftools view -Ob --threads {threads} -m2 -M2 -v snps {input.bcf} --regions {chr1,chr2} -o {output}
  bcftools view -Ob --threads {threads} -m2 -M2 -v snps {input.bcf} --regions {{chr1,chr2}} -o {output}
  bcftools view -Ob --threads {threads} -m2 -M2 -v snps {input.bcf} --regions {{chr1} {chr2}} 
   {{chr2}} -o {output}
  bcftools view -Ob --threads {threads} -m2 -M2 -v snps {input.bcf} --regions ['chr1','chr2'] -o {output}
  </code></pre>
  <p>But it doesn't work, and i am having trouble finding any suggestions to this specific issue.</p>
  <p>I know it works if i just run bcftools filter in my command line, so using --regions should work.</p>
  <p>Could anyone have any suggestions how to add --regions to the snakemake rule?</p>
   77: <p>Something like the following would work:</p>
  <pre><code>rule bcftools_filter:
      input:
          bcf = &quot;/dir/{sample}_aligned_call.bcf&quot;,
      output:
          &quot;/dir/{sample}_aligned_call_filter.bcf&quot;
      params:
          regions=&quot;chr1,chr2&quot;
      threads: 20
      shell:
          &quot;bcftools view -Ob --threads {threads} -m2 -M2 --regions {params.regions} -v snps {input.bcf} -o {output}&quot;
  </code></pre>
  <p>You could also include the regions as part of the output file name, rather than specifying it as a param.</p>
  