mirror of
https://github.com/biopython/biopython.git
synced 2025-10-20 13:43:47 +08:00
Removal of PopGen deprecated libraries
This commit is contained in:
@ -1,65 +0,0 @@
|
||||
# Copyright 2007 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.
|
||||
|
||||
"""Asynchronous local execution (DEPRECATED).
|
||||
|
||||
Supports multicore architectures.
|
||||
"""
|
||||
|
||||
import threading
|
||||
|
||||
from Bio.PopGen.Async import Async
|
||||
|
||||
|
||||
class Local(Async):
|
||||
"""Execution on Local machine."""
|
||||
|
||||
def __init__(self, num_cores=1):
|
||||
"""Constructor.
|
||||
|
||||
Parameters:
|
||||
- num_cores - Number of cores (for multiprocessor machines,
|
||||
multiply accordingly)
|
||||
|
||||
"""
|
||||
Async.__init__(self)
|
||||
self.num_cores = num_cores
|
||||
self.cores_used = 0
|
||||
|
||||
def _run_program(self, id, hook, parameters, input_files):
|
||||
"""Run program.
|
||||
|
||||
For parameters, please check Async.run_program.
|
||||
|
||||
Either runs a program if a core is available or
|
||||
schedules it.
|
||||
"""
|
||||
self.access_ds.acquire()
|
||||
self.waiting.append((id, hook, parameters, input_files))
|
||||
if self.cores_used < self.num_cores:
|
||||
self.cores_used += 1
|
||||
threading.Thread(target=self.start_work).run()
|
||||
self.access_ds.release()
|
||||
|
||||
def start_work(self):
|
||||
"""Starts work.
|
||||
|
||||
Thread initial point.
|
||||
While there are tasks to be done, runs them.
|
||||
The thread dies as soon as there is nothing waiting to be
|
||||
executed.
|
||||
"""
|
||||
self.access_ds.acquire()
|
||||
while (len(self.waiting) > 0):
|
||||
id, hook, parameters, input_files = self.waiting[0]
|
||||
del self.waiting[0]
|
||||
self.running[id] = True
|
||||
self.access_ds.release()
|
||||
ret_code, output_files = hook.run_job(parameters, input_files)
|
||||
self.access_ds.acquire()
|
||||
del self.running[id]
|
||||
self.done[id] = ret_code, output_files
|
||||
self.cores_used -= 1
|
||||
self.access_ds.release()
|
@ -1,124 +0,0 @@
|
||||
# Copyright 2007 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.
|
||||
|
||||
"""Support for asynchronous execution (DEPRECATED)."""
|
||||
|
||||
import os
|
||||
import threading
|
||||
import warnings
|
||||
|
||||
from Bio import BiopythonDeprecationWarning
|
||||
|
||||
warnings.warn("Bio.PopGen.Async has been deprecated, and we intend to remove"
|
||||
" it in a future release of Biopython. If you would like to"
|
||||
" continue using it, please contact the Biopython developers"
|
||||
" via the mailing list.", BiopythonDeprecationWarning)
|
||||
|
||||
|
||||
class Async(object):
|
||||
"""Abstract Asynchronous execution class.
|
||||
|
||||
This is the top abstract class.
|
||||
Concrete classes must implement the _run_program method.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""Async constructor.
|
||||
|
||||
Initializes the queues, among other things.
|
||||
Of notice, is the access_ds lock for controlling exclusive
|
||||
access to this object.
|
||||
"""
|
||||
self.running = {}
|
||||
self.waiting = []
|
||||
self.done = {}
|
||||
self.id = 0
|
||||
self.hooks = {}
|
||||
self.access_ds = threading.Lock()
|
||||
|
||||
def run_program(self, program, parameters, input_files):
|
||||
"""Runs a program.
|
||||
|
||||
Real _run_program to be implemented by concrete classes.
|
||||
|
||||
Parameters:
|
||||
program String identifying program.
|
||||
parameters List of String parameters.
|
||||
input_files Hash of Input file descriptors.
|
||||
|
||||
Returns:
|
||||
Task Id.
|
||||
|
||||
The input_files hash key is the path that is passed
|
||||
to the program. It should always be relative.
|
||||
Value is a stream.
|
||||
|
||||
"""
|
||||
if program in self.hooks:
|
||||
self.access_ds.acquire()
|
||||
self.id += 1
|
||||
id = self.id
|
||||
self.access_ds.release()
|
||||
self._run_program(id, self.hooks[program], parameters, input_files)
|
||||
return id
|
||||
|
||||
def _run_program(self, id, program, parameters, input_files):
|
||||
"""Actually run the program, handled by a subclass (PRIVATE).
|
||||
|
||||
This method should be replaced by any derived class to do
|
||||
something useful. It will be called by the run_program method.
|
||||
"""
|
||||
raise NotImplementedError("This object should be subclassed")
|
||||
|
||||
def get_result(self, id):
|
||||
"""Returns results for a certain Id, the info for that Id is forgotten.
|
||||
|
||||
Parameters:
|
||||
id Id of the task.
|
||||
|
||||
Returns:
|
||||
(return_code, output_files) return code and file access object.
|
||||
|
||||
The output_files hash key is a relative file name, and the value a
|
||||
output stream.
|
||||
|
||||
"""
|
||||
self.access_ds.acquire()
|
||||
if id in self.done:
|
||||
returnCode, fileObject = self.done[id]
|
||||
del self.done[id]
|
||||
self.access_ds.release()
|
||||
else:
|
||||
self.access_ds.release()
|
||||
return None
|
||||
|
||||
|
||||
class FileRetriever(object):
|
||||
"""An Abstract Support class to retrieve files."""
|
||||
|
||||
def __init__(self):
|
||||
self.file_list = []
|
||||
|
||||
def get_File_list(self):
|
||||
"""Returns the list of available files."""
|
||||
return self.file_list
|
||||
|
||||
def get_file(self, name):
|
||||
raise NotImplementedError('Abstract method')
|
||||
|
||||
|
||||
class DirectoryRetriever(FileRetriever):
|
||||
"""Retrieves a directory content."""
|
||||
|
||||
def __init__(self, directory):
|
||||
FileRetriever.__init__(self)
|
||||
self.directory = directory
|
||||
walk_list = os.walk(directory)
|
||||
for dir, dir_list, file_list in walk_list:
|
||||
for file in file_list:
|
||||
self.file_list.append(file[len(directory) + 1:])
|
||||
|
||||
def get_file(self, name):
|
||||
return open(self.directory + os.sep + name)
|
@ -1,180 +0,0 @@
|
||||
# Copyright 2007 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.
|
||||
|
||||
"""Asynchronous execution of Fdist and spliting of loads (DEPRECATED).
|
||||
|
||||
FDistAsync Allows for the execution of FDist.
|
||||
|
||||
SplitFDist splits a single Fdist execution in several, taking advantage
|
||||
of multi-core architectures.
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import threading
|
||||
from time import sleep
|
||||
|
||||
from Bio.PopGen.Async import Local
|
||||
from Bio.PopGen.FDist.Controller import FDistController
|
||||
|
||||
|
||||
class FDistAsync(FDistController):
|
||||
"""Asynchronous FDist execution."""
|
||||
|
||||
def __init__(self, fdist_dir="", ext=None):
|
||||
"""Constructor.
|
||||
|
||||
Parameters:
|
||||
|
||||
- fdist_dir - Where fdist can be found, if = "", then it
|
||||
should be on the path.
|
||||
- ext - Extension of binary names (e.g. nothing on Unix,
|
||||
".exe" on Windows
|
||||
|
||||
"""
|
||||
FDistController.__init__(self, fdist_dir, ext)
|
||||
|
||||
def run_job(self, parameters, input_files):
|
||||
"""Runs FDist asynchronously.
|
||||
|
||||
Gets typical Fdist parameters from a dictionary and
|
||||
makes a "normal" call. This is run, normally, inside
|
||||
a separate thread.
|
||||
"""
|
||||
npops = parameters['npops']
|
||||
nsamples = parameters['nsamples']
|
||||
fst = parameters['fst']
|
||||
sample_size = parameters['sample_size']
|
||||
mut = parameters.get('mut', 0)
|
||||
num_sims = parameters.get('num_sims', 20000)
|
||||
data_dir = parameters.get('data_dir', '.')
|
||||
is_dominant = parameters.get('is_dominant', False)
|
||||
theta = parameters.get('theta', 0.06)
|
||||
beta = parameters.get('beta', (0.25, 0.25))
|
||||
max_freq = parameters.get('max_freq', 0.99)
|
||||
fst = self.run_fdist(npops, nsamples, fst, sample_size,
|
||||
mut, num_sims, data_dir,
|
||||
is_dominant, theta, beta,
|
||||
max_freq)
|
||||
output_files = {}
|
||||
output_files['out.dat'] = open(data_dir + os.sep + 'out.dat', 'r')
|
||||
return fst, output_files
|
||||
|
||||
|
||||
class SplitFDist(object):
|
||||
"""Splits a FDist run.
|
||||
|
||||
The idea is to split a certain number of simulations in smaller
|
||||
numbers (e.g. 30.000 sims split in 30 packets of 1.000). This
|
||||
allows to run simulations in parallel, thus taking advantage
|
||||
of multi-core CPUs.
|
||||
|
||||
Each SplitFDist object can only be used to run a single FDist
|
||||
simulation.
|
||||
"""
|
||||
|
||||
def __init__(self, report_fun=None,
|
||||
num_thr=2, split_size=1000, fdist_dir='', ext=None):
|
||||
"""Constructor.
|
||||
|
||||
Parameters:
|
||||
|
||||
- report_fun - Function that is called when a single packet is
|
||||
run, it should have a single parameter: Fst.
|
||||
- num_thr - Number of desired threads, typically the number
|
||||
of cores.
|
||||
- split_size - Size that a full simulation will be split in.
|
||||
- ext - Binary extension name (e.g. nothing on Unix, '.exe' on
|
||||
Windows).
|
||||
|
||||
"""
|
||||
self.async = Local.Local(num_thr)
|
||||
self.async.hooks['fdist'] = FDistAsync(fdist_dir, ext)
|
||||
self.report_fun = report_fun
|
||||
self.split_size = split_size
|
||||
|
||||
# There might be races when reporting...
|
||||
def monitor(self):
|
||||
"""Monitors and reports (using report_fun) execution.
|
||||
|
||||
Every time a partial simulation ends, calls report_fun.
|
||||
IMPORTANT: monitor calls can be concurrent with other
|
||||
events, ie, a tasks might end while report_fun is being
|
||||
called. This means that report_fun should be consider that
|
||||
other events might be happening while it is running (it
|
||||
can call acquire/release if necessary).
|
||||
"""
|
||||
while(True):
|
||||
sleep(1)
|
||||
self.async.access_ds.acquire()
|
||||
keys = list(self.async.done.keys()) # copy it
|
||||
self.async.access_ds.release()
|
||||
for done in keys:
|
||||
self.async.access_ds.acquire()
|
||||
fst, files = self.async.done[done]
|
||||
del self.async.done[done]
|
||||
out_dat = files['out.dat']
|
||||
f = open(self.data_dir + os.sep + 'out.dat', 'a')
|
||||
f.writelines(out_dat.readlines())
|
||||
f.close()
|
||||
out_dat.close()
|
||||
self.async.access_ds.release()
|
||||
for file in os.listdir(self.parts[done]):
|
||||
os.remove(self.parts[done] + os.sep + file)
|
||||
os.rmdir(self.parts[done])
|
||||
if self.report_fun:
|
||||
self.report_fun(fst)
|
||||
self.async.access_ds.acquire()
|
||||
if len(self.async.waiting) == 0 and len(self.async.running) == 0 \
|
||||
and len(self.async.done) == 0:
|
||||
break
|
||||
self.async.access_ds.release()
|
||||
|
||||
def acquire(self):
|
||||
"""Allows the external acquisition of the lock."""
|
||||
self.async.access_ds.acquire()
|
||||
|
||||
def release(self):
|
||||
"""Allows the external release of the lock."""
|
||||
self.async.access_ds.release()
|
||||
|
||||
# You can only run a fdist case at a time
|
||||
def run_fdist(self, npops, nsamples, fst, sample_size,
|
||||
mut=0, num_sims=20000, data_dir='.',
|
||||
is_dominant=False, theta=0.06, beta=(0.25, 0.25),
|
||||
max_freq=0.99):
|
||||
"""Runs FDist.
|
||||
|
||||
Parameters can be seen on FDistController.run_fdist.
|
||||
|
||||
It will split a single execution in several parts and
|
||||
create separated data directories.
|
||||
"""
|
||||
num_parts = num_sims // self.split_size
|
||||
self.parts = {}
|
||||
self.data_dir = data_dir
|
||||
for directory in range(num_parts):
|
||||
full_path = data_dir + os.sep + str(directory)
|
||||
try:
|
||||
os.mkdir(full_path)
|
||||
except OSError:
|
||||
pass # Its ok, if it is already there
|
||||
if "ss_file" in os.listdir(data_dir):
|
||||
shutil.copy(data_dir + os.sep + "ss_file", full_path)
|
||||
id = self.async.run_program('fdist', {
|
||||
'npops': npops,
|
||||
'nsamples': nsamples,
|
||||
'fst': fst,
|
||||
'sample_size': sample_size,
|
||||
'mut': mut,
|
||||
'num_sims': self.split_size,
|
||||
'data_dir': full_path,
|
||||
'is_dominant': is_dominant,
|
||||
'theta': theta,
|
||||
'beta': beta,
|
||||
'max_freq': max_freq
|
||||
}, {})
|
||||
self.parts[id] = full_path
|
||||
threading.Thread(target=self.monitor).run()
|
@ -1,293 +0,0 @@
|
||||
# Copyright 2007 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.
|
||||
|
||||
"""Code to control fdist (DEPRECATED).
|
||||
|
||||
This will allow you to call fdist and associated programs (cplot,
|
||||
datacal, pv) by Mark Beaumont.
|
||||
|
||||
http://www.rubic.rdg.ac.uk/~mab/software.html (old)
|
||||
http://www.maths.bris.ac.uk/~mamab/ (new)
|
||||
"""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from random import randint
|
||||
from time import strftime, clock
|
||||
# from logging import debug
|
||||
|
||||
|
||||
def my_float(f):
|
||||
# Because of Jython, mostly
|
||||
if f == "-nan":
|
||||
f = "nan"
|
||||
return float(f)
|
||||
|
||||
|
||||
class FDistController(object):
|
||||
def __init__(self, fdist_dir='', ext=None):
|
||||
"""Initializes the controller.
|
||||
|
||||
fdist_dir is the directory where fdist2 is.
|
||||
ext is the extension of binaries (.exe on windows,
|
||||
none on Unix)
|
||||
"""
|
||||
self.tmp_idx = 0
|
||||
self.fdist_dir = fdist_dir
|
||||
self.os_name = os.name
|
||||
if sys.platform == 'win32':
|
||||
py_ext = '.exe'
|
||||
else:
|
||||
py_ext = ''
|
||||
if ext is None:
|
||||
self.ext = py_ext
|
||||
else:
|
||||
self.ext = ext
|
||||
|
||||
def _get_path(self, app):
|
||||
"""Returns the path to an fdist application.
|
||||
|
||||
Includes Path where fdist can be found plus executable extension.
|
||||
"""
|
||||
if self.fdist_dir == '':
|
||||
return app + self.ext
|
||||
else:
|
||||
return os.sep.join([self.fdist_dir, app]) + self.ext
|
||||
|
||||
def _get_temp_file(self):
|
||||
"""Gets a temporary file name.
|
||||
|
||||
Returns a temporary file name, if executing inside jython
|
||||
tries to replace unexisting tempfile.mkstemp().
|
||||
"""
|
||||
self.tmp_idx += 1
|
||||
return strftime("%H%M%S") + str(int(clock() * 100)) + str(randint(0, 1000)) + str(self.tmp_idx)
|
||||
|
||||
def run_datacal(self, data_dir='.', version=1,
|
||||
crit_freq=0.99, p=0.5, beta=(0.25, 0.25)):
|
||||
"""Executes datacal.
|
||||
|
||||
data_dir - Where the data is found.
|
||||
"""
|
||||
if version == 1:
|
||||
datacal_name = "datacal"
|
||||
else:
|
||||
datacal_name = "Ddatacal"
|
||||
proc = subprocess.Popen([self._get_path(datacal_name)],
|
||||
universal_newlines=True,
|
||||
stdin=subprocess.PIPE,
|
||||
shell=(sys.platform != "win32"),
|
||||
stdout=subprocess.PIPE, cwd=data_dir)
|
||||
if version == 1:
|
||||
out, err = proc.communicate('a\n')
|
||||
lines = out.split("\n")
|
||||
fst_line = lines[0].rstrip().split(' ')
|
||||
fst = my_float(fst_line[4])
|
||||
sample_line = lines[1].rstrip().split(' ')
|
||||
sample = int(sample_line[9])
|
||||
else:
|
||||
out, err = proc.communicate('%f\n%f\n%f %f\na\n' % (
|
||||
crit_freq, p, beta[0], beta[1]))
|
||||
lines = out.split("\n")
|
||||
l = lines[0].rstrip().split(" ")
|
||||
loci, pops = int(l[-5]), int(l[-2])
|
||||
fst_line = lines[1].rstrip().split(' ')
|
||||
fst = my_float(fst_line[4])
|
||||
sample_line = lines[2].rstrip().split(' ')
|
||||
sample = int(sample_line[9])
|
||||
F_line = lines[3].rstrip().split(' ')
|
||||
F, obs = my_float(F_line[5]), int(F_line[8])
|
||||
if version == 1:
|
||||
return fst, sample
|
||||
else:
|
||||
return fst, sample, loci, pops, F, obs
|
||||
|
||||
def _generate_intfile(self, data_dir):
|
||||
"""Generates an INTFILE.
|
||||
|
||||
Parameter:
|
||||
- data_dir - data directory
|
||||
"""
|
||||
inf = open(data_dir + os.sep + 'INTFILE', 'w')
|
||||
for i in range(98):
|
||||
inf.write(str(randint(-2 ** 31 + 1, 2 ** 31 - 1)) + '\n')
|
||||
inf.write('8\n')
|
||||
inf.close()
|
||||
|
||||
def run_fdist(self, npops, nsamples, fst, sample_size,
|
||||
mut=0, num_sims=50000, data_dir='.',
|
||||
is_dominant=False, theta=0.06, beta=(0.25, 0.25),
|
||||
max_freq=0.99):
|
||||
"""Executes (d)fdist.
|
||||
|
||||
Parameters:
|
||||
- npops - Number of populations
|
||||
- nsamples - Number of populations sampled
|
||||
- fst - expected Fst
|
||||
- sample_size - Sample size per population
|
||||
For dfdist: if zero a sample size file has to be provided
|
||||
- mut - 1=Stepwise, 0=Infinite allele
|
||||
- num_sims - number of simulations
|
||||
- data_dir - Where the data is found
|
||||
- is_dominant - If true executes dfdist
|
||||
- theta - Theta (=2Nmu)
|
||||
- beta - Parameters for the beta prior
|
||||
- max_freq - Maximum allowed frequency of the commonest allele
|
||||
|
||||
Returns:
|
||||
- fst - Average Fst
|
||||
|
||||
Important Note: This can take quite a while to run!
|
||||
|
||||
"""
|
||||
if fst >= 0.9:
|
||||
# Lets not joke
|
||||
fst = 0.899
|
||||
if fst <= 0.0:
|
||||
# 0 will make fdist run forever
|
||||
fst = 0.001
|
||||
if is_dominant:
|
||||
config_name = "Dfdist_params"
|
||||
else:
|
||||
config_name = "fdist_params2.dat"
|
||||
|
||||
f = open(data_dir + os.sep + config_name, 'w')
|
||||
f.write(str(npops) + '\n')
|
||||
f.write(str(nsamples) + '\n')
|
||||
f.write(str(fst) + '\n')
|
||||
f.write(str(sample_size) + '\n')
|
||||
if is_dominant:
|
||||
f.write(str(theta) + '\n')
|
||||
else:
|
||||
f.write(str(mut) + '\n')
|
||||
f.write(str(num_sims) + '\n')
|
||||
if is_dominant:
|
||||
f.write("%f %f\n" % beta)
|
||||
f.write("%f\n" % max_freq)
|
||||
f.close()
|
||||
|
||||
self._generate_intfile(data_dir)
|
||||
|
||||
if is_dominant:
|
||||
bin_name = "Dfdist"
|
||||
else:
|
||||
bin_name = "fdist2"
|
||||
proc = subprocess.Popen([self._get_path(bin_name)], cwd=data_dir,
|
||||
universal_newlines=True,
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
shell=(sys.platform != "win32"))
|
||||
out, err = proc.communicate('y\n\n')
|
||||
lines = out.split("\n")
|
||||
for line in lines:
|
||||
if line.startswith('average Fst'):
|
||||
fst = my_float(line.rstrip().split(' ')[-1])
|
||||
return fst
|
||||
|
||||
def run_fdist_force_fst(self, npops, nsamples, fst, sample_size,
|
||||
mut=0, num_sims=50000, data_dir='.',
|
||||
try_runs=5000, limit=0.001, is_dominant=False,
|
||||
theta=0.06, beta=(0.25, 0.25),
|
||||
max_freq=0.99):
|
||||
"""Executes fdist trying to force Fst.
|
||||
|
||||
Parameters:
|
||||
- try_runs - Number of simulations on the part trying to get
|
||||
Fst correct
|
||||
- limit - Interval limit
|
||||
|
||||
Other parameters can be seen on run_fdist.
|
||||
|
||||
"""
|
||||
max_run_fst = 1
|
||||
min_run_fst = 0
|
||||
current_run_fst = fst
|
||||
while True:
|
||||
real_fst = self.run_fdist(npops, nsamples, current_run_fst,
|
||||
sample_size, mut, try_runs, data_dir,
|
||||
is_dominant, theta, beta, max_freq)
|
||||
if abs(real_fst - fst) < limit:
|
||||
return self.run_fdist(npops, nsamples, current_run_fst,
|
||||
sample_size, mut, num_sims, data_dir,
|
||||
is_dominant, theta, beta, max_freq)
|
||||
if real_fst > fst:
|
||||
max_run_fst = current_run_fst
|
||||
if current_run_fst < min_run_fst + limit:
|
||||
# we can do no better
|
||||
# debug('Lower limit is ' + str(min_run_fst))
|
||||
return self.run_fdist(npops, nsamples, current_run_fst,
|
||||
sample_size, mut, num_sims,
|
||||
data_dir)
|
||||
current_run_fst = (min_run_fst + current_run_fst) / 2
|
||||
else:
|
||||
min_run_fst = current_run_fst
|
||||
if current_run_fst > max_run_fst - limit:
|
||||
return self.run_fdist(npops, nsamples, current_run_fst,
|
||||
sample_size, mut, num_sims,
|
||||
data_dir, is_dominant, theta,
|
||||
beta, max_freq)
|
||||
current_run_fst = (max_run_fst + current_run_fst) / 2
|
||||
|
||||
def run_cplot(self, ci=0.95, data_dir='.', version=1, smooth=0.04):
|
||||
"""Executes cplot.
|
||||
|
||||
ci - Confidence interval.
|
||||
data_dir - Where the data is found.
|
||||
"""
|
||||
self._generate_intfile(data_dir)
|
||||
if version == 1:
|
||||
cplot_name = "cplot"
|
||||
else:
|
||||
cplot_name = "cplot2"
|
||||
proc = subprocess.Popen([self._get_path(cplot_name)], cwd=data_dir,
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
shell=(sys.platform != "win32"),
|
||||
universal_newlines=True)
|
||||
if version == 1:
|
||||
proc.communicate('out.dat out.cpl\n' + str(ci) + '\n')
|
||||
else:
|
||||
proc.communicate("\n".join([
|
||||
"data_fst_outfile out.cpl out.dat",
|
||||
str(ci), str(smooth)]))
|
||||
|
||||
f = open(data_dir + os.sep + 'out.cpl')
|
||||
conf_lines = []
|
||||
l = f.readline()
|
||||
try:
|
||||
while l != '':
|
||||
conf_lines.append(
|
||||
tuple(my_float(x) for x in l.rstrip().split(' ')))
|
||||
l = f.readline()
|
||||
except ValueError:
|
||||
f.close()
|
||||
return []
|
||||
f.close()
|
||||
return conf_lines
|
||||
|
||||
def run_pv(self, out_file='probs.dat', data_dir='.',
|
||||
version=1, smooth=0.04):
|
||||
"""Executes pv.
|
||||
|
||||
out_file - Name of output file.
|
||||
data_dir - Where the data is found.
|
||||
"""
|
||||
self._generate_intfile(data_dir)
|
||||
|
||||
if version == 1:
|
||||
pv_name = "pv"
|
||||
else:
|
||||
pv_name = "pv2"
|
||||
|
||||
proc = subprocess.Popen([self._get_path(pv_name)], cwd=data_dir,
|
||||
shell=(sys.platform != "win32"),
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
universal_newlines=True)
|
||||
proc.communicate('data_fst_outfile ' + out_file +
|
||||
' out.dat\n' + str(smooth) + '\n')
|
||||
pvf = open(data_dir + os.sep + out_file, 'r')
|
||||
result = [tuple(my_float(y) for y in x.rstrip().split(' ')) for x in pvf.readlines()]
|
||||
pvf.close()
|
||||
return result
|
@ -1,216 +0,0 @@
|
||||
# Copyright 2007 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.
|
||||
|
||||
"""Utility functions for working with FDist (DEPRECATED)."""
|
||||
|
||||
from Bio.PopGen.GenePop import FileParser
|
||||
import Bio.PopGen.FDist
|
||||
|
||||
|
||||
# Quite a few utility functions could be done (like remove pop,
|
||||
# add locus, etc...). The recommended strategy is convert back
|
||||
# and forth from/to GenePop and use GenePop Utils
|
||||
|
||||
|
||||
def convert_genepop_to_fdist(gp_rec, report_pops=None):
|
||||
"""Converts a GenePop record to a FDist one.
|
||||
|
||||
Parameters:
|
||||
gp_rec - Genepop Record (either standard or big)
|
||||
|
||||
Returns:
|
||||
FDist record.
|
||||
|
||||
"""
|
||||
if hasattr(gp_rec, "populations"):
|
||||
return _convert_genepop_to_fdist(gp_rec)
|
||||
else:
|
||||
return _convert_genepop_to_fdist_big(gp_rec, report_pops)
|
||||
|
||||
|
||||
def _convert_genepop_to_fdist(gp_rec):
|
||||
"""Converts a standard GenePop record to a FDist one.
|
||||
|
||||
Parameters:
|
||||
gp_rec - Genepop Record (Standard)
|
||||
|
||||
Returns:
|
||||
FDist record.
|
||||
|
||||
"""
|
||||
fd_rec = Bio.PopGen.FDist.Record()
|
||||
|
||||
fd_rec.data_org = 0
|
||||
fd_rec.num_loci = len(gp_rec.loci_list)
|
||||
fd_rec.num_pops = len(gp_rec.populations)
|
||||
for lc_i in range(len(gp_rec.loci_list)):
|
||||
alleles = []
|
||||
pop_data = []
|
||||
for pop_i in range(len(gp_rec.populations)):
|
||||
for indiv in gp_rec.populations[pop_i]:
|
||||
for al in indiv[1][lc_i]:
|
||||
if al is not None and al not in alleles:
|
||||
alleles.append(al)
|
||||
alleles.sort() # Dominance requires this
|
||||
|
||||
# here we go again (necessary...)
|
||||
for pop_i in range(len(gp_rec.populations)):
|
||||
allele_counts = {}
|
||||
for indiv in gp_rec.populations[pop_i]:
|
||||
for al in indiv[1][lc_i]:
|
||||
if al is not None:
|
||||
count = allele_counts.get(al, 0)
|
||||
allele_counts[al] = count + 1
|
||||
allele_array = [] # We need the same order as in alleles
|
||||
for allele in alleles:
|
||||
allele_array.append(allele_counts.get(allele, 0))
|
||||
pop_data.append(allele_array)
|
||||
fd_rec.loci_data.append((len(alleles), pop_data))
|
||||
return fd_rec
|
||||
|
||||
|
||||
def _convert_genepop_to_fdist_big(gp_rec, report_pops=None):
|
||||
"""Converts a big GenePop record to a FDist one.
|
||||
|
||||
Parameters:
|
||||
gp_rec - Genepop Record (Big)
|
||||
|
||||
Returns:
|
||||
FDist record.
|
||||
|
||||
"""
|
||||
fd_rec = Bio.PopGen.FDist.Record()
|
||||
|
||||
fd_rec.data_org = 1
|
||||
fd_rec.num_loci = len(gp_rec.loci_list)
|
||||
num_loci = len(gp_rec.loci_list)
|
||||
loci = []
|
||||
for i in range(num_loci):
|
||||
loci.append(set())
|
||||
pops = []
|
||||
work_rec = FileParser.read(gp_rec.fname)
|
||||
lParser = work_rec.get_individual()
|
||||
|
||||
def init_pop():
|
||||
my_pop = []
|
||||
for i in range(num_loci):
|
||||
my_pop.append({})
|
||||
return my_pop
|
||||
|
||||
curr_pop = init_pop()
|
||||
num_pops = 1
|
||||
if report_pops:
|
||||
report_pops(num_pops)
|
||||
while lParser:
|
||||
if lParser is not True:
|
||||
for loci_pos in range(num_loci):
|
||||
for al in lParser[1][loci_pos]:
|
||||
if al is not None:
|
||||
loci[loci_pos].add(al)
|
||||
curr_pop[loci_pos][al] = curr_pop[loci_pos].get(al, 0) + 1
|
||||
else:
|
||||
pops.append(curr_pop)
|
||||
num_pops += 1
|
||||
if report_pops:
|
||||
report_pops(num_pops)
|
||||
curr_pop = init_pop()
|
||||
lParser = work_rec.get_individual()
|
||||
work_rec._handle.close() # TODO - Needs a proper fix
|
||||
pops.append(curr_pop)
|
||||
fd_rec.num_pops = num_pops
|
||||
for loci_pos in range(num_loci):
|
||||
alleles = sorted(loci[loci_pos])
|
||||
loci_rec = [len(alleles), []]
|
||||
for pop in pops:
|
||||
pop_rec = []
|
||||
for allele in alleles:
|
||||
pop_rec.append(pop[loci_pos].get(allele, 0))
|
||||
loci_rec[1].append(pop_rec)
|
||||
fd_rec.loci_data.append(tuple(loci_rec))
|
||||
return fd_rec
|
||||
|
||||
|
||||
def _convert_genepop_to_fdist_big_old(gp_rec, report_loci=None):
|
||||
"""Converts a big GenePop record to a FDist one.
|
||||
|
||||
Parameters:
|
||||
gp_rec - Genepop Record (Big)
|
||||
|
||||
Returns:
|
||||
FDist record.
|
||||
|
||||
"""
|
||||
fd_rec = Bio.PopGen.FDist.Record()
|
||||
|
||||
def countPops(rec):
|
||||
f2 = FileParser.read(rec.fname)
|
||||
popCnt = 1
|
||||
while f2.skip_population():
|
||||
popCnt += 1
|
||||
return popCnt
|
||||
|
||||
fd_rec.data_org = 0
|
||||
fd_rec.num_loci = len(gp_rec.loci_list)
|
||||
work_rec0 = FileParser.read(gp_rec.fname)
|
||||
fd_rec.num_pops = countPops(work_rec0)
|
||||
|
||||
num_loci = len(gp_rec.loci_list)
|
||||
for lc_i in range(num_loci):
|
||||
if report_loci:
|
||||
report_loci(lc_i, num_loci)
|
||||
work_rec = FileParser.read(gp_rec.fname)
|
||||
work_rec2 = FileParser.read(gp_rec.fname)
|
||||
|
||||
alleles = []
|
||||
pop_data = []
|
||||
lParser = work_rec.get_individual()
|
||||
while lParser:
|
||||
if lParser is not True:
|
||||
for al in lParser[1][lc_i]:
|
||||
if al is not None and al not in alleles:
|
||||
alleles.append(al)
|
||||
lParser = work_rec.get_individual()
|
||||
# here we go again (necessary...)
|
||||
alleles.sort()
|
||||
|
||||
def process_pop(pop_data, alleles, allele_counts):
|
||||
allele_array = [] # We need the same order as in alleles
|
||||
for allele in alleles:
|
||||
allele_array.append(allele_counts.get(allele, 0))
|
||||
pop_data.append(allele_array)
|
||||
|
||||
lParser = work_rec2.get_individual()
|
||||
allele_counts = {}
|
||||
for allele in alleles:
|
||||
allele_counts[allele] = 0
|
||||
allele_counts[None] = 0
|
||||
while lParser:
|
||||
if lParser is True:
|
||||
process_pop(pop_data, alleles, allele_counts)
|
||||
allele_counts = {}
|
||||
for allele in alleles:
|
||||
allele_counts[allele] = 0
|
||||
allele_counts[None] = 0
|
||||
else:
|
||||
for al in lParser[1][lc_i]:
|
||||
allele_counts[al] += 1
|
||||
lParser = work_rec2.get_individual()
|
||||
process_pop(pop_data, alleles, allele_counts)
|
||||
fd_rec.loci_data.append((len(alleles), pop_data))
|
||||
return fd_rec
|
||||
|
||||
|
||||
def approximate_fst(desired_fst, simulated_fst, parameter_fst,
|
||||
max_run_fst=1, min_run_fst=0, limit=0.005):
|
||||
"""Calculates next Fst attempt to approximate a desired Fst."""
|
||||
if abs(simulated_fst - desired_fst) < limit:
|
||||
return parameter_fst, max_run_fst, min_run_fst
|
||||
if simulated_fst > desired_fst:
|
||||
max_run_fst = parameter_fst
|
||||
next_parameter_fst = (min_run_fst + parameter_fst) / 2
|
||||
else:
|
||||
min_run_fst = parameter_fst
|
||||
next_parameter_fst = (max_run_fst + parameter_fst) / 2
|
||||
return next_parameter_fst, max_run_fst, min_run_fst
|
@ -1,90 +0,0 @@
|
||||
# Copyright 2007 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.
|
||||
|
||||
"""Code to work with FDist (DEPRECATED).
|
||||
|
||||
See http://www.rubic.rdg.ac.uk/~mab/software.html (old) and
|
||||
http://www.maths.bris.ac.uk/~mamab/ (new) for downloading the
|
||||
FDist tool by Mark Beaumont.
|
||||
|
||||
Classes:
|
||||
Record Holds FDist data.
|
||||
|
||||
Functions:
|
||||
read Parses a FDist record (file) into a Record object.
|
||||
|
||||
"""
|
||||
|
||||
import warnings
|
||||
|
||||
from Bio import BiopythonDeprecationWarning
|
||||
|
||||
warnings.warn("Bio.PopGen.FDist has been deprecated, and we intend to remove"
|
||||
" it in a future release of Biopython. If you would like to"
|
||||
" continue using it, please contact the Biopython developers"
|
||||
" via the mailing list.", BiopythonDeprecationWarning)
|
||||
|
||||
|
||||
def read(handle):
|
||||
"""Parses FDist data into a Record object.
|
||||
|
||||
handle is a file-like object that contains a FDist record.
|
||||
"""
|
||||
record = Record()
|
||||
record.data_org = int(str(next(handle)).rstrip())
|
||||
record.num_pops = int(str(next(handle)).rstrip())
|
||||
record.num_loci = int(str(next(handle)).rstrip())
|
||||
for i in range(record.num_loci):
|
||||
next(handle)
|
||||
num_alleles = int(str(next(handle)).rstrip())
|
||||
pops_data = []
|
||||
if record.data_org == 0:
|
||||
for j in range(record.num_pops):
|
||||
line_comp = str(next(handle)).rstrip().split(' ')
|
||||
pop_dist = [int(x) for x in line_comp]
|
||||
pops_data.append(pop_dist)
|
||||
else:
|
||||
raise NotImplementedError('1/alleles by rows not implemented')
|
||||
record.loci_data.append((num_alleles, pops_data))
|
||||
return record
|
||||
|
||||
|
||||
class Record(object):
|
||||
"""Holds information from a FDist record.
|
||||
|
||||
Members:
|
||||
|
||||
- data_org - Data organization (0 pops by rows, 1 alleles by rows).
|
||||
The Record will behave as if data was 0 (converting if needed)
|
||||
- num_pops - Number of populations
|
||||
- num_loci - Number of loci
|
||||
- loci_data - Loci data
|
||||
|
||||
loci_data is a list, where each element represents a locus. Each element
|
||||
is a tuple, the first element is the number of alleles, the second
|
||||
element a list. Each element of the list is the count of each allele
|
||||
per population.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.data_org = 0
|
||||
self.num_pops = 0
|
||||
self.num_loci = 0
|
||||
self.loci_data = []
|
||||
|
||||
def __str__(self):
|
||||
rep = ['0\n'] # We only export in 0 format, even if originally was 1
|
||||
rep.append(str(self.num_pops) + '\n')
|
||||
rep.append(str(self.num_loci) + '\n')
|
||||
rep.append('\n')
|
||||
for locus_data in self.loci_data:
|
||||
num_alleles, pops_data = locus_data
|
||||
rep.append(str(num_alleles) + '\n')
|
||||
for pop_data in pops_data:
|
||||
for allele_count in pop_data:
|
||||
rep.append(str(allele_count) + ' ')
|
||||
rep.append('\n')
|
||||
rep.append('\n')
|
||||
return "".join(rep)
|
@ -1,31 +0,0 @@
|
||||
# Copyright 2007 by Tiago Antao <tiagoantao@gmail.com>. All rights reserved.
|
||||
|
||||
"""Async. caching of Simcoal2 results (DEPRECATED).
|
||||
|
||||
This module allows to cache Simcoal2 results, and return on the fly
|
||||
in case the calculation was done. Async version
|
||||
|
||||
This version will run Sincoal2 (if necessary) Asynchrously.
|
||||
|
||||
"""
|
||||
|
||||
import os
|
||||
from . import Cache
|
||||
|
||||
|
||||
class SimCoalCache(Cache.SimCoalCache):
|
||||
def __init__(self, data_dir, simcoal_dir):
|
||||
self.data_dir = data_dir
|
||||
Cache.SimCoalCache.__init__(self, data_dir, simcoal_dir)
|
||||
|
||||
def runJob(self, parameters, inputFiles):
|
||||
parFile = parameters['parFile']
|
||||
numSims = parameters['numSims']
|
||||
ploydi = parameters.get('ploydi', '1')
|
||||
f = inputFiles[parFile]
|
||||
text = f.read()
|
||||
f.close()
|
||||
with open(os.sep.join([self.data_dir, 'SimCoal', 'runs', parFile]), 'w') as w:
|
||||
w.write(text)
|
||||
self.run_simcoal(parFile, numSims, ploydi)
|
||||
return 0, None
|
@ -1,84 +0,0 @@
|
||||
# Copyright 2007 by Tiago Antao <tiagoantao@gmail.com>. All rights reserved.
|
||||
|
||||
"""Cache for Simcoal2 results (DEPRECATED).
|
||||
|
||||
This module allows you to cache Simcoal2 results, and return on the fly
|
||||
in case the calculation was done.
|
||||
"""
|
||||
|
||||
import os
|
||||
import tarfile
|
||||
from .Controller import SimCoalController
|
||||
|
||||
|
||||
class SimCoalCache(object):
|
||||
def __init__(self, data_dir, simcoal_dir):
|
||||
"""Initializes the cache.
|
||||
|
||||
- data_dir - Where the cache can be found
|
||||
- simcoal_dir - where the binaries are
|
||||
|
||||
IMPORTANT: The cache only makes sense if the file name univocally
|
||||
identifies the model.
|
||||
For now use use the model name as key,
|
||||
and it will probably stay like that.
|
||||
"""
|
||||
self.dataDir = data_dir
|
||||
self.cacheDir = os.sep.join([data_dir, 'SimCoal', 'cache'])
|
||||
self.simcoalDir = simcoal_dir
|
||||
|
||||
def run_simcoal(self, par_file, num_sims, ploydi='1', parDir=None):
|
||||
if parDir is None:
|
||||
parDir = os.sep.join([self.dataDir, 'SimCoal', 'runs'])
|
||||
par_file_root = par_file[:-4]
|
||||
tar_name = os.sep.join([self.cacheDir, ploydi, par_file_root +
|
||||
'.tar.bz2'])
|
||||
if os.access(tar_name, os.R_OK):
|
||||
tf = tarfile.open(tar_name)
|
||||
tar_num_sims = len(tf.getmembers()) - 3
|
||||
else:
|
||||
tar_num_sims = 0
|
||||
if tar_num_sims >= num_sims:
|
||||
tf.extractall(parDir)
|
||||
tf.close()
|
||||
return
|
||||
else:
|
||||
try:
|
||||
tf.close()
|
||||
except NameError:
|
||||
pass # not opened in the first place, OK.
|
||||
scc = SimCoalController(self.simcoalDir)
|
||||
scc.run_simcoal(par_file, num_sims, ploydi, parDir)
|
||||
tf = tarfile.open(tar_name, 'w:bz2')
|
||||
tf.add(os.sep.join([parDir, par_file_root]), par_file_root)
|
||||
tf.close()
|
||||
|
||||
def listSimulations(self, ploidy='1'):
|
||||
"""Lists available simulations."""
|
||||
files = os.listdir(self.cacheDir + os.sep + ploidy)
|
||||
sims = []
|
||||
for file in files:
|
||||
if file.endswith('.tar.bz2'):
|
||||
sims.append(file[:-8])
|
||||
return sims
|
||||
|
||||
def getSimulation(self, sim_name, ploidy='1', parDir=None):
|
||||
"""Makes available a cached simulation.
|
||||
|
||||
@param sim_name simulation name.
|
||||
|
||||
This mainly means untaring a file.
|
||||
"""
|
||||
if parDir is None:
|
||||
parDir = os.sep.join([self.dataDir, 'SimCoal', 'runs'])
|
||||
tar_name = os.sep.join([self.cacheDir, ploidy, sim_name +
|
||||
'.tar.bz2'])
|
||||
tf = tarfile.open(tar_name)
|
||||
tf.extractall(parDir)
|
||||
tf.close()
|
||||
|
||||
|
||||
# if __name__ == '__main__':
|
||||
# cache = Cache('/home/work/werk/consolidator/sc_cache',
|
||||
# '/home/work/software/simcoal')
|
||||
# cache.run_simcoal('.', 'island_snp-50_0.0025_10_0.083_100_60.par', 102)
|
@ -1,221 +0,0 @@
|
||||
# Copyright 2007 by Tiago Antao <tiagoantao@gmail.com>.
|
||||
# Revisions copyright 2014 by Melissa Gymrek <mgymrek@mit.edu>.
|
||||
# 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.
|
||||
|
||||
"""Control Simcoal2 and FastSimcoal (DEPRECATED)."""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from Bio.Application import AbstractCommandline, _Option, _Switch
|
||||
|
||||
|
||||
class SimCoalController(object):
|
||||
def __init__(self, simcoal_dir):
|
||||
"""Initializes the controller (DEPRECATED).
|
||||
|
||||
simcoal_dir is the directory where simcoal is.
|
||||
|
||||
The initializer checks for existence and executability of binaries.
|
||||
"""
|
||||
self.simcoal_dir = simcoal_dir
|
||||
self.os_name = os.name # remove this?
|
||||
dir_contents = os.listdir(self.simcoal_dir)
|
||||
# We expect the tool to be installed as simcoal2(.exe)
|
||||
# without any trailing version number.
|
||||
self.bin_name = "simcoal2"
|
||||
if self.bin_name not in dir_contents:
|
||||
# Try case insensitive,
|
||||
dir_contents = [x.lower() for x in dir_contents]
|
||||
if self.bin_name not in dir_contents:
|
||||
# Try with .exe
|
||||
self.bin_name += '.exe'
|
||||
if self.bin_name not in dir_contents:
|
||||
raise IOError("SimCoal not available")
|
||||
if not os.access(os.path.join(self.simcoal_dir, self.bin_name),
|
||||
os.X_OK):
|
||||
raise IOError("SimCoal not executable")
|
||||
|
||||
def run_simcoal(self, par_file, num_sims, ploydi='1', par_dir='.'):
|
||||
"""Executes SimCoal."""
|
||||
if par_dir is None:
|
||||
par_dir = os.sep.join([".", 'SimCoal', 'runs'])
|
||||
curr_dir = os.getcwd()
|
||||
# TODO - Make sure we change drive on Windows as well?
|
||||
os.chdir(par_dir)
|
||||
exe = os.path.join(self.simcoal_dir, self.bin_name)
|
||||
if " " in exe:
|
||||
exe = '"' + exe + '"'
|
||||
cmd = exe + ' ' + par_file + ' ' + str(num_sims) + ' ' + ploydi
|
||||
# TODO - Better way to spot if on Jython on Windows?
|
||||
if sys.platform == "win32" or self.bin_name.endswith(".exe"):
|
||||
# There is no /dev/nul on Windows
|
||||
cmd += ' > nul 2>nul'
|
||||
else:
|
||||
cmd += ' >/dev/null 2>&1'
|
||||
os.system(cmd)
|
||||
os.chdir(curr_dir)
|
||||
|
||||
|
||||
class _FastSimCoalCommandLine(AbstractCommandline):
|
||||
"""Command Line Wrapper for Fastsimcoal (PRIVATE)."""
|
||||
|
||||
def __init__(self, fastsimcoal_dir=None, cmd='fastsimcoal', **kwargs):
|
||||
self.parameters = [
|
||||
_Option(["-i", "--ifile", "parfile"], "Name of the parameter file",
|
||||
filename=True, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, str)),
|
||||
_Option(["-n", "--numsims", "numsims"], "Number of simulations to perform",
|
||||
filename=False, equate=False, is_required=True,
|
||||
checker_function=lambda x: isinstance(x, int)),
|
||||
_Option(["-t", "--tfile", "tfile"], "Name of template parameter file",
|
||||
filename=True, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, str)),
|
||||
_Option(["-f", "--dfile", "dfile"], "Name of parameter definition file",
|
||||
filename=True, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, str)),
|
||||
_Option(["-F", "--dFile", "dFile"],
|
||||
"""Same as -f but only uses simple parameters defined
|
||||
in the template file. Complex params are recomputed""",
|
||||
filename=True, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, str)),
|
||||
_Option(["-e", "--efile", "efile"],
|
||||
"""Parameter prior definition file.
|
||||
Parameters drawn from specified distributions are
|
||||
substituted into template file.""",
|
||||
filename=True, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, str)),
|
||||
_Option(["-E", "--numest", "numest"],
|
||||
"""Number of estimations from parameter priors.
|
||||
Listed parameter values are substituted in template file.""",
|
||||
filename=False, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, int)),
|
||||
_Switch(["-g", "--genotypic", "genotypic"], "Generates Arlequin projects with genotypic data"),
|
||||
_Switch(["-p", "--phased", "phased"], "Specifies that phase is known in Arlequin output"),
|
||||
_Option(["-s", "--dnatosnp", "dnatosnp"],
|
||||
""""Output DNA as SNP data (0: ancestral, 1: derived
|
||||
and specify maximum no. SNPs to output.""",
|
||||
filename=False, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, int)),
|
||||
_Switch(["-S", "--allsites", "allsites"],
|
||||
"""Output the whole DNA sequence, including monomorphic sites"""),
|
||||
_Switch(["-I", "--inf", "inf"],
|
||||
"""Generates DNA mutations according to an
|
||||
infinite sites (IS) mutation model."""),
|
||||
_Switch(["-d", "--dsfs", "dsfs"], "Computes derived site frequency spectrum"),
|
||||
_Switch(["-m", "--msfs", "msfs"], "Computes minor site frequency spectrum"),
|
||||
_Option(["-o", "--oname", "oname"], "Generic name for observed SFS files",
|
||||
filename=False, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, str)),
|
||||
_Switch(["-H", "--header", "header"], "Generates header in site frequency spectrum files."),
|
||||
_Switch(["-q", "--quiet", "quiet"], "Minimal messages output to console"),
|
||||
_Switch(["-T", "--tree", "tree"], "Output coalescent tree in nexus format."),
|
||||
_Option(["-k", "--keep", "keep"],
|
||||
"""Number of simulated polymorphic sites kept in memory.
|
||||
If the simulated no. is larger, then temporary files are created.""",
|
||||
filename=False, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, int)),
|
||||
_Option(["--seed", "seed"], "Seed for the random number generator (positive int <=1E6)",
|
||||
filename=False, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, int)),
|
||||
_Switch(["-x", "--noarloutput", "noarloutput"], "Does not generate Arlequin output"),
|
||||
_Switch(["-D", "--dadioutput", "dadioutput"], "Output SFS in dadi format"),
|
||||
_Option(["-M", "--maxlhood", "maxlhood"],
|
||||
"""Perform parameter estimation by max lhood from SFS, and
|
||||
define stop criterion as min., rel., diff. in parameter
|
||||
values between iterations""",
|
||||
filename=False, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, float)),
|
||||
_Option(["-N", "--maxnumsims", "maxnumsims"],
|
||||
"""Maximum number of simulations to perform during
|
||||
likelihood maximization.""",
|
||||
filename=False, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, int)),
|
||||
_Option(["-l", "--minnumloops", "minnumloops"],
|
||||
"""Minimum number of iteration loops to perform during
|
||||
likelihood maximization.""",
|
||||
filename=False, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, int)),
|
||||
_Option(["-L", "--maxnumloops", "maxnumloops"],
|
||||
"""Maximum number of iterations to perform during
|
||||
likelihood maximization""",
|
||||
filename=False, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, int)),
|
||||
_Option(["-C", "--minSFSCount", "minSFSCount"],
|
||||
"""Minimum observed SFS entry count taken into account
|
||||
in likelihood computation""",
|
||||
filename=False, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, int)),
|
||||
_Switch(["-0", "--removeZeroSFS", "removeZeroSFS"],
|
||||
"""Do not take into account monomorphic sites for
|
||||
SFS likelihood computation."""),
|
||||
_Option(["-a", "--ascDeme", "ascDeme"],
|
||||
"""This is the deme id where ascertainment is performed
|
||||
when simulating SNPs.""",
|
||||
filename=False, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, int)),
|
||||
_Option(["-A", "--ascSize", "ascSize"],
|
||||
"""Number of ascertained chromosomes used to define SNPs in
|
||||
a given deme.""",
|
||||
filename=False, equate=False, is_required=False,
|
||||
checker_function=lambda x: isinstance(x, int)),
|
||||
_Switch(["-u", "--multiSFS", "multiSFS"],
|
||||
"Generate or use multidimensional SFS")]
|
||||
AbstractCommandline.__init__(self, cmd, **kwargs)
|
||||
|
||||
|
||||
class FastSimCoalController(object):
|
||||
def __init__(self, fastsimcoal_dir=None, bin_name="fsc252"):
|
||||
"""Initializes the controller.
|
||||
|
||||
fastsimcoal_dir is the directory where fastsimcoal is.
|
||||
By default the binary should be called fsc252.
|
||||
bin_name specifies a different name for the binary.
|
||||
|
||||
The initializer checks for existence and executability of binaries
|
||||
and sets up the command line controller.
|
||||
|
||||
Fastsimcoal2 is available here: http://cmpg.unibe.ch/software/fastsimcoal2/.
|
||||
This wrapper was written and tested for fastsimcoal version 2.51.
|
||||
"""
|
||||
self.bin_name = bin_name
|
||||
self.fastsimcoal_dir = fastsimcoal_dir
|
||||
if fastsimcoal_dir is None:
|
||||
for path in os.environ["PATH"].split(os.pathsep):
|
||||
if os.path.isfile(os.path.join(path, self.bin_name)):
|
||||
self.fastsimcoal_dir = path
|
||||
if self.fastsimcoal_dir is None:
|
||||
raise IOError("Fastsimcoal not available")
|
||||
else:
|
||||
dir_contents = os.listdir(fastsimcoal_dir)
|
||||
if self.bin_name not in dir_contents:
|
||||
raise IOError("Fastsimcoal not available")
|
||||
if not os.access(os.path.join(self.fastsimcoal_dir, self.bin_name), os.X_OK):
|
||||
raise IOError("Fastsimcoal not executable")
|
||||
|
||||
def run_fastsimcoal(self, par_file, num_sims, par_dir='.', opts=None):
|
||||
"""Executes Fastsimcoal.
|
||||
|
||||
par_file is the input parameter file (--ifile) for fastsimcoal.
|
||||
num_sims is the number of simulations to perform.
|
||||
par_dir is the directory where par_file is and where output will be written.
|
||||
opts is a dictionary of additional options to fastsimcoal.
|
||||
"""
|
||||
if opts is None:
|
||||
opts = {}
|
||||
if par_dir is None:
|
||||
par_dir = os.sep.join([".", "Fastsimcoal", "runs"])
|
||||
if not os.path.exists(par_dir):
|
||||
os.mkdir(par_dir)
|
||||
curr_dir = os.getcwd()
|
||||
os.chdir(par_dir)
|
||||
if par_file is None: # Must use .tpl for -t instead if no par_file
|
||||
controller = _FastSimCoalCommandLine(cmd=os.path.join(self.fastsimcoal_dir, self.bin_name),
|
||||
numsims=num_sims, **opts)
|
||||
else:
|
||||
controller = _FastSimCoalCommandLine(cmd=os.path.join(self.fastsimcoal_dir, self.bin_name),
|
||||
parfile=par_file, numsims=num_sims, **opts)
|
||||
controller()
|
||||
os.chdir(curr_dir)
|
@ -1,228 +0,0 @@
|
||||
# Copyright 2007 by Tiago Antao. 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.
|
||||
|
||||
"""Utility code for using SimCoal (DEPRECATED)."""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from os import sep
|
||||
import re
|
||||
from functools import reduce
|
||||
|
||||
from Bio.PopGen.SimCoal import builtin_tpl_dir
|
||||
|
||||
|
||||
def exec_template(template):
|
||||
executed_template = template
|
||||
match = re.search('!!!(.*?)!!!', executed_template, re.MULTILINE)
|
||||
# while len(match.groups())>0:
|
||||
while match:
|
||||
exec_result = str(eval(match.groups()[0]))
|
||||
executed_template = executed_template.replace(
|
||||
'!!!' + match.groups()[0] + '!!!',
|
||||
exec_result, 1)
|
||||
match = re.search('!!!(.*?)!!!', executed_template, re.MULTILINE)
|
||||
# match = patt.matcher(String(executed_template))
|
||||
return executed_template
|
||||
|
||||
|
||||
def process_para(in_string, out_file_prefix, para_list, curr_values):
|
||||
if (para_list == []):
|
||||
template = in_string
|
||||
f_name = out_file_prefix
|
||||
# f_name += '_' + str(total_size)
|
||||
for tup in curr_values:
|
||||
name, val = tup
|
||||
f_name += '_' + str(val)
|
||||
# reg = re.compile('\?' + name, re.MULTILINE)
|
||||
# template = re.sub(reg, str(val), template)
|
||||
template = template.replace('?' + name, str(val))
|
||||
with open(f_name + '.par', 'w') as f:
|
||||
# executed_template = template
|
||||
executed_template = exec_template(template)
|
||||
clean_template = executed_template.replace('\r\n', '\n').replace('\n\n', '\n')
|
||||
f.write(clean_template)
|
||||
return [f_name]
|
||||
else:
|
||||
name, rng = para_list[0]
|
||||
fnames = []
|
||||
for val in rng:
|
||||
new_values = [(name, val)]
|
||||
new_values.extend(curr_values)
|
||||
more_names = process_para(in_string, out_file_prefix, para_list[1:], new_values)
|
||||
fnames.extend(more_names)
|
||||
return fnames
|
||||
|
||||
|
||||
def dupe(motif, times):
|
||||
ret_str = ''
|
||||
for i in range(1, times + 1):
|
||||
ret_str += motif + '\r\n'
|
||||
return ret_str
|
||||
|
||||
|
||||
def get_xy_from_matrix(x_max, y_max, pos):
|
||||
y = (pos - 1) / x_max
|
||||
x = (pos - 1) % x_max
|
||||
return x, y
|
||||
|
||||
|
||||
def get_step_2d(x_max, y_max, x, y, mig):
|
||||
my_x, my_y = get_xy_from_matrix(x_max, y_max, y)
|
||||
other_x, other_y = get_xy_from_matrix(x_max, y_max, x)
|
||||
|
||||
if (my_x - other_x) ** 2 + (my_y - other_y) ** 2 == 1:
|
||||
return str(mig) + ' '
|
||||
else:
|
||||
return '0 '
|
||||
|
||||
|
||||
def generate_ssm2d_mat(x_max, y_max, mig):
|
||||
mig_mat = ''
|
||||
for x in range(1, x_max * y_max + 1):
|
||||
for y in range(1, x_max * y_max + 1):
|
||||
mig_mat += get_step_2d(x_max, y_max, x, y, mig)
|
||||
mig_mat += "\r\n"
|
||||
return mig_mat
|
||||
|
||||
|
||||
def generate_island_mat(total_size, mig):
|
||||
mig_mat = ''
|
||||
for x in range(1, total_size + 1):
|
||||
for y in range(1, total_size + 1):
|
||||
if (x == y):
|
||||
mig_mat += '0 '
|
||||
else:
|
||||
mig_mat += '!!!' + str(mig) + '!!! '
|
||||
mig_mat += "\r\n"
|
||||
return mig_mat
|
||||
|
||||
|
||||
def generate_null_mat(total_size):
|
||||
null_mat = ''
|
||||
for x in range(1, total_size + 1):
|
||||
for y in range(1, total_size + 1):
|
||||
null_mat += '0 '
|
||||
null_mat += '\r\n'
|
||||
return null_mat
|
||||
|
||||
|
||||
def generate_join_events(t, total_size, join_size, orig_size):
|
||||
events = ''
|
||||
for i in range(1, total_size - 1):
|
||||
events += str(t) + ' ' + str(i) + ' 0 1 1 0 1\r\n'
|
||||
events += str(t) + ' ' + str(total_size - 1) + ' 0 1 ' + str(1.0 * total_size * join_size / orig_size) + ' 0 1\r\n'
|
||||
return events
|
||||
|
||||
|
||||
def no_processor(in_string):
|
||||
return in_string
|
||||
|
||||
|
||||
def process_text(in_string, out_file_prefix, para_list, curr_values,
|
||||
specific_processor):
|
||||
text = specific_processor(in_string)
|
||||
return process_para(text, out_file_prefix, para_list, [])
|
||||
|
||||
|
||||
# def prepare_dir():
|
||||
# try:
|
||||
# mkdir(sep.join([Config.dataDir, 'SimCoal'])) # Should exist, but...
|
||||
# except OSError:
|
||||
# pass # Its ok if already exists
|
||||
# try:
|
||||
# mkdir(sep.join([Config.dataDir, 'SimCoal', 'runs']))
|
||||
# except OSError:
|
||||
# pass # Its ok if already exists
|
||||
|
||||
|
||||
# sep is because of jython
|
||||
def generate_model(par_stream, out_prefix, params,
|
||||
specific_processor=no_processor, out_dir='.'):
|
||||
# prepare_dir()
|
||||
text = par_stream.read()
|
||||
out_file_prefix = sep.join([out_dir, out_prefix])
|
||||
return process_text(text, out_file_prefix, params, [], specific_processor)
|
||||
|
||||
|
||||
def get_demography_template(stream, model, tp_dir=None):
|
||||
"""Gets a demograpy template.
|
||||
|
||||
Most probably this model needs to be sent to GenCases.
|
||||
|
||||
- stream - Writable stream.
|
||||
- param - Template file.
|
||||
- tp_dir - Directory where to find the template, if None
|
||||
use an internal template
|
||||
"""
|
||||
if tp_dir is None:
|
||||
# Internal Template
|
||||
filename = sep.join([builtin_tpl_dir, model + '.par'])
|
||||
else:
|
||||
# External template
|
||||
filename = sep.join([tp_dir, model + '.par'])
|
||||
with open(filename, 'r') as f:
|
||||
l = f.readline()
|
||||
while l != '':
|
||||
stream.write(l)
|
||||
l = f.readline()
|
||||
|
||||
|
||||
def _gen_loci(stream, loci):
|
||||
stream.write('//Number of contiguous linkage blocks in chromosome\n')
|
||||
stream.write(str(len(loci)) + '\n')
|
||||
stream.write('//Per Block: Data type, No. of loci, Recombination rate to the right-side locus, plus optional parameters\n')
|
||||
for locus in loci:
|
||||
stream.write(' '.join([locus[0]] +
|
||||
[str(x) for x in list(locus[1])]) + '\n')
|
||||
|
||||
|
||||
def get_chr_template(stream, chrs):
|
||||
"""Writes a Simcoal2 loci template part.
|
||||
|
||||
stream - Writable stream.
|
||||
chr - Chromosome list.
|
||||
|
||||
Current loci list:
|
||||
|
||||
- [(chr_repeats,[(marker, (params))])]
|
||||
|
||||
- chr_repeats --> Number of chromosome repeats
|
||||
- marker --> 'SNP', 'DNA', 'RFLP', 'MICROSAT'
|
||||
- params --> Simcoal2 parameters for markers (list of floats
|
||||
or ints - if to be processed by generate_model)
|
||||
"""
|
||||
num_chrs = reduce(lambda x, y: x + y[0], chrs, 0)
|
||||
stream.write('//Number of independent (unlinked) chromosomes, and "chromosome structure" flag: 0 for identical structure across chromosomes, and 1 for different structures on different chromosomes.\n')
|
||||
if len(chrs) > 1 or num_chrs == 1:
|
||||
stream.write(str(num_chrs) + ' 1\n')
|
||||
else:
|
||||
stream.write(str(num_chrs) + ' 0\n')
|
||||
for chr in chrs:
|
||||
repeats = chr[0]
|
||||
loci = chr[1]
|
||||
if len(chrs) == 1:
|
||||
_gen_loci(stream, loci)
|
||||
else:
|
||||
for i in range(repeats):
|
||||
_gen_loci(stream, loci)
|
||||
|
||||
|
||||
def generate_simcoal_from_template(model, chrs, params, out_dir='.', tp_dir=None):
|
||||
"""Writes a complete SimCoal2 template file.
|
||||
|
||||
This joins together get_demography_template and get_chr_template,
|
||||
which are feed into generate_model
|
||||
Please check the three functions for parameters (model from
|
||||
get_demography_template, chrs from get_chr_template and
|
||||
params from generate_model).
|
||||
"""
|
||||
with open(out_dir + sep + 'tmp.par', 'w') as stream:
|
||||
get_demography_template(stream, model, tp_dir)
|
||||
get_chr_template(stream, chrs)
|
||||
# with open(out_dir + sep + 'tmp.par', 'r') as par_stream:
|
||||
# print par_stream.read()
|
||||
with open(out_dir + sep + 'tmp.par', 'r') as par_stream:
|
||||
generate_model(par_stream, model, params, out_dir=out_dir)
|
@ -1,26 +0,0 @@
|
||||
# Copyright 2007 by Tiago Antao. 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.
|
||||
|
||||
"""SimCoal2 execution module and support functions (DEPRECATED)."""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
from Bio import BiopythonDeprecationWarning
|
||||
|
||||
warnings.warn("Bio.PopGen.SimCoal has been deprecated, and we intend to "
|
||||
" remove it in a future release of Biopython. If you would like"
|
||||
" to continue using it, please contact the Biopython developers"
|
||||
" via the mailing list.", BiopythonDeprecationWarning)
|
||||
|
||||
|
||||
# This is a workaround to work with the test system
|
||||
# In any case the problem is with the test system
|
||||
for instance in sys.path:
|
||||
test_path = os.path.join(instance, 'Bio', 'PopGen', 'SimCoal', 'data')
|
||||
if os.access(test_path, os.F_OK):
|
||||
builtin_tpl_dir = test_path
|
||||
break
|
@ -1,14 +0,0 @@
|
||||
//Parameters for the coalescence simulation program : simcoal.exe
|
||||
1 samples
|
||||
//Population effective sizes (number of genes 2*diploids)
|
||||
?pop_size
|
||||
//Samples sizes (number of genes 2*diploids)
|
||||
?sample_size
|
||||
//Growth rates : negative growth implies population expansion
|
||||
0
|
||||
//Number of migration matrices : 0 implies no migration between demes
|
||||
0
|
||||
//historical event: time, source, sink, migrants, new deme size, new growth rate, migration matrix index
|
||||
2 historical events
|
||||
?contract_gen 0 0 1 !!!1.0*?ne1/?ne2!!! 0 1
|
||||
?expand_gen 0 0 1 !!!1.0*?ne2/?pop_size!!! 0 1
|
@ -1,14 +0,0 @@
|
||||
//Parameters for the coalescence simulation program : simcoal.exe
|
||||
1 samples
|
||||
//Population effective sizes (number of genes 2*diploids)
|
||||
?pop_size
|
||||
//Samples sizes (number of genes 2*diploids)
|
||||
?sample_size
|
||||
//Growth rates : negative growth implies population expansion
|
||||
0
|
||||
//Number of migration matrices : 0 implies no migration between demes
|
||||
0
|
||||
//historical event: time, source, sink, migrants, new deme size, new growth rate, migration matrix index
|
||||
2 historical events
|
||||
?t2 0 0 1 1 0 1
|
||||
?t1 0 0 1 1 ?r 1
|
@ -1,23 +0,0 @@
|
||||
//Parameters for the coalescence simulation program : simcoal.exe
|
||||
2 samples
|
||||
//Population effective sizes (number of genes 2*diploids)
|
||||
?pop_size
|
||||
?pop_size
|
||||
//Samples sizes (number of genes 2*diploids)
|
||||
?sample_size
|
||||
?sample_size
|
||||
//Growth rates : negative growth implies population expansion
|
||||
0
|
||||
0
|
||||
//Number of migration matrices : 0 implies no migration between demes
|
||||
2
|
||||
//mig
|
||||
0 ?mig
|
||||
?mig 0
|
||||
//nothing
|
||||
0 0
|
||||
0 0
|
||||
//historical event: time, source, sink, migrants, new deme size, new growth rate, migration matrix index
|
||||
2 historical events
|
||||
?contract_gen 0 0 1 !!!1.0*?ne1/?ne2!!! 0 1
|
||||
?split_gen 1 0 1 !!!1.0*?ne2/(2*?pop_size)!!! 0 1
|
@ -1,14 +0,0 @@
|
||||
//Parameters for the coalescence simulation program simcoal.
|
||||
?total_demes samples
|
||||
//Population effective sizes (number of genes 2*diploids)
|
||||
!!!dupe('?pop_size', ?total_demes)!!!
|
||||
//Samples sizes (number of genes 2*diploids)
|
||||
!!!dupe('?sample_size', ?total_demes)!!!
|
||||
//Growth rates : negative growth implies population expansion
|
||||
!!!dupe('0', ?total_demes)!!!
|
||||
//Number of migration matrices : 0 implies no migration between demes
|
||||
1
|
||||
//mig
|
||||
!!!generate_island_mat(?total_demes,?mig)!!!
|
||||
//historical event: time, source, sink, migrants, new deme size, new growth rate, migration matrix index
|
||||
0 historical events
|
@ -1,12 +0,0 @@
|
||||
//Parameters for the coalescence simulation program : simcoal.exe
|
||||
1 samples
|
||||
//Population effective sizes (number of genes 2*diploids)
|
||||
?pop_size
|
||||
//Samples sizes (number of genes 2*diploids)
|
||||
?sample_size
|
||||
//Growth rates : negative growth implies population expansion
|
||||
0
|
||||
//Number of migration matrices : 0 implies no migration between demes
|
||||
0
|
||||
//historical event: time, source, sink, migrants, new deme size, new growth rate, migration matrix index
|
||||
0 historical events
|
@ -1,17 +0,0 @@
|
||||
//Parameters for the coalescence simulation program simcoal.
|
||||
?total_demes samples
|
||||
//Population effective sizes (number of genes 2*diploids)
|
||||
!!!dupe('?pop_size', ?total_demes)!!!
|
||||
//Samples sizes (number of genes 2*diploids)
|
||||
!!!dupe('?sample_size', ?total_demes)!!!
|
||||
//Growth rates : negative growth implies population expansion
|
||||
!!!dupe('0', ?total_demes)!!!
|
||||
//Number of migration matrices : 0 implies no migration between demes
|
||||
2
|
||||
//mig
|
||||
!!!generate_island_mat(?total_demes,?mig)!!!
|
||||
//nothing
|
||||
!!!generate_null_mat(?total_demes)!!!
|
||||
//historical event: time, source, sink, migrants, new deme size, new growth rate, migration matrix index
|
||||
!!!?total_demes-1!!! historical events
|
||||
!!!generate_join_events(?t1,?total_demes,?ne1,?pop_size)!!!
|
@ -1,17 +0,0 @@
|
||||
//Parameters for the coalescence simulation program simcoal.
|
||||
?total_demes samples
|
||||
//Population effective sizes (number of genes 2*diploids)
|
||||
!!!dupe('?pop_size', ?total_demes)!!!
|
||||
//Samples sizes (number of genes 2*diploids)
|
||||
!!!dupe('?sample_size', ?total_demes)!!!
|
||||
//Growth rates : negative growth implies population expansion
|
||||
!!!dupe('0', ?total_demes)!!!
|
||||
//Number of migration matrices : 0 implies no migration between demes
|
||||
2
|
||||
//mig
|
||||
!!!generate_ssm2d_mat(?total_demes, 1, ?mig)!!!
|
||||
//nothing
|
||||
!!!generate_null_mat(?total_demes)!!!
|
||||
//historical event: time, source, sink, migrants, new deme size, new growth rate, migration matrix index
|
||||
!!!?total_demes-1!!! historical events
|
||||
!!!generate_join_events(?t, ?total_demes, ?ne, ?pop_size)!!!
|
@ -1,17 +0,0 @@
|
||||
//Parameters for the coalescence simulation program simcoal.
|
||||
!!!?x * ?y!!! samples
|
||||
//Population effective sizes (number of genes 2*diploids)
|
||||
!!!dupe('?pop_size', ?x * ?y)!!!
|
||||
//Samples sizes (number of genes 2*diploids)
|
||||
!!!dupe('?sample_size', ?x * ?y)!!!
|
||||
//Growth rates : negative growth implies population expansion
|
||||
!!!dupe('0', ?x * ?y)!!!
|
||||
//Number of migration matrices : 0 implies no migration between demes
|
||||
2
|
||||
//mig
|
||||
!!!generate_ssm2d_mat(?x, ?y, ?mig)!!!
|
||||
//nothing
|
||||
!!!generate_null_mat(?x * ?y)!!!
|
||||
//historical event: time, source, sink, migrants, new deme size, new growth rate, migration matrix index
|
||||
!!!?x * ?y -1!!! historical events
|
||||
!!!generate_join_events(?t, ?x * ?y, ?ne, ?pop_size)!!!
|
@ -1,14 +0,0 @@
|
||||
//Parameters for the coalescence simulation program simcoal.
|
||||
?total_demes samples
|
||||
//Population effective sizes (number of genes 2*diploids)
|
||||
!!!dupe('?pop_size', ?total_demes)!!!
|
||||
//Samples sizes (number of genes 2*diploids)
|
||||
!!!dupe('?sample_size', ?total_demes)!!!
|
||||
//Growth rates : negative growth implies population expansion
|
||||
!!!dupe('0', ?total_demes)!!!
|
||||
//Number of migration matrices : 0 implies no migration between demes
|
||||
1
|
||||
//mig
|
||||
!!!generate_ssm2d_mat(?total_demes, 1, ?mig)!!!
|
||||
//historical event: time, source, sink, migrants, new deme size, new growth rate, migration matrix index
|
||||
0 historical events
|
@ -1,14 +0,0 @@
|
||||
//Parameters for the coalescence simulation program simcoal.
|
||||
!!!?x * ?y!!! samples
|
||||
//Population effective sizes (number of genes 2*diploids)
|
||||
!!!dupe('?pop_size', ?x * ?y)!!!
|
||||
//Samples sizes (number of genes 2*diploids)
|
||||
!!!dupe('?sample_size', ?x * ?y)!!!
|
||||
//Growth rates : negative growth implies population expansion
|
||||
!!!dupe('0', ?x * ?y)!!!
|
||||
//Number of migration matrices : 0 implies no migration between demes
|
||||
1
|
||||
//mig
|
||||
!!!generate_ssm2d_mat(?x, ?y, ?mig)!!!
|
||||
//historical event: time, source, sink, migrants, new deme size, new growth rate, migration matrix index
|
||||
0 historical events
|
@ -7,10 +7,3 @@ c3line.gen - 3 chars per allele, one locus name per line
|
||||
c2space.gen - 2 chars per allele, all loci in one line
|
||||
c3space.gen - 3 chars per allele, all loci in one line
|
||||
|
||||
|
||||
FDist
|
||||
-----
|
||||
fdist1 - marker input example
|
||||
data_fst_outfile - He and Fst pairs per locus
|
||||
out.dat - simulated dataset
|
||||
out.cpl - confidence interval contour
|
||||
|
@ -1,300 +0,0 @@
|
||||
0.436888 0.895615 0.909199 0
|
||||
0.153835 0.013321 0.158897 1
|
||||
0.436888 0.895615 0.909199 2
|
||||
0.445165 0.877152 0.894919 3
|
||||
0.428231 0.764552 0.798622 4
|
||||
0.428231 0.913775 0.923244 5
|
||||
0.034977 0.010452 0.039120 6
|
||||
0.139486 0.076696 0.151522 7
|
||||
0.445165 0.877152 0.894919 8
|
||||
0.428231 0.913775 0.923244 9
|
||||
0.436888 0.895615 0.909199 10
|
||||
0.095538 0.027104 0.101246 11
|
||||
0.445165 0.877152 0.894919 12
|
||||
0.428231 0.913775 0.923244 13
|
||||
0.480093 0.779693 0.819503 14
|
||||
0.453043 0.858370 0.880390 15
|
||||
0.436888 0.895615 0.909199 16
|
||||
0.445165 0.877152 0.894919 17
|
||||
0.324185 0.390388 0.445303 18
|
||||
0.445165 0.719886 0.777598 19
|
||||
0.400156 -0.013452 0.398984 20
|
||||
0.346274 0.151229 0.328664 21
|
||||
0.379840 0.053440 0.396405 22
|
||||
0.503811 0.040791 0.515075 23
|
||||
0.485604 -0.018853 0.481491 24
|
||||
0.453043 0.000680 0.455013 25
|
||||
0.494888 0.158666 0.543336 26
|
||||
0.153835 0.149937 0.176581 27
|
||||
0.505317 -0.021063 0.499876 28
|
||||
0.298509 -0.044880 0.293336 29
|
||||
0.381783 0.007672 0.374964 30
|
||||
0.312303 -0.012274 0.312567 31
|
||||
0.034977 0.010452 0.039120 32
|
||||
0.485604 -0.007553 0.484636 33
|
||||
0.034977 0.010452 0.039120 34
|
||||
0.445165 0.039750 0.458440 35
|
||||
0.050317 0.026458 0.055204 36
|
||||
0.501083 0.098300 0.522142 37
|
||||
0.300192 0.220032 0.357527 38
|
||||
0.195920 0.021859 0.202490 39
|
||||
0.467511 0.061669 0.487176 40
|
||||
0.223128 0.251267 0.275689 41
|
||||
0.501572 -0.006555 0.500307 42
|
||||
0.390149 -0.007590 0.390617 43
|
||||
0.485604 0.280951 0.578928 44
|
||||
0.346274 -0.024258 0.339252 45
|
||||
0.409395 0.042403 0.405182 46
|
||||
0.501083 -0.021814 0.495347 47
|
||||
0.347226 0.327797 0.448964 48
|
||||
0.182057 0.082348 0.197200 49
|
||||
0.381783 0.203197 0.370071 50
|
||||
0.195920 0.209138 0.234497 51
|
||||
0.505232 0.068046 0.523333 52
|
||||
0.505317 0.241305 0.567485 53
|
||||
0.501083 0.521010 0.618888 54
|
||||
0.494888 0.052887 0.510796 55
|
||||
0.312303 0.140343 0.348915 56
|
||||
0.494888 0.228421 0.566683 57
|
||||
0.463420 -0.028485 0.456497 58
|
||||
0.505232 0.624385 0.699158 59
|
||||
0.445165 0.076734 0.469536 60
|
||||
0.453043 0.414856 0.606977 61
|
||||
0.497036 0.275949 0.554063 62
|
||||
0.498579 -0.014805 0.495230 63
|
||||
0.491486 0.001006 0.489980 64
|
||||
0.474980 0.180237 0.498825 65
|
||||
0.346274 -0.024258 0.339252 66
|
||||
0.400156 0.576877 0.637009 67
|
||||
0.236462 0.067205 0.251707 68
|
||||
0.505763 0.008671 0.507797 69
|
||||
0.346274 0.151229 0.328664 70
|
||||
0.474980 0.180237 0.498825 71
|
||||
0.501083 0.037324 0.508367 72
|
||||
0.381783 0.203197 0.370071 73
|
||||
0.080601 0.059843 0.088226 74
|
||||
0.431379 0.291415 0.439663 75
|
||||
0.236462 0.067205 0.251707 76
|
||||
0.275314 0.079967 0.294898 77
|
||||
0.400156 0.368118 0.528193 78
|
||||
0.484222 0.027144 0.486787 79
|
||||
0.409849 0.072512 0.432437 80
|
||||
0.379840 0.240957 0.454700 81
|
||||
0.195920 0.021859 0.202490 82
|
||||
0.501083 0.037324 0.508367 83
|
||||
0.095538 0.077101 0.105196 84
|
||||
0.474980 0.070486 0.483014 85
|
||||
0.034977 0.010452 0.039120 86
|
||||
0.065526 0.042953 0.071567 87
|
||||
0.490548 -0.014683 0.487471 88
|
||||
0.501572 0.111629 0.533693 89
|
||||
0.346274 -0.024258 0.339252 90
|
||||
0.298509 0.090707 0.279728 91
|
||||
0.034977 0.010452 0.039120 92
|
||||
0.358368 0.091678 0.384734 93
|
||||
0.050317 -0.010690 0.053692 94
|
||||
0.298509 0.090707 0.279728 95
|
||||
0.050317 0.026458 0.055204 96
|
||||
0.034977 0.010452 0.039120 97
|
||||
0.498579 -0.014805 0.495230 98
|
||||
0.501083 -0.002258 0.499612 99
|
||||
0.124984 0.018599 0.130366 100
|
||||
0.503811 -0.014871 0.500208 101
|
||||
0.110333 0.042816 0.117679 102
|
||||
0.445165 0.011333 0.450242 103
|
||||
0.050317 0.026458 0.055204 104
|
||||
0.050317 0.026458 0.055204 105
|
||||
0.494888 0.017000 0.500493 106
|
||||
0.050317 0.026458 0.055204 107
|
||||
0.034977 0.010452 0.039120 108
|
||||
0.080601 0.059843 0.088226 109
|
||||
0.275314 0.227217 0.330897 110
|
||||
0.298509 0.090707 0.279728 111
|
||||
0.324185 0.215346 0.383460 112
|
||||
0.346274 -0.024258 0.339252 113
|
||||
0.381783 -0.035992 0.374966 114
|
||||
0.491486 0.049641 0.499289 115
|
||||
0.369242 0.328698 0.475505 116
|
||||
0.503796 0.012448 0.506014 117
|
||||
0.501572 -0.019829 0.496771 118
|
||||
0.474052 0.193253 0.536653 119
|
||||
0.262561 0.103759 0.286601 120
|
||||
0.050317 0.026458 0.055204 121
|
||||
0.236462 0.005307 0.240612 122
|
||||
0.298509 0.090707 0.279728 123
|
||||
0.034977 0.010452 0.039120 124
|
||||
0.463420 0.366377 0.498390 125
|
||||
0.262561 -0.011468 0.263573 126
|
||||
0.463420 0.146758 0.478162 127
|
||||
0.298509 0.090707 0.279728 128
|
||||
0.346274 -0.024258 0.339252 129
|
||||
0.236462 0.215037 0.282782 130
|
||||
0.034977 0.010452 0.039120 131
|
||||
0.065526 0.042953 0.071567 132
|
||||
0.262561 0.260485 0.325093 133
|
||||
0.080601 0.012515 0.085114 134
|
||||
0.249609 -0.004619 0.251978 135
|
||||
0.409395 0.042403 0.405182 136
|
||||
0.490548 0.071630 0.512367 137
|
||||
0.498579 0.380140 0.623573 138
|
||||
0.409395 0.249406 0.406607 139
|
||||
0.501572 0.352872 0.613049 140
|
||||
0.445165 0.076734 0.469536 141
|
||||
0.503796 0.012448 0.506014 142
|
||||
0.335829 0.001276 0.338907 143
|
||||
0.490548 0.071630 0.512367 144
|
||||
0.168027 -0.000494 0.171445 145
|
||||
0.050317 0.026458 0.055204 146
|
||||
0.335829 0.137437 0.373540 147
|
||||
0.505317 0.574398 0.660364 148
|
||||
0.449092 0.112513 0.455968 149
|
||||
0.501083 0.184302 0.542052 150
|
||||
0.505232 0.421443 0.631406 151
|
||||
0.347226 0.037913 0.359169 152
|
||||
0.505763 0.103411 0.532462 153
|
||||
0.453043 0.339369 0.573044 154
|
||||
0.168027 0.169189 0.195421 155
|
||||
0.153835 0.149937 0.176581 156
|
||||
0.390149 0.037187 0.402440 157
|
||||
0.400156 0.022884 0.408620 158
|
||||
0.262561 0.319439 0.342322 159
|
||||
0.034977 0.010452 0.039120 160
|
||||
0.381783 -0.035992 0.374966 161
|
||||
0.347226 0.268836 0.427381 162
|
||||
0.505232 0.068046 0.523333 163
|
||||
0.431379 0.077622 0.431844 164
|
||||
0.445165 0.613796 0.707527 165
|
||||
0.346274 0.151229 0.328664 166
|
||||
0.484222 0.212921 0.518236 167
|
||||
0.379840 0.091398 0.407016 168
|
||||
0.065526 0.042953 0.071567 169
|
||||
0.195920 -0.002279 0.198984 170
|
||||
0.505763 0.008671 0.507797 171
|
||||
0.249609 0.237380 0.303607 172
|
||||
0.480093 0.602560 0.721488 173
|
||||
0.236462 0.215037 0.282782 174
|
||||
0.381783 0.007672 0.374964 175
|
||||
0.346274 -0.024258 0.339252 176
|
||||
0.505232 0.421443 0.631406 177
|
||||
0.460499 0.563647 0.690256 178
|
||||
0.034977 0.010452 0.039120 179
|
||||
0.034977 0.010452 0.039120 180
|
||||
0.065526 0.042953 0.071567 181
|
||||
0.298509 0.090707 0.279728 182
|
||||
0.335829 0.092938 0.361489 183
|
||||
0.034977 0.010452 0.039120 184
|
||||
0.453043 0.000680 0.455013 185
|
||||
0.050317 0.026458 0.055204 186
|
||||
0.050317 0.026458 0.055204 187
|
||||
0.050317 0.026458 0.055204 188
|
||||
0.358368 0.053794 0.374576 189
|
||||
0.369242 0.212440 0.433081 190
|
||||
0.505763 0.008671 0.507797 191
|
||||
0.453043 0.000680 0.455013 192
|
||||
0.467511 0.105686 0.500903 193
|
||||
0.436888 0.468860 0.617366 194
|
||||
0.223128 0.251267 0.275689 195
|
||||
0.381783 -0.035992 0.374966 196
|
||||
0.065526 -0.015542 0.068502 197
|
||||
0.034977 0.010452 0.039120 198
|
||||
0.050317 -0.010690 0.053692 199
|
||||
0.275314 0.079967 0.294898 200
|
||||
0.480093 0.001836 0.481908 201
|
||||
0.409395 0.042403 0.405182 202
|
||||
0.335829 -0.012609 0.335725 203
|
||||
0.369242 0.112849 0.402114 204
|
||||
0.249609 0.046362 0.261362 205
|
||||
0.249609 0.016166 0.255722 206
|
||||
0.080601 0.012515 0.085114 207
|
||||
0.505763 0.269544 0.579467 208
|
||||
0.503811 0.325345 0.602211 209
|
||||
0.498579 0.079170 0.521767 210
|
||||
0.065526 -0.015542 0.068502 211
|
||||
0.346274 -0.024258 0.339252 212
|
||||
0.287860 -0.011898 0.288496 213
|
||||
0.080601 0.012515 0.085114 214
|
||||
0.409849 0.339897 0.527031 215
|
||||
0.034977 0.010452 0.039120 216
|
||||
0.453043 0.697094 0.766804 217
|
||||
0.484222 0.098556 0.499086 218
|
||||
0.409395 0.042403 0.405182 219
|
||||
0.409395 0.042403 0.405182 220
|
||||
0.300192 0.076385 0.320099 221
|
||||
0.195920 -0.014640 0.197234 222
|
||||
0.400156 0.304374 0.501455 223
|
||||
0.080601 -0.012426 0.083561 224
|
||||
0.249609 0.237380 0.303607 225
|
||||
0.346274 -0.024258 0.339252 226
|
||||
0.275314 0.227217 0.330897 227
|
||||
0.358368 -0.012912 0.357902 228
|
||||
0.379840 0.240957 0.454700 229
|
||||
0.034977 0.010452 0.039120 230
|
||||
0.369242 0.268921 0.452753 231
|
||||
0.505763 0.008671 0.507797 232
|
||||
0.124984 -0.007056 0.127932 233
|
||||
0.428231 0.662998 0.724170 234
|
||||
0.505232 0.023819 0.511519 235
|
||||
0.124984 0.059394 0.134432 236
|
||||
0.080601 -0.012426 0.083561 237
|
||||
0.409395 -0.025633 0.402744 238
|
||||
0.369242 0.268921 0.452753 239
|
||||
0.400156 0.434886 0.559145 240
|
||||
0.505763 0.269544 0.579467 241
|
||||
0.484222 0.212921 0.518236 242
|
||||
0.262561 0.260485 0.325093 243
|
||||
0.491486 0.244816 0.536597 244
|
||||
0.390149 0.396783 0.529334 245
|
||||
0.503811 0.325345 0.602211 246
|
||||
0.236462 0.215037 0.282782 247
|
||||
0.050317 0.026458 0.055204 248
|
||||
0.494888 0.310317 0.596120 249
|
||||
0.494888 -0.007158 0.493757 250
|
||||
0.050317 -0.010690 0.053692 251
|
||||
0.153835 0.094645 0.168973 252
|
||||
0.312303 0.025074 0.320758 253
|
||||
0.491486 0.049641 0.499289 254
|
||||
0.139486 0.032850 0.146562 255
|
||||
0.390149 0.214024 0.456685 256
|
||||
0.110333 0.042816 0.117679 257
|
||||
0.428231 0.167577 0.481509 258
|
||||
0.182057 0.132348 0.205052 259
|
||||
0.491486 0.001006 0.489980 260
|
||||
0.298509 0.090707 0.279728 261
|
||||
0.369242 0.160108 0.416260 262
|
||||
0.298509 -0.044880 0.293336 263
|
||||
0.491486 0.001006 0.489980 264
|
||||
0.209612 -0.016283 0.210501 265
|
||||
0.110333 0.005901 0.114478 266
|
||||
0.034977 -0.015415 0.038374 267
|
||||
0.065526 0.042953 0.071567 268
|
||||
0.369242 0.071611 0.390506 269
|
||||
0.110333 0.094727 0.122495 270
|
||||
0.428231 0.350897 0.552115 271
|
||||
0.409395 0.249406 0.406607 272
|
||||
0.298509 0.090707 0.279728 273
|
||||
0.347226 0.160803 0.392607 274
|
||||
0.453043 0.100348 0.484820 275
|
||||
0.501083 0.184302 0.542052 276
|
||||
0.324185 0.163110 0.368104 277
|
||||
0.236462 0.160325 0.270439 278
|
||||
0.312303 0.001918 0.315631 279
|
||||
0.209612 0.035579 0.218518 280
|
||||
0.312303 0.140343 0.348915 281
|
||||
0.034977 0.010452 0.039120 282
|
||||
0.494888 -0.019315 0.490426 283
|
||||
0.275314 0.014338 0.281222 284
|
||||
0.324185 0.452016 0.471856 285
|
||||
0.110333 0.042816 0.117679 286
|
||||
0.287860 0.309265 0.370331 287
|
||||
0.195920 0.152086 0.223735 288
|
||||
0.428231 -0.017374 0.425588 289
|
||||
0.445165 0.296565 0.547190 290
|
||||
0.065526 0.042953 0.071567 291
|
||||
0.287860 0.002767 0.291450 292
|
||||
0.312303 0.190641 0.362768 293
|
||||
0.262561 0.103759 0.286601 294
|
||||
0.449092 -0.024747 0.442633 295
|
||||
0.346274 -0.024258 0.339252 296
|
||||
0.139486 0.002038 0.143265 297
|
||||
0.034977 0.010452 0.039120 298
|
||||
0.275314 0.014338 0.281222 299
|
@ -1,4 +0,0 @@
|
||||
0.555556 0.380952
|
||||
0.750000 0.541126
|
||||
0.750000 0.144014
|
||||
0.666667 0.722222
|
1204
Tests/PopGen/dfdist1
1204
Tests/PopGen/dfdist1
File diff suppressed because it is too large
Load Diff
@ -1,300 +0,0 @@
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 -0.015415 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.034977 0.010452 -0.015415 0.010452 0.026458
|
||||
0.050317 0.026458 -0.015542 0.026458 0.042953
|
||||
0.050317 -0.010690 -0.015542 0.026458 0.042953
|
||||
0.050317 0.026458 -0.015542 0.026458 0.042953
|
||||
0.050317 0.026458 -0.015542 0.026458 0.042953
|
||||
0.050317 0.026458 -0.015542 0.026458 0.042953
|
||||
0.050317 0.026458 -0.015542 0.026458 0.042953
|
||||
0.050317 0.026458 -0.015542 0.026458 0.042953
|
||||
0.050317 0.026458 -0.015542 0.026458 0.042953
|
||||
0.050317 0.026458 -0.015542 0.026458 0.042953
|
||||
0.050317 0.026458 -0.015542 0.026458 0.042953
|
||||
0.050317 0.026458 -0.015542 0.026458 0.042953
|
||||
0.050317 0.026458 -0.015542 0.026458 0.042953
|
||||
0.050317 -0.010690 -0.015542 0.026458 0.042953
|
||||
0.050317 -0.010690 -0.015542 0.026458 0.042953
|
||||
0.065526 0.042953 -0.015542 0.042953 0.059843
|
||||
0.065526 0.042953 -0.015542 0.042953 0.059843
|
||||
0.065526 0.042953 -0.015542 0.042953 0.059843
|
||||
0.065526 0.042953 -0.015542 0.042953 0.059843
|
||||
0.065526 0.042953 -0.015542 0.042953 0.059843
|
||||
0.065526 -0.015542 -0.015542 0.042953 0.059843
|
||||
0.065526 -0.015542 -0.015542 0.042953 0.059843
|
||||
0.065526 0.042953 -0.015542 0.042953 0.059843
|
||||
0.080601 0.059843 -0.015675 0.027104 0.077101
|
||||
0.080601 0.012515 -0.015675 0.027104 0.077101
|
||||
0.080601 -0.012426 -0.015675 0.027104 0.077101
|
||||
0.080601 0.012515 -0.015675 0.027104 0.077101
|
||||
0.080601 -0.012426 -0.015675 0.027104 0.077101
|
||||
0.080601 0.059843 -0.015675 0.027104 0.077101
|
||||
0.080601 0.012515 -0.015675 0.027104 0.077101
|
||||
0.095538 0.077101 -0.015675 0.027104 0.094727
|
||||
0.095538 0.027104 -0.015675 0.027104 0.094727
|
||||
0.110333 0.042816 -0.015815 0.018599 0.112730
|
||||
0.110333 0.042816 -0.015815 0.018599 0.112730
|
||||
0.110333 0.094727 -0.015815 0.018599 0.112730
|
||||
0.110333 0.042816 -0.015815 0.018599 0.112730
|
||||
0.110333 0.005901 -0.015815 0.018599 0.112730
|
||||
0.124984 0.059394 -0.015962 0.018599 0.149937
|
||||
0.124984 0.018599 -0.015962 0.018599 0.149937
|
||||
0.124984 -0.007056 -0.015962 0.018599 0.149937
|
||||
0.139486 0.076696 -0.015962 0.026365 0.169189
|
||||
0.139486 0.002038 -0.015962 0.026365 0.169189
|
||||
0.139486 0.032850 -0.015962 0.026365 0.169189
|
||||
0.153835 0.094645 -0.016118 0.026365 0.188912
|
||||
0.153835 0.013321 -0.016118 0.026365 0.188912
|
||||
0.153835 0.149937 -0.016118 0.026365 0.188912
|
||||
0.153835 0.149937 -0.016118 0.026365 0.188912
|
||||
0.168027 -0.000494 -0.016118 0.026365 0.209138
|
||||
0.168027 0.169189 -0.016118 0.026365 0.209138
|
||||
0.182057 0.082348 -0.016283 0.021859 0.229908
|
||||
0.182057 0.132348 -0.016283 0.021859 0.229908
|
||||
0.195920 0.021859 -0.016283 0.021859 0.251267
|
||||
0.195920 0.209138 -0.016283 0.021859 0.251267
|
||||
0.195920 -0.002279 -0.016283 0.021859 0.251267
|
||||
0.195920 0.152086 -0.016283 0.021859 0.251267
|
||||
0.195920 0.021859 -0.016283 0.021859 0.251267
|
||||
0.195920 -0.014640 -0.016283 0.021859 0.251267
|
||||
0.209612 0.035579 -0.016283 0.015847 0.251267
|
||||
0.209612 -0.016283 -0.016283 0.015847 0.251267
|
||||
0.223128 0.251267 -0.016283 0.015847 0.251267
|
||||
0.223128 0.251267 -0.016283 0.015847 0.251267
|
||||
0.236462 0.215037 -0.016645 0.015847 0.295967
|
||||
0.236462 0.215037 -0.016645 0.015847 0.295967
|
||||
0.236462 0.160325 -0.016645 0.015847 0.295967
|
||||
0.236462 0.215037 -0.016645 0.015847 0.295967
|
||||
0.236462 0.067205 -0.016645 0.015847 0.295967
|
||||
0.236462 0.067205 -0.016645 0.015847 0.295967
|
||||
0.236462 0.005307 -0.016645 0.015847 0.295967
|
||||
0.249609 0.016166 -0.016645 0.016166 0.295967
|
||||
0.249609 -0.004619 -0.016645 0.016166 0.295967
|
||||
0.249609 0.046362 -0.016645 0.016166 0.295967
|
||||
0.249609 0.237380 -0.016645 0.016166 0.295967
|
||||
0.249609 0.237380 -0.016645 0.016166 0.295967
|
||||
0.262561 0.260485 -0.044880 0.016166 0.309265
|
||||
0.262561 0.260485 -0.044880 0.016166 0.309265
|
||||
0.262561 0.103759 -0.044880 0.016166 0.309265
|
||||
0.262561 0.103759 -0.044880 0.016166 0.309265
|
||||
0.262561 0.319439 -0.044880 0.016166 0.309265
|
||||
0.262561 -0.011468 -0.044880 0.016166 0.309265
|
||||
0.275314 0.014338 -0.044880 0.028810 0.309265
|
||||
0.275314 0.227217 -0.044880 0.028810 0.309265
|
||||
0.275314 0.227217 -0.044880 0.028810 0.309265
|
||||
0.275314 0.079967 -0.044880 0.028810 0.309265
|
||||
0.275314 0.014338 -0.044880 0.028810 0.309265
|
||||
0.275314 0.079967 -0.044880 0.028810 0.309265
|
||||
0.287860 -0.011898 -0.044880 0.058993 0.309265
|
||||
0.287860 0.309265 -0.044880 0.058993 0.309265
|
||||
0.287860 0.002767 -0.044880 0.058993 0.309265
|
||||
0.298509 0.090707 -0.044880 0.076385 0.302521
|
||||
0.298509 -0.044880 -0.044880 0.076385 0.302521
|
||||
0.298509 0.090707 -0.044880 0.076385 0.302521
|
||||
0.298509 0.090707 -0.044880 0.076385 0.302521
|
||||
0.298509 0.090707 -0.044880 0.076385 0.302521
|
||||
0.298509 0.090707 -0.044880 0.076385 0.302521
|
||||
0.298509 0.090707 -0.044880 0.076385 0.302521
|
||||
0.298509 0.090707 -0.044880 0.076385 0.302521
|
||||
0.298509 -0.044880 -0.044880 0.076385 0.302521
|
||||
0.298509 0.090707 -0.044880 0.076385 0.302521
|
||||
0.300192 0.076385 -0.044880 0.040728 0.358643
|
||||
0.300192 0.220032 -0.044880 0.040728 0.358643
|
||||
0.312303 0.025074 -0.044880 0.023958 0.358643
|
||||
0.312303 0.140343 -0.044880 0.023958 0.358643
|
||||
0.312303 -0.012274 -0.044880 0.023958 0.358643
|
||||
0.312303 0.190641 -0.044880 0.023958 0.358643
|
||||
0.312303 0.140343 -0.044880 0.023958 0.358643
|
||||
0.312303 0.001918 -0.044880 0.023958 0.358643
|
||||
0.324185 0.215346 -0.024258 0.023958 0.358643
|
||||
0.324185 0.452016 -0.024258 0.023958 0.358643
|
||||
0.324185 0.390388 -0.024258 0.023958 0.358643
|
||||
0.324185 0.163110 -0.024258 0.023958 0.358643
|
||||
0.335829 0.137437 -0.024258 0.023958 0.358643
|
||||
0.335829 0.092938 -0.024258 0.023958 0.358643
|
||||
0.335829 0.001276 -0.024258 0.023958 0.358643
|
||||
0.335829 -0.012609 -0.024258 0.023958 0.358643
|
||||
0.346274 -0.024258 -0.024258 0.011228 0.358456
|
||||
0.346274 -0.024258 -0.024258 0.011228 0.358456
|
||||
0.346274 -0.024258 -0.024258 0.011228 0.358456
|
||||
0.346274 -0.024258 -0.024258 0.011228 0.358456
|
||||
0.346274 -0.024258 -0.024258 0.011228 0.358456
|
||||
0.346274 0.151229 -0.024258 0.011228 0.358456
|
||||
0.346274 -0.024258 -0.024258 0.011228 0.358456
|
||||
0.346274 0.151229 -0.024258 0.011228 0.358456
|
||||
0.346274 -0.024258 -0.024258 0.011228 0.358456
|
||||
0.346274 0.151229 -0.024258 0.011228 0.358456
|
||||
0.346274 -0.024258 -0.024258 0.011228 0.358456
|
||||
0.346274 -0.024258 -0.024258 0.011228 0.358456
|
||||
0.347226 0.327797 -0.024258 0.011228 0.358456
|
||||
0.347226 0.268836 -0.024258 0.011228 0.358456
|
||||
0.347226 0.160803 -0.024258 0.011228 0.358456
|
||||
0.347226 0.037913 -0.024258 0.011228 0.358456
|
||||
0.358368 -0.012912 -0.035992 0.011228 0.358456
|
||||
0.358368 0.053794 -0.035992 0.011228 0.358456
|
||||
0.358368 0.091678 -0.035992 0.011228 0.358456
|
||||
0.369242 0.268921 -0.035992 0.010770 0.358456
|
||||
0.369242 0.328698 -0.035992 0.010770 0.358456
|
||||
0.369242 0.268921 -0.035992 0.010770 0.358456
|
||||
0.369242 0.112849 -0.035992 0.010770 0.358456
|
||||
0.369242 0.212440 -0.035992 0.010770 0.358456
|
||||
0.369242 0.071611 -0.035992 0.010770 0.358456
|
||||
0.369242 0.160108 -0.035992 0.010770 0.358456
|
||||
0.379840 0.240957 -0.035992 0.007672 0.328698
|
||||
0.379840 0.053440 -0.035992 0.007672 0.328698
|
||||
0.379840 0.091398 -0.035992 0.007672 0.328698
|
||||
0.379840 0.240957 -0.035992 0.007672 0.328698
|
||||
0.381783 0.007672 -0.035992 0.007672 0.368118
|
||||
0.381783 -0.035992 -0.035992 0.007672 0.368118
|
||||
0.381783 0.203197 -0.035992 0.007672 0.368118
|
||||
0.381783 -0.035992 -0.035992 0.007672 0.368118
|
||||
0.381783 0.007672 -0.035992 0.007672 0.368118
|
||||
0.381783 -0.035992 -0.035992 0.007672 0.368118
|
||||
0.381783 0.203197 -0.035992 0.007672 0.368118
|
||||
0.390149 0.396783 -0.035992 0.010552 0.368118
|
||||
0.390149 -0.007590 -0.035992 0.010552 0.368118
|
||||
0.390149 0.037187 -0.035992 0.010552 0.368118
|
||||
0.390149 0.214024 -0.035992 0.010552 0.368118
|
||||
0.400156 0.434886 -0.035992 0.037187 0.368118
|
||||
0.400156 0.304374 -0.035992 0.037187 0.368118
|
||||
0.400156 -0.013452 -0.035992 0.037187 0.368118
|
||||
0.400156 0.022884 -0.035992 0.037187 0.368118
|
||||
0.400156 0.368118 -0.035992 0.037187 0.368118
|
||||
0.400156 0.576877 -0.035992 0.037187 0.368118
|
||||
0.409395 -0.025633 -0.025633 0.037537 0.350897
|
||||
0.409395 0.042403 -0.025633 0.037537 0.350897
|
||||
0.409395 0.042403 -0.025633 0.037537 0.350897
|
||||
0.409395 0.042403 -0.025633 0.037537 0.350897
|
||||
0.409395 0.042403 -0.025633 0.037537 0.350897
|
||||
0.409395 0.249406 -0.025633 0.037537 0.350897
|
||||
0.409395 0.042403 -0.025633 0.037537 0.350897
|
||||
0.409395 0.249406 -0.025633 0.037537 0.350897
|
||||
0.409849 0.339897 -0.031395 0.023223 0.350897
|
||||
0.409849 0.072512 -0.031395 0.023223 0.350897
|
||||
0.428231 0.662998 -0.031395 0.010567 0.350897
|
||||
0.428231 0.913775 -0.031395 0.010567 0.350897
|
||||
0.428231 0.913775 -0.031395 0.010567 0.350897
|
||||
0.428231 0.913775 -0.031395 0.010567 0.350897
|
||||
0.428231 -0.017374 -0.031395 0.010567 0.350897
|
||||
0.428231 0.764552 -0.031395 0.010567 0.350897
|
||||
0.428231 0.350897 -0.031395 0.010567 0.350897
|
||||
0.428231 0.167577 -0.031395 0.010567 0.350897
|
||||
0.431379 0.077622 -0.031395 0.011333 0.330190
|
||||
0.431379 0.291415 -0.031395 0.011333 0.330190
|
||||
0.436888 0.895615 -0.031395 0.017188 0.330190
|
||||
0.436888 0.895615 -0.031395 0.017188 0.330190
|
||||
0.436888 0.468860 -0.031395 0.017188 0.330190
|
||||
0.436888 0.895615 -0.031395 0.017188 0.330190
|
||||
0.436888 0.895615 -0.031395 0.017188 0.330190
|
||||
0.445165 0.076734 -0.031395 0.017188 0.393735
|
||||
0.445165 0.877152 -0.031395 0.017188 0.393735
|
||||
0.445165 0.011333 -0.031395 0.017188 0.393735
|
||||
0.445165 0.613796 -0.031395 0.017188 0.393735
|
||||
0.445165 0.719886 -0.031395 0.017188 0.393735
|
||||
0.445165 0.877152 -0.031395 0.017188 0.393735
|
||||
0.445165 0.877152 -0.031395 0.017188 0.393735
|
||||
0.445165 0.039750 -0.031395 0.017188 0.393735
|
||||
0.445165 0.296565 -0.031395 0.017188 0.393735
|
||||
0.445165 0.076734 -0.031395 0.017188 0.393735
|
||||
0.445165 0.877152 -0.031395 0.017188 0.393735
|
||||
0.449092 0.112513 -0.028485 0.017188 0.387906
|
||||
0.449092 -0.024747 -0.028485 0.017188 0.387906
|
||||
0.453043 0.414856 -0.028485 0.017188 0.366377
|
||||
0.453043 0.697094 -0.028485 0.017188 0.366377
|
||||
0.453043 0.000680 -0.028485 0.017188 0.366377
|
||||
0.453043 0.000680 -0.028485 0.017188 0.366377
|
||||
0.453043 0.000680 -0.028485 0.017188 0.366377
|
||||
0.453043 0.339369 -0.028485 0.017188 0.366377
|
||||
0.453043 0.100348 -0.028485 0.017188 0.366377
|
||||
0.453043 0.858370 -0.028485 0.017188 0.366377
|
||||
0.460499 0.563647 -0.028485 0.017188 0.387906
|
||||
0.463420 0.366377 -0.028485 0.013287 0.414856
|
||||
0.463420 -0.028485 -0.028485 0.013287 0.414856
|
||||
0.463420 0.146758 -0.028485 0.013287 0.414856
|
||||
0.467511 0.105686 -0.028485 0.013287 0.400433
|
||||
0.467511 0.061669 -0.028485 0.013287 0.400433
|
||||
0.474052 0.193253 -0.028485 0.013287 0.417641
|
||||
0.474980 0.070486 -0.026435 0.013287 0.432693
|
||||
0.474980 0.180237 -0.026435 0.013287 0.432693
|
||||
0.474980 0.180237 -0.026435 0.013287 0.432693
|
||||
0.480093 0.779693 -0.026435 0.014866 0.432693
|
||||
0.480093 0.001836 -0.026435 0.014866 0.432693
|
||||
0.480093 0.602560 -0.026435 0.014866 0.432693
|
||||
0.484222 0.212921 -0.026435 0.014866 0.463416
|
||||
0.484222 0.098556 -0.026435 0.014866 0.463416
|
||||
0.484222 0.212921 -0.026435 0.014866 0.463416
|
||||
0.484222 0.027144 -0.026435 0.014866 0.463416
|
||||
0.485604 -0.018853 -0.026435 0.014866 0.463416
|
||||
0.485604 0.280951 -0.026435 0.014866 0.463416
|
||||
0.485604 -0.007553 -0.026435 0.014866 0.463416
|
||||
0.490548 -0.014683 -0.026435 0.017000 0.463416
|
||||
0.490548 0.071630 -0.026435 0.017000 0.463416
|
||||
0.490548 0.071630 -0.026435 0.017000 0.463416
|
||||
0.491486 0.049641 -0.024891 0.017000 0.492801
|
||||
0.491486 0.244816 -0.024891 0.017000 0.492801
|
||||
0.491486 0.049641 -0.024891 0.017000 0.492801
|
||||
0.491486 0.001006 -0.024891 0.017000 0.492801
|
||||
0.491486 0.001006 -0.024891 0.017000 0.492801
|
||||
0.491486 0.001006 -0.024891 0.017000 0.492801
|
||||
0.494888 -0.007158 -0.024891 0.017000 0.501840
|
||||
0.494888 0.310317 -0.024891 0.017000 0.501840
|
||||
0.494888 0.228421 -0.024891 0.017000 0.501840
|
||||
0.494888 0.052887 -0.024891 0.017000 0.501840
|
||||
0.494888 0.158666 -0.024891 0.017000 0.501840
|
||||
0.494888 0.017000 -0.024891 0.017000 0.501840
|
||||
0.494888 -0.019315 -0.024891 0.017000 0.501840
|
||||
0.497036 0.275949 -0.024891 0.017000 0.521010
|
||||
0.498579 0.079170 -0.024891 0.018106 0.521010
|
||||
0.498579 -0.014805 -0.024891 0.018106 0.521010
|
||||
0.498579 0.380140 -0.024891 0.018106 0.521010
|
||||
0.498579 -0.014805 -0.024891 0.018106 0.521010
|
||||
0.501083 0.521010 -0.024891 0.012448 0.521010
|
||||
0.501083 -0.002258 -0.024891 0.012448 0.521010
|
||||
0.501083 -0.021814 -0.024891 0.012448 0.521010
|
||||
0.501083 0.037324 -0.024891 0.012448 0.521010
|
||||
0.501083 0.098300 -0.024891 0.012448 0.521010
|
||||
0.501083 0.184302 -0.024891 0.012448 0.521010
|
||||
0.501083 0.037324 -0.024891 0.012448 0.521010
|
||||
0.501083 0.184302 -0.024891 0.012448 0.521010
|
||||
0.501572 -0.019829 -0.023674 0.012448 0.521010
|
||||
0.501572 0.111629 -0.023674 0.012448 0.521010
|
||||
0.501572 -0.006555 -0.023674 0.012448 0.521010
|
||||
0.501572 0.352872 -0.023674 0.012448 0.521010
|
||||
0.503796 0.012448 -0.023674 0.012448 0.475544
|
||||
0.503796 0.012448 -0.023674 0.012448 0.475544
|
||||
0.503811 0.325345 -0.023674 0.012448 0.448754
|
||||
0.503811 0.325345 -0.023674 0.012448 0.448754
|
||||
0.503811 -0.014871 -0.023674 0.012448 0.448754
|
||||
0.503811 0.040791 -0.023674 0.012448 0.448754
|
||||
0.505232 0.624385 -0.023674 0.012448 0.448754
|
||||
0.505232 0.023819 -0.023674 0.012448 0.448754
|
||||
0.505232 0.068046 -0.023674 0.012448 0.448754
|
||||
0.505232 0.421443 -0.023674 0.012448 0.448754
|
||||
0.505232 0.068046 -0.023674 0.012448 0.448754
|
||||
0.505232 0.421443 -0.023674 0.012448 0.448754
|
||||
0.505317 -0.021063 -0.023674 0.012448 0.448754
|
||||
0.505317 0.241305 -0.023674 0.012448 0.448754
|
||||
0.505317 0.574398 -0.023674 0.012448 0.448754
|
||||
0.505763 0.269544 -0.023674 0.012448 0.448754
|
||||
0.505763 0.008671 -0.023674 0.012448 0.448754
|
||||
0.505763 0.269544 -0.023674 0.012448 0.448754
|
||||
0.505763 0.008671 -0.023674 0.012448 0.448754
|
||||
0.505763 0.008671 -0.023674 0.012448 0.448754
|
||||
0.505763 0.103411 -0.023674 0.012448 0.448754
|
||||
0.505763 0.008671 -0.023674 0.012448 0.448754
|
50000
Tests/PopGen/dout.dat
50000
Tests/PopGen/dout.dat
File diff suppressed because it is too large
Load Diff
@ -1,24 +0,0 @@
|
||||
0
|
||||
3
|
||||
4
|
||||
|
||||
2
|
||||
5 10
|
||||
20 0
|
||||
5 5
|
||||
|
||||
3
|
||||
0 0 10
|
||||
5 5 5
|
||||
10 1 1
|
||||
|
||||
4
|
||||
0 0 0 0
|
||||
5 5 5 5
|
||||
9 0 5 0
|
||||
|
||||
2
|
||||
0 9
|
||||
9 0
|
||||
5 5
|
||||
|
@ -1,18 +0,0 @@
|
||||
//Parameters for the coalescence simulation program : simcoal.exe
|
||||
1 samples
|
||||
//Population effective sizes (number of genes 2*diploids)
|
||||
100
|
||||
//Samples sizes (number of genes 2*diploids)
|
||||
30
|
||||
//Growth rates : negative growth implies population expansion
|
||||
0
|
||||
//Number of migration matrices : 0 implies no migration between demes
|
||||
0
|
||||
//historical event: time, source, sink, migrants, new deme size, new growth rate, migration matrix index
|
||||
0 historical events
|
||||
//Number of independent (unlinked) chromosomes, and "chromosome structure" flag: 0 for identical structure across chromosomes, and 1 for different structures on different chromosomes.
|
||||
1 1
|
||||
//Number of contiguous linkage blocks in chromosome
|
||||
1
|
||||
//Per Block: Data type, No. of loci, Recombination rate to the right-side locus, plus optional parameters
|
||||
SNP 24 0.0005 0.0
|
@ -1,131 +0,0 @@
|
||||
# Copyright 2010 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.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
from Bio import MissingExternalDependencyError
|
||||
from Bio import BiopythonDeprecationWarning
|
||||
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", BiopythonDeprecationWarning)
|
||||
from Bio.PopGen import FDist
|
||||
from Bio.PopGen.FDist import Controller
|
||||
|
||||
# Tests DFDist related code. Note: this case requires Dfdist (four binaries)
|
||||
# test_PopGen_FDist_nodepend tests code that does not require fdist2 or Dfdist
|
||||
|
||||
|
||||
def is_pypy():
|
||||
import platform
|
||||
try:
|
||||
if platform.python_implementation() == 'PyPy':
|
||||
return True
|
||||
except AttributeError:
|
||||
# New in Python 2.6, not in Jython yet either
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
wanted = dict()
|
||||
for path in os.environ['PATH'].split(os.pathsep):
|
||||
try:
|
||||
list = os.listdir(path)
|
||||
for file in os.listdir(path):
|
||||
for f in ['Dfdist', 'Ddatacal', 'pv2', 'cplot2']:
|
||||
if file == f or file.lower() == f.lower() + ".exe":
|
||||
wanted[f] = file
|
||||
except os.error:
|
||||
pass # Path doesn't exist - correct to pass
|
||||
if len(wanted) != 4:
|
||||
raise MissingExternalDependencyError(
|
||||
"Install Dfdist, Ddatacal, pv2 and cplot2 if you want to use DFDist with Bio.PopGen.FDist.")
|
||||
del wanted
|
||||
|
||||
import sys
|
||||
if not is_pypy() and sys.version_info[0] == 3 and sys.version_info < (3, 2, 4):
|
||||
raise MissingExternalDependencyError("Under Python 3, please use Python 3.2.4"
|
||||
" onwards for this test - see http://bugs.python.org/issue16903")
|
||||
|
||||
|
||||
class AppTest(unittest.TestCase):
|
||||
"""Tests the Dfdist 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_dfst_outfile', 'data_fst_outfile')
|
||||
self._copyfile('dfdist1', 'infile')
|
||||
self._copyfile('dout.dat', 'out.dat')
|
||||
self._copyfile('dout.cpl', 'out.cpl')
|
||||
|
||||
def tearDown(self):
|
||||
# Not sure how exactly, but its possible the temp directory
|
||||
# may not (still) exist.
|
||||
if os.path.isdir(self.dirname):
|
||||
for file in os.listdir(self.dirname):
|
||||
os.remove(self.dirname + os.sep + file)
|
||||
os.rmdir(self.dirname)
|
||||
|
||||
def test_ddatacal(self):
|
||||
"""Test Ddatacal execution."""
|
||||
fst, samp_size, loci, pops, F, obs = \
|
||||
self.ctrl.run_datacal(data_dir=self.dirname, version=2)
|
||||
self.assertTrue(fst - 0.23 < 0.02)
|
||||
self.assertEqual(samp_size, 32)
|
||||
self.assertEqual(loci, 300)
|
||||
self.assertEqual(pops, 2)
|
||||
self.assertTrue(F - 0.11 < 0.01)
|
||||
self.assertEqual(obs, 300)
|
||||
|
||||
def test_dfdist(self):
|
||||
"""Test Dfdist execution."""
|
||||
# The number of simulations in real life should be at least 10000,
|
||||
# see the fdist2 documentation.
|
||||
fst = self.ctrl.run_fdist(npops=15, nsamples=10, fst=0.1,
|
||||
sample_size=20, mut=0, num_sims=100,
|
||||
data_dir=self.dirname, is_dominant=True)
|
||||
self.assertTrue(abs(fst - 0.1) < 0.03,
|
||||
"Stochastic result, expected %f close to 0.1" % fst)
|
||||
|
||||
def atest_dfdist_force_fst(self):
|
||||
"""Test dfdist execution approximating Fst.
|
||||
|
||||
THIS IS TOO SLOW
|
||||
"""
|
||||
# The number of simulations in real life should be at least 10000,
|
||||
# see the fdist2 documentation.
|
||||
fst = self.ctrl.run_fdist_force_fst(npops=15, nsamples=10,
|
||||
fst=0.1,
|
||||
sample_size=20, mut=0, num_sims=100,
|
||||
data_dir=self.dirname, is_dominant=True)
|
||||
self.assertTrue(abs(fst - 0.09) < 0.05,
|
||||
"Stochastic result, expected %f close to 0.09" % fst)
|
||||
|
||||
def test_cplot2(self):
|
||||
"""Test cplot2 execution."""
|
||||
cpl_interval = self.ctrl.run_cplot(data_dir=self.dirname, version=2)
|
||||
self.assertEqual(len(cpl_interval), 300)
|
||||
|
||||
def test_pv2(self):
|
||||
"""Test pv2 execution."""
|
||||
pv_data = self.ctrl.run_pv(data_dir=self.dirname, version=2)
|
||||
self.assertEqual(len(pv_data), 300)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Running fdist tests, which might take some time, please wait")
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
unittest.main(testRunner=runner)
|
@ -1,129 +0,0 @@
|
||||
# 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.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
from Bio import MissingExternalDependencyError
|
||||
from Bio import BiopythonDeprecationWarning
|
||||
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", BiopythonDeprecationWarning)
|
||||
from Bio.PopGen import FDist
|
||||
from Bio.PopGen.FDist import Controller
|
||||
|
||||
|
||||
# Tests FDist2 related code. Note: this case requires fdist2 (four binaries)
|
||||
# test_PopGen_FDist_nodepend tests code that does not require fdist2 or Dfdist
|
||||
|
||||
|
||||
def is_pypy():
|
||||
import platform
|
||||
try:
|
||||
if platform.python_implementation() == 'PyPy':
|
||||
return True
|
||||
except AttributeError:
|
||||
# New in Python 2.6, not in Jython yet either
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
wanted = dict()
|
||||
for path in os.environ['PATH'].split(os.pathsep):
|
||||
try:
|
||||
list = os.listdir(path)
|
||||
for file in os.listdir(path):
|
||||
for f in ['fdist2', 'datacal', 'pv', 'cplot']:
|
||||
if file == f or file.lower() == f.lower() + ".exe":
|
||||
wanted[f] = file
|
||||
except os.error:
|
||||
pass # Path doesn't exist - correct to pass
|
||||
if len(wanted) != 4:
|
||||
raise MissingExternalDependencyError(
|
||||
"Install fdist2, datacal, pv and cplot if you want to use FDist2 with Bio.PopGen.FDist.")
|
||||
del wanted
|
||||
|
||||
import sys
|
||||
if not is_pypy() and sys.version_info[0] == 3 and sys.version_info < (3, 2, 4):
|
||||
raise MissingExternalDependencyError("Under Python 3, please use Python 3.2.4"
|
||||
" onwards for this test - see http://bugs.python.org/issue16903")
|
||||
|
||||
|
||||
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):
|
||||
# Not sure how exactly, but its possible the temp directory
|
||||
# may not (still) exist.
|
||||
if os.path.isdir(self.dirname):
|
||||
for file in os.listdir(self.dirname):
|
||||
os.remove(self.dirname + os.sep + file)
|
||||
os.rmdir(self.dirname)
|
||||
|
||||
def test_datacal(self):
|
||||
"""Test datacal execution.
|
||||
"""
|
||||
fst, samp_size = self.ctrl.run_datacal(data_dir=self.dirname)
|
||||
self.assertTrue(fst - 0.44 < 0.01)
|
||||
self.assertEqual(samp_size, 11)
|
||||
|
||||
def test_fdist(self):
|
||||
"""Test fdist execution.
|
||||
"""
|
||||
# The number of simulations in real life should be at least 10000,
|
||||
# see the fdist2 documentation.
|
||||
fst = self.ctrl.run_fdist(npops=15, nsamples=10, fst=0.1,
|
||||
sample_size=20, mut=0, num_sims=100,
|
||||
data_dir=self.dirname)
|
||||
self.assertTrue(abs(fst - 0.1) < 0.03,
|
||||
"Stochastic result, expected %f close to 0.1" % fst)
|
||||
|
||||
def test_fdist_force_fst(self):
|
||||
"""Test fdist execution approximating Fst.
|
||||
"""
|
||||
# The number of simulations in real life should be at least 10000,
|
||||
# see the fdist2 documentation.
|
||||
fst = self.ctrl.run_fdist_force_fst(npops=15, nsamples=10,
|
||||
fst=0.1,
|
||||
sample_size=20, mut=0, num_sims=100,
|
||||
data_dir=self.dirname)
|
||||
self.assertTrue(abs(fst - 0.09) < 0.05,
|
||||
"Stochastic result, expected %f close to 0.09" % fst)
|
||||
|
||||
def test_cplot(self):
|
||||
"""Test cplot execution.
|
||||
"""
|
||||
cpl_interval = self.ctrl.run_cplot(data_dir=self.dirname)
|
||||
self.assertEqual(len(cpl_interval), 8)
|
||||
|
||||
def test_pv(self):
|
||||
"""Test pv execution.
|
||||
"""
|
||||
pv_data = self.ctrl.run_pv(data_dir=self.dirname)
|
||||
self.assertEqual(len(pv_data), 4)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Running fdist tests, which might take some time, please wait")
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
unittest.main(testRunner=runner)
|
@ -1,109 +0,0 @@
|
||||
# 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 os
|
||||
import unittest
|
||||
from Bio.PopGen import GenePop
|
||||
from Bio.PopGen import FDist
|
||||
from Bio.PopGen.GenePop import FileParser
|
||||
from Bio.PopGen.FDist.Utils import convert_genepop_to_fdist
|
||||
|
||||
# Tests fdist related code. Note: this case doesn't require fdist
|
||||
# test_PopGen_FDist tests code that requires fdist
|
||||
|
||||
|
||||
class RecordTest(unittest.TestCase):
|
||||
def test_record_basic(self):
|
||||
"""Basic test on Record
|
||||
"""
|
||||
|
||||
r = FDist.Record()
|
||||
assert isinstance(r.data_org, int)
|
||||
assert isinstance(r.num_pops, int)
|
||||
assert isinstance(r.num_loci, int)
|
||||
assert isinstance(r.loci_data, list)
|
||||
|
||||
|
||||
class ParserTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
files = ["fdist1"]
|
||||
self.handles = []
|
||||
for filename in files:
|
||||
self.handles.append(open(os.path.join("PopGen", filename)))
|
||||
|
||||
self.pops_loci = [
|
||||
(3, 4)
|
||||
]
|
||||
self.num_markers = [
|
||||
[2, 3, 4, 2]
|
||||
]
|
||||
# format is locus, pop, position, value
|
||||
self.test_pos = [
|
||||
[
|
||||
(0, 0, 0, 5),
|
||||
(3, 2, 0, 5)
|
||||
]
|
||||
]
|
||||
|
||||
def tearDown(self):
|
||||
for handle in self.handles:
|
||||
handle.close()
|
||||
|
||||
def test_record_parser(self):
|
||||
"""Basic operation of the Record Parser.
|
||||
"""
|
||||
for index in range(len(self.handles)):
|
||||
handle = self.handles[index]
|
||||
rec = FDist.read(handle)
|
||||
assert isinstance(rec, FDist.Record)
|
||||
assert rec.data_org == 0 # We don't support any other
|
||||
assert rec.num_pops, rec.num_loci == self.pops_loci[index]
|
||||
for i in range(len(self.num_markers[index])):
|
||||
assert rec.loci_data[i][0] == \
|
||||
self.num_markers[index][i]
|
||||
for i in range(len(self.test_pos[index])):
|
||||
my_test_pos = self.test_pos[index]
|
||||
for test in my_test_pos:
|
||||
locus, pop, pos, value = test
|
||||
assert(rec.loci_data[locus][1][pop][pos] == value)
|
||||
|
||||
|
||||
class ConversionTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
files = ["c2line.gen", "haplo2.gen"]
|
||||
self.handles = []
|
||||
self.names = []
|
||||
for filename in files:
|
||||
self.names.append(os.path.join("PopGen", filename))
|
||||
self.handles.append(open(os.path.join("PopGen", filename)))
|
||||
|
||||
def test_convert(self):
|
||||
"""Basic conversion test.
|
||||
"""
|
||||
for i in range(len(self.names)):
|
||||
handle = self.handles[i]
|
||||
gp_rec = GenePop.read(handle)
|
||||
fd_rec = convert_genepop_to_fdist(gp_rec)
|
||||
assert(fd_rec.num_loci == 3)
|
||||
assert(fd_rec.num_pops == 3)
|
||||
|
||||
def test_convert_big(self):
|
||||
"""Big interface conversion test.
|
||||
"""
|
||||
for i in range(len(self.names)):
|
||||
gp_rec = FileParser.read(self.names[i])
|
||||
fd_rec = convert_genepop_to_fdist(gp_rec)
|
||||
assert(fd_rec.num_loci == 3)
|
||||
assert(fd_rec.num_pops == 3)
|
||||
gp_rec._handle.close() # TODO - Needs a proper fix
|
||||
|
||||
def tearDown(self):
|
||||
for handle in self.handles:
|
||||
handle.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
unittest.main(testRunner=runner)
|
@ -1,63 +0,0 @@
|
||||
# Copyright 2014 by Melissa Gymrek <mgymrek@mit.edu>. 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 os
|
||||
import shutil
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
from Bio import MissingExternalDependencyError
|
||||
from Bio import BiopythonDeprecationWarning
|
||||
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", BiopythonDeprecationWarning)
|
||||
from Bio.PopGen.SimCoal.Controller import FastSimCoalController
|
||||
|
||||
# Tests fastsimcoal related code. Note: this case requires fastsimcoal 2.51
|
||||
|
||||
found = False
|
||||
for path in os.environ['PATH'].split(os.pathsep):
|
||||
try:
|
||||
for filename in os.listdir(path):
|
||||
if filename == "fsc252" \
|
||||
or (filename.lower() == "fsc252.exe"):
|
||||
found = True
|
||||
fastsimcoal_dir = path
|
||||
except os.error:
|
||||
pass # Path doesn't exist - correct to pass
|
||||
if not found:
|
||||
raise MissingExternalDependencyError(
|
||||
"Install fastsimcoal if you want to use "
|
||||
"Bio.PopGen.SimCoal.Controller.FastSimCoalController.")
|
||||
|
||||
|
||||
class AppTest(unittest.TestCase):
|
||||
"""Tests fastsimcoal execution via biopython."""
|
||||
|
||||
def setUp(self):
|
||||
self.tidy()
|
||||
|
||||
def tearDown(self):
|
||||
self.tidy()
|
||||
|
||||
def tidy(self):
|
||||
if not os.path.isdir(os.path.join('PopGen', 'simple')):
|
||||
# Unit test must have failed to invoke fastsimcoal251,
|
||||
# and thus it never created the directory.
|
||||
return
|
||||
shutil.rmtree(os.path.join('PopGen', 'simple'))
|
||||
|
||||
def test_fastsimcoal(self):
|
||||
"""Test fastsimcoal execution."""
|
||||
ctrl = FastSimCoalController(fastsimcoal_dir=fastsimcoal_dir)
|
||||
ctrl.run_fastsimcoal('simple.par', 50, par_dir='PopGen')
|
||||
assert os.path.isdir(os.path.join('PopGen', 'simple')), \
|
||||
"Output directory not created!"
|
||||
assert(len(os.listdir(os.path.join('PopGen', 'simple'))) == 52)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
unittest.main(testRunner=runner)
|
@ -1,66 +0,0 @@
|
||||
# Copyright 2007 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 os
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
from Bio import MissingExternalDependencyError
|
||||
from Bio import BiopythonDeprecationWarning
|
||||
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", BiopythonDeprecationWarning)
|
||||
from Bio.PopGen import SimCoal
|
||||
from Bio.PopGen.SimCoal.Controller import SimCoalController
|
||||
|
||||
# Tests simcoal related code. Note: this case requires simcoal
|
||||
# test_PopGen_SimCoal_nodepend tests code that does not require simcoal
|
||||
|
||||
found = False
|
||||
for path in os.environ['PATH'].split(os.pathsep):
|
||||
try:
|
||||
for filename in os.listdir(path):
|
||||
if filename == "simcoal2" \
|
||||
or (filename.lower() == "simcoal2.exe"):
|
||||
found = True
|
||||
simcoal_dir = path
|
||||
except os.error:
|
||||
pass # Path doesn't exist - correct to pass
|
||||
if not found:
|
||||
raise MissingExternalDependencyError(
|
||||
"Install SIMCOAL2 if you want to use Bio.PopGen.SimCoal.")
|
||||
|
||||
|
||||
class AppTest(unittest.TestCase):
|
||||
"""Tests simcoal execution via biopython.
|
||||
"""
|
||||
def setUp(self):
|
||||
self.tidy()
|
||||
|
||||
def tearDown(self):
|
||||
self.tidy()
|
||||
|
||||
def tidy(self):
|
||||
if not os.path.isdir(os.path.join('PopGen', 'simple')):
|
||||
# Unit test must have failed to invoke simcaol,
|
||||
# and thus it never created the directory.
|
||||
return
|
||||
for file in os.listdir(os.path.join('PopGen', 'simple')):
|
||||
os.remove(os.sep.join(['PopGen', 'simple', file]))
|
||||
os.rmdir(os.path.join('PopGen', 'simple'))
|
||||
|
||||
def test_simcoal(self):
|
||||
"""Test simcoal execution.
|
||||
"""
|
||||
ctrl = SimCoalController(simcoal_dir)
|
||||
ctrl.run_simcoal('simple.par', 50, par_dir='PopGen')
|
||||
assert os.path.isdir(os.path.join('PopGen', 'simple')), \
|
||||
"Output directory not created!"
|
||||
assert(len(os.listdir(os.path.join('PopGen', 'simple'))) == 52)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
unittest.main(testRunner=runner)
|
@ -1,53 +0,0 @@
|
||||
# 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.
|
||||
|
||||
from Bio._py3k import _universal_read_mode
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
from Bio import BiopythonDeprecationWarning
|
||||
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", BiopythonDeprecationWarning)
|
||||
from Bio.PopGen.SimCoal.Template import generate_simcoal_from_template
|
||||
|
||||
# Tests simcoal related code. Note: this case doesn't require simcoal
|
||||
# test_PopGen_SimCoal tests code that requires simcoal
|
||||
|
||||
|
||||
class TemplateTest(unittest.TestCase):
|
||||
def test_template_full(self):
|
||||
"""Full template creation test
|
||||
"""
|
||||
generate_simcoal_from_template('simple',
|
||||
[(1, [('SNP', [24, 0.0005, 0.0])])],
|
||||
[('sample_size', [30]),
|
||||
('pop_size', [100])],
|
||||
'PopGen')
|
||||
# Confirm the files match (ignoring any switch of line endings
|
||||
# possible if the input file used a different OS convention)
|
||||
with open(os.path.join('PopGen', 'simple.par'), _universal_read_mode) as handle:
|
||||
old = handle.readlines()
|
||||
with open(os.path.join('PopGen', 'simple_100_30.par')) as handle:
|
||||
new = handle.readlines()
|
||||
assert old == new, "Error - Old:\n%s\n\nNew:\n%s\n" % (old, new)
|
||||
# assert(os.stat('PopGen' + os.sep + 'simple.par').st_size ==
|
||||
# os.stat('PopGen' + os.sep + 'simple_100_30.par').st_size)
|
||||
|
||||
def tearDown(self):
|
||||
if os.path.isfile(os.path.join('PopGen', 'tmp.par')):
|
||||
# This is a temp file create by the Bio.PopGen.SimCoal.Template
|
||||
# function generate_simcoal_from_template
|
||||
os.remove(os.path.join('PopGen', 'tmp.par'))
|
||||
if os.path.isfile(os.path.join('PopGen', 'simple_100_30.par')):
|
||||
# This won't exist if the template generation failed:
|
||||
os.remove(os.path.join('PopGen', 'simple_100_30.par'))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
unittest.main(testRunner=runner)
|
Reference in New Issue
Block a user