How mosdepth calculates coverage
masterAlgorithm
mosdepth calculates depth by creating an array for each chromosome. For every read start encountered, it increments the value at that position; for every stop, it decrements it. The depth at any position is the cumulative sum of all preceding array positions.
Key characteristics:
- Accuracy: It avoids double-counting overlapping mate-pairs and tracks every aligned part of every read using CIGAR operations.
- Performance: It is generally faster than
samtools depthbecause it avoids the per-base pileup machinery. It is highly efficient for window-based or BED-based regional queries. - Memory Usage: It uses more memory than
samtools. Memory consumption is approximately32-bits * longest chromosome length(e.g., ~1GB for Chromosome 1).