def main(): global recipes, user_path, main_path, desktop_path, code_path, KFV_path, KFP_path, excel_path_recover, excel_path, excel_path_test print('Demo mode: ' + str(demo_mode)) if demo_mode == False: # Read the excel file from the run and obtain the dictionary of samples xls = pd.ExcelFile(excel_path) code_data = pd.read_excel(xls, xls.sheet_names[2]) code_data = code_data.iloc[1:] # generate listed dictionary for sampled plates f = dict() for i, key_row in enumerate(code_data['Table 1'].tolist()): for idx, value in enumerate(code_data.iloc[i][1:]): f.update({key_row + str(idx + 1): value}) thermocycler_values = pd.DataFrame(f, index=[0]).transpose() # count number of declared elements in Dictionary to check with user declared values num_samples_control = 0 for elem in f.values(): if elem != 0: num_samples_control += 1 else: excel_path = excel_path_test xls = pd.ExcelFile(excel_path) code_data = pd.read_excel(xls, xls.sheet_names[2]) code_data = code_data.iloc[1:] # generate listed dictionary for sampled plates f = dict() for i, key_row in enumerate(code_data['Table 1'].tolist()): for idx, value in enumerate(code_data.iloc[i][1:]): f.update({key_row + str(idx + 1): value}) thermocycler_values = pd.DataFrame(f, index=[0]).transpose() # count number of declared elements in Dictionary to check with user declared values num_samples_control = 0 for elem in f.values(): if elem != 0: num_samples_control += 1 print('Num muestras test: ' + str(num_samples_control)) # Get sample data from user control = False while control == False: num_samples = int( input('Número de muestras a procesar (excluidos PC + NC): ')) if (num_samples > 0 and num_samples <= 94): control = True else: print( 'Número de muestras debe ser un número entre 1 y 94 (no incluyas los controles)' ) print( '------------------------------------------------------------------------' ) print('El número de muestras registradas en el excel es: ' + str(num_samples_control)) if num_samples_control != num_samples: print( 'Error: El número de muestras entre excel y reportado no coincide, revisar por favor.' ) exit() else: print('El número de muestras coincide') print( '------------------------------------------------------------------------' ) # Get technician name control = False while control == False: tec_name = '\'' + (input('Nombre del técnico (usuario): ')) + '\'' print( '------------------------------------------------------------------------' ) if isinstance(tec_name, str): tec_name = tec_name.upper() control = True else: print('Introduce tu usuario HUC, por favor') # Get run session ID control = False while control == False: id = (input('ID run: ')) print( '------------------------------------------------------------------------' ) try: id = int(id) except: print('Por favor, assigna un ID numérico para este RUN') if isinstance(id, int): control = True # Get date fecha = datetime.now() t_registro = '\'' + fecha.strftime("%m/%d/%Y, %H:%M:%S") + '\'' h_registro = fecha.strftime("%H:%M") dia_registro = fecha.strftime("%Y_%m_%d") # select the type of protocol to be run [protocol, protocol_path] = select_protocol_type(KFV_path, KFP_path) print( '------------------------------------------------------------------------' ) num_samples_c = math.ceil( num_samples / 8) * 8 # corrected num_samples value to calculate needed volumes num_cols = math.ceil(num_samples_c / 8) final_data = generate_recipe(protocol, num_samples_c, recipes, num_samples) print(final_data) operation_data = { '$technician': str(tec_name), '$num_samples': str(num_samples), '$date': str(t_registro), '$run_id': str(id), '$hora': str(h_registro), '$dia': str(dia_registro), '$num_s_corrected': str(num_samples_c), '$num_cols': str(num_cols), '$MMIX': str(final_data['MMIX'][0]), '$Taqpath': str(final_data['Taqpath'][0]), '$Assay': str(final_data['Assay'][0]), '$Water': str(final_data['Water'][0]) } #determine output path run_name = str(dia_registro) + '_OT' + str(id) + '_' + protocol final_path = os.path.join(main_path, run_name) # create folder directory in case it doesn't already exist and copy excel registry file there if not os.path.isdir(final_path): os.mkdir(final_path) os.mkdir(final_path + '/scripts') os.mkdir(final_path + '/results') thermocycler_values.to_excel(final_path + '/results/' + run_name + '_thermocycler.xlsx', index=True, header=False) os.mkdir(final_path + '/logs') os.system('cp ' + excel_path + ' ' + final_path + '/OT' + str(id) + '_samples.xlsx') # copy excel input file to destination #reset desktop excel file os.system('cp ' + excel_path_recover + ' ' + desktop_path + 'fill.xlsx') if protocol == 'V': os.system('cp ' + main_path + 'covid19huc/Automation/volumes_viral_readme.html' + ' ' + final_path + '/readme.html') pV = generate_multi_well_viral(final_path + '/results', final_data) mini_well = generate_multi_mini_well(final_path + '/results', final_data, protocol) update_readme(final_path, 'readme.html', protocol, [pV, mini_well], operation_data) elif protocol == 'P': os.system('cp ' + main_path + 'covid19huc/Automation/volumes_pathogen_readme.html' + ' ' + final_path + '/readme.html') pB = generate_multi_well_pathogen_IC(final_path + '/results', final_data) pR = generate_multi_well_pathogen_R(final_path + '/results', final_data) mini_well = generate_multi_mini_well(final_path + '/results', final_data, protocol) update_readme(final_path, 'readme.html', protocol, [pR, pB, mini_well], operation_data) else: print('BEWARE! This protocol and ID run already exists! Exitting...') exit() # move protocol .py files to final destination for file in os.listdir(protocol_path): # look for all protocols in folder if file.endswith('.py'): position = re.search( '_template', file).start() # find _ position after the name and get value filename = file[:position] + '_' + str(dia_registro) + '_OT' + str( id) + '.py' # assign a filename date + station name + id os.system('cp ' + os.path.join(protocol_path, file) + ' ' + os.path.join(final_path + '/scripts/', filename)) # change values to protocols for final user for filename in os.listdir(final_path + '/scripts/'): if re.match('KA', filename): update_files(final_path, filename, final_data, operation_data) elif re.match('KB', filename): update_files(final_path, filename, final_data, operation_data) elif re.match('KC', filename): update_files(final_path, filename, final_data, operation_data) else: print('No files found')
def main(): global recipes, user_path, main_path, desktop_path, code_path, KFV_path, KFP_path, excel_path_recover, excel_path, excel_path_test print('Demo mode: ' + str(demo_mode)) if demo_mode == False: # Read the excel file from the run and obtain the dictionary of samples [num_samples_control, thermocycler_values] = thermocycler_generator(excel_path) else: excel_path = excel_path_test [num_samples_control, thermocycler_values] = thermocycler_generator(excel_path) print('Num muestras test: ' + str(num_samples_control)) # Get sample data from user control = False while control == False: num_samples = int( input('Número de muestras a procesar (excluidos PC + NC): ')) if (num_samples > 0 and num_samples <= 94): control = True else: print( 'Número de muestras debe ser un número entre 1 y 94 (no incluyas los controles)' ) print( '------------------------------------------------------------------------' ) print('El número de muestras registradas en el excel es: ' + str(num_samples_control)) if num_samples_control != num_samples: print( 'Error: El número de muestras entre excel y reportado no coincide, revisar por favor.' ) exit() else: print('El número de muestras coincide') print( '------------------------------------------------------------------------' ) # Get technician name control = False while control == False: tec_name = '\'' + (input('Nombre del técnico (usuario): ')) + '\'' print( '------------------------------------------------------------------------' ) if isinstance(tec_name, str): tec_name = tec_name.lower() tec_name = tec_name[0].upper() + tec_name[1:] control = True else: print('Introduce tu usuario HUC, por favor') # Get run session ID if demo_mode == True: id = 1000001 fecha = datetime.now() t_registro = '\'' + fecha.strftime("%m/%d/%Y, %H:%M:%S") + '\'' h_registro = fecha.strftime("%H:%M") dia_registro = fecha.strftime("%Y_%m_%d") else: if not os.path.isdir(id_path): os.mkdir(id_path) id_runs = id_path + '/id_runs.txt' with open(id_runs, 'w') as f: f.write('ID\tdate\thora\tsample_num\n') f.close() if os.path.isdir(id_path): # Get date id_runs = id_path + '/id_runs.txt' fecha = datetime.now() t_registro = '\'' + fecha.strftime("%m/%d/%Y, %H:%M:%S") + '\'' h_registro = fecha.strftime("%H:%M") dia_registro = fecha.strftime("%Y_%m_%d") with open(id_runs, 'r+') as f: lines = f.read().splitlines() last_line = lines[-1] if last_line.split('\t')[0] == 'ID': id = 1 print('The ID for the run will be: ' + '%d' % id + ', on ' + dia_registro + ' ' + h_registro + '\n') f.write('%d' % 1 + '\t' + dia_registro + '\t' + h_registro + '\t' + '%d' % num_samples + '\n') else: id = int(last_line.split('\t')[0]) + 1 print('The ID for the run will be: ' + '%d' % id + ', on ' + dia_registro + ' ' + h_registro + '\n') f.write('%d' % id + '\t' + dia_registro + '\t' + h_registro + '\t' + '%d' % num_samples + '\n') f.close() # select the type of protocol to be run [protocol, protocol_path] = select_protocol_type(KFV_path, KFP_path) print( '------------------------------------------------------------------------' ) num_samples_c = math.ceil( num_samples / 8) * 8 # corrected num_samples value to calculate needed volumes num_cols = math.ceil(num_samples_c / 8) final_data = generate_recipe(protocol, num_samples_c, recipes, num_samples) print(final_data) operation_data = { '$technician': str(tec_name), '$num_samples': str(num_samples), '$date': str(t_registro), '$run_id': str(id), '$hora': str(h_registro), '$dia': str(dia_registro), '$num_s_corrected': str(num_samples_c), '$num_cols': str(num_cols), '$MMIX': str(final_data['MMIX'][0]), '$Taqpath': str(final_data['Taqpath'][0]), '$Assay': str(final_data['Assay'][0]), '$Water': str(final_data['Water'][0]) } #determine output path run_name = str(dia_registro) + '_OT_' + str(id) + '_' + protocol if demo_mode == True: run_name = run_name + '_prueba' final_path = os.path.join(main_path, run_name) # create folder directory in case it doesn't already exist and copy excel registry file there if not os.path.isdir(final_path): os.mkdir(final_path) os.mkdir(final_path + '/scripts') os.mkdir(final_path + '/results') thermocycler_values.to_excel(final_path + '/results/' + run_name + '_thermocycler.xlsx', index=True, header=False) os.mkdir(final_path + '/logs') os.system('cp ' + excel_path + ' ' + final_path + '/OT' + str(id) + '_samples.xlsx') # copy excel input file to destination #reset desktop excel file os.system('cp ' + excel_path_recover + ' ' + desktop_path + 'fill.xlsx') if protocol == 'V': os.system('cp ' + main_path + 'covid19huc/Automation/volumes_viral_readme_linux.html' + ' ' + final_path + '/readme.html') pV = generate_multi_well_viral(final_path + '/results', final_data) mini_well = generate_multi_mini_well(final_path + '\\results', final_data, protocol, num_cols) update_readme(final_path, 'readme.html', protocol, [pV, mini_well], operation_data) elif protocol == 'P': os.system( 'cp ' + main_path + 'covid19huc/Automation/volumes_pathogen_readme_linux.html' + ' ' + final_path + '/readme.html') pB = generate_multi_well_pathogen_IC(final_path + '/results', final_data) pR = generate_multi_well_pathogen_R(final_path + '/results', final_data) mini_well = generate_multi_mini_well(final_path + '\\results', final_data, protocol, num_cols) update_readme(final_path, 'readme.html', protocol, [pR, pB, mini_well], operation_data) else: print('BEWARE! This protocol and ID run already exists! Exitting...') exit() # move protocol .py files to final destination for file in os.listdir(protocol_path): # look for all protocols in folder if file.endswith('.py'): position = re.search( '_template', file).start() # find _ position after the name and get value filename = file[:position] + '_' + str(dia_registro) + '_OT' + str( id) + '.py' # assign a filename date + station name + id os.system('cp ' + os.path.join(protocol_path, file) + ' ' + os.path.join(final_path + '/scripts/', filename)) # change values to protocols for final user for filename in os.listdir(final_path + '/scripts/'): if re.match('KA', filename): update_files(final_path, filename, final_data, operation_data) elif re.match('KB', filename): update_files(final_path, filename, final_data, operation_data) elif re.match('KC', filename): update_files(final_path, filename, final_data, operation_data) else: print('No files found')