20 #ifndef ANTKEEPER_GENETICS_SEQUENCE_HPP
21 #define ANTKEEPER_GENETICS_SEQUENCE_HPP
39 template <
class Iterator>
57 template <
class ForwardIt1,
class ForwardIt2,
class URBG>
58 ForwardIt2
crossover(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, URBG&& g);
68 template <
class ForwardIt1,
class ForwardIt2,
class Size,
class URBG>
69 void crossover_n(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, Size
count, URBG&& g);
78 template <
class ForwardIt>
89 template <
class ForwardIt,
class UnaryOperation,
class URBG>
90 ForwardIt
mutate(ForwardIt first, ForwardIt last, UnaryOperation unary_op, URBG&& g);
100 template <
class ForwardIt,
class Size,
class UnaryOperation,
class URBG>
101 void mutate_n(ForwardIt first, ForwardIt last, Size
count, UnaryOperation unary_op, URBG&& g);
111 template <
class ForwardIt1,
class ForwardIt2>
112 ForwardIt1
search(ForwardIt1 first, ForwardIt1 last, ForwardIt2 s_first, ForwardIt2 s_last,
typename std::iterator_traits<ForwardIt1>::difference_type stride);
121 template <
class InputIt,
class OutputIt>
122 OutputIt
transcribe(InputIt first, InputIt last, OutputIt d_first);
132 template <
class InputIt,
class OutputIt>
145 template <
class InputIt,
class OutputIt>
146 OutputIt
complement(InputIt first, InputIt last, OutputIt d_first);
159 template <
class InputIt,
class OutputIt>
160 OutputIt
complement(InputIt first, InputIt last, OutputIt d_first);
163 template <
class ForwardIt1,
class ForwardIt2,
class URBG>
164 ForwardIt2
crossover(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, URBG&& g)
166 typedef typename std::iterator_traits<ForwardIt1>::difference_type difference_t;
167 std::uniform_int_distribution<difference_t> distribution(0,
std::distance(first1, last1) - 1);
168 difference_t pos = distribution(g);
169 std::advance(first1, pos);
170 std::advance(first2, pos);
171 std::swap_ranges(first1, last1, first2);
175 template <
class ForwardIt1,
class ForwardIt2,
class Size,
class URBG>
176 void crossover_n(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, Size
count, URBG&& g)
178 typedef typename std::iterator_traits<ForwardIt1>::difference_type difference_t;
180 std::uniform_int_distribution<difference_t> distribution(0,
std::distance(first1, last1) - 1);
181 ForwardIt1 crossover1, crossover2;
188 difference_t pos = distribution(g);
189 std::advance(crossover1, pos);
190 std::advance(crossover2, pos);
191 std::swap_ranges(crossover1, last1, crossover2);
197 template <
class ForwardIt>
217 result.
start = first;
227 while (third != last);
246 template <
class ForwardIt,
class UnaryOperation,
class URBG>
247 ForwardIt
mutate(ForwardIt first, ForwardIt last, UnaryOperation unary_op, URBG&& g)
249 typedef typename std::iterator_traits<ForwardIt>::difference_type difference_t;
254 std::uniform_int_distribution<difference_t> distribution(0,
std::distance(first, last) - 1);
255 std::advance(first, distribution(g));
256 *first = unary_op(*first);
261 template <
class ForwardIt,
class Size,
class UnaryOperation,
class URBG>
262 void mutate_n(ForwardIt first, ForwardIt last, Size
count, UnaryOperation unary_op, URBG&& g)
264 typedef typename std::iterator_traits<ForwardIt>::difference_type difference_t;
269 std::uniform_int_distribution<difference_t> distribution(0,
std::distance(first, last) - 1);
275 std::advance(mutation, distribution(g));
276 *mutation = unary_op(*mutation);
281 template <
class ForwardIt1,
class ForwardIt2>
282 ForwardIt1
search(ForwardIt1 first, ForwardIt1 last, ForwardIt2 s_first, ForwardIt2 s_last,
typename std::iterator_traits<ForwardIt1>::difference_type stride)
286 ForwardIt1 it = first;
287 for (ForwardIt2 s_it = s_first; ; ++it, ++s_it)
300 std::advance(first, stride);
306 template <
class InputIt,
class OutputIt>
307 inline OutputIt
transcribe(InputIt first, InputIt last, OutputIt d_first)
312 template <
class InputIt,
class OutputIt>
319 InputIt second = first;
321 InputIt third = second;
341 template <
class InputIt,
class OutputIt>
342 inline OutputIt
complement(InputIt first, InputIt last, OutputIt d_first)
350 template <
class InputIt,
class OutputIt>
351 inline OutputIt
complement(InputIt first, InputIt last, OutputIt d_first)
constexpr int count(T x) noexcept
Returns the number of set bits in a value, known as a population count or Hamming weight.
char complement(char symbol)
Returns the DNA complement of an IUPAC degenerate base symbol.
char complement(char symbol)
Returns the RNA complement of an IUPAC degenerate base symbol.
int compare(char a, char b)
Returns the number of bases that are represented by both IUPAC degenerate base symbols.
char transcribe(char symbol)
Transcribes an IUPAC degenerate base symbol between DNA and RNA, swapping T for U or U for T.
char translate(char base1, char base2, char base3, const char *aas)
Translates a codon into an amino acid.
bool is_stop(char base1, char base2, char base3, const char *aas)
Returns true if a codon is a stop codon.
bool is_start(char base1, char base2, char base3, const char *starts)
Returns true if a codon is a start codon.
OutputIt complement(InputIt first, InputIt last, OutputIt d_first)
Generates the complementary sequence for a sequence of IUPAC degenerate DNA base symbols.
OutputIt complement(InputIt first, InputIt last, OutputIt d_first)
Generates the complementary sequence for a sequence of IUPAC degenerate RNA base symbols.
ForwardIt2 crossover(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, URBG &&g)
Exchanges elements between two ranges, starting at a random offset.
OutputIt transcribe(InputIt first, InputIt last, OutputIt d_first)
Transcribes a sequence of IUPAC base symbols between DNA and RNA, swapping T for U or U for T.
OutputIt translate(InputIt first, InputIt last, OutputIt d_first, const codon::table &table)
Translates a sequence of codons into amino acids.
void mutate_n(ForwardIt first, ForwardIt last, Size count, UnaryOperation unary_op, URBG &&g)
Applies the given function to a random selection of elements in a range.
orf< ForwardIt > find_orf(ForwardIt first, ForwardIt last, const codon::table &table)
Searches a sequence for an open reading frame (ORF).
ForwardIt mutate(ForwardIt first, ForwardIt last, UnaryOperation unary_op, URBG &&g)
Applies the given function to a randomly selected element in a range.
void crossover_n(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, Size count, URBG &&g)
Exchanges elements between two ranges multiple times, starting at a random offset each time.
ForwardIt1 search(ForwardIt1 first, ForwardIt1 last, ForwardIt2 s_first, ForwardIt2 s_last, typename std::iterator_traits< ForwardIt1 >::difference_type stride)
Searches a sequence of IUPAC base symbols for a pattern matching a search string of IUPAC degenerate ...
T length(const quaternion< T > &q)
Calculates the length of a quaternion.
T distance(const vector< T, N > &p0, const vector< T, N > &p1)
Calculates the distance between two points.
Table for translating codons to amino acids.
const char * aas
String of 64 IUPAC amino acid base symbols, in TCAG order.
const char * starts
String of 64 IUPAC amino acid base symbols, in TCAG order, where symbols other than - and * indicate ...
Open reading frame (ORF), defined by a start codon and stop codon, with the distance between divisibl...
Iterator start
Iterator to the first base of the start codon.
Iterator stop
Iterator to the first base of the stop codon.