2727plink2_exec = check_plink2 ()
2828
2929class Assoc :
30- def __init__ (self , geno_path = None , out_path = None , pca = 10 , build = 'hg38' , gwas = True , pheno_name = 'PHENO1' , covar_path = None , covar_names = None ):
30+ def __init__ (self , geno_path = None , out_path = None , pca = 10 , build = 'hg38' , gwas = True , pheno_name = 'PHENO1' , covar_path = None , covar_names = None , maf_lambdas = False ):
3131 self .geno_path = geno_path
3232 self .out_path = out_path
3333 self .pca = pca
@@ -36,6 +36,7 @@ def __init__(self, geno_path=None, out_path=None, pca=10, build='hg38', gwas=Tru
3636 self .pheno_name = pheno_name
3737 self .covar_path = covar_path
3838 self .covar_names = covar_names
39+ self .maf_lambdas = maf_lambdas
3940
4041
4142 def write_exclusion_file (self ):
@@ -276,16 +277,34 @@ def run_gwas(self, covars=True):
276277 # add pruning step here (pre lambdas)
277278 gwas_df_add = gwas_df .loc [gwas_df .TEST == 'ADD' ]
278279
280+ if self .maf_lambdas :
281+ gwas_df_maf = gwas_df_add [gwas_df_add ['A1_FREQ' ]>= 0.01 ]
282+ gwas_df_maf = gwas_df_maf [gwas_df_maf ['A1_FREQ' ]<= 0.99 ]
283+ gwas_df_maf = gwas_df_maf [~ gwas_df_maf ['P' ].isna ()]
284+
285+ lambda_maf_dict = Assoc .calculate_inflation (gwas_df_maf .P , normalize = False )
286+ lambda1000_maf_dict = Assoc .calculate_inflation (gwas_df_maf .P , normalize = True , ncases = ncases , ncontrols = ncontrols )
287+
279288 # calculate inflation
280289 lambda_dict = Assoc .calculate_inflation (gwas_df_add .P , normalize = False )
281290 lambda1000_dict = Assoc .calculate_inflation (gwas_df_add .P , normalize = True , ncases = ncases , ncontrols = ncontrols )
282291
283- metrics_dict = {
284- 'lambda' : lambda_dict ['metrics' ]['inflation' ],
285- 'lambda1000' : lambda1000_dict ['metrics' ]['inflation' ],
286- 'cases' : ncases ,
287- 'controls' : ncontrols
292+ if self .maf_lambdas :
293+ metrics_dict = {
294+ 'lambda' : lambda_dict ['metrics' ]['inflation' ],
295+ 'lambda1000' : lambda1000_dict ['metrics' ]['inflation' ],
296+ 'lambda_maf' : lambda_maf_dict ['metrics' ]['inflation' ],
297+ 'lambda1000_maf' : lambda1000_maf_dict ['metrics' ]['inflation' ],
298+ 'cases' : ncases ,
299+ 'controls' : ncontrols
288300 }
301+ else :
302+ metrics_dict = {
303+ 'lambda' : lambda_dict ['metrics' ]['inflation' ],
304+ 'lambda1000' : lambda1000_dict ['metrics' ]['inflation' ],
305+ 'cases' : ncases ,
306+ 'controls' : ncontrols
307+ }
289308
290309 process_complete = True
291310
0 commit comments