You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+98-73Lines changed: 98 additions & 73 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,40 +6,33 @@
6
6
7
7
# jam-rs
8
8
9
-
Just another minhash (jam) implementation. A high-performance minhashing tool for genomic sequence similarity analysis, specifically optimized for plasmidsand other small genomic elements.
9
+
Just another minhash (jam). A high-performance FracMinHash implementation for genomic sequence similarity analysis, optimized for searching plasmids, phages, and other small genomic elements in large datasets.
10
10
11
-
Implements the FracMinHash algorithm for rapid similarity comparisons with enhanced metadata tracking including GC content and sequence length categories tuned for typical plasmid ranges.
11
+
jam uses a custom hash function ([jamhash](https://github.com/St4NNi/jamhash)) that provides lower collision rates, 2-10x higher speed and better uniformity than murmur3. It also includes a compact memory-mapped database format (`.jam`) for fast random access, and a bias filtering system based on Count-Min Sketches to selectively increase sensitivity for target sequences.
12
12
13
13
### Installation
14
14
15
-
Install the latest release from [crates.io](https://crates.io/):
15
+
From [crates.io](https://crates.io/crates/jam-rs):
-**Plasmid-optimized**: GC content and length categories specifically tuned for plasmid analysis (30-70% GC, 1kB-500kB lengths)
30
-
-**Fast sketching**: Entropy-filtered k-mers with optimized hash functions to exclude low-complexity regions
31
-
-**Rich metadata**: Enhanced metadata tracking with file index, GC category, and length category for each hash
29
+
-**Custom hash function**: [jamhash](https://github.com/St4NNi/jamhash) provides lower collisions, better uniformity and is faster compared to murmur3
30
+
-**Bias-aware sketching**: Count-Min Sketch based compositional filtering with automatic background extraction
31
+
-**Complexity filtering**: Shannon entropy threshold to exclude low-complexity k-mers
32
32
-**Memory-efficient**: External sorting for processing datasets larger than available RAM
33
-
-**LMDB storage**: Fast random access and compact representation with dual database structure
34
-
-**Parallel execution**: File-level parallelization with configurable thread count
35
-
36
-
### Scaling Methods
37
-
38
-
Multiple scaling methods for different use cases:
39
-
-**FracMinHash** (`--fscale`): Restricts hash-space to a fraction of `u64::MAX` / `fscale`
40
-
-**Max hashes** (`--nmax`): Limits maximum number of hashes per sequence (memory control)
41
-
-**Complexity filtering** (`--complexity`): Only hash sequences with Shannon entropy above threshold (default: 0.0)
42
-
-**Singleton mode** (`--singleton`): Creates separate sketch per sequence record
33
+
-**Compact storage**: 256-bucket memory-mapped `.jam` format with binary fuse filters for fast random access
34
+
-**Parallel execution**: File-level parallelization via rayon with configurable thread count
35
+
-**Tuned for speed**: jemalloc allocator, LTO, single codegen unit, `opt-level = 3`
43
36
44
37
### Usage
45
38
@@ -51,21 +44,23 @@ Usage: jam [OPTIONS] <COMMAND>
51
44
52
45
Commands:
53
46
sketch Sketch one or more files and write the result to an output file
54
-
dist Estimate containment of a (small) sketch against a subset of one or more sketches as database. Requires all sketches to have the same kmer size
55
-
stats Display statistics about an LMDB database
47
+
dist Estimate containment of a query sequence against a sketch database
48
+
bias Build and analyze hash bias tables for filtering
49
+
stats Display statistics about a JAM database
56
50
help Print this message or the help of the given subcommand(s)
57
51
58
52
Options:
59
53
-t, --threads <THREADS> Number of threads to use [default: 1]
60
54
-f, --force Overwrite output files
61
-
-s, --silent Silent mode, no (additional) output to stdout Only errors and output files will be printed
55
+
-s, --silent Silent mode, no (additional) output to stdout
56
+
-m, --memory <MEMORY> Maximum memory usage in GB [default: 2]
62
57
-h, --help Print help
63
58
-V, --version Print version
64
59
```
65
60
66
61
#### Sketching
67
62
68
-
Create sketches from FASTA/FASTQ files. Supports single files, multiple files, or directories.
63
+
Create `.jam` databases from FASTA/FASTQ files (plain or gzip/bzip2/xz/zstd compressed). Supports single files, multiple files, or directories.
69
64
70
65
```console
71
66
$ jam sketch --help
@@ -77,104 +72,134 @@ Arguments:
77
72
[INPUT]... Input file(s), directories, or file with list of files to be hashed
78
73
79
74
Options:
80
-
-o, --output <OUTPUT> Output file (.lmdb will be appended if not present)
75
+
-o, --output <OUTPUT> Output file (.jam format)
81
76
-k, --kmer-size <KMER_SIZE> K-mer size, all sketches must have the same size to be compared and below 32 [default: 21]
82
77
--fscale <FSCALE> Scale the hash space to a minimum fraction of the maximum hash value (FracMinHash)
83
-
--nmax <NMAX> Maximum number of k-mers (per record) to be hashed, top cut-off
84
-
--complexity <COMPLEXITY> Complexity cut-off, only hash sequences with complexity above this value This is created via shannon entropy [default: 0.0]
85
-
--singleton Create a separate sketch for each sequence record Will increase the size of the output file
86
-
-t, --threads <THREADS> Number of threads to use [default: 1]
87
-
-f, --force Overwrite output files
78
+
--complexity <COMPLEXITY> Complexity cut-off, only hash sequences with complexity above this value [default: 0.0]
79
+
--singleton Create a separate sketch for each sequence record
80
+
--temp-dir <TEMP_DIR> Custom temporary directory for intermediate files during sorting
81
+
--bias-table <BIAS_TABLE> Path to a bias table file (.bias) for compositional filtering
88
82
-h, --help Print help
89
83
```
90
84
91
85
Examples:
92
86
```bash
93
-
#Basic plasmid sketching
94
-
jam sketch plasmid.fasta -o sketch.lmdb
87
+
#Sketch a single file
88
+
jam sketch input.fasta -o sketch.jam
95
89
96
-
#Multiple plasmid files with custom k-mer size
97
-
jam sketch plasmids/ -o plasmid_db.lmdb -k 21 -t 8
90
+
#Sketch a directory with 8 threads and FracMinHash scaling
91
+
jam sketch genomes/ -o db.jam --fscale 1000 -t 8
98
92
99
-
#Large collections with memory limits and complexity filtering
-o, --output <OUTPUT> Output to file instead of stdout
120
117
-c, --cutoff <CUTOFF> Cut-off value for similarity/containment [default: 0.0]
121
-
--singleton Singleton mode, process each query sequence separately
122
-
-t, --threads <THREADS> Number of threads to use [default: 1]
123
-
-f, --force Overwrite output files
118
+
--singleton Singleton mode, process each query sequence separately
124
119
-h, --help Print help
125
120
```
126
121
127
122
Examples:
128
123
```bash
129
-
# Query plasmid against database
130
-
jam dist -i query_plasmid.fasta -d plasmid_db.lmdb -c 0.1 -o results.tsv
131
-
132
-
# Sketch-to-sketch comparison
133
-
jam dist -i query.lmdb -d plasmid_db.lmdb -c 0.05
124
+
# Query against a database with a containment cutoff
125
+
jam dist -i query.fasta -d db.jam -c 0.1 -o results.tsv
134
126
135
-
#Process each sequence separately with singleton mode
136
-
jam dist -i multi_query.fasta -d plasmid_db.lmdb --singleton -c 0.1
127
+
#Per-sequence queries
128
+
jam dist -i multi_query.fasta -d db.jam --singleton -c 0.1
137
129
```
138
130
139
-
#### Statistics
131
+
Output is tab-separated: `query`, `sample_id`, `hit_count`, `containment`.
140
132
141
-
Display database statistics including hash counts and distribution analysis.
133
+
#### Bias Table Construction
134
+
135
+
Bias tables allow compositional filtering to increase sensitivity for target sequences while suppressing background noise. They work by scoring k-mers based on their enrichment in a positive (target) set relative to a negative (background) set.
136
+
137
+
The underlying data structure is a **Count-Min Sketch (CMS)**, a probabilistic structure that approximates k-mer frequencies using multiple independent hash functions mapped to a fixed-width table. This keeps memory usage constant regardless of the number of distinct k-mers. By default, the CMS uses 1,048,576 columns and 5 hash functions (~5 MB).
138
+
139
+
**How it works:**
140
+
141
+
1. K-mer frequencies from both the positive and negative input sets are counted into separate CMS tables.
142
+
2.**Background extraction**: The positive counts are subtracted from the negative counts (floored at zero). This prevents k-mers naturally shared between target and background from being penalized.
143
+
3. A log-ratio weight is computed per CMS cell: `log((pos + alpha) / (adjusted_neg + alpha))`, where `alpha` is a smoothing parameter.
144
+
4. Weights are quantized to `i8` (-127 to +127) for compact storage.
145
+
5.**Threshold calibration**: All 255 possible thresholds are evaluated. The threshold that maximizes fold enrichment (positive retention / negative retention) is selected. If a target fold enrichment is specified, the closest achievable threshold is used instead.
142
146
143
147
```console
144
-
$ jam stats --help
145
-
Display statistics about an LMDB database
148
+
$ jam bias create --help
149
+
Create a bias table from positive (target) and negative (background) FASTA files.
150
+
Target signal is always subtracted from background before computing bias weights.
Display database statistics including hash counts and distribution analysis.
184
+
185
+
```console
186
+
$ jam stats --help
187
+
Display statistics about a JAM database
172
188
173
-
Statistics include hash counts, GC content distribution, and sequence length categories optimized for plasmids and small genomic elements.
189
+
Usage: jam stats [OPTIONS] --input <INPUT>
174
190
175
-
### Algorithm
191
+
Options:
192
+
-i, --input <INPUT> Input JAM database (.jam file)
193
+
--short Short summary only
194
+
--full Include the full entry statistics
195
+
-h, --help Print help
196
+
```
176
197
177
-
JAM uses entropy-filtered k-mers to exclude low-complexity regions, stores rich metadata (file index, GC category, length category) with each hash, and employs external sorting for memory-efficient processing of large datasets. The categorization system is specifically tuned for plasmid analysis, with fine-grained bins in typical plasmid size and GC content ranges.
198
+
Examples:
199
+
```bash
200
+
jam stats -i db.jam --short
201
+
jam stats -i db.jam --full
202
+
```
178
203
179
204
### License
180
205
@@ -186,4 +211,4 @@ If you have any ideas, suggestions, or issues, please don't hesitate to open an
186
211
187
212
### Credits
188
213
189
-
This tool is inspired by [finch-rs](https://github.com/onecodex/finch-rs) and [sourmash](https://github.com/sourmash-bio/sourmash). Check them out if you need a more mature ecosystem with well tested hash functions and more features.
214
+
This tool is inspired by [finch-rs](https://github.com/onecodex/finch-rs) and [sourmash](https://github.com/sourmash-bio/sourmash). Check them out if you need a more mature ecosystem.
0 commit comments