Quick Demo (v0.3.0)¶
This is a bare bones demo for quick reference - please consult other tutorials for more details.
In [16]:
Copied!
import numpy as np
import shadie
import toytree
import numpy as np
import shadie
import toytree
Setup the model¶
Create a simple chromosome¶
In [2]:
Copied!
chrom = shadie.chromosome.explicit({
(0, 1_200_000): shadie.NONCDS,
(1_200_001, 1_400_000): shadie.EXON,
(1_400_001, 1_600_000): shadie.INTRON,
(1_600_001, 1_800_000): shadie.EXON,
(1_800_001, 5_000_000): shadie.NONCDS,
})
chrom.draw();
chrom = shadie.chromosome.explicit({
(0, 1_200_000): shadie.NONCDS,
(1_200_001, 1_400_000): shadie.EXON,
(1_400_001, 1_600_000): shadie.INTRON,
(1_600_001, 1_800_000): shadie.EXON,
(1_800_001, 5_000_000): shadie.NONCDS,
})
chrom.draw();
In [3]:
Copied!
with shadie.Model() as bryodio_model:
bryodio_model.initialize(
chromosome=chrom,
sim_time=1000,
mutation_rate=1e-8,
recomb_rate=1e-8,
file_out="bryodio_example.trees",
)
bryodio_model.reproduction.bryophyte_dioicous(
spo_pop_size=500,
gam_pop_size=1000)
with shadie.Model() as bryodio_model:
bryodio_model.initialize(
chromosome=chrom,
sim_time=1000,
mutation_rate=1e-8,
recomb_rate=1e-8,
file_out="bryodio_example.trees",
)
bryodio_model.reproduction.bryophyte_dioicous(
spo_pop_size=500,
gam_pop_size=1000)
In [4]:
Copied!
#uncomment the line below to see the model script
#print(bryodio_model.script)
#uncomment the line below to see the model script
#print(bryodio_model.script)
Run the model¶
In [10]:
Copied!
bryodio_model.run()
bryodio_model.run()
Recapitate & Mutate¶
When you load the .trees
file you just generated with the postsim
module it will automatically recapitate and mutate, unless you adjust parameter settings
In [4]:
Copied!
post = shadie.postsim.OneSim("bryodio_example.trees", chrom)
post = shadie.postsim.OneSim("bryodio_example.trees", chrom)
🌿 INFO | one_sim.py | shadie assumes sims were run without a burn-in and without neutral mutations and will recapitate (add ancestry simulation) and mutate (add neutral mutations) any loaded sims by default. Current settings - Recapitate: True Add neutral mutations: True 🌿 INFO | one_sim.py | Simulation currently has 7 existing mutations of type(s) {2, 3}. 🌿 INFO | one_sim.py | Mutating using mutation rate: 1e-08. Keeping 1232 existing mutations of type(s) {0, 2, 3}.
You can check for the presence of your simulation and the ancestral population by access the tree sequence metadata, for example:
In [5]:
Copied!
post.tree_sequence.population(0), post.tree_sequence.population(1)
post.tree_sequence.population(0), post.tree_sequence.population(1)
Out[5]:
(Population(id=0, metadata={'name': 'p0', 'slim_id': 0}), Population(id=1, metadata={'description': 'ancestral population simulated by msprime', 'name': 'ancestral'}))
Plot simulation summary¶
In [6]:
Copied!
post.draw_tree_sequence(sample=6, seed=333);
post.draw_tree_sequence(sample=6, seed=333);
Plot individual trees¶
In [15]:
Copied!
post.draw_tree(idx=3, sample=[10, 10], seed=123);
post.draw_tree(idx=3, sample=[10, 10], seed=123);
Calculate statistics¶
In [8]:
Copied!
post.stats(sample=10, reps=20)
post.stats(sample=10, reps=20)
Out[8]:
mean | CI_5% | CI_95% | |
---|---|---|---|
theta | 0.000030 | 0.000028 | 0.000033 |
D_Taj | 0.959716 | 0.456231 | 1.463200 |
Access Metadata¶
In [24]:
Copied!
post.tree_sequence.metadata["SLiM"]["user_metadata"]
post.tree_sequence.metadata["SLiM"]["user_metadata"]
Out[24]:
{'file_in': ['None'], 'file_out': ['bryodio_example.trees'], 'gam_archegonia_per': ['10'], 'gam_ceiling': ['10000'], 'gam_clone_rate': ['0.8'], 'gam_clones_per': ['10'], 'gam_female_to_male_ratio': ['0.6666666666666666'], 'gam_maternal_effect': ['0.5'], 'gam_mutation_rate': ['5e-09'], 'gam_pop_size': ['1000'], 'gam_random_death_chance': ['0.08'], 'gens_per_lifecycle': ['2'], 'lineage': ['Bryophyte'], 'mode': ['dioicous'], 'model_source': ['shadie'], 'mutation_rate': ['1e-08'], 'recomb_rate': ['1e-08'], 'spo_mutation_rate': ['5e-09'], 'spo_pop_size': ['500'], 'spo_random_death_chance': ['0.08'], 'spo_self_rate_per_egg': ['0.1'], 'spo_spores_per': ['10']}