DNA-sim

git clone git://git.codymlewis.com/DNA-sim.git
Log | Files | Refs | README | LICENSE

commit 4e3edc050e131f044e5947fa78fff2bfbd3c2925
parent 404bb0bd592a4a21cbf0dafe32785cb847c25a68
Author: luxdosugi <luxdotsugi@gmail.com>
Date:   Sun,  8 Jul 2018 11:36:35 +1000

Added the Codons

Diffstat:
ACodon.cpp | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ACodon.h | 38++++++++++++++++++++++++++++++++++++++
2 files changed, 118 insertions(+), 0 deletions(-)

diff --git a/Codon.cpp b/Codon.cpp @@ -0,0 +1,80 @@ +/** + * Codon.cpp - DNA_sim + * Author: Cody Lewis + * Date: 2018-07-07 + * Last Modified: 2018-07-07 + * Description: + * A Class for A codon (a collection of three mRNA bases) + */ +#include <cstdlib> +#include "Codon.h" +namespace DNA_sim { + // Constructors + Codon::Codon() { + bases.resize(3); + } + Codon::Codon(std::string input) { + Codon(); + set_bases(input); + } + // Destructor + Codon::~Codon() {} + // Queries + std::string Codon::get_bases() const { + std::string base_string; + for(std::size_t i = 0; i < bases.size(); ++i) { + switch (bases[i]) { + case Base::adenine: + base_string += 'A'; + break; + case Base::uracil: + base_string += 'U'; + break; + case Base::cytosine: + base_string += 'C'; + break; + case Base::guanine: + base_string += 'G'; + break; + default: + base_string += '_'; + } + } + return base_string; + } + // Mutators + bool Codon::set_bases(std::string input) { + int j = 0; + for(std::string::iterator it = input.begin(); it != input.end(); ++it) { + switch (*it) { + case 'A': + bases[j] = Base::adenine; + break; + case 'U': + bases[j] = Base::uracil; + break; + case 'C': + bases[j] = Base::cytosine; + break; + case 'G': + bases[j] = Base::guanine; + break; + default: + bases[j] = Base::adenine; + } + j++; + } + return true; + } + // Operator overloads + std::istream& operator>>(std::istream& in, Codon& cod) { + std::string input; + in >> input; + cod.set_bases(input); + return in; + } + std::ostream& operator<<(std::ostream& out, const Codon& cod) { + out << cod.get_bases(); + return out; + } +} diff --git a/Codon.h b/Codon.h @@ -0,0 +1,38 @@ +/** + * Codon.h - DNA_sim + * Author: Cody Lewis + * Date: 2018-07-07 + * Last Modified: 2018-07-07 + * Description: + * A Class for A codon (a collection of three mRNA bases) + */ +#ifndef CODON_h +#define CODON_h +#include <string> +#include <vector> +#include <iostream> +namespace DNA_sim { + class Codon { + private: + /* enum Base + * The invidual bases of mRNA + */ + enum Base { adenine, uracil, cytosine, guanine }; + std::vector<Base> bases; // 3 bases per codon + public: + Codon(); // Default constructor + Codon(std::string input); // Input constructor + ~Codon(); // Destructor + + // Queries + std::string get_bases() const; + + // Mutators + bool set_bases(std::string input); + // TODO: Add crossover + }; + // Operator Overloads + std::istream& operator>>(std::istream& in, Codon& cod); // input + std::ostream& operator<<(std::ostream& out, const Codon& cod); // output +} +#endif /* ifndef CODON_h */