Answers.Body: <p>The first step of any analysis should be to actually check your data. I tried your commands on a vcf file I had, and the answer was obvious:</p>
  <pre><code>$ bcftools view -v indels input.vcf.gz -Oz -o indels.vcf.gz
  $ bcftools view -v snps indels.vcf.gz | tail -n3 | cut -f 1-5
  22  49591397    .   T   A,TGTAG
  22  49839228    .   G   A,GAGAA
  22  50602312    .   AT  TT,A
  </code></pre>
  <p>As you can see, in my case and most likely in yours, what happens is that you have one line describing multiple variants. This is relatively common. You are looking at cases where the snp is heterozygous and the sample has an indel at the same position as the snp. Or you might be dealing with cancer data or mosaicism or non diploid organisms, there are loads of different reasons this might happen.</p>
  <p>If you want only snps even in cases where you have both a snp and an indel in the same position, one approach is to first split all multi-allelic sites, so that two variants in the same position are now shown on separate lines, and then select snps only.</p>
  <p>So first use <code>bcftools norm -m -any</code> to split. The <code>-m</code> option is:</p>
  <pre><code>    -m, --multiallelics -|+TYPE     Split multiallelics (-) or join biallelics (+), type: snps|indels|both|any [both]
  </code></pre>
  <p>So <code>-m -any</code> will split all multiallelic sites. Now you can use <code>view</code> to get indels only:</p>
  <pre><code>bcftools norm -m -any input.vcf.gz -Oz |
    bcftools view -v indels -Oz &gt; indels.vcf.gz
  </code></pre>
  <p>If you now check the new <code>indels.vcf.gz</code> file, it should contain only indels:</p>
  <pre><code>$ bcftools view -v snps indels.vcf.gz|grep -v -c '^#'
  0
  </code></pre>
  <p>And looking at one of the examples from before, we can see that only the indel has been kept:</p>
  <pre><code>$ zgrep 49591397 indels.vcf.gz | cut -f 1-5
  22  49591397    .   T   TGTAG
  </code></pre>
  <p>While the original had both:</p>
  <pre><code>$ zgrep 49591397 input.vcf.gz | cut -f 1-5
  22  49591397    .   T   A,TGTAG
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-13T22:40:44.730Z
Answers.Text: Sorry for the delay in responding. I edited my comment and added the data. I used the command `bcftools view -v snps indels.vcf.gz | tail -n10 | cut -f 1-5`. Hope this helps. I'm new to bioinformatics and know almost nothing about it.
Answers.UserDisplayName: Jhonatan Henrique Rossini Lcio
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-14T11:21:49.543Z
Answers.Text: @JhonatanHenriqueRossiniLcio see updated answer for how to keep only indels in the end.
Answers.UserDisplayName: terdon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-16T00:37:40.423Z
Answers.Text: I have a question: do I first use the command `bcftools norm -m -any input.vcf.gz -Oz` and then the command `bcftools view -v indels -Oz > indels.vcf.gz` or do I use the command `bcftools norm -m -any input.vcf.gz -Oz | bcftools view -v indels -Oz > indels.vcf.gz` all at once? Thanks for helping me
Answers.UserDisplayName: Jhonatan Henrique Rossini Lcio
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-16T11:10:24.510Z
Answers.Text: @JhonatanHenriqueRossiniLcio you run them both together. That's why I have them both together in the answer.
Answers.UserDisplayName: terdon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-20T11:19:09.043Z
Answers.Text: Thanks for helping me out! So, I used the command `bcftools norm -m -any input.vcf.gz -Oz | bcftools view -v indels -Oz > indels.vcf.gz` and it gave me a file. When I used the command `bcftools view -v snps indels.vcf.gz|grep -v -c '^#'` to see how many snps there were, there were none. However, when I used the command `bcftools view -v indels indelss.vcf.gz|grep -v -c '^#'` to see if it had filtered out the indels correctly, it gave me a value of 26067197, when there were originally 18722319. What could have happened?
Answers.UserDisplayName: Jhonatan Henrique Rossini Lcio
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-20T15:38:16.983Z
Answers.Text: @JhonatanHenriqueRossiniLcio I don't know. Have you tried looking? We don't have access to your data, you will need to put some effort yourself. Find specific indels present in one file and absent in the others and see if you can figure it out. If not, please post a new question since this site is only for Q&A and not discussion.
Answers.UserDisplayName: terdon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-20T23:09:28.737Z
Answers.Text: okay. thank you very much for your help
Answers.UserDisplayName: Jhonatan Henrique Rossini Lcio
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-12T19:58:52.297Z
Answers.LastActivityDate: 2024-11-14T11:21:29.877Z
Answers.LastEditDate: 2024-11-14T11:21:29.877Z
Answers.UserDisplayName: terdon
Body: <p><a href="https://www.biostars.org/p/9605443/" rel="nofollow noreferrer">Cross-posted on biostars</a></p>
  <hr />
  <p>So, I used the command <code>bcftools view -v indels SRZ189891_722g.990.SNP.INDEL.chrAll.vcf.gz -Oz -o indels.vcf.gz</code>to create a file with only the indels. When I checked if the number of indels in the file SRZ189891_722g.990.SNP.INDEL.chrAll.vcf.gz was the same as in indels.vcf.gz, the results matched. However, I wanted to verify if any SNPs had been filtered out as well, so I used the command <code>bcftools view -v snps indels.vcf.gz|grep -v -c '^#'</code>. The result was that there were SNPs in the file indels.vcf.gz, when there should only be indels.</p>
  <p>What could have happened? What can I do to have only the indels?</p>
  <p>Edit: here are my data</p>
  <pre><code>chrX    77397836        .       CAG     CAGAGAG,CAGAG,GAG,C,CAGAGAGAGAG,CAGAGAGAGAGAGAG
  chrX    77398227        .       T       A,TA
  chrX    77398233        .       TTTATTTAA       ATTATTTAA,T
  chrX    77398237        .       TTTAATTAA       TTTAA,ATTAATTAA,T
  chrX    77398241        .       A       T,AT,ATTTATTTAT
  chrX    77400094        .       C       T,CA
  chrX    77401622        .       CA      C,AA
  chrX    77404139        .       CG      C,TG
  chrX    77406406        .       TCC     TCCC,CCC,TCCCC,T
  chrX    77411156        .       CAAATAAATAAAT   CAAAT,CAAATAAAT,CAAATAAATAAATAAAT,TAAATAAATAAAT,C
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-11-12T18:16:47.933Z
Comments.Text: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
Comments.UserDisplayName: Community
Tags: <bcftools>
Title: BCFTOOLS: command does not work correctly. Can you help me?
ThreadText: # BCFTOOLS: command does not work correctly. Can you help me?
  
  (Asked by: username_0 on 2024-11-12)
  
  [Cross-posted on biostars](https://www.biostars.org/p/9605443/)
  
  ---
  
  So, I used the command `bcftools view -v indels SRZ189891_722g.990.SNP.INDEL.chrAll.vcf.gz -Oz -o indels.vcf.gz`to create a file with only the indels. When I checked if the number of indels in the file SRZ189891\_722g.990.SNP.INDEL.chrAll.vcf.gz was the same as in indels.vcf.gz, the results matched. However, I wanted to verify if any SNPs had been filtered out as well, so I used the command `bcftools view -v snps indels.vcf.gz|grep -v -c '^#'`. The result was that there were SNPs in the file indels.vcf.gz, when there should only be indels.
  
  What could have happened? What can I do to have only the indels?
  
  Edit: here are my data
  
  ```
  chrX    77397836        .       CAG     CAGAGAG,CAGAG,GAG,C,CAGAGAGAGAG,CAGAGAGAGAGAGAG
  chrX    77398227        .       T       A,TA
  chrX    77398233        .       TTTATTTAA       ATTATTTAA,T
  chrX    77398237        .       TTTAATTAA       TTTAA,ATTAATTAA,T
  chrX    77398241        .       A       T,AT,ATTTATTTAT
  chrX    77400094        .       C       T,CA
  chrX    77401622        .       CA      C,AA
  chrX    77404139        .       CG      C,TG
  chrX    77406406        .       TCC     TCCC,CCC,TCCCC,T
  chrX    77411156        .       CAAATAAATAAAT   CAAAT,CAAATAAAT,CAAATAAATAAATAAAT,TAAATAAATAAAT,C
  
  ```
  
  **Tags:** bcftools
  
  > **Comments:**
  > **username_1**: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2024-11-12. Score: 3
  
  The first step of any analysis should be to actually check your data. I tried your commands on a vcf file I had, and the answer was obvious:
  
  ```
  $ bcftools view -v indels input.vcf.gz -Oz -o indels.vcf.gz
  $ bcftools view -v snps indels.vcf.gz | tail -n3 | cut -f 1-5
  22  49591397    .   T   A,TGTAG
  22  49839228    .   G   A,GAGAA
  22  50602312    .   AT  TT,A
  
  ```
  
  As you can see, in my case and most likely in yours, what happens is that you have one line describing multiple variants. This is relatively common. You are looking at cases where the snp is heterozygous and the sample has an indel at the same position as the snp. Or you might be dealing with cancer data or mosaicism or non diploid organisms, there are loads of different reasons this might happen.
  
  If you want only snps even in cases where you have both a snp and an indel in the same position, one approach is to first split all multi-allelic sites, so that two variants in the same position are now shown on separate lines, and then select snps only.
  
  So first use `bcftools norm -m -any` to split. The `-m` option is:
  
  ```
      -m, --multiallelics -|+TYPE     Split multiallelics (-) or join biallelics (+), type: snps|indels|both|any [both]
  
  ```
  
  So `-m -any` will split all multiallelic sites. Now you can use `view` to get indels only:
  
  ```
  bcftools norm -m -any input.vcf.gz -Oz |
    bcftools view -v indels -Oz > indels.vcf.gz
  
  ```
  
  If you now check the new `indels.vcf.gz` file, it should contain only indels:
  
  ```
  $ bcftools view -v snps indels.vcf.gz|grep -v -c '^#'
  0
  
  ```
  
  And looking at one of the examples from before, we can see that only the indel has been kept:
  
  ```
  $ zgrep 49591397 indels.vcf.gz | cut -f 1-5
  22  49591397    .   T   TGTAG
  
  ```
  
  While the original had both:
  
  ```
  $ zgrep 49591397 input.vcf.gz | cut -f 1-5
  22  49591397    .   T   A,TGTAG
  
  ```
  
  > **Comments:**
  > **username_0**: Sorry for the delay in responding. I edited my comment and added the data. I used the command `bcftools view -v snps indels.vcf.gz | tail -n10 | cut -f 1-5`. Hope this helps. I'm new to bioinformatics and know almost nothing about it.  
  > **username_2**: @username_0 see updated answer for how to keep only indels in the end.  
  > **username_0**: I have a question: do I first use the command `bcftools norm -m -any input.vcf.gz -Oz` and then the command `bcftools view -v indels -Oz > indels.vcf.gz` or do I use the command `bcftools norm -m -any input.vcf.gz -Oz | bcftools view -v indels -Oz > indels.vcf.gz` all at once? Thanks for helping me  
  > **username_2**: @username_0 you run them both together. That's why I have them both together in the answer.  
  > **username_0**: Thanks for helping me out! So, I used the command `bcftools norm -m -any input.vcf.gz -Oz | bcftools view -v indels -Oz > indels.vcf.gz` and it gave me a file. When I used the command `bcftools view -v snps indels.vcf.gz|grep -v -c '^#'` to see how many snps there were, there were none. However, when I used the command `bcftools view -v indels indelss.vcf.gz|grep -v -c '^#'` to see if it had filtered out the indels correctly, it gave me a value of 26067197, when there were originally 18722319. What could have happened?  
  > **username_2**: @username_0 I don't know. Have you tried looking? We don't have access to your data, you will need to put some effort yourself. Find specific indels present in one file and absent in the others and see if you can figure it out. If not, please post a new question since this site is only for Q&A and not discussion.  
  > **username_0**: okay. thank you very much for your help  
  
  ---
  
  