Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
Bio.PopGen.SimCoal.Cache.SimCoalCache Class Reference
Inheritance diagram for Bio.PopGen.SimCoal.Cache.SimCoalCache:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def run_simcoal
def listSimulations
def getSimulation

Public Attributes

 dataDir
 cacheDir
 simcoalDir

Detailed Description

Definition at line 16 of file Cache.py.


Constructor & Destructor Documentation

def Bio.PopGen.SimCoal.Cache.SimCoalCache.__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.

Reimplemented in Bio.PopGen.SimCoal.Async.SimCoalCache.

Definition at line 17 of file Cache.py.

00017 
00018     def __init__(self, data_dir, simcoal_dir):
00019         """Initializes the cache.
00020         
00021         data_dir - Where the cache can be found
00022         simcoal_dir - where the binaries are
00023 
00024         IMPORTANT: The cache only makes sense if the file name univocally
00025         identifies the model.
00026           For now use use the model name as key,
00027           and it will probably stay like that.
00028         """
00029         self.dataDir = data_dir
00030         self.cacheDir = os.sep.join([data_dir, 'SimCoal', 'cache'])
00031         self.simcoalDir = simcoal_dir
00032 


Member Function Documentation

def Bio.PopGen.SimCoal.Cache.SimCoalCache.getSimulation (   self,
  sim_name,
  ploidy = '1',
  parDir = None 
)
   Makes available a cached simulation.

   @param sim_name simulation name.

   This mainly means untaring a file.

Definition at line 70 of file Cache.py.

00070 
00071     def getSimulation(self, sim_name, ploidy = '1', parDir = None):
00072         '''
00073            Makes available a cached simulation.
00074 
00075            @param sim_name simulation name.
00076 
00077            This mainly means untaring a file.
00078         '''
00079         if parDir == None:
00080             parDir = os.sep.join([self.dataDir, 'SimCoal', 'runs'])
00081         tar_name = os.sep.join([self.cacheDir, ploidy, sim_name + 
00082             '.tar.bz2'])
00083         tf = tarfile.open(tar_name)
00084         tf.extractall(parDir)
00085         tf.close()
00086 
00087 
00088 #if __name__ == '__main__':
00089 #  cache = Cache('/home/work/werk/consolidator/sc_cache',
00090 #      '/home/work/software/simcoal')
00091 #  cache.run_simcoal('.', 'island_snp-50_0.0025_10_0.083_100_60.par', 102)
def Bio.PopGen.SimCoal.Cache.SimCoalCache.listSimulations (   self,
  ploidy = '1' 
)
   Lists available simulations.

Definition at line 59 of file Cache.py.

00059 
00060     def listSimulations(self, ploidy = '1'):
00061         '''
00062            Lists available simulations.
00063         '''
00064         files = os.listdir(self.cacheDir + os.sep + ploidy)
00065         sims = []
00066         for file in files:
00067             if file.endswith('.tar.bz2'):
00068                 sims.append(file[:-8])
00069         return sims

def Bio.PopGen.SimCoal.Cache.SimCoalCache.run_simcoal (   self,
  par_file,
  num_sims,
  ploydi = '1',
  parDir = None 
)

Definition at line 33 of file Cache.py.

00033 
00034     def run_simcoal(self, par_file, num_sims, ploydi = '1', parDir = None):
00035         if parDir == None:
00036             parDir = os.sep.join([self.dataDir, 'SimCoal', 'runs'])
00037         par_file_root = par_file[:-4]
00038         tar_name = os.sep.join([self.cacheDir, ploydi, par_file_root + 
00039             '.tar.bz2'])
00040         if os.access(tar_name, os.R_OK):
00041             tf = tarfile.open(tar_name)
00042             tar_num_sims = len(tf.getmembers()) - 3
00043         else:
00044             tar_num_sims = 0
00045         if tar_num_sims >= num_sims:
00046             tf.extractall(parDir)
00047             tf.close()
00048             return
00049         else:
00050             try:
00051                 tf.close()
00052             except NameError:
00053                 pass #not opened in the first place, OK.
00054         scc = SimCoalController(self.simcoalDir)
00055         scc.run_simcoal(par_file, num_sims, ploydi, parDir)
00056         tf = tarfile.open(tar_name, 'w:bz2')
00057         tf.add(os.sep.join([parDir, par_file_root]), par_file_root)
00058         tf.close()

Here is the caller graph for this function:


Member Data Documentation

Definition at line 29 of file Cache.py.

Definition at line 28 of file Cache.py.

Definition at line 30 of file Cache.py.


The documentation for this class was generated from the following file: