-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
test_PopGen_FDist.py
111 lines (93 loc) · 3.45 KB
/
test_PopGen_FDist.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
110
111
# Copyright 2006 by Tiago Antao <tiagoantao@gmail.com>. All rights reserved.
# This code is part of the Biopython distribution and governed by its
# license. Please see the LICENSE file that should have been included
# as part of this package.
import commands
import os
import shutil
import sys
import tempfile
import unittest
from Bio.PopGen import FDist
from Bio.PopGen.FDist import Controller
from Bio import MissingExternalDependencyError
#Tests fdist related code. Note: this case requires fdist
#test_PopGen_FDist_nodepend tests code that does not require fdist
found = False
for path in os.environ['PATH'].split(os.pathsep):
try:
list = os.listdir(path)
for file in os.listdir(path):
if file.startswith('fdist2'):
found = True
except os.error:
pass #Path doesn't exist - correct to pass
if not found:
raise MissingExternalDependencyError("Fdist not found (not a problem if you do not intend to use it).")
def run_tests(argv):
test_suite = testing_suite()
runner = unittest.TextTestRunner(sys.stdout, verbosity = 2)
runner.run(test_suite)
def testing_suite():
"""Generate the suite of tests.
"""
print "Running fdist tests, which might take some time, please wait"
test_suite = unittest.TestSuite()
test_loader = unittest.TestLoader()
test_loader.testMethodPrefix = 't_'
tests = [AppTest]
for test in tests:
cur_suite = test_loader.loadTestsFromTestCase(test)
test_suite.addTest(cur_suite)
return test_suite
class AppTest(unittest.TestCase):
"""Tests the fdist suite of applications.
"""
def _copyfile(self, inname, outname):
shutil.copyfile(
'PopGen' + os.sep + inname,
self.dirname + os.sep + outname)
def setUp(self):
self.ctrl = Controller.FDistController()
self.dirname = tempfile.mkdtemp()
self._copyfile('data_fst_outfile', 'data_fst_outfile')
self._copyfile('fdist1', 'infile')
self._copyfile('out.dat', 'out.dat')
self._copyfile('out.cpl', 'out.cpl')
def tearDown(self):
for file in os.listdir(self.dirname):
os.remove(self.dirname + os.sep + file)
os.rmdir(self.dirname)
def t_datacal(self):
"""Test datacal execution.
"""
fst, samp_size = self.ctrl.run_datacal(data_dir = self.dirname)
assert (fst - 0.44 < 0.01)
assert (samp_size == 11)
def t_fdist(self):
"""Test fdist execution.
"""
fst = self.ctrl.run_fdist(npops = 15, nsamples = 10, fst = 0.1,
sample_size = 20, mut = 0, num_sims = 10000,
data_dir = self.dirname)
assert(abs(fst - 0.1) < 0.02) #Stochastic result...
def t_fdist_force_fst(self):
"""Test fdist execution approximating Fst.
"""
fst = self.ctrl.run_fdist_force_fst(npops = 15, nsamples = 10,
fst = 0.1,
sample_size = 20, mut = 0, num_sims = 10000,
data_dir = self.dirname)
assert(abs(fst - 0.09) < 0.05) #Stochastic result...
def t_cplot(self):
"""Test cplot execution.
"""
cpl_interval =self.ctrl.run_cplot(data_dir = self.dirname)
assert(len(cpl_interval) == 8)
def t_pv(self):
"""Test pv execution.
"""
pv_data = self.ctrl.run_pv(data_dir = self.dirname)
assert(len(pv_data) == 4)
if __name__ == "__main__":
sys.exit(run_tests(sys.argv))