|
9 | 9 |
|
10 | 10 | from snakemake.script import snakemake
|
11 | 11 |
|
12 |
| -from legenddataflow import FileKey, patterns |
| 12 | +from legenddataflow import patterns |
13 | 13 | from legenddataflow import utils as ut
|
14 | 14 | from legenddataflow.execenv import _execenv2str, execenv_pyexe
|
15 | 15 |
|
@@ -88,82 +88,6 @@ def check_log_files(log_path, output_file, gen_output, warning_file=None):
|
88 | 88 | Path(path).rmdir()
|
89 | 89 |
|
90 | 90 |
|
91 |
| -def add_spaces(n): |
92 |
| - out_string = "" |
93 |
| - for _i in range(n): |
94 |
| - out_string += " " |
95 |
| - return out_string |
96 |
| - |
97 |
| - |
98 |
| -def readable_json(dic, ncol=6, indent=4): |
99 |
| - def reformat_dict(dic, out_string="", indent_level=0, ncol=ncol, indent=indent): |
100 |
| - for key, item in dic.items(): |
101 |
| - if isinstance(item, list): |
102 |
| - out_string += ( |
103 |
| - f'{add_spaces(indent_level+indent)}"{key}"' |
104 |
| - + ": [\n" |
105 |
| - + f"{add_spaces(2*indent+indent_level)}" |
106 |
| - ) |
107 |
| - for i, _item in enumerate(item): |
108 |
| - if i > 0 and (i) % ncol == 0: |
109 |
| - out_string += f"\n{add_spaces(2*indent+indent_level)}" |
110 |
| - out_string += f'"{_item}", ' |
111 |
| - out_string = out_string[:-2] |
112 |
| - out_string += "\n" + f"{add_spaces(indent+indent_level)}" + "],\n" |
113 |
| - |
114 |
| - elif isinstance(item, dict): |
115 |
| - out_string += f'{add_spaces(indent+indent_level)}"{key}": ' + "{\n" |
116 |
| - out_string = reformat_dict( |
117 |
| - item, out_string, indent_level=indent_level + indent, ncol=ncol |
118 |
| - ) |
119 |
| - out_string += "\n" + f"{add_spaces(indent_level+indent)}" + "},\n" |
120 |
| - return out_string[:-2] |
121 |
| - |
122 |
| - out_string = "{\n" |
123 |
| - out_string = reformat_dict(dic, out_string=out_string, ncol=6) |
124 |
| - out_string += "\n}\n" |
125 |
| - |
126 |
| - return out_string |
127 |
| - |
128 |
| - |
129 |
| -def get_keys(files): |
130 |
| - def get_run(Filekey): |
131 |
| - return f"{Filekey.experiment}-{Filekey.period}-{Filekey.run}-{Filekey.datatype}" |
132 |
| - |
133 |
| - key_dict = {} |
134 |
| - for file in files: |
135 |
| - key = FileKey.get_filekey_from_filename(Path(file).name) |
136 |
| - if get_run(key) in key_dict: |
137 |
| - key_dict[get_run(key)].append(file) |
138 |
| - else: |
139 |
| - key_dict[get_run(key)] = [file] |
140 |
| - return key_dict |
141 |
| - |
142 |
| - |
143 |
| -def build_valid_keys(input_files_regex, output_dir): |
144 |
| - in_regex = Path(as_ro(input_files_regex)) |
145 |
| - infiles = in_regex.parent.glob(in_regex.name) |
146 |
| - key_dict = get_keys(infiles) |
147 |
| - |
148 |
| - for key in list(key_dict): |
149 |
| - dtype = key.split("-")[-1] |
150 |
| - out_file = ( |
151 |
| - Path(output_dir) / f'{key.replace(f"-{dtype}", "")}-valid_{dtype}.json' |
152 |
| - ) |
153 |
| - out_file.parent.mkdir(parents=True, exist_ok=True) |
154 |
| - if Path(out_file).is_file(): |
155 |
| - out_dict = Props.read_from([out_file] + key_dict[key]) |
156 |
| - else: |
157 |
| - out_dict = Props.read_from(key_dict[key]) |
158 |
| - out_string = readable_json(out_dict) |
159 |
| - with Path(out_file).open("w") as w: |
160 |
| - w.write(out_string) |
161 |
| - |
162 |
| - for input_file in infiles: |
163 |
| - if Path(input_file).is_file(): |
164 |
| - Path(input_file).unlink() |
165 |
| - |
166 |
| - |
167 | 91 | def find_gen_runs(gen_tier_path):
|
168 | 92 | # first look for non-concat tiers
|
169 | 93 | paths = gen_tier_path.glob("*/*/*/*")
|
@@ -285,26 +209,18 @@ def tdirs(tier):
|
285 | 209 | "table_format": snakemake.params.setup["table_format"],
|
286 | 210 | }
|
287 | 211 |
|
288 |
| -if snakemake.wildcards.tier != "daq": |
289 |
| - if snakemake.params.setup.get("build_file_dbs", True): |
290 |
| - print(f"INFO: ...building FileDBs with {snakemake.threads} threads") |
291 |
| - |
292 |
| - Path(snakemake.params.filedb_path).mkdir(parents=True, exist_ok=True) |
| 212 | +if (snakemake.wildcards.tier != "daq") and snakemake.params.setup.get( |
| 213 | + "build_file_dbs", True |
| 214 | +): |
| 215 | + print(f"INFO: ...building FileDBs with {snakemake.threads} threads") |
293 | 216 |
|
294 |
| - with (Path(snakemake.params.filedb_path) / "file_db_config.json").open( |
295 |
| - "w" |
296 |
| - ) as f: |
297 |
| - json.dump(file_db_config, f, indent=2) |
| 217 | + Path(snakemake.params.filedb_path).mkdir(parents=True, exist_ok=True) |
298 | 218 |
|
299 |
| - build_file_dbs( |
300 |
| - ut.tier_path(snakemake.params.setup), snakemake.params.filedb_path |
301 |
| - ) |
302 |
| - (Path(snakemake.params.filedb_path) / "file_db_config.json").unlink() |
| 219 | + with (Path(snakemake.params.filedb_path) / "file_db_config.json").open("w") as f: |
| 220 | + json.dump(file_db_config, f, indent=2) |
303 | 221 |
|
304 |
| - build_valid_keys( |
305 |
| - Path(ut.tmp_par_path(snakemake.params.setup)) / "*_db.json", |
306 |
| - snakemake.params.valid_keys_path, |
307 |
| - ) |
| 222 | + build_file_dbs(ut.tier_path(snakemake.params.setup), snakemake.params.filedb_path) |
| 223 | + (Path(snakemake.params.filedb_path) / "file_db_config.json").unlink() |
308 | 224 |
|
309 | 225 | if snakemake.params.setup.get("check_log_files", True):
|
310 | 226 | print("INFO: ...checking log files")
|
|
0 commit comments