Skip to content

Commit

Permalink
make reused dozeu's that appear const, update aligner interface for x…
Browse files Browse the repository at this point in the history
…drop
jeizenga committed Apr 9, 2020
1 parent cbc03be commit f9e215b
Showing 8 changed files with 165 additions and 212 deletions.
56 changes: 24 additions & 32 deletions src/aligner.cpp
Original file line number Diff line number Diff line change
@@ -1145,9 +1145,18 @@ void Aligner::align(Alignment& alignment, const HandleGraph& g, bool traceback_a
align_internal(alignment, nullptr, g, false, false, 1, traceback_aln, print_score_matrices);
}

void Aligner::align_pinned(Alignment& alignment, const HandleGraph& g, bool pin_left) const {
void Aligner::align_pinned(Alignment& alignment, const HandleGraph& g, bool pin_left, bool xdrop) const {

align_internal(alignment, nullptr, g, true, pin_left, 1, true, false);
if (xdrop) {
// XdropAligner manages its own stack, so it can never be threadsafe without be recreated
// for every alignment, which meshes poorly with its stack implementation. We achieve
// thread-safety by having one per thread, which makes this method const-ish.
XdropAligner& xdrop = const_cast<XdropAligner&>(xdrops[omp_get_thread_num()]);
xdrop.align_pinned(alignment, g, pin_left);
}
else {
align_internal(alignment, nullptr, g, true, pin_left, 1, true, false);
}
}

void Aligner::align_pinned_multi(Alignment& alignment, vector<Alignment>& alt_alignments, const HandleGraph& g,
@@ -1274,20 +1283,13 @@ void Aligner::align_global_banded_multi(Alignment& alignment, vector<Alignment>&
}
}

// X-drop aligner
void Aligner::align_xdrop(Alignment& alignment, const HandleGraph& g, const vector<MaximalExactMatch>& mems, bool reverse_complemented) const
{
// Make a single-problem aligner, so we don't modify ourselves and are thread-safe.
xdrops[omp_get_thread_num()].align(alignment, g, mems, reverse_complemented);
}

void Aligner::align_xdrop_multi(Alignment& alignment, const HandleGraph& g, const vector<MaximalExactMatch>& mems, bool reverse_complemented, int32_t max_alt_alns) const
{
throw runtime_error("Aligner::align_xdrop_multi not yet implemented");
}

const XdropAligner& Aligner::get_xdrop() const {
return xdrops[omp_get_thread_num()];
// XdropAligner manages its own stack, so it can never be threadsafe without be recreated
// for every alignment, which meshes poorly with its stack implementation. We achieve
// thread-safety by having one per thread, which makes this method const-ish.
XdropAligner& xdrop = const_cast<XdropAligner&>(xdrops[omp_get_thread_num()]);
xdrop.align(alignment, g, mems, reverse_complemented);
}


@@ -1665,10 +1667,14 @@ void QualAdjAligner::align(Alignment& alignment, const HandleGraph& g, bool trac
align_internal(alignment, nullptr, g, false, false, 1, traceback_aln, print_score_matrices);
}

void QualAdjAligner::align_pinned(Alignment& alignment, const HandleGraph& g, bool pin_left) const {

align_internal(alignment, nullptr, g, true, pin_left, 1, true, false);

void QualAdjAligner::align_pinned(Alignment& alignment, const HandleGraph& g, bool pin_left, bool xdrop) const {
if (xdrop) {
cerr << "error::[QualAdjAligner] quality-adjusted, X-drop alignment is not implemented" << endl;
exit(1);
}
else {
align_internal(alignment, nullptr, g, true, pin_left, 1, true, false);
}
}

void QualAdjAligner::align_pinned_multi(Alignment& alignment, vector<Alignment>& alt_alignments, const HandleGraph& g,
@@ -1710,20 +1716,6 @@ void QualAdjAligner::align_xdrop(Alignment& alignment, const HandleGraph& g, con
exit(1);
}

void QualAdjAligner::align_xdrop_multi(Alignment& alignment, const HandleGraph& g, const vector<MaximalExactMatch>& mems, bool reverse_complemented, int32_t max_alt_alns) const
{
// TODO: implement?
cerr << "error::[QualAdjAligner] quality-adjusted, X-drop alignment is not implemented" << endl;
exit(1);
}

const XdropAligner& QualAdjAligner::get_xdrop() const {
// TODO: implement?
cerr << "error::[QualAdjAligner] quality-adjusted, X-drop alignment is not implemented" << endl;
exit(1);
return XdropAligner();
}

int32_t QualAdjAligner::score_exact_match(const Alignment& aln, size_t read_offset, size_t length) const {
auto& sequence = aln.sequence();
auto& base_quality = aln.quality();
20 changes: 7 additions & 13 deletions src/aligner.hpp
Original file line number Diff line number Diff line change
@@ -116,14 +116,15 @@ namespace vg {
double estimate_max_possible_mapping_quality(int length, double min_diffs, double next_min_diffs) const;

/// store optimal alignment against a graph in the Alignment object with one end of the sequence
/// guaranteed to align to a source/sink node
/// guaranteed to align to a source/sink node. if xdrop is selected, use the xdrop heuristic, which
/// does not guarantee an optimal alignment.
///
/// pinning left means that that the alignment starts with the first base of the read sequence and
/// the first base of a source node sequence, pinning right means that the alignment starts with
/// the final base of the read sequence and the final base of a sink node sequence
///
/// Gives the full length bonus only on the non-pinned end of the alignment.
virtual void align_pinned(Alignment& alignment, const HandleGraph& g, bool pin_left) const = 0;
virtual void align_pinned(Alignment& alignment, const HandleGraph& g, bool pin_left, bool xdrop = false) const = 0;

/// store the top scoring pinned alignments in the vector in descending score order up to a maximum
/// number of alignments (including the optimal one). if there are fewer than the maximum number in
@@ -147,10 +148,6 @@ namespace vg {
bool permissive_banding = true) const = 0;
// xdrop aligner
virtual void align_xdrop(Alignment& alignment, const HandleGraph& g, const vector<MaximalExactMatch>& mems, bool reverse_complemented) const = 0;
virtual void align_xdrop_multi(Alignment& alignment, const HandleGraph& g, const vector<MaximalExactMatch>& mems, bool reverse_complemented, int32_t max_alt_alns) const = 0;
/// Get a fresh XdropAligner instance to align with.
/// TODO: make XdropAligner thread safe, and make it a thing you can get from GetAligner.
virtual const XdropAligner& get_xdrop() const = 0;

/// Compute the score of an exact match in the given alignment, from the
/// given offset, of the given length.
@@ -284,14 +281,15 @@ namespace vg {
void align(Alignment& alignment, const HandleGraph& g, bool traceback_aln, bool print_score_matrices) const;

/// store optimal alignment against a graph in the Alignment object with one end of the sequence
/// guaranteed to align to a source/sink node
/// guaranteed to align to a source/sink node. if xdrop is selected, use the xdrop heuristic, which
/// does not guarantee an optimal alignment.
///
/// pinning left means that that the alignment starts with the first base of the read sequence and
/// the first base of a source node sequence, pinning right means that the alignment starts with
/// the final base of the read sequence and the final base of a sink node sequence
///
/// Gives the full length bonus only on the non-pinned end of the alignment.
void align_pinned(Alignment& alignment, const HandleGraph& g, bool pin_left) const;
void align_pinned(Alignment& alignment, const HandleGraph& g, bool pin_left, bool xdrop = false) const;

/// store the top scoring pinned alignments in the vector in descending score order up to a maximum
/// number of alignments (including the optimal one). if there are fewer than the maximum number in
@@ -315,8 +313,6 @@ namespace vg {

// xdrop aligner
void align_xdrop(Alignment& alignment, const HandleGraph& g, const vector<MaximalExactMatch>& mems, bool reverse_complemented) const;
void align_xdrop_multi(Alignment& alignment, const HandleGraph& g, const vector<MaximalExactMatch>& mems, bool reverse_complemented, int32_t max_alt_alns) const;
const XdropAligner& get_xdrop() const;

int32_t score_exact_match(const Alignment& aln, size_t read_offset, size_t length) const;
int32_t score_exact_match(const string& sequence, const string& base_quality) const;
@@ -362,16 +358,14 @@ namespace vg {
void align(Alignment& alignment, const HandleGraph& g, bool traceback_aln, bool print_score_matrices) const;
void align_global_banded(Alignment& alignment, const HandleGraph& g,
int32_t band_padding = 0, bool permissive_banding = true) const;
void align_pinned(Alignment& alignment, const HandleGraph& g, bool pin_left) const;
void align_pinned(Alignment& alignment, const HandleGraph& g, bool pin_left, bool xdrop = false) const;
void align_global_banded_multi(Alignment& alignment, vector<Alignment>& alt_alignments, const HandleGraph& g,
int32_t max_alt_alns, int32_t band_padding = 0, bool permissive_banding = true) const;
void align_pinned_multi(Alignment& alignment, vector<Alignment>& alt_alignments, const HandleGraph& g,
bool pin_left, int32_t max_alt_alns) const;

// TODO: xdrop isn't actually possible with the quality adjusted aligner (yet).
void align_xdrop(Alignment& alignment, const HandleGraph& g, const vector<MaximalExactMatch>& mems, bool reverse_complemented) const;
void align_xdrop_multi(Alignment& alignment, const HandleGraph& g, const vector<MaximalExactMatch>& mems, bool reverse_complemented, int32_t max_alt_alns) const;
const XdropAligner& get_xdrop() const;

int32_t score_exact_match(const Alignment& aln, size_t read_offset, size_t length) const;
int32_t score_exact_match(const string& sequence, const string& base_quality) const;
6 changes: 3 additions & 3 deletions src/mapper.cpp
Original file line number Diff line number Diff line change
@@ -1827,9 +1827,9 @@ Alignment Mapper::align_to_graph(const Alignment& aln,
} else if (pinned_alignment) {
get_aligner(!aln.quality().empty())->align_pinned(aligned, align_graph, pin_left);
} else if (xdrop_alignment) {
get_aligner(!aln.quality().empty())->get_xdrop().align(aligned, align_graph,
translate_mems(mems, node_trans),
(xdrop_alignment == 1) ? false : true);
get_aligner(!aln.quality().empty())->align_xdrop(aligned, align_graph,
translate_mems(mems, node_trans),
xdrop_alignment != 1);
} else {
get_aligner(!aln.quality().empty())->align(aligned, align_graph, traceback, false);
}
4 changes: 2 additions & 2 deletions src/minimizer_mapper.cpp
Original file line number Diff line number Diff line change
@@ -2969,9 +2969,9 @@ pair<Path, size_t> MinimizerMapper::get_best_alignment_against_any_tree(const ve
#endif
#endif

// Align, accounting for full length bonus.
// X-drop align, accounting for full length bonus.
// We *always* do left-pinned alignment internally, since that's the shape of trees we get.
get_regular_aligner()->get_xdrop().align_pinned(current_alignment, subgraph, true);
get_regular_aligner()->align_pinned(current_alignment, subgraph, true, true);

#ifdef debug
cerr << "\tScore: " << current_alignment.score() << endl;
Loading
Oops, something went wrong.

0 comments on commit f9e215b

Please sign in to comment.