Esempio n. 1
0
 def link_to_evol_model(self, path, model):
     '''
     link EvolTree to evolutionary model
       * free-branch model ('fb') will append evol values to tree
       * Site models (M0, M1, M2, M7, M8) will give evol values by site
         and likelihood
     
     :argument path: path to outfile containing model computation result
     :argument model: either the name of a model, or a Model object (usually empty)
     
     '''
     if type(model) == str :
         model = Model(model, self, path)
     else:
         model._load(path)
     # new entry in _models dict
     while self._models.has_key(model.name):
         model.name = model.name.split('__')[0] + str(
             (int(model.name.split('__')[1])
              +1)  if '__' in model.name else 0)
     self._models[model.name] = model
     if not os.path.isfile(path):
         warn("ERROR: not a file: " + path)
         return 1
     if len(self._models) == 1 and model.properties['exec']=='codeml':
         self.change_dist_to_evol('bL', model, fill=True)
Esempio n. 2
0
 def link_to_evol_model(self, path, model):
     '''
     link EvolTree to evolutionary model
       * free-branch model ('fb') will append evol values to tree
       * Site models (M0, M1, M2, M7, M8) will give evol values by site
         and likelihood
     
     :argument path: path to outfile containing model computation result
     :argument model: either the name of a model, or a Model object (usually empty)
     
     '''
     if type(model) == str:
         model = Model(model, self, path)
     else:
         model._load(path)
     # new entry in _models dict
     while self._models.has_key(model.name):
         model.name = model.name.split('__')[0] + str(
             (int(model.name.split('__')[1]) +
              1) if '__' in model.name else 0)
     self._models[model.name] = model
     if not os.path.isfile(path):
         warn("ERROR: not a file: " + path)
         return 1
     if len(self._models) == 1 and model.properties['exec'] == 'codeml':
         self.change_dist_to_evol('bL', model, fill=True)
Esempio n. 3
0
    def run_model(self, model_name, ctrl_string='', keep=True, **kwargs):
        '''
        To compute evolutionnary models.     e.g.: b_free_lala.vs.lele, will launch one free branch model, and store 
        it in "WORK_DIR/b_free_lala.vs.lele" directory
        
        WARNING: this functionality needs to create a working directory in "rep"
        
        WARNING: you need to have codeml and/or SLR in your path

        The models available are:

        =========== ============================= ==================
        Model name  Description                   Model kind       
        =========== ============================= ==================\n%s
        =========== ============================= ==================\n
        
        :argument model_name: a string like "model-name[.some-secondary-name]" (e.g.: "fb.my_first_try", or just "fb")
                              * model-name is compulsory, is the name of the model (see table above for the full list)
                              * the second part is accessory, it is to avoid over-writing models with the same name.
        :argument ctrl_string: list of parameters that can be used as control file.
        :argument kwargs: extra parameters should be one of: %s.
        '''
        from subprocess import Popen, PIPE
        model_obj = Model(model_name, self, **kwargs)
        fullpath = os.path.join (self.workdir, model_obj.name)
        os.system("mkdir -p %s" %fullpath)
        # write tree file
        self.__write_algn(fullpath + '/algn')
        if model_obj.properties['exec'] == 'Slr':
            self.write(outfile=fullpath+'/tree',
                       format = (11))
        else:
            self.write(outfile=fullpath+'/tree',
                       format = (10 if model_obj.properties['allow_mark'] else 9))
        # write algn file
        ## MODEL MODEL MDE
        if ctrl_string == '':
            ctrl_string = model_obj.get_ctrl_string(fullpath+'/tmp.ctl')
        else:
            open(fullpath+'/tmp.ctl', 'w').write(ctrl_string)
        hlddir = os.getcwd()
        os.chdir(fullpath)
        bin = os.path.join(self.execpath, model_obj.properties['exec'])
        try:
            proc = Popen([bin, 'tmp.ctl'], stdout=PIPE)
        except OSError:
            raise Exception(('ERROR: {} not installed, ' +
                             'or wrong path to binary\n').format(bin))
        run, err = proc.communicate()
        if err is not None:
            warn("ERROR: codeml not found!!!\n" + 
                 "       define your variable EvolTree.execpath")
            return 1
        if 'error' in run or 'Error' in run:
            warn("ERROR: inside codeml!!\n" + run)
            return 1
        os.chdir(hlddir)
        if keep:
            setattr(model_obj, 'run', run)
            self.link_to_evol_model(os.path.join(fullpath,'out'), model_obj)
Esempio n. 4
0
    def run_model(self, model_name, ctrl_string='', keep=True, **kwargs):
        '''
        To compute evolutionnary models.     e.g.: b_free_lala.vs.lele, will launch one free branch model, and store 
        it in "WORK_DIR/b_free_lala.vs.lele" directory
        
        WARNING: this functionality needs to create a working directory in "rep"
        
        WARNING: you need to have codeml and/or SLR in your path

        The models available are:

        =========== ============================= ==================
        Model name  Description                   Model kind       
        =========== ============================= ==================\n%s
        =========== ============================= ==================\n
        
        :argument model_name: a string like "model-name[.some-secondary-name]" (e.g.: "fb.my_first_try", or just "fb")
                              * model-name is compulsory, is the name of the model (see table above for the full list)
                              * the second part is accessory, it is to avoid over-writing models with the same name.
        :argument ctrl_string: list of parameters that can be used as control file.
        :argument kwargs: extra parameters should be one of: %s.
        '''
        from subprocess import Popen, PIPE
        model_obj = Model(model_name, self, **kwargs)
        fullpath = os.path.join(self.workdir, model_obj.name)
        os.system("mkdir -p %s" % fullpath)
        # write tree file
        self.__write_algn(fullpath + '/algn')
        if model_obj.properties['exec'] == 'Slr':
            self.write(outfile=fullpath + '/tree', format=(11))
        else:
            self.write(
                outfile=fullpath + '/tree',
                format=(10 if model_obj.properties['allow_mark'] else 9))
        # write algn file
        ## MODEL MODEL MDE
        if ctrl_string == '':
            ctrl_string = model_obj.get_ctrl_string(fullpath + '/tmp.ctl')
        else:
            open(fullpath + '/tmp.ctl', 'w').write(ctrl_string)
        hlddir = os.getcwd()
        os.chdir(fullpath)
        bin = os.path.join(self.execpath, model_obj.properties['exec'])
        try:
            proc = Popen([bin, 'tmp.ctl'], stdout=PIPE)
        except OSError:
            raise Exception(('ERROR: {} not installed, ' +
                             'or wrong path to binary\n').format(bin))
        run, err = proc.communicate()
        if err is not None:
            warn("ERROR: codeml not found!!!\n" +
                 "       define your variable EvolTree.execpath")
            return 1
        if 'error' in run or 'Error' in run:
            warn("ERROR: inside codeml!!\n" + run)
            return 1
        os.chdir(hlddir)
        if keep:
            setattr(model_obj, 'run', run)
            self.link_to_evol_model(os.path.join(fullpath, 'out'), model_obj)