seqan / seqan3

The modern C++ library for sequence analysis. Contains version 3 of the library and API docs.
https://www.seqan.de
Other
412 stars 82 forks source link

Allow min_score alignment config for arbitrary (user defined) edit distance schemes #3253

Closed feldroop closed 6 months ago

feldroop commented 6 months ago

I want to align sequences with a custom uint8_t based alphabet and edit distance. I also have a bound on the number of allowed errors in the alignment, so I would like to additionally use the seqan3::align_cfg::min_score configuration.

I am using the seqan3/alphabet/adaptation/uint.hpp header and have already implemented my own scoring scheme by specializing the seqan3::scoring_scheme_base class.

This is my code:

// custom scoring scheme
template <seqan3::arithmetic score_type = int8_t>
class uint8_adaptation_scoring_scheme : public seqan3::scoring_scheme_base<
    uint8_adaptation_scoring_scheme<score_type>, 
    uint8_t, score_type
> {
private:
    using base_t = seqan3::scoring_scheme_base<uint8_adaptation_scoring_scheme<score_type>, uint8_t, score_type>;
    friend base_t;

public:
    constexpr uint8_adaptation_scoring_scheme() noexcept 
        : base_t(seqan3::match_score<score_type>{0}, seqan3::mismatch_score<score_type>{-1}) {};
};

// alignment config
 auto config = seqan3::align_cfg::method_global{}
    | seqan3::align_cfg::scoring_scheme{uint8_adaptation_scoring_scheme{}} // gap scheme defaults to edit distance
    | seqan3::align_cfg::min_score{-10}; // <-- this doesn't work

seqan3::align_pairwise(std::tie(reference, query), config);

This code compiles, but I get the following runtime error:

The align_cfg::min_score configuration is only allowed for the specific edit distance computation

Would it be possible to add a feature that allows this code to work and let me use the min_score config (for optimization purposes)?

rrahn commented 6 months ago

Thanks for reporting this. At the moment we explicitly allow the fast myers edit distance computation only for nucleotide scoring schemes and min_score is only implemented for this type of algorithm and not the general DP algorithm. This however is somewhat limiting as the bitparallel algorithm doesn't even need to access the scoring scheme once since the score values are predefined anyway. Solving this, however, is less intuitive than I first expected, but I am looking into ways how to solve this.

rrahn commented 6 months ago

@feldroop with the above linked PR your code should just work by sticking to the seqan3::align_cfg::edit_scheme{} without setting the scoring scheme or the gap scheme explicitly.

eseiler commented 6 months ago

As far as I understand, this should now work?

auto config = seqan3::align_cfg::method_global{}
            | seqan3::align_cfg::scoring_scheme{seqan3::hamming_scoring_scheme{}}
            | seqan3::align_cfg::min_score{-10};

seqan3::align_pairwise(std::tie(reference, query), config);
feldroop commented 6 months ago

Yes, and this also works even with an adapted uint8 alphabet, which is exactly my use case.

auto config = seqan3::align_cfg::method_global{}
            | seqan3::align_cfg::edit_scheme
            | seqan3::align_cfg::min_score{-10};

seqan3::align_pairwise(std::tie(reference, query), config);