From eea8665dcd3924464add4c1f63bfa0329fd4b6dc Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Sat, 19 Dec 2020 23:03:31 +0800 Subject: [PATCH] Add DNA transcription functions --- src/game/genetics/crossover.hpp | 6 ++-- src/game/genetics/mutate.hpp | 6 ++-- .../genetics/{trait.hpp => transcribe.hpp} | 36 ++++++++++++++----- src/game/genetics/translate.hpp | 8 ++--- 4 files changed, 37 insertions(+), 19 deletions(-) rename src/game/genetics/{trait.hpp => transcribe.hpp} (50%) diff --git a/src/game/genetics/crossover.hpp b/src/game/genetics/crossover.hpp index 4cae2ed..7bb3eaf 100644 --- a/src/game/genetics/crossover.hpp +++ b/src/game/genetics/crossover.hpp @@ -17,8 +17,8 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_CROSSOVER_HPP -#define ANTKEEPER_CROSSOVER_HPP +#ifndef ANTKEEPER_DNA_CROSSOVER_HPP +#define ANTKEEPER_DNA_CROSSOVER_HPP #include #include @@ -85,4 +85,4 @@ void crossover_n(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, Size co } // namespace dna -#endif // ANTKEEPER_CROSSOVER_HPP +#endif // ANTKEEPER_DNA_CROSSOVER_HPP diff --git a/src/game/genetics/mutate.hpp b/src/game/genetics/mutate.hpp index d4dc2d2..fee49eb 100644 --- a/src/game/genetics/mutate.hpp +++ b/src/game/genetics/mutate.hpp @@ -17,8 +17,8 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_MUTATE_HPP -#define ANTKEEPER_MUTATE_HPP +#ifndef ANTKEEPER_DNA_MUTATE_HPP +#define ANTKEEPER_DNA_MUTATE_HPP #include #include @@ -80,4 +80,4 @@ void mutate_n(ForwardIt first, ForwardIt last, Size count, UnaryOperation unary_ } // namespace dna -#endif // ANTKEEPER_MUTATE_HPP +#endif // ANTKEEPER_DNA_MUTATE_HPP diff --git a/src/game/genetics/trait.hpp b/src/game/genetics/transcribe.hpp similarity index 50% rename from src/game/genetics/trait.hpp rename to src/game/genetics/transcribe.hpp index 5d019ff..237c3fc 100644 --- a/src/game/genetics/trait.hpp +++ b/src/game/genetics/transcribe.hpp @@ -17,24 +17,42 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_TRAIT_HPP -#define ANTKEEPER_TRAIT_HPP +#ifndef ANTKEEPER_DNA_TRANSCRIBE_HPP +#define ANTKEEPER_DNA_TRANSCRIBE_HPP + +#include namespace dna { -template -T mendelian_variant(T x) +/** + * Transcribes DNA into RNA, replacing all occurences of `T` with `U`. + * + * @param first,last Range of DNA bases to transcribe. + */ +template +void transcribe(ForwardIt first, ForwardIt last); + +/** + * Transcribes RNA back into DNA, replacing all occurences of `U` with `T`. + * + * @param first,last Range of RNA bases to transcribe. + */ +template +void untranscribe(ForwardIt first, ForwardIt last); + +template +void transcribe(ForwardIt first, ForwardIt last) { - return !!x; + std::replace(first, last, 'T', 'U'); } -template -T nonmendelian_variant(T x) +template +void untranscribe(ForwardIt first, ForwardIt last) { - return popcount(x); + std::replace(first, last, 'U', 'T'); } } // namespace dna -#endif // ANTKEEPER_TRAIT_HPP +#endif // ANTKEEPER_DNA_TRANSCRIBE_HPP diff --git a/src/game/genetics/translate.hpp b/src/game/genetics/translate.hpp index 327fa52..c071cc9 100644 --- a/src/game/genetics/translate.hpp +++ b/src/game/genetics/translate.hpp @@ -17,8 +17,8 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_TRANSLATE_HPP -#define ANTKEEPER_TRANSLATE_HPP +#ifndef ANTKEEPER_DNA_TRANSLATE_HPP +#define ANTKEEPER_DNA_TRANSLATE_HPP #include #include @@ -27,7 +27,7 @@ namespace dna { -/// Standard genetic code translation table. +/// DNA translation table for standard genetic code. constexpr char* standard_code = "FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG" // Amino acid "---M------**--*----M---------------M----------------------------" // Start/stop @@ -202,4 +202,4 @@ OutputIt translate(InputIt1 first, InputIt1 last, InputIt2 t_first, OutputIt d_f } // namespace dna -#endif // ANTKEEPER_TRANSLATE_HPP +#endif // ANTKEEPER_DNA_TRANSLATE_HPP