Loading...
Searching...
No Matches
seqan3::dna4 Class Reference
Alphabet » Nucleotide

The four letter DNA alphabet of A,C,G,T. More...

`#include <seqan3/alphabet/nucleotide/dna4.hpp>`

Inheritance diagram for seqan3::dna4:
[legend]

## Public Member Functions

constexpr dna4 | complement () const noexcept
| Returns the complement of the current nucleotide.
Constructors, destructor and assignment
constexpr | dna4 () noexcept=default
| Defaulted.
constexpr | dna4 (dna4 const &) noexcept=default
| Defaulted.
constexpr | dna4 (dna4 &&) noexcept=default
| Defaulted.
constexpr dna4 & | operator= (dna4 const &) noexcept=default
| Defaulted.
constexpr dna4 & | operator= (dna4 &&) noexcept=default
| Defaulted.
| ~dna4 () noexcept=default
| Defaulted.
template<std::same_as< rna4 > t>
constexpr | dna4 (t const &r) noexcept
| Allow implicit construction from seqan3::rna4 of the same size.
Public Member Functions inherited from seqan3::nucleotide_base< dna4, 4 >
constexpr rank_type | to_rank () const noexcept
| Return the letter's numeric value (rank in the alphabet).
constexpr dna4 | complement () const noexcept
| Return the complement of the letter.
constexpr | nucleotide_base (other_nucl_type const &other) noexcept
| Allow explicit construction from any other nucleotide type and convert via the character representation.
Public Member Functions inherited from seqan3::alphabet_base< derived_type, size, char_t >
constexpr | alphabet_base () noexcept=default
| Defaulted.
constexpr | alphabet_base (alphabet_base const &) noexcept=default
| Defaulted.
constexpr | alphabet_base (alphabet_base &&) noexcept=default
| Defaulted.
constexpr alphabet_base & | operator= (alphabet_base const &) noexcept=default
| Defaulted.
constexpr alphabet_base & | operator= (alphabet_base &&) noexcept=default
| Defaulted.
| ~alphabet_base () noexcept=default
| Defaulted.
constexpr char_type | to_char () const noexcept
| Return the letter as a character of char_type.
constexpr rank_type | to_rank () const noexcept
| Return the letter's numeric value (rank in the alphabet).
constexpr derived_type & | assign_char (char_type const chr) noexcept
| Assign from a character, implicitly converts invalid characters.
constexpr derived_type & | assign_rank (rank_type const c) noexcept
| Assign from a numeric value.

## Related Symbols

(Note that these are not member symbols.)
using | dna4_vector = std::vector<dna4>
| Alias for a std::vector of seqan3::dna4.
Nucleotide literals
constexpr dna4 | operator""_dna4 (char const c) noexcept
| The seqan3::dna4 char literal.
constexpr dna4_vector | operator""_dna4 (char const *s, std::size_t n)
| The seqan3::dna4 string literal.

## Additional Inherited Members

Static Public Member Functions inherited from seqan3::nucleotide_base< dna4, 4 >
static constexpr bool | char_is_valid (char_type const c) noexcept
| Validate whether a character value has a one-to-one mapping to an alphabet value.
Static Public Attributes inherited from seqan3::nucleotide_base< dna4, 4 >
static constexpr detail::min_viable_uint_t< size > | alphabet_size
| The size of the alphabet, i.e. the number of different values it can take.
Static Public Attributes inherited from seqan3::alphabet_base< derived_type, size, char_t >
static constexpr detail::min_viable_uint_t< size > | alphabet_size = size
| The size of the alphabet, i.e. the number of different values it can take.
Protected Types inherited from seqan3::alphabet_base< derived_type, size, char_t >
using | char_type = std::conditional_t<std::same_as<char_t, void>, char, char_t>
| The char representation; conditional needed to make semi alphabet definitions legal.
using | rank_type = detail::min_viable_uint_t<size - 1>
| The type of the alphabet when represented as a number (e.g. via to_rank()).

## Detailed Description

The four letter DNA alphabet of A,C,G,T.

Note that you can assign 'U' as a character to dna4 and it will silently be converted to 'T'.

