{"id":40950252,"url":"https://github.com/suchapalaver/kmerust","last_synced_at":"2026-02-18T00:17:50.669Z","repository":{"id":38019094,"uuid":"403723873","full_name":"suchapalaver/kmerust","owner":"suchapalaver","description":"Bioinformatics 101 tool for counting unique k-length substrings in DNA","archived":false,"fork":false,"pushed_at":"2026-01-27T20:57:24.000Z","size":24429,"stargazers_count":33,"open_issues_count":0,"forks_count":4,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-28T08:54:14.649Z","etag":null,"topics":["beginner-friendly","bioinformatics","bioinformatics-tool","bitpacking","bytes","clap","dashmap","genomics","insta","k-mer","k-mer-counting","k-mers","kmer","kmer-counting","kmers","needletail","parallelization","rayon","rust","rust-bio"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/suchapalaver.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-09-06T18:32:57.000Z","updated_at":"2026-01-27T20:54:23.000Z","dependencies_parsed_at":"2024-10-28T11:28:32.835Z","dependency_job_id":"439ef43b-287a-4828-9e6d-b237cde2350b","html_url":"https://github.com/suchapalaver/kmerust","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/suchapalaver/kmerust","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suchapalaver%2Fkmerust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suchapalaver%2Fkmerust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suchapalaver%2Fkmerust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suchapalaver%2Fkmerust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/suchapalaver","download_url":"https://codeload.github.com/suchapalaver/kmerust/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suchapalaver%2Fkmerust/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29563461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T21:50:49.831Z","status":"ssl_error","status_checked_at":"2026-02-17T21:46:15.313Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beginner-friendly","bioinformatics","bioinformatics-tool","bitpacking","bytes","clap","dashmap","genomics","insta","k-mer","k-mer-counting","k-mers","kmer","kmer-counting","kmers","needletail","parallelization","rayon","rust","rust-bio"],"created_at":"2026-01-22T05:10:51.573Z","updated_at":"2026-02-18T00:17:50.661Z","avatar_url":"https://github.com/suchapalaver.png","language":"Rust","readme":"# kmerust\n\n[![Crates.io](https://img.shields.io/crates/v/kmerust.svg)](https://crates.io/crates/kmerust)\n[![Documentation](https://docs.rs/kmerust/badge.svg)](https://docs.rs/kmerust)\n[![CI](https://github.com/suchapalaver/kmerust/workflows/CI/badge.svg)](https://github.com/suchapalaver/kmerust/actions)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nA fast, parallel [k-mer](https://en.wikipedia.org/wiki/K-mer) counter for DNA sequences in FASTA and FASTQ files.\n\n## Features\n\n- **Fast parallel processing** using [rayon](https://docs.rs/rayon) and [dashmap](https://docs.rs/dashmap)\n- **FASTA and FASTQ support** with automatic format detection from file extension\n- **Canonical k-mers** - outputs the lexicographically smaller of each k-mer and its reverse complement\n- **Flexible k-mer lengths** from 1 to 32\n- **Handles N bases** by skipping invalid k-mers\n- **Jellyfish-compatible output** format for easy integration with existing pipelines\n- **Tested for accuracy** against [Jellyfish](https://github.com/gmarcais/Jellyfish)\n\n## Installation\n\n### From crates.io\n\n```bash\ncargo install kmerust\n```\n\n### From source\n\n```bash\ngit clone https://github.com/suchapalaver/kmerust.git\ncd kmerust\ncargo install --path .\n```\n\n## Usage\n\n```bash\nkmerust \u003ck\u003e \u003cpath\u003e\n```\n\n### Arguments\n\n- `\u003ck\u003e` - K-mer length (1-32)\n- `\u003cpath\u003e` - Path to a FASTA or FASTQ file (use `-` or omit for stdin)\n\n### Options\n\n- `-f, --format \u003cFORMAT\u003e` - Output format: `fasta` (default), `tsv`, `json`, or `histogram`\n- `-i, --input-format \u003cFORMAT\u003e` - Input format: `auto` (default), `fasta`, or `fastq`\n- `-m, --min-count \u003cN\u003e` - Minimum count threshold (default: 1)\n- `-Q, --min-quality \u003cN\u003e` - Minimum Phred quality score for FASTQ (0-93); bases below this are skipped\n- `--save \u003cPATH\u003e` - Save k-mer counts to a binary index file for fast querying\n- `-q, --quiet` - Suppress informational output\n- `-h, --help` - Print help information\n- `-V, --version` - Print version information\n\n### Examples\n\nCount 21-mers in a FASTA file:\n\n```bash\nkmerust 21 sequences.fa \u003e kmers.txt\n```\n\nCount 21-mers in a FASTQ file (format auto-detected):\n\n```bash\nkmerust 21 reads.fq \u003e kmers.txt\n```\n\nCount 5-mers:\n\n```bash\nkmerust 5 sequences.fa \u003e kmers.txt\n```\n\n### Unix Pipeline Integration\n\nkmerust supports reading from stdin, enabling seamless integration with Unix pipelines:\n\n```bash\n# Pipe from another command\ncat genome.fa | kmerust 21\n\n# Decompress and count\nzcat large.fa.gz | kmerust 21 \u003e counts.tsv\n\n# Sample reads and count\nseqtk sample reads.fa 0.1 | kmerust 17\n\n# Explicit stdin marker\ncat genome.fa | kmerust 21 -\n\n# FASTQ from stdin (specify format explicitly)\ncat reads.fq | kmerust 21 --input-format fastq\nzcat reads.fq.gz | kmerust 21 -i fastq \u003e counts.tsv\n```\n\n### Output Formats\n\nUse `--format` to choose the output format:\n\n```bash\n# TSV format (tab-separated)\nkmerust 21 sequences.fa --format tsv\n\n# JSON format\nkmerust 21 sequences.fa --format json\n\n# FASTA-like format (default)\nkmerust 21 sequences.fa --format fasta\n\n# Histogram format (k-mer frequency spectrum)\nkmerust 21 sequences.fa --format histogram\n```\n\n### Histogram Output\n\nThe histogram format outputs the k-mer frequency spectrum (count of counts), useful for genome size estimation and error detection:\n\n```bash\nkmerust 21 genome.fa --format histogram \u003e spectrum.tsv\n```\n\nOutput is tab-separated with columns `count` and `frequency`:\n\n```\n1       1523456    # 1.5M k-mers appear exactly once (likely errors)\n2       234567     # 234K k-mers appear twice\n10      45678      # 45K k-mers appear 10 times\n...\n```\n\n### Quality Filtering (FASTQ)\n\nFor FASTQ files, use `--min-quality` to filter out k-mers containing low-quality bases:\n\n```bash\n# Skip k-mers with any base below Q20\nkmerust 21 reads.fq --min-quality 20\n\n# Higher threshold for stricter filtering\nkmerust 21 reads.fq -Q 30 --format tsv\n```\n\nK-mers containing bases with Phred quality scores below the threshold are skipped entirely.\n\n### Index Serialization\n\nFor large genomes, save k-mer counts to a binary index file to avoid re-counting:\n\n```bash\n# Count and save to index\nkmerust 21 genome.fa --save counts.kmix\n\n# Counts are also written to stdout as usual\nkmerust 21 genome.fa --save counts.kmix \u003e counts.tsv\n```\n\nThe index file uses a compact binary format with CRC32 checksums for integrity verification. Gzip compression is auto-detected from the `.gz` extension:\n\n```bash\n# Save with gzip compression\nkmerust 21 genome.fa --save counts.kmix.gz\n```\n\n### Querying a Saved Index\n\nUse the `query` subcommand to look up k-mer counts from a saved index:\n\n```bash\n# Query a single k-mer\nkmerust query counts.kmix ACGTACGTACGTACGTACGTA\n# Output: 42 (or 0 if not found)\n\n# Queries are case-insensitive and canonicalized\nkmerust query counts.kmix acgtacgtacgtacgtacgta  # Same result\nkmerust query counts.kmix TGTACGTACGTACGTACGTAC  # Reverse complement, same result\n```\n\nThe query k-mer length must match the index's k value.\n\n### Sequence Readers\n\nkmerust supports two sequence readers via feature flags, both supporting FASTA and FASTQ:\n\n- `rust-bio` (default) - Uses the [rust-bio](https://docs.rs/bio) library\n- `needletail` - Uses the [needletail](https://docs.rs/needletail) library\n\nTo use needletail instead:\n\n```bash\ncargo run --release --no-default-features --features needletail -- 21 sequences.fa\n```\n\nWith needletail, format is auto-detected from file content. With rust-bio, format is detected from file extension (`.fa`, `.fasta`, `.fna` for FASTA; `.fq`, `.fastq` for FASTQ).\n\n### Production Features\n\nEnable production features for additional capabilities:\n\n```bash\ncargo build --release --features production\n```\n\nOr enable individual features:\n\n- `gzip` - Read gzip-compressed FASTA files (`.fa.gz`)\n- `mmap` - Memory-mapped I/O for large files\n- `tracing` - Structured logging and diagnostics\n\n#### Gzip Compressed Input\n\nWith the `gzip` feature, kmerust can directly read gzip-compressed files:\n\n```bash\ncargo run --release --features gzip -- 21 sequences.fa.gz\n```\n\n#### Tracing/Logging\n\nWith the `tracing` feature, use the `RUST_LOG` environment variable for diagnostic output:\n\n```bash\nRUST_LOG=kmerust=debug cargo run --features tracing -- 21 sequences.fa\n```\n\n## Output Format\n\nOutput is written to stdout in FASTA-like format:\n\n```\n\u003e{count}\n{canonical_kmer}\n```\n\nExample output:\n\n```\n\u003e114928\nATGCC\n\u003e289495\nAATCA\n```\n\n## Library Usage\n\nkmerust can also be used as a library:\n\n```rust\nuse kmerust::run::count_kmers;\nuse std::path::PathBuf;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    // Works with both FASTA and FASTQ (format auto-detected)\n    let path = PathBuf::from(\"sequences.fa\");\n    let counts = count_kmers(\u0026path, 21)?;\n    for (kmer, count) in counts {\n        println!(\"{kmer}: {count}\");\n    }\n    Ok(())\n}\n```\n\n### Explicit Format Selection\n\nWhen using the builder API, you can explicitly specify the input format:\n\n```rust\nuse kmerust::builder::KmerCounter;\nuse kmerust::format::SequenceFormat;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let counts = KmerCounter::new()\n        .k(21)?\n        .input_format(SequenceFormat::Fastq)\n        .count(\"reads.fq\")?;\n    Ok(())\n}\n```\n\n### Progress Reporting\n\nMonitor progress during long-running operations:\n\n```rust\nuse kmerust::run::count_kmers_with_progress;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let counts = count_kmers_with_progress(\"genome.fa\", 21, |progress| {\n        eprintln!(\n            \"Processed {} sequences ({} bases)\",\n            progress.sequences_processed,\n            progress.bases_processed\n        );\n    })?;\n    Ok(())\n}\n```\n\n### Memory-Mapped I/O\n\nFor large files, use memory-mapped I/O (requires `mmap` feature):\n\n```rust\nuse kmerust::run::count_kmers_mmap;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let counts = count_kmers_mmap(\"large_genome.fa\", 21)?;\n    println!(\"Found {} unique k-mers\", counts.len());\n    Ok(())\n}\n```\n\n### Streaming API\n\nFor memory-efficient processing:\n\n```rust\nuse kmerust::streaming::count_kmers_streaming;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let counts = count_kmers_streaming(\"genome.fa\", 21)?;\n    println!(\"Found {} unique k-mers\", counts.len());\n    Ok(())\n}\n```\n\n### Reading from Any Source\n\nCount k-mers from any `BufRead` source, including stdin or in-memory data:\n\n```rust\nuse kmerust::streaming::count_kmers_from_reader;\nuse std::io::BufReader;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    // From in-memory data\n    let fasta_data = b\"\u003eseq1\\nACGTACGT\\n\u003eseq2\\nTGCATGCA\\n\";\n    let reader = BufReader::new(\u0026fasta_data[..]);\n    let counts = count_kmers_from_reader(reader, 4)?;\n\n    // From stdin\n    // use kmerust::streaming::count_kmers_stdin;\n    // let counts = count_kmers_stdin(21)?;\n\n    Ok(())\n}\n```\n\n## Performance\n\nkmerust uses parallel processing to efficiently count k-mers:\n\n- Sequences are processed in parallel using rayon\n- A concurrent hash map (dashmap) allows lock-free updates\n- FxHash provides fast hashing for 64-bit packed k-mers\n\n## License\n\nMIT License - see [LICENSE](LICENSE) for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuchapalaver%2Fkmerust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuchapalaver%2Fkmerust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuchapalaver%2Fkmerust/lists"}