# Calculate allele frequency in a VCF File

**URL:** <https://discuss.hail.is/t/calculate-allele-frequency-in-a-vcf-file/1958>\
**Category:** Hail Query & hailctl\
**Created:** [March 15, 2021, 4:39pm UTC](https://discuss.hail.is/t/calculate-allele-frequency-in-a-vcf-file/1958 "2021-03-15T16:39:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaden30](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/jaden30/32/501_2.png) [@Jaden30](https://discuss.hail.is/u/Jaden30)\
**Post date:** [March 15, 2021, 4:39pm UTC](https://discuss.hail.is/t/calculate-allele-frequency-in-a-vcf-file/1958/1 "2021-03-15T16:39:47Z")

</div>

Hello,  
I am trying to calculate the allele frequency of each variant in a VCF file

I am struggling to figure out the methods to implement.  
Any help will be appreciated

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [March 15, 2021, 4:45pm UTC](https://discuss.hail.is/t/calculate-allele-frequency-in-a-vcf-file/1958/2 "2021-03-15T16:45:09Z")

</div>

`hl.variant_qc` should do what you need!

---

<div class="post-metadata">

**Author:** ![Jaden30](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/jaden30/32/501_2.png) [@Jaden30](https://discuss.hail.is/u/Jaden30)\
**Post date:** [March 15, 2021, 5:01pm UTC](https://discuss.hail.is/t/calculate-allele-frequency-in-a-vcf-file/1958/3 "2021-03-15T17:01:41Z")

</div>

Thank you very much  
But then I want to write the locus, alleles, location and allele frequency into a text file.  
Thats the tricky part

---

<div class="post-metadata">

**Author:** ![johnc1231](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/johnc1231/32/286_2.png) [@johnc1231](https://discuss.hail.is/u/johnc1231)\
**Post date:** [March 15, 2021, 5:19pm UTC](https://discuss.hail.is/t/calculate-allele-frequency-in-a-vcf-file/1958/4 "2021-03-15T17:19:31Z")

</div>

That won’t be tricky. It should look roughly like:

```auto
mt = hl.import_vcf(.....)
mt = hl.variant_qc(mt)
rows = mt.rows()
to_be_exported= rows.select(.....<whatever fields you want> .....)
to_be_exported.export("filename.tsv")

```

---

<div class="post-metadata">

**Author:** ![Jaden30](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/jaden30/32/501_2.png) [@Jaden30](https://discuss.hail.is/u/Jaden30)\
**Post date:** [March 15, 2021, 5:41pm UTC](https://discuss.hail.is/t/calculate-allele-frequency-in-a-vcf-file/1958/5 "2021-03-15T17:41:59Z")

</div>

Alright. Thank you very much. You have been very helpful
