In addition to the answer from @gringer there is a bcftoolsplugin called split that can do this, but gives you the added ability to output single-sample VCFs by specifying a filename for each sample.
$ bcftools +split
About: Split VCF by sample, creating single-sample VCFs.
Usage: bcftools +split [Options]
Plugin options:
-e, --exclude EXPR exclude sites for which the expression is true (applied on the outputs)
-i, --include EXPR include only sites for which the expression is true (applied on the outputs)
-k, --keep-tags LIST list of tags to keep. By default all tags are preserved
-o, --output DIR write output to the directory DIR
-O, --output-type b|u|z|v b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]
-r, --regions REGION restrict to comma-separated list of regions
-R, --regions-file FILE restrict to regions listed in a file
-S, --samples-file FILE list of samples to keep with second (optional) column for basename of the new file
-t, --targets REGION similar to -r but streams rather than index-jumps
-T, --targets-file FILE similar to -R but streams rather than index-jumps
Examples:
# Split a VCF file
bcftools +split input.bcf -Ob -o dir
# Exclude sites with missing or hom-ref genotypes
bcftools +split input.bcf -Ob -o dir -i'GT="alt"'
# Keep all INFO tags but only GT and PL in FORMAT
bcftools +split input.bcf -Ob -o dir -k INFO,FMT/GT,PL
# Keep all FORMAT tags but drop all INFO tags
bcftools +split input.bcf -Ob -o dir -k FMT
So if you had the following samples file samples.tsv
In addition to the answer from @gringer there is a bcftoolsplugin called split that can do this, but gives you the added ability to output single-sample VCFs by specifying a filename for each sample.
$ bcftools +splitAbout: Split VCF by sample, creating single-sample VCFs.Usage: bcftools +split [Options]Plugin options: -e, --exclude EXPR exclude sites for which the expression is true (applied on the outputs) -i, --include EXPR include only sites for which the expression is true (applied on the outputs) -k, --keep-tags LIST list of tags to keep. By default all tags are preserved -o, --output DIR write output to the directory DIR -O, --output-type b|u|z|v b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v] -r, --regions REGION restrict to comma-separated list of regions -R, --regions-file FILE restrict to regions listed in a file -S, --samples-file FILE list of samples to keep with second (optional) column for basename of the new file -t, --targets REGION similar to -r but streams rather than index-jumps -T, --targets-file FILE similar to -R but streams rather than index-jumpsExamples: # Split a VCF file bcftools +split input.bcf -Ob -o dir # Exclude sites with missing or hom-ref genotypes bcftools +split input.bcf -Ob -o dir -i'GT="alt"' # Keep all INFO tags but only GT and PL in FORMAT bcftools +split input.bcf -Ob -o dir -k INFO,FMT/GT,PL # Keep all FORMAT tags but drop all INFO tags bcftools +split input.bcf -Ob -o dir -k FMT
So if you had the following samples file samples.tsv
Bcftools has sample/individual filtering as an option for most of the commands. You can subset individuals by using the -s or -S option:
-s, --samples [^]LIST
Comma-separated list of samples to include or exclude if prefixed with "^". Note that in general tags such as INFO/AC, INFO/AN, etc are not updated to correspond to the subset samples. bcftools view is the exception where some
tags will be updated (unless the -I, --no-update option is used; see bcftools view documentation). To use updated tags for the subset in another command one can pipe from view into that command. For example:
-S, --samples-file FILE
File of sample names to include or exclude if prefixed with "^". One sample per line. See also the note above for the -s, --samples option. The command bcftools call accepts an optional second column indicating ploidy (0, 1 or 2) or sex (as defined by --ploidy, for example "F" or "M"), and can parse also PED files. If the second column is not present, the sex "F" is assumed. With bcftools call -C trio, PED file is expected. File formats examples:
sample1 1
sample2 2
sample3 2
or
sample1 M
sample2 F
sample3 F
or a .ped file (here is shown a minimum working example, the first column is ignored and the last indicates sex: 1=male, 2=female):
Bcftools has sample/individual filtering as an option for most of the commands. You can subset individuals by using the -s or -S option:
-s, --samples [^]LIST
Comma-separated list of samples to include or exclude if prefixed with "^". Note that in general tags such as INFO/AC, INFO/AN, etc are not updated to correspond to the subset samples. bcftools view is the exception where some tags will be updated (unless the -I, --no-update option is used; see bcftools view documentation). To use updated tags for the subset in another command one can pipe from view into that command. For example:
-S, --samples-file FILE
File of sample names to include or exclude if prefixed with "^". One sample per line. See also the note above for the -s, --samples option. The command bcftools call accepts an optional second column indicating ploidy (0, 1 or 2) or sex (as defined by --ploidy, for example "F" or "M"), and can parse also PED files. If the second column is not present, the sex "F" is assumed. With bcftools call -C trio, PED file is expected. File formats examples:
sample1 1sample2 2sample3 2
or
sample1 Msample2 Fsample3 F
or a .ped file (here is shown a minimum working example, the first column is ignored and the last indicates sex: 1=male, 2=female):
You can use the GATK's SelectVariants tool with the
-snflag.E.g.
gatk SelectVariants -V input.vcf -R reference.fasta -sn Sample_01 -out sample.vcfYou may use the
-snflag several times so as to select several samples, or use it to point to a file containing a sample name on every line.You can use the GATK's SelectVariants tool with the
-snflag.E.g.
gatk SelectVariants -V input.vcf -R reference.fasta -sn Sample_01 -out sample.vcfYou may use the
-snflag several times so as to select several samples, or use it to point to a file containing a sample name on every line.More
VOTE
In addition to the answer from @gringer there is a
bcftoolsplugin calledsplitthat can do this, but gives you the added ability to output single-sample VCFs by specifying a filename for each sample.So if you had the following samples file
samples.tsvYou can run it and get the following
Without the second column, you would just get a single VCF with the two samples in it (as you would with
view)In addition to the answer from @gringer there is a
bcftoolsplugin calledsplitthat can do this, but gives you the added ability to output single-sample VCFs by specifying a filename for each sample.So if you had the following samples file
samples.tsvYou can run it and get the following
Without the second column, you would just get a single VCF with the two samples in it (as you would with
view)More
VOTE
Bcftools has sample/individual filtering as an option for most of the commands. You can subset individuals by using the
-sor-Soption:Example usage:
See the bcftools manpage for more information.
Bcftools has sample/individual filtering as an option for most of the commands. You can subset individuals by using the
-sor-Soption:Example usage:
See the bcftools manpage for more information.
More
VOTE