pub mod fiber;
pub mod basemods;
pub mod center;
#[cfg(feature = "cli")]
pub mod cli;
pub mod extract;
pub mod nucleosomes;
pub mod predict_m6a;
pub mod strip_basemods;
pub mod fire;
pub mod decorator;
pub mod footprint;
pub mod bamlift;
pub mod bio_io;
pub mod bamranges;
pub mod m6a_burn;
use anyhow::Result;
use bio_io::*;
use itertools::Itertools;
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 clear_kinetics(bam: &mut bam::Reader, out: &mut bam::Writer) {
let bar = bio_io::no_length_progress_bar();
for rec in bam.records() {
let mut record = rec.unwrap();
record.remove_aux(b"fp").unwrap_or(());
record.remove_aux(b"fi").unwrap_or(());
record.remove_aux(b"rp").unwrap_or(());
record.remove_aux(b"ri").unwrap_or(());
out.write(&record).unwrap();
bar.inc_length(1);
bar.inc(1);
}
bar.finish();
}
pub fn bam_writer(out: &str, template_bam: &bam::Reader, threads: usize) -> bam::Writer {
let program_name = "fibertools-rs";
let program_id = "ft";
let program_version = VERSION;
program_bam_writer(
out,
template_bam,
threads,
program_name,
program_id,
program_version,
)
}