From 461e864c49e2693252ebb22a709d421221354faf Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Sun, 3 Jan 2021 22:59:04 +0800 Subject: [PATCH] Move genetics folder out of game folder, document subnamespaces of genetics namespace, move genetics::translation_table to genetics::codon::table --- CMakeLists.txt | 1 - src/game/states/play-state.cpp | 2 +- src/{game => }/genetics/amino-acid.hpp | 2 ++ src/{game => }/genetics/base.cpp | 0 src/{game => }/genetics/base.hpp | 4 ++++ src/{game => }/genetics/codon.cpp | 0 src/{game => }/genetics/codon.hpp | 16 +++++++++++++ src/{game => }/genetics/genetics.hpp | 2 +- src/{game => }/genetics/matrix.hpp | 2 ++ src/{game => }/genetics/protein.hpp | 2 ++ src/{game => }/genetics/sequence.hpp | 13 ++++++---- .../standard-code.hpp} | 24 +++++++------------ 12 files changed, 44 insertions(+), 24 deletions(-) rename src/{game => }/genetics/amino-acid.hpp (96%) rename src/{game => }/genetics/base.cpp (100%) rename src/{game => }/genetics/base.hpp (90%) rename src/{game => }/genetics/codon.cpp (100%) rename src/{game => }/genetics/codon.hpp (84%) rename src/{game => }/genetics/genetics.hpp (96%) rename src/{game => }/genetics/matrix.hpp (99%) rename src/{game => }/genetics/protein.hpp (98%) rename src/{game => }/genetics/sequence.hpp (95%) rename src/{game/genetics/translation-table.hpp => genetics/standard-code.hpp} (65%) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc40e61..d4aa351 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,6 @@ find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG) find_package(OpenAL REQUIRED CONFIG) find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib") - # Determine dependencies set(STATIC_LIBS dr_wav diff --git a/src/game/states/play-state.cpp b/src/game/states/play-state.cpp index b428f29..a91f8e7 100644 --- a/src/game/states/play-state.cpp +++ b/src/game/states/play-state.cpp @@ -63,7 +63,7 @@ #include "utility/gamma.hpp" #include "utility/bit-math.hpp" -#include "game/genetics/genetics.hpp" +#include "genetics/genetics.hpp" #include #include #include diff --git a/src/game/genetics/amino-acid.hpp b/src/genetics/amino-acid.hpp similarity index 96% rename from src/game/genetics/amino-acid.hpp rename to src/genetics/amino-acid.hpp index 3a5b86f..58fe68d 100644 --- a/src/game/genetics/amino-acid.hpp +++ b/src/genetics/amino-acid.hpp @@ -23,6 +23,8 @@ #include namespace genetics { + +/// Functions which operate on IUPAC amino acid symbols. namespace amino_acid { /** diff --git a/src/game/genetics/base.cpp b/src/genetics/base.cpp similarity index 100% rename from src/game/genetics/base.cpp rename to src/genetics/base.cpp diff --git a/src/game/genetics/base.hpp b/src/genetics/base.hpp similarity index 90% rename from src/game/genetics/base.hpp rename to src/genetics/base.hpp index c4c491e..95789cc 100644 --- a/src/game/genetics/base.hpp +++ b/src/genetics/base.hpp @@ -21,6 +21,8 @@ #define ANTKEEPER_GENETICS_BASE_HPP namespace genetics { + +/// Functions which operate on IUPAC degenerate base symbols. namespace base { /** @@ -40,6 +42,7 @@ int compare(char a, char b); */ char transcribe(char symbol); +/// Functions which operate on IUPAC degenerate **DNA** base symbols. namespace dna { /** @@ -51,6 +54,7 @@ namespace dna char complement(char symbol); } +/// Functions which operate on IUPAC degenerate **RNA** base symbols. namespace rna { /** diff --git a/src/game/genetics/codon.cpp b/src/genetics/codon.cpp similarity index 100% rename from src/game/genetics/codon.cpp rename to src/genetics/codon.cpp diff --git a/src/game/genetics/codon.hpp b/src/genetics/codon.hpp similarity index 84% rename from src/game/genetics/codon.hpp rename to src/genetics/codon.hpp index 55ee538..18d9539 100644 --- a/src/game/genetics/codon.hpp +++ b/src/genetics/codon.hpp @@ -21,8 +21,24 @@ #define ANTKEEPER_GENETICS_CODON_HPP namespace genetics { + +/// Functions and structures related to triplets of IUPAC base symbols. namespace codon { +/** + * Table for translating codons to amino acids. + * + * @see https://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi + */ +struct table +{ + /// String of 64 IUPAC amino acid base symbols, in TCAG order. + const char* aas; + + /// String of 64 IUPAC amino acid base symbols, in TCAG order, where symbols other than `-` and `*` indicate a start codon and its amino acid. + const char* starts; +}; + /** * Returns `true` if a codon is a start codon. * diff --git a/src/game/genetics/genetics.hpp b/src/genetics/genetics.hpp similarity index 96% rename from src/game/genetics/genetics.hpp rename to src/genetics/genetics.hpp index 07ab23b..ae38006 100644 --- a/src/game/genetics/genetics.hpp +++ b/src/genetics/genetics.hpp @@ -29,6 +29,6 @@ namespace genetics {} #include "matrix.hpp" #include "protein.hpp" #include "sequence.hpp" -#include "translation-table.hpp" +#include "standard-code.hpp" #endif // ANTKEEPER_GENETICS_HPP diff --git a/src/game/genetics/matrix.hpp b/src/genetics/matrix.hpp similarity index 99% rename from src/game/genetics/matrix.hpp rename to src/genetics/matrix.hpp index 5235f0f..098bb13 100644 --- a/src/game/genetics/matrix.hpp +++ b/src/genetics/matrix.hpp @@ -21,6 +21,8 @@ #define ANTKEEPER_GENETICS_MATRIX_HPP namespace genetics { + +/// Substitution matrix constants. namespace matrix { /** diff --git a/src/game/genetics/protein.hpp b/src/genetics/protein.hpp similarity index 98% rename from src/game/genetics/protein.hpp rename to src/genetics/protein.hpp index ca34cf8..c016671 100644 --- a/src/game/genetics/protein.hpp +++ b/src/genetics/protein.hpp @@ -24,6 +24,8 @@ #include namespace genetics { + +/// Functions which operate on sequences of IUPAC amino acid symbols. namespace protein { /** diff --git a/src/game/genetics/sequence.hpp b/src/genetics/sequence.hpp similarity index 95% rename from src/game/genetics/sequence.hpp rename to src/genetics/sequence.hpp index c74f1b1..9608643 100644 --- a/src/game/genetics/sequence.hpp +++ b/src/genetics/sequence.hpp @@ -22,12 +22,13 @@ #include "base.hpp" #include "codon.hpp" -#include "translation-table.hpp" #include #include #include namespace genetics { + +/// Functions and structures related to sequences of IUPAC degenerate base symbols. namespace sequence { /** @@ -75,7 +76,7 @@ void crossover_n(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, Size co * @return First ORF in the sequence, or `{last, last}` if no ORF was found. */ template -orf find_orf(ForwardIt first, ForwardIt last, const translation_table& table); +orf find_orf(ForwardIt first, ForwardIt last, const codon::table& table); /** * Applies the given function to a randomly selected element in a range. @@ -129,8 +130,9 @@ OutputIt transcribe(InputIt first, InputIt last, OutputIt d_first); * @return Output iterator to the element past the last element translated. */ template -OutputIt translate(InputIt first, InputIt last, OutputIt d_first, const translation_table& table); +OutputIt translate(InputIt first, InputIt last, OutputIt d_first, const codon::table& table); +/// Functions which operate on sequences of IUPAC degenerate **DNA** base symbols. namespace dna { /** @@ -144,6 +146,7 @@ namespace dna OutputIt complement(InputIt first, InputIt last, OutputIt d_first); } +/// Functions which operate on sequences of IUPAC degenerate **RNA** base symbols. namespace rna { /** @@ -192,7 +195,7 @@ void crossover_n(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, Size co } template -orf find_orf(ForwardIt first, ForwardIt last, const translation_table& table) +orf find_orf(ForwardIt first, ForwardIt last, const codon::table& table) { ForwardIt second; ForwardIt third; @@ -307,7 +310,7 @@ inline OutputIt transcribe(InputIt first, InputIt last, OutputIt d_first) } template -OutputIt translate(InputIt first, InputIt last, OutputIt d_first, const translation_table& table) +OutputIt translate(InputIt first, InputIt last, OutputIt d_first, const codon::table& table) { auto length = std::distance(first, last); diff --git a/src/game/genetics/translation-table.hpp b/src/genetics/standard-code.hpp similarity index 65% rename from src/game/genetics/translation-table.hpp rename to src/genetics/standard-code.hpp index b646402..3e66b20 100644 --- a/src/game/genetics/translation-table.hpp +++ b/src/genetics/standard-code.hpp @@ -17,27 +17,19 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GENETICS_TRANSLATION_TABLE_HPP -#define ANTKEEPER_GENETICS_TRANSLATION_TABLE_HPP +#ifndef ANTKEEPER_GENETICS_STANDARD_CODE_HPP +#define ANTKEEPER_GENETICS_STANDARD_CODE_HPP + +#include "codon.hpp" namespace genetics { /** - * Genetic code translation table. + * Codon table for standard genetic code. * - * @see https://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi + * @see https://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi#SG1 */ -struct translation_table -{ - /// String of 64 IUPAC amino acid base symbols, in TCAG order. - const char* aas; - - /// String of 64 IUPAC amino acid base symbols, in TCAG order, where symbols other than `-` and `*` indicate a start codon and its amino acid. - const char* starts; -}; - -/// Translation table for standard genetic code. -constexpr translation_table standard_code = +constexpr codon::table standard_code = { "FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG", "---M------**--*----M---------------M----------------------------", @@ -45,4 +37,4 @@ constexpr translation_table standard_code = } // namespace genetics -#endif // ANTKEEPER_GENETICS_TRANSLATION_TABLE_HPP +#endif // ANTKEEPER_GENETICS_STANDARD_CODE_HPP