|
4 | 4 |
|
5 | 5 | # Standard Library |
6 | 6 | from __future__ import print_function |
| 7 | +from datetime import datetime |
7 | 8 | from textwrap import dedent |
8 | 9 | import argparse, gzip, os, sys |
9 | 10 |
|
@@ -109,6 +110,30 @@ def fatal(*message, **kwargs): |
109 | 110 | sys.exit(1) |
110 | 111 |
|
111 | 112 |
|
| 113 | +def timestamp(format="%Y-%m-%d %H:%M:%S"): |
| 114 | + """Returns a formatted timestamp string |
| 115 | + for the current time. |
| 116 | + @param format <str>: |
| 117 | + Format string for the timestamp, default: |
| 118 | + "%Y-%m-%d %H:%M:%S" which is equivalent to |
| 119 | + "2023-10-01 12:00:00" for example. |
| 120 | + @return <str>: |
| 121 | + Formatted timestamp string, i.e. "2023-10-01 12:00:00" |
| 122 | + """ |
| 123 | + return datetime.now().strftime(format) |
| 124 | + |
| 125 | + |
| 126 | +def log(*message): |
| 127 | + """Logs a message to standard output with a timestamp. |
| 128 | + @param message <any>: |
| 129 | + Values printed to log |
| 130 | + """ |
| 131 | + print("[{0}] {1}".format( |
| 132 | + timestamp(), |
| 133 | + " ".join([str(m) for m in message])) |
| 134 | + ) |
| 135 | + |
| 136 | + |
112 | 137 | def check_permissions(parser, path, *args, **kwargs): |
113 | 138 | """Checks permissions using os.access() to see the |
114 | 139 | user is authorized to access a file/directory. Checks |
@@ -271,6 +296,7 @@ def index_file(file, keys, key_delim, values): |
271 | 296 | keys=["A","B"], values["C","D"], key_delim="|" |
272 | 297 | returns {"A|B": {"C": "c_i", "D": "d_i"}} |
273 | 298 | """ |
| 299 | + log("Started indexing input file: {0}".format(file)) |
274 | 300 | file_idx = {} |
275 | 301 | # Handler for opening files, i.e. |
276 | 302 | # uncompressed or gzip files |
@@ -348,6 +374,7 @@ def get_additional_annotation_information(annotation_dict, first_key, values): |
348 | 374 | # Nothing was provided |
349 | 375 | fatal('Invalid usage: {0} [-h] ...'.format(os.path.basename(sys.argv[0]))) |
350 | 376 |
|
| 377 | + log("Running leafcutter annotation script with the following options: ", args) |
351 | 378 | # Create output directory if |
352 | 379 | # it does not exist |
353 | 380 | output_dir = os.path.abspath(os.path.dirname(args.output)) |
@@ -387,6 +414,7 @@ def get_additional_annotation_information(annotation_dict, first_key, values): |
387 | 414 |
|
388 | 415 | # Loop through effect sizes file |
389 | 416 | # and add more detailed information |
| 417 | + log("Writing annotated output file: ", args.output) |
390 | 418 | ofh = open(args.output, "w") |
391 | 419 | with open(args.effect_sizes, "r") as ifh: |
392 | 420 | input_header = next(ifh).rstrip().split("\t") + PARSE_CLUSTER_SIGNIF + PARSE_INTRON_ANN |
|
0 commit comments