Skip to content

Commit

Permalink
Add output info.
Browse files Browse the repository at this point in the history
  • Loading branch information
hhandika committed Aug 5, 2024
1 parent 352272f commit adf6cba
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ colored = "2.0.0"
chrono = "0.4.*"
dialoguer = "0.*"
glob = "0.3.*"
indexmap = "1.*"
indexmap = "2.*"
indicatif = "0.17.*"
lazy_static = "1.*"
log = "0.*"
Expand Down
23 changes: 18 additions & 5 deletions src/core/sequence/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::{
sync::atomic::{AtomicUsize, Ordering},
};

use colored::Colorize;
use rayon::prelude::*;

use crate::{
Expand All @@ -28,7 +29,7 @@ use crate::{

/// Available sequence filtering options.
pub enum SequenceFilteringOptions {
/// Total percentage of gaps in a sequence.
/// Filtered sequences based the percentage of gaps in a sequence.
/// Remove sequences that have a percentage
/// of gaps higher than the threshold.
/// The threshold is calculated as the number
Expand All @@ -41,7 +42,8 @@ pub enum SequenceFilteringOptions {
/// the float will be floored.
/// For example, 5.1, 5.5, or 5.9, will be 5.
GapThreshold(f64),
/// Minimum sequence length.
/// Filter sequences based on the minimum sequence length.
/// Remove sequences that have a length less than the specified number.
MinSequenceLength(usize),
}

Expand Down Expand Up @@ -114,8 +116,12 @@ impl<'a> SequenceFiltering<'a> {
self.filter_sequences_by_length(min_length)
}
};
assert!(filtered_aln > 0, "No alignments left after filtering!");
spinner.finish_with_message("Finished filtering sequences!\n");
if filtered_aln == 0 {
log::warn!("No matching sequences were found!!");
} else {
self.print_output_info(filtered_aln);
}
}

/// Setter for the concatenation parameters.
Expand Down Expand Up @@ -145,6 +151,13 @@ impl<'a> SequenceFiltering<'a> {
.expect("Failed writing the output file");
}

fn print_output_info(&self, counter: usize) {
log::info!("{}", "Output".yellow());
log::info!("Directory: {}", self.output.display());
log::info!("Format: {:?}", self.output_fmt);
log::info!("Total files: {}", counter);
}

fn filter_sequences_by_length(&self, length: &usize) -> usize {
let counter = AtomicUsize::new(0);
self.files.par_iter().for_each(|file| {
Expand Down Expand Up @@ -172,13 +185,13 @@ impl<'a> SequenceFiltering<'a> {
// Find sequences with gaps higher than the threshold.
matrix.iter().for_each(|(name, seq)| {
let gaps = seq.bytes().filter(|&c| c == b'-' || c == b'?').count();
if gaps > max_gaps {
if gaps <= max_gaps {
to_remove.push(String::from(name));
}
});

to_remove.iter().for_each(|name| {
matrix.remove(name);
matrix.retain(|n, _| n == name);
});

header.ntax = matrix.len();
Expand Down
4 changes: 2 additions & 2 deletions src/core/sequence/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ impl<'a> SequenceRemoval<'a> {

fn remove_sequence(&self, fpath: &Path, ids: &[String]) -> (SeqMatrix, Header) {
let (mut matrix, header) = SeqParser::new(fpath, self.datatype).parse(self.input_fmt);
ids.iter().for_each(|id| if matrix.remove(id).is_some() {});
ids.iter()
.for_each(|id| if matrix.shift_remove(id).is_some() {});

let fnl_header = if !matrix.is_empty() && header.ntax != matrix.len() {
self.get_header(&matrix)
} else {
header
};

(matrix, fnl_header)
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/sequence/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ macro_rules! process_files {
macro_rules! rm_id {
($new_ids: ident, $ids: ident) => {
$new_ids.iter().for_each(|(old, _)| {
$ids.remove(old);
$ids.shift_remove(old);
});
};
}
Expand Down Expand Up @@ -110,7 +110,7 @@ impl<'a> SequenceRenamingDry<'a> {
) -> Vec<(String, String)> {
let mut new_ids: Vec<(String, String)> = Vec::new();
names.iter().for_each(|(old, new)| {
let is_id = ids.remove(old);
let is_id = ids.shift_remove(old);
if is_id {
new_ids.push((old.to_string(), new.to_string()));
}
Expand Down Expand Up @@ -226,7 +226,7 @@ impl<'a> SequenceRenaming<'a> {
let (mut matrix, header) = SeqParser::new(file, self.datatype).parse(self.input_fmt);
let original_size = matrix.len();
names.iter().for_each(|(origin, destination)| {
let values = matrix.remove(origin);
let values = matrix.shift_remove(origin);
if let Some(value) = values {
matrix.insert(destination.to_string(), value);
}
Expand Down

0 comments on commit adf6cba

Please sign in to comment.