Skip to content

Commit

Permalink
[TEST] Adds first simple test case for vectorised alignment algorithm.
Browse files Browse the repository at this point in the history
* Tests dna sequences of same length.
* Only score and back coordinate can be computed.
  • Loading branch information
rrahn committed Dec 15, 2019
1 parent 8ff4827 commit 940d824
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 13 deletions.
4 changes: 3 additions & 1 deletion include/seqan3/alignment/pairwise/alignment_algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class alignment_algorithm :
}

//!\overload
template <std::ranges::forward_range indexed_sequence_pairs_t>
template <indexed_sequence_pair_range indexed_sequence_pairs_t>
auto operator()(indexed_sequence_pairs_t && indexed_sequence_pairs)
//!\cond
requires traits_t::is_vectorised
Expand Down Expand Up @@ -587,7 +587,9 @@ class alignment_algorithm :
* coordinates as well as the trace matrix if applicable.
*/
template <typename index_t, typename sequence1_t, typename sequence2_t>
//!\cond
requires !traits_t::is_vectorised
//!\endcond
constexpr auto make_alignment_result(index_t const idx,
sequence1_t & sequence1,
sequence2_t & sequence2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ struct alignment_configurator
template <typename traits_t>
struct select_gap_policy
{
private:

private:
//!\brief The score type for the alignment computation.
using score_t = typename traits_t::score_t;
//!\brief The is_local constant converted to a type.
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alignment/pairwise/detail/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct alignment_configuration_traits
return 1;
}();
//!\brief The rank of the selected result type.
static constexpr int8_t result_type_rank = static_cast<size_t>(decltype(std::declval<result_t>().value)::rank);
static constexpr int8_t result_type_rank = static_cast<int8_t>(decltype(std::declval<result_t>().value)::rank);
};

} // namespace seqan3::detail
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ class simd_affine_gap_policy
//!\brief Befriends the derived class to grant it access to the private members.
friend alignment_algorithm_t;

//!\brief The state of the alignment algorithm for affine gaps.
//!\brief The type of state of the alignment algorithm for affine gaps.
using alignment_state_t = alignment_algorithm_state<score_t>;

/*!\name Constructors, destructor and assignment
* \{
*/
constexpr simd_affine_gap_policy() noexcept = default; //!< Defaulted
constexpr simd_affine_gap_policy(simd_affine_gap_policy const &) noexcept = default; //!< Defaulted
constexpr simd_affine_gap_policy(simd_affine_gap_policy &&) noexcept = default; //!< Defaulted
constexpr simd_affine_gap_policy & operator=(simd_affine_gap_policy const &) noexcept = default; //!< Defaulted
constexpr simd_affine_gap_policy & operator=(simd_affine_gap_policy &&) noexcept = default; //!< Defaulted
~simd_affine_gap_policy() noexcept = default; //!< Defaulted
constexpr simd_affine_gap_policy() noexcept = default; //!< Defaulted.
constexpr simd_affine_gap_policy(simd_affine_gap_policy const &) noexcept = default; //!< Defaulted.
constexpr simd_affine_gap_policy(simd_affine_gap_policy &&) noexcept = default; //!< Defaulted.
constexpr simd_affine_gap_policy & operator=(simd_affine_gap_policy const &) noexcept = default; //!< Defaulted.
constexpr simd_affine_gap_policy & operator=(simd_affine_gap_policy &&) noexcept = default; //!< Defaulted.
~simd_affine_gap_policy() noexcept = default; //!< Defaulted.
//!\}

/*!\brief Computes the score of the current simd cell.
Expand All @@ -84,7 +84,7 @@ class simd_affine_gap_policy
* stored in the zipped tuple is the seqan3::detail::alignment_score_matrix_proxy and the second value is the
* seqan3::detail::alignment_trace_matrix_proxy.
*
* In order to compute the maximum for two simd vectors gcc implements the ternary operator such that
* In order to compute the maximum for two simd vectors, gcc implements the ternary operator such that
* `std::max(a, b)` can be implemented as `(a > b) ? a : b`, where `(a > b)` returns a mask vector. This implements
* the compare-and-blend approach for simd vector types.
*/
Expand Down
1 change: 1 addition & 0 deletions test/unit/alignment/pairwise/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ seqan3_test(alignment_result_test.cpp)
seqan3_test(align_result_selector_test.cpp)
seqan3_test(alignment_configurator_test.cpp)
seqan3_test(global_affine_banded_test.cpp)
seqan3_test(global_affine_unbanded_collection_simd_test.cpp)
seqan3_test(global_affine_unbanded_collection_test.cpp)
seqan3_test(global_affine_unbanded_test.cpp)
seqan3_test(local_affine_banded_test.cpp)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// -----------------------------------------------------------------------------------------------------
// Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
// Copyright (c) 2016-2019, Knut Reinert & MPI für molekulare Genetik
// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
// -----------------------------------------------------------------------------------------------------

#include <vector>

#include <gtest/gtest.h>

#include <seqan3/alignment/pairwise/align_pairwise.hpp>

#include "fixture/global_affine_unbanded.hpp"
#include "pairwise_alignment_collection_test_template.hpp"

using namespace seqan3;
using namespace seqan3::detail;
using namespace seqan3::test::alignment;

namespace seqan3::test::alignment::collection::simd::global::affine::unbanded
{

static auto dna4_01 = []()
{
using fixture_t = decltype(fixture::global::affine::unbanded::dna4_01);

std::vector<fixture_t> data;
for (size_t i = 0; i < 100; ++i)
data.push_back(fixture::global::affine::unbanded::dna4_01);

auto config = fixture::global::affine::unbanded::dna4_01.config | align_cfg::vectorise;
return alignment_fixture_collection{config, data};
}();

} // namespace seqan3::test::alignment::collection::simd::global::affine::unbanded

using pairwise_collection_simd_global_affine_unbanded_testing_types = ::testing::Types<
pairwise_alignment_fixture<&collection::simd::global::affine::unbanded::dna4_01>
>;

INSTANTIATE_TYPED_TEST_CASE_P(pairwise_collection_simd_global_affine_unbanded,
pairwise_alignment_collection_test,
pairwise_collection_simd_global_affine_unbanded_testing_types);
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ TYPED_TEST_P(pairwise_alignment_collection_test, front_coordinate)
{
auto [database, query] = fixture.get_sequences();
auto res_vec = align_pairwise(views::zip(database, query), align_cfg)
| views::to<std::vector>;
| views::to<std::vector>;

EXPECT_TRUE((std::ranges::equal(res_vec | std::views::transform([] (auto res) { return res.score(); }),
fixture.get_scores())));
Expand All @@ -96,7 +96,7 @@ TYPED_TEST_P(pairwise_alignment_collection_test, alignment)
{
auto [database, query] = fixture.get_sequences();
auto res_vec = align_pairwise(views::zip(database, query), align_cfg)
| views::to<std::vector>;
| views::to<std::vector>;

EXPECT_TRUE((std::ranges::equal(res_vec | std::views::transform([] (auto res) { return res.score(); }),
fixture.get_scores())));
Expand Down

0 comments on commit 940d824

Please sign in to comment.