[Avida-SVN] r3495 - development/source/main

dk at myxo.css.msu.edu dk at myxo.css.msu.edu
Thu Oct 15 09:26:21 PDT 2009


Author: dk
Date: 2009-10-15 12:26:21 -0400 (Thu, 15 Oct 2009)
New Revision: 3495

Modified:
   development/source/main/cPopulationInterface.cc
Log:
updated HGT to respect genome circularity

Modified: development/source/main/cPopulationInterface.cc
===================================================================
--- development/source/main/cPopulationInterface.cc	2009-10-15 15:27:27 UTC (rev 3494)
+++ development/source/main/cPopulationInterface.cc	2009-10-15 16:26:21 UTC (rev 3495)
@@ -650,9 +650,23 @@
 	fragment_list_type::iterator f=fragments.begin();
 	std::advance(f, ctx.GetRandom().GetInt(fragments.size()));
 	
-	// find the location within this organism's genome that best matches the selected fragment:
-	cGenomeUtil::substring_match ssm = cGenomeUtil::FindBestSubstringMatch(cell.GetOrganism()->GetGenome(), *f);
+	// need to take circularity of the genome into account.
+	// we can do this by appending the genome with a copy of its first fragment-size
+	// instructions.  handling insertions and replacements gets complicated after this...
+	cGenome circ(offspring);
+	for(int i=0; i<f->GetSize(); ++i) {
+		circ.Append(offspring[i]);
+	}
 	
+	// find the location within the offspring's genome that best matches the selected fragment:
+	cGenomeUtil::substring_match ssm = cGenomeUtil::FindBestSubstringMatch(circ, *f);
+	
+	if(ssm.position > offspring.GetSize()) {
+		// we matched on the circular portion of the genome, so we have to modify the
+		// matched position to reflect this;
+		ssm.position -= offspring.GetSize();
+	} 
+	
 	// there are (currently) two supported types of HGT mutations: insertions & replacements.
 	// which one are we doing?
 	if(ctx.GetRandom().P(m_world->GetConfig().HGT_INSERTION_MUT_P.Get())) {
@@ -660,13 +674,14 @@
 		offspring.Insert(ssm.position, *f);
 	} else {
 		// replacement: replace up to fragment size instructions in the genome.
-
-		// replacement counts forward, so let's get the starting index of where the
-		// fragment needs to go.  *inclusive* of the final match position (so +1), and
-		// a floor at 0.
-		int start = std::max(ssm.position-f->GetSize()+1, 0);
-
-		offspring.Replace(start, ssm.position-start+1, *f);
+		// note that replacement can wrap around from front->back.  replacement counts
+		// forward, so we have to find the start position first.
+		int start = ssm.position - f->GetSize() + 1;
+		if(start < 0) { start += offspring.GetSize(); }
+		for(int i=0; i<f->GetSize(); ++i) {
+			offspring[start] = (*f)[i];
+			if(++start >= offspring.GetSize()) { start = 0; }
+		}
 	}
 	
 	// resource utilization, cleanup, and stats tracking:




More information about the Avida-cvs mailing list