Skip to content

dp_input — High-Level .bin + FASTA Pipeline

Source: crates/fastdpplot-core/src/dp_input.rs


DpInput

All data needed to render a DP dotplot.

pub struct DpInput {
    pub query:               FastaRecord,  // first record from fasta_a
    pub subject:             FastaRecord,  // first record from fasta_b
    pub matrix:              BinMatrix,    // loaded binary matrix
    pub query_axis_label:    String,       // formatted Y-axis label
    pub subject_axis_label:  String,       // formatted X-axis label
}

load_dp_input

pub fn load_dp_input(
    matrix_path:  &str,
    fasta_a_path: &str,
    fasta_b_path: &str,
    dtype:        Option<MatrixDtype>,
) -> Result<DpInput, FastDpError>

One-shot loader: parse both FASTA files and the .bin matrix, validate dimensions, and return a [DpInput] ready for rendering.

Processing steps

  1. Parse FASTA A (fasta_a_path) — derive query.
  2. Parse FASTA B (fasta_b_path) — derive subject.
  3. Resolve dtype — if dtype is None, call infer_dtype_from_size with (query.length, subject.length).
  4. Load matrix at (query.length, subject.length).
  5. Transposed fallback — if step 4 raises SizeMismatch, retry with (subject.length, query.length) and swap query ↔ subject.
  6. Format axis labelsformat_axis_label(record, 80).

Errors

Error Condition
FastDpError::NoRecords A FASTA file is empty.
FastDpError::EmptySequence A FASTA record has no sequence bases.
FastDpError::CannotInferDtype File size matches no dtype (dtype = auto).
FastDpError::DimMismatch Matrix size does not match sequences even after transposition.
FastDpError::Io File I/O failure.

Transposed matrix warning

If the matrix is loaded with swapped dimensions a warning is printed to stderr:

warning: matrix appears transposed; swapping query/subject axes
This is not an error; rendering proceeds normally.


dp_input_to_dotpoints

pub fn dp_input_to_dotpoints(input: &DpInput) -> Vec<DotPoint>

Convert a loaded DpInput to Vec<DotPoint> with raw, unnormalised scores.

There is no threshold parameter — all non-boundary cells are included. Scores are cast directly from i32 to f32; sign is fully preserved (negative penalties remain negative, zero stays zero, positive scores remain positive).

Delegates to matrix_to_dotpoints.

Example (Rust)

use fastdpplot_core::dp_input::{load_dp_input, dp_input_to_dotpoints};

let input = load_dp_input("data/dp.bin", "data/q.fasta", "data/s.fasta")?;
let points = dp_input_to_dotpoints(&input);
println!("{} dot points loaded", points.len());