def convert_csv_to_ini(self,new_ini_file): #print self.args from pipeline.get_ini import readCSV print 'CSV path',self.general_config_dict['csvPath'] my_csv = readCSV(file_path = self.general_config_dict['csvPath']) content = my_csv.read_csv() headers = content[1].keys() headers_clean = [x.strip('"').replace(" ", "_").lower() for x in headers] projects = {} #print #print content[1] #print # get list of keys keys_list = [] if self.check_headers(headers_clean): logger.info("CSV headers okay") for k,values in content.iteritems(): keys_list.append(values['barcode_index']+"_"+values['run_key']+"_"+values['lane']) fh = open(new_ini_file,'w') # general section fh.write("#\n#\tCreated by MBL Pipeline for run: "+self.general_config_dict['run']+" on "+self.general_config_dict['date']+"\n#\n\n") fh.write("[general]\n") fh.write("run = "+self.general_config_dict['run']+"\n") fh.write("configPath = "+new_ini_file+"\n") fh.write("configPath_orig = "+self.general_config_dict['configPath']+"\n") fh.write("platform = "+self.general_config_dict['platform']+"\n") fh.write("output_dir = " + self.general_config_dict['output_dir']+"\n") #fh.write("output_dir = "+os.path.join(self.general_config_dict['baseoutputdir'],self.general_config_dict['run'])+"\n") if self.general_config_dict['platform'] == 'illumina': #fh.write("input_file_suffix = " + self.general_config_dict['input_file_suffix']+"\n") fh.write("input_file_format = " + self.general_config_dict['input_file_format']+"\n") fh.write("anchor_file = " + self.general_config_dict['anchor_file']+"\n") fh.write("primer_file = " + self.general_config_dict['primer_file']+"\n") fh.write("compressed = " + str(self.general_config_dict['compressed'])+"\n") fh.write("database_host = " + self.general_config_dict['database_host']+"\n") fh.write("database_name = " + self.general_config_dict['database_name']+"\n") fh.write("input_dir = " + self.general_config_dict['input_dir']+"\n") fh.write("require_distal = " + str(self.general_config_dict['require_distal'])+"\n") fh.write("use_cluster = " + str(self.general_config_dict['use_cluster'])+"\n") fh.write("date = " + str(datetime.date.today())+"\n") fh.write("idx_keys = " +','.join(keys_list)+"\n") if 'input_dir' in self.general_config_dict and self.general_config_dict['input_dir'] != '': file_list = self.get_input_files() fh.write("input_files = " + ','.join(file_list)+"\n") else: fh.write("input_files = \n") #fh.write(getattr(args,'force_runkey', "")) for k,values in content.iteritems(): fh.write("\n") if self.general_config_dict['platform'] == 'illumina': fh.write("["+values['barcode_index']+"_"+values['run_key']+"_"+values['lane']+"]\n") elif self.general_config_dict['platform'] == '454': fh.write("["+values['lane']+"_"+values['run_key']+"]\n") for v in values: fh.write(v+" = "+values[v]+"\n") fh.close() return new_ini_file
def convert_csv_to_ini(self, new_ini_file): #print self.args from pipeline.get_ini import readCSV print 'CSV path', self.general_config_dict['csvPath'] my_csv = readCSV(file_path = self.general_config_dict['csvPath']) content = my_csv.read_csv() headers = content[1].keys() headers_clean = [x.strip('"').replace(" ", "_").lower() for x in headers] projects = {} #print #print content[1] #print # get list of keys keys_list = [] if self.check_headers(headers_clean): logger.info("CSV headers okay") for k,values in content.iteritems(): keys_list.append(values['barcode_index']+"_"+values['run_key']+"_"+values['lane']) fh = open(new_ini_file,'w') # general section fh.write("#\n#\tCreated by MBL Pipeline for run: "+self.general_config_dict['run']+" on "+self.general_config_dict['date']+"\n#\n\n") fh.write("[general]\n") fh.write("run = "+self.general_config_dict['run']+"\n") fh.write("configPath = "+new_ini_file+"\n") fh.write("configPath_orig = " + self.general_config_dict['configPath']+"\n") fh.write("platform = " + self.general_config_dict['platform']+"\n") fh.write("output_dir = " + os.path.dirname(new_ini_file)+"\n") #fh.write("output_dir = "+os.path.join(self.general_config_dict['baseoutputdir'],self.general_config_dict['run'])+"\n") if self.general_config_dict['platform'] == 'illumina': #fh.write("input_file_suffix = " + self.general_config_dict['input_file_suffix']+"\n") fh.write("input_file_format = " + self.general_config_dict['input_file_format']+"\n") fh.write("anchor_file = " + self.general_config_dict['anchor_file']+"\n") fh.write("primer_file = " + self.general_config_dict['primer_file']+"\n") fh.write("compressed = " + str(self.general_config_dict['compressed'])+"\n") fh.write("do_perfect = " + str(self.general_config_dict['do_perfect'])+"\n") fh.write("lane_name = " + str(self.general_config_dict['lane_name'])+"\n") fh.write("database_host = " + self.general_config_dict['database_host']+"\n") fh.write("database_name = " + self.general_config_dict['database_name']+"\n") fh.write("input_dir = " + self.general_config_dict['input_dir']+"\n") fh.write("require_distal = " + str(self.general_config_dict['require_distal'])+"\n") fh.write("use_cluster = " + str(self.general_config_dict['use_cluster'])+"\n") fh.write("date = " + str(datetime.date.today())+"\n") fh.write("site = " + self.general_config_dict['site']+"\n") fh.write("load_vamps_database = " + str(self.general_config_dict['load_vamps_database'])+"\n") fh.write("idx_keys = " +','.join(keys_list)+"\n") if 'input_dir' in self.general_config_dict and self.general_config_dict['input_dir'] != '': file_list = self.get_input_files() fh.write("input_files = " + ','.join(file_list)+"\n") else: fh.write("input_files = \n") #fh.write(getattr(args,'force_runkey', "")) for k, values in content.iteritems(): fh.write("\n") if self.general_config_dict['platform'] == 'illumina': fh.write("["+values['barcode_index']+"_"+values['run_key']+"_"+values['lane']+"]\n") elif self.general_config_dict['platform'] == '454': fh.write("["+values['lane']+"_"+values['run_key']+"]\n") for v in values: if v == "env_sample_source": try: new_val = [str(j[0]) for j in self.env if j[1] == values[v]][0] except: print """There was an error in env_sample_source. Please check your metadata. Possible values: ----------- air extreme habitat host associated human associated human-amniotic-fluid human-blood human-gut human-oral human-skin human-urine human-vaginal indoor microbial mat/biofilm miscellaneous_natural_or_artificial_environment plant associated sediment soil/sand unknown wastewater/sludge water-freshwater water-marine ----------- """ raise fh.write("env_sample_source_id = "+new_val+"\n") else: fh.write(v+" = "+values[v]+"\n") fh.close() return new_ini_file
def convert_csv_to_ini(self, new_ini_file): #print(self.args) from pipeline.get_ini import readCSV print('CSV path', self.general_config_dict['csvPath']) my_csv = readCSV(file_path = self.general_config_dict['csvPath']) content = my_csv.read_csv() headers = content[1].keys() headers_clean = [x.strip('"').replace(" ", "_").lower() for x in headers] projects = {} #print #print(content[1]) #print # get list of keys keys_list = [] if self.check_headers(headers_clean): logger.info("CSV headers okay") for k,values in content.items(): keys_list.append(values['barcode_index']+"_"+values['run_key']+"_"+values['lane']) fh = open(new_ini_file,'w') # general section fh.write("#\n#\tCreated by MBL Pipeline for run: "+self.general_config_dict['run']+" on "+self.general_config_dict['date']+"\n#\n\n") fh.write("[general]\n") fh.write("run = "+self.general_config_dict['run']+"\n") fh.write("configPath = "+new_ini_file+"\n") fh.write("configPath_orig = " + self.general_config_dict['configPath']+"\n") fh.write("platform = " + self.general_config_dict['platform']+"\n") fh.write("output_dir = " + os.path.dirname(new_ini_file)+"\n") #fh.write("output_dir = "+os.path.join(self.general_config_dict['baseoutputdir'],self.general_config_dict['run'])+"\n") if self.general_config_dict['platform'] in C.illumina_list: #fh.write("input_file_suffix = " + self.general_config_dict['input_file_suffix']+"\n") fh.write("input_file_format = " + self.general_config_dict['input_file_format']+"\n") fh.write("anchor_file = " + self.general_config_dict['anchor_file']+"\n") fh.write("primer_file = " + self.general_config_dict['primer_file']+"\n") fh.write("compressed = " + str(self.general_config_dict['compressed'])+"\n") fh.write("do_perfect = " + str(self.general_config_dict['do_perfect'])+"\n") fh.write("lane_name = " + str(self.general_config_dict['lane_name'])+"\n") fh.write("database_host = " + self.general_config_dict['database_host']+"\n") fh.write("database_name = " + self.general_config_dict['database_name']+"\n") fh.write("input_dir = " + self.general_config_dict['input_dir']+"\n") fh.write("require_distal = " + str(self.general_config_dict['require_distal'])+"\n") fh.write("use_cluster = " + str(self.general_config_dict['use_cluster'])+"\n") fh.write("date = " + str(datetime.date.today())+"\n") fh.write("site = " + self.general_config_dict['site']+"\n") fh.write("load_vamps_database = " + str(self.general_config_dict['load_vamps_database'])+"\n") fh.write("idx_keys = " +','.join(keys_list)+"\n") if 'input_dir' in self.general_config_dict and self.general_config_dict['input_dir'] != '': file_list = self.get_input_files() fh.write("input_files = " + ','.join(file_list)+"\n") else: fh.write("input_files = \n") #fh.write(getattr(args,'force_runkey', "")) for k, values in content.items(): fh.write("\n") if self.general_config_dict['platform'] in C.illumina_list: fh.write("["+values['barcode_index']+"_"+values['run_key']+"_"+values['lane']+"]\n") elif self.general_config_dict['platform'] == '454': fh.write("["+values['lane']+"_"+values['run_key']+"]\n") for v in values: if v == "env_sample_source": try: new_val = [str(j[0]) for j in self.env if j[1] == values[v]][0] except: text = """There was an error in env_sample_source. Please check your metadata. Possible values: ----------- air extreme habitat host associated human associated human-amniotic-fluid human-blood human-gut human-oral human-skin human-urine human-vaginal indoor microbial mat/biofilm miscellaneous_natural_or_artificial_environment plant associated sediment soil/sand unknown wastewater/sludge water-freshwater water-marine ----------- """ print(text) raise fh.write("env_sample_source_id = "+new_val+"\n") else: fh.write(v+" = "+values[v]+"\n") fh.close() return new_ini_file