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

Fix/issue_3264 #3268

Merged
merged 5 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions include/seqan3/alphabet/aminoacid/aminoacid_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <seqan3/alphabet/alphabet_base.hpp>
#include <seqan3/alphabet/aminoacid/concept.hpp>
#include <seqan3/alphabet/detail/concept.hpp>
#include <seqan3/alphabet/detail/convert.hpp>
#include <seqan3/utility/char_operations/transform.hpp>

Expand Down Expand Up @@ -69,6 +70,7 @@ class aminoacid_base : public aminoacid_empty_base, public alphabet_base<derived
template <typename other_aa_type>
requires (!std::same_as<aminoacid_base, other_aa_type>)
&& (!std::same_as<derived_type, other_aa_type>) && aminoacid_alphabet<other_aa_type>
&& detail::convertable_to_through_char_representation<other_aa_type, derived_type>
explicit constexpr aminoacid_base(other_aa_type const other) noexcept
{
if constexpr (is_constexpr_default_constructible_v<other_aa_type>
Expand Down
15 changes: 15 additions & 0 deletions include/seqan3/alphabet/detail/concept.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <concepts>

#include <seqan3/alphabet/concept.hpp>
#include <seqan3/core/platform.hpp>

namespace seqan3::detail
Expand Down Expand Up @@ -54,4 +55,18 @@ concept weakly_ordered_with =
};
//!\endcond

/*!\interface seqan3::detail::convertable_to_through_char_representation <>
* \ingroup alphabet
* \tparam from_t The type to convert from.
* \tparam to_t The type to convert to.
* \brief Checks whether `from_t` can be converted through `to_t` using their char representation.
*
* Requires that both `from_t` and `to_t` are alphabets and additionally, that `from_t` is default constructible.
*/
//!\cond
template <typename from_t, typename to_t>
concept convertable_to_through_char_representation =
alphabet<from_t> && alphabet<to_t> && std::default_initializable<from_t>;
//!\endcond

} // namespace seqan3::detail
7 changes: 4 additions & 3 deletions include/seqan3/alphabet/detail/convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include <array>

#include <seqan3/alphabet/concept.hpp>
#include <seqan3/alphabet/detail/concept.hpp>

// ============================================================================
// conversion to/from char/rank types
Expand All @@ -25,11 +25,12 @@ namespace seqan3::detail
// clang-format off
/*!\brief A precomputed conversion table for two alphabets based on their char representations.
* \ingroup alphabet
* \tparam in_t The type of the input, must satisfy seqan3::alphabet.
* \tparam in_t The type of the input, must satisfy seqan3::alphabet and must be default initializable.
* \tparam out_t The type of the output, must satisfy seqan3::alphabet.
* \hideinitializer
*/
template <alphabet in_t, alphabet out_t>
template <typename in_t, typename out_t>
requires convertable_to_through_char_representation<in_t, out_t>
constexpr std::array<out_t, alphabet_size<in_t>> convert_through_char_representation
{
[]() constexpr {
Expand Down
2 changes: 2 additions & 0 deletions include/seqan3/alphabet/nucleotide/nucleotide_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#pragma once

#include <seqan3/alphabet/alphabet_base.hpp>
#include <seqan3/alphabet/detail/concept.hpp>
#include <seqan3/alphabet/detail/convert.hpp>
#include <seqan3/alphabet/nucleotide/concept.hpp>
#include <seqan3/utility/char_operations/transform.hpp>
Expand Down Expand Up @@ -77,6 +78,7 @@ class nucleotide_base : public alphabet_base<derived_type, size, char>
template <typename other_nucl_type>
requires (!std::same_as<nucleotide_base, other_nucl_type>)
&& (!std::same_as<derived_type, other_nucl_type>) && nucleotide_alphabet<other_nucl_type>
&& detail::convertable_to_through_char_representation<other_nucl_type, derived_type>
explicit constexpr nucleotide_base(other_nucl_type const & other) noexcept
{
static_cast<derived_type &>(*this) =
Expand Down
13 changes: 13 additions & 0 deletions test/unit/alphabet/container/bitpacked_sequence_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <gtest/gtest.h>

#include <vector>

rrahn marked this conversation as resolved.
Show resolved Hide resolved
rrahn marked this conversation as resolved.
Show resolved Hide resolved
#include <seqan3/alphabet/composite/alphabet_variant.hpp>
#include <seqan3/alphabet/container/bitpacked_sequence.hpp>
#include <seqan3/alphabet/nucleotide/concept.hpp>
Expand Down Expand Up @@ -51,3 +53,14 @@ TEST(bitpacked_sequence_test, issue371)
auto end = source.end();
[[maybe_unused]] bool result = it != end; // This line causes error.
}

// https://github.com/seqan/seqan3/issues/3264
TEST(bitpacked_sequence_test, issue3264)
{
using namespace seqan3::literals;

seqan3::bitpacked_sequence<seqan3::dna4> source{"ACGGTCAGGTTC"_dna4};
auto it = source.begin();
seqan3::dna4 val = static_cast<seqan3::dna4>(*it); // this line caused the compiler error
EXPECT_EQ(val, 'A'_dna4);
}
1 change: 1 addition & 0 deletions test/unit/search/fm_index_cursor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ seqan3_test (fm_index_cursor_test.cpp)
seqan3_test (fm_index_cursor_collection_test.cpp)
seqan3_test (bi_fm_index_cursor_test.cpp)
seqan3_test (bi_fm_index_cursor_collection_test.cpp)
seqan3_test (extend_bitpacked_query_sequence_test.cpp)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause

#include <gtest/gtest.h>

#include <vector>

Comment on lines +7 to +8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <vector>

Needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I am using a std::vector. It might be included by the helper.hpp already. Not including it has the potential that if some other code is refactored this test might not compile anymore since vector is not included through some dependent includes. Adding it makes clear, that I need it in the test.
But frankly, I don't care too much. What is the preferred policy here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, didn't see the result_t. It's fine then

#include <seqan3/alphabet/container/bitpacked_sequence.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/search/fm_index/fm_index.hpp>
#include <seqan3/utility/views/slice.hpp>

#include "../helper.hpp"

TEST(fm_index_cursor_test, extend_right_with_bitpacked_sequence)
{
using namespace seqan3::literals;
using result_t = std::vector<std::pair<uint64_t, uint64_t>>;

seqan3::bitpacked_sequence<seqan3::dna4> seq{"ACGGTCAGGTTC"_dna4};
seqan3::fm_index index{seq};

auto bitpacked_query = seqan3::views::slice(seq, 1, 4);

auto it = index.cursor();
it.extend_right(bitpacked_query); // this line caused the compile time error
EXPECT_EQ(seqan3::uniquify(it.locate()), (result_t{{0, 1}}));
}
Loading