예제 #1
0
    def test_time_already_in_script(self):
        config = slime.PopulationConfiguration(0, 10, growth_rate = 0)
        scr = slime.RecentHistory(final_gen = 21, chrom_length = 10,
            reference_configs = [config, config, config], adm_configs = config,
            prop = [0.5, 0.4, 0.1])
        # scr.print_script()
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 late', '21 late'])

        config1 = slime.PopulationConfiguration(0, 10, growth_rate = 0.1)
        scr = slime.RecentHistory(final_gen = 11, chrom_length = 10,
            reference_configs = [config1, config], adm_configs = config1,
            prop = [0.5, 0.5])
예제 #2
0
 def test_recenthistory_migration_rates(self):
     config = slime.PopulationConfiguration(sample_size=10, initial_size=100)
     script = slime.RecentHistory(final_gen=20, chrom_length=10, recombination=.001,
         reference_configs=[config, config], adm_configs=config, prop=[0.3,0.7])
     script.add_migration_rate(rates=[.01,.02])
     script.add_migration_rate(rates=[0.0, 0.0], time=(8, 'late'))
     # script.print_script()
     script.run_slim(verbose=False)
예제 #3
0
 def test_random_recombination_map(self):
     config = slime.PopulationConfiguration(initial_size=10)
     utils.random_recombination_map(sequence_length=100, no_rows=20, 
         filename='examples/test.recomb')
     script = slime.RecentHistory(final_gen=20, chrom_length=100,
         reference_configs=[config, config], adm_configs=config,
         prop=[0.3,0.7], recombination='examples/test.recomb')
     script.run_slim(verbose=False)
