This is a test version of Biostars. For the public version, visit https://www.biostars.org.
automatically create index files from output in bcftools

say i am running a command in bcftools like

/share/apps/genomics/bcftools-1.9/bin/bcftools view -O b -o $x.multiallelicIndelsRemoved.1240positions.vcf.bgz -R $variants --exclude-types indels $sample

Rather than then having to run a separate command on the output file to produce an index file:

/share/apps/genomics/bcftools-1.9/bin/bcftools index $x.multiallelicIndelsRemoved.1240positions.vcf.bgz

Is there a option that I can use in the first command which will automatically produce an index for the output file? I'm sure there must be, but I couldn't find it in the documentation.

Thanks.

software error

If there is an other command called bcftools index why would you want to use an option to index your file in bcftools view ?

If you want a single command line to do both you can :

/share/apps/genomics/bcftools-1.9/bin/bcftools view -O b -o $x.multiallelicIndelsRemoved.1240positions.vcf.bgz -R $variants --exclude-types indels $sample && /share/apps/genomics/bcftools-1.9/bin/bcftools index $x.multiallelicIndelsRemoved.1240positions.vcf.bgz

Do you want to keep the $x.multiallelicIndelsRemoved.1240positions.vcf.bgz file ?

1 answer

I think that you need to clear up what your file extensions mean.

With your first command, you have specified:

-O b -o $x.multiallelicIndelsRemoved.1240positions.vcf.bgz

-O b does not output a bgzipped VCF file, as your output filename ($x.multiallelicIndelsRemoved.1240positions.vcf.bgz) is implying. -O b outputs a compressed BCF, so, your output file should have the BCF extension.

After you output BCF, you simply index it with bcftools index

Take a closer look at the command line options for the commands that you aim to use.

Kevin

Log in to answer this question.