jvarkit

DownSampleVcf

Last commit

DownSample a VCF. Will keep ā€˜nā€™ random variants in a vcf.

Usage

Usage: downsamplevcf [options] Files
  Options:
    -h, --help
      print help and exit
    --helpFormat
      What kind of help. One of [usage,markdown,xml].
    -o, --output
      Output file. Optional . Default: stdout
    --version
      print version and exit
    -N
      random seed. -1==use current time
      Default: -1
    -n
      output size. keep 'n' random variants in the input vcf
      Default: 10

Keywords

See also in Biostars

Compilation

Requirements / Dependencies

Download and Compile

$ git clone "https://github.com/lindenb/jvarkit.git"
$ cd jvarkit
$ ./gradlew downsamplevcf

The java jar file will be installed in the dist directory.

Creation Date

20131210

Source code

https://github.com/lindenb/jvarkit/tree/master/src/main/java/com/github/lindenb/jvarkit/tools/misc/DownSampleVcf.java

Unit Tests

https://github.com/lindenb/jvarkit/tree/master/src/test/java/com/github/lindenb/jvarkit/tools/misc/DownSampleVcfTest.java

Contribute

License

The project is licensed under the MIT license.

Citing

Should you cite downsamplevcf ? https://github.com/mr-c/shouldacite/blob/master/should-I-cite-this-software.md

The current reference is:

http://dx.doi.org/10.6084/m9.figshare.1425030

Lindenbaum, Pierre (2015): JVarkit: java-based utilities for Bioinformatics. figshare. http://dx.doi.org/10.6084/m9.figshare.1425030

How about bcftools ?

bcftools view --header-only  input.vcf > subsample.vcf
bcftools view --no-header input.vcf | awk '{printf("%f\t%s\n",rand(),$0);}' | sort -t $'\t' -k1,1g | cut -f2-  | head -n 1000 >>  subsample.vcf

Example

$ curl -skL "ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/release/20130502/ALL.wgs.phase3_shapeit2_mvncall_integrated_v5a.20130502.sites.vcf.gz" |\
  gunzip -c |\
java -jar dist/downsamplevcf.jar -n 100 > output.vcf