<commit_before>//!
//!	This module is responsible for reading mappability information produced using tallymer.
//!
use std::io::prelude::*;
use std::ffi::OsString;
use std::io::Result;
use std::io::Error;
use std::io::ErrorKind;
use std::io::Lines;
use std::collections::BTreeMap;
use std::mem::swap;

/// Specifies if a position is unmappable in each strand.
#[derive(Copy, Clone)]
pub struct UnMapPosition {
    pub plus: bool,
    pub minus: bool,
}

pub struct UnMap<R: BufRead> {
    data: BTreeMap<u64, UnMapPosition>, // map from position to pair (unmappable in plus, unmappable in minus)
    data_next: BTreeMap<u64, UnMapPosition>, // will contain the data for the next sequence, if any 
    lines: Lines<R>,
    seqnumber: u64,
    next_seqnumber: u64,
}

fn parse_line(bytes: Vec<u8>) -> Result<(u64, u64, bool)> {
    let mut seq_idx = 0u64;
    let mut pos = 0u64;
    let mut idx = 0;
    
    while bytes[idx] >= b'0' && bytes[idx] <= b'9' {
        seq_idx = seq_idx * 10 + (bytes[idx] - b'0') as u64;
        idx += 1;
    }
    
    if bytes[idx] != b'\t' {
        return Err(Error::new(ErrorKind::Other, "unexpected byte in tallymer line"));
    }
    
    // parse sign
    idx += 1;
    let is_minus = match bytes[idx] {
        b'-' => true,
        b'+' => false,
        _ => return Err(Error::new(ErrorKind::Other, "unexpected byte in tallymer line"))
    };
    idx += 1;
    
    // parse position
    while bytes[idx] >= b'0' && bytes[idx] <= b'9' {
        pos = pos * 10 + (bytes[idx] - b'0') as u64;
        idx += 1;<commit_msg>Bug fix: missing guard on tallymer line parser<commit_after>//!
//!	This module is responsible for reading mappability information produced using tallymer.
//!
use std::io::prelude::*;
use std::ffi::OsString;
use std::io::Result;
use std::io::Error;
use std::io::ErrorKind;
use std::io::Lines;
use std::collections::BTreeMap;
use std::mem::swap;

/// Specifies if a position is unmappable in each strand.
#[derive(Copy, Clone)]
pub struct UnMapPosition {
    pub plus: bool,
    pub minus: bool,
}

pub struct UnMap<R: BufRead> {
    data: BTreeMap<u64, UnMapPosition>, // map from position to pair (unmappable in plus, unmappable in minus)
    data_next: BTreeMap<u64, UnMapPosition>, // will contain the data for the next sequence, if any 
    lines: Lines<R>,
    seqnumber: u64,
    next_seqnumber: u64,
}

fn parse_line(bytes: Vec<u8>) -> Result<(u64, u64, bool)> {
    let mut seq_idx = 0u64;
    let mut pos = 0u64;
    let mut idx = 0;
        
    while bytes[idx] >= b'0' && bytes[idx] <= b'9' {
        seq_idx = seq_idx * 10 + (bytes[idx] - b'0') as u64;
        idx += 1;
    }
    
    if bytes[idx] != b'\t' {
        return Err(Error::new(ErrorKind::Other, "unexpected byte in tallymer line"));
    }
    
    // parse sign
    idx += 1;
    let is_minus = match bytes[idx] {
        b'-' => true,
        b'+' => false,
        _ => return Err(Error::new(ErrorKind::Other, "unexpected byte in tallymer line"))
    };
    idx += 1;
    
    // parse position
    while idx < bytes.len() && bytes[idx] >= b'0' && bytes[idx] <= b'9' {
        pos = pos * 10 + (bytes[idx] - b'0') as u64;
        idx += 1;
{'fraction_non_alphanumeric': 0.15566037735849056, 'fraction_numerical': 0.02389937106918239, 'mean_word_length': 2.837153196622437, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '758897', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1117, 'n_words': 336}