Ejemplo n.º 1
0
    def create_job(self,
                   alignment,
                   starting_tree=None,
                   name='default',
                   **kwargs):
        scratch_dir, seqfn, dt, score_fn = self._prepare_input(
            alignment, **kwargs)
        invoc = [
            sys.executable,
            self.exe,
            seqfn,
            dt,
            os.path.join(scratch_dir, 'output.tre'),
        ]

        dirs_to_delete = []
        if kwargs.get('delete_temps', self.delete_temps):
            dirs_to_delete.append(scratch_dir)

        pasta_products = kwargs.get('pasta_products')
        step_num = kwargs.get('step_num')

        def randtree_result_processor(dir=scratch_dir,
                                      score_fn=score_fn,
                                      fn=os.path.join(scratch_dir,
                                                      'output.tre'),
                                      dirs_to_delete=dirs_to_delete,
                                      temp_fs=self.temp_fs,
                                      pasta_products=pasta_products,
                                      step_num=step_num):
            score = float(open(score_fn, 'rU').read().strip())
            tree_str = open(fn, 'rU').read().strip()
            copy_temp_tree(fn, pasta_products, step_num)
            for d in dirs_to_delete:
                temp_fs.remove_dir(d)
            return (score, tree_str)

        job_id = kwargs.get('context_str', '') + '_randtree'
        job = DispatchableJob(invoc,
                              result_processor=randtree_result_processor,
                              cwd=scratch_dir,
                              context_str=job_id,
                              stdout=score_fn)
        return job
Ejemplo n.º 2
0
    def create_job(self, alignment, starting_tree=None, **kwargs):
        scratch_dir, seqfn, datatype, options = self._prepare_input(
            alignment, **kwargs)
        num_cpus = kwargs.get('num_cpus')
        log_file = os.path.join(scratch_dir, 'log')

        invoc = [self.exe, '-quiet']
        if datatype != '':
            invoc.extend([datatype])

        model = self.model if self.model is not None else ''

        if model != '':
            model = model.split(' ')
            invoc.extend(model)
        #elif datatype == '-nt':
        #    model = '-gtr'
        #    invoc.append(model)

        if options is not None and len(options) >= 1:
            invoc.extend(options)

        fasttree_result = os.path.join(scratch_dir, 'results')

        if starting_tree is not None:
            if isinstance(starting_tree, str):
                tree_str = starting_tree
            else:
                tree_str = str(starting_tree)
            tree_fn = os.path.join(os.path.abspath(scratch_dir), "start.tre")
            tree_file_obj = open(tree_fn, "w")
            tree_file_obj.write("%s;\n" % tree_str)
            tree_file_obj.close()
            invoc.extend(['-intree', tree_fn])

        invoc.extend(['-log', log_file, seqfn])

        if num_cpus > 1:
            if platform.system() == 'Windows':
                mp_path = self.exe.replace('.', 'MP.')
            else:
                mp_path = self.exe + 'MP'
            if os.path.exists(mp_path):
                os.environ["OMP_NUM_THREADS"] = str(
                    num_cpus if num_cpus < 5 else 4)
                invoc[0] = mp_path

        dirs_to_delete = []
        if kwargs.get('delete_temps', self.delete_temps):
            dirs_to_delete.append(scratch_dir)

        pasta_products = kwargs.get('pasta_products')
        step_num = kwargs.get('step_num')
        rpc = lambda: read_fasttree_results(
            scratch_dir,
            fasttree_result,
            log_file,
            delete_dir=kwargs.get('delete_temps', self.delete_temps),
            pasta_products=pasta_products,
            step_num=step_num)
        job_id = kwargs.get('context_str', '') + '_fasttree'
        job = DispatchableJob(invoc,
                              result_processor=rpc,
                              cwd=scratch_dir,
                              stdout=fasttree_result,
                              context_str=job_id)
        return job
Ejemplo n.º 3
0
    def create_job(self,
                   alignment,
                   starting_tree=None,
                   name='default',
                   **kwargs):
        scratch_dir, seqfn, parfn, model = self._prepare_input(
            alignment, **kwargs)
        num_cpus = kwargs.get('num_cpus')
        invoc = [
            self.exe,
            '-m',
            model,
            '-n',
            name,
            '-q',
            parfn,
            '-s',
            seqfn,
            # '-M', # Branch length estimates per partition
        ]
        #x = open(parfn).readlines()
        #npar = [i.count(',') for i in x]

        # if npar > 1:
        #   invoc.extend('-M')

        if self.user_opts is not None and len(self.user_opts) >= 1:
            invoc.extend(self.user_opts)

        if starting_tree is not None:
            if isinstance(starting_tree, str):
                tree_str = starting_tree
            else:
                tree_str = str(starting_tree)
            tree_fn = os.path.join(os.path.abspath(scratch_dir), "start.tre")
            tree_file_obj = open(tree_fn, "w")
            tree_file_obj.write("%s;\n" % tree_str)
            tree_file_obj.close()
            invoc.extend(['-t', tree_fn])
        if num_cpus > 1:
            invoc.extend(['-T', str(num_cpus)])
            if platform.system() == 'Windows':
                x = invoc[0].split('.')
                x[-2] += 'p'
                invoc[0] = '.'.join(x)
            else:
                invoc[0] += 'p'
        if GLOBAL_DEBUG:
            invoc.extend(['-p', '123456789'])

        dirs_to_delete = []
        if kwargs.get('delete_temps', self.delete_temps):
            dirs_to_delete.append(scratch_dir)

        pasta_products = kwargs.get('pasta_products')
        step_num = kwargs.get('step_num')
        rpc = lambda: read_raxml_results(scratch_dir,
                                         dirs_to_delete=dirs_to_delete,
                                         temp_fs=self.temp_fs,
                                         pasta_products=pasta_products,
                                         step_num=step_num)
        job_id = kwargs.get('context_str', '') + '_raxml'
        job = DispatchableJob(invoc,
                              result_processor=rpc,
                              cwd=scratch_dir,
                              context_str=job_id)
        return job