Пример #1
0
    def finish(self):
        # first job is the raxml tree
        best_model = None
        best_model_in_next_line = False
        t = None
        for line in open(self.jobs[-1].stdout_file, "rU"):
            line = line.strip()
            if best_model_in_next_line and line.startswith("Model"):
                pass#best_model = line.split("=")[1].strip()
            elif best_model_in_next_line and line.startswith("partition"):
                best_model = line.split("=")[1].strip()
                best_model_in_next_line = False
            elif line.startswith("Model selected:"):
                best_model_in_next_line = True
            elif line.startswith("ML tree (NNI) for the best AIC model ="): 
                nw = line.replace("ML tree (NNI) for the best AIC model =", "")
                t = PhyloTree(nw)

        open(self.best_model_file, "w").write(best_model)
        log.log(26, "Best model: %s" %best_model)
        if self.ttype == "tree": 
            tree_job = self.jobs[-1]
            tree_file =  os.path.join(tree_job.jobdir,
                                      "jModelTest_tree."+self.nodeid)
            t.write(outfile=self.tree_file)
            self.model = best_model
        

        ModelTesterTask.finish(self)
Пример #2
0
 def finish(self):
     lks = []
     if self.lk_mode == "phyml":
         for job in [j for j in self.jobs if j.flag == "phyml"]:
             tree_file = os.path.join(job.jobdir,
                                      self.alg_basename+"_phyml_tree.txt")
             stats_file = os.path.join(j.jobdir,
                                       self.alg_basename+"_phyml_stats.txt")
             tree = PhyloTree(tree_file)
             m = re.search('Log-likelihood:\s+(-?\d+\.\d+)',
                           open(stats_file).read())
             lk = float(m.groups()[0])
             tree.add_feature("lk", lk)
             tree.add_feature("model", job.args["--model"])
             lks.append([float(tree.lk), tree.model, tree])
     elif self.lk_mode == "raxml":
         for job in [j for j in self.jobs if j.flag == "raxml"]:
             lk = open(os.path.join(job.jobdir, "RAxML_log.%s"
                                    %job.args["-n"])).readline().split()[1]
             tree = PhyloTree(job.args["-t"])
             tree.add_feature("lk", lk)
             tree.add_feature("model", job.model)
             lks.append([lk, tree.model, tree])
     lks.sort()
     lks.reverse()
     # choose the model with higher likelihood
     best_model = lks[-1][1]
     best_tree = lks[-1][2]
     open(self.best_model_file, "w").write(best_model)
     if self.tree_file:
         tree.write(self.tree_file)
     ModelTesterTask.finish(self)
Пример #3
0
    def finish(self):
        lks = []
        j = self.jobs[0]
        tree_file = os.path.join(j.jobdir,
                                 self.alg_phylip_file+"_phyml_tree.txt")
        stats_file = os.path.join(j.jobdir,
                                  self.alg_phylip_file+"_phyml_stats.txt")

        m = re.search('Log-likelihood:\s+(-?\d+\.\d+)',
                      open(stats_file).read())
        lk = float(m.groups()[0])
        stats = {"lk": lk}
        tree = PhyloTree(tree_file)        
        TreeTask.store_data(self, tree.write(), stats)