forked from popsim-consortium/stdpopsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_CaeEle.py
109 lines (92 loc) · 3.32 KB
/
test_CaeEle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import pytest
import stdpopsim
from tests import test_species
class TestSpeciesData(test_species.SpeciesTestBase):
species = stdpopsim.get_species("CaeEle")
def test_ensembl_id(self):
assert self.species.ensembl_id == "caenorhabditis_elegans"
def test_name(self):
assert self.species.name == "Caenorhabditis elegans"
def test_common_name(self):
assert self.species.common_name == "C. elegans"
def test_qc_population_size(self):
assert self.species.population_size == 10000
def test_qc_generation_time(self):
assert self.species.generation_time == 0.01
class TestGenomeData(test_species.GenomeTestBase):
genome = stdpopsim.get_species("CaeEle").genome
mu = 1.84e-9
# # downloading genetic map, for calculating total cM per chromosome
# comm = "wget http://sesame.uoregon.edu/~ateterina/rockman2009_maps.tgz"
# os.system(comm)
# try:
# comm = "tar -zxvf rockman2009_maps.tgz"
# os.system(comm)
# except:
# pass
# my_recs = {}
# genome = stdpopsim.get_species("CaeEle").genome
# chromlist = ["I", "II", "III", "IV", "V", "X"]
# for chrom in chromlist:
# bps, rates, cM = [], [], 0
# with open(
# "genetic_map/C.elegans.Rockman.Kruglyak.2009." + chrom + ".hapmap.txt"
# ) as infile:
# infile.readline() # header
# newline = infile.readline().strip().split()
# bp = float(newline[1])
# rate = float(newline[2])
# bps.append(bp)
# rates.append(rate)
# for line in infile:
# newline = line.strip().split()
# bp = float(newline[1])
# rate = float(newline[2])
# bps.append(bp)
# rates.append(rate)
# previous_index = bps.index(bp) - 1
# length = bp - bps[previous_index]
# cM += rates[previous_index] * length
# total_rate = cM / genome.get_chromosome(chrom).length
# total_rate /= 100 # cM to rate
# total_rate /= 1000000 # Mb to bp
# total_rate /= 1000 # 0.1% outcrossing
# my_recs[chrom] = total_rate
# print(my_recs)
my_recs = {
"I": 3.1216265402124167e-11,
"II": 3.529290802315087e-11,
"III": 3.906598767640363e-11,
"IV": 2.712098077556377e-11,
"V": 2.4705737572511805e-11,
"X": 2.9472374817864404e-11,
"MtDNA": 0,
}
@pytest.mark.parametrize(
["name", "rate"],
my_recs.items(),
)
def test_recombination_rate(self, name, rate):
assert rate == pytest.approx(
self.genome.get_chromosome(name).recombination_rate
)
@pytest.mark.parametrize(
["name", "rate"],
{
"I": mu,
"II": mu,
"III": mu,
"IV": mu,
"V": mu,
"X": mu,
"MtDNA": 1.05e-7,
}.items(),
)
def test_mutation_rate(self, name, rate):
assert rate == pytest.approx(self.genome.get_chromosome(name).mutation_rate)
@pytest.mark.parametrize("chrom", [chrom for chrom in genome.chromosomes])
def test_chromosome_ploidy(self, chrom):
if chrom.id in ["MtDNA"]:
assert chrom.ploidy == 1
else:
assert chrom.ploidy == 2