Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-18T22:12:38.480Z
Answers.Text: Would a simple `--regions \"chr1,chr2\"` in the shell command not work?
Answers.UserDisplayName: Ram RS
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-18T22:13:57.737Z
Answers.Text: You don't need to even quote it. However having it as a param allows you to set it elsewhere (e.g., the command line).
Answers.UserDisplayName: Devon Ryan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-18T19:06:59.737Z
Answers.LastActivityDate: 2021-08-18T19:06:59.737Z
Answers.UserDisplayName: Devon Ryan
Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-18T14:58:14.540Z
Comments.Text: Have you tried `expand()` function? https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html?highlight=expand#the-expand-function
Comments.UserDisplayName: zorbax
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-18T16:29:23.337Z
Comments.Text: No i havent tried that, i didn't realize you could potentially use the expand() function for the shell part. But i will look into it
Comments.UserDisplayName: RAHenriksen
Tags: <snp><snakemake><bcftools>
Title: Snakemake rule issue with bcftools view filtering
ThreadText: # Snakemake rule issue with bcftools view filtering
  
  (Asked by: username_0 on 2021-08-18)
  
  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?
  
  **Tags:** snp, snakemake, bcftools
  
  > **Comments:**
  > **username_1**: Have you tried `expand()` function? https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html?highlight=expand#the-expand-function  
  > **username_0**: No i havent tried that, i didn't realize you could potentially use the expand() function for the shell part. But i will look into it  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-08-18. Score: 1
  
  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.
  
  > **Comments:**
  > **username_3**: Would a simple `--regions \"chr1,chr2\"` in the shell command not work?  
  > **username_2**: You don't need to even quote it. However having it as a param allows you to set it elsewhere (e.g., the command line).  
  
  ---
  
  