Welcome to the Genome Toolbox! I am glad you navigated to the blog and hope you find the contents useful and insightful for your genomic needs. If you find any of the entries particularly helpful, be sure to click the +1 button on the bottom of the post and share with your colleagues. Your input is encouraged, so if you have comments or are aware of more efficient tools not included in a post, I would love to hear from you. Enjoy your time browsing through the Toolbox.
Showing posts with label vcftools. Show all posts
Showing posts with label vcftools. Show all posts

Tuesday, July 9, 2013

Calculate Minor Allele Frequencies from VCF File Variants

Today I needed to calculate minor allele frequencies (MAFs) for sequence variants called in a .vcf file.  I couldn't find any programs that would do this for me, so I wrote a quick script to do it in Python.


This can be run in python from the command prompt by typing:


where project.vcf is the vcf file you want to calculate MAFs for.  It will return a project.txt file that contains the calculated MAF values.  This script will only work for SNPs and does not work on insertions and deletions.

Alternatively, if Python scares you there is a bit of a round about way that will do this for you too.  First use vcftools to convert your .vcf file into a Plink compatible .ped and .map file.


Then, open Plink and run the --freq option on the newly created .ped file.

**UPDATE**
Today I found an updated way to use Vcftools to directly calculate the MAF values for you.  It just takes the simple command --freq.  Here is some example code:

Monday, May 20, 2013

Merge VCF Files

VCF tools can be used to merge .vcf files using the following commnad.

How to Install Vcftools

Vcftools is a handy program to manipulate .vcf files.  This page describes how to install vcftools.  Here is a brief summary of what to do.

1) Download the most recent version of vcftools.
2) Extract vcftools using the extract command or the following line of code.


3) To build vcftools, cd into the vcftools directory and type make.
4) Add the following two lines to you .bashrc file and then type source .bashrc.


One final note: vcftools requires .vcf files be zipped by bgzip and indexed by Tabix.  To install Tabix, see these installation instructions.  Enjoy using vcftools!

Thursday, May 9, 2013

Create .ped and .map files from .vcf file

Here is a quick and easy script to convert .vcf files into a PLINK compatible .ped and .map file using vcftools.  Only bi-allelic loci will be output.  The --plink option can be very slow on large datasets in which case it is recommended to use the --chr option to output individual chromosomes or the --plink-tped option to output transposed PLINK files.