pub mod common;
pub mod consensus_reads;
pub mod correct_reads;
pub mod fastq_reads;
pub mod grouped_reads;
pub mod mapped_reads;
pub mod sort;
use crate::commands::command::Command;
use anyhow::Result;
use clap::{Parser, Subcommand};
pub use consensus_reads::ConsensusReads;
pub use correct_reads::CorrectReads;
pub use fastq_reads::FastqReads;
pub use grouped_reads::GroupedReads;
pub use mapped_reads::MappedReads;
#[derive(Parser, Debug)]
#[command(
name = "simulate",
about = "\x1b[38;5;166m[UTILITIES]\x1b[0m \x1b[36mGenerate synthetic test data\x1b[0m"
)]
pub struct Simulate {
#[command(subcommand)]
pub command: SimulateCommand,
}
impl Command for Simulate {
fn execute(&self, command_line: &str) -> Result<()> {
self.command.execute(command_line)
}
}
#[derive(Subcommand, Debug)]
pub enum SimulateCommand {
FastqReads(FastqReads),
MappedReads(MappedReads),
GroupedReads(GroupedReads),
ConsensusReads(ConsensusReads),
CorrectReads(CorrectReads),
}
impl SimulateCommand {
fn execute(&self, command_line: &str) -> Result<()> {
match self {
Self::FastqReads(cmd) => cmd.execute(command_line),
Self::MappedReads(cmd) => cmd.execute(command_line),
Self::GroupedReads(cmd) => cmd.execute(command_line),
Self::ConsensusReads(cmd) => cmd.execute(command_line),
Self::CorrectReads(cmd) => cmd.execute(command_line),
}
}
}
#[allow(clippy::eq_op, clippy::cast_possible_truncation)]
#[must_use]
pub fn region_to_bin(start_1based: Option<u32>, end_1based: Option<u32>) -> u16 {
const UNMAPPED_BIN: u16 = 4680;
let (Some(start_1), Some(end_1)) = (start_1based, end_1based) else {
return UNMAPPED_BIN;
};
let start = (start_1.saturating_sub(1)) as usize;
let end = (end_1.saturating_sub(1)) as usize;
let bin = if start >> 14 == end >> 14 {
((1 << 15) - 1) / 7 + (start >> 14)
} else if start >> 17 == end >> 17 {
((1 << 12) - 1) / 7 + (start >> 17)
} else if start >> 20 == end >> 20 {
((1 << 9) - 1) / 7 + (start >> 20)
} else if start >> 23 == end >> 23 {
((1 << 6) - 1) / 7 + (start >> 23)
} else if start >> 26 == end >> 26 {
((1 << 3) - 1) / 7 + (start >> 26)
} else {
0
};
bin as u16
}