Avida

 

Changeset 3638

Show
Ignore:
Timestamp:
02/10/10 16:09:19 (7 months ago)
Author:
dk
Message:

Added option to scramble HGT fragments prior to insertion or replacement.

Location:
development/source/main
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • development/source/main/cAvidaConfig.h

    r3629 r3638  
    677677        CONFIG_ADD_VAR(HGT_INSERTION_MUT_P, double, 0.5, "Probability that an HGT mutation will result in an insertion (default=0.5); replacement if false."); 
    678678        CONFIG_ADD_VAR(HGT_CONJUGATION_METHOD, int, 0, "Method used to select the receiver of an HGT conjugation (0=faced [default])"); 
     679        CONFIG_ADD_VAR(HGT_SCRAMBLE_FRAGMENT, int, 0, "Scramble each fragment after match, prior to insertion or replacment; 0=false [default], 1=true."); 
    679680         
    680681  CONFIG_ADD_GROUP(INST_RES_GROUP, "Resource-Dependent Instructions Settings"); 
  • development/source/main/cGenomeUtil.cc

    r3629 r3638  
    384384} 
    385385 
     386 
     387/*! Split a genome into a list of fragments, each with the given mean size and variance, and add them to the given fragment list. 
     388 */ 
    386389void cGenomeUtil::RandomSplit(cAvidaContext& ctx, double mean, double variance, const cGenome& genome, fragment_list_type& fragments) {  
    387390        // rotate this genome to remove bais for the beginning and end of the genome: 
     
    405408 
    406409 
     410/*! Randomly shuffle the instructions within genome in-place. 
     411 */ 
     412void cGenomeUtil::RandomShuffle(cAvidaContext& ctx, cGenome& genome) { 
     413        std::vector<int> idx(static_cast<std::size_t>(genome.GetSize())); 
     414        iota(idx.begin(), idx.end(), 0); 
     415        cRandomStdAdaptor rng(ctx.GetRandom()); 
     416        std::random_shuffle(idx.begin(), idx.end(), rng); 
     417        cGenome shuffled(genome.GetSize()); 
     418        for(int i=0; i<genome.GetSize(); ++i) { 
     419                shuffled[i] = genome[idx[i]]; 
     420        } 
     421        genome = shuffled; 
     422} 
     423 
    407424cGenome cGenomeUtil::Crop(const cGenome & in_genome, int start, int end) 
    408425{ 
  • development/source/main/cGenomeUtil.h

    r3629 r3638  
    103103        //! Split a genome into a list of fragments, each with the given mean size and variance, and add them to the given fragment list. 
    104104        static void RandomSplit(cAvidaContext& ctx, double mean, double variance, const cGenome& genome, fragment_list_type& fragments); 
     105        //! Randomly shuffle the instructions within genome in-place. 
     106        static void RandomShuffle(cAvidaContext& ctx, cGenome& genome); 
    105107         
    106108  // ===== Construction methods ===== 
  • development/source/main/cPopulationInterface.cc

    r3632 r3638  
    703703        fragment_list_type fragments(m_hgt_support->_pending); // these come from conjugation 
    704704         
    705         // these come from natural competence (ie, eating the dead): 
     705        // these come from "natural" competence (ie, eating the dead): 
    706706        if((m_world->GetConfig().HGT_MUTATION_P.Get() > 0.0) 
    707707                 && (ctx.GetRandom().P(m_world->GetConfig().HGT_MUTATION_P.Get()))) { 
     
    745745                switch(m_world->GetConfig().HGT_FRAGMENT_SELECTION.Get()) { 
    746746                        case 0: { // random selection 
    747                                 HGTRandomFragmentSelection(ctx, offspring, i, location); 
     747                                HGTMatchPlacement(ctx, offspring, i, location); 
    748748                                break; 
    749749                        } 
    750750                        case 1: { // random selection with redundant instruction trimming 
    751                                 HGTTrimmedFragmentSelection(ctx, offspring, i, location); 
     751                                HGTTrimmedPlacement(ctx, offspring, i, location); 
    752752                                break; 
    753753                        } 
    754754                        case 2: { // random selection and random placement 
    755                                 HGTRandomFragmentPlacement(ctx, offspring, i, location); 
     755                                HGTRandomPlacement(ctx, offspring, i, location); 
    756756                                break; 
    757757                        } 
     
    760760                                break; 
    761761                        } 
     762                } 
     763                 
     764                // as a type of control, potentially "scramble" the genome after matching 
     765                // and prior to insertion to see if the fragment is contributing useful code.            
     766                if(m_world->GetConfig().HGT_SCRAMBLE_FRAGMENT.Get()) { 
     767                        cGenomeUtil::RandomShuffle(ctx, *i); 
    762768                } 
    763769                 
     
    779785 
    780786 
    781 /*! Randomly select the fragment used for HGT mutation. 
    782  */ 
    783 void cPopulationInterface::HGTRandomFragmentSelection(cAvidaContext& ctx, const cGenome& offspring, 
    784                                                                                                                                                                                                                         fragment_list_type::iterator& selected, 
    785                                                                                                                                                                                                                         substring_match& location) { 
     787/*! Place the fragment at the location of best match. 
     788 */ 
     789void cPopulationInterface::HGTMatchPlacement(cAvidaContext& ctx, const cGenome& offspring, 
     790                                                                                                                                                                                 fragment_list_type::iterator& selected, 
     791                                                                                                                                                                                 substring_match& location) { 
    786792        // find the location within the offspring's genome that best matches the selected fragment: 
    787793        location = cGenomeUtil::FindUnbiasedCircularMatch(ctx, offspring, *selected); 
     
    789795 
    790796 
    791 /*! Randomly select the fragment used for HGT mutation, trimming redundant instructions. 
    792   
    793  In this fragment selection method, the fragment itself is selected randomly, but the 
     797/*! Place the fragment at the location of best match, with redundant instructions trimmed. 
     798 
     799 In this fragment selection method, the 
    794800 match location within the genome is calculated on a "trimmed" fragment.  Specifically, 
    795801 the trimmed fragment has all duplicate instructions at its end removed prior to the match. 
     
    798804 increases the insertion rate.  E.g., hgt(abcde, abcccc) -> abccccde. 
    799805 */ 
    800 void cPopulationInterface::HGTTrimmedFragmentSelection(cAvidaContext& ctx, const cGenome& offspring, 
     806void cPopulationInterface::HGTTrimmedPlacement(cAvidaContext& ctx, const cGenome& offspring, 
    801807                                                                                                                                                                                                                         fragment_list_type::iterator& selected, 
    802808                                                                                                                                                                                                                         substring_match& location) { 
     
    812818 
    813819 
    814 /*! Random selection of the fragment used for HGT mutation, located at a random position. 
     820/*! Place the fragment at a random location. 
    815821  
    816  Here we select a random fragment and a random location for that fragment within the offspring. 
     822 Here we select a random location for the fragment within the offspring. 
    817823 The beginning of the fragment location is selected at random, while the end is selected a 
    818824 random distance (up to the length of the selected fragment * 2) instructions away. 
    819825 */ 
    820 void cPopulationInterface::HGTRandomFragmentPlacement(cAvidaContext& ctx, const cGenome& offspring, 
     826void cPopulationInterface::HGTRandomPlacement(cAvidaContext& ctx, const cGenome& offspring, 
    821827                                                                                                                                                                                                                        fragment_list_type::iterator& selected, 
    822828                                                                                                                                                                                                                        substring_match& location) { 
  • development/source/main/cPopulationInterface.h

    r3629 r3638  
    157157         
    158158protected: 
    159         //! Random selection of the fragment used for HGT mutation, located at the best match. 
    160         void HGTRandomFragmentSelection(cAvidaContext& ctx, const cGenome& offspring, 
    161                                                                                                                                         fragment_list_type::iterator& selected, 
    162                                                                                                                                         substring_match& location); 
    163         //! Random selection of the fragment used for HGT mutation, with redundant instructions trimmed. 
    164         void HGTTrimmedFragmentSelection(cAvidaContext& ctx, const cGenome& offspring, 
    165                                                                                                                                         fragment_list_type::iterator& selected, 
    166                                                                                                                                         substring_match& location);     
    167         //! Random selection of the fragment used for HGT mutation, located at a random position. 
    168         void HGTRandomFragmentPlacement(cAvidaContext& ctx, const cGenome& offspring, 
    169                                                                                                                                         fragment_list_type::iterator& selected, 
    170                                                                                                                                         substring_match& location); 
     159        //! Place the fragment at the location of best match. 
     160        void HGTMatchPlacement(cAvidaContext& ctx, const cGenome& offspring, 
     161                                                                                                 fragment_list_type::iterator& selected, 
     162                                                                                                 substring_match& location); 
     163        //! Place the fragment at the location of best match, with redundant instructions trimmed. 
     164        void HGTTrimmedPlacement(cAvidaContext& ctx, const cGenome& offspring, 
     165                                                                                                        fragment_list_type::iterator& selected, 
     166                                                                                                        substring_match& location);     
     167        //! Place the fragment at a random location. 
     168        void HGTRandomPlacement(cAvidaContext& ctx, const cGenome& offspring, 
     169                                                                                                        fragment_list_type::iterator& selected, 
     170                                                                                                        substring_match& location); 
    171171        //! Support for stateful HGT mutations. 
    172172        struct HGTSupport {