def concatinate(self, outputdir): # create a dir for output create_outputdir(outputdir) # print actual informations about the step on stdout print_step(self.step_number, 'Assembly', 'Concatinate Reads', self.concat_parameter) newline() # open the logfile logfile = open_logfile(self.logdir + 'concatination.log') # start the program Flash with parameter from the conf file a # errors will be piped to extra error logfile p = subprocess.Popen(shlex.split('%s -t %d -d %s %s %s' % (self.flash_exe, self.threads, outputdir, self.concat_parameter, self.input)), stdout = subprocess.PIPE, stderr = open_logfile(self.logdir + 'flash.err.log')) # during processing print Flash output in verbose mode and update the logfile while p.poll() is None: if self.verbose: print_verbose(p.stdout.readline()) logfile.write(p.stdout.readline()) else: print_compact(p.stdout.readline().rstrip('\n')) logfile.write(p.stdout.readline()) # wait until process is finished p.wait() if p.returncode: raise FlashException(self.logdir + 'flash.err.log') else: # remove empty error logs remove_empty_logfile(self.logdir + 'flash.err.log') # print summary of the process after completion newline() print_verbose('Concatination complete \n') print_running_time(self.time)
def parse_to_db(self, input, output): # create a dir for output create_outputdir(output) # generate filename for db outfile = output + os.sep + self.parser_name + '.db' # remove old databases with same name if os.path.exists(outfile): os.remove(outfile) # print actual informations about the step on stdout print_step(self.step_number, 'Analysis', 'Parse database from blast results', self.parser_parameter) newline() # start the parser and wait until completion p = subprocess.Popen(shlex.split('%s -o %s %s %s' % (self.parser_exe, outfile, self.parser_parameter, input)), stdout = subprocess.PIPE, stderr = open_logfile(self.logdir + 'parser.err.log')) # print information about the status while p.poll() is None: if self.verbose: print_verbose(p.stdout.readline()) else: print_compact(p.stdout.readline().rstrip('\n')) # wait until process is complete p.wait() # save the exit code for later function calls self.exitcode = p.returncode # raise Exception when an error occurs during processing if p.returncode: raise ParserException(self.logdir + 'parser.err.log') else: # remove empty error logs remove_empty_logfile(self.logdir + 'parser.err.log') # print summary of the process after completion print_verbose('Parsing of blast XML File complete \n') print_running_time(self.time) newline()
def qualityCheck(self): # create a dir for output create_outputdir(self.quality_dir) # print actual informations about the step on stdout print_step(self.step_number, 'Preprocess', 'quality analysis', self.fastqc_parameter) newline() # run FastQC with the given parameter, in seperate threads and extract the output p = subprocess.Popen(shlex.split('%s -t %s -o %s --extract %s %s' % (self.fastqc_exe, self.threads, self.quality_dir, self.fastqc_parameter, to_string(self.input))), stdout = subprocess.PIPE, stderr = subprocess.PIPE) # during processing pipe the output and print it on screen while p.poll() is None: if self.verbose: print_verbose(p.stderr.readline()) else: print_compact(p.stderr.readline().rstrip('\n')) # wait until process is finished p.wait() if p.returncode: raise FastQCException() else: # print summary of the process after completion print_verbose('Quality check complete for %s\n' % (self.input)) print_running_time(self.time) newline()
def metacv(self, outputdir): # create a dir for output create_outputdir(outputdir) # select the input for metacv and convert it in an usable format if self.contigs is True: input = to_string(self.input) else: input = to_string(self.raw) # print actual informations about the step on stdout print_step(self.step_number, 'Annotation', 'Annotate bacterial reads with MetaCV', '%s %s %s' % (self.metacv_seq, self.metacv_mode, self.metacv_orf)) newline() # metacv has a maximum thread number of 64 # parameter has to be adjusted if self.threads > 64: threads = 64 else: threads = self.threads classify = open_logfile(self.logdir + 'metacv.classify.log') # start MetaCV function and wait until completion p = subprocess.Popen(shlex.split('%s classify %s %s %s %s %s %s --threads=%s' % (self.metacv_exe, self.metacv_db, input, self.metacv_name, self.metacv_seq, self.metacv_mode, self.metacv_orf, threads)), stderr = subprocess.PIPE, stdout = subprocess.PIPE, cwd = outputdir + os.sep) # during processing pipe the output and print it on screen while p.poll() is None: if self.verbose: print_verbose(p.stderr.readline()) classify.write(p.stderr.readline()) else: print_compact(p.stderr.readline().rstrip('\n')) classify.write(p.stderr.readline()) # wait until process is finished p.wait() if p.returncode: raise MetaCVException(self.logdir + 'metacv.classify.log') else: # remove unused error logs remove_empty_logfile(self.logdir + 'metacv.classify.log') # print actual informations about the step on stdout print_step(self.step_number, 'Annotation', 'Analyse the results of MetaCV', '%s %s %s' % (self.metacv_total_reads, self.metacv_min_qual, self.metacv_taxon)) newline() res2table = open_logfile(self.logdir + 'metacv.res2table.log') # start MetaCV's res2table function and wait until completion p = subprocess.Popen(shlex.split('%s res2table %s %s %s %s %s %s --threads=%s' % (self.metacv_exe, self.metacv_db, to_string(update_reads(outputdir,'metpipe','res')), self.metacv_name + '.res2table', self.metacv_total_reads, self.metacv_min_qual, self.metacv_taxon, threads)), stderr = subprocess.PIPE, stdout = subprocess.PIPE, cwd = outputdir + os.sep) # during processing pipe the output and print it on screen while p.poll() is None: if self.verbose: print_verbose(p.stderr.readline()) res2table.write(p.stderr.readline()) else: print_compact(p.stderr.readline().rstrip('\n')) res2table.write(p.stderr.readline()) # wait until process is finished p.wait() if p.returncode: raise MetaCVSumException(self.logdir + 'metacv.res2table.log') else: # remove unused error logs remove_empty_logfile(self.logdir + 'metacv.res2table.log') # print actual informations about the step on stdout print_step(self.step_number, 'Annotation', 'Summarize the results of MetaCV', self.metacv_min_qual) newline() res2sum = open_logfile(self.logdir + 'metacv.res2sum.log') # start MetaCV's res2sum function and wait until completion # the workingdir must be specified to maintain the correct # order of output files p = subprocess.Popen(shlex.split('%s res2sum %s %s %s %s' % (self.metacv_exe, self.metacv_db, to_string(update_reads(outputdir,'metpipe','res')), self.metacv_name + '.res2sum', self.metacv_min_qual)), stderr = subprocess.PIPE, stdout = subprocess.PIPE, cwd = outputdir + os.sep) # during processing pipe the output and print it on screen while p.poll() is None: if self.verbose: print_verbose(p.stderr.readline()) res2sum.write(p.stderr.readline()) else: print_compact(p.stderr.readline().rstrip('\n')) res2sum.write(p.stderr.readline()) # wait until process is finished p.wait() if p.returncode: raise MetaCVSumException(self.logdir + 'metacv.res2sum.log') else: # remove unused error logs remove_empty_logfile(self.logdir + 'metacv.res2sum.log') # print summary of the process after completion print_verbose('Annotation with MetaCV complete \n') print_running_time(self.time) newline()