seqan3 icon indicating copy to clipboard operation
seqan3 copied to clipboard

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

Open feldroop opened this issue 9 months ago • 2 comments

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)?

feldroop avatar May 08 '24 16:05 feldroop

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 avatar May 09 '24 14:05 rrahn

@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.

rrahn avatar May 15 '24 14:05 rrahn

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);

eseiler avatar May 31 '24 11:05 eseiler

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);

feldroop avatar May 31 '24 11:05 feldroop