mopdepth v0.0.0
mopdepth
A fast BAM/CRAM depth calculation tool written in Crystal, inspired by mosdepth.
This is an experiment to see if well-known tools can be ported to Crystal using “vibe coding”.
Features
- Fast depth calculation for BAM/CRAM files
- Multiple processing modes (fast mode, fragment mode, CIGAR-based)
- Per-base and region-based depth analysis
- BED file support for custom regions
- Window-based analysis
- Comprehensive filtering options (MAPQ, fragment length, flags)
Installation
Prerequisites
- Crystal
- hts-lib (for BAM/CRAM support)
Build from source
git clone https://github.com/kojix2/mopdepth
cd mopdepth
shards install
shares build --release
Usage
./mopdepth [options] <prefix> <BAM-or-CRAM>
Basic example
./mopdepth output sample.bam
Options
-t, --threads THREADS: BAM decompression threads-c, --chrom CHROM: Restrict to chromosome-b, --by BY: BED file or numeric window size-n, --no-per-base: Skip per-base output-Q, --mapq MAPQ: MAPQ threshold-l, --min-frag-len MIN: Minimum fragment length-u, --max-frag-len MAX: Maximum fragment length-x, --fast-mode: Fast mode (read start/end positions only)-a, --fragment-mode: Count full fragment (proper pairs only)-m, --use-median: Use median for region stats instead of mean-M, --mos: Use mosdepth-compatible filenames (mosdepth.); default is depth.-v, --version: Show version-h, --help: Show help message
Processing modes
- Default mode: CIGAR-based depth calculation (most accurate)
- Fast mode (
-x): Uses read start/end positions (faster but less accurate) - Fragment mode (
-a): Counts full fragments for paired-end reads
Note: Fast mode and fragment mode cannot be used together.
Output files
- Summary:
<prefix>.(mopdepth|mosdepth).summary.txt - Per-base:
<prefix>.per-base.bed(unless-n) - Global dist:
<prefix>.(mopdepth|mosdepth).global.dist.txt - Regions:
<prefix>.regions.bed(when--by) - Region dist:
<prefix>.(mopdepth|mosdepth).region.dist.txt(when--by)
By default, files are named with the mopdepth.* label. Use -M/--mos to switch to mosdepth.*.
Summary file format
The summary file contains the following columns:
chrom: Chromosome namelength: Chromosome lengthsum_depth: Total depth (sum of all depths)mean: Mean depthmin: Minimum depthmax: Maximum depth
Examples
Basic depth calculation
./mopdepth output sample.bam
With BED regions
./mopdepth -b regions.bed output sample.bam
Window-based analysis (1kb windows)
./mopdepth -b 1000 output sample.bam
Fast mode with MAPQ filtering
./mopdepth -x -Q 20 output sample.bam
Fragment mode for paired-end data
./mopdepth -a -l 100 -u 1000 output sample.bam
License
MIT License
Repository
mopdepth
Owner
Statistic
- 0
- 0
- 2
- 0
- 1
- 4 days ago
- September 5, 2025
License
MIT License
Links
Synced at
Fri, 28 Nov 2025 04:01:29 GMT
Languages