__main__.py 2.63 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
import argparse
import pandas as pd
from impute_jass.imputation_launcher import ImputationLauncher


def launch_chromosome_imputation(args):
    """
    Function whose only purpose is to allow the calling of the ImputationLauncher.chromosome_imputation method
    from an entry point
    """
11
    print("Imputation of {0} gwas for chromosome {1}".format(args.gwas, args.chrom))
12
13
14
15
    imputer = ImputationLauncher( window_size=int(args.window_size), buf=int(args.buffer_size),
                        lamb= float(args.l2_regularization), pinv_rcond = float(args.eigen_treshold))

    z_file = "{0}/z_{1}_{2}.txt".format(args.zscore_folder, args.gwas, args.chrom)
16
    zscore = pd.read_csv(z_file,index_col=0, sep="\t")
17
18
    ref_panel_file = args.ref_folder + "/"+ args.chrom +".eur.1pct.bim"
    ref_panel = pd.read_csv(ref_panel_file, sep="\t", names=['chr', "nothing", 'pos', 'Ref_all', 'alt_all'], index_col = 1)
19
    
20

21
22
23
24
25
    imputed_zscore = imputer.chromosome_imputation(args.chrom, zscore, ref_panel, args.ld_folder)
    print("Imputation DONE")
    z_fo = "{0}/z_{1}_{2}.txt".format(args.output_folder, args.gwas, args.chrom)
    imputed_zscore.to_csv(z_fo, sep='\t')
    print("Save imputation done ")
26
27
28
29
30
31

def add_chromosome_imputation_argument(parser):
    parser.add_argument('--chrom', required=True, help= "chromosome to impute to the chr\d+ format")
    parser.add_argument('--gwas', required=True, help= "GWAS to impute to the consortia_trait format")

    parser.add_argument('--ref-folder', required=True, help= "reference panel location (used to determine which snp to impute)")
Hanna  JULIENNE's avatar
Hanna JULIENNE committed
32
    parser.add_argument('--ld-folder', required=True, help= "Location  LD correlation matrices")
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
    parser.add_argument('--zscore-folder', required=True, help= "Location of the zscore files of the gwases to impute")
    parser.add_argument('--output-folder', required=True, help= "Location of the impute zscore files")

    parser.add_argument('--window-size', help= "Size of the non overlapping window", default = 500000)
    parser.add_argument('--buffer-size', help= "Size of the buffer around the imputation window", default = 125000)
    parser.add_argument('--l2-regularization', help= "Size of the buffer around the imputation window", default = 0.1)
    parser.add_argument('--eigen-treshold', help= "treshold under which eigen vectors are removed for the computation of the pseudo inverse", default = 0.1)
    parser.set_defaults(func=launch_chromosome_imputation)
    return(parser)


def main():

    parser = argparse.ArgumentParser()#prog='impute_jass')
    parser = add_chromosome_imputation_argument(parser)
    args = parser.parse_args()
    args.func(args)


if __name__=="__main__":
    main()