示例#1
0
def get_gynodioecious_mating(r_rate,
                             weight,
                             size,
                             sex_ratio,
                             loci,
                             allele_length,
                             field='self_gen'):
    """
    Sets up gynodioecious mating.
    """

    sex_mode = (simu.PROB_OF_MALES, sex_ratio)

    rec_loci = [allele_length * i - 1 for i in range(1, loci + 1)]

    selfing = simu.SelfMating(ops=[
        simu.Recombinator(rates=r_rate, loci=rec_loci),
        cf.MySelfingTagger(field)
    ],
                              sexMode=sex_mode,
                              subPops=[(0, 0)],
                              weight=weight)

    outcross = simu.RandomMating(ops=[
        simu.Recombinator(rates=r_rate, loci=rec_loci),
        cf.MySelfingTagger(field)
    ],
                                 sexMode=sex_mode,
                                 weight=weight)

    return simu.HeteroMating(matingSchemes=[selfing, outcross],
                             subPopSize=size)
    def test_selfing_after_outcrossing(self):
        """Test scinario: generations of selfing after generations of outcrossing."""

        # outcrossing
        self.sim.evolve(initOps=self.initOps,
                        matingScheme=simu.RandomMating(
                            subPopSize=10,
                            sexMode=self.sexMode,
                            ops=[
                                simu.MendelianGenoTransmitter(),
                                cf.MyOutcrossingTagger()
                            ]),
                        gen=10)

        for pop in self.sim.populations():
            for ind in pop.individuals():
                assert ind.info('self_gen') == 0

        assert pop.dvars().gen == 10

        # selfing
        self.sim.evolve(
            initOps=self.initOps,
            matingScheme=simu.SelfMating(
                subPopSize=10,
                sexMode=self.sexMode,
                ops=[simu.SelfingGenoTransmitter(),
                     cf.MySelfingTagger()]),
            gen=10)

        for pop in self.sim.populations():
            for ind in pop.individuals():
                assert ind.info('self_gen') == 10

        assert pop.dvars().gen == 20
示例#3
0
def get_pure_hermaphrodite_mating(r_rate,
                                  weight,
                                  size,
                                  loci,
                                  allele_length,
                                  field='self_gen'):
    """
    Construct mating scheme for pure hermaphrodite with partial selfing under the
    infinite sites model.

    A fraction, 0 <= weight <= 1, of offspring is generated by selfing, and others are
    generated by outcrossing.  In this model, there is no specific sex so that any
    individual can mate with any other individuals in a population.
    Furthermore, a parent can participate in both selfing and outcrossing.
    """
    field = str(field)
    # Index of sites, after which recombinations happen.
    rec_loci = [allele_length * i - 1 for i in range(1, loci + 1)]
    selfing = simu.SelfMating(ops=[
        simu.Recombinator(rates=r_rate, loci=rec_loci),
        cf.MySelfingTagger(field)
    ],
                              weight=weight)

    outcross = simu.HomoMating(
        chooser=simu.PyParentsChooser(generator=cf.pickTwoParents),
        generator=simu.OffspringGenerator(ops=[
            simu.Recombinator(rates=r_rate, loci=rec_loci),
            cf.MyOutcrossingTagger(field)
        ]),
        weight=1.0 - weight)

    return simu.HeteroMating(matingSchemes=[selfing, outcross],
                             subPopSize=size)
示例#4
0
 def expand_by_selfing(self, pop, recombination_rates):
     """
     Specific for plant populations capable of selfing.
     Creates an F2 subpopulations generation by selfing the individuals of
     'pop'. Works on a population with one or more subpopulations.
     :param pop:
     """
     # self.odd_to_even(pop)
     num_sub_pops = pop.numSubPop()
     progeny_per_individual = int(self.operating_population_size / 2)
     return pop.evolve(
         preOps=[
             sim.MergeSubPops(),
             sim.PyEval(r'"Generation: %d\n" % gen'),
             sim.SplitSubPops(sizes=[1] * num_sub_pops, randomize=False),
         ],
         matingScheme=sim.SelfMating(
             subPopSize=[progeny_per_individual] * num_sub_pops,
             numOffspring=progeny_per_individual,
             ops=[
                 sim.Recombinator(rates=recombination_rates),
                 sim.IdTagger(),
                 sim.PedigreeTagger()
             ],
         ),
         gen=1,
     )
