However, more desirable solution would avoid using -s option.
I would like to extract VCF subset with only those variants that are present in one particular sample. E.g. i have three sample VCF with ten variants. Only one variant has been detected in the first sample, so i would like to subset VCF so that only this variant is kept. Pseudo code would be something like:
bcftools query -f'%CHROM:%POS %INFO [%GT]\n' -i'GT="alt in sample1"' file.vcf
The desired output is VCF with three samples but only variants present in one of the samples, in this case sample1
3 answers
Alternative solution is to use bcftools +split plugin, e.g.:
bcftools +split file.vcf -Ob -o testDir -i'GT="alt"'
using vcffilterjdk http://lindenb.github.io/jvarkit/VcfFilterJdk.html
java -jar dist/vcffilterjdk.jar -e 'String sample="S1"; final Genotype g=variant.getGenotype(sample);if(g.isHomRef() || g.isNoCall()) return false; return variant.getGenotypes().stream().filter(G->G.getSampleName().equals(sample)==false).allMatch(G->G.isNoCall() || G.isHomRef());' in.vcf
The solution is to add -s option, e.g.:
bcftools query -f'%CHROM:%POS \n' -s sample1 -i'GT="alt"'
How so? That is a valid option for the command and how it is meant to used.
-s, --samples LIST List of samples to include
-S, --samples-file FILE File of samples to include
Because many plugins does not support -s option, more specifically it's not present in +split-vep
Log in to answer this question.