-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint_method.py
61 lines (43 loc) · 2.46 KB
/
entrypoint_method.py
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
52
53
54
55
56
57
58
59
60
61
import argparse
import os
def concatenate_input_content(input_files):
concatenated_content = "" # Initialize an empty string to hold the concatenated content
# Iterate over each input file
for input_file in input_files:
# Open each input file in read mode and read its content
with open(input_file, 'r') as file:
# Read the content of the input file and append it to the concatenated_content string
concatenated_content += file.read()
# Optionally, you can add a newline between the content of each file
concatenated_content += '\n'
return concatenated_content
def run_method(output_dir, name, input_files, parameters):
# Create the output directory if it doesn't exist
os.makedirs(output_dir, exist_ok=True)
content = concatenate_input_content(input_files)
method_mapping_file = os.path.join(output_dir, f'{name}.model.out.gz')
content += f"\n3. Running method using parameters '{parameters}' into {method_mapping_file}"
with open(method_mapping_file, 'w') as file:
file.write(content)
def main():
# Create argument parser
parser = argparse.ArgumentParser(description='Run method on files.')
# Add arguments
parser.add_argument('--output_dir', type=str, help='output directory where method will store results.')
parser.add_argument('--name', type=str, help='name of the dataset')
parser.add_argument('--process.filtered', type=str, help='optional input file #1.', required=False)
parser.add_argument('--data.counts', type=str, help='optional input file #1.', required=False)
parser.add_argument('--data.meta', type=str, help='input file #2.')
parser.add_argument('--data.data_specific_params', type=str, help='input file #3.')
# Parse arguments
args, extra_arguments = parser.parse_known_args()
process_filtered_input = getattr(args, 'process.filtered')
data_counts_input = getattr(args, 'data.counts')
data_meta_input = getattr(args, 'data.meta')
data_params_input = getattr(args, 'data.data_specific_params')
assert process_filtered_input is not None or data_counts_input is not None, "At least one of the values must not be None"
data_counts_input = process_filtered_input if process_filtered_input else data_counts_input
input_files = [data_counts_input, data_meta_input, data_params_input]
run_method(args.output_dir, args.name, input_files, extra_arguments)
if __name__ == "__main__":
main()