CS 19: Protein Class
Public Member Functions | Friends | List of all members
cs19::Protein Class Reference

Represents the primary structure of a protein as a sequence of amino acids. More...

#include <cs19_protein.h>

Public Member Functions

 Protein ()
 Constructs a new "empty" Protein (i.e. More...
 
 Protein (const char *amino_acids)
 Constructs a new Protein object with an initial primary structure. More...
 
template<typename Sequence >
 Protein (const Sequence &amino_acids)
 Constructs a new Protein object with an initial primary structure. More...
 
template<class InputIterator >
 Protein (InputIterator first, InputIterator last)
 Constructs a new Protein object from a range of values [first, last). More...
 
 Protein (std::initializer_list< char > list)
 Constructs a new Protein object with an initial primary structure. More...
 
char operator[] (std::size_t index) const
 Returns the amino-acid character at a specified index in this protein. More...
 
template<typename Sequence >
Protein operator+ (const Sequence &that) const
 Returns a concatenation of this protein with another. More...
 
Protein operator+ (const char *that) const
 Returns a concatenation of this protein with another. More...
 
Protein operator* (std::size_t repeat_count) const
 Returns a repeated concatenation of this protein. More...
 
template<typename Sequence >
bool operator== (const Sequence &that) const
 Determines whether this protein's sequence of amino acids is equal to another sequence. More...
 
template<typename Sequence >
bool operator!= (const Sequence &that) const
 Determines whether this protein's sequence of amino acids is not equal to another sequence. More...
 
bool operator== (const char *that) const
 Determines whether this protein's sequence of amino acids is equal to another sequence. More...
 
bool operator!= (const char *that) const
 Determines whether this protein's sequence of amino acids is not equal to another sequence. More...
 
auto begin () const
 Returns an iterator pointing to the first amino acid in this protein. More...
 
auto end () const
 Returns an iterator referring to the past-the-end element in this protein. More...
 
double mass () const
 Computes and returns this protein's mass. More...
 
std::size_t size () const
 Returns the length of this protein's primary structure. More...
 
std::string to_string () const
 Returns a string representing the protein's amino-acid sequence. More...
 
template<typename Sequence >
Proteinoperator= (const Sequence &that)
 Replaces this protein's contents with another sequence. More...
 
Proteinoperator= (const char *that)
 Replaces this protein's contents with another sequence. More...
 
template<typename Sequence >
Proteinoperator+= (const Sequence &appendage)
 Appends a sequence of amino acids to this protein's primary structure. More...
 
Proteinoperator+= (const char *appendage)
 Appends a sequence of amino acids to this protein's primary structure. More...
 
Proteinoperator+= (char appendage)
 Appends a single amino acid to this protein's primary structure. More...
 
void set (std::size_t index, char amino_acid)
 Replaces the amino acid at a given index in this protein. More...
 

Friends

std::ostream & operator<< (std::ostream &out, const Protein &protein)
 Inserts a protein's sequence of amino-acid characters into an output stream. More...
 
std::istream & operator>> (std::istream &in, Protein &protein)
 Replaces the contents of this protein with characters extracted from an input stream, using the same rules as string extraction. More...
 

Detailed Description

Represents the primary structure of a protein as a sequence of amino acids.

Constructor & Destructor Documentation

◆ Protein() [1/5]

cs19::Protein::Protein ( )
inline

Constructs a new "empty" Protein (i.e.

with no amino acids).

◆ Protein() [2/5]

cs19::Protein::Protein ( const char *  amino_acids)
inline

Constructs a new Protein object with an initial primary structure.

Parameters
amino_acidsa C-string denoting the primary structure
Exceptions
std::domain_erroramino_acids contains any illegal characters

◆ Protein() [3/5]

template<typename Sequence >
cs19::Protein::Protein ( const Sequence &  amino_acids)
inline

Constructs a new Protein object with an initial primary structure.

Template Parameters
Sequencean iterable type assumed to contain amino-acid characters
Parameters
amino_acidsa sequence of characters denoting the primary structure
Exceptions
std::domain_errorif amino_acids contains any illegal characters

◆ Protein() [4/5]

template<class InputIterator >
cs19::Protein::Protein ( InputIterator  first,
InputIterator  last 
)
inline

Constructs a new Protein object from a range of values [first, last).

Template Parameters
InputIteratoran iterator type assumed to point to values convertible to char
Parameters
firstthe initial position in the range
lastthe final position in the range
Exceptions
std::domain_errorif the range contains any illegal characters

◆ Protein() [5/5]

cs19::Protein::Protein ( std::initializer_list< char >  list)
inline

Constructs a new Protein object with an initial primary structure.

Parameters
lista list assumed to contain amino-acid characters
Exceptions
std::domain_errorif list contains any illegal characters

Member Function Documentation

◆ begin()

auto cs19::Protein::begin ( ) const
inline

Returns an iterator pointing to the first amino acid in this protein.

Returns
a const iterator pointing to the first character in this protein's sequence

◆ end()

auto cs19::Protein::end ( ) const
inline

Returns an iterator referring to the past-the-end element in this protein.

Returns
a const iterator to the character past the end of this protein's sequence

◆ mass()

double cs19::Protein::mass ( ) const
inline

Computes and returns this protein's mass.

See: http://rosalind.info/problems/prtm/

Returns
a sum of the monoisotopic masses of this protein's amino acids

◆ operator!=() [1/2]

bool cs19::Protein::operator!= ( const char *  that) const
inline

Determines whether this protein's sequence of amino acids is not equal to another sequence.

Parameters
thata C-string with which to compare
Returns
true if that does not contain the same sequence of amino-acid characters as this protein, otherwise false

◆ operator!=() [2/2]

template<typename Sequence >
bool cs19::Protein::operator!= ( const Sequence &  that) const
inline

Determines whether this protein's sequence of amino acids is not equal to another sequence.

Template Parameters
Sequencean iterable type assumed to contain amino-acid characters
Parameters
thatthe sequence with which to compare
Returns
true if that does not contain the same sequence of amino-acid characters as this protein, otherwise false

◆ operator*()

Protein cs19::Protein::operator* ( std::size_t  repeat_count) const
inline

Returns a repeated concatenation of this protein.

Parameters
repeat_countthe desired number of concatenations
Returns
a new Protein consisting of this protein's sequence repeated repeat_count times

◆ operator+() [1/2]

Protein cs19::Protein::operator+ ( const char *  that) const
inline

Returns a concatenation of this protein with another.

Parameters
thata C-string containing the sequence to concatenate
Returns
a Protein consisting of this protein's amino acids concatenated with that
Exceptions
std::domain_errorif that contains any illegal characters

◆ operator+() [2/2]

template<typename Sequence >
Protein cs19::Protein::operator+ ( const Sequence &  that) const
inline

Returns a concatenation of this protein with another.

Template Parameters
Sequencean iterable type assumed to contain amino-acid characters
Parameters
thatthe sequence to concatenate
Returns
a Protein consisting of this protein's amino acids concatenated with that
Exceptions
std::domain_errorif that contains any illegal characters

◆ operator+=() [1/3]

Protein* cs19::Protein::operator+= ( char  appendage)
inline

Appends a single amino acid to this protein's primary structure.

Parameters
appendagea char denoting the amino acid to append
Exceptions
std::domain_errorif appendage is an illegal character

◆ operator+=() [2/3]

Protein* cs19::Protein::operator+= ( const char *  appendage)
inline

Appends a sequence of amino acids to this protein's primary structure.

Parameters
appendagea C-string denoting the amino acids to append
Exceptions
std::domain_errorif appendage contains any illegal characters

◆ operator+=() [3/3]

template<typename Sequence >
Protein* cs19::Protein::operator+= ( const Sequence &  appendage)
inline

Appends a sequence of amino acids to this protein's primary structure.

Template Parameters
Sequencean iterable type assumed to contain amino-acid characters
Parameters
appendagea sequence of characters denoting the amino acids to append
Exceptions
std::domain_errorif appendage contains any illegal characters

◆ operator=() [1/2]

Protein& cs19::Protein::operator= ( const char *  that)
inline

Replaces this protein's contents with another sequence.

Parameters
thata C-string with which to replace this protein's contents
Exceptions
std::domain_errorif that contains any illegal characters

◆ operator=() [2/2]

template<typename Sequence >
Protein& cs19::Protein::operator= ( const Sequence &  that)
inline

Replaces this protein's contents with another sequence.

Template Parameters
Sequencean iterable type assumed to contain amino-acid characters
Parameters
thatthe sequence with which to replace this protein's contents
Exceptions
std::domain_errorif that contains any illegal characters

◆ operator==() [1/2]

bool cs19::Protein::operator== ( const char *  that) const
inline

Determines whether this protein's sequence of amino acids is equal to another sequence.

Parameters
thata C-string with which to compare
Returns
true if that contains the same sequence of amino-acid characters as this protein, otherwise false

◆ operator==() [2/2]

template<typename Sequence >
bool cs19::Protein::operator== ( const Sequence &  that) const
inline

Determines whether this protein's sequence of amino acids is equal to another sequence.

Template Parameters
Sequencean iterable type assumed to contain amino-acid characters
Parameters
thatthe sequence with which to compare
Returns
true if that contains the same sequence of amino-acid characters as this protein, otherwise false

◆ operator[]()

char cs19::Protein::operator[] ( std::size_t  index) const
inline

Returns the amino-acid character at a specified index in this protein.

Parameters
indexthe desired index in the sequence
Returns
the value a the requested index
Exceptions
std::out_of_rangeif index is an invalid index in this protein

◆ set()

void cs19::Protein::set ( std::size_t  index,
char  amino_acid 
)
inline

Replaces the amino acid at a given index in this protein.

Parameters
indexthe index of the amino acid to replace
amino_acidthe replacement amino acid
Exceptions
std::domain_errorif amino_acid is an illegal character
std::out_of_rangeif index is an invalid index in this protein

◆ size()

std::size_t cs19::Protein::size ( ) const
inline

Returns the length of this protein's primary structure.

Returns
the number of amino acids in this protein's primary structure

◆ to_string()

std::string cs19::Protein::to_string ( ) const
inline

Returns a string representing the protein's amino-acid sequence.

Returns
a string containing the amino-acid characters in this protein's primary structure.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const Protein protein 
)
friend

Inserts a protein's sequence of amino-acid characters into an output stream.

Parameters
outthe destination stream
proteinthe Protein from which to insert
Returns
out

◆ operator>>

std::istream& operator>> ( std::istream &  in,
Protein protein 
)
friend

Replaces the contents of this protein with characters extracted from an input stream, using the same rules as string extraction.

Parameters
inthe source stream
proteinthe Protein receiving the characters
Returns
in
Exceptions
std::domain_errorif the token from the stream contains any illegal characters

The documentation for this class was generated from the following file: