Package: vcfstats
vcfstats - powerful statistics for VCF filesDocumentation|CHANGELOGMotivationThere are a couple of tools that can plot some statistics of VCF files, includingbcftoolsandjvarkit. However, none of them could:plot specific metricscustomize the plotsfocus on variants with certain filtersR packagevcfRcan do some of the above. However, it has to load entire VCF into memory, which is not friendly to large VCF files.Installationpipinstall-UvcfstatsOr run with docker:dockerrun\-w/vcfstats/workdir\-v$(pwd):/vcfstats/workdir\--rmjustold/vcfstats:latest\vcfstats\--vcfmyfile.vcf\-ooutputs\--formula'COUNT(1) ~ CONTIG'\--title'Number of variants on each chromosome'GalleryNumber of variants on each chromosomevcfstats--vcfexamples/sample.vcf\--outdirexamples/\--formula'COUNT(1) ~ CONTIG'\--title'Number of variants on each chromosome'\--configexamples/config.tomlChanging labels and ticksvcfstatsusesplotninefor plotting, read more about it on how to specify--ggsto modify the plots.vcfstats--vcfexamples/sample.vcf\--outdirexamples/\--formula'COUNT(1) ~ CONTIG'\--title'Number of variants on each chromosome (modified)'\--configexamples/config.toml\--ggs'scale_x_discrete(name ="Chromosome", \limits=["1","2","3","4","5","6","7","8","9","10","X"]); \ylab("# Variants")'Number of variants on first 5 chromosomevcfstats--vcfexamples/sample.vcf\--outdirexamples/\--formula'COUNT(1) ~ CONTIG[1,2,3,4,5]'\--title'Number of variants on each chromosome (first 5)'\--configexamples/config.toml# orvcfstats--vcfexamples/sample.vcf\--outdirexamples/\--formula'COUNT(1) ~ CONTIG[1-5]'\--title'Number of variants on each chromosome (first 5)'\--configexamples/config.toml# or# require vcf file to be tabix-indexed.vcfstats--vcfexamples/sample.vcf\--outdirexamples/\--formula'COUNT(1) ~ CONTIG'\--title'Number of variants on each chromosome (first 5)'\--configexamples/config.toml-r12345Number of substitutions of SNPsvcfstats--vcfexamples/sample.vcf\--outdirexamples/\--formula'COUNT(1, VARTYPE[snp]) ~ SUBST[A>T,A>G,A>C,T>A,T>G,T>C,G>A,G>T,G>C,C>A,C>T,C>G]'\--title'Number of substitutions of SNPs'\--configexamples/config.tomlOnly with SNPs PASS all filtersvcfstats--vcfexamples/sample.vcf\--outdirexamples/\--formula'COUNT(1, VARTYPE[snp]) ~ SUBST[A>T,A>G,A>C,T>A,T>G,T>C,G>A,G>T,G>C,C>A,C>T,C>G]'\--title'Number of substitutions of SNPs (passed)'\--configexamples/config.toml\--passedAlternative allele frequency on each chromosome# using a dark themevcfstats--vcfexamples/sample.vcf\--outdirexamples/\--formula'AAF ~ CONTIG'\--title'Allele frequency on each chromosome'\--configexamples/config.toml--ggs'theme_dark()'Using boxplotvcfstats--vcfexamples/sample.vcf\--outdirexamples/\--formula'AAF ~ CONTIG'\--title'Allele frequency on each chromosome (boxplot)'\--configexamples/config.toml\--figtypeboxplotUsing density plot/histogram to investigate the distribution:You can plot the distribution, using density plot or histogramvcfstats--vcfexamples/sample.vcf\--outdirexamples/\--formula'AAF ~ CONTIG[1,2]'\--title'Allele frequency on chromosome 1,2'\--configexamples/config.toml\--figtypedensityOverall distribution of allele frequencyvcfstats--vcfexamples/sample.vcf\--outdirexamples/\--formula'AAF ~ 1'\--title'Overall allele frequency distribution'\--configexamples/config.tomlExcluding some low/high frequency variantsvcfstats--vcfexamples/sample.vcf\--outdirexamples/\--formula'AAF[0.05, 0.95] ~ 1'\--title'Overall allele frequency distribution (0.05-0.95)'\--configexamples/config.tomlCounting types of variants on each chromosomevcfstats--vcfexamples/sample.vcf\--outdirexamples/\--formula'COUNT(1, group=VARTYPE) ~ CHROM'\# or simply# --formula 'VARTYPE ~ CHROM' \--title'Types of variants on each chromosome'\--configexamples/config.tomlUsing bar chart if there is only one chromosomevcfstats--vcfexamples/sample.vcf\--outdirexamples/\--formula'COUNT(1, group=VARTYPE) ~ CHROM[1]'\# or simply# --formula 'VARTYPE ~ CHROM[1]' \--title'Types of variants on chromosome 1'\--configexamples/config.toml\--figtypepieCounting variant types on whole genomevcfstats--vcfexamples/sample.vcf\--outdirexamples/\# or simply# --formula 'VARTYPE ~ 1' \--formula'COUNT(1, group=VARTYPE) ~ 1'\--title'Types of variants on whole genome'\--configexamples/config.tomlCounting type of mutant genotypes (HET, HOM_ALT) for sample 1 on each chromosomevcfstats--vcfexamples/sample.vcf\--outdirexamples/\# or simply# --formula 'GTTYPEs[HET,HOM_ALT]{0} ~ CHROM' \--formula'COUNT(1, group=GTTYPEs[HET,HOM_ALT]{0}) ~ CHROM'\--title'Mutant genotypes on each chromosome (sample 1)'\--configexamples/config.tomlExploration of mean(genotype quality) and mean(depth) on each chromosome for sample 1vcfstats--vcfexamples/sample.vcf\--outdirexamples/\--formula'MEAN(GQs{0}) ~ MEAN(DEPTHs{0}, group=CHROM)'\--title'GQ vs depth (sample 1)'\--configexamples/config.tomlExploration of depths for sample 1,2vcfstats--vcfexamples/sample.vcf\--outdirexamples/\--formula'DEPTHs{0} ~ DEPTHs{1}'\--title'Depths between sample 1 and 2'\--configexamples/config.tomlSee more examples:https://github.com/pwwang/vcfstats/issues/15#issuecomment-1029367903