@ -0,0 +1,50 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_ENTITY_COMPONENT_GENOME_HPP | |||
#define ANTKEEPER_ENTITY_COMPONENT_GENOME_HPP | |||
#include <string> | |||
#include <vector> | |||
namespace entity { | |||
namespace component { | |||
/// Complete set of genetic material in an organism. | |||
struct genome | |||
{ | |||
/** | |||
* Number of complete sets of chromosomes in a cell. | |||
* | |||
* A value of `1` indicates the organism is haploid, `2` is diploid, `3` is triploid, etc. | |||
*/ | |||
unsigned int ploidy; | |||
/** | |||
* Set of DNA base sequences for every chromosomes in the genome. | |||
* | |||
* A DNA base sequence is a string of IUPAC DNA base symbols. Homologous chromosomes should be stored consecutively, such that in a diploid organism, a chromosome with an even index is homologous to the following chromosome. | |||
*/ | |||
std::vector<std::string> chromosomes; | |||
}; | |||
} // namespace component | |||
} // namespace entity | |||
#endif // ANTKEEPER_ENTITY_COMPONENT_GENOME_HPP |
@ -0,0 +1,39 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_ENTITY_COMPONENT_PROTEOME_HPP | |||
#define ANTKEEPER_ENTITY_COMPONENT_PROTEOME_HPP | |||
#include <string> | |||
#include <vector> | |||
namespace entity { | |||
namespace component { | |||
/// Set of all proteins that can be expressed by an organism. | |||
struct proteome | |||
{ | |||
/// Set of amino acid sequences of every protein in the proteome. | |||
std::vector<std::string> proteins; | |||
}; | |||
} // namespace component | |||
} // namespace entity | |||
#endif // ANTKEEPER_ENTITY_COMPONENT_PROTEOME_HPP |
@ -0,0 +1,34 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#include "entity/systems/morphogenesis.hpp" | |||
#include "entity/id.hpp" | |||
namespace entity { | |||
namespace system { | |||
morphogenesis::morphogenesis(entity::registry& registry): | |||
updatable(registry) | |||
{} | |||
void morphogenesis::update(double t, double dt) | |||
{} | |||
} // namespace system | |||
} // namespace entity |
@ -0,0 +1,60 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_ENTITY_SYSTEM_MORPHOGENESIS_HPP | |||
#define ANTKEEPER_ENTITY_SYSTEM_MORPHOGENESIS_HPP | |||
#include "entity/systems/updatable.hpp" | |||
namespace entity { | |||
namespace system { | |||
/** | |||
* Constructs the forms of organisms from their genetic codes. | |||
* | |||
* Algorithm: | |||
* | |||
* 1. Consider inital egg cell as a sphere at the origin. | |||
* 2. Use the marching cubes algorithm to generate a mesh from the isosurface formed by the sum of all cells. | |||
* 3. Generate evenly-distributed points across surface area of the mesh (Poisson sample?). | |||
* 4. For each point, evaluate morphogenic genes to determine type, direction, and color of the next cell. | |||
* 5. Create new cells given the output of step 4. | |||
* 6. Go to step 2 and repeat. | |||
*/ | |||
class morphogenesis: | |||
public updatable | |||
{ | |||
public: | |||
morphogenesis(entity::registry& registry); | |||
/** | |||
* Scales then adds the timestep `dt` to the current time, then recalculates the positions of morphogenesising bodies. | |||
* | |||
* @param t Time, in seconds. | |||
* @param dt Delta time, in seconds. | |||
*/ | |||
virtual void update(double t, double dt); | |||
private: | |||
}; | |||
} // namespace system | |||
} // namespace entity | |||
#endif // ANTKEEPER_ENTITY_SYSTEM_MORPHOGENESIS_HPP |
@ -0,0 +1,74 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#include "entity/systems/proteome.hpp" | |||
#include "entity/components/proteome.hpp" | |||
#include "genetics/sequence.hpp" | |||
#include "genetics/standard-code.hpp" | |||
namespace entity { | |||
namespace system { | |||
proteome::proteome(entity::registry& registry): | |||
updatable(registry) | |||
{ | |||
registry.on_construct<entity::component::genome>().connect<&proteome::on_genome_construct>(this); | |||
registry.on_replace<entity::component::genome>().connect<&proteome::on_genome_replace>(this); | |||
} | |||
void proteome::update(double t, double dt) | |||
{} | |||
void proteome::on_genome_construct(entity::registry& registry, entity::id entity_id, entity::component::genome& genome) | |||
{ | |||
on_genome_replace(registry, entity_id, genome); | |||
} | |||
void proteome::on_genome_replace(entity::registry& registry, entity::id entity_id, entity::component::genome& genome) | |||
{ | |||
// Allocate a proteome component | |||
entity::component::proteome proteome_component; | |||
// For each chromosome in the genome | |||
for (const std::string& chromosome: genome.chromosomes) | |||
{ | |||
// Find the first ORF in the chromosome | |||
auto orf = genetics::sequence::find_orf(chromosome.begin(), chromosome.end(), genetics::standard_code); | |||
// While the ORF is valid | |||
while (orf.start != chromosome.end()) | |||
{ | |||
// Translate the base sequence into an amino acid sequence (protein) | |||
std::string protein; | |||
genetics::sequence::translate(orf.start, orf.stop, std::back_inserter(protein), genetics::standard_code); | |||
// Append protein to the proteome | |||
proteome_component.proteins.push_back(protein); | |||
// Find the next ORF | |||
orf = genetics::sequence::find_orf(orf.stop, chromosome.end(), genetics::standard_code); | |||
} | |||
} | |||
// Assign or replace the entity's proteome component | |||
registry.assign_or_replace<entity::component::proteome>(entity_id, proteome_component); | |||
} | |||
} // namespace system | |||
} // namespace entity |
@ -0,0 +1,55 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_ENTITY_SYSTEM_PROTEOME_HPP | |||
#define ANTKEEPER_ENTITY_SYSTEM_PROTEOME_HPP | |||
#include "entity/systems/updatable.hpp" | |||
#include "entity/components/genome.hpp" | |||
#include "entity/id.hpp" | |||
namespace entity { | |||
namespace system { | |||
/** | |||
* Generates proteomes for every genome. | |||
*/ | |||
class proteome: | |||
public updatable | |||
{ | |||
public: | |||
proteome(entity::registry& registry); | |||
/** | |||
* Scales then adds the timestep `dt` to the current time, then recalculates the positions of proteomeing bodies. | |||
* | |||
* @param t Time, in seconds. | |||
* @param dt Delta time, in seconds. | |||
*/ | |||
virtual void update(double t, double dt); | |||
private: | |||
void on_genome_construct(entity::registry& registry, entity::id entity_id, entity::component::genome& genome); | |||
void on_genome_replace(entity::registry& registry, entity::id entity_id, entity::component::genome& genome); | |||
}; | |||
} // namespace system | |||
} // namespace entity | |||
#endif // ANTKEEPER_ENTITY_SYSTEM_PROTEOME_HPP |