<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>

CC BY-SA 4.0
2023-02-18T21:19:03.143Z
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.
arara
CC BY-SA 4.0
2023-02-18T21:20:56.877Z
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"}}'
Anas Jamshed
CC BY-SA 4.0
2023-02-18T21:30:57.690Z
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.
arara
CC BY-SA 4.0
2023-02-18T21:52:13.747Z
I only have X chromosome present in VCF File
Anas Jamshed
CC BY-SA 4.0
2023-02-18T22:47:26.267Z
What's the species. Drosophila?
arara
CC BY-SA 4.0
2023-02-18T22:54:21.610Z
I dont know about the species but when I separate N1 , N2 and N3 all files show the same record
Anas Jamshed
CC BY-SA 4.0
2023-02-18T22:56:37.027Z
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.
arara
CC BY-SA 4.0
2023-02-19T10:21:48.177Z
@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.
terdon
CC BY-SA 4.0
2023-02-19T10:23:14.230Z
@arara don't forget the pseudoautosomal regions: you will likely have some, albeit few, homozygous variants in both X and Y even in males.
terdon
CC BY-SA 4.0
2023-02-20T22:39:49.367Z
[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.
Ram RS
<vcf><shell>
How to Split VCF File into male and Female groups
# How to Split VCF File into male and Female groups

(Asked by: username_0 on 2023-02-18)

Cross-posted on biostars
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**: @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.  
> **username_2**: @arara 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