예제 #4
0
    def test_all_generations_and_times(self):
        config = slime.PopulationConfiguration(0, 10, growth_rate = 0)
        scr = slime.RecentHistory(final_gen = 5, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_event_over_time_range(start = 3, end = 4, event = 'continuous event') 
        # scr.print_script()
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 late', '3:4', '5 late'])
        self.assertEqual(scr.all_generations_and_times(return_as_strings=False),
            [(1, 'early'), (1, 'late'), (2, 'late'), (3,4), (5, 'late')])

        scr = slime.RecentHistory(final_gen = 23, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_event((5, 'late'), 'event in gen 5')
        scr.add_continuous_process((3, 20), event = 'event')
        scr.add_continuous_process((4, 10), event = 'another event')
예제 #5
0
 def test_mutations(self):
     muts = slime.MutationTypes(mutation_rate=.005, selection_coeffs=[0.2,0.6,.3],
         proportions=[.5,.4, .1], dominance_coeffs=[.7, .45, .57])
     config = slime.PopulationConfiguration(initial_size=10)
     script = slime.RecentHistory(final_gen=20, chrom_length=100,
         reference_configs=[config, config], adm_configs=config,
         prop=[0.3,0.7], mutations=muts)
     # script.print_script()
     script.run_slim(verbose=False)
예제 #6
0
 def test_recenthistory_constant_growth(self):
     ref_pops = [slime.PopulationConfiguration(sample_size=10, initial_size=100),
            slime.PopulationConfiguration(sample_size=10, initial_size=100)]
     adm_pop = slime.PopulationConfiguration(sample_size=20, initial_size=50, growth_rate=0.1)
     adm_prop = [0.3, 0.7]
     gens = 20 # 100
     script = slime.RecentHistory(final_gen=gens, chrom_length=10,
             recombination=1e-1, reference_configs=ref_pops, adm_configs=adm_pop,
             prop=adm_prop)
     script.run_slim(verbose=False)
예제 #7
0
def basic_two_way_admixture(length=10,
                            final_gen=20,
                            prop=[0.3, 0.7],
                            rho=.001):
    config = slime.PopulationConfiguration(sample_size=0, initial_size=10)
    script = slime.RecentHistory(final_gen=final_gen,
                                 chrom_length=length,
                                 reference_configs=[config, config],
                                 adm_configs=config,
                                 recombination=rho,
                                 prop=prop)
    return (script)
예제 #8
0
 def test_recenthistory_instant_size_change(self):
     ref_pops = [slime.PopulationConfiguration(sample_size=10, initial_size=100),
             slime.PopulationConfiguration(sample_size=10, initial_size=100)]
     adm_pop = slime.PopulationConfiguration(sample_size=20, initial_size=50)
     adm_prop = [0.3, 0.7]
     gens = 20 # 100
     ch = msprime.PopulationParametersChange(time=11, initial_size=25, population_id=2)
     script = slime.RecentHistory(final_gen=gens, chrom_length=10,
         recombination=1e-1, reference_configs=ref_pops, adm_configs=adm_pop,
         prop=adm_prop)
     script.add_size_change(ch)
     script.run_slim(verbose=False)
예제 #9
0
 def test_size_changes(self):
     config = slime.PopulationConfiguration(initial_size=10)
     config1 = slime.PopulationConfiguration(initial_size=10, growth_rate=0.1)
     script = slime.RecentHistory(final_gen=30, chrom_length=10,
         reference_configs=[config, config1], adm_configs=config1,
         prop=[0.3,0.7])
     for pop in [0, 1, 2]:
         times = random.sample(range(3,29), 3)
         new_sizes = random.sample(range(10, 25), 3)
         for i in range(0,3):
             script.add_size_change(msprime.PopulationParametersChange(time=times[i],
                 initial_size=new_sizes[i], population=pop))
     # script.print_script()
     script.run_slim(verbose=False)
예제 #10
0
 def test_constantly_growing_populations(self):
     ref_configs = []
     for pop in range(0,3):
         ref_configs.append(slime.PopulationConfiguration(initial_size=10, 
             growth_rate=random.randint(1,10)/100))
     adm_config = slime.PopulationConfiguration(initial_size=10,
         growth_rate = random.randint(1,10)/100)
     script = slime.RecentHistory(final_gen=17, chrom_length=10,
         reference_configs=ref_configs, adm_configs=adm_config,
         prop=[0.2,0.3,0.5])
     self.assertEqual(script.all_generations_and_times(),
         ['1 early', '1 late', '2 early', '2 late', '3:16', '17 early', '17 late'])
     # script.print_script()
     script.run_slim(verbose=False)
예제 #11
0
 def test_ordering_inside_events(self):
     config = slime.PopulationConfiguration(0, 100, growth_rate = 0)
     scr = slime.RecentHistory(final_gen = 5, chrom_length = 10,
         reference_configs = [config, config], adm_configs = config,
         prop = [0.5, 0.5])
     scr.add_event((3, 'late'), 'second event')
     scr.add_event((3, 'late'), 'first event', insert_at_start=True)
     scr.add_event((3, 'late'), 'third event')
     script = scr.dump_script()
     event = '3 late(){'
     event_loc = script.find(event)
     end_of_scr = script[event_loc:]
     first_loc = end_of_scr.find('first event')
     second_loc = end_of_scr.find('second event')
     third_loc = end_of_scr.find('third event')
     self.assertLess(first_loc, second_loc)
     self.assertLess(second_loc, third_loc)
예제 #12
0
 def test_size_changes(self):
     config = slime.PopulationConfiguration(initial_size=10)
     config1 = slime.PopulationConfiguration(initial_size=10, growth_rate=0.1)
     script = slime.RecentHistory(final_gen=15, chrom_length=10,
         reference_configs=[config, config1], adm_configs=config1,
         prop=[0.3,0.7])
     script.add_size_change(msprime.PopulationParametersChange(time=10,
             initial_size=15, population=2))
     script.add_size_change(msprime.PopulationParametersChange(time=10,
             initial_size=15, population=0))
     # script.print_script()
     e_gen10 = script.all_events_at_a_given_time('10 early')
     self.assertEqual(len(e_gen10), 3)
     assert 'p0.setSubpopulationSize(15)' in e_gen10
     assert 'p2.setSubpopulationSize(15)' in e_gen10
     assert 'p1.setSubpopulationSize(asInteger(p2.individualCount * exp(0.100000)))' not in e_gen10
     script.run_slim(verbose=False)
예제 #13
0
 def test_quickstart(self):
     ref0_config = slime.PopulationConfiguration(initial_size=10, growth_rate=0)
     ref1_config = slime.PopulationConfiguration(initial_size=15, growth_rate=0)
     adm_config = slime.PopulationConfiguration(sample_size=5, initial_size=10, growth_rate = 0)
     adm_props = [0.3, 0.7]
     rho = 0.1
     length = 10
     gens = 15
     script = slime.RecentHistory(final_gen=gens, chrom_length=length,
         reference_configs=[ref0_config, ref1_config], adm_configs=adm_config,
         prop=adm_props)
     script.run_slim(verbose=False)
     # Check output.
     ts = tskit.load("recent-history.trees")
     self.assertEqual(len(ts.samples(0)), 10*2)
     self.assertEqual(len(ts.samples(1)), 15*2)
     self.assertEqual(len(ts.samples(2)), 10*2)
     root0 = ts.first().roots[0]
     self.assertEqual(ts.first().time(root0), 15)
예제 #14
0
class TestCorrectOutput(unittest.TestCase):
    """
    Tests that the output produced by slime is as expected.
    """
    ref0_config = slime.PopulationConfiguration(initial_size=10, growth_rate=0)
    ref1_config = slime.PopulationConfiguration(initial_size=15, growth_rate=0)
    adm_config = slime.PopulationConfiguration(sample_size=5, initial_size=5, growth_rate = 0)
    adm_props = [0.3, 0.7]
    rho = 0.1
    length = 10
    gens = 15
    script = slime.RecentHistory(final_gen=gens, chrom_length=length,
        reference_configs=[ref0_config, ref1_config], adm_configs=adm_config,
        prop=adm_props, recombination=.001)
    script.run_slim(verbose=False)
    # script.print_script()
    # Check output.
    ts = tskit.load("recent-history.trees")

    def test_population_size(self):
        self.assertEqual(len(self.ts.samples(0)), 20)
        self.assertEqual(len(self.ts.samples(1)), 30)
        self.assertEqual(len(self.ts.samples(2)), 10)
예제 #15
0
    def test_add_continuous_processes(self):
        # scr = slime.RecentHistory(final_gen = 10, chrom_length = 10)
        config = slime.PopulationConfiguration(0, 10, growth_rate = 0)
        scr = slime.RecentHistory(final_gen = 23, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_event((5, 'late'), 'event in gen 5')
        scr.add_continuous_process((3, 20), event = 'event')
        scr.add_continuous_process((4, 10), event = 'another event')
        # scr.print_script()
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 late', '3 early', '4 early', '5 early', '5 late',
            '6:10', '11:20', '23 late'])
        self.assertEqual(scr.all_events_at_a_given_time(time='3 early'),
            ['event'])
        self.assertEqual(scr.all_events_at_a_given_time(time='4 early'),
            ['event', 'another event'])
        self.assertEqual(scr.all_events_at_a_given_time(time='5 early'),
            ['event', 'another event'])
        self.assertEqual(scr.all_events_at_a_given_time(time='5 late'),
            ['event in gen 5'])
        self.assertEqual(scr.all_events_at_a_given_time(time='6:10'),
            ['event', 'another event'])
        self.assertEqual(scr.all_events_at_a_given_time(time='11:20'),
            ['event'])

        scr.add_continuous_process((10,19), event='yet another event')
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 late', '3 early', '4 early', '5 early', '5 late',
            '6:9', '10 early', '11:19', '20 early', '23 late'])
        self.assertEqual(scr.all_events_at_a_given_time(time='10 early'),
            ['event', 'another event', 'yet another event'])
        self.assertEqual(scr.all_events_at_a_given_time(time='11:19'),
            ['event', 'yet another event'])
        self.assertEqual(scr.all_events_at_a_given_time(time='20 early'),
            ['event'])
