Body: <p><a href="https://www.biostars.org/p/9554899/" rel="nofollow noreferrer"><em><strong>Cross-posted on biostars</strong></em></a></p>
  <p>I have trio_example.vcf file and I want to split them into male and female groups. I tried this:</p>
  <pre><code>$ bcftools query -l trio_example.vcf
  </code></pre>
  <p>And it gave me:</p>
  <pre><code>N1
  N2
  N3
  </code></pre>
  <p>After that I tried this command:</p>
  <pre><code>for sample in `bcftools query -l trio_example.vcf.gz`; do vcf-subset --exclude-ref -c <span class="math-container">$sample trio_example.vcf.gz &gt; $</span>{sample}.vcf; done
  </code></pre>
  <p>to split 3 samples. Now its showing same data in all 3 N files</p>
  <p>How can I solve this issue? Also I need to split the data into male and female. For splitting I am using:</p>
  <pre><code>bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%AF\n' trio_example.vcf | awk '{if(<span class="math-container">$1 == "X" &amp;&amp; $</span>5 &gt;= 0.3 &amp;&amp; <span class="math-container">$5 &lt;= 0.7) {print $6 " is male"} else if ($</span>1 == &quot;Y&quot; &amp;&amp; <span class="math-container">$5 == 1) {print $6 " is male"} else if ($</span>1 == &quot;X&quot; &amp;&amp; <span class="math-container">$5 == 1) {print $6 " is female"} else {print $</span>6 &quot; is of unknown sex&quot;}}'
  </code></pre>
  <p>But it also not give me exact result</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-18T21:19:03.143Z
