Ejemplo n.º 1
0
 def manage_analysis(self):
     
    
     if self.annotation_mode in 'metacv':
         print_verbose("For a detailed analysis blastn with XML output is needed")
     else:
         # test for blastrun with outfmt 5 mode
         if is_xml(self.blast_output):
             # create a SQLite DB from the xml file
             self.parse_to_db(to_string(self.blast_output), self.parsed_db_out)
             # test the exit code, because next script need the output as input
             if self.exitcode is 0:
                 # update input 
                 parser_out = absolute_path(update_reads(self.parsed_db_out, 
                                                         self.parser_name, 
                                                         'db'))
                 # raise step_number
                 self.step_number += 1
                 # create a new database with taxonomical annotations
                 self.annotate_db(parser_out, self.annotated_db_out)
                 # test the exit code, because next script need the output as input
                 if self.exitcode is 0:
                     # update input
                     annotated_output = absolute_path(update_reads(self.annotated_db_out, 
                                                                   self.R_annotate_name, 
                                                                   'db'))
                     # raise step_number
                     self.step_number += 1
                     # subset the taxonomical database for a better and 
                     # faster analysis after the pipline has finished
                     self.subset_db(annotated_output, self.subseted_db_out, parser_out)
                     # raise step_number
                     self.step_number += 1
                 else:
                     print_verbose("ERROR: Annotated Database could not be subseted correctly") 
                 # create a pie chart of the blast data with Krona Webtools 
                 if self.krona:
                     self.krona_report(self.blast_output, self.krona_report_out, parser_out)
                     
                 return [parser_out, annotated_output]   
             else: 
                 print_verbose("ERROR: XML file could not be parsed")
         # test for blast tabular output
         elif is_tabular(self.blast_output) and self.krona is True:
             self.krona_report(self.blast_output, self.krona_report_out, '')
             return []
         else:
             print_verbose("ERROR: Blast output file is not in xml or tabular format.\n" +
                           "Please use outfmt 5 or 6 for Blast run")
             return []
Ejemplo n.º 2
0
 def krona_report(self, input, output, parser_output):
     
     # create a dir for output
     create_outputdir(output)
     # generate path and name for output file
     outfile = output + os.sep + self.krona_name + '.html'
     
     # test type of input file
     if is_tabular(input):
         # print actual informations about the step on stdout    
         print_step(self.step_number, 
                    'Analysis', 
                    'Create Overview from tabular output',
                    self.krona_parameter)
         newline()
         
         # start the Krona import script for Blast tabular output
         # pipe all output for stdout in a logfile
         p = subprocess.Popen(shlex.split('perl -l %s %s -o %s %s %s' 
                                          % (self.perl_lib,
                                             self.krona_exe,
                                             outfile,
                                             self.krona_parameter,
                                             to_string(input))),
                              stdout = open_logfile(self.logdir + 'krona.log'),
                              stderr = open_logfile(self.logdir + 'krona.err.log'))
         # wait until process is complete
         p.wait()
         if p.returncode:
             raise KronaException(self.logdir + 'krona.err.log')
         else:
             # remove unused error logs
             remove_empty_logfile(self.logdir + 'krona.err.log')
             # print summary of the process after completion
             print_verbose('Creation of Krona Pie Chart complete \n')
             print_running_time(self.time)
             newline()
         
     elif is_xml(input) and is_db(parser_output):
         print_step(self.step_number, 
                    'Analysis', 
                    'Create Overview from XML output',
                    self.krona_parameter)
         # convert the values from database to tabular format
         extract_tabular(to_string(parser_output), output)
         # set the new input
         input = update_reads(output, 'extracted_from_DB','tab')
         
         # start the Krona import script for Blast tabular output
         # pipe all output for stdout in a logfile
         p = subprocess.Popen(shlex.split('perl -l %s %s -o %s %s %s' 
                                          % (self.perl_lib,
                                             self.krona_exe,
                                             outfile,
                                             self.krona_parameter,
                                             to_string(input))),
                              stdout = open_logfile(self.logdir + 'krona.log'),
                              stderr = open_logfile(self.logdir + 'krona.err.log'))
         # wait until process is complete
         p.wait()
         if p.returncode:
             raise KronaException(self.logdir + 'krona.err.log')
         else:
             # remove unused error logs
             remove_empty_logfile(self.logdir + 'krona.err.log')
             # print summary of the process after completion
             print_verbose('Creation of Krona Pie Chart complete \n')
             print_running_time(self.time)
             newline()
         
     elif not is_tabular(input) or not is_xml(input):
         raise KronaFormatException()
     else:
         print_verbose('ERROR 25: Krona Report could not be generated, because of unknown reasons')
         sys.exit(1)