Browse Source

Add DNA transcription functions

master
C. J. Howard 3 years ago
parent
commit
eea8665dcd
4 changed files with 37 additions and 19 deletions
  1. +3
    -3
      src/game/genetics/crossover.hpp
  2. +3
    -3
      src/game/genetics/mutate.hpp
  3. +27
    -9
      src/game/genetics/transcribe.hpp
  4. +4
    -4
      src/game/genetics/translate.hpp

+ 3
- 3
src/game/genetics/crossover.hpp View File

@ -17,8 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_CROSSOVER_HPP
#define ANTKEEPER_CROSSOVER_HPP
#ifndef ANTKEEPER_DNA_CROSSOVER_HPP
#define ANTKEEPER_DNA_CROSSOVER_HPP
#include <algorithm>
#include <iterator>
@ -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

+ 3
- 3
src/game/genetics/mutate.hpp View File

@ -17,8 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_MUTATE_HPP
#define ANTKEEPER_MUTATE_HPP
#ifndef ANTKEEPER_DNA_MUTATE_HPP
#define ANTKEEPER_DNA_MUTATE_HPP
#include <algorithm>
#include <iterator>
@ -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

src/game/genetics/trait.hpp → src/game/genetics/transcribe.hpp View File

@ -17,24 +17,42 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_TRAIT_HPP
#define ANTKEEPER_TRAIT_HPP
#ifndef ANTKEEPER_DNA_TRANSCRIBE_HPP
#define ANTKEEPER_DNA_TRANSCRIBE_HPP
#include <algorithm>
namespace dna
{
template <typename T>
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 <class ForwardIt>
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 <class ForwardIt>
void untranscribe(ForwardIt first, ForwardIt last);
template <class ForwardIt>
void transcribe(ForwardIt first, ForwardIt last)
{
return !!x;
std::replace(first, last, 'T', 'U');
}
template <typename T>
T nonmendelian_variant(T x)
template <class ForwardIt>
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

+ 4
- 4
src/game/genetics/translate.hpp View File

@ -17,8 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_TRANSLATE_HPP
#define ANTKEEPER_TRANSLATE_HPP
#ifndef ANTKEEPER_DNA_TRANSLATE_HPP
#define ANTKEEPER_DNA_TRANSLATE_HPP
#include <algorithm>
#include <cstdint>
@ -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

Loading…
Cancel
Save