Skip to content

Commit

Permalink
Merge pull request #95 from mmore500/whole-genome-duplication
Browse files Browse the repository at this point in the history
Add whole genome duplication event
  • Loading branch information
mmore500 authored Jan 27, 2025
2 parents f371b0f + 092e39d commit 47f13da
Show file tree
Hide file tree
Showing 118 changed files with 240,617 additions and 14 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ jobs:
# run: |
# bash ./run_tests

tests-mac:
runs-on: macos-12
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
brew install cmake
brew install python
- name: Build Avida
run: |
./build_avida
- name: Run tests
run: |
./run_tests
# tests-mac:
# runs-on: macos-12
# steps:
# - uses: actions/checkout@v2
# - name: Install dependencies
# run: |
# brew install cmake
# brew install python
# - name: Build Avida
# run: |
# ./build_avida
# - name: Run tests
# run: |
# ./run_tests

docker-build:
name: Docker Image Build
Expand Down
73 changes: 73 additions & 0 deletions avida-core/source/actions/PopulationActions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,77 @@ class cActionInject : public cAction
}
};

/*
Replaces all population members with end-to-end duplicated versions of
themselves.
*/
class cActionInjectWholeGenomeDuplications : public cAction
{

public:
cActionInjectWholeGenomeDuplications(cWorld* world, const cString& args, Feedback&) : cAction(world, args){}

static const cString GetDescription() { return "No arguments"; }

void Process(cAvidaContext& ctx)
{
for (int i = 0; i < m_world->GetPopulation().GetSize(); i++)
{
if (!m_world->GetPopulation().GetCell(i).IsOccupied()) continue;

auto genome_str = m_world->GetPopulation().GetCell(i).GetOrganism()->GetGenome().AsString();
auto seq_str = m_world->GetPopulation().GetCell(i).GetOrganism()->GetGenome().AsString();
seq_str.Pop(',');
seq_str.Pop(',');
std::cout << "genome_str: " << genome_str << std::endl;
std::cout << "seq_str: " << seq_str << std::endl;
genome_str += seq_str;
std::cout << "genome_str cat: " << genome_str << std::endl;

const Genome genome(genome_str);
m_world->GetPopulation().Inject(genome, Systematics::Source(Systematics::DIVISION, "whole-genome duplication", true), ctx, i);
}
}
};

/*
Replaces all population members with end-to-end duplicated versions of
themselves, with duplicated content being replaced with nop-c instructions.
*/
class cActionInjectWholeGenomeDuplicationsNopCPrepend : public cAction
{

public:
cActionInjectWholeGenomeDuplicationsNopCPrepend(cWorld* world, const cString& args, Feedback&) : cAction(world, args){}

static const cString GetDescription() { return "No arguments"; }

void Process(cAvidaContext& ctx)
{
for (int i = 0; i < m_world->GetPopulation().GetSize(); i++)
{
if (!m_world->GetPopulation().GetCell(i).IsOccupied()) continue;

auto genome_str = m_world->GetPopulation().GetCell(i).GetOrganism()->GetGenome().AsString();
auto seq_str = m_world->GetPopulation().GetCell(i).GetOrganism()->GetGenome().AsString();
seq_str.Pop(',');
seq_str.Pop(',');
genome_str = genome_str.Substring(
0, genome_str.GetSize() - seq_str.GetSize()
);
for (int j = 0; j < seq_str.GetSize(); j++) {
genome_str += "c";
}

genome_str += seq_str;

const Genome genome(genome_str);
m_world->GetPopulation().Inject(genome, Systematics::Source(Systematics::DIVISION, "whole-genome duplication nopc prepend", true), ctx, i);
}
}
};

