def __init__(self, log_dir, process_names=[]): os.chdir(log_dir) if process_names is None: process_names = [] self.process_names = process_names for device_dir in self.list_device_dirs(): logger.info('create report for %s' % device_dir) core_num = 1 try: with open(os.path.join(device_dir, 'corenum.txt'), 'r') as f: core_num = int(f.read()) except: pass file_names = self.filter_file_names(device_dir) logger.debug('%s' % file_names) if file_names: book_name = '%s-%s.xlsx' % (device_dir, datetime.now().strftime('%Y.%m.%d-%H.%M.%S')) excel = Excel(book_name) for file_name in file_names: name = file_name.split('.')[0] info = INFO_CONFIG.get(name)(device_dir, file_name, process_names, core_num) for sheet in info.get_sheet_list(): logger.info('add sheet %s' % sheet[0]) excel.add_sheet(*sheet) logger.info('wait to save %s' % book_name) excel.save()
def onButton_data(self, event): """ This method is fired when its corresponding button is pressed """ openDirDialog = wx.DirDialog(self.panel1, 'Choose input directory', '.', wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST) # if openDirDialog.ShowModal() != wx.ID_CANCEL: # ---------------------------------------- # Get all data files # ---------------------------------------- patients = {} for filename in glob.glob(openDirDialog.GetPath() + os.sep + '*.txt'): file_content = AminoacidAnalyzes_file(filename) if file_content.patient not in patients: patients[file_content.patient] = Patient() patients[file_content.patient].add_data(file_content) # # ---------------------------------------- # Create result folder # ---------------------------------------- folder = ''.join((openDirDialog.GetPath(), os.sep, '..', os.sep, 'result', os.sep)) if not os.path.isdir(folder): os.makedirs(folder) # ---------------------------------------- # Go through each patient data and create an excel file for each # ---------------------------------------- uptakes = {} for patient in patients: print patient patients[patient].calculate_average() # ---------------------------------------- # Create Excel file # ---------------------------------------- excelfile = Excel() # ---------------------------------------- # Raw data # ---------------------------------------- excelfile.add_sheet('raw data', patients[patient].raw_data()[1]) # ---------------------------------------- # Concentration # ---------------------------------------- excelfile.add_sheet('concentration', patients[patient].raw_data()[0]) # ---------------------------------------- # Mean + Std # ---------------------------------------- excelfile.add_sheet('mean', patients[patient].mean_std()) # ---------------------------------------- # Normalized to aminoacid # ---------------------------------------- for i in xrange(len(patients[patient].aa)): # new = np.array(patients[patient].normalized(-1, i)) if i == 0: a = new else: a = np.concatenate((a, new), axis = 1) # excelfile.add_sheet('normalized', a) # ---------------------------------------- # Uptake # ---------------------------------------- excelfile.add_sheet('uptake', patients[patient].normalized(0, -1)) # ---------------------------------------- # Uptake normalized # ---------------------------------------- for i in xrange(len(patients[patient].aa)): new = np.array(patients[patient].normalized(0, i)) if i == 0: a = new else: a = np.concatenate((a, new), axis = 1) # excelfile.add_sheet('uptake normalized', a) # ---------------------------------------- # Save Excel datafile # ---------------------------------------- excelfile.save_excel_file(folder + patient + '.xls') # ---------------------------------------- # Uptake is Arg # ---------------------------------------- uptakes[patient] = patients[patient].uptake(7) # ---------------------------------------- # Create a file with all results # ---------------------------------------- excelfile = Excel() groups = list(set([key.split('-')[0] for key in uptakes.keys()])) groups.sort() patient_data = [['patient'] + patients[uptakes.keys()[0]].samples] for group in groups: keys = [] group_data = [] for key in uptakes.keys(): if group in key: keys.append(key) group_data.append(uptakes[key]) group_data = np.array(group_data) mean = group_data.mean(axis = 0) std = group_data.std(axis = 0) for key in keys: patient_data.append([key] + uptakes[key]) patient_data.append(['' for _ in xrange(len(mean)+1)]) patient_data.append(['Mean'] + list(mean)) patient_data.append(['Std'] + list(std)) patient_data.append(['' for _ in xrange(len(mean)+1)]) patient_data.append(['' for _ in xrange(len(mean)+1)]) patient_data = np.array(patient_data) excelfile.add_sheet('patient_data', patient_data.T) excelfile.save_excel_file(folder + 'patients.xls') # ---------------------------------------- # Finish # ---------------------------------------- self.button_data.Label = 'Saved!' # openDirDialog.Destroy() # return None