Like most alphabets, this alphabet cannot be initialised directly from its character representation. Instead initialise/assign from the character literal 'A'_dna4 or use the function seqan3::dna4::assign_char().

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna4 letter{'C'_dna4};
letter.assign_char('F'); // Characters other than IUPAC characters are implicitly converted to A.
seqan3::debug_stream << letter << '\n'; // prints "A"
// IUPAC characters are implicitly converted to their best fitting representative
seqan3::debug_stream << letter.assign_char('R') << '\n'; // prints "A"
seqan3::debug_stream << letter.assign_char('Y') << '\n'; // prints "C"
seqan3::debug_stream << letter.assign_char('S') << '\n'; // prints "C"
seqan3::debug_stream << letter.assign_char('W') << '\n'; // prints "A"
seqan3::debug_stream << letter.assign_char('K') << '\n'; // prints "G"
seqan3::debug_stream << letter.assign_char('M') << '\n'; // prints "A"
seqan3::debug_stream << letter.assign_char('B') << '\n'; // prints "C"
seqan3::debug_stream << letter.assign_char('D') << '\n'; // prints "A"
seqan3::debug_stream << letter.assign_char('H') << '\n'; // prints "A"
seqan3::debug_stream << letter.assign_char('V') << '\n'; // prints "A"
letter.assign_char('a'); // Lower case letters are the same as their upper case equivalent.
seqan3::debug_stream << letter << '\n'; // prints "A"
}
seqan3::alphabet_base::assign_char
constexpr derived_type & assign_char(char_type const chr) noexcept
Assign from a character, implicitly converts invalid characters.
Definition alphabet_base.hpp:160
seqan3::dna4
The four letter DNA alphabet of A,C,G,T.
Definition dna4.hpp:50
debug_stream.hpp
Provides seqan3::debug_stream and related types.
dna4.hpp
Provides seqan3::dna4, container aliases and string literals.
seqan3::debug_stream
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition debug_stream.hpp:38
seqan3::literals
The SeqAn namespace for literals.

If the special char conversion of IUPAC characters is not your desired behaviour, refer to our cookbook for an example of A custom dna4 alphabet that converts all unknown characters to A to change the conversion behaviour.

This entity is stable. Since version 3.1.

## Constructor & Destructor Documentation

## dna4()

template<std::same_as< rna4 > t>

seqan3::dna4::dna4 | ( | t const & | r | ) |

inline constexpr noexcept

Allow implicit construction from seqan3::rna4 of the same size.

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

#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/nucleotide/rna4.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna4 letter1 = 'C'_rna4; // implicitly converted
seqan3::dna4 letter2{};
letter2 = 'C'_rna4; // implicitly converted
}

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

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

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

#include <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/nucleotide/rna4.hpp>
#include <seqan3/utility/views/convert.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna4_vector vector = "ACG"_dna4;
auto rna4_view = vector | seqan3::views::convert<seqan3::rna4>;
for (auto && chr : rna4_view) // converts lazily on-the-fly
{
static_assert(std::same_as<decltype(chr), seqan3::rna4 &&>);
}
}

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

#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/nucleotide/rna4.hpp>
struct my_dna4 : public seqan3::dna4
{
// using seqan3::dna4::dna4; // uncomment to import implicit conversion shown by letter1
};
struct my_rna4 : public seqan3::rna4
{};
int main()
{
using namespace seqan3::literals;
// my_dna4 letter1 = 'C'_rna4; // NO automatic implicit conversion!
// seqan3::dna4 letter2 = my_rna4{}; // seqan3::dna4 only allows implicit conversion from seqan3::rna4!
}

This entity is stable. Since version 3.1.

## Friends And Related Symbol Documentation

## dna4_vector

using dna4_vector = std::vector<dna4>

related

Alias for a std::vector of seqan3::dna4.

This entity is stable. Since version 3.1.

## operator""_dna4() [1/2]

dna4_vector operator""_dna4 | ( | char const * | s,
|  | std::size_t | n )

related

The seqan3::dna4 string literal.

Returns
  seqan3::dna4_vector You can use this string literal to easily assign to dna4_vector:
  // SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
  // SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
  // SPDX-License-Identifier: CC0-1.0
  // generated from test/snippet/alphabet/nucleotide/@target_alphabet@_literal.cpp.in
  #include <seqan3/alphabet/nucleotide/dna4.hpp>
  int main()
  {
  using namespace seqan3::literals;
  seqan3::dna4_vector sequence1{"ACGTTA"_dna4};
  seqan3::dna4_vector sequence2 = "ACGTTA"_dna4;
  auto sequence3 = "ACGTTA"_dna4;
  }

This entity is stable. Since version 3.1.

## operator""_dna4() [2/2]

dna4 operator""_dna4 | ( | char const | c | ) |

related

The seqan3::dna4 char literal.

Returns
  seqan3::dna4

You can use this char literal to assign a seqan3::dna4 character:

#include <seqan3/alphabet/nucleotide/dna4.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna4 letter1{'A'_dna4};
auto letter2 = 'A'_dna4;
}

This entity is stable. Since version 3.1.

The documentation for this class was generated from the following file:

- dna4.hpp

Hide me