💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
3.0 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_GENETICS_CODON_HPP
  20. #define ANTKEEPER_GENETICS_CODON_HPP
  21. namespace genetics {
  22. /// Functions and structures related to triplets of IUPAC base symbols.
  23. namespace codon {
  24. /**
  25. * Table for translating codons to amino acids.
  26. *
  27. * @see https://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi
  28. */
  29. struct table
  30. {
  31. /// String of 64 IUPAC amino acid base symbols, in TCAG order.
  32. const char* aas;
  33. /// String of 64 IUPAC amino acid base symbols, in TCAG order, where symbols other than `-` and `*` indicate a start codon and its amino acid.
  34. const char* starts;
  35. };
  36. /**
  37. * Returns `true` if a codon is a start codon.
  38. *
  39. * @param base1 IUPAC base code of first nucleobase, either `U`, `T`, `C`, `A`, or `G`.
  40. * @param base2 IUPAC base code of second nucleobase, either `U`, `T`, `C`, `A`, or `G`.
  41. * @param base3 IUPAC base code of third nucleobase, either `U`, `T`, `C`, `A`, or `G`.
  42. * @param starts String of 64 IUPAC amino acid codes, in TCAG order.
  43. * @return `true` if the codon is a start codon, `false` otherwise.
  44. */
  45. bool is_start(char base1, char base2, char base3, const char* starts);
  46. /**
  47. * Returns `true` if a codon is a stop codon.
  48. *
  49. * @param base1 IUPAC base code of first nucleobase, either `U`, `T`, `C`, `A`, or `G`.
  50. * @param base2 IUPAC base code of second nucleobase, either `U`, `T`, `C`, `A`, or `G`.
  51. * @param base3 IUPAC base code of third nucleobase, either `U`, `T`, `C`, `A`, or `G`.
  52. * @param aas String of 64 IUPAC amino acid codes, in TCAG order.
  53. * @return `true` if the codon is a stop codon, `false` otherwise.
  54. */
  55. bool is_stop(char base1, char base2, char base3, const char* aas);
  56. /**
  57. * Translates a codon into an amino acid.
  58. *
  59. * @param base1 IUPAC base code of first nucleobase, either `U`, `T`, `C`, `A`, or `G`.
  60. * @param base2 IUPAC base code of second nucleobase, either `U`, `T`, `C`, `A`, or `G`.
  61. * @param base3 IUPAC base code of third nucleobase, either `U`, `T`, `C`, `A`, or `G`.
  62. * @param aas String of 64 IUPAC amino acid codes, in TCAG order.
  63. * @return IUPAC amino acid code of corresponding amino acid, or `-` if an invalid codon was supplied.
  64. */
  65. char translate(char base1, char base2, char base3, const char* aas);
  66. } // namspace codon
  67. } // namespace genetics
  68. #endif // ANTKEEPER_GENETICS_CODON_HPP