def _read_input_csv(in_file): """Parse useful details from SampleSheet CSV file. """ # Sanitize raw file before opening with csv reader #_sanitize(in_file) try: with open(in_file, "rU") as in_handle: dialect = csv.excel reader = csv.DictReader(in_handle, dialect=dialect) for line in reader: if line: # skip empty lines # convert '__' to '.' for key, val in line.items(): if val is not None and type(val) is str: line[key] = val.replace('__', '.') yield line['FCID'], line['Lane'], line['SampleID'], \ line['SampleRef'], line['Index'], line['Description'], \ line.get('Recipe', None), line.get('Operator', None), \ line.get('SampleProject', line['Description']) except ValueError: log.warning("Corrupt samplesheet %s, please fix it" % in_file) pass
def _read_input_csv(in_file): """Parse useful details from SampleSheet CSV file. """ # Sanitize raw file before opening with csv reader # _sanitize(in_file) try: with open(in_file, "rU") as in_handle: dialect = csv.excel reader = csv.DictReader(in_handle, dialect=dialect) for line in reader: if line: # skip empty lines # convert '__' to '.' for key, val in line.items(): if val is not None and type(val) is str: line[key] = val.replace("__", ".") yield line["FCID"], line["Lane"], line["SampleID"], line["SampleRef"], line["Index"], line[ "Description" ], line.get("Recipe", None), line.get("Operator", None), line.get( "SampleProject", line["Description"] ) except ValueError: log.warning("Corrupt samplesheet %s, please fix it" % in_file) pass
def __init__(self, project_name, config): """Initialize the object""" col_mapping = self.column_mapping() name_column = col_mapping["project_name"] columns = [] attributes = [] for attr, col in col_mapping.items(): columns.append(col) attributes.append(attr) setattr(self, attr, None) # Get the credentials encoded_credentials = bcbio.google.get_credentials(config) assert encoded_credentials is not None, \ "The Google Docs credentials could not be found." # Get the name of the spreadsheet where uppnex ids can be found gdocs_config = config.get("gdocs_upload", {}) ssheet_title = gdocs_config.get("projects_spreadsheet", None) wsheet_title = gdocs_config.get("projects_worksheet", None) assert ssheet_title is not None and wsheet_title is not None, \ "The names of the projects spreadsheet and worksheet on Google \ Docs could not be found." # Connect to the spread- and worksheet client = bcbio.google.spreadsheet.get_client(encoded_credentials) ssheet = bcbio.google.spreadsheet.get_spreadsheet(client, ssheet_title) assert ssheet is not None, \ "Could not fetch %s from Google Docs." % ssheet_title # We allow multiple, comma-separated worksheets to be searched for wtitle in wsheet_title.split(','): wsheet = bcbio.google.spreadsheet.get_worksheet(client, ssheet, wtitle.strip()) if not wsheet: logger2.warning("Could not locate %s in %s." % (wsheet_title, ssheet_title)) continue # Get the rows for the project rows = bcbio.google.spreadsheet.get_rows_columns_with_constraint( \ client, ssheet, wsheet, columns, {name_column: project_name}) if len(rows) == 0: continue # Will only use the first result found to set each attribute for i, val in enumerate(rows[0]): setattr(self, attributes[i], val) # We have found the project data so stop iterating break
def _log_messages(self, log_handler, subject="Test email"): try: with log_handler.applicationbound(): with logbook.Processor(lambda record: record.extra.__setitem__('run', subject)): logger2.debug("DEBUG record test generated @ %s" % time.strftime("%x - %X")) logger2.info("INFO record test generated @ %s" % time.strftime("%x - %X")) logger2.notice("NOTICE record test generated @ %s" % time.strftime("%x - %X")) logger2.warning("WARNING record test generated @ %s" % time.strftime("%x - %X")) logger2.error("ERROR record test generated @ %s" % time.strftime("%x - %X")) logger2.critical("CRITICAL record test generated @ %s" % time.strftime("%x - %X")) except Exception as e: return e return None
def _log_messages(self, log_handler, subject="Test email"): try: with log_handler.applicationbound(): with logbook.Processor(lambda record: record.extra.__setitem__( 'run', subject)): logger2.debug("DEBUG record test generated @ %s" % time.strftime("%x - %X")) logger2.info("INFO record test generated @ %s" % time.strftime("%x - %X")) logger2.notice("NOTICE record test generated @ %s" % time.strftime("%x - %X")) logger2.warning("WARNING record test generated @ %s" % time.strftime("%x - %X")) logger2.error("ERROR record test generated @ %s" % time.strftime("%x - %X")) logger2.critical("CRITICAL record test generated @ %s" % time.strftime("%x - %X")) except Exception as e: return e return None