SeqAn3 3.3.0
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
dna5_implicit_conversion_from_rna5

Normally, we do not allow implicit conversion of single argument constructors, but in this case we make an exception, because seqan3::dna5 and seqan3::rna5 are interchangeable as they behave nearly the same (e.g. same ranks, same char to rank conversion).

int main()
{
using namespace seqan3::literals;
seqan3::dna5 letter1 = 'C'_rna5; // implicitly converted
seqan3::dna5 letter2{};
letter2 = 'C'_rna5; // implicitly converted
}
The five letter DNA alphabet of A,C,G,T and the unknown character N..
Definition dna5.hpp:51
Provides seqan3::dna5, container aliases and string literals.
The SeqAn namespace for literals.
Provides seqan3::rna5, container aliases and string literals.


seqan3::sequences (e.g. seqan3::dna5_vector) in general are not implicitly convertible and must be explicitly copied to be converted:

#include <vector>
int main()
{
using namespace seqan3::literals;
seqan3::dna5_vector vector{'A'_rna5, 'C'_rna5, 'G'_rna5}; // (element-wise) implicit conversion
// but this won't work:
// seqan3::dna5_vector dna5_vector{"ACGT"_rna5};
// as a workaround you can use:
// side note: this would also work without the implicit conversion.
seqan3::rna5_vector rna5_vector = "ACGT"_rna5;
seqan3::dna5_vector dna5_vector{rna5_vector.begin(), rna5_vector.end()};
}


You can avoid this copy by using std::ranges::views:

#include <vector>
int main()
{
using namespace seqan3::literals;
seqan3::dna5_vector vector = "ACG"_dna5;
auto rna5_view = vector | seqan3::views::convert<seqan3::rna5>;
for (auto && chr: rna5_view) // converts lazily on-the-fly
{
static_assert(std::same_as<decltype(chr), seqan3::rna5 &&>);
}
}
The five letter RNA alphabet of A,C,G,U and the unknown character N..
Definition rna5.hpp:49
Provides seqan3::views::convert.


This conversion constructor only allows converting seqan3::rna5 to seqan3::dna5. Other alphabets that inherit from seqan3::rna5 will not be implicitly convertible to seqan3::dna5.

struct my_dna5 : public seqan3::dna5
{
// using seqan3::dna5::dna5; // uncomment to import implicit conversion shown by letter1
};
struct my_rna5 : public seqan3::rna5
{};
int main()
{
using namespace seqan3::literals;
// my_dna5 letter1 = 'C'_rna5; // NO automatic implicit conversion!
// seqan3::dna5 letter2 = my_rna5{}; // seqan3::dna5 only allows implicit conversion from seqan3::rna5!
}