Skip to content

Commit df68f65

Browse files
committed
Adding logging information
1 parent 275e4fd commit df68f65

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

workflow/scripts/leafcutter_annotation.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# Standard Library
66
from __future__ import print_function
7+
from datetime import datetime
78
from textwrap import dedent
89
import argparse, gzip, os, sys
910

@@ -109,6 +110,30 @@ def fatal(*message, **kwargs):
109110
sys.exit(1)
110111

111112

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+
112137
def check_permissions(parser, path, *args, **kwargs):
113138
"""Checks permissions using os.access() to see the
114139
user is authorized to access a file/directory. Checks
@@ -271,6 +296,7 @@ def index_file(file, keys, key_delim, values):
271296
keys=["A","B"], values["C","D"], key_delim="|"
272297
returns {"A|B": {"C": "c_i", "D": "d_i"}}
273298
"""
299+
log("Started indexing input file: {0}".format(file))
274300
file_idx = {}
275301
# Handler for opening files, i.e.
276302
# uncompressed or gzip files
@@ -348,6 +374,7 @@ def get_additional_annotation_information(annotation_dict, first_key, values):
348374
# Nothing was provided
349375
fatal('Invalid usage: {0} [-h] ...'.format(os.path.basename(sys.argv[0])))
350376

377+
log("Running leafcutter annotation script with the following options: ", args)
351378
# Create output directory if
352379
# it does not exist
353380
output_dir = os.path.abspath(os.path.dirname(args.output))
@@ -387,6 +414,7 @@ def get_additional_annotation_information(annotation_dict, first_key, values):
387414

388415
# Loop through effect sizes file
389416
# and add more detailed information
417+
log("Writing annotated output file: ", args.output)
390418
ofh = open(args.output, "w")
391419
with open(args.effect_sizes, "r") as ifh:
392420
input_header = next(ifh).rstrip().split("\t") + PARSE_CLUSTER_SIGNIF + PARSE_INTRON_ANN

0 commit comments

Comments
 (0)