pub struct Fasta {
pub id: String, pub seq: String, }
impl Fasta {
pub fn new() -> Fasta {
Fasta {
id: String::new(),
seq: String::new(),
}
}
}
pub struct Fastq {
pub id: String, pub seq1: String, pub qual1: String, pub seq2: String,
pub qual2: String,
}
impl Fastq {
pub fn new() -> Fastq {
Fastq {
id: String::new(),
seq1: String::new(),
qual1: String::new(),
seq2: String::new(),
qual2: String::new(),
}
}
}
pub fn qual_mask(seq: &String, qual: &String, max_quality_offset: u8) -> String {
if max_quality_offset == 0 {
seq.to_string()
} else {
let max_quality: u8 = max_quality_offset + 33;
let mut seq_chars = seq.chars();
let mut new_seq = String::new();
for q in qual.chars() {
let current_nt = seq_chars
.next()
.expect("ERROR: could not get the next nt in the sequence");
let phred = q as u8;
if phred < max_quality {
new_seq.push('N');
} else {
new_seq.push(current_nt);
}
}
new_seq
}
}
pub fn is_good_base(chr: u8) -> bool {
match chr as char {
'a' | 'c' | 'g' | 't' | 'A' | 'C' | 'G' | 'T' => true,
_ => false,
}
}
pub fn has_no_n<'a>(seq: &'a [u8]) -> bool {
seq.iter().all(|n| is_good_base(*n))
}
#[test]
fn can_detect_no_n() {
assert!(has_no_n(b"AAGT"));
assert!(!has_no_n(b"NAGT"));
}