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, path): # Super # DirectoryPath.__init__(self, path) # The git directory # self.git_dir = self.path + '.git' # Check exists # if not os.path.exists(self.git_dir): raise Exception("No git repository at '%s'" % (self.git_dir))
def __init__(self, path, empty=False): # Super # DirectoryPath.__init__(self, path) # The git directory # self.git_dir = self.path + '.git' # Check exists # if not empty and not self: raise Exception("No git repository at '%s'" % (self.git_dir)) # Default arguments # self.default = ["--git-dir=" + self.git_dir, "--work-tree=" + self.path]
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 make_raw_zip_bundle(cluster): """Zip all the raw samples files in one file""" result_dir = DirectoryPath(cluster.base_dir + "raw_reads") result_dir.remove() result_dir.create() for sample in tqdm(cluster.samples): subdir = DirectoryPath(result_dir + sample.short_name) subdir.create() shutil.copy(sample.raw.fwd, subdir) shutil.copy(sample.raw.rev, subdir) result_dir.zip(keep_orig=False)
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))
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 = GitRepo(os.path.abspath(module_dir + '/../')) project_name = os.path.basename(repos_dir) static_module_dir = modules_dir + project_name + '/' module_version = module.__version__ + ' ' + repos_dir.tag # 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)
class FastQC(object): """Takes care of running the FastQC program. See http://www.bioinformatics.babraham.ac.uk/projects/fastqc/ Expects version 0.10.1.""" 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 check(self): assert sh.fastqc('--v', ) def run(self): if self.dest is None: sh.fastqc(self.source, '-q') os.remove(self.source.prefix_path + '_fastqc.zip') if self.dest is not None: if self.dest.exists: self.dest.remove() self.tmp_dir = new_temp_dir() sh.fastqc(self.source, '-q', '-o', self.tmp_dir) created_dir = self.tmp_dir + self.source.prefix.split('.')[0] + '_fastqc/' shutil.move(created_dir, self.dest) self.tmp_dir.remove() return self.results @property def output_dir(self): if self.dest is None: return self.source.split('.')[0] + '_fastqc/' else: return self.dest @property_cached def results(self): results = FastQCResults(self.output_dir) if not results: self.run() return results