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   
 3  """ 
 4  This module allows to control Simcoal2. 
 5   
 6  """ 
 7   
 8  import os 
 9  import sys 
10  import tempfile 
11  from shutil import copyfile 
12  from logging import debug 
13   
14 -class SimCoalController:
15 - def __init__(self, simcoal_dir):
16 """Initializes the controller. 17 18 simcoal_dir is the directory where simcoal is. 19 20 The initializer checks for existance and executability of binaries. 21 """ 22 self.simcoal_dir = simcoal_dir 23 self.os_name = os.name 24 if self.os_name=='nt' or sys.platform=='cygwin': 25 self.bin_name = 'simcoal2.exe' 26 #this is wrong (the exe name), most probably 27 else: 28 self.bin_name = 'simcoal2' 29 #This name is too specific 30 dir_contents = os.listdir(self.simcoal_dir) 31 if self.bin_name in dir_contents: 32 if not os.access(self.simcoal_dir + os.sep + 33 self.bin_name, os.X_OK): 34 raise IOError, "SimCoal not executable" 35 else: 36 raise IOError, "SimCoal not available"
37
38 - def run_simcoal(self, par_file, num_sims, ploydi = '1', par_dir = '.'):
39 """Executes SimCoal. 40 """ 41 if par_dir == None: 42 par_dir = os.sep.join([Config.dataDir, 'SimCoal', 'runs']) 43 curr_dir = os.getcwd() 44 os.chdir(par_dir) 45 os.system(self.simcoal_dir + os.sep + self.bin_name + ' ' + 46 par_file + ' ' + str(num_sims) + ' ' + ploydi + ' >/dev/null 2>&1') 47 os.chdir(curr_dir)
48