diff --git a/test/gtest/EukTest_mutations.cpp b/test/gtest/EukTest_mutations.cpp new file mode 100644 index 0000000000000000000000000000000000000000..999a21a73afa091e0da8ff67f10ea3e0eb99a356 --- /dev/null +++ b/test/gtest/EukTest_mutations.cpp @@ -0,0 +1,650 @@ +// **************************************************************************** +// +// Aevol - An in silico experimental evolution platform +// +// **************************************************************************** +// +// Copyright: See the AUTHORS file provided with the package or <www.aevol.fr> +// Web: http://www.aevol.fr/ +// E-mail: See <http://www.aevol.fr/contact/> +// Original Authors : Guillaume Beslon, Carole Knibbe, David Parsons +// +// This program 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 2 of the License, or +// (at your option) any later version. +// +// This program 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 this program. If not, see <http://www.gnu.org/licenses/>. +// +//***************************************************************************** + + + + +// ================================================================= +// Includes +// ================================================================= +#include <inttypes.h> +#include <cstring> + +#include <list> +#include <vector> +#include <memory> + +#include <gtest/gtest.h> + +#include "DnaFactory.h" +#include "ExpManager_7.h" +#include "ExpSetup.h" +#include "fuzzy/FuzzyFactory_7.h" +#include "Individual_7.h" +#include "legacy/biochemistry/Rna.h" +#include "legacy/biochemistry/Protein.h" +#include "macros.h" +#include "MutationParams.h" +#include "Strand.h" + +using namespace aevol; + +//############################################################################ +// # +// Class IndividualTest # +// # +//############################################################################ +class IndividualTest : public testing::Test +{ + protected: + virtual void SetUp(void); + virtual void TearDown(void); + + // We have an version of each individual for each fuzzy set flavor + Individual_7* indiv1; + Individual_7* indiv2; + Individual_7* indiv3; + Individual_7* indiv4; + Individual_7* indiv5; + Individual_7* indiv6; + Individual_7* indiv7; + Individual_7* indiv8; + Individual_7* indiv9; + Individual_7* indiv10; +}; + +// =========================================================================== +// Public Methods +// =========================================================================== +void IndividualTest::SetUp(void) +{ + // Build ad-hoc genomes + // (and reverse to test the same things on the lagging strand.): + // + // indiv1: (prom + AS + AG + AS + term + AS + prom) + // indiv2: reverse + // indiv3: (prom-1 + AS + AG + AS + term) + // indiv4: reverse + // indiv5: (term + AS + AG + AS + prom-1) + // indiv6: reverse + // indiv7: (prom + AS + term + AS + AG + AS + prom) + // indiv8: reverse + // indiv9: (term + AS + AG + AS + prom-1) + // indiv10: reverse + // + // AS = Arbitrary Sequence + // AG = Arbitrary Gene + // Do not modify the sequences ! + + // Define a few arbitrary sequences + char as[5][10] = { + "0011", + "11101", + "110011", + "11000", + "000101" + }; + + // Define an arbitrary gene + char gene[29]; + sprintf(gene, "%s0011000100110110010001", SHINE_DAL_SEQ); + + // Define an arbitrary terminator + char term[TERM_SIZE+1] = "01000001101"; + + // Define a few arbitrary promoters + char prom[2][23] = { + "0101010001110110010110", // dist from consensus: 2 => basal level: 0.6 + "0101011001110010010010" // dist from consensus: 1 => basal level: 0.8 + }; + + char lag_prom[2][23] = { + "1001011001000111010101", // dist from consensus: 2 => basal level: 0.6 + "1011011011000110010101" // dist from consensus: 1 => basal level: 0.8 + }; + + + char bad_prom[2][23] = { + "101010001110110010110", // removed first base : add 0 at end + "010101100111001001001" // removed last base : add 0 at begin + }; + + char bad_lag_prom[2][23] = { + "001011001000111010101", // removed first base : add 1 at end + "101101101100011001010" // removed last base : add 1 at begin + }; + + + // Initialize the experimental setup. + // These are needed in the GeneticUnit constructors. + ExpSetup* exp_s = new ExpSetup(nullptr); + MutationParams params_mut; + + + // Update fuzzy flavor and fuzzy factory // TODO<dpa> Still needed/useful? + FuzzyFlavor fuzzyFlavor = FuzzyFlavor::VECTOR; + exp_s->set_fuzzy_flavor(fuzzyFlavor); + + DnaFactory* dna_factory = new DnaFactory(DnaFactory_Policy::LOCAL_GLOBAL_FIT, 48, 1000, 16); + FuzzyFactory_7* fuzzy_factory = new FuzzyFactory_7(fuzzyFlavor, 16, 300, 16); + + // Build indiv1 + // Construct a genome with these arbitrary sequences + char* genome = new char[100]; + sprintf(genome, "%s%s%s%s%s%s%s",prom[0], as[1], gene, as[2], term, as[3], lag_prom[1]); + + indiv1 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv1->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv1->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv1->annotated_chromosome_[A]; + indiv1->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv1->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv1); + + indiv1->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv1->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv1->annotated_chromosome_[B]; + indiv1->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv1->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv1); + genome = nullptr; + + // Do transcription and translation + indiv1->start_stop_RNA(); + indiv1->prom_compute_RNA(*exp_s); + indiv1->start_protein(); + indiv1->compute_protein(); + indiv1->translate_protein(*exp_s, 1.0); + + + // Build indiv2 + // Reverse the whole genome + genome = new char[100]; + std::string tmp_genome = indiv1->annotated_chromosome_[A]->dna_->subseq(0, + indiv1->annotated_chromosome_[A]->length(), + aevol::Strand::LAGGING); + strcpy(genome, tmp_genome.c_str()); + indiv2 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv2->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv2->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv2->annotated_chromosome_[A]; + indiv2->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv2->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv2); + + indiv2->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv2->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv2->annotated_chromosome_[B]; + indiv2->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv2->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv2); + genome = nullptr; + + + // Do transcription and translation + indiv2->start_stop_RNA(); + indiv2->prom_compute_RNA(*exp_s); + indiv2->start_protein(); + indiv2->compute_protein(); + indiv2->translate_protein(*exp_s, 1.0); + + +// indiv3: (prom-1 + AS + AG + AS + term) +// indiv4: reverse + + genome = new char[100]; + sprintf(genome, "%s%s%s%s%s0",bad_prom[0], as[1], gene, as[2], term); + + indiv3 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv3->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv3->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv3->annotated_chromosome_[A]; + indiv3->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv3->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv3); + + indiv3->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv3->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv3->annotated_chromosome_[B]; + indiv3->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv3->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv3); + genome = nullptr; + + // Do transcription and translation + indiv3->start_stop_RNA(); + indiv3->prom_compute_RNA(*exp_s); + indiv3->start_protein(); + indiv3->compute_protein(); + indiv3->translate_protein(*exp_s, 1.0); + + + + genome = new char[100]; + tmp_genome = indiv3->annotated_chromosome_[A]->dna_->subseq(0, + indiv3->annotated_chromosome_[A]->length(), + aevol::Strand::LAGGING); + strcpy(genome, tmp_genome.c_str()); + indiv4 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv4->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv4->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv4->annotated_chromosome_[A]; + indiv4->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv4->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv4); + + indiv4->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv4->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv4->annotated_chromosome_[B]; + indiv4->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv4->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv4); + genome = nullptr; + + + // Do transcription and translation + indiv4->start_stop_RNA(); + indiv4->prom_compute_RNA(*exp_s); + indiv4->start_protein(); + indiv4->compute_protein(); + indiv4->translate_protein(*exp_s, 1.0); + + + // indiv5: (term + AS + AG + AS + prom-1) + // indiv6: reverse + + genome = new char[100]; + sprintf(genome, "0%s%s%s%s%s",term, as[0], gene, as[4], bad_lag_prom[1]); + + indiv5 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv5->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv5->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv5->annotated_chromosome_[A]; + indiv5->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv5->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv5); + + indiv5->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv5->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv5->annotated_chromosome_[B]; + indiv5->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv5->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv5); + genome = nullptr; + + // Do transcription and translation + indiv5->start_stop_RNA(); + indiv5->prom_compute_RNA(*exp_s); + indiv5->start_protein(); + indiv5->compute_protein(); + indiv5->translate_protein(*exp_s, 1.0); + + + genome = new char[100]; + tmp_genome = indiv5->annotated_chromosome_[A]->dna_->subseq(0, + indiv5->annotated_chromosome_[A]->length(), + aevol::Strand::LAGGING); + strcpy(genome, tmp_genome.c_str()); + indiv6 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv6->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv6->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv6->annotated_chromosome_[A]; + indiv6->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv6->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv6); + + indiv6->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv6->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv6->annotated_chromosome_[B]; + indiv6->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv6->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv6); + genome = nullptr; + + + // Do transcription and translation + indiv6->start_stop_RNA(); + indiv6->prom_compute_RNA(*exp_s); + indiv6->start_protein(); + indiv6->compute_protein(); + indiv6->translate_protein(*exp_s, 1.0); + + + + // indiv7: (prom + AS + term + AS + AG + AS + prom) + // indiv8: reverse + genome = new char[100]; + sprintf(genome, "%s%s%s%s%s%s%s",prom[1], as[0], term, as[4], gene, as[3], lag_prom[0]); + + indiv7 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv7->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv7->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv7->annotated_chromosome_[A]; + indiv7->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv7->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv7); + + indiv7->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv7->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv7->annotated_chromosome_[B]; + indiv7->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv7->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv7); + genome = nullptr; + + // Do transcription and translation + indiv7->start_stop_RNA(); + indiv7->prom_compute_RNA(*exp_s); + indiv7->start_protein(); + indiv7->compute_protein(); + indiv7->translate_protein(*exp_s, 1.0); + + + genome = new char[100]; + tmp_genome = indiv7->annotated_chromosome_[A]->dna_->subseq(0, + indiv7->annotated_chromosome_[A]->length(), + aevol::Strand::LAGGING); + strcpy(genome, tmp_genome.c_str()); + indiv8 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv8->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv8->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv8->annotated_chromosome_[A]; + indiv8->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv8->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv8); + + indiv8->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv8->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv8->annotated_chromosome_[B]; + indiv8->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv8->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv8); + genome = nullptr; + + + // Do transcription and translation + indiv8->start_stop_RNA(); + indiv8->prom_compute_RNA(*exp_s); + indiv8->start_protein(); + indiv8->compute_protein(); + indiv8->translate_protein(*exp_s, 1.0); + + + // indiv9: (term + AS + AG + AS + prom-1) + // indiv10: reverse + genome = new char[100]; + sprintf(genome, "0%s%s%s%s%s",term, as[4], gene, as[3], bad_lag_prom[1]); + + indiv9 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv9->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv9->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv9->annotated_chromosome_[A]; + indiv9->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv9->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv9); + + indiv9->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv9->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv9->annotated_chromosome_[B]; + indiv9->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv9->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv9); + genome = nullptr; + + // Do transcription and translation + indiv9->start_stop_RNA(); + indiv9->prom_compute_RNA(*exp_s); + indiv9->start_protein(); + indiv9->compute_protein(); + indiv9->translate_protein(*exp_s, 1.0); + + + genome = new char[100]; + tmp_genome = indiv9->annotated_chromosome_[A]->dna_->subseq(0, + indiv9->annotated_chromosome_[A]->length(), + aevol::Strand::LAGGING); + strcpy(genome, tmp_genome.c_str()); + indiv10 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv10->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv10->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv10->annotated_chromosome_[A]; + indiv10->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv10->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv10); + + indiv10->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv10->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv10->annotated_chromosome_[B]; + indiv10->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv10->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv10); + genome = nullptr; + + + // Do transcription and translation + indiv10->start_stop_RNA(); + indiv10->prom_compute_RNA(*exp_s); + indiv10->start_protein(); + indiv10->compute_protein(); + indiv10->translate_protein(*exp_s, 1.0); + +} + +void IndividualTest::TearDown() { +// for (auto indiv : indivs1) { +// delete indiv; +// } +} + +// For each version of each individual constructed with a different +// fuzzy set implementation, we check that all values are correct. +// We don't need to change the fuzzy set implementation in the +// experimental setup again because it's only used at transcription and +// translation time. + +TEST_F(IndividualTest, TestIndiv1) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(99, indiv1->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(99, indiv1->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv1->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(1, rna_list.size()); + const auto* rna = rna_list.front(); + EXPECT_EQ(Strand::LEADING, rna->strand_); + EXPECT_EQ(0, rna->prom->pos); + EXPECT_FLOAT_EQ(0.6, rna->e); + EXPECT_EQ(50, rna->length); + + // Check protein list + auto prot_list = indiv1->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(1, prot_list.size()); + + const auto* prot = prot_list.front(); + EXPECT_EQ(Strand::LEADING, prot->strand_); + EXPECT_EQ(40, prot->protein_start); + EXPECT_EQ(4, prot->protein_length); + EXPECT_FLOAT_EQ(0.6, prot->e); + EXPECT_EQ(true, prot->is_init_); + EXPECT_EQ(1, prot->rna_list_.size()); + } +} + +TEST_F(IndividualTest, TestIndiv2) +{ + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(99, indiv2->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(99, indiv2->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv2->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(1, rna_list.size()); + + + // Check protein list + auto prot_list = indiv2->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv3) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(72, indiv3->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(72, indiv3->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv3->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv3->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + + +TEST_F(IndividualTest, TestIndiv4) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(72, indiv4->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(72, indiv4->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv4->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv4->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv5) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(71, indiv5->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(71, indiv5->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv5->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv5->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv6) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(71, indiv6->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(71, indiv6->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv6->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv6->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv7) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(98, indiv7->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(98, indiv7->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv7->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(1, rna_list.size()); + //ADD CHECK FOR LENGTH (and to other no prot but 1 rna tests too) + + // Check protein list + auto prot_list = indiv7->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv8) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(98, indiv8->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(98, indiv8->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv8->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(1, rna_list.size()); + const auto* rna = rna_list.front(); + EXPECT_EQ(Strand::LAGGING, rna->strand_); + EXPECT_EQ(0, rna->prom->pos); + EXPECT_FLOAT_EQ(0.6, rna->e); + EXPECT_EQ(50, rna->length); + + // Check protein list + auto prot_list = indiv8->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(1, prot_list.size()); + + const auto* prot = prot_list.front(); + EXPECT_EQ(Strand::LAGGING, prot->strand_); + EXPECT_EQ(40, prot->protein_start); + EXPECT_EQ(4, prot->protein_length); + EXPECT_FLOAT_EQ(0.6, prot->e); + EXPECT_EQ(true, prot->is_init_); + EXPECT_EQ(1, prot->rna_list_.size()); + } +} +TEST_F(IndividualTest, TestIndiv9) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(99, indiv9->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(99, indiv9->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv9->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv9->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv10) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(99, indiv10->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(99, indiv10->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv10->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv10->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +// =========================================================================== +// Protected Methods +// =========================================================================== + +// =========================================================================== +// Non inline accessors +// =========================================================================== diff --git a/test/gtest/EukTest_nornas.cpp b/test/gtest/EukTest_nornas.cpp new file mode 100644 index 0000000000000000000000000000000000000000..43e6e65241a306342911e12f94fd9df83d33d069 --- /dev/null +++ b/test/gtest/EukTest_nornas.cpp @@ -0,0 +1,565 @@ +// **************************************************************************** +// +// Aevol - An in silico experimental evolution platform +// +// **************************************************************************** +// +// Copyright: See the AUTHORS file provided with the package or <www.aevol.fr> +// Web: http://www.aevol.fr/ +// E-mail: See <http://www.aevol.fr/contact/> +// Original Authors : Guillaume Beslon, Carole Knibbe, David Parsons +// +// This program 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 2 of the License, or +// (at your option) any later version. +// +// This program 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 this program. If not, see <http://www.gnu.org/licenses/>. +// +//***************************************************************************** + + + + +// ================================================================= +// Includes +// ================================================================= +#include <inttypes.h> +#include <cstring> + +#include <list> +#include <vector> +#include <memory> + +#include <gtest/gtest.h> + +#include "DnaFactory.h" +#include "ExpManager_7.h" +#include "ExpSetup.h" +#include "fuzzy/FuzzyFactory_7.h" +#include "Individual_7.h" +#include "legacy/biochemistry/Rna.h" +#include "legacy/biochemistry/Protein.h" +#include "macros.h" +#include "MutationParams.h" +#include "Strand.h" + +using namespace aevol; + +//############################################################################ +// # +// Class IndividualTest # +// # +//############################################################################ +class IndividualTest : public testing::Test +{ + protected: + virtual void SetUp(void); + virtual void TearDown(void); + + // We have an version of each individual for each fuzzy set flavor + Individual_7* indiv1; + Individual_7* indiv2; + Individual_7* indiv3; + Individual_7* indiv4; + Individual_7* indiv5; + Individual_7* indiv6; + Individual_7* indiv7; + Individual_7* indiv8; + Individual_7* indiv9; + Individual_7* indiv10; +}; + +// =========================================================================== +// Public Methods +// =========================================================================== +void IndividualTest::SetUp(void) +{ + // Build ad-hoc genomes + // (and reverse to test the same things on the lagging strand.): + // + // indiv1: LEAD (prom-1 + AS + AG + AS + term) + // size 22+5+28+6+11=72 + // indiv2: LEAD (prom-1 + AS + term) + // size 22+5+11=38 + // indiv3: LAGG (term + AS + AG + AS + prom-1) + // size 11+5+28+6+22=72 + // indiv4: LAGG (term + AS + prom-1) + // size 22+5+11=38 + // indiv5: LEAD (prom + AS + AG + AS + term-1) + // size 22+4+28+6+11=71 + // indiv6: LEAD (prom + AS + term-1) + // size 22+4+11=37 + // indiv7: LAGG (term-1 + AS + AG + AS + prom) + // size 11+6+28+5+22=72 + // indiv8: LAGG (term-1 + AS + prom) + // size 11+6+22=39 + // + // AS = Arbitrary Sequence + // AG = Arbitrary Gene + // Do not modify the sequences ! + + // Define a few arbitrary sequences + char as[5][10] = { + "0011", + "11101", + "110011", + "11000", + "000101" + }; + + const char* SHINE_DAL_SEQ = "011011"; + const char* SHINE_DAL_SEQ_LAG = "001001"; + // Define an arbitrary gene + char gene[100]; + sprintf(gene, "%s0011000100110110010001", SHINE_DAL_SEQ); + + char lag_gene[100]; + sprintf(lag_gene, "1100111011001001101110%s", SHINE_DAL_SEQ_LAG); + + // Define an arbitrary terminator + char term[TERM_SIZE+1] = "01000001101"; + char bad_term_end[TERM_SIZE] = "0100000110"; + char bad_term_beg[TERM_SIZE] = "1000001101"; + + // Define a few arbitrary promoters + char prom[2][23] = { + "0101010001110110010110", // dist from consensus: 2 => basal level: 0.6 + "0101011001110010010010" // dist from consensus: 1 => basal level: 0.8 + }; + + char lag_prom[2][23] = { + "1001011001000111010101", // dist from consensus: 2 => basal level: 0.6 + "1011011011000110010101" // dist from consensus: 1 => basal level: 0.8 + }; + + + char bad_prom[2][23] = { + "101010001110110010110", // removed first base : add 0 at end + "010101100111001001001" // removed last base : add 0 at begin + }; + + char bad_lag_prom[2][23] = { + "001011001000111010101", // removed first base : add 1 at end + "101101101100011001010" // removed last base : add 1 at begin + }; + + + // Initialize the experimental setup. + // These are needed in the GeneticUnit constructors. + ExpSetup* exp_s = new ExpSetup(nullptr); + MutationParams params_mut; + + + // Update fuzzy flavor and fuzzy factory // TODO<dpa> Still needed/useful? + FuzzyFlavor fuzzyFlavor = FuzzyFlavor::VECTOR; + exp_s->set_fuzzy_flavor(fuzzyFlavor); + + DnaFactory* dna_factory = new DnaFactory(DnaFactory_Policy::LOCAL_GLOBAL_FIT, 48, 1000, 16); + FuzzyFactory_7* fuzzy_factory = new FuzzyFactory_7(fuzzyFlavor, 16, 300, 16); + + + + // Build indiv1 LEAD (prom-1 + AS + AG + AS + term) + // Construct a genome with these arbitrary sequences + char* genome = new char[100]; + sprintf(genome, "%s%s%s%s%s0",bad_prom[0], as[1], gene, as[2], term); + + indiv1 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv1->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv1->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv1->annotated_chromosome_[A]; + indiv1->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv1->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv1); + + indiv1->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv1->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv1->annotated_chromosome_[B]; + indiv1->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv1->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv1); + genome = nullptr; + + // Do transcription and translation + indiv1->start_stop_RNA(); + indiv1->prom_compute_RNA(*exp_s); + indiv1->start_protein(); + indiv1->compute_protein(); + indiv1->translate_protein(*exp_s, 1.0); + + + + // Build indiv2 LEAD (prom-1 + AS + term) + genome = new char[100]; + sprintf(genome, "%s%s%s0",bad_prom[0], as[1], term); + + indiv2 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv2->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv2->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv2->annotated_chromosome_[A]; + indiv2->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv2->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv2); + + indiv2->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv2->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv2->annotated_chromosome_[B]; + indiv2->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv2->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv2); + genome = nullptr; + + + // Do transcription and translation + indiv2->start_stop_RNA(); + indiv2->prom_compute_RNA(*exp_s); + indiv2->start_protein(); + indiv2->compute_protein(); + indiv2->translate_protein(*exp_s, 1.0); + + + +// indiv3: LAGG (term + AS + AG + AS + prom-1) + genome = new char[100]; + sprintf(genome, "1%s%s%s%s%s", term, as[1], lag_gene, as[2], bad_lag_prom[1]); + + indiv3 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv3->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv3->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv3->annotated_chromosome_[A]; + indiv3->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv3->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv3); + + indiv3->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv3->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv3->annotated_chromosome_[B]; + indiv3->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv3->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv3); + genome = nullptr; + + // Do transcription and translation + indiv3->start_stop_RNA(); + indiv3->prom_compute_RNA(*exp_s); + indiv3->start_protein(); + indiv3->compute_protein(); + indiv3->translate_protein(*exp_s, 1.0); + + + +// indiv4: LAGG (term + AS + prom-1) + genome = new char[100]; + sprintf(genome, "1%s%s%s", term, as[1], bad_lag_prom[1]); + + indiv4 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv4->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv4->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv4->annotated_chromosome_[A]; + indiv4->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv4->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv4); + + indiv4->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv4->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv4->annotated_chromosome_[B]; + indiv4->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv4->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv4); + genome = nullptr; + + // Do transcription and translation + indiv4->start_stop_RNA(); + indiv4->prom_compute_RNA(*exp_s); + indiv4->start_protein(); + indiv4->compute_protein(); + indiv4->translate_protein(*exp_s, 1.0); + + + + // indiv5: LEAD (prom + AS + AG + AS + term-1) + genome = new char[100]; + sprintf(genome, "1%s%s%s%s%s",prom[1], as[0], gene, as[4], bad_term_end); + + indiv5 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv5->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv5->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv5->annotated_chromosome_[A]; + indiv5->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv5->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv5); + + indiv5->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv5->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv5->annotated_chromosome_[B]; + indiv5->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv5->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv5); + genome = nullptr; + + // Do transcription and translation + indiv5->start_stop_RNA(); + indiv5->prom_compute_RNA(*exp_s); + indiv5->start_protein(); + indiv5->compute_protein(); + indiv5->translate_protein(*exp_s, 1.0); + + + + // indiv6: LEAD (prom + AS + term-1) + genome = new char[100]; + sprintf(genome, "1%s%s%s",prom[1], as[0], bad_term_end); + + indiv6 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv6->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv6->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv6->annotated_chromosome_[A]; + indiv6->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv6->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv6); + + indiv6->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv6->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv6->annotated_chromosome_[B]; + indiv6->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv6->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv6); + genome = nullptr; + + // Do transcription and translation + indiv6->start_stop_RNA(); + indiv6->prom_compute_RNA(*exp_s); + indiv6->start_protein(); + indiv6->compute_protein(); + indiv6->translate_protein(*exp_s, 1.0); + + + + // indiv7: LAGG (term-1 + AS + AG + AS + prom) + genome = new char[100]; + sprintf(genome, "%s%s%s%s%s1", bad_term_beg, as[4], lag_gene, as[3], lag_prom[0]); + + indiv7 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv7->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv7->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv7->annotated_chromosome_[A]; + indiv7->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv7->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv7); + + indiv7->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv7->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv7->annotated_chromosome_[B]; + indiv7->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv7->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv7); + genome = nullptr; + + // Do transcription and translation + indiv7->start_stop_RNA(); + indiv7->prom_compute_RNA(*exp_s); + indiv7->start_protein(); + indiv7->compute_protein(); + indiv7->translate_protein(*exp_s, 1.0); + + + + // indiv8: LAGG (term-1 + AS + AG + AS + prom) + genome = new char[100]; + sprintf(genome, "%s%s%s1", bad_term_beg, as[4], lag_prom[0]); + + indiv8 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv8->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv8->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv8->annotated_chromosome_[A]; + indiv8->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv8->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv8); + + indiv8->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv8->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv8->annotated_chromosome_[B]; + indiv8->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv8->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv8); + genome = nullptr; + + // Do transcription and translation + indiv8->start_stop_RNA(); + indiv8->prom_compute_RNA(*exp_s); + indiv8->start_protein(); + indiv8->compute_protein(); + indiv8->translate_protein(*exp_s, 1.0); + +} + +void IndividualTest::TearDown() { +// for (auto indiv : indivs1) { +// delete indiv; +// } +} + +// For each version of each individual constructed with a different +// fuzzy set implementation, we check that all values are correct. +// We don't need to change the fuzzy set implementation in the +// experimental setup again because it's only used at transcription and +// translation time. + +TEST_F(IndividualTest, TestIndiv1) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(72, indiv1->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(72, indiv1->annotated_chromosome_[chrsm]->length()); + + // Check Prom list + EXPECT_EQ(0, indiv1->annotated_chromosome_[chrsm]->promoter_list().promoter_count()); + + // Check RNA list + auto rna_list = indiv1->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv1->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv2){ + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(38, indiv2->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(38, indiv2->annotated_chromosome_[chrsm]->length()); + + // Check Prom list + EXPECT_EQ(0, indiv2->annotated_chromosome_[chrsm]->promoter_list().promoter_count()); + + // Check RNA list + auto rna_list = indiv2->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv2->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv3){ + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(72, indiv3->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(72, indiv3->annotated_chromosome_[chrsm]->length()); + + // Check Prom list + EXPECT_EQ(0, indiv3->annotated_chromosome_[chrsm]->promoter_list().promoter_count()); + + // Check RNA list + auto rna_list = indiv3->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv3->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + + +TEST_F(IndividualTest, TestIndiv4){ + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(38, indiv4->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(38, indiv4->annotated_chromosome_[chrsm]->length()); + + // Check Prom list + EXPECT_EQ(0, indiv4->annotated_chromosome_[chrsm]->promoter_list().promoter_count()); + + // Check RNA list + auto rna_list = indiv4->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv4->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv5){ + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(71, indiv5->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(71, indiv5->annotated_chromosome_[chrsm]->length()); + + // Check Prom list + EXPECT_EQ(0, indiv5->annotated_chromosome_[chrsm]->promoter_list().promoter_count()); + + // Check RNA list + auto rna_list = indiv5->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv5->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv6){ + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(37, indiv6->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(37, indiv6->annotated_chromosome_[chrsm]->length()); + + // Check Prom list + EXPECT_EQ(0, indiv6->annotated_chromosome_[chrsm]->promoter_list().promoter_count()); + + // Check RNA list + auto rna_list = indiv6->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv6->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv7){ + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(72, indiv7->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(72, indiv7->annotated_chromosome_[chrsm]->length()); + + // Check Prom list + EXPECT_EQ(0, indiv7->annotated_chromosome_[chrsm]->promoter_list().promoter_count()); + + // Check RNA list + auto rna_list = indiv7->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv7->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv8){ + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(39, indiv8->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(39, indiv8->annotated_chromosome_[chrsm]->length()); + + // Check Prom list + EXPECT_EQ(0, indiv8->annotated_chromosome_[chrsm]->promoter_list().promoter_count()); + + // Check RNA list + auto rna_list = indiv8->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv8->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + + + +// =========================================================================== +// Protected Methods +// =========================================================================== + +// =========================================================================== +// Non inline accessors +// =========================================================================== diff --git a/test/gtest/EukTest_recombination.cpp b/test/gtest/EukTest_recombination.cpp new file mode 100644 index 0000000000000000000000000000000000000000..999a21a73afa091e0da8ff67f10ea3e0eb99a356 --- /dev/null +++ b/test/gtest/EukTest_recombination.cpp @@ -0,0 +1,650 @@ +// **************************************************************************** +// +// Aevol - An in silico experimental evolution platform +// +// **************************************************************************** +// +// Copyright: See the AUTHORS file provided with the package or <www.aevol.fr> +// Web: http://www.aevol.fr/ +// E-mail: See <http://www.aevol.fr/contact/> +// Original Authors : Guillaume Beslon, Carole Knibbe, David Parsons +// +// This program 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 2 of the License, or +// (at your option) any later version. +// +// This program 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 this program. If not, see <http://www.gnu.org/licenses/>. +// +//***************************************************************************** + + + + +// ================================================================= +// Includes +// ================================================================= +#include <inttypes.h> +#include <cstring> + +#include <list> +#include <vector> +#include <memory> + +#include <gtest/gtest.h> + +#include "DnaFactory.h" +#include "ExpManager_7.h" +#include "ExpSetup.h" +#include "fuzzy/FuzzyFactory_7.h" +#include "Individual_7.h" +#include "legacy/biochemistry/Rna.h" +#include "legacy/biochemistry/Protein.h" +#include "macros.h" +#include "MutationParams.h" +#include "Strand.h" + +using namespace aevol; + +//############################################################################ +// # +// Class IndividualTest # +// # +//############################################################################ +class IndividualTest : public testing::Test +{ + protected: + virtual void SetUp(void); + virtual void TearDown(void); + + // We have an version of each individual for each fuzzy set flavor + Individual_7* indiv1; + Individual_7* indiv2; + Individual_7* indiv3; + Individual_7* indiv4; + Individual_7* indiv5; + Individual_7* indiv6; + Individual_7* indiv7; + Individual_7* indiv8; + Individual_7* indiv9; + Individual_7* indiv10; +}; + +// =========================================================================== +// Public Methods +// =========================================================================== +void IndividualTest::SetUp(void) +{ + // Build ad-hoc genomes + // (and reverse to test the same things on the lagging strand.): + // + // indiv1: (prom + AS + AG + AS + term + AS + prom) + // indiv2: reverse + // indiv3: (prom-1 + AS + AG + AS + term) + // indiv4: reverse + // indiv5: (term + AS + AG + AS + prom-1) + // indiv6: reverse + // indiv7: (prom + AS + term + AS + AG + AS + prom) + // indiv8: reverse + // indiv9: (term + AS + AG + AS + prom-1) + // indiv10: reverse + // + // AS = Arbitrary Sequence + // AG = Arbitrary Gene + // Do not modify the sequences ! + + // Define a few arbitrary sequences + char as[5][10] = { + "0011", + "11101", + "110011", + "11000", + "000101" + }; + + // Define an arbitrary gene + char gene[29]; + sprintf(gene, "%s0011000100110110010001", SHINE_DAL_SEQ); + + // Define an arbitrary terminator + char term[TERM_SIZE+1] = "01000001101"; + + // Define a few arbitrary promoters + char prom[2][23] = { + "0101010001110110010110", // dist from consensus: 2 => basal level: 0.6 + "0101011001110010010010" // dist from consensus: 1 => basal level: 0.8 + }; + + char lag_prom[2][23] = { + "1001011001000111010101", // dist from consensus: 2 => basal level: 0.6 + "1011011011000110010101" // dist from consensus: 1 => basal level: 0.8 + }; + + + char bad_prom[2][23] = { + "101010001110110010110", // removed first base : add 0 at end + "010101100111001001001" // removed last base : add 0 at begin + }; + + char bad_lag_prom[2][23] = { + "001011001000111010101", // removed first base : add 1 at end + "101101101100011001010" // removed last base : add 1 at begin + }; + + + // Initialize the experimental setup. + // These are needed in the GeneticUnit constructors. + ExpSetup* exp_s = new ExpSetup(nullptr); + MutationParams params_mut; + + + // Update fuzzy flavor and fuzzy factory // TODO<dpa> Still needed/useful? + FuzzyFlavor fuzzyFlavor = FuzzyFlavor::VECTOR; + exp_s->set_fuzzy_flavor(fuzzyFlavor); + + DnaFactory* dna_factory = new DnaFactory(DnaFactory_Policy::LOCAL_GLOBAL_FIT, 48, 1000, 16); + FuzzyFactory_7* fuzzy_factory = new FuzzyFactory_7(fuzzyFlavor, 16, 300, 16); + + // Build indiv1 + // Construct a genome with these arbitrary sequences + char* genome = new char[100]; + sprintf(genome, "%s%s%s%s%s%s%s",prom[0], as[1], gene, as[2], term, as[3], lag_prom[1]); + + indiv1 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv1->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv1->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv1->annotated_chromosome_[A]; + indiv1->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv1->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv1); + + indiv1->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv1->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv1->annotated_chromosome_[B]; + indiv1->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv1->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv1); + genome = nullptr; + + // Do transcription and translation + indiv1->start_stop_RNA(); + indiv1->prom_compute_RNA(*exp_s); + indiv1->start_protein(); + indiv1->compute_protein(); + indiv1->translate_protein(*exp_s, 1.0); + + + // Build indiv2 + // Reverse the whole genome + genome = new char[100]; + std::string tmp_genome = indiv1->annotated_chromosome_[A]->dna_->subseq(0, + indiv1->annotated_chromosome_[A]->length(), + aevol::Strand::LAGGING); + strcpy(genome, tmp_genome.c_str()); + indiv2 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv2->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv2->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv2->annotated_chromosome_[A]; + indiv2->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv2->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv2); + + indiv2->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv2->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv2->annotated_chromosome_[B]; + indiv2->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv2->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv2); + genome = nullptr; + + + // Do transcription and translation + indiv2->start_stop_RNA(); + indiv2->prom_compute_RNA(*exp_s); + indiv2->start_protein(); + indiv2->compute_protein(); + indiv2->translate_protein(*exp_s, 1.0); + + +// indiv3: (prom-1 + AS + AG + AS + term) +// indiv4: reverse + + genome = new char[100]; + sprintf(genome, "%s%s%s%s%s0",bad_prom[0], as[1], gene, as[2], term); + + indiv3 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv3->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv3->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv3->annotated_chromosome_[A]; + indiv3->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv3->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv3); + + indiv3->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv3->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv3->annotated_chromosome_[B]; + indiv3->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv3->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv3); + genome = nullptr; + + // Do transcription and translation + indiv3->start_stop_RNA(); + indiv3->prom_compute_RNA(*exp_s); + indiv3->start_protein(); + indiv3->compute_protein(); + indiv3->translate_protein(*exp_s, 1.0); + + + + genome = new char[100]; + tmp_genome = indiv3->annotated_chromosome_[A]->dna_->subseq(0, + indiv3->annotated_chromosome_[A]->length(), + aevol::Strand::LAGGING); + strcpy(genome, tmp_genome.c_str()); + indiv4 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv4->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv4->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv4->annotated_chromosome_[A]; + indiv4->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv4->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv4); + + indiv4->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv4->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv4->annotated_chromosome_[B]; + indiv4->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv4->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv4); + genome = nullptr; + + + // Do transcription and translation + indiv4->start_stop_RNA(); + indiv4->prom_compute_RNA(*exp_s); + indiv4->start_protein(); + indiv4->compute_protein(); + indiv4->translate_protein(*exp_s, 1.0); + + + // indiv5: (term + AS + AG + AS + prom-1) + // indiv6: reverse + + genome = new char[100]; + sprintf(genome, "0%s%s%s%s%s",term, as[0], gene, as[4], bad_lag_prom[1]); + + indiv5 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv5->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv5->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv5->annotated_chromosome_[A]; + indiv5->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv5->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv5); + + indiv5->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv5->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv5->annotated_chromosome_[B]; + indiv5->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv5->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv5); + genome = nullptr; + + // Do transcription and translation + indiv5->start_stop_RNA(); + indiv5->prom_compute_RNA(*exp_s); + indiv5->start_protein(); + indiv5->compute_protein(); + indiv5->translate_protein(*exp_s, 1.0); + + + genome = new char[100]; + tmp_genome = indiv5->annotated_chromosome_[A]->dna_->subseq(0, + indiv5->annotated_chromosome_[A]->length(), + aevol::Strand::LAGGING); + strcpy(genome, tmp_genome.c_str()); + indiv6 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv6->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv6->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv6->annotated_chromosome_[A]; + indiv6->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv6->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv6); + + indiv6->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv6->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv6->annotated_chromosome_[B]; + indiv6->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv6->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv6); + genome = nullptr; + + + // Do transcription and translation + indiv6->start_stop_RNA(); + indiv6->prom_compute_RNA(*exp_s); + indiv6->start_protein(); + indiv6->compute_protein(); + indiv6->translate_protein(*exp_s, 1.0); + + + + // indiv7: (prom + AS + term + AS + AG + AS + prom) + // indiv8: reverse + genome = new char[100]; + sprintf(genome, "%s%s%s%s%s%s%s",prom[1], as[0], term, as[4], gene, as[3], lag_prom[0]); + + indiv7 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv7->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv7->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv7->annotated_chromosome_[A]; + indiv7->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv7->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv7); + + indiv7->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv7->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv7->annotated_chromosome_[B]; + indiv7->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv7->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv7); + genome = nullptr; + + // Do transcription and translation + indiv7->start_stop_RNA(); + indiv7->prom_compute_RNA(*exp_s); + indiv7->start_protein(); + indiv7->compute_protein(); + indiv7->translate_protein(*exp_s, 1.0); + + + genome = new char[100]; + tmp_genome = indiv7->annotated_chromosome_[A]->dna_->subseq(0, + indiv7->annotated_chromosome_[A]->length(), + aevol::Strand::LAGGING); + strcpy(genome, tmp_genome.c_str()); + indiv8 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv8->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv8->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv8->annotated_chromosome_[A]; + indiv8->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv8->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv8); + + indiv8->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv8->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv8->annotated_chromosome_[B]; + indiv8->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv8->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv8); + genome = nullptr; + + + // Do transcription and translation + indiv8->start_stop_RNA(); + indiv8->prom_compute_RNA(*exp_s); + indiv8->start_protein(); + indiv8->compute_protein(); + indiv8->translate_protein(*exp_s, 1.0); + + + // indiv9: (term + AS + AG + AS + prom-1) + // indiv10: reverse + genome = new char[100]; + sprintf(genome, "0%s%s%s%s%s",term, as[4], gene, as[3], bad_lag_prom[1]); + + indiv9 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv9->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv9->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv9->annotated_chromosome_[A]; + indiv9->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv9->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv9); + + indiv9->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv9->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv9->annotated_chromosome_[B]; + indiv9->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv9->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv9); + genome = nullptr; + + // Do transcription and translation + indiv9->start_stop_RNA(); + indiv9->prom_compute_RNA(*exp_s); + indiv9->start_protein(); + indiv9->compute_protein(); + indiv9->translate_protein(*exp_s, 1.0); + + + genome = new char[100]; + tmp_genome = indiv9->annotated_chromosome_[A]->dna_->subseq(0, + indiv9->annotated_chromosome_[A]->length(), + aevol::Strand::LAGGING); + strcpy(genome, tmp_genome.c_str()); + indiv10 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv10->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv10->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv10->annotated_chromosome_[A]; + indiv10->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv10->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv10); + + indiv10->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv10->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv10->annotated_chromosome_[B]; + indiv10->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv10->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv10); + genome = nullptr; + + + // Do transcription and translation + indiv10->start_stop_RNA(); + indiv10->prom_compute_RNA(*exp_s); + indiv10->start_protein(); + indiv10->compute_protein(); + indiv10->translate_protein(*exp_s, 1.0); + +} + +void IndividualTest::TearDown() { +// for (auto indiv : indivs1) { +// delete indiv; +// } +} + +// For each version of each individual constructed with a different +// fuzzy set implementation, we check that all values are correct. +// We don't need to change the fuzzy set implementation in the +// experimental setup again because it's only used at transcription and +// translation time. + +TEST_F(IndividualTest, TestIndiv1) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(99, indiv1->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(99, indiv1->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv1->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(1, rna_list.size()); + const auto* rna = rna_list.front(); + EXPECT_EQ(Strand::LEADING, rna->strand_); + EXPECT_EQ(0, rna->prom->pos); + EXPECT_FLOAT_EQ(0.6, rna->e); + EXPECT_EQ(50, rna->length); + + // Check protein list + auto prot_list = indiv1->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(1, prot_list.size()); + + const auto* prot = prot_list.front(); + EXPECT_EQ(Strand::LEADING, prot->strand_); + EXPECT_EQ(40, prot->protein_start); + EXPECT_EQ(4, prot->protein_length); + EXPECT_FLOAT_EQ(0.6, prot->e); + EXPECT_EQ(true, prot->is_init_); + EXPECT_EQ(1, prot->rna_list_.size()); + } +} + +TEST_F(IndividualTest, TestIndiv2) +{ + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(99, indiv2->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(99, indiv2->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv2->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(1, rna_list.size()); + + + // Check protein list + auto prot_list = indiv2->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv3) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(72, indiv3->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(72, indiv3->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv3->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv3->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + + +TEST_F(IndividualTest, TestIndiv4) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(72, indiv4->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(72, indiv4->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv4->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv4->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv5) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(71, indiv5->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(71, indiv5->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv5->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv5->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv6) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(71, indiv6->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(71, indiv6->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv6->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv6->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv7) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(98, indiv7->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(98, indiv7->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv7->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(1, rna_list.size()); + //ADD CHECK FOR LENGTH (and to other no prot but 1 rna tests too) + + // Check protein list + auto prot_list = indiv7->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv8) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(98, indiv8->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(98, indiv8->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv8->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(1, rna_list.size()); + const auto* rna = rna_list.front(); + EXPECT_EQ(Strand::LAGGING, rna->strand_); + EXPECT_EQ(0, rna->prom->pos); + EXPECT_FLOAT_EQ(0.6, rna->e); + EXPECT_EQ(50, rna->length); + + // Check protein list + auto prot_list = indiv8->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(1, prot_list.size()); + + const auto* prot = prot_list.front(); + EXPECT_EQ(Strand::LAGGING, prot->strand_); + EXPECT_EQ(40, prot->protein_start); + EXPECT_EQ(4, prot->protein_length); + EXPECT_FLOAT_EQ(0.6, prot->e); + EXPECT_EQ(true, prot->is_init_); + EXPECT_EQ(1, prot->rna_list_.size()); + } +} +TEST_F(IndividualTest, TestIndiv9) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(99, indiv9->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(99, indiv9->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv9->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv9->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv10) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(99, indiv10->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(99, indiv10->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv10->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv10->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +// =========================================================================== +// Protected Methods +// =========================================================================== + +// =========================================================================== +// Non inline accessors +// =========================================================================== diff --git a/test/gtest/EukTest_withrnas.cpp b/test/gtest/EukTest_withrnas.cpp new file mode 100644 index 0000000000000000000000000000000000000000..999a21a73afa091e0da8ff67f10ea3e0eb99a356 --- /dev/null +++ b/test/gtest/EukTest_withrnas.cpp @@ -0,0 +1,650 @@ +// **************************************************************************** +// +// Aevol - An in silico experimental evolution platform +// +// **************************************************************************** +// +// Copyright: See the AUTHORS file provided with the package or <www.aevol.fr> +// Web: http://www.aevol.fr/ +// E-mail: See <http://www.aevol.fr/contact/> +// Original Authors : Guillaume Beslon, Carole Knibbe, David Parsons +// +// This program 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 2 of the License, or +// (at your option) any later version. +// +// This program 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 this program. If not, see <http://www.gnu.org/licenses/>. +// +//***************************************************************************** + + + + +// ================================================================= +// Includes +// ================================================================= +#include <inttypes.h> +#include <cstring> + +#include <list> +#include <vector> +#include <memory> + +#include <gtest/gtest.h> + +#include "DnaFactory.h" +#include "ExpManager_7.h" +#include "ExpSetup.h" +#include "fuzzy/FuzzyFactory_7.h" +#include "Individual_7.h" +#include "legacy/biochemistry/Rna.h" +#include "legacy/biochemistry/Protein.h" +#include "macros.h" +#include "MutationParams.h" +#include "Strand.h" + +using namespace aevol; + +//############################################################################ +// # +// Class IndividualTest # +// # +//############################################################################ +class IndividualTest : public testing::Test +{ + protected: + virtual void SetUp(void); + virtual void TearDown(void); + + // We have an version of each individual for each fuzzy set flavor + Individual_7* indiv1; + Individual_7* indiv2; + Individual_7* indiv3; + Individual_7* indiv4; + Individual_7* indiv5; + Individual_7* indiv6; + Individual_7* indiv7; + Individual_7* indiv8; + Individual_7* indiv9; + Individual_7* indiv10; +}; + +// =========================================================================== +// Public Methods +// =========================================================================== +void IndividualTest::SetUp(void) +{ + // Build ad-hoc genomes + // (and reverse to test the same things on the lagging strand.): + // + // indiv1: (prom + AS + AG + AS + term + AS + prom) + // indiv2: reverse + // indiv3: (prom-1 + AS + AG + AS + term) + // indiv4: reverse + // indiv5: (term + AS + AG + AS + prom-1) + // indiv6: reverse + // indiv7: (prom + AS + term + AS + AG + AS + prom) + // indiv8: reverse + // indiv9: (term + AS + AG + AS + prom-1) + // indiv10: reverse + // + // AS = Arbitrary Sequence + // AG = Arbitrary Gene + // Do not modify the sequences ! + + // Define a few arbitrary sequences + char as[5][10] = { + "0011", + "11101", + "110011", + "11000", + "000101" + }; + + // Define an arbitrary gene + char gene[29]; + sprintf(gene, "%s0011000100110110010001", SHINE_DAL_SEQ); + + // Define an arbitrary terminator + char term[TERM_SIZE+1] = "01000001101"; + + // Define a few arbitrary promoters + char prom[2][23] = { + "0101010001110110010110", // dist from consensus: 2 => basal level: 0.6 + "0101011001110010010010" // dist from consensus: 1 => basal level: 0.8 + }; + + char lag_prom[2][23] = { + "1001011001000111010101", // dist from consensus: 2 => basal level: 0.6 + "1011011011000110010101" // dist from consensus: 1 => basal level: 0.8 + }; + + + char bad_prom[2][23] = { + "101010001110110010110", // removed first base : add 0 at end + "010101100111001001001" // removed last base : add 0 at begin + }; + + char bad_lag_prom[2][23] = { + "001011001000111010101", // removed first base : add 1 at end + "101101101100011001010" // removed last base : add 1 at begin + }; + + + // Initialize the experimental setup. + // These are needed in the GeneticUnit constructors. + ExpSetup* exp_s = new ExpSetup(nullptr); + MutationParams params_mut; + + + // Update fuzzy flavor and fuzzy factory // TODO<dpa> Still needed/useful? + FuzzyFlavor fuzzyFlavor = FuzzyFlavor::VECTOR; + exp_s->set_fuzzy_flavor(fuzzyFlavor); + + DnaFactory* dna_factory = new DnaFactory(DnaFactory_Policy::LOCAL_GLOBAL_FIT, 48, 1000, 16); + FuzzyFactory_7* fuzzy_factory = new FuzzyFactory_7(fuzzyFlavor, 16, 300, 16); + + // Build indiv1 + // Construct a genome with these arbitrary sequences + char* genome = new char[100]; + sprintf(genome, "%s%s%s%s%s%s%s",prom[0], as[1], gene, as[2], term, as[3], lag_prom[1]); + + indiv1 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv1->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv1->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv1->annotated_chromosome_[A]; + indiv1->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv1->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv1); + + indiv1->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv1->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv1->annotated_chromosome_[B]; + indiv1->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv1->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv1); + genome = nullptr; + + // Do transcription and translation + indiv1->start_stop_RNA(); + indiv1->prom_compute_RNA(*exp_s); + indiv1->start_protein(); + indiv1->compute_protein(); + indiv1->translate_protein(*exp_s, 1.0); + + + // Build indiv2 + // Reverse the whole genome + genome = new char[100]; + std::string tmp_genome = indiv1->annotated_chromosome_[A]->dna_->subseq(0, + indiv1->annotated_chromosome_[A]->length(), + aevol::Strand::LAGGING); + strcpy(genome, tmp_genome.c_str()); + indiv2 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv2->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv2->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv2->annotated_chromosome_[A]; + indiv2->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv2->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv2); + + indiv2->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv2->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv2->annotated_chromosome_[B]; + indiv2->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv2->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv2); + genome = nullptr; + + + // Do transcription and translation + indiv2->start_stop_RNA(); + indiv2->prom_compute_RNA(*exp_s); + indiv2->start_protein(); + indiv2->compute_protein(); + indiv2->translate_protein(*exp_s, 1.0); + + +// indiv3: (prom-1 + AS + AG + AS + term) +// indiv4: reverse + + genome = new char[100]; + sprintf(genome, "%s%s%s%s%s0",bad_prom[0], as[1], gene, as[2], term); + + indiv3 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv3->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv3->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv3->annotated_chromosome_[A]; + indiv3->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv3->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv3); + + indiv3->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv3->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv3->annotated_chromosome_[B]; + indiv3->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv3->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv3); + genome = nullptr; + + // Do transcription and translation + indiv3->start_stop_RNA(); + indiv3->prom_compute_RNA(*exp_s); + indiv3->start_protein(); + indiv3->compute_protein(); + indiv3->translate_protein(*exp_s, 1.0); + + + + genome = new char[100]; + tmp_genome = indiv3->annotated_chromosome_[A]->dna_->subseq(0, + indiv3->annotated_chromosome_[A]->length(), + aevol::Strand::LAGGING); + strcpy(genome, tmp_genome.c_str()); + indiv4 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv4->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv4->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv4->annotated_chromosome_[A]; + indiv4->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv4->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv4); + + indiv4->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv4->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv4->annotated_chromosome_[B]; + indiv4->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv4->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv4); + genome = nullptr; + + + // Do transcription and translation + indiv4->start_stop_RNA(); + indiv4->prom_compute_RNA(*exp_s); + indiv4->start_protein(); + indiv4->compute_protein(); + indiv4->translate_protein(*exp_s, 1.0); + + + // indiv5: (term + AS + AG + AS + prom-1) + // indiv6: reverse + + genome = new char[100]; + sprintf(genome, "0%s%s%s%s%s",term, as[0], gene, as[4], bad_lag_prom[1]); + + indiv5 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv5->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv5->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv5->annotated_chromosome_[A]; + indiv5->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv5->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv5); + + indiv5->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv5->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv5->annotated_chromosome_[B]; + indiv5->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv5->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv5); + genome = nullptr; + + // Do transcription and translation + indiv5->start_stop_RNA(); + indiv5->prom_compute_RNA(*exp_s); + indiv5->start_protein(); + indiv5->compute_protein(); + indiv5->translate_protein(*exp_s, 1.0); + + + genome = new char[100]; + tmp_genome = indiv5->annotated_chromosome_[A]->dna_->subseq(0, + indiv5->annotated_chromosome_[A]->length(), + aevol::Strand::LAGGING); + strcpy(genome, tmp_genome.c_str()); + indiv6 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv6->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv6->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv6->annotated_chromosome_[A]; + indiv6->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv6->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv6); + + indiv6->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv6->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv6->annotated_chromosome_[B]; + indiv6->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv6->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv6); + genome = nullptr; + + + // Do transcription and translation + indiv6->start_stop_RNA(); + indiv6->prom_compute_RNA(*exp_s); + indiv6->start_protein(); + indiv6->compute_protein(); + indiv6->translate_protein(*exp_s, 1.0); + + + + // indiv7: (prom + AS + term + AS + AG + AS + prom) + // indiv8: reverse + genome = new char[100]; + sprintf(genome, "%s%s%s%s%s%s%s",prom[1], as[0], term, as[4], gene, as[3], lag_prom[0]); + + indiv7 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv7->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv7->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv7->annotated_chromosome_[A]; + indiv7->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv7->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv7); + + indiv7->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv7->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv7->annotated_chromosome_[B]; + indiv7->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv7->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv7); + genome = nullptr; + + // Do transcription and translation + indiv7->start_stop_RNA(); + indiv7->prom_compute_RNA(*exp_s); + indiv7->start_protein(); + indiv7->compute_protein(); + indiv7->translate_protein(*exp_s, 1.0); + + + genome = new char[100]; + tmp_genome = indiv7->annotated_chromosome_[A]->dna_->subseq(0, + indiv7->annotated_chromosome_[A]->length(), + aevol::Strand::LAGGING); + strcpy(genome, tmp_genome.c_str()); + indiv8 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv8->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv8->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv8->annotated_chromosome_[A]; + indiv8->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv8->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv8); + + indiv8->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv8->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv8->annotated_chromosome_[B]; + indiv8->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv8->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv8); + genome = nullptr; + + + // Do transcription and translation + indiv8->start_stop_RNA(); + indiv8->prom_compute_RNA(*exp_s); + indiv8->start_protein(); + indiv8->compute_protein(); + indiv8->translate_protein(*exp_s, 1.0); + + + // indiv9: (term + AS + AG + AS + prom-1) + // indiv10: reverse + genome = new char[100]; + sprintf(genome, "0%s%s%s%s%s",term, as[4], gene, as[3], bad_lag_prom[1]); + + indiv9 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv9->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv9->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv9->annotated_chromosome_[A]; + indiv9->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv9->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv9); + + indiv9->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv9->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv9->annotated_chromosome_[B]; + indiv9->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv9->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv9); + genome = nullptr; + + // Do transcription and translation + indiv9->start_stop_RNA(); + indiv9->prom_compute_RNA(*exp_s); + indiv9->start_protein(); + indiv9->compute_protein(); + indiv9->translate_protein(*exp_s, 1.0); + + + genome = new char[100]; + tmp_genome = indiv9->annotated_chromosome_[A]->dna_->subseq(0, + indiv9->annotated_chromosome_[A]->length(), + aevol::Strand::LAGGING); + strcpy(genome, tmp_genome.c_str()); + indiv10 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv10->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv10->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv10->annotated_chromosome_[A]; + indiv10->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv10->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv10); + + indiv10->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv10->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv10->annotated_chromosome_[B]; + indiv10->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv10->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv10); + genome = nullptr; + + + // Do transcription and translation + indiv10->start_stop_RNA(); + indiv10->prom_compute_RNA(*exp_s); + indiv10->start_protein(); + indiv10->compute_protein(); + indiv10->translate_protein(*exp_s, 1.0); + +} + +void IndividualTest::TearDown() { +// for (auto indiv : indivs1) { +// delete indiv; +// } +} + +// For each version of each individual constructed with a different +// fuzzy set implementation, we check that all values are correct. +// We don't need to change the fuzzy set implementation in the +// experimental setup again because it's only used at transcription and +// translation time. + +TEST_F(IndividualTest, TestIndiv1) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(99, indiv1->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(99, indiv1->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv1->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(1, rna_list.size()); + const auto* rna = rna_list.front(); + EXPECT_EQ(Strand::LEADING, rna->strand_); + EXPECT_EQ(0, rna->prom->pos); + EXPECT_FLOAT_EQ(0.6, rna->e); + EXPECT_EQ(50, rna->length); + + // Check protein list + auto prot_list = indiv1->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(1, prot_list.size()); + + const auto* prot = prot_list.front(); + EXPECT_EQ(Strand::LEADING, prot->strand_); + EXPECT_EQ(40, prot->protein_start); + EXPECT_EQ(4, prot->protein_length); + EXPECT_FLOAT_EQ(0.6, prot->e); + EXPECT_EQ(true, prot->is_init_); + EXPECT_EQ(1, prot->rna_list_.size()); + } +} + +TEST_F(IndividualTest, TestIndiv2) +{ + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(99, indiv2->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(99, indiv2->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv2->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(1, rna_list.size()); + + + // Check protein list + auto prot_list = indiv2->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv3) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(72, indiv3->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(72, indiv3->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv3->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv3->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + + +TEST_F(IndividualTest, TestIndiv4) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(72, indiv4->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(72, indiv4->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv4->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv4->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv5) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(71, indiv5->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(71, indiv5->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv5->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv5->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv6) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(71, indiv6->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(71, indiv6->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv6->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv6->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv7) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(98, indiv7->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(98, indiv7->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv7->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(1, rna_list.size()); + //ADD CHECK FOR LENGTH (and to other no prot but 1 rna tests too) + + // Check protein list + auto prot_list = indiv7->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv8) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(98, indiv8->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(98, indiv8->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv8->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(1, rna_list.size()); + const auto* rna = rna_list.front(); + EXPECT_EQ(Strand::LAGGING, rna->strand_); + EXPECT_EQ(0, rna->prom->pos); + EXPECT_FLOAT_EQ(0.6, rna->e); + EXPECT_EQ(50, rna->length); + + // Check protein list + auto prot_list = indiv8->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(1, prot_list.size()); + + const auto* prot = prot_list.front(); + EXPECT_EQ(Strand::LAGGING, prot->strand_); + EXPECT_EQ(40, prot->protein_start); + EXPECT_EQ(4, prot->protein_length); + EXPECT_FLOAT_EQ(0.6, prot->e); + EXPECT_EQ(true, prot->is_init_); + EXPECT_EQ(1, prot->rna_list_.size()); + } +} +TEST_F(IndividualTest, TestIndiv9) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(99, indiv9->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(99, indiv9->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv9->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv9->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +TEST_F(IndividualTest, TestIndiv10) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(99, indiv10->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(99, indiv10->annotated_chromosome_[chrsm]->length()); + + // Check RNA list + auto rna_list = indiv10->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv10->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + +// =========================================================================== +// Protected Methods +// =========================================================================== + +// =========================================================================== +// Non inline accessors +// =========================================================================== diff --git a/test/gtest/MiniEukTest.cpp b/test/gtest/MiniEukTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3b6af2a9e1b5c1f431dc571959aea2d7e669ade0 --- /dev/null +++ b/test/gtest/MiniEukTest.cpp @@ -0,0 +1,213 @@ +// **************************************************************************** +// +// Aevol - An in silico experimental evolution platform +// +// **************************************************************************** +// +// Copyright: See the AUTHORS file provided with the package or <www.aevol.fr> +// Web: http://www.aevol.fr/ +// E-mail: See <http://www.aevol.fr/contact/> +// Original Authors : Guillaume Beslon, Carole Knibbe, David Parsons +// +// This program 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 2 of the License, or +// (at your option) any later version. +// +// This program 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 this program. If not, see <http://www.gnu.org/licenses/>. +// +//***************************************************************************** + + + + +// ================================================================= +// Includes +// ================================================================= +#include <inttypes.h> +#include <cstring> + +#include <list> +#include <vector> +#include <memory> + +#include <gtest/gtest.h> + +#include "DnaFactory.h" +#include "ExpManager_7.h" +#include "ExpSetup.h" +#include "fuzzy/FuzzyFactory_7.h" +#include "Individual_7.h" +#include "legacy/biochemistry/Rna.h" +#include "legacy/biochemistry/Protein.h" +#include "macros.h" +#include "MutationParams.h" +#include "Strand.h" + +using namespace aevol; + +//############################################################################ +// # +// Class IndividualTest # +// # +//############################################################################ +class IndividualTest : public testing::Test +{ + protected: + virtual void SetUp(void); + virtual void TearDown(void); + + // We have an version of each individual for each fuzzy set flavor + Individual_7* indiv1; +}; + +// =========================================================================== +// Public Methods +// =========================================================================== +void IndividualTest::SetUp(void) +{ + // Build ad-hoc genomes + // (and reverse to test the same things on the lagging strand.): + // + // indiv1: LEAD (prom-1 + AS + AG + AS + term) + // size 22+5+28+6+11=72 + // AS = Arbitrary Sequence + // AG = Arbitrary Gene + // Do not modify the sequences ! + + // Define a few arbitrary sequences + char as[5][10] = { + "0011", + "11101", + "110011", + "11000", + "000101" + }; + + const char* SHINE_DAL_SEQ = "011011"; + // const char* SHINE_DAL_SEQ_LAG = "001001"; + // Define an arbitrary gene + char gene[100]; + sprintf(gene, "%s0011000100110110010001", SHINE_DAL_SEQ); + + // char lag_gene[100]; + // sprintf(lag_gene, "1100111011001001101110%s", SHINE_DAL_SEQ_LAG); + + // Define an arbitrary terminator + char term[TERM_SIZE+1] = "01000001101"; + // char bad_term_end[TERM_SIZE] = "0100000110"; + // char bad_term_beg[TERM_SIZE] = "1000001101"; + + // Define a few arbitrary promoters + // char prom[2][23] = { + // "0101010001110110010110", // dist from consensus: 2 => basal level: 0.6 + // "0101011001110010010010" // dist from consensus: 1 => basal level: 0.8 + // }; + + // char lag_prom[2][23] = { + // "1001011001000111010101", // dist from consensus: 2 => basal level: 0.6 + // "1011011011000110010101" // dist from consensus: 1 => basal level: 0.8 + // }; + + + char bad_prom[2][23] = { + "101010001110110010110", // removed first base : add 0 at end + "010101100111001001001" // removed last base : add 0 at begin + }; + + // char bad_lag_prom[2][23] = { + // "001011001000111010101", // removed first base : add 1 at end + // "101101101100011001010" // removed last base : add 1 at begin + // }; + + + // Initialize the experimental setup. + // These are needed in the GeneticUnit constructors. + ExpSetup* exp_s = new ExpSetup(nullptr); + MutationParams params_mut; + + + // Update fuzzy flavor and fuzzy factory // TODO<dpa> Still needed/useful? + FuzzyFlavor fuzzyFlavor = FuzzyFlavor::VECTOR; + exp_s->set_fuzzy_flavor(fuzzyFlavor); + + DnaFactory* dna_factory = new DnaFactory(DnaFactory_Policy::LOCAL_GLOBAL_FIT, 48, 1000, 16); + FuzzyFactory_7* fuzzy_factory = new FuzzyFactory_7(fuzzyFlavor, 16, 300, 16); + + + + // Build indiv1 LEAD (prom-1 + AS + AG + AS + term) + // Construct a genome with these arbitrary sequences + char* genome = new char[100]; + sprintf(genome, "%s%s%s%s%s0",bad_prom[0], as[1], gene, as[2], term); + + indiv1 = new Individual_7(1.0, dna_factory, fuzzy_factory); + indiv1->annotated_chromosome_[A]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv1->annotated_chromosome_[A]->dna_->ann_chrsm_ = indiv1->annotated_chromosome_[A]; + indiv1->annotated_chromosome_[A]->dna_->dna_factory_ = dna_factory; + indiv1->annotated_chromosome_[A]->dna_->set_indiv(genome, strlen(genome), indiv1); + + indiv1->annotated_chromosome_[B]->dna_ = dna_factory->get_dna(strlen(genome)); + indiv1->annotated_chromosome_[B]->dna_->ann_chrsm_ = indiv1->annotated_chromosome_[B]; + indiv1->annotated_chromosome_[B]->dna_->dna_factory_ = dna_factory; + indiv1->annotated_chromosome_[B]->dna_->set_indiv(genome, strlen(genome), indiv1); + genome = nullptr; + + // Do transcription and translation + indiv1->start_stop_RNA(); + indiv1->prom_compute_RNA(*exp_s); + indiv1->start_protein(); + indiv1->compute_protein(); + indiv1->translate_protein(*exp_s, 1.0); + +} + +void IndividualTest::TearDown() { +// for (auto indiv : indivs1) { +// delete indiv; +// } +} + +// For each version of each individual constructed with a different +// fuzzy set implementation, we check that all values are correct. +// We don't need to change the fuzzy set implementation in the +// experimental setup again because it's only used at transcription and +// translation time. + +TEST_F(IndividualTest, TestIndiv1) { + // Check that we have the right number of promoters, terminators etc + // and at the right positions + // "right" means those values we have computed by hand + for (auto chrsm: {A,B}){ + // Check genome size + EXPECT_EQ(72, indiv1->annotated_chromosome_[chrsm]->dna_->length()); + EXPECT_EQ(72, indiv1->annotated_chromosome_[chrsm]->length()); + + // Check Prom list + EXPECT_EQ(0, indiv1->annotated_chromosome_[chrsm]->promoter_list().promoter_count()); + + // Check RNA list + auto rna_list = indiv1->annotated_chromosome_[chrsm]->rnas(); + EXPECT_EQ(0, rna_list.size()); + + // Check protein list + auto prot_list = indiv1->annotated_chromosome_[chrsm]->proteins(); + EXPECT_EQ(0, prot_list.size()); + } +} + + + +// =========================================================================== +// Protected Methods +// =========================================================================== + +// =========================================================================== +// Non inline accessors +// ===========================================================================