Skip to content

Commit

Permalink
Added unique filter in de-novo-align
Browse files Browse the repository at this point in the history
  • Loading branch information
douweschulte committed Sep 27, 2024
1 parent 743061a commit 4496c85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
1 change: 0 additions & 1 deletion examples/de-novo-align/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ clap = { workspace = true }
itertools = { workspace = true }
rayon = { workspace = true }
serde_json = { workspace = true }
ordered-float = { workspace = true }
28 changes: 23 additions & 5 deletions examples/de-novo-align/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{collections::HashMap, fs::File, io::BufWriter};

use clap::Parser;
use itertools::Itertools;
use ordered_float::OrderedFloat;
use rayon::prelude::*;
use rustyms::{
align::{align, matrix, AlignType},
Expand Down Expand Up @@ -36,8 +35,8 @@ fn main() {

let alignments: Vec<_> = peptides
.par_iter()
.map(|peptide| {
database
.flat_map(|peptide| {
let alignments = database
.iter()
.map(|db| {
(
Expand All @@ -52,10 +51,28 @@ fn main() {
),
)
})
.max_by_key(|a| OrderedFloat(a.2.normalised_score()))
.collect_vec();
let max = alignments
.iter()
.max_by(|a, b| a.2.normalised_score().total_cmp(&b.2.normalised_score()))
.unwrap()
.2
.normalised_score();
let mut alignments = alignments
.into_iter()
.filter(|a| a.2.normalised_score() == max)
.collect_vec();
if alignments.len() == 1 {
let (d, p, a) = alignments.pop().unwrap();
vec![(d, p, a, true)]
} else {
alignments
.into_iter()
.map(|(d, p, a)| (d, p, a, false))
.collect_vec()
}
})
.map(|(db, peptide, alignment)| {
.map(|(db, peptide, alignment, unique)| {
HashMap::from([
("Peptide".to_string(), alignment.seq_b().to_string()),
(
Expand All @@ -73,6 +90,7 @@ fn main() {
"Alignment score".to_string(),
alignment.normalised_score().to_string(),
),
("Unique".to_string(), unique.to_string()),
("Start".to_string(), alignment.start_a().to_string()),
(
"End".to_string(),
Expand Down

0 comments on commit 4496c85

Please sign in to comment.