From 33111d3e0c299a2634dc4a3649d04b6287deac95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kmiecinski?= Date: Thu, 11 Oct 2018 19:18:51 +0200 Subject: [PATCH] Activated the "not found" bin changed exception handling to accomodate reads that are not present in a provided classification file. bin.py:write_read_class Introducing function local variable only_warn (default=True) that allows for not found reads. Also echoing a warning to stderr and choose not to increment the bin counter bin.py:print_summary_and_zip casting odict_keys(Object) classnames to list to enable subsequent append to work. --- deepbinner/bin.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/deepbinner/bin.py b/deepbinner/bin.py index ba298b3..7f844dc 100644 --- a/deepbinner/bin.py +++ b/deepbinner/bin.py @@ -141,13 +141,23 @@ def write_read_files(reads_filename, classifications, out_filenames, input_type) read_class = 'not found' class_name = class_to_class_names(read_class) + only_warn = True + try: + out_files[class_name].write(read_line_1) + out_files[class_name].write(read_line_2) + out_files[class_name].write(read_line_3) + out_files[class_name].write(read_line_4) + except KeyError as k_err: + err = KeyError("%s: %s\n read_id: %s" % (k_err, class_name, + read_id)) + if only_warn: + print( + 'Warning: %s - not found in classification' % read_id, + file=sys.stderr) + else: + raise err bin_counts[class_name] += 1 - out_files[class_name].write(read_line_1) - out_files[class_name].write(read_line_2) - out_files[class_name].write(read_line_3) - out_files[class_name].write(read_line_4) - print_progress(count, carriage_return=False) print('\n') @@ -190,7 +200,7 @@ def print_summary_and_zip(bin_counts, out_filenames): gzip = 'gzip' print('Gzipping reads:') print(' Barcode Reads File') - class_names = out_filenames.keys() + class_names = list(out_filenames.keys()) if 'not found' in bin_counts: class_names.append('not found') for class_name in class_names: -- 2.1.4