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   
14   
15 -class SimCoalController(object):
16 - def __init__(self, simcoal_dir):
17 """Initializes the controller. 18 19 simcoal_dir is the directory where simcoal is. 20 21 The initializer checks for existance and executability of binaries. 22 """ 23 self.simcoal_dir = simcoal_dir 24 self.os_name = os.name # remove this? 25 dir_contents = os.listdir(self.simcoal_dir) 26 #We expect the tool to be installed as simcoal2(.exe) 27 #without any trailing version number. 28 self.bin_name = "simcoal2" 29 if self.bin_name not in dir_contents: 30 #Try case insensitive, 31 dir_contents = [x.lower() for x in dir_contents] 32 if self.bin_name not in dir_contents: 33 #Try with .exe 34 self.bin_name += '.exe' 35 if self.bin_name not in dir_contents: 36 raise IOError("SimCoal not available") 37 if not os.access(os.path.join(self.simcoal_dir, self.bin_name), 38 os.X_OK): 39 raise IOError("SimCoal not executable")
40
41 - def run_simcoal(self, par_file, num_sims, ploydi = '1', par_dir = '.'):
42 """Executes SimCoal. 43 """ 44 if par_dir is None: 45 par_dir = os.sep.join([".", 'SimCoal', 'runs']) 46 curr_dir = os.getcwd() 47 #TODO - Make sure we change drive on Windows as well? 48 os.chdir(par_dir) 49 exe = os.path.join(self.simcoal_dir, self.bin_name) 50 if " " in exe: 51 exe = '"' + exe + '"' 52 cmd = exe + ' ' + par_file + ' ' + str(num_sims) + ' ' + ploydi 53 #TODO - Better way to spot if on Jython on Windows? 54 if sys.platform=="win32" or self.bin_name.endswith(".exe"): 55 #There is no /dev/nul on Windows 56 cmd += ' > nul 2>nul' 57 else: 58 cmd += ' >/dev/null 2>&1' 59 os.system(cmd) 60 os.chdir(curr_dir)
61