pub mod fiber;
pub mod m6a_burn;
pub mod subcommands;
pub mod utils;
#[cfg(feature = "cli")]
pub mod cli;
use crate::utils::bio_io::*;
use anyhow::Result;
use itertools::Itertools;
use rust_htslib::bam::FetchDefinition;
use rust_htslib::{bam, bam::Read};
use std::env;
use std::io::Write;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const GIT_HASH: &str = env!("CARGO_GIT_HASH");
pub const LONG_VERSION: &str = env!("CARGO_LONG_VERSION");
const PROGRESS_STYLE: &str =
"[{elapsed_precise:.yellow}] {bar:>35.cyan/blue} {human_pos:>5.cyan}/{human_len:.blue} {percent:>3.green}% {per_sec:<10.cyan}";
pub const NUC_COLOR: &str = "169,169,169";
pub const M6A_COLOR: &str = "128,0,128";
pub const CPG_COLOR: &str = "139,69,19";
pub const LINKER_COLOR: &str = "147,112,219";
pub const FIRE_COLORS: [(f32, &str); 9] = [
(1.0, "139,0,0"),
(2.0, "175,0,0"),
(3.0, "200,0,0"),
(4.0, "225,0,0"),
(5.0, "255,0,0"),
(10.0, "255,140,0"),
(25.0, "225,225,0"),
(100.0, LINKER_COLOR),
(200.0, NUC_COLOR),
];
pub fn unzip_to_vectors<T, U>(vec: Vec<(T, U)>) -> (Vec<T>, Vec<U>) {
vec.into_iter().unzip()
}
pub fn join_by_str<'a, I, Z>(vals: I, sep: &str) -> String
where
I: IntoIterator<Item = Z>,
Z: ToString + 'a,
{
vals.into_iter().map(|v| v.to_string() + sep).collect()
}
pub fn join_by_str_option(vals: &[Option<i64>], sep: &str) -> String {
vals.iter()
.map(|v| match v {
Some(v) => v.to_string(),
None => String::from("NA"),
})
.map(|v| v + sep)
.collect()
}
pub fn join_by_str_option_can_skip(vals: &[Option<i64>], sep: &str, skip_none: bool) -> String {
vals.iter()
.map(|v| match v {
Some(v) => v.to_string(),
None => {
if skip_none {
String::from("")
} else {
String::from("NA")
}
}
})
.filter(|v| !v.is_empty())
.map(|v| v + sep)
.collect()
}
pub fn region_parser(rgn: &str) -> (FetchDefinition<'_>, String) {
if rgn.contains(':') {
let (chrom, rest) = rgn.split(':').collect_tuple().unwrap();
let (start, end) = rest.split('-').collect_tuple().unwrap();
let st: i64 = start
.replace(',', "")
.parse()
.unwrap_or_else(|_| panic!("Could not parse start of region: {}", start));
(
FetchDefinition::RegionString(
chrom.as_bytes(),
st,
end.replace(',', "")
.parse()
.unwrap_or_else(|_| panic!("Could not parse end of region: {}", end)),
),
chrom.to_string(),
)
} else {
(FetchDefinition::String(rgn.as_bytes()), rgn.to_string())
}
}