def blastn(self, outputdir): # create a dir for output create_outputdir(outputdir) # blastn can only run with fasta files, so input has to be converted if is_fastq(self.input): # print actual informations about the step on stdout print_step(self.step_number, 'Annotation', 'convert fastq files', cut_path(self.input)) newline() self.input = convert_fastq(self.input, self.blast_dir, self.converter_exe) # blastn can only annotated one file, so input has to be merged to one file if is_paired(self.input): # print actual informations about the step on stdout print_step(self.step_number, 'Annotation', 'merging reads to on file', cut_path(self.input)) newline() self.input = merge_files(self.input, self.blast_dir, 'merged', 'fasta') # define the outputformat for the blastn results outfile = outputdir + os.sep + blast_output(self.outfmt) # print actual informations about the step on stdout print_step(self.step_number, 'Annotation', 'blast sequences against nt database', self.blast_parameter) newline() # start blastn and wait until completion # logfile is not requiered, because blastn has no log function and no output to stdout p = subprocess.Popen(shlex.split('%s -db %s -query %s -out %s -num_threads %s %s ' % (self.blastn_exe, self.blastn_db, to_string(self.input), outfile, self.threads, self.blast_parameter)), stderr = open_logfile(self.logdir + 'blastn.err.log')) # wait until process is complete p.wait() if p.returncode: raise BlastnException(self.logdir + 'blastn.err.log') else: # remove the temporary files: converted fastq files and the merged fasta files remove_file(outputdir + os.sep, 'converted', 'fasta') remove_file(outputdir + os.sep, 'merged', 'fasta') # remove unused error logs remove_empty_logfile(self.logdir + 'blastn.err.log') # print summary of the process after completion print_verbose('Annotation with blastn complete \n') print_running_time(self.time) newline()
def manage_annotation(self): blastn_out = '' metacv_out = '' # run the annotation functions when the module is initialized if self.mode.lower() == 'blastn': # is executable existing and runnable? if is_executable(self.blastn_exe): # start annotation with blastn self.blastn(self.blast_dir) # set the output file for further steps blastn_out = update_reads(self.blast_dir, 'blastn', blast_output(self.outfmt).split('.')[1]) # raise step_number self.step_number += 1 elif self.mode.lower() == 'metacv': # is executable existing and runnable? if is_executable(self.metacv_exe): # start annotation with metacv self.metacv(self.metacv_dir) # set the output file for further steps metacv_out = update_reads(self.metacv_dir, self.metacv_name, 'res') # raise step_number self.step_number += 1 else: # is executable existing and runnable? if is_executable(self.blastn_exe) and is_executable(self.metacv_exe): # start annotation with both tools self.blastn(self.blast_dir) # test for ending and set the right blast output blastn_out = update_reads(self.blast_dir, 'blastn', blast_output(self.outfmt).split('.')[1]) self.metacv(self.metacv_dir) metacv_out = update_reads(self.metacv_dir, self.metacv_name, 'res') # raise step_number self.step_number += 1 return [self.step_number, blastn_out, metacv_out]