Skip to content

Commit

Permalink
chore: simplify colos
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvollger committed Jan 12, 2024
1 parent 6393bd8 commit 62f4f49
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
16 changes: 0 additions & 16 deletions src/decorator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,6 @@ use rust_htslib::bam::ext::BamRecordExtensions;
use std::cmp::Ordering;
use std::fmt::Display;

const NUC_COLOR: &str = "169,169,169";
const M6A_COLOR: &str = "128,0,128";
const CPG_COLOR: &str = "139,69,19";
const LINKER_COLOR: &str = "147,112,219";
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 get_fire_color(fdr: f32) -> &'static str {
for (fdr_val, color) in FIRE_COLORS.iter() {
if fdr <= *fdr_val {
Expand Down
17 changes: 9 additions & 8 deletions src/fiber.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
use crate::CPG_COLOR;
use crate::LINKER_COLOR;
use crate::M6A_COLOR;
use crate::NUC_COLOR;

use super::bamlift::*;
use super::basemods::BaseMods;
use super::bio_io::*;
Expand Down Expand Up @@ -396,7 +401,6 @@ impl FiberseqData {
// WRITE BED12 FUNCTIONS
//
pub fn write_msp(&self, reference: bool) -> String {
let color = "255,0,255";
let (starts, _ends, lengths) = if reference {
(
&self.msp.reference_starts,
Expand All @@ -406,11 +410,10 @@ impl FiberseqData {
} else {
(&self.msp.starts, &self.msp.ends, &self.msp.lengths)
};
self.to_bed12(reference, starts, lengths, color)
self.to_bed12(reference, starts, lengths, LINKER_COLOR)
}

pub fn write_nuc(&self, reference: bool) -> String {
let color = "169,169,169";
let (starts, _ends, lengths) = if reference {
(
&self.nuc.reference_starts,
Expand All @@ -420,29 +423,27 @@ impl FiberseqData {
} else {
(&self.nuc.starts, &self.nuc.ends, &self.nuc.lengths)
};
self.to_bed12(reference, starts, lengths, color)
self.to_bed12(reference, starts, lengths, NUC_COLOR)
}

pub fn write_m6a(&self, reference: bool) -> String {
let color = "128,0,128";
let starts = if reference {
&self.m6a.reference_starts
} else {
&self.m6a.starts
};
let lengths = vec![Some(1); starts.len()];
self.to_bed12(reference, starts, &lengths, color)
self.to_bed12(reference, starts, &lengths, M6A_COLOR)
}

pub fn write_cpg(&self, reference: bool) -> String {
let color = "139,69,19";
let starts = if reference {
&self.cpg.reference_starts
} else {
&self.cpg.starts
};
let lengths = vec![Some(1); starts.len()];
self.to_bed12(reference, starts, &lengths, color)
self.to_bed12(reference, starts, &lengths, CPG_COLOR)
}

pub fn to_bed12(
Expand Down
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ 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}";

/// COLORS
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),
];

/// unzip a vector of tuples
pub fn unzip_to_vectors<T, U>(vec: Vec<(T, U)>) -> (Vec<T>, Vec<U>) {
vec.into_iter().unzip()
Expand Down

0 comments on commit 62f4f49

Please sign in to comment.