/*
Injects a randomly generated genome into the population.
Expand Down Expand Up @@ -6133,6 +6204,8 @@ void RegisterPopulationActions(cActionLibrary* action_lib)
{
action_lib->Register<cActionInject>("Inject");
action_lib->Register<cActionInjectRandom>("InjectRandom");
action_lib->Register<cActionInjectWholeGenomeDuplications>("InjectWholeGenomeDuplications");
action_lib->Register<cActionInjectWholeGenomeDuplicationsNopCPrepend>("InjectWholeGenomeDuplicationsNopCPrepend");
action_lib->Register<cActionInjectAllRandomRepro>("InjectAllRandomRepro");
action_lib->Register<cActionInjectAll>("InjectAll");
action_lib->Register<cActionInjectRange>("InjectRange");
Expand Down
37 changes: 37 additions & 0 deletions avida-core/tests/whole_genome_duplication/config/avida.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
VERSION_ID 2.12.0

WORLD_GEOMETRY 2 # 2 = Torus
RANDOM_SEED 101

EVENT_FILE events.cfg # File containing list of events during run
ENVIRONMENT_FILE environment.cfg # File that describes the environment

INST_SET_LOAD_LEGACY 0

INSTSET heads_default:hw_type=0
INST nop-A
INST nop-B
INST nop-C
INST if-n-equ
INST if-less
INST pop
INST push
INST swap-stk
INST swap
INST shift-r
INST shift-l
INST inc
INST dec
INST add
INST sub
INST nand
INST IO
INST h-alloc
INST h-divide
INST h-copy
INST h-search
INST mov-head
INST jmp-head
INST get-head
INST if-label
INST set-flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
h-alloc # Allocate space for child
h-search # Locate the end of the organism
nop-C #
nop-A #
mov-head # Place write-head at beginning of offspring.
nop-C #
nop-C #
nop-C #
nop-C #
nop-C #
h-search # Mark the beginning of the copy loop
h-copy # Do the copy
if-label # If we're done copying....
nop-C #
nop-A #
h-divide # ...divide!
mov-head # Otherwise, loop back to the beginning of the copy loop.
nop-A # End label.
nop-B #
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
REACTION NOT not process:value=1.0:type=pow requisite:max_count=1
REACTION NAND nand process:value=1.0:type=pow requisite:max_count=1
REACTION AND and process:value=2.0:type=pow requisite:max_count=1
REACTION ORN orn process:value=2.0:type=pow requisite:max_count=1
REACTION OR or process:value=3.0:type=pow requisite:max_count=1
REACTION ANDN andn process:value=3.0:type=pow requisite:max_count=1
REACTION NOR nor process:value=4.0:type=pow requisite:max_count=1
REACTION XOR xor process:value=4.0:type=pow requisite:max_count=1
REACTION EQU equ process:value=5.0:type=pow requisite:max_count=1
11 changes: 11 additions & 0 deletions avida-core/tests/whole_genome_duplication/config/events.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
u begin Inject default-classic.org

# Print all of the standard data files...
u 0:10:end PrintAverageData # Save info about they average genotypes

# Setup the exit time and full population data collection.
u 0:10:end SavePopulation

u 99 InjectWholeGenomeDuplications

u 500 Exit # exit
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Avida Average Data
# Sun Nov 3 20:35:15 2024
# 1: Update
# 2: Merit
# 3: Gestation Time
# 4: Fitness
# 5: Repro Rate?
# 6: (deprecated) Size
# 7: Copied Size
# 8: Executed Size
# 9: (deprecated) Abundance
# 10: Proportion of organisms that gave birth in this update
# 11: Proportion of Breed True Organisms
# 12: (deprecated) Genotype Depth
# 13: Generation
# 14: Neutral Metric
# 15: Lineage Label
# 16: True Replication Rate (based on births/update, time-averaged)

0 16 65 0 0 0 19 16 0 1 1 0 0 0 0 0
10 16 65 0.246154 0 0 19 16 0 0.2 0.2 0 3.93333 0.779251 0 0
20 15.573 63.7753 0.243426 0 0 18.6404 15.573 0 0.168539 0.146067 0 8.03371 1.45069 0 0
30 15.7576 64.1515 0.245311 0 0 18.7424 15.7576 0 0.242424 0.181818 0 12.6894 1.93131 0 0
40 15.7563 63.7329 0.246933 0 0 18.6862 15.7563 0 0.259259 0.181287 0 17.2476 2.2828 0 0
50 15.7725 63.9512 0.246373 0 0 18.6848 15.7725 0 0.289678 0.234184 0 21.9501 2.97972 0 0
60 15.8077 63.8665 0.247322 0 0 18.7475 15.8077 0 0.246734 0.189405 0 26.6379 2.88236 0 0
70 15.8563 64.3477 0.246562 0 0 18.788 15.8563 0 0.277328 0.203947 0 31.4686 3.19316 0 0
80 15.8771 64.2914 0.246868 0 0 18.8335 15.8771 0 0.274812 0.206015 0 36.1383 2.84073 0 0
90 15.9991 64.8297 0.246646 0 0 18.9429 15.9991 0 0.293478 0.222222 0 40.878 2.24124 0 0
100 19.7562 57.2447 0 0 0 38.6572 19.7562 0 0 0 0 0 0 0 0
110 16.5183 65.3103 0.243985 0 0 20.4803 16.5183 0 0.205278 0.135278 0 3.96528 0.0115889 0 0
120 16.3907 66.0997 0.248073 0 0 19.2837 16.3912 0 0.300639 0.22534 0 8.68436 -0.00972108 0 0
130 16.4701 66.3394 0.248873 0 0 19.3492 16.4726 0 0.299138 0.221018 0 13.387 0.00674033 0 0
140 16.5258 66.1006 0.250796 0 0 19.3822 16.5294 0 0.288889 0.226389 0 18.1133 0.0585448 0 0
150 16.7952 66.4422 0.253586 0 0 19.6145 16.7957 0 0.291551 0.220956 0 22.9405 0.115293 0 0
160 16.92 66.8869 0.254127 0 0 19.706 16.9214 0 0.288136 0.212003 0 27.7066 0.25028 0 0
170 17.0906 66.7487 0.257248 0 0 19.8577 17.0914 0 0.284047 0.208727 0 32.6676 0.23917 0 0
180 17.6174 67.549 0.261213 0 0 20.3576 17.6174 0 0.277577 0.209225 0 37.7549 0.016051 0 0
190 18.1045 68.5654 0.265543 0 0 20.8372 18.105 0 0.282023 0.208947 0 42.9114 -0.24512 0 0
200 18.3968 68.3668 0.269041 0 0 21.1986 18.3968 0 0.267798 0.195495 0 48.0003 0.219401 0 0
210 18.4747 67.7281 0.273427 0 0 21.3219 18.4753 0 0.277222 0.208333 0 53.3544 0.186011 0 0
220 18.948 68.4396 0.277368 0 0 21.7997 18.948 0 0.278689 0.195332 0 58.7369 0.238729 0 0
230 19.3168 68.9578 0.282429 0 0 22.2335 19.3205 0 0.270984 0.199555 0 64.4252 -0.235457 0 0
240 19.8136 70.2242 0.286648 0 0 22.7155 19.8463 0 0.255904 0.185885 0 69.788 -0.24973 0 0
250 20.3997 70.3722 0.293529 0 0 23.3396 20.4234 0 0.256467 0.188039 0 75.7508 -0.144379 0 0
260 20.7512 69.7832 0.301026 0 0 23.6439 20.7751 0 0.262997 0.202669 0 81.712 0.216172 0 0
270 21.3595 70.8413 0.306906 0 0 24.2209 21.3651 0 0.270909 0.18783 0 87.9203 0.675043 0 0
280 21.6804 71.085 0.311666 0 0 24.5356 21.6898 0 0.26876 0.193163 0 93.955 0.883239 0 0
290 21.6151 70.2518 0.315118 0 0 24.5523 21.6398 0 0.259311 0.192607 0 99.6109 0.955468 0 0
300 21.5688 68.6819 0.321713 0 0 24.4868 21.5696 0 0.272576 0.19172 0 105.649 0.606747 0 0
310 21.8231 68.2739 0.325618 0 0 24.6583 21.8239 0 0.273056 0.203611 0 111.133 0.618987 0 0
320 21.761 67.6949 0.330179 0 0 24.576 21.7635 0 0.293137 0.212837 0 117.265 0.692737 0 0
330 21.345 65.4869 0.334408 0 0 24.1422 21.3472 0 0.295556 0.217222 0 123.538 -0.202152 0 0
340 21.3204 65.3659 0.337257 0 0 24.1095 21.3212 0 0.289247 0.218116 0 129.792 -0.0288514 0 0
350 21.307 64.7338 0.340769 0 0 24.1164 21.3215 0 0.292026 0.206724 0 136.063 0.131069 0 0
360 21.3907 63.973 0.346287 0 0 24.249 21.3912 0 0.296749 0.220339 0 142.431 0.169888 0 0
370 21.5521 64.3551 0.349896 0 0 24.3882 21.5529 0 0.308975 0.220061 0 148.896 0.0482889 0 0
380 21.1928 62.1081 0.355021 0 0 24.0247 21.1933 0 0.311667 0.223889 0 155.375 0.0160717 0 0
390 20.5309 59.7968 0.359692 0 0 23.3243 20.5314 0 0.33463 0.243469 0 162.42 0.253333 0 0
400 20.6019 59.0108 0.361598 0 0 23.3858 20.6025 0 0.33 0.2375 0 168.779 -0.121841 0 0
410 20.5675 57.8769 0.364893 0 0 23.2839 20.5681 0 0.324167 0.238611 0 175.279 0.0679735 0 0
420 19.9244 55.8144 0.368565 0 0 22.5964 19.9247 0 0.323333 0.239167 0 182.22 0.284736 0 0
430 19.8033 55.0345 0.371051 0 0 22.4398 19.8033 0 0.342317 0.261184 0 188.834 -0.0896306 0 0
440 19.7773 54.5385 0.372602 0 0 22.4618 19.7773 0 0.348068 0.263831 0 195.243 -0.329435 0 0
450 19.5428 53.5539 0.376048 0 0 22.1772 19.5428 0 0.357222 0.269167 0 202.097 0.443936 0 0
460 19.5251 53.0864 0.377587 0 0 22.1331 19.5251 0 0.353987 0.272298 0 208.666 0.785116 0 0
470 19.6179 53.0167 0.379735 0 0 22.2573 19.6185 0 0.354821 0.266185 0 215.423 0.867064 0 0
480 19.6134 52.8835 0.382005 0 0 22.2829 19.6134 0 0.359922 0.269594 0 222.16 2.51841 0 0
490 19.4023 51.8225 0.386416 0 0 21.9722 19.4023 0 0.346485 0.26424 0 229.421 2.61261 0 0
500 19.2374 51.4389 0.386223 0 0 21.858 19.2374 0 0.371317 0.288494 0 236.2 3.26682 0 0.185777
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#filetype genotype_data
#format id src src_args parents num_units total_units length merit gest_time fitness gen_born update_born update_deactivated depth hw_type inst_set sequence cells gest_offset lineage
# Structured Population Save
# Sun Nov 3 20:35:15 2024
# 1: ID
# 2: Source
# 3: Source Args
# 4: Parent ID(s)
# 5: Number of currently living organisms
# 6: Total number of organisms that ever existed
# 7: Genome Length
# 8: Average Merit
# 9: Average Gestation Time
# 10: Average Fitness
# 11: Generation Born
# 12: Update Born
# 13: Update Deactivated
# 14: Phylogenetic Depth
# 15: Hardware Type ID
# 16: Inst Set Name
# 17: Genome Sequence
# 18: Occupied Cell IDs
# 19: Gestation (CPU) Cycle Offsets
# 20: Lineage Label

1 div:ext (none) (none) 1 1 19 0 0 0 0 -1 -1 0 0 heads_default rucavcccccutycasvab 0 33 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#filetype genotype_data
#format id src src_args parents num_units total_units length merit gest_time fitness gen_born update_born update_deactivated depth hw_type inst_set sequence cells gest_offset lineage
# Structured Population Save
# Sun Nov 3 20:35:15 2024
# 1: ID
# 2: Source
# 3: Source Args
# 4: Parent ID(s)
# 5: Number of currently living organisms
# 6: Total number of organisms that ever existed
# 7: Genome Length
# 8: Average Merit
# 9: Average Gestation Time
# 10: Average Fitness
# 11: Generation Born
# 12: Update Born
# 13: Update Deactivated
# 14: Phylogenetic Depth
# 15: Hardware Type ID
# 16: Inst Set Name
# 17: Genome Sequence
# 18: Occupied Cell IDs
# 19: Gestation (CPU) Cycle Offsets
# 20: Lineage Label

1 div:ext (none) (none) 13 13 19 16 65 0.246154 0 -1 -1 0 0 heads_default rucavcccccutycasvab 0,59,60,61,119,179,3480,3481,3482,3483,3540,3541,3542 64,32,32,64,32,33,33,64,32,33,64,32,64 0,0,0,0,0,0,0,0,0,0,0,0,0
2 div:int (none) 1 1 1 19 0 0 0 3 7 -1 1 0 heads_default rucavcccccutycasvar 3422 99 0
3 div:int (none) 1 1 1 20 0 0 0 4 9 -1 1 0 heads_default rucavcccciutycastvab 118 66 0
Loading

0 comments on commit 47f13da

Please sign in to comment.