This is a test version of Biostars. For the public version, visit https://www.biostars.org.
0-based coordinates from samtools depth

Hello everyone, is there an option in samtools depth (or any other way) to obtain an output that considers 0-based coordinates? Or do I need to modify my BAM files and subtract 1 from each position? Thank you very much.

samtools coverage depth

1 answer

no tested:

samtools depth in.bam | awk -F '\t' '{OFS="\t";$2=int($2)-1;print;}'

Thank you! What do you mean by 'no tested'? The only thing I don't understand is why Samtools provides a 1-based output when generally a Bam format file uses a 0-based coordinate system? Maybe it depends on the aligner?

What do you mean by 'no tested'?

i did not test my command line. I hope it works.

What do you mean by 'no tested'?

Provided code should logically work but has not actually been tested in practice. You can do that and if something does not work the post back here.

I don't understand is why Samtools provides a 1-based output when generally a Bam format file uses a 0-based coordinate system?

Please see the discussion by developers here: https://github.com/samtools/samtools/issues/1063

Thank you very much for your explanation! It is well explained in the discussion.

Your command works, It starts from chr 0 and shifts the coverage by 1

Please accept the answer so the question is marked solved on the website. To do that, click on the green check mark on the left side of the answer.

Log in to answer this question.