def writeSammpleSheets(sample_list, sheet_path, template_sheet): samplesheet_name = os.path.basename(sheet_path) samplesheet_dir = os.path.dirname(os.path.realpath(sheet_path)) count = 0 exit_status = "success" for key in sample_list: count += 1 logger.debug( f"{len(sample_list[key])} samples with idx lengths {key[1]}/{key[2]} for {key[0]} dataset" ) new_sample_sheet = SampleSheet() new_sample_sheet.Header = template_sheet.Header new_sample_sheet.Reads = template_sheet.Reads new_sample_sheet.Settings = template_sheet.Settings for sample in sample_list[key]: new_sample_sheet.add_sample(sample) new_sample_sheet_file = os.path.join( samplesheet_dir, samplesheet_name + ".custom." + str(count) + "." + key[0]) logger.info(f"Creating custom sample sheet: {new_sample_sheet_file}") try: with open(new_sample_sheet_file, "w") as ss_writer: new_sample_sheet.write(ss_writer) except Exception as error: logger.error(f"Exception writing new sample sheet: {error}") exit_status = "failure" logger.debug(f"Created custom sample sheet: {new_sample_sheet_file}") return exit_status
def to_csv(sample_sheet: SampleSheet) -> str: with io.StringIO() as sio: sample_sheet.write(sio) return sio.getvalue()