Comments.Text: Do you know which of the individuals in the VCF are male and female? If so, you can use bcftools (view command) to subset the VCF twice, once creating a VCF only including males, a second time making a VCF only including females.
Comments.UserDisplayName: arara
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-18T21:20:56.877Z
Comments.Text: I dont know thats why I am using now this command: bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%AF\n' trio_example.vcf | awk '{if($1 == "X" && $5 >= 0.3 && $5 <= 0.7) {print $6 " is male"} else if ($1 == "Y" && $5 == 1) {print $6 " is male"} else if ($1 == "X" && $5 == 1) {print $6 " is female"} else {print $6 " is of unknown sex"}}'
Comments.UserDisplayName: Anas Jamshed
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-18T21:30:57.690Z
Comments.Text: Is the information about the sex of your individuals anywhere in the VCF? In the INFO tag maybe? Somewhere in any paper or supplementary file? Which organism are you working on -- does this organism have sex chromosomes? Does the VCF have X and Y chromosomes (or Z/W etc depending on the sex determining system)? If so, individuals with variants at Y or hemizygous for X should be male, whereas individuals with homozygous variants at X should be female.
Comments.UserDisplayName: arara
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-18T21:52:13.747Z
Comments.Text: I only have X chromosome present in VCF File
Comments.UserDisplayName: Anas Jamshed
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-18T22:47:26.267Z
Comments.Text: What's the species. Drosophila?
Comments.UserDisplayName: arara
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-18T22:54:21.610Z
Comments.Text: I dont know about the species but when I separate N1 , N2 and N3 all files show the same record
Comments.UserDisplayName: Anas Jamshed
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-18T22:56:37.027Z
Comments.Text: If you don't even know what species you're working with I think you should figure that out ... because if you want to make an inference of sex from the VCF and that information simply isn't stated anywhere, you need to know the sex determining system you're working with. Drosophila only has X chromosomes, but males have one X and females have two. This kind of information is important if you want to infer sex because males can only have one variant at X, females can have two.
Comments.UserDisplayName: arara
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-19T10:21:48.177Z
Comments.Text: @AnasJamshed please add all extra information to your question, not in comments. As you can see your `bcftools -f` command is  very hard to read. Add it to the question please, along with all the other extra information you have given so that the next person to see the question can have all information there.
Comments.UserDisplayName: terdon
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-19T10:23:14.230Z
Comments.Text: @arara don't forget the pseudoautosomal regions: you will likely have some, albeit few, homozygous variants in both X and Y even in males.
Comments.UserDisplayName: terdon
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-20T22:39:49.367Z
Comments.Text: [Cross-posted on biostars](https://www.biostars.org/p/9554899/). OP was reprimanded on biostars by multiple users for opening a lot of tangential posts and is probably attempting a similar move here.
Comments.UserDisplayName: Ram RS
Tags: <vcf><shell>
Title: How to Split VCF File into male and Female groups
ThreadText: # How to Split VCF File into male and Female groups
  
  (Asked by: username_0 on 2023-02-18)
  
  [***Cross-posted on biostars***](https://www.biostars.org/p/9554899/)
  
  I have trio\_example.vcf file and I want to split them into male and female groups. I tried this:
  
  ```
  $ bcftools query -l trio_example.vcf
  
  ```
  
  And it gave me:
  
  ```
  N1
  N2
  N3
  
  ```
  
  After that I tried this command:
  
  ```
  for sample in `bcftools query -l trio_example.vcf.gz`; do vcf-subset --exclude-ref -c $sample trio_example.vcf.gz > ${sample}.vcf; done
  
  ```
  
  to split 3 samples. Now its showing same data in all 3 N files
  
  How can I solve this issue? Also I need to split the data into male and female. For splitting I am using:
  
  ```
  bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%AF\n' trio_example.vcf | awk '{if($1 == "X" && $5 >= 0.3 && $5 <= 0.7) {print $6 " is male"} else if ($1 == "Y" && $5 == 1) {print $6 " is male"} else if ($1 == "X" && $5 == 1) {print $6 " is female"} else {print $6 " is of unknown sex"}}'
  
  ```
  
  But it also not give me exact result
  
  **Tags:** vcf, shell
  
  > **Comments:**
  > **username_1**: Do you know which of the individuals in the VCF are male and female? If so, you can use bcftools (view command) to subset the VCF twice, once creating a VCF only including males, a second time making a VCF only including females.  
  > **username_0**: I dont know thats why I am using now this command: bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%AF\n' trio_example.vcf | awk '{if($1 == "X" && $5 >= 0.3 && $5 <= 0.7) {print $6 " is male"} else if ($1 == "Y" && $5 == 1) {print $6 " is male"} else if ($1 == "X" && $5 == 1) {print $6 " is female"} else {print $6 " is of unknown sex"}}'  
  > **username_1**: Is the information about the sex of your individuals anywhere in the VCF? In the INFO tag maybe? Somewhere in any paper or supplementary file? Which organism are you working on -- does this organism have sex chromosomes? Does the VCF have X and Y chromosomes (or Z/W etc depending on the sex determining system)? If so, individuals with variants at Y or hemizygous for X should be male, whereas individuals with homozygous variants at X should be female.  
  > **username_0**: I only have X chromosome present in VCF File  
  > **username_1**: What's the species. Drosophila?  
  > **username_0**: I dont know about the species but when I separate N1 , N2 and N3 all files show the same record  
  > **username_1**: If you don't even know what species you're working with I think you should figure that out ... because if you want to make an inference of sex from the VCF and that information simply isn't stated anywhere, you need to know the sex determining system you're working with. Drosophila only has X chromosomes, but males have one X and females have two. This kind of information is important if you want to infer sex because males can only have one variant at X, females can have two.  
  > **username_2**: @username_0 please add all extra information to your question, not in comments. As you can see your `bcftools -f` command is  very hard to read. Add it to the question please, along with all the other extra information you have given so that the next person to see the question can have all information there.  
  > **username_2**: @username_1 don't forget the pseudoautosomal regions: you will likely have some, albeit few, homozygous variants in both X and Y even in males.  
  > **username_3**: [Cross-posted on biostars](https://www.biostars.org/p/9554899/). OP was reprimanded on biostars by multiple users for opening a lot of tangential posts and is probably attempting a similar move here.  
  
  ---
  
  ## 0 answers
  
  