feat: add phylogenetic sampling, masking, and plain FASTA writer
Introduces configurable phylogenetic sampling and masking controls via new CLI flags (`--subsample`, `--entropy`, `--exclude-genome`, etc.). Adds a complete SNP pseudo-alignment pipeline featuring entropy-biased Gaussian sampling, post-hoc state masking, and proportional per-layer filtering. Extends the FASTA writer with a `write_plain_record` API for bare-header output without JSON annotations.
This commit is contained in:
1 parent
5a0b71d105
commit
beb2951c20
12 files changed
+768
-27
No files matched your search
@@ -39,9 +39,12 @@ pub fn seq_id(ascii: &[u8]) -> String {
|
||||
format!("{:016X}", xxh64(ascii, 0))
|
||||
}
|
||||
|
||||
/// Write `seq` as one line of ASCII DNA, followed by a newline.
|
||||
/// Write `seq` as one line of ASCII text, followed by a newline — plain DNA
|
||||
/// (A/C/G/T) from every caller in this crate today, but any single-byte
|
||||
/// ASCII alphabet is sound here (e.g. IUPAC ambiguity codes, `-`/`?`
|
||||
/// alignment gap/missing markers).
|
||||
pub fn write_sequence<W: Write>(writer: &mut W, seq: &[u8]) -> io::Result<()> {
|
||||
// SAFETY: seq is valid ASCII DNA (A/C/G/T).
|
||||
// SAFETY: every caller in this crate only ever passes valid ASCII bytes.
|
||||
writeln!(writer, "{}", unsafe { std::str::from_utf8_unchecked(seq) })
|
||||
}
|
||||
|
||||
@@ -59,3 +62,16 @@ pub fn write_record<W: Write>(
|
||||
writeln!(out)?;
|
||||
write_sequence(out, seq)
|
||||
}
|
||||
|
||||
/// Plain FASTA record writer — no OBITools JSON annotation block.
|
||||
///
|
||||
/// Writes `>{id}\n{sequence}\n`. For callers with no per-record metadata to
|
||||
/// carry (e.g. a phylogenetic pseudo-alignment's per-genome row, consumed
|
||||
/// by external tools that don't expect a trailing `{...}` on the header
|
||||
/// line) — [`write_record`] with an empty `fields` slice would still emit
|
||||
/// `>{id} {}` (a real, if empty, JSON object plus its leading space), not
|
||||
/// a bare header.
|
||||
pub fn write_plain_record<W: Write>(seq: &[u8], id: &str, out: &mut W) -> io::Result<()> {
|
||||
writeln!(out, ">{id}")?;
|
||||
write_sequence(out, seq)
|
||||
}
|
||||
@@ -14,7 +14,10 @@
|
||||
//! ```
|
||||
//!
|
||||
//! The lower-level primitive [`write_record`] and the [`JsonVal`] type are also
|
||||
//! public for callers that need custom annotations.
|
||||
//! public for callers that need custom annotations — or, for callers with no
|
||||
//! per-record metadata at all (e.g. a phylogenetic pseudo-alignment's rows),
|
||||
//! [`write_plain_record`] writes a bare `>{id}\n{sequence}\n`, no annotation
|
||||
//! block.
|
||||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
@@ -24,7 +27,7 @@ use std::io::{self, Write};
|
||||
|
||||
use obikseq::{Minimizer, SuperKmer, Unitig};
|
||||
|
||||
pub use fasta::{JsonVal, annotation, seq_id, write_record};
|
||||
pub use fasta::{JsonVal, annotation, seq_id, write_plain_record, write_record};
|
||||
|
||||
// ── public API ────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in new issue
Block a user