Skip to content

Commit

Permalink
NW now returnes a scaled f32 value
Browse files Browse the repository at this point in the history
And thereby takes the length of the sequence into account - cleaning
some false positives.
  • Loading branch information
stela2502 committed Jan 23, 2024
1 parent 5248b9c commit 804e457
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/fast_mapper/fast_mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ impl FastMapper{
return None
}

/*let bad_gene = "Ighm";
/*let bad_gene = "Adgrg3";
let bad = self.get_id( bad_gene.to_string()) ;*/

// check if there is only one gene //
Expand Down
10 changes: 5 additions & 5 deletions src/fast_mapper/mapper_entries/mapper_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct MapperEntry{
pub map:Vec::<(SecondSeq, NameEntry)>, // the data storage
only:usize,
hamming_cut: u32, // the bit difference up to which a match between two 32bp regions would still be acceptable.
needleman_wunsch_cut: u32,
needleman_wunsch_cut: f32,
}

impl MapperEntry{
Expand All @@ -22,7 +22,7 @@ impl MapperEntry{
map,
only :0,
hamming_cut :2,
needleman_wunsch_cut: 25
needleman_wunsch_cut: 0.7
}
}

Expand Down Expand Up @@ -99,8 +99,8 @@ impl MapperEntry{
/// If this becomes necessary it can be added later.
pub fn find (&self, seq:&SecondSeq ) -> Option<Vec<&NameEntry>> {
let mut ret : Vec::<&NameEntry> = vec![];
let mut dists : Vec::<u32> = vec![];
let mut min_dist: u32 = u32::MAX;
let mut dists : Vec::<f32> = vec![];
let mut min_dist: f32 = f32::MAX;
for i in 0..self.map.len() {
//eprintln!("Hamming distance below {} - returning {:?}", self.hamming_cut, self.map[i].1.data );
//let dist = self.map[i].0.hamming_distance( seq );
Expand Down Expand Up @@ -221,4 +221,4 @@ mod tests {
assert_eq!(this.map[0].1.data[0], (2_usize, 2_usize));
}

}
}
8 changes: 4 additions & 4 deletions src/fast_mapper/mapper_entries/second_seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl SecondSeq {

/// Almost a needleman_wunsch implementation. It just returns the difference from the expected result
/// comparing the sequences in there minimal defined length. Similar to the hamming_distance function.
pub fn needleman_wunsch(&self, other: &SecondSeq ) -> u32 {
pub fn needleman_wunsch(&self, other: &SecondSeq ) -> f32 {

let size = self.min_length(other);

Expand Down Expand Up @@ -154,7 +154,7 @@ impl SecondSeq {
println!();
}*/

(size as i32 - matrix[rows - 1][cols - 1].score).abs() as u32
(size as i32 - matrix[rows - 1][cols - 1].score).abs() as f32 / size as f32
}

/// returns the minimal size the two SecondSeq obejcts are defined for
Expand Down Expand Up @@ -230,7 +230,7 @@ impl SecondSeq {
println!("{} sig bp", self.1);
}

pub fn fuzzy_match(&self, other:&SecondSeq, max_dist:u32 ) -> bool {
pub fn fuzzy_match(&self, other:&SecondSeq, max_dist:f32 ) -> bool {

//return self.hamming_distance( other ) <= max_dist.try_into().unwrap()
return self.needleman_wunsch( other ) <= max_dist.try_into().unwrap()
Expand Down Expand Up @@ -340,4 +340,4 @@ mod tests {
let seq6 = SecondSeq(0b0, 20);
assert_eq!( seq1.hamming_distance( &seq6 ), 3 );
}
}
}

0 comments on commit 804e457

Please sign in to comment.