LinuxCommandLibrary

bcftools

Variant calling and VCF/BCF file manipulation

TLDR

View a VCF/BCF file

$ bcftools view [input.vcf.gz]
copy
Filter variants by region
$ bcftools view -r [chr1:1000000-2000000] [input.vcf.gz]
copy
Convert VCF to BCF
$ bcftools view -Ob -o [output.bcf] [input.vcf.gz]
copy
Call variants from aligned reads
$ bcftools mpileup -f [reference.fa] [aligned.bam] | bcftools call -mv -Oz -o [calls.vcf.gz]
copy
Merge multiple VCF files
$ bcftools merge [file1.vcf.gz] [file2.vcf.gz] -Oz -o [merged.vcf.gz]
copy
Filter variants by quality
$ bcftools filter -i 'QUAL>30 && DP>10' [input.vcf.gz] -Oz -o [filtered.vcf.gz]
copy
Extract sample genotypes
$ bcftools query -f '%CHROM\t%POS\t%REF\t%ALT[\t%GT]\n' [input.vcf.gz]
copy
Index a VCF/BCF file
$ bcftools index [input.vcf.gz]
copy

SYNOPSIS

bcftools subcommand [options] [file]

DESCRIPTION

bcftools is a suite of utilities for variant calling and manipulating files in the Variant Call Format (VCF) and its binary counterpart BCF. It is part of the SAMtools/HTSlib project and is widely used in bioinformatics for genomic variant analysis.
All commands work transparently with both VCF and BCF files, compressed or uncompressed. The tools are designed to work in pipelines, reading from stdin and writing to stdout.

PARAMETERS

-Ob

Output compressed BCF
-Oz
Output compressed VCF (bgzipped)
-Ov
Output uncompressed VCF
-Ou
Output uncompressed BCF (fastest for piping)
-r region
Restrict to regions (chr:from-to format)
-s samples
Comma-separated list of samples to include
-i expression
Include sites matching filter expression
-e expression
Exclude sites matching filter expression
-o file
Output file name

SUBCOMMANDS

Variant Calling

mpileup, call
File Operations
view, merge, concat, sort, index, convert
Filtering & Querying
filter, query, norm
Statistics
stats, roh, gtcheck
Annotation
annotate, csq, fill-tags
Manipulation
reheader, isec, +split, +scatter
Consensus
consensus

CAVEATS

Use -Ou when piping between bcftools subcommands to avoid unnecessary compression overhead. Indexed files are required for random access and some operations. VCF/BCF files should be sorted by chromosome and position for most operations.

HISTORY

bcftools was developed as part of the SAMtools project, initially created by Heng Li at the Wellcome Sanger Institute. It became a separate project around 2014 with the HTSlib library rewrite, gaining significant functionality for variant analysis.

SEE ALSO

samtools(1), tabix(1), bgzip(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community