Package Bio :: Package PopGen :: Package SimCoal :: Module Controller
[hide private]
[frames] | no frames]

Source Code for Module Bio.PopGen.SimCoal.Controller

 1  # Copyright 2007 by Tiago Antao <tiagoantao@gmail.com>.  All rights reserved. 
 2  # This code is part of the Biopython distribution and governed by its 
 3  # license.  Please see the LICENSE file that should have been included 
 4  # as part of this package. 
 5   
 6  """ 
 7  This module allows you to control Simcoal2. 
 8   
 9  """ 
10   
11  import os 
12  import sys 
13  import tempfile 
14  from shutil import copyfile 
15  from logging import debug 
16   
17 -class SimCoalController:
18 - def __init__(self, simcoal_dir):
19 """Initializes the controller. 20 21 simcoal_dir is the directory where simcoal is. 22 23 The initializer checks for existance and executability of binaries. 24 """ 25 self.simcoal_dir = simcoal_dir 26 self.os_name = os.name 27 dir_contents = os.listdir(self.simcoal_dir) 28 #We expect the tool to be installed as simcoal2(.exe) 29 #without any trailing version number. 30 if self.os_name=='nt' or sys.platform=='cygwin': 31 self.bin_name = 'simcoal2.exe' 32 #Windows is case insenstive 33 dir_contents = [x.lower() for x in dir_contents] 34 else: 35 self.bin_name = 'simcoal2' 36 if self.bin_name in dir_contents: 37 if not os.access(self.simcoal_dir + os.sep + 38 self.bin_name, os.X_OK): 39 raise IOError("SimCoal not executable") 40 else: 41 raise IOError("SimCoal not available")
42
43 - def run_simcoal(self, par_file, num_sims, ploydi = '1', par_dir = '.'):
44 """Executes SimCoal. 45 """ 46 if par_dir == None: 47 par_dir = os.sep.join([Config.dataDir, 'SimCoal', 'runs']) 48 curr_dir = os.getcwd() 49 #TODO - Make sure we change drive on Windows as well? 50 os.chdir(par_dir) 51 cmd = self.simcoal_dir + os.sep + self.bin_name + ' ' + \ 52 par_file + ' ' + str(num_sims) + ' ' + ploydi 53 if sys.platform=="win32" : 54 #There is no /dev/nul on Windows 55 cmd += ' > nul 2>nul' 56 else : 57 cmd += ' >/dev/null 2>&1' 58 os.system(cmd) 59 os.chdir(curr_dir)
60