Nanodrop.Mode protocol (nanodrop v0.3.1)

Copy Markdown

Protocol for measurement modes (DNA, Protein, etc.).

Each mode defines how to extract metadata from a spectrum and generate SVG overlays for visualization.

Summary

Types

t()

All the types that implement this protocol.

Functions

Find the absorbance value at a specific wavelength.

Extract metadata from a spectrum for this mode.

Generate SVG overlay elements from metadata.

Safely compute a ratio, returning nil if denominator is zero or near-zero.

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

absorbance_at(spectrum, target_wavelength)

@spec absorbance_at(map(), float()) :: float()

Find the absorbance value at a specific wavelength.

If the spectrum has :corrected_absorbance, uses that. Otherwise uses :absorbance.

metadata(mode, spectrum)

Extract metadata from a spectrum for this mode.

Returns a map of key-value pairs. Keys starting with underscore are considered private/internal (e.g., _baseline, _corrected_absorbance).

overlays(mode, metadata, context)

Generate SVG overlay elements from metadata.

The context map contains:

  • :scale_x - function to convert wavelength to x pixel
  • :scale_y - function to convert absorbance to y pixel
  • :x_off, :y_off - chart offsets
  • :width, :height - chart dimensions

Returns an SVG string to be inserted into the graph.

safe_ratio(num, denom)

@spec safe_ratio(float(), float()) :: float() | nil

Safely compute a ratio, returning nil if denominator is zero or near-zero.