-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathentrypoint_process.py
More file actions
51 lines (40 loc) · 1.91 KB
/
entrypoint_process.py
File metadata and controls
51 lines (40 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import argparse
import os
import time
def main():
# Set up argument parser
parser = argparse.ArgumentParser(description="Process dataset files")
# Define arguments
parser.add_argument("--output_dir", "-o", dest="output_dir", type=str, help="output directory where files will be saved", required=True)
parser.add_argument("--name", "-n", dest="name", type=str, help="name of the dataset", required=True)
parser.add_argument("--data.counts", dest="data_counts", type=str, help="input file #1")
parser.add_argument("--data.meta", dest="data_meta", type=str, help="input file #2")
parser.add_argument("-a", "--a", dest="arg_a", type=float, default=0, help="extra argument a")
parser.add_argument("-b", "--b", dest="arg_b", type=float, default=0, help="extra argument b")
parser.add_argument("--sleep", dest="sleep", type=float, default=0, help="sleep for N seconds before processing")
# Parse arguments
args = parser.parse_args()
output_dir = args.output_dir
name = args.name
data_counts_input = args.data_counts
data_meta_input = args.data_meta
input_files = [f for f in [data_counts_input, data_meta_input] if f]
a = args.arg_a
b = args.arg_b
sleep_secs = args.sleep
if sleep_secs > 0:
time.sleep(sleep_secs)
# Read and combine content from input files
processed_content = []
for input_file in input_files:
with open(input_file, 'r') as f:
processed_content.extend(f.readlines())
# Append the module message
module_message = f"\n2. Preprocessing dataset files using parameters '-a {a} -b {b}' into {os.path.join(output_dir, name)}.txt.gz\n"
processed_content.append(module_message)
# Write output to gzipped file
output_path = os.path.join(output_dir, f"{name}.txt.gz")
with open(output_path, 'wt') as out_file:
out_file.writelines(processed_content)
if __name__ == "__main__":
main()