示例#5
0
 def create_self_crosses(self, existing_pop, offspring_per_individual):
     new_pop_size = offspring_per_individual * existing_pop.popSize()
     existing_pop.evolve(
         matingScheme=sim.SelfMating(
             replacement=False,
             numOffspring=offspring_per_individual,
             subPopSize=new_pop_size,
             ops=[
                 sim.IdTagger(),
                 sim.PedigreeTagger(),
                 sim.Recombinator(rates=0.01)
             ],
         ),
         gen=1,
     )
    def test_pure_selfing(self):
        """Test pure inbreeding population.

        When all individuals undergo selfing, the values in `self_gen` should be identical
        to the number of generations since simulations started.
        """
        self.sim.evolve(
            initOps=self.initOps,
            matingScheme=simu.SelfMating(
                subPopSize=10,
                sexMode=self.sexMode,
                ops=[simu.SelfingGenoTransmitter(),
                     cf.MySelfingTagger()]),
            gen=10)

        for pop in self.sim.populations():
            for ind in pop.individuals():
                assert ind.info('self_gen') == 10
示例#7
0
 def _generate_f_two(self, pop: sim.Population) -> sim.Population:
     """
     Creates an F2 subpopulations generation by selfing the individuals of 'pop'. Works on a population with one
     or more subpopulations.
     """
     pop.vars()['generations'][2] = 'F_2'
     self.odd_to_even(pop)
     num_sub_pops = pop.numSubPop()
     progeny_per_individual = int(self.selected_population_size/2)
     print("Creating the F_two population.")
     return pop.evolve(
         preOps=[
             sim.MergeSubPops(),
             sim.PyEval(r'"Generation: %d\n" % gen'),
             operators.CalcTripletFreq(),
             sim.PyExec('triplet_freq[gen]=tripletFreq'),
             sim.SplitSubPops(sizes=[1]*num_sub_pops, randomize=False),
         ],
         matingScheme=sim.SelfMating(subPopSize=[progeny_per_individual] * num_sub_pops,
                                     numOffspring=progeny_per_individual,
                                     ops=[sim.Recombinator(rates=0.01), sim.IdTagger(), sim.PedigreeTagger()],
                                     ),
         gen=1,
     )
import simuPOP as sim
pop = sim.Population(size=[10000, 10000], loci=1)
pop.setVirtualSplitter(sim.ProportionSplitter([0.8, 0.2]))
pop.evolve(initOps=[sim.InitSex(),
                    sim.InitGenotype(freq=[0.5, 0.5])],
           preOps=[
               sim.Stat(homoFreq=0, subPops=[0, 1], vars='homoFreq_sp'),
               sim.PyEval(r"'(%.2f, %.2f)\n' % (subPop[0]['homoFreq'][0], "
                          "subPop[1]['homoFreq'][0])"),
           ],
           matingScheme=sim.HeteroMating(matingSchemes=[
               sim.RandomMating(subPops=[(0, 0), 1]),
               sim.SelfMating(subPops=[(0, 1)]),
           ]),
           gen=3)
示例#9
0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

# This script is an example in the simuPOP user's guide. Please refer to
# the user's guide (http://simupop.sourceforge.net/manual) for a detailed
# description of this example.
#

import simuPOP as sim
pop = sim.Population(size=[1000],
                     loci=2,
                     infoFields=['father_idx', 'mother_idx'])
pop.setVirtualSplitter(sim.ProportionSplitter([0.2, 0.8]))
pop.evolve(
    initOps=sim.InitSex(),
    matingScheme=sim.HeteroMating(matingSchemes=[
        sim.SelfMating(subPops=[(0, 0)],
                       ops=[sim.SelfingGenoTransmitter(),
                            sim.ParentsTagger()]),
        sim.RandomMating(
            subPops=[(0, 1)],
            ops=[sim.SelfingGenoTransmitter(),
                 sim.ParentsTagger()])
    ]),
    gen=10)
[int(ind.father_idx) for ind in pop.individuals(0)][:15]
[int(ind.mother_idx) for ind in pop.individuals(0)][:15]
示例#10
0
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#

# This script is an example in the simuPOP user's guide. Please refer to
# the user's guide (http://simupop.sourceforge.net/manual) for a detailed
# description of this example.
#

import simuPOP as sim
pop = sim.Population(20, loci=8)
# every chromosomes are different. :-)
for idx, ind in enumerate(pop.individuals()):
    ind.setGenotype([idx*2], 0)
    ind.setGenotype([idx*2+1], 1)

pop.evolve(
    matingScheme=sim.SelfMating(ops=sim.Recombinator(rates=0.01)),
    gen = 1
)
sim.dump(pop, width=3, structure=False, max=10)