use noodles::fastq;
use rand_distr::Normal;
#[derive(Debug)]
pub struct SeqLen(pub String, pub usize);
impl SeqLen {
pub fn get_seq_name(&self) -> &String {
&self.0
}
pub fn get_seq_len(&self) -> usize {
self.1
}
}
#[derive(Debug)]
pub struct NormalDistributionParams(f64, f64);
impl NormalDistributionParams {
pub fn new(mu: f64, sigma: f64) -> Self {
NormalDistributionParams(mu, sigma)
}
pub fn get_mu(&self) -> f64 {
self.0
}
pub fn get_sigma(&self) -> f64 {
self.1
}
}
impl From<NormalDistributionParams> for Normal<f64> {
fn from(params: NormalDistributionParams) -> Self {
Normal::new(params.get_mu(), params.get_sigma()).unwrap_or_else(|_| {
panic!(
"Could not create normal distribution from parameters: {:?}",
params
)
})
}
}
#[derive(Debug)]
pub struct PairedRead(pub fastq::Record, pub fastq::Record);
impl PairedRead {
pub fn get_forward_read(&self) -> &fastq::Record {
&self.0
}
pub fn get_reverse_read(&self) -> &fastq::Record {
&self.1
}
}
pub fn compliment(seq: &u8) -> Option<u8> {
match seq {
0x61 => Some(0x74), 0x63 => Some(0x67), 0x67 => Some(0x63), 0x74 => Some(0x61), 0x41 => Some(0x54), 0x43 => Some(0x47), 0x47 => Some(0x43), 0x54 => Some(0x41), _ => None,
}
}
pub fn reverse_compliment(seq: &[u8]) -> Option<Vec<u8>> {
let iter = seq.iter().map(compliment);
if iter.clone().any(|x| x.is_none()) {
return None;
}
let mut result: Vec<u8> = iter.map(|x| x.unwrap()).collect();
result.reverse();
Some(result)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_compliment_valid() {
let input = "ACTGactg".as_bytes();
assert_eq!(reverse_compliment(input), Some(Vec::from("cagtCAGT")));
}
#[test]
fn test_compliment_invalid() {
let input: Vec<u8> = "n".as_bytes().to_vec();
assert_eq!(super::reverse_compliment(&input), None);
}
}