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

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

int main()
{
using namespace seqan3::literals;
seqan3::rna15 letter1 = 'C'_dna15; // implicitly converted
seqan3::rna15 letter2{};
letter2 = 'C'_dna15; // implicitly converted
}
The 15 letter RNA alphabet, containing all IUPAC smybols minus the gap..
Definition rna15.hpp:51
Provides seqan3::dna15, container aliases and string literals.
The SeqAn namespace for literals.
Provides seqan3::rna15, container aliases and string literals.


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

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


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

#include <vector>
int main()
{
using namespace seqan3::literals;
seqan3::rna15_vector vector = "ACG"_rna15;
auto dna15_view = vector | seqan3::views::convert<seqan3::dna15>;
for (auto && chr: dna15_view) // converts lazily on-the-fly
{
static_assert(std::same_as<decltype(chr), seqan3::dna15 &&>);
}
}
The 15 letter DNA alphabet, containing all IUPAC smybols minus the gap..
Definition dna15.hpp:51
Provides seqan3::views::convert.


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

struct my_rna15 : public seqan3::rna15
{
// using seqan3::rna15::rna15; // uncomment to import implicit conversion shown by letter1
};
struct my_dna15 : public seqan3::dna15
{};
int main()
{
using namespace seqan3::literals;
// my_rna15 letter1 = 'C'_dna15; // NO automatic implicit conversion!
// seqan3::rna15 letter2 = my_dna15{}; // seqan3::rna15 only allows implicit conversion from seqan3::dna15!
}