0-based coordinates from samtools depth
1
0
Entering edit mode
4 weeks ago
marco.barr ▴ 80

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 • 402 views
ADD COMMENT
1
Entering edit mode
4 weeks ago

no tested:

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

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?

ADD REPLY
0
Entering edit mode

What do you mean by 'no tested'?

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

SAM is 1 based https://samtools.github.io/hts-specs/SAMv1.pdf

1-based leftmost mapping POSition

BAM is ALWAYS 0 based. you don't look at the values in a BAM unless you're a programmer.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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.

ADD REPLY

Login before adding your answer.

Traffic: 1667 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6