From 2fe66fde83df9739a8e5ec4fce4045d849658172 Mon Sep 17 00:00:00 2001 From: anastasiia Date: Thu, 10 Jan 2019 13:51:30 +0100 Subject: [PATCH] adding a validation while printing to the output file. If there are problems with start/end positions or max_pos, the footprint will not be written to the output file --- .../footprints_extraction.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/1.1_footprint_extraction/footprints_extraction.py b/bin/1.1_footprint_extraction/footprints_extraction.py index f8fea5a..b340dc7 100644 --- a/bin/1.1_footprint_extraction/footprints_extraction.py +++ b/bin/1.1_footprint_extraction/footprints_extraction.py @@ -529,11 +529,18 @@ def write_to_bed_file(all_footprints, sorted_output_file_name): #write each footprint line for line to the output file for footprint in all_footprints: - #if footprint[1]['start'] >= footprint[1]['end']: - # print(footprint) - #if footprint[1]['max_pos'] == 0: - # print(footprint) - output_file.write('\t'.join([footprint[1]['chromosom'], str(footprint[1]['start']), str(footprint[1]['end']), footprint[0], str(round(footprint[1]['score'], 6)), '.', str(footprint[1]['len']), str(footprint[1]['max_pos']), ';'.join(footprint[1]['bonus'])]) + '\n') + #validation of the footprints, if there is a problem with some of them, write which one it is + #first check the start and end positions + if footprint[1]['start'] >= footprint[1]['end']: + logger.info("The problem occured with start and end positions. This footprint will not be printed to the output file:") + logger.info(footprint) + #then check the max_pos + elif footprint[1]['max_pos'] == 0: + logger.info("The problem occured with max_pos of the footprint. This footprint will not be printed to the output file:") + logger.info(footprint) + #otherwise everything is fine, write to the output + else: + output_file.write('\t'.join([footprint[1]['chromosom'], str(footprint[1]['start']), str(footprint[1]['end']), footprint[0], str(round(footprint[1]['score'], 6)), '.', str(footprint[1]['len']), str(footprint[1]['max_pos']), ';'.join(footprint[1]['bonus'])]) + '\n') output_file.close()