예제 #16
0
 def test_many_populations(self):
     config = slime.PopulationConfiguration(initial_size=10, growth_rate=0)
     num_pops = random.randint(5, 15)
     ref_configs = [config for i in range(0, num_pops)]
     props = np.zeros(num_pops)
      # Ensure rounding error doesn't cause an error.
      # This is giving me quite a bit of grief!!
     while sum(props) != 1 or any(props) == 0:
         props = np.random.dirichlet([1 for i in range(0, num_pops)])
         props = np.round(props, decimals=2)
         props[-1] = np.round(1 - sum(props[:-1]), decimals=2)
     # props = np.round(props, decimals=2)
     assert sum(props) == 1
     script = slime.RecentHistory(final_gen=20, chrom_length=10,
         reference_configs=ref_configs, adm_configs=config,
         prop=props)
     # script.print_script()
     script.run_slim(verbose=False)
     # Check output
     ts = tskit.load("recent-history.trees")
     for pop in range(0, num_pops + 1):
         self.assertEqual(len(ts.samples(pop)), 10*2)
     root0 = ts.first().roots[0]
     self.assertEqual(ts.first().time(root0), 20)
예제 #17
0
class TestSlime(unittest.TestCase):

    # Example supplied SLiM script
    slim_script = '''
// set up a simple neutral simulation
initialize() {
    
    // Set constants.
    defineConstant("chromLength", 9999);
    defineConstant("p0Size", 100);
    defineConstant("p1Size", 100);
    defineConstant("p2Size", 100);
    defineConstant("p0Prop", 1/100);
    defineConstant("p1Prop", 1 - p0Prop);

    initializeSLiMModelType("WF");
    initializeSLiMOptions(keepPedigrees = T); // Keep pedigree information
    initializeTreeSeq();
    initializeMutationRate(1e-3);
    
    // m1 mutation type: slightly positive
    initializeMutationType("m1", 0.5, "f", 0.1);
    
    // g1 genomic element type: uses m1 for all mutations
    initializeGenomicElementType("g1", m1, 1.0);
    
    // uniform chromosome of length 100 kb
    initializeGenomicElement(g1, 0, chromLength);
    
    initializeRecombinationRate(1e-8);
    
}

1 early(){
    sim.addSubpop("p0", p0Size);
    sim.addSubpop("p1", p1Size);
}

1 late() { 
    
    // Add admixing population.
    sim.addSubpop("p2", p2Size);
    p2.setMigrationRates(c(p0,p1),c(p0Prop, p1Prop));
    
}

2 late() {
    p2.setMigrationRates(c(p0,p1),c(0.0,0.0));
}

// save the tree output after 25 generations.
25 late() {
    sim.treeSeqOutput("examples/ex-recent-history.trees");
    sim.simulationFinished();
}
'''

    slim_file = open("ex_script.slim", "w")
    slim_file.writelines(slim_script)
    slim_file.close()

    scr = slime.RecentHistory(final_gen = 10, chrom_length = 10)
    scr.initialize_recombination(0.2)
    config = msprime.PopulationConfiguration(0, 100, growth_rate = 0)
    config1 = msprime.PopulationConfiguration(0, 100, growth_rate = 0.05)
    scr.add_reference_population(config, 'pop0')
    scr.add_reference_population(config, 'pop1')
    scr.add_admixed_population(config1, 'adm', proportions = [0.2, 0.8])
    change1 = msprime.PopulationParametersChange(3, growth_rate =  .5, population_id = 0)
    change2 = msprime.PopulationParametersChange(6, growth_rate =  .6, population_id = 0)
    change3 = msprime.PopulationParametersChange(2, growth_rate =  .3, population_id = 1)
    change4 = msprime.PopulationParametersChange(8, growth_rate =  0, population_id = 1, initial_size = 100)
    scr.add_demographic_events([change3, change1, change2, change4])
    scr.save_script("ex_script2.slim")

    def test_simulate_recent_history(self):
        slime.simulate_recent_history("ex_script.slim")
        slime.simulate_recent_history("ex_script2.slim")

    def test_slime_run_saved_script(self):
        rho = 1e-8
        mu = 1e-8
        ######################
        # POPULATION HISTORY #
        ######################
        N0 = 1e4 # population size
        divergenceGen = 20000

        # Population IDs
        population_configurations = [
            # CEU
            msprime.PopulationConfiguration(
                initial_size = N0,
                growth_rate = 0),
            # YRI
            msprime.PopulationConfiguration(                                
                initial_size = N0,                                
                growth_rate = 0)
        ]

        demographic_events = [
            msprime.MassMigration(
                time=divergenceGen,
                source = 1,
                destination = 0,
                proportion = 1.0),
            msprime.MigrationRateChange(time = divergenceGen,
                rate = 0)
        ]

        # First, with the created script.
        mysim = slime.AdmixtureSimulation(slim_script="ex_script.slim", 
                    slim_out="examples/ex-recent-history.trees",
                    neutral_mutation_rate = mu, ancient_recombination_rate = rho,
                    ancient_population_configurations = population_configurations,
                    ancient_demographic_events = demographic_events,
                    out_file = "examples/ex_out.trees",
                    populations_to_sample_from = [2], sample_sizes = [10], 
                    )
        ts = mysim.go()

        # Next, with the generated script.
        mysim2 = slime.AdmixtureSimulation(slim_script="ex_script2.slim", 
            slim_out="examples/ex-recent-history.trees",
            neutral_mutation_rate = mu, ancient_recombination_rate = rho,
            ancient_population_configurations = population_configurations,
            ancient_demographic_events = demographic_events,
            out_file = "examples/ex_out.trees",
            populations_to_sample_from = [2], sample_sizes = [10], 
            )
        ts2 = mysim2.go()
