This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Variant calling by using samtools and bcftools

Hi all

I want to do variant calling by using samtools and bcftools. As the pipelines that I found on the internet, I should run the following commands:

1. samtools view -bS aligned.sam > aligned.bam
2. samtools sort aligned.bam  aligned_sorted
3. samtools faidx genome.fasta
4. samtools mpileup -I -u -f genome.fasta aligned_sorted.bam > pileup.bcf
5. bcftools call -cv pileup.bcf > variant.bcf

In the second command, I face with the following error

[bam_sort] Use -T PREFIX / -o FILE to specify temporary and final output files

and for fixing that I use following command:

samtools sort aligned.bam > aligned_sorted

but I think that it is not right and it disrupts the pipeline. (although the pipeline can runs until end)

And I have another problem. How can I reports the reads Id in the varinat.bcf file?

variant calling samtools bcftools

2 answers

You have to redirect the output of sort to a file, be it either with the -o option or save stdout to disk with >. sort also accepts SAM files so there is no need for the view command. Do either of these two:

samtools sort -o aligned_sorted.bam aligned.sam
samtools sort -O BAM aligned.sam > aligned_sorted.bam
# Indexing Reference Genome
time samtools faidx reference.fa
# Indexing Alignment file(.bam) for variant calling
time samtools index alignment.bam 
# Variant calling using bcftools
# "samtools mpileup" to generate BCF or VCF files is now deprecated, we have to use bcftools
time bcftools mpileup  -f reference.fa alignment.bam | bcftools call -v -m -O z -o variants.vcf.gz

What is the purpose of this post? Is unrelated the the question.

Log in to answer this question.