nanocov 0.1.0

Rust Coverage Calculator and QC Plot Generation Tool
Documentation
use std::collections::HashMap;
use std::io::BufRead;
use std::path::PathBuf;

/// Type alias for BED regions mapping chromosomes to position ranges
pub type BedRegions = HashMap<String, Vec<(u32, u32)>>;

pub fn parse_bed(path: &PathBuf) -> Result<BedRegions, Box<dyn std::error::Error>> {
    let mut regions: BedRegions = HashMap::new();
    let file = std::fs::File::open(path)?;
    let reader = std::io::BufReader::new(file);
    for line in reader.lines() {
        let line = line?;
        if line.starts_with('#') || line.trim().is_empty() {
            continue;
        }
        let fields: Vec<_> = line.split_whitespace().collect();
        if fields.len() < 3 {
            continue;
        }
        let chrom = fields[0].to_string();
        let start: u32 = fields[1].parse()?;
        let end: u32 = fields[2].parse()?;
        if end <= start {
            continue;
        }
        // BED is 0-based, end-exclusive; convert to 1-based inclusive.
        let start = start.saturating_add(1);
        regions.entry(chrom).or_default().push((start, end));
    }
    Ok(regions)
}