This repository has been archived by the owner. It is now read-only.
moffdepth v0.0.0
# moffdepth モ フ
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/moffdepth
cd moffdepth
shards install
crystal build src/depth.cr --release
Usage
./depth [options] <prefix> <BAM-or-CRAM>
Basic example
./depth 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>.(depth|mosdepth).summary.txt
- Per-base:
<prefix>.per-base.bed
(unless-n
) - Global dist:
<prefix>.(depth|mosdepth).global.dist.txt
- Regions:
<prefix>.regions.bed
(when--by
) - Region dist:
<prefix>.(depth|mosdepth).region.dist.txt
(when--by
)
By default, files are named with the depth.*
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
./depth output sample.bam
With BED regions
./depth -b regions.bed output sample.bam
Window-based analysis (1kb windows)
./depth -b 1000 output sample.bam
Fast mode with MAPQ filtering
./depth -x -Q 20 output sample.bam
Fragment mode for paired-end data
./depth -a -l 100 -u 1000 output sample.bam
License
MIT License
Repository
moffdepth
Owner
Statistic
- 0
- 0
- 0
- 0
- 1
- 4 days ago
- August 31, 2025
License
MIT License
Links
Synced at
Mon, 08 Sep 2025 09:46:53 GMT
Languages