27
27
plink2_exec = check_plink2 ()
28
28
29
29
class 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 ):
31
31
self .geno_path = geno_path
32
32
self .out_path = out_path
33
33
self .pca = pca
@@ -36,6 +36,7 @@ def __init__(self, geno_path=None, out_path=None, pca=10, build='hg38', gwas=Tru
36
36
self .pheno_name = pheno_name
37
37
self .covar_path = covar_path
38
38
self .covar_names = covar_names
39
+ self .maf_lambdas = maf_lambdas
39
40
40
41
41
42
def write_exclusion_file (self ):
@@ -276,16 +277,34 @@ def run_gwas(self, covars=True):
276
277
# add pruning step here (pre lambdas)
277
278
gwas_df_add = gwas_df .loc [gwas_df .TEST == 'ADD' ]
278
279
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
+
279
288
# calculate inflation
280
289
lambda_dict = Assoc .calculate_inflation (gwas_df_add .P , normalize = False )
281
290
lambda1000_dict = Assoc .calculate_inflation (gwas_df_add .P , normalize = True , ncases = ncases , ncontrols = ncontrols )
282
291
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
288
300
}
301
+ else :
302
+ metrics_dict = {
303
+ 'lambda' : lambda_dict ['metrics' ]['inflation' ],
304
+ 'lambda1000' : lambda1000_dict ['metrics' ]['inflation' ],
305
+ 'cases' : ncases ,
306
+ 'controls' : ncontrols
307
+ }
289
308
290
309
process_complete = True
291
310
0 commit comments