|
4 | 4 | import pathlib
|
5 | 5 | import sys
|
6 | 6 | import os
|
| 7 | +from pathlib import Path |
7 | 8 |
|
8 | 9 | sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
9 | 10 |
|
|
15 | 16 | # pr.enable()
|
16 | 17 |
|
17 | 18 |
|
| 19 | +def full_path(output, original_path): |
| 20 | + """ |
| 21 | + Modifies the given path by replacing the last segment with the output directory |
| 22 | + and appending the original last segment to the new path. |
| 23 | +
|
| 24 | + Parameters: |
| 25 | + original_path (str): The original file path. |
| 26 | + output (str): The new directory name to replace the last segment. |
| 27 | +
|
| 28 | + Returns: |
| 29 | + str: The modified file path. |
| 30 | + """ |
| 31 | + # Convert to Path object |
| 32 | + path = Path(original_path) |
| 33 | + |
| 34 | + # Construct the new path |
| 35 | + new_path = path.parent / output / path.name |
| 36 | + |
| 37 | + # Return the new path as a string |
| 38 | + return str(new_path) |
| 39 | + |
| 40 | + |
18 | 41 | def run_impute(
|
19 | 42 | conf_file="../conf/minimal-configuration.json",
|
20 | 43 | project_dir_graph="",
|
21 | 44 | project_dir_in_file="",
|
| 45 | + hap_pop_pair = False, |
| 46 | + graph = None |
22 | 47 | ):
|
23 | 48 |
|
24 | 49 | configuration_file = conf_file
|
@@ -56,18 +81,12 @@ def run_impute(
|
56 | 81 | + json_conf.get("edges_csv_file"),
|
57 | 82 | "imputation_input_file": project_dir_in_file
|
58 | 83 | + json_conf.get("imputation_in_file"),
|
59 |
| - "imputation_out_umug_freq_file": output_dir |
60 |
| - + json_conf.get("imputation_out_umug_freq_filename"), |
61 |
| - "imputation_out_umug_pops_file": output_dir |
62 |
| - + json_conf.get("imputation_out_umug_pops_filename"), |
63 |
| - "imputation_out_hap_freq_file": output_dir |
64 |
| - + json_conf.get("imputation_out_hap_freq_filename"), |
65 |
| - "imputation_out_hap_pops_file": output_dir |
66 |
| - + json_conf.get("imputation_out_hap_pops_filename"), |
67 |
| - "imputation_out_miss_file": output_dir |
68 |
| - + json_conf.get("imputation_out_miss_filename"), |
69 |
| - "imputation_out_problem_file": output_dir |
70 |
| - + json_conf.get("imputation_out_problem_filename"), |
| 84 | + "imputation_out_umug_freq_file": full_path(output_dir, json_conf.get("imputation_out_umug_freq_filename")), |
| 85 | + "imputation_out_umug_pops_file": full_path(output_dir, json_conf.get("imputation_out_umug_pops_filename")), |
| 86 | + "imputation_out_hap_freq_file": full_path(output_dir, json_conf.get("imputation_out_hap_freq_filename")), |
| 87 | + "imputation_out_hap_pops_file": full_path(output_dir, json_conf.get("imputation_out_hap_pops_filename")), |
| 88 | + "imputation_out_miss_file": full_path(output_dir, json_conf.get("imputation_out_miss_filename")), |
| 89 | + "imputation_out_problem_file": full_path(output_dir, json_conf.get("imputation_out_problem_filename")), |
71 | 90 | "factor_missing_data": json_conf.get("factor_missing_data", 0.01),
|
72 | 91 | "loci_map": json_conf.get(
|
73 | 92 | "loci_map", {"A": 1, "B": 3, "C": 2, "DQB1": 4, "DRB1": 5}
|
@@ -161,18 +180,21 @@ def run_impute(
|
161 | 180 |
|
162 | 181 | config["full_loci"] = "".join(sorted(all_loci_set))
|
163 | 182 | # Perform imputation
|
164 |
| - graph = Graph(config) |
165 |
| - graph.build_graph( |
166 |
| - config["node_file"], config["top_links_file"], config["edges_file"] |
167 |
| - ) |
| 183 | + if graph==None: |
| 184 | + graph = Graph(config) |
| 185 | + graph.build_graph( |
| 186 | + config["node_file"], config["top_links_file"], config["edges_file"] |
| 187 | + ) |
168 | 188 | imputation = Imputation(graph, config)
|
169 | 189 |
|
170 | 190 | # Create output directory if it doesn't exist
|
171 | 191 | pathlib.Path(output_dir).mkdir(parents=False, exist_ok=True)
|
172 | 192 |
|
173 | 193 | # Write out the results from imputation
|
174 |
| - imputation.impute_file(config) |
| 194 | + imputation.impute_file(config, em_mr=hap_pop_pair) |
175 | 195 |
|
176 | 196 | # Profiler end
|
177 | 197 | # pr.disable()
|
178 | 198 | # pr.print_stats(sort="time")
|
| 199 | + |
| 200 | + return graph |
0 commit comments