def __init__(self,config,sample_keys=None,number=None,key=int(-1),flowcell=None,input_dir=None,base_output_dir=None,output_dir=None,date=strftime("%Y%m%d",localtime()),time=strftime("%H:%M:%S",localtime()),process_name='flowcell_report',complete_file=None,**kwargs): """ Initializes flowcell statistic report. """ if flowcell is None: flowcell = Flowcell(config,key="dummy_flowcell_key") if flowcell.__class__.__name__ != "Flowcell": raise Exception("Trying to start a flowcell statistics reports object on a non-flowcell.") if output_dir is None: if base_output_dir is None: base_output_dir = config.get('Common_directories','flowcell_reports') self.output_dir = os.path.join(os.path.join(base_output_dir,flowcell.key + "_reports"),str(number)) else: self.output_dir = output_dir if complete_file is None: self.complete_file = os.path.join(self.output_dir,"report_" + str(number) + ".complete") else: self.complete_file = complete_file QsubProcess.__init__(self,config,key=key,input_dir=input_dir,base_output_dir=base_output_dir,output_dir=self.output_dir,date=date,time=time,process_name=process_name,complete_file=self.complete_file,**kwargs) self.flowcell_key = flowcell.key if sample_keys is None: self.sample_keys = "" else: self.sample_keys = ";".join(sample_keys) self.number = number #List of samples from the project self.all_samples_file = os.path.join(self.output_dir,'all_samples.ls') if self.key != -1: write_list_file(sample_keys,self.all_samples_file,original_list_file=config.get('Filenames','all_samples')) self.current_samples_file = os.path.join(self.output_dir,'current_samples.ls') if self.key != -1: write_list_file(sample_keys,self.current_samples_file) #Output files self.full_report = os.path.join(self.output_dir,'all_samples_report.csv') self.current_report = os.path.join(self.output_dir,'current_samples_report.csv') self.concordance_jpeg = os.path.join(self.output_dir,'concordance_vs_depth.jpeg') self.dbsnp_jpeg = os.path.join(self.output_dir,'dbsnp_vs_depth.jpeg') self.greater_than_10x_jpeg = os.path.join(self.output_dir,'greater_than_10x_vs_depth.jpeg') self.zero_coverage_jpeg = os.path.join(self.output_dir,'zero_coverage_vs_depth.jpeg') self.hethomratio_jpeg = os.path.join(self.output_dir,'hethomratio_vs_depth.jpeg') self.reads_jpeg = os.path.join(self.output_dir,'reads_vs_depth.jpeg') self.report_pdf = os.path.join(self.output_dir,self.flowcell_key + '_report.pdf') #Flag to keep track if report has been sent self.report_sent = False
def __send_reports__(self,config,mockdb): """ For reports that have generated but not been sent, this script attaches the appropriate plots and tables and sends the email. """ numbers = config.get('Flowcell_reports','numbers').split(',') for number in numbers: flowcell_report_key = getattr(self,'flowcell_report_' + str(number) + '_key') if flowcell_report_key is None: continue report = mockdb['FlowcellStatisticReport'].objects[flowcell_report_key] if report.report_sent is True: #If the report is already sent, next. continue if not report.__is_complete__(): #If the qsub script is still running, next. continue if self.sequencing_run_type == 'RapidRun' and str(number) == '16': recipients = config.get('Flowcell_reports','last_recipients') subject, body = report.__generate_flowcell_report_text__(config,mockdb,report_type="last_report") #Add samples to the all sample list sample_keys = self.__completed_samples_list__(mockdb) write_list_file(sample_keys,config.get('Filenames','all_samples'),original_list_file=config.get('Filenames','all_samples')) self.__finish__() elif self.sequencing_run_type == 'HighThroughputRun' and str(number) == '64': recipients = config.get('Flowcell_reports','last_recipients') subject, body = report.__generate_flowcell_report_text__(config,mockdb,report_type="last_report") #Add samples to the all sample list sample_keys = self.__completed_samples_list__(mockdb) write_list_file(sample_keys,config.get('Filenames','all_samples'),original_list_file=config.get('Filenames','all_samples')) self.__finish__() else: recipients = config.get('Flowcell_reports','subset_recipients') subject, body = report.__generate_flowcell_report_text__(config,mockdb,report_type="subset_report") files = [] files.append(report.report_pdf) files.append(report.full_report) files.append(report.current_report) send_email(subject,body,recipients=recipients,files=files) report.__finish__() report.report_sent = True return 1