pub struct TargetRegions { /* private fields */ }Expand description
A collection of genomic target regions loaded from a BED file, indexed for efficient overlap queries.
Internally stores one COITree per contig for O(log N) overlap detection.
BED coordinates are 0-based half-open [start, end), but coitrees uses
end-inclusive intervals, so we store [start, end-1] internally.
Debug is implemented manually because COITree does not implement Debug.
Implementations§
Source§impl TargetRegions
impl TargetRegions
Sourcepub fn from_path(path: &Path, dict: &SequenceDictionary) -> Result<Self>
pub fn from_path(path: &Path, dict: &SequenceDictionary) -> Result<Self>
Load target regions from a BED file.
The file may be plain text or gzipped. Coordinates are validated against
dict — unknown contigs or out-of-range coordinates cause an error.
§Errors
Returns an error if the file cannot be read, contains invalid entries, or references contigs not present in the dictionary.
Sourcepub fn total_territory(&self) -> u64
pub fn total_territory(&self) -> u64
Return the total number of bases covered by all target regions.
Note: if the BED file contains overlapping intervals, overlapping bases are counted multiple times. Callers that need exact territory should provide a non-overlapping BED.
Sourcepub fn contig_territory(&self, contig_index: usize) -> u64
pub fn contig_territory(&self, contig_index: usize) -> u64
Return the target territory (in bases) for a specific contig.
Sourcepub fn overlaps(&self, contig_index: usize, start: u32, end: u32) -> bool
pub fn overlaps(&self, contig_index: usize, start: u32, end: u32) -> bool
Check whether the interval [start, end) (0-based half-open) on the
given contig overlaps any target region.
Sourcepub fn contig_intervals(&self, contig_index: usize) -> &[(u32, u32)]
pub fn contig_intervals(&self, contig_index: usize) -> &[(u32, u32)]
Return the sorted target intervals for a contig in 0-based half-open
coordinates [start, end).
Sourcepub fn effective_territory(&self, fragment_mean: usize) -> u64
pub fn effective_territory(&self, fragment_mean: usize) -> u64
Compute the effective territory for coverage calculation, accounting for the fact that fragments extend beyond target boundaries.
For a target of width W, a fragment of length L placed uniformly to
overlap the target has an on-target fraction of W / (W + L - 1).
The effective territory per target is therefore W + L - 1 — the
catchment zone of fragment start positions — and the total effective
territory is the sum across all targets. Using this as effective_size
in the standard coverage formula N = C * effective_size / bases_per_read
yields the correct number of reads for the desired mean target coverage.
Sourcepub fn contig_effective_territory(
&self,
contig_index: usize,
fragment_mean: usize,
) -> u64
pub fn contig_effective_territory( &self, contig_index: usize, fragment_mean: usize, ) -> u64
Compute the effective territory for a single contig.
See effective_territory for the rationale.
Sourcepub fn dict(&self) -> &SequenceDictionary
pub fn dict(&self) -> &SequenceDictionary
Return a reference to the underlying sequence dictionary.