From 73fefea5c6a60121be57335dd8e13cc55ede529a Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Tue, 22 Dec 2020 22:24:32 +0800 Subject: [PATCH] Add transcribe function --- src/game/genetics/transcribe.hpp | 46 ++++++++++++++++++++++++++++++++ src/game/genetics/translate.hpp | 3 +++ 2 files changed, 49 insertions(+) create mode 100644 src/game/genetics/transcribe.hpp diff --git a/src/game/genetics/transcribe.hpp b/src/game/genetics/transcribe.hpp new file mode 100644 index 0000000..b87da6e --- /dev/null +++ b/src/game/genetics/transcribe.hpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2020 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_DNA_TRANSCRIBE_HPP +#define ANTKEEPER_DNA_TRANSCRIBE_HPP + +#include "nucleobase.hpp" +#include + +namespace dna { + +/** + * Transcribes a range of IUPAC degenerate base symbols between DNA and RNA, swapping `T` for `U` or `U` for `T`. + * + * @param first,last Range of elements to transcribe. + * @param d_first Beginning of the destination range. + * @return Output iterator to the element past the last element transcribed. + */ +template +OutputIt transcribe(InputIt first, InputIt last, OutputIt d_first); + +template +OutputIt transcribe(InputIt first, InputIt last, OutputIt d_first) +{ + return std::transform(first, last, d_first, base::transcribe); +} + +} // namespace dna + +#endif // ANTKEEPER_DNA_TRANSCRIBE_HPP diff --git a/src/game/genetics/translate.hpp b/src/game/genetics/translate.hpp index e336570..02ef693 100644 --- a/src/game/genetics/translate.hpp +++ b/src/game/genetics/translate.hpp @@ -33,6 +33,9 @@ namespace dna { * @param binary_op Binary operation function object that will be applied to each subrange of @p n elements. * @return Output iterator to the element past the last element translated. */ +template +OutputIt translate(InputIt first, InputIt last, OutputIt d_first, Size n, BinaryOperation binary_op); + template OutputIt translate(InputIt first, InputIt last, OutputIt d_first, Size n, BinaryOperation binary_op) {