Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make identity() calculation ignore soft clips #4502

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2290,7 +2290,6 @@ double divergence(const Mapping& m) {
}

double identity(const Path& path) {
double ident = 0;
size_t total_length = path_to_length(path);
size_t matched_length = 0;
for (size_t i = 0; i < path.mapping_size(); ++i) {
Expand All @@ -2299,6 +2298,12 @@ double identity(const Path& path) {
auto& edit = mapping.edit(j);
if (edit_is_match(edit)) {
matched_length += edit.from_length();
} else if (edit_is_insertion(edit)) {
bool is_first_edit = (i == 0) && (j == 0);
bool is_last_edit = (i == path.mapping_size() - 1) && (j == mapping.edit_size() - 1);
if (is_first_edit || is_last_edit) {
total_length -= edit.to_length();
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ bool adjacent_mappings(const Mapping& m1, const Mapping& m2);
// Return true if a mapping is a perfect match (i.e. contains no non-match edits)
bool mapping_is_match(const Mapping& m);
double divergence(const Mapping& m);
// Return the identity for the path: perfect matches over total length.
// Return the identity for the path: perfect matches over total length, ignoring soft clips.
// For zero-length paths, returns 0.
double identity(const Path& path);
// compare the agreement between two alignments
Expand Down
Loading