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_preprocessing(self): # run the preprocessing functions when the module is initialized try: is_fastq(self.input) except FastQException: self.quality = False self.trim = False if self.quality: # is executable existing and runnable? if is_executable(self.fastqc_exe): self.qualityCheck() # raise the step number for cmd output self.step_number += 1 #self.files.set_quality_report() if self.trim: if is_executable(self.trim_exe): self.trim_and_filter() # raise the step number for cmd output self.step_number += 1 return [self.step_number, update_reads(self.trim_dir, 'val', 'fq')] else: return [self.step_number]