示例#1
0
 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()
示例#2
0
    def manage_assembly(self):
        
        concatinated = ''
        assembled = ''
        # run the assembling functions when the module is initialized
        if self.mode.lower() == 'flash':
            # is executable existing and runnable?
            if is_executable(self.flash_exe):
                # start concatination and update the input for next step
                self.concatinate(self.concat_out)
                self.step_number += 1
                # merge the concatinated reads with non concatinated rest
                if (self.merge_uncombined):
                    self.input = merge_files([to_string(update_reads(self.concat_out, 'extendedFrags', 'fastq')),
                                             to_string(update_reads(self.concat_out, 'out.notCombined', 'fastq'))],
                                             self.concat_out,
                                             'merged_concat','fastq')
                else:
                    concatinated = update_reads(self.concat_out, 'extendedFrags', 'fastq')
                    self.input = concatinated
                

        if self.mode.lower() == 'metavelvet':
            # is executable existing and runnable?
            if is_executable(self.velveth_exe) and is_executable(self.velveth_exe) and is_executable(self.metavelvet_exe):
                # start assembly and update the input for next step
                self.assemble_reads(self.assembly_out)
                assembled = update_reads(self.assembly_out, 'meta-velvetg', 'fa')
                self.input = assembled
                self.step_number += 1
                
        if self.mode.lower() == 'both':
            #TODO: not working because of auto mode --> see logs
            
            # is executable existing and runnable?
            if is_executable(self.flash_exe) and is_executable(self.velveth_exe) and is_executable(self.velveth_exe) and is_executable(self.metavelvet_exe):
                # start processing and update the input for next step
                self.concatinate(self.concat_out)
                concatinated = update_reads(self.out, 'extendedFrags', 'fastq')
                self.input = concatinated
                self.assemble_reads(self.assembly_out)
                assembled = update_reads(self.assembly_out, 'meta-velvetg', 'fa')
                self.step_number += 1
                self.input = assembled
        return [self.step_number, self.input, concatinated, assembled]