Ejemplo n.º 1
0
 def build_tree_raxml(self,
                      new_path=None,
                      seq_type='nucl' or 'prot',
                      num_threads=None,
                      free_cores=2,
                      keep_dir=False):
     """Make a tree with RAxML."""
     # Check output #
     if new_path is None: new_path = self.prefix_path + '.tree'
     # What model to choose #
     if seq_type == 'nucl': model = "GTRGAMMA"
     if seq_type == 'prot': model = "PROTGAMMAJTTF"
     # Threads #
     if num_threads is None:
         num_threads = multiprocessing.cpu_count() - free_cores
     else:
         num_threads = int(num_threads) - free_cores
     num_threads = max(1, num_threads)
     # Run it #
     temp_dir = new_temp_dir()
     sh.raxml811('-m', model, "-T", num_threads, '-p', 1, '-s', self.path,
                 '-n', 'tree', '-w', temp_dir, '-f', 'a', '-x', 1, '-N',
                 'autoMR')
     # Move into place #
     if keep_dir:
         shutil.rmtree(new_path)
         shutil.move(temp_dir, new_path)
     if not keep_dir:
         shutil.move(temp_dir + 'RAxML_bestTree.tree', new_path)
     # Return #
     return FilePath(new_path)
Ejemplo n.º 2
0
Archivo: job.py Proyecto: DC23/plumbing
 def set_paths(self, base_dir, script_path):
     """Set the directory, the script path and the outfile path"""
     # Make absolute paths #
     if 'change_dir' in self.kwargs:
         self.kwargs['change_dir'] = DirectoryPath(
             os.path.abspath(self.kwargs['change_dir']))
     if 'out_file' in self.kwargs:
         self.kwargs['out_file'] = FilePath(
             os.path.abspath(self.kwargs['out_file']))
     # In case there is a base directory #
     if base_dir is not None:
         self.base_dir = DirectoryPath(os.path.abspath(base_dir))
         self.script_path = FilePath(base_dir + "run." +
                                     self.extensions[self.language])
         self.kwargs['change_dir'] = base_dir
         self.kwargs['out_file'] = FilePath(base_dir + "run.out")
     # Other cases #
     if base_dir is None and script_path is None:
         self.script_path = FilePath(new_temp_path())
     if script_path is not None:
         self.script_path = FilePath(os.path.abspath(script_path))
Ejemplo n.º 3
0
 def build_tree_fast(self, new_path=None, seq_type='nucl' or 'prot'):
     """Make a tree with FastTree. Names will be truncated however."""
     # Check output #
     if new_path is None: new_path = self.prefix_path + '.tree'
     # Command #
     command_args = []
     if seq_type == 'nucl': command_args += ['-nt']
     command_args += ['-gamma']
     command_args += ['-out', new_path]
     command_args += [self.path]
     # Run it #
     sh.FastTree(*command_args)
     # Return #
     return FilePath(new_path)
Ejemplo n.º 4
0
 def tree(self):
     """The path to the tree built with raxml"""
     tree = FilePath(self.p.tree_dir + 'RAxML_bestTree.tree')
     if not tree.exists:
         # Check we can do it #
         if self.gaps_in_alignment:
             message = "Can't build a tree for cluster %i because of gaps. Skipping."
             warnings.warn(message % self.num)
             return None
         # Do it #
         self.alignment.build_tree(new_path=self.p.tree_dir,
                                   seq_type=self.analysis.seq_type,
                                   num_threads=self.analysis.num_threads,
                                   free_cores=0,
                                   keep_dir=True)
     return tree
Ejemplo n.º 5
0
 def retrieve_from_cache(self):
     # Is it in the cache ? #
     if '__cache__' not in self.__dict__: self.__cache__ = {}
     if f.__name__ in self.__cache__: return self.__cache__[f.__name__]
     # Where should we look in the file system ? #
     if 'cache_dir' in self.__dict__:
         path = FilePath(self.__dict__['cache_dir'] + f.func_name +
                         '.pickle')
     else:
         path = getattr(self.p, f.func_name)
     # Is it on disk ? #
     if path.exists:
         with open(path) as handle:
             result = pickle.load(handle)
         self.__cache__[f.__name__] = result
         return result
     # Otherwise let's compute it #
     result = f(self)
     with open(path, 'w') as handle:
         pickle.dump(result, handle)
     self.__cache__[f.__name__] = result
     return result
Ejemplo n.º 6
0
 def __init__(self, parent):
     self.parent = parent
     self.path = FilePath(self.parent.prefix_path + '_len_hist.pdf')
Ejemplo n.º 7
0
 def to_qual(self, path):
     with open(path, 'w') as handle:
         for r in self:
             SeqIO.write(r, handle, 'qual')
     return FilePath(path)