<p>You would want to instead use the <code>-a</code> option with <code>bwa mem</code> to output all alignments. You would be best off filtering these with a custom script to only keep those with a close enough score to the primary hit. <code>samtools depth</code> can't be told to include secondary alignments (<a href="https://github.com/samtools/samtools/blob/ffdddb6927827d805c603993cbc07a6faa9a63a6/bam2depth.c#L65" rel="nofollow noreferrer">it's hard-coded</a>), so you'll need to use something else like <code>bamCoverage</code> or <code>samtools mpileup</code>.</p>

CC BY-SA 4.0
2019-09-10T09:56:57.483Z
2019-09-10T09:56:57.483Z
Devon Ryan
<p>when mapping short reads with bwa mem, if a read has alternative mapping positions they are reported by bwa mem in the X0 and XA tags. 
Now, let's say I want to compute the coverage of my bam file. How would I do for the alternative hits to be taken into accounts. What I mean is that, if a read QUERY has a selected best HIT position and 3 alternate HIT positions, I would like that QUERY read to be counted as 1 unit of coverage for the best HIT position, but also as 1 unit of coverage for each of the alternate HIT position. </p>

<p>My understanding is that samtools depth will only consider the best hit (which makes sense in 99.99% of the cases). </p>

<p>I guess I could edit the bam file with custom scripts so that the alternative hits are also reported as primary hits but I was wondering if there was an already existing tool (as I am not that confident with my ability to mess around with sam files). </p>

<p>Thanks a lot.</p>

<samtools><bwa><coverage>
How to take into account alternative bwa mem mapping when computing coverage
# How to take into account alternative bwa mem mapping when computing coverage

(Asked by: username_0 on 2019-09-09)

when mapping short reads with bwa mem, if a read has alternative mapping positions they are reported by bwa mem in the X0 and XA tags.
Now, let's say I want to compute the coverage of my bam file. How would I do for the alternative hits to be taken into accounts. What I mean is that, if a read QUERY has a selected best HIT position and 3 alternate HIT positions, I would like that QUERY read to be counted as 1 unit of coverage for the best HIT position, but also as 1 unit of coverage for each of the alternate HIT position.

My understanding is that samtools depth will only consider the best hit (which makes sense in 99.99% of the cases).

I guess I could edit the bam file with custom scripts so that the alternative hits are also reported as primary hits but I was wondering if there was an already existing tool (as I am not that confident with my ability to mess around with sam files).

Thanks a lot.

**Tags:** samtools, bwa, coverage

---

## 1 answers

### Answer by username_1 on 2019-09-10. Score: 1

You would want to instead use the `-a` option with `bwa mem` to output all alignments. You would be best off filtering these with a custom script to only keep those with a close enough score to the primary hit. `samtools depth` can't be told to include secondary alignments ([it's hard-coded](https://github.com/samtools/samtools/blob/ffdddb6927827d805c603993cbc07a6faa9a63a6/bam2depth.c#L65)), so you'll need to use something else like `bamCoverage` or `samtools mpileup`.


---

