Skip to content

Commit 893cc53

Browse files
committed
update normalised similarity
1 parent 58b2352 commit 893cc53

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

goombay-rs/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

goombay-rs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "goombay-rs"
3-
version = "0.1.1"
3+
version = "0.2.0"
44
edition = "2024"
55

66
[dependencies]

goombay-rs/src/alignment/edit/needleman_wunsch.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl AlignmentMatrices<GeneralScoring> for NeedlemanWunsch<GeneralScoring> {
8383
metric: Metric::Similarity,
8484
identity: self.scores.identity,
8585
mismatch: self.scores.mismatch,
86+
gap: self.scores.gap,
8687
all_alignments: false,
8788
}
8889
}

goombay-rs/src/alignment/edit/wagner_fischer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ impl AlignmentMatrices<LevenshteinScoring> for WagnerFischer<LevenshteinScoring>
8080
metric: Metric::Distance,
8181
identity: 0,
8282
mismatch: self.scores.substitution,
83+
gap: self.scores.gap,
8384
all_alignments: false,
8485
}
8586
}

goombay-rs/src/alignment/global_base.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub struct GlobalAlignmentModel {
4040
pub metric: Metric,
4141
pub identity: usize,
4242
pub mismatch: usize,
43+
pub gap: usize,
4344
pub all_alignments: bool,
4445
}
4546

@@ -51,6 +52,7 @@ impl GlobalAlignmentModel {
5152
metric: self.metric.clone(),
5253
identity: self.identity,
5354
mismatch: self.mismatch,
55+
gap: self.gap,
5456
all_alignments: value,
5557
}
5658
}
@@ -146,12 +148,20 @@ impl GlobalAlignmentModel {
146148
.max()
147149
.copied()
148150
.unwrap();
151+
let min_length = [self.data.query.len(), self.data.subject.len()]
152+
.iter()
153+
.min()
154+
.copied()
155+
.unwrap();
149156
let max_possible = (max_length * self.identity) as f64;
150-
let min_possible = (max_length * self.mismatch) as f64;
157+
let min_possible =
158+
-((min_length * self.mismatch + (max_length - min_length) * self.gap) as f64);
151159

152-
let score_range = max_possible + min_possible.abs();
153-
154-
(raw_sim + min_possible.abs()) / score_range
160+
let score_range = max_possible - min_possible;
161+
if score_range.abs() < f64::EPSILON {
162+
return 1.0;
163+
}
164+
(raw_sim - min_possible) / score_range
155165
}
156166
Metric::Distance => 1_f64 - self.normalized_distance(),
157167
}

0 commit comments

Comments
 (0)