예제 #18
0
class TestRecentHistory(unittest.TestCase):

    config = slime.PopulationConfiguration(0, 100, growth_rate = 0)
    scr = slime.RecentHistory(final_gen = 5, chrom_length = 10,
        reference_configs = [config, config], adm_configs = config,
        prop = [0.5, 0.5])
    scr.add_event((1, 'early'), 'start of simulation')
    scr.add_event((3, 'late'), 'second event')
    scr.add_event((3, 'late'), 'first event', insert_at_start=True)
    scr.add_event((3, 'late'), 'third event')
    scr.add_event((2, 'late'), 'the middle of the script')
    scr.add_event((5, 'late'), 'the end of the script')
    scr.add_event((4, 'early'), 'more middle of the script')

    # """
    # Tests the methods in the RecentHistory class.
    # """

    def test_initialize(self):
        scr = self.scr
        scr.initialize('end of initialize')
        scr.initialize('start of initialize', start = True) 
        # scr.print_script()

    def test_time_is_continuous(self):
        scr = self.scr
        self.assertEqual(scr.time_is_continuous((1, 'early')), False)
        self.assertEqual(scr.time_is_continuous((2, 'late')), False)
        self.assertEqual(scr.time_is_continuous((1, 3)), True)

    def test_generation_order(self):
        scr = self.scr.dump_script()
        test_regex = re.compile("^\d+", flags=re.MULTILINE)
        generations = test_regex.findall(scr)
        generations = [int(gen) for gen in generations]
        self.assertEqual(generations, sorted(generations))

    def test_ordering_inside_events(self):
        config = slime.PopulationConfiguration(0, 100, growth_rate = 0)
        scr = slime.RecentHistory(final_gen = 5, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_event((3, 'late'), 'second event')
        scr.add_event((3, 'late'), 'first event', insert_at_start=True)
        scr.add_event((3, 'late'), 'third event')
        script = scr.dump_script()
        event = '3 late(){'
        event_loc = script.find(event)
        end_of_scr = script[event_loc:]
        first_loc = end_of_scr.find('first event')
        second_loc = end_of_scr.find('second event')
        third_loc = end_of_scr.find('third event')
        self.assertLess(first_loc, second_loc)
        self.assertLess(second_loc, third_loc)
        # self.scr.print_script()

    def test_add_event_over_time_range(self):
        config = slime.PopulationConfiguration(0, 10, growth_rate = 0)
        scr = slime.RecentHistory(final_gen = 10, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_event_over_time_range(start = 3, end = 7, event = 'continuous event')  
        # scr.print_script() 

    def test_delete_time(self):
        scr = self.scr
        scr.delete_time('3 late')
        scr.delete_time('4 early')
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 late', '5 late'])
        scr.add_continuous_process((3,4), event='to delete')
        scr.delete_time('3:4 {')
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 late', '5 late'])

    def test_all_generations_and_times(self):
        config = slime.PopulationConfiguration(0, 10, growth_rate = 0)
        scr = slime.RecentHistory(final_gen = 5, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_event_over_time_range(start = 3, end = 4, event = 'continuous event') 
        # scr.print_script()
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 late', '3:4', '5 late'])
        self.assertEqual(scr.all_generations_and_times(return_as_strings=False),
            [(1, 'early'), (1, 'late'), (2, 'late'), (3,4), (5, 'late')])

        scr = slime.RecentHistory(final_gen = 23, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_event((5, 'late'), 'event in gen 5')
        scr.add_continuous_process((3, 20), event = 'event')
        scr.add_continuous_process((4, 10), event = 'another event')
        # print(scr.all_generations_and_times())
        # scr.print_script()


    def test_all_early_events(self):
        scr = self.scr
        self.assertEqual(scr.all_early_events(), 
            ['1 early', '4 early'])

    def test_all_late_events(self):
        scr = self.scr
        self.assertEqual(scr.all_late_events(), 
            ['1 late', '2 late', '3 late', '5 late'])

    def test_all_early_or_late_events(self):
        scr = self.scr
        self.assertEqual(scr.all_early_or_late_events(),
            ['1 early', '1 late', '2 late', '3 late', '4 early', '5 late'])

    def test_add_continuous_processes(self):
        # scr = slime.RecentHistory(final_gen = 10, chrom_length = 10)
        config = slime.PopulationConfiguration(0, 10, growth_rate = 0)
        scr = slime.RecentHistory(final_gen = 23, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_event((5, 'late'), 'event in gen 5')
        scr.add_continuous_process((3, 20), event = 'event')
        scr.add_continuous_process((4, 10), event = 'another event')
        # scr.print_script()
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 late', '3 early', '4 early', '5 early', '5 late',
            '6:10', '11:20', '23 late'])
        self.assertEqual(scr.all_events_at_a_given_time(time='3 early'),
            ['event'])
        self.assertEqual(scr.all_events_at_a_given_time(time='4 early'),
            ['event', 'another event'])
        self.assertEqual(scr.all_events_at_a_given_time(time='5 early'),
            ['event', 'another event'])
        self.assertEqual(scr.all_events_at_a_given_time(time='5 late'),
            ['event in gen 5'])
        self.assertEqual(scr.all_events_at_a_given_time(time='6:10'),
            ['event', 'another event'])
        self.assertEqual(scr.all_events_at_a_given_time(time='11:20'),
            ['event'])

        scr.add_continuous_process((10,19), event='yet another event')
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 late', '3 early', '4 early', '5 early', '5 late',
            '6:9', '10 early', '11:19', '20 early', '23 late'])
        self.assertEqual(scr.all_events_at_a_given_time(time='10 early'),
            ['event', 'another event', 'yet another event'])
        self.assertEqual(scr.all_events_at_a_given_time(time='11:19'),
            ['event', 'yet another event'])
        self.assertEqual(scr.all_events_at_a_given_time(time='20 early'),
            ['event'])

    def test_all_events_at_a_given_time(self):
        scr = self.scr
        scr.all_events_at_a_given_time('3 late')
        self.assertEqual(scr.all_events_at_a_given_time('3 late'),
            ['first event', 'second event', 'third event'])

    def test_break_up_range(self):
        config = slime.PopulationConfiguration(0, 10, growth_rate = 0)
        config1 = slime.PopulationConfiguration(0, 10, growth_rate = 0.01)
        scr = slime.RecentHistory(final_gen = 5, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_continuous_process((2, 4), event = 'growth')
        scr.add_event((2, 'early'), event = 'event')
        events = scr.all_generations_and_times()
        # scr.print_script()
        self.assertEqual(events, ['1 early', '1 late', '2 early', '2 late', '3:4', '5 late'])

        scr = slime.RecentHistory(final_gen = 5, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_continuous_process((2, 3), event = 'growth')
        scr.add_event((2, 'early'), event = 'event')
        # scr.print_script()
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 early', '2 late', '3 early', '5 late'])

        scr = slime.RecentHistory(final_gen = 5, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_continuous_process((2, 4), event = 'growth')
        scr.add_event((4, 'early'), event = 'event')
        # scr.print_script()
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 early', '2 late', '3 early', '4 early', '5 late'])

        scr = slime.RecentHistory(final_gen = 10, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_continuous_process((2, 8), event = 'continuous')
        scr.add_event((5, 'early'), event = 'middle')
        # scr.print_script()
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 early', '2 late', '3:4', '5 early', '6:8', '10 late'])

        scr = slime.RecentHistory(final_gen = 10, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_continuous_process((2, 8), event = 'continuous')
        scr.add_event((3, 'early'), event = 'middle')
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 early', '2 late', '3 early', '4:8', '10 late'])

        scr = slime.RecentHistory(final_gen = 10, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_continuous_process((2, 8), event = 'continuous')
        scr.add_event((8, 'early'), event = 'middle')
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 early', '2 late', '3:7', '8 early', '10 late'])

        scr = slime.RecentHistory(final_gen = 10, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_continuous_process((2, 8), event = 'continuous')
        scr.add_event((7, 'early'), event = 'middle')
        # scr.print_script()
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 early', '2 late', '3:6', '7 early',
            '8 early', '10 late'])

        scr = slime.RecentHistory(final_gen = 11, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_continuous_process((3, 11), event = 'continuous')
        scr.add_continuous_process((6, 11), event = 'continuous2')
        scr.add_continuous_process((5, 11), event = 'continuous3')
        # scr.print_script()
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 late', '3:4', '5 early', '6:10',
            '11 early', '11 late'])
        self.assertEqual(scr.all_events_at_a_given_time('3:4'), ['continuous'])
        self.assertEqual(scr.all_events_at_a_given_time('5 early'),
            ['continuous', 'continuous3'])
        self.assertEqual(scr.all_events_at_a_given_time('6:10'),
            ['continuous', 'continuous2', 'continuous3'])
        self.assertEqual(scr.all_events_at_a_given_time('11 early'),
            ['continuous', 'continuous2', 'continuous3'])

    def test_break_up_initial_growth(self):
        config0 = slime.PopulationConfiguration(0, 10, growth_rate = 0)
        config1 = slime.PopulationConfiguration(0, 10, growth_rate = 0.1)
        scr = slime.RecentHistory(final_gen = 10, chrom_length = 10,
            reference_configs = [config1, config1], adm_configs = config0,
            prop = [0.4, 0.6])
        # scr.print_script()

    def test_time_already_in_script(self):
        config = slime.PopulationConfiguration(0, 10, growth_rate = 0)
        scr = slime.RecentHistory(final_gen = 21, chrom_length = 10,
            reference_configs = [config, config, config], adm_configs = config,
            prop = [0.5, 0.4, 0.1])
        # scr.print_script()
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 late', '21 late'])

        config1 = slime.PopulationConfiguration(0, 10, growth_rate = 0.1)
        scr = slime.RecentHistory(final_gen = 11, chrom_length = 10,
            reference_configs = [config1, config], adm_configs = config1,
            prop = [0.5, 0.5])
예제 #19
0
 def test_break_up_initial_growth(self):
     config0 = slime.PopulationConfiguration(0, 10, growth_rate = 0)
     config1 = slime.PopulationConfiguration(0, 10, growth_rate = 0.1)
     scr = slime.RecentHistory(final_gen = 10, chrom_length = 10,
         reference_configs = [config1, config1], adm_configs = config0,
         prop = [0.4, 0.6])
예제 #20
0
 def test_add_event_over_time_range(self):
     config = slime.PopulationConfiguration(0, 10, growth_rate = 0)
     scr = slime.RecentHistory(final_gen = 10, chrom_length = 10,
         reference_configs = [config, config], adm_configs = config,
         prop = [0.5, 0.5])
     scr.add_event_over_time_range(start = 3, end = 7, event = 'continuous event')  
예제 #21
0
 def test_basic_input(self):
     config = slime.PopulationConfiguration(initial_size=10)
     scr = slime.RecentHistory(final_gen = 5, chrom_length = 10,
         reference_configs = [config, config], adm_configs = config,
         prop = [0.5, 0.5])
     scr.run_slim(verbose=False)
예제 #22
0
    def test_break_up_range(self):
        config = slime.PopulationConfiguration(0, 10, growth_rate = 0)
        config1 = slime.PopulationConfiguration(0, 10, growth_rate = 0.01)
        scr = slime.RecentHistory(final_gen = 5, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_continuous_process((2, 4), event = 'growth')
        scr.add_event((2, 'early'), event = 'event')
        events = scr.all_generations_and_times()
        # scr.print_script()
        self.assertEqual(events, ['1 early', '1 late', '2 early', '2 late', '3:4', '5 late'])

        scr = slime.RecentHistory(final_gen = 5, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_continuous_process((2, 3), event = 'growth')
        scr.add_event((2, 'early'), event = 'event')
        # scr.print_script()
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 early', '2 late', '3 early', '5 late'])

        scr = slime.RecentHistory(final_gen = 5, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_continuous_process((2, 4), event = 'growth')
        scr.add_event((4, 'early'), event = 'event')
        # scr.print_script()
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 early', '2 late', '3 early', '4 early', '5 late'])

        scr = slime.RecentHistory(final_gen = 10, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_continuous_process((2, 8), event = 'continuous')
        scr.add_event((5, 'early'), event = 'middle')
        # scr.print_script()
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 early', '2 late', '3:4', '5 early', '6:8', '10 late'])

        scr = slime.RecentHistory(final_gen = 10, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_continuous_process((2, 8), event = 'continuous')
        scr.add_event((3, 'early'), event = 'middle')
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 early', '2 late', '3 early', '4:8', '10 late'])

        scr = slime.RecentHistory(final_gen = 10, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_continuous_process((2, 8), event = 'continuous')
        scr.add_event((8, 'early'), event = 'middle')
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 early', '2 late', '3:7', '8 early', '10 late'])

        scr = slime.RecentHistory(final_gen = 10, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_continuous_process((2, 8), event = 'continuous')
        scr.add_event((7, 'early'), event = 'middle')
        # scr.print_script()
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 early', '2 late', '3:6', '7 early',
            '8 early', '10 late'])

        scr = slime.RecentHistory(final_gen = 11, chrom_length = 10,
            reference_configs = [config, config], adm_configs = config,
            prop = [0.5, 0.5])
        scr.add_continuous_process((3, 11), event = 'continuous')
        scr.add_continuous_process((6, 11), event = 'continuous2')
        scr.add_continuous_process((5, 11), event = 'continuous3')
        # scr.print_script()
        self.assertEqual(scr.all_generations_and_times(),
            ['1 early', '1 late', '2 late', '3:4', '5 early', '6:10',
            '11 early', '11 late'])
        self.assertEqual(scr.all_events_at_a_given_time('3:4'), ['continuous'])
        self.assertEqual(scr.all_events_at_a_given_time('5 early'),
            ['continuous', 'continuous3'])
        self.assertEqual(scr.all_events_at_a_given_time('6:10'),
            ['continuous', 'continuous2', 'continuous3'])
        self.assertEqual(scr.all_events_at_a_given_time('11 early'),
            ['continuous', 'continuous2', 'continuous3'])