|
| 1 | +import json |
| 2 | +import os |
| 3 | +import pandas as pd |
| 4 | + |
| 5 | +from graph_generation.generate_hpf import produce_hpf |
| 6 | +from grim.grim import graph_freqs |
| 7 | +from grim.grim import impute |
| 8 | +from filter_top_3 import change_donor_file |
| 9 | +from filter_by_rest import change_output_by_extra_gl |
| 10 | + |
| 11 | + |
| 12 | +def remove_empty_rows(file_path): |
| 13 | + df = pd.read_csv(file_path) |
| 14 | + |
| 15 | + df_cleaned = df.dropna(how="all") |
| 16 | + |
| 17 | + df_cleaned.to_csv(file_path, index=False) |
| 18 | + |
| 19 | + |
| 20 | +def run_original_grim( |
| 21 | + path_configuration, hap_pop_pair=True, Producehpf=False, dominant3=True |
| 22 | +): |
| 23 | + with open(path_configuration, "r") as f: |
| 24 | + config = json.load(f) |
| 25 | + |
| 26 | + # first step in py-graph-imputation |
| 27 | + if Producehpf: |
| 28 | + produce_hpf(conf_file=path_configuration) |
| 29 | + |
| 30 | + path_hpf = config["freq_file"] |
| 31 | + # remove empty rows from hpf otherwise doesnt work |
| 32 | + remove_empty_rows(path_hpf) |
| 33 | + |
| 34 | + # second step in py-graph-imputation |
| 35 | + graph_freqs(conf_file=path_configuration) |
| 36 | + |
| 37 | + # changing donor file to 3 most imporatnt gls and returning short_gl,extra_gl for each row in donor |
| 38 | + if dominant3: |
| 39 | + path_donor = config["imputation_in_file"] |
| 40 | + |
| 41 | + gls, lines = change_donor_file(path_donor) # change so wont change donor file |
| 42 | + |
| 43 | + # imputation |
| 44 | + impute(conf_file=path_configuration, hap_pop_pair=hap_pop_pair) |
| 45 | + |
| 46 | + # change the output and filter by the extra_gl |
| 47 | + if dominant3: |
| 48 | + path_pmug = os.path.join( |
| 49 | + config["imputation_out_path"], config["imputation_out_hap_freq_filename"] |
| 50 | + ) |
| 51 | + path_umug = os.path.join( |
| 52 | + config["imputation_out_path"], config["imputation_out_umug_freq_filename"] |
| 53 | + ) |
| 54 | + path_umug_pops = os.path.join( |
| 55 | + config["imputation_out_path"], config["imputation_out_umug_pops_filename"] |
| 56 | + ) |
| 57 | + path_pmug_pops = os.path.join( |
| 58 | + config["imputation_out_path"], config["imputation_out_hap_pops_filename"] |
| 59 | + ) |
| 60 | + path_miss = os.path.join( |
| 61 | + config["imputation_out_path"], config["imputation_out_miss_filename"] |
| 62 | + ) |
| 63 | + |
| 64 | + change_output_by_extra_gl( |
| 65 | + config, gls, path_pmug, path_umug, path_umug_pops, path_pmug_pops, path_miss |
| 66 | + ) # filter reasults in our origianl file, add miss to existing miss |
| 67 | + |
| 68 | + # changing to original donor file |
| 69 | + with open(path_donor, "w") as file: |
| 70 | + for line in lines: |
| 71 | + file.write(line) |
| 72 | + file.close() |
| 73 | + |
| 74 | + |
| 75 | +if __name__ == "__main__": |
| 76 | + conf_file = "conf/minimal-configuration.json" |
| 77 | + run_original_grim(conf_file, True, True, True) |
0 commit comments