From 851fef1e169663bcbcc0fcf168e558afc5969a1a Mon Sep 17 00:00:00 2001 From: ASLeonard Date: Tue, 2 Apr 2024 14:36:45 +0200 Subject: [PATCH] generalise to reading and writing in pipes --- util/RM2Bed.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/util/RM2Bed.py b/util/RM2Bed.py index c1797ca..b2c8ec5 100755 --- a/util/RM2Bed.py +++ b/util/RM2Bed.py @@ -203,6 +203,8 @@ def openOptGzipFile(filename, modes='r'): Returns: A file object """ + if filename == "-": + return sys.stdin f = open(filename, 'b'+modes) # First two byte signature of a gzip'd file if (f.read(2) == b'\x1f\x8b'): @@ -437,7 +439,7 @@ def __call__(self, parser, args, values, option_string=None): LOGGER.info("#\n# RM2Bed.py\n#") - if ( not os.path.exists(args.rm_file) ): + if args.rm_file != '-' and ( not os.path.exists(args.rm_file) ): raise Exception("File " + args.rm_file + " is missing.") LOGGER.info("Data File: " + args.rm_file) @@ -770,12 +772,12 @@ def __call__(self, parser, args, values, option_string=None): # Write as monolithic file if args.output_bed == '-': - output_bed = "/dev/stdout" + output_bed = sys.stdout elif args.output_bed is not None: output_bed = args.output_bed else: output_bed = file_prefix + '_rm.bed' - LOGGER.info("Creating: " + output_bed) + LOGGER.info("Creating: " + str(output_bed)) annot_dataframe.to_csv(output_bed, sep='\t', header=False, index=False) #