def __init__(self, source, dest=None): # Basic # self.source = FASTQ(source) self.dest = DirectoryPath(dest) # Default case # if dest is None: self.dest = DirectoryPath(self.source.prefix_path + '.fastqc')
def __init__(self, command, language='python', base_dir=os.path.abspath(os.getcwd()), modules=None, **kwargs): # Check the modules variable is a list # if modules is None: self.modules = [] elif not isinstance(modules, list): self.modules = list(modules) else: self.modules = modules # Check command type # if not isinstance(command, list): command = [command] # Log directory # for i in range(30): now = datetime.datetime.now(dateutil.tz.tzlocal()) log_name = now.strftime("%Y-%m-%da%Hh%Mm%Ss%Z%z") base_dir = DirectoryPath(base_dir + log_name + '/') if not base_dir.exists: base_dir.create() break else: time.sleep(2) continue else: base_dir.create() # Modules directory # modules_dir = DirectoryPath(base_dir + "modules/") modules_dir.create() # The script to be sent # script = [] # Copy modules to the log directory # for module in self.modules: module_dir = os.path.dirname(module.__file__) module_name = module.__name__ repos_dir = os.path.abspath(module_dir + '/../') project_name = os.path.basename(repos_dir) static_module_dir = modules_dir + project_name + '/' module_version = module.__version__ + ' ' + get_git_tag(repos_dir) # Copy # print "Making static copy of module '%s' for SLURM job..." % module_name sh.cp('-R', repos_dir, static_module_dir) # Make script # script.insert(0, "sys.path.insert(0, '%s')" % static_module_dir) script += ["import %s" % module_name] script += [ "print 'Using static copy of module %s version %s'" % (module_name, module_version) ] # Prepend to the script to be sent # script.insert(0, "import os, sys") # Add the user's command to the script # script += command # Super # JobSLURM.__init__(self, script, language, base_dir, **kwargs)
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))