Browse Source

Document genetics::protein::identity function

master
C. J. Howard 3 years ago
parent
commit
af8b516e7a
1 changed files with 25 additions and 2 deletions
  1. +25
    -2
      src/game/genetics/protein.hpp

+ 25
- 2
src/game/genetics/protein.hpp View File

@ -26,11 +26,21 @@
namespace genetics { namespace genetics {
namespace protein { namespace protein {
/**
* Returns the percent identity between two proteins.
*
* @param first1,last1 Range of IUPAC amino acids which constitute the first protein.
* @param first2 Beginning of the range of IUPAC amino acids which constitute the second protein.
* @return Percent identity between the two proteins.
*/
template <class T, class ForwardIt1, class ForwardIt2>
T identity(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2);
/** /**
* Scores two proteins using a substitution matrix. * Scores two proteins using a substitution matrix.
* *
* @param first1,last1 Sequence of IUPAC amino acid codes which constitute the first protein.
* @param first2,last2 Sequence of IUPAC amino acid codes which constitute the second protein.
* @param first1,last1 Range of IUPAC amino acid codes which constitute the first protein.
* @param first2,last2 Range of IUPAC amino acid codes which constitute the second protein.
* @param matrix Substitution matrix. * @param matrix Substitution matrix.
* @return Score of the two proteins. * @return Score of the two proteins.
*/ */
@ -46,6 +56,19 @@ typename std::remove_all_extents::type score(ForwardIt1 first1, ForwardI
return result; return result;
} }
template <class T, class ForwardIt1, class ForwardIt2>
T identity(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2)
{
auto length = std::distance(first1, last1);
T sum = 0;
for (; first1 != last1; ++first1, ++first2)
if (*first1 == *first2)
++sum;
return sum / static_cast<T>(length);
}
} // namespace protein } // namespace protein
} // namespace genetics } // namespace genetics

Loading…
Cancel
Save