cosmic_files/sequencing/
bed.rs

1use std::fs::File;
2use std::io::{BufRead, BufReader};
3
4#[derive(Debug, Clone)]
5pub struct BarcodeRecord {
6    pub chrom: String,
7    pub start: u64,   // 0-based, BED convention
8    pub end: u64,
9    pub subspecies: String,
10    pub allele: char,
11}
12
13pub fn parse_barcode_bed(path: &str) -> anyhow::Result<Vec<BarcodeRecord>> {
14    let reader = BufReader::new(File::open(path)?);
15    let mut records = Vec::new();
16
17    for line in reader.lines() {
18        let line = line?;
19        if line.starts_with('#') || line.trim().is_empty() {
20            continue;
21        }
22        let cols: Vec<&str> = line.split('\t').collect();
23        if cols.len() < 5 {
24            continue;
25        }
26        records.push(BarcodeRecord {
27            chrom: cols[0].to_string(),
28            start: cols[1].parse()?,
29            end:   cols[2].parse()?,
30            subspecies: cols[3].to_string(),
31            allele: cols[4].chars().next().unwrap_or('N'),
32        });
33    }
34    Ok(records)
35}
36