[Avida-SVN] r2934 - in development/source: analyze script
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Tue Nov 11 10:00:40 PST 2008
Author: brysonda
Date: 2008-11-11 13:00:40 -0500 (Tue, 11 Nov 2008)
New Revision: 2934
Modified:
development/source/analyze/cGenotypeBatch.cc
development/source/analyze/cGenotypeBatch.h
development/source/script/ASAvidaLib.cc
Log:
Implement cGenotypeBatch::FindLastCommonAncestor.
Modified: development/source/analyze/cGenotypeBatch.cc
===================================================================
--- development/source/analyze/cGenotypeBatch.cc 2008-11-11 16:36:51 UTC (rev 2933)
+++ development/source/analyze/cGenotypeBatch.cc 2008-11-11 18:00:40 UTC (rev 2934)
@@ -145,6 +145,50 @@
}
+cAnalyzeGenotype* cGenotypeBatch::FindLastCommonAncestor()
+{
+ // Assumes that the batch contains a population and all of its common ancestors
+ // Finds the last common ancestor among all current organisms that are still alive,
+ // i.e. have an update_died of -1.
+
+ // Connect each genotype to its parent.
+ tListIterator<cAnalyzeGenotype> it(m_list);
+ tListIterator<cAnalyzeGenotype> parent_it(m_list);
+ cAnalyzeGenotype* on_child = NULL;
+ while ((on_child = it.Next())) {
+ parent_it.Reset();
+ cAnalyzeGenotype* on_parent = NULL;
+ while ((on_parent = parent_it.Next())) {
+ if (on_child->GetParentID() == on_parent->GetID()) {
+ on_child->LinkParent(on_parent);
+ break;
+ }
+ }
+ }
+
+ // Find the genotype without a parent (there should only be one)
+ it.Reset();
+ cAnalyzeGenotype* lca = NULL;
+ cAnalyzeGenotype* test_lca = NULL;
+ while ((test_lca = it.Next())) {
+ if (!test_lca->GetParent()) {
+ // It is an error to get two genotypes without a parent
+ if (lca) return NULL;
+ lca = test_lca;
+ }
+ }
+
+ // Follow the children from this parent until we find a genotype with more than one child.
+ // This is the last common ancestor.
+ while (lca->GetChildList().GetSize() == 1) {
+ lca = lca->GetChildList().Pop();
+ }
+
+ return new cAnalyzeGenotype(*lca);
+}
+
+
+
cGenotypeBatch* cGenotypeBatch::FindLineage(cAnalyzeGenotype* end_genotype) const
{
if ((end_genotype)) return FindLineage(end_genotype->GetID());
Modified: development/source/analyze/cGenotypeBatch.h
===================================================================
--- development/source/analyze/cGenotypeBatch.h 2008-11-11 16:36:51 UTC (rev 2933)
+++ development/source/analyze/cGenotypeBatch.h 2008-11-11 18:00:40 UTC (rev 2934)
@@ -89,6 +89,8 @@
inline cAnalyzeGenotype* FindOrganismRandom(cRandom* rng) const { return FindOrganismRandom(*rng); }
inline cAnalyzeGenotype* PopOrganismRandom(cRandom* rng) { return PopOrganismRandom(*rng); }
+ cAnalyzeGenotype* FindLastCommonAncestor();
+
cGenotypeBatch* FindLineage(cAnalyzeGenotype* end_genotype) const;
cGenotypeBatch* FindLineage(int end_genotype_id) const;
Modified: development/source/script/ASAvidaLib.cc
===================================================================
--- development/source/script/ASAvidaLib.cc 2008-11-11 16:36:51 UTC (rev 2933)
+++ development/source/script/ASAvidaLib.cc 2008-11-11 18:00:40 UTC (rev 2934)
@@ -81,6 +81,7 @@
// REGISTER_S_METHOD(cGenotypeBatch, "PopGenotypeRandom", PopGenotypeRandom, cAnalyzeGenotype* (cRandom*));
// REGISTER_C_METHOD(cGenotypeBatch, "FindOrganismRandom", FindOrganismRandom, cAnalyzeGenotype* (cRandom*));
// REGISTER_S_METHOD(cGenotypeBatch, "PopOrganismRandom", PopOrganismRandom, cAnalyzeGenotype* (cRandom*));
+ REGISTER_S_METHOD(cGenotypeBatch, "FindLastCommonAncestor", FindLastCommonAncestor, cAnalyzeGenotype* ());
REGISTER_C_METHOD(cGenotypeBatch, "FindLineage", FindLineage, cGenotypeBatch* (cAnalyzeGenotype*));
REGISTER_C_METHOD(cGenotypeBatch, "FindSexLineage", FindSexLineage, cGenotypeBatch* (cAnalyzeGenotype*, bool));
REGISTER_C_METHOD(cGenotypeBatch, "FindClade", FindClade, cGenotypeBatch* (cAnalyzeGenotype*));
More information about the Avida-cvs
mailing list