@@ -166,22 +166,36 @@ def main(args):
166
166
df ["lead_variant" ].iloc [lead_idx_snp ] = True
167
167
168
168
# annotate LD
169
- for pop in gnomad_pops ["GRCh37" ]:
170
- ht = hl .read_table (gnomad_ld_variant_indices [reference_genome ].format (pop = pop ))
169
+ r2_label = "r2" if not args .export_r else "r"
170
+ if args .ld_reference == "gnomad" :
171
+ ld_matrices = [
172
+ f"gs://gcp-public-data--gnomad/release/2.1.1/ld/gnomad.genomes.r2.1.1.{ pop } .common.ld.bm"
173
+ for pop in gnomad_pops ["GRCh37" ]
174
+ ]
175
+ ld_variant_indices = [
176
+ gnomad_ld_variant_indices [reference_genome ].format (pop = pop ) for pop in gnomad_pops ["GRCh37" ]
177
+ ]
178
+ ld_labels = [f"gnomad_lead_{ r2_label } _{ pop } " for pop in gnomad_pops ["GRCh37" ]]
179
+ else :
180
+ ld_matrices = [args .custom_ld_path ]
181
+ ld_variant_indices = [args .custom_ld_variant_index_path ]
182
+ ld_labels = [f"{ args .custom_ld_label } _lead_{ r2_label } " ]
183
+
184
+ for ld_bm_path , ld_ht_path , col in zip (ld_matrices , ld_variant_indices , ld_labels ):
185
+ ht = hl .read_table (ld_ht_path )
171
186
ht = ht_snp .join (ht , "inner" )
172
187
ht = ht .checkpoint (new_temp_file ())
173
188
174
189
lead_idx = ht .filter (hl .variant_str (ht .locus , ht .alleles ) == args .lead_variant ).head (1 ).idx .collect ()
175
190
176
191
if len (lead_idx ) == 0 :
177
- col = f"gnomad_lead_r2_{ pop } " if not args .export_r else f"gnomad_lead_r_{ pop } "
178
192
df [col ] = np .nan
179
193
continue
180
194
181
195
idx = ht .idx .collect ()
182
196
idx2 = sorted (list (set (idx )))
183
197
184
- bm = BlockMatrix .read (f"gs://gcp-public-data--gnomad/release/2.1.1/ld/gnomad.genomes.r2.1.1. { pop } .common.ld.bm" )
198
+ bm = BlockMatrix .read (ld_bm_path )
185
199
bm = bm .filter (idx2 , idx2 )
186
200
if not np .all (np .diff (idx ) > 0 ):
187
201
order = np .argsort (idx )
@@ -199,9 +213,6 @@ def main(args):
199
213
r2 = bm .to_numpy ()[0 ]
200
214
if not args .export_r :
201
215
r2 = r2 ** 2
202
- col = f"gnomad_lead_r2_{ pop } "
203
- else :
204
- col = f"gnomad_lead_r_{ pop } "
205
216
206
217
df [col ] = np .nan
207
218
df [col ].iloc [idx_snp ] = r2
@@ -224,6 +235,8 @@ def main(args):
224
235
n_samples = np .array (n_samples ).T
225
236
ld = np .array (ld ).T
226
237
df ["r" ] = np .nansum (n_samples * ld , axis = 1 ) / np .nansum (n_samples * ~ np .isnan (ld ), axis = 1 )
238
+ elif args .ld_reference == "custom" :
239
+ df ["r" ] = df [ld_labels [0 ]]
227
240
else :
228
241
df ["r" ] = df ["gnomad_lead_r_nfe" ]
229
242
@@ -294,6 +307,12 @@ def main(args):
294
307
parser .add_argument ("--align-alleles" , action = "store_true" , help = "Whether to align alleles with gnomAD" )
295
308
parser .add_argument ("--annotate-consequence" , action = "store_true" , help = "Whether to annotate VEP consequences" )
296
309
parser .add_argument ("--annotate-gnomad-freq" , action = "store_true" , help = "Whether to annotate gnomAD frequencies" )
310
+ parser .add_argument (
311
+ "--ld-reference" , type = str , default = "gnomad" , choices = ["gnomad" , "custom" ], help = "Choice of LD reference"
312
+ )
313
+ parser .add_argument ("--custom-ld-path" , type = str , help = "Path of user-provided LD BlockMatrix" )
314
+ parser .add_argument ("--custom-ld-variant-index-path" , type = str , help = "Path of user-provided LD variant index table" )
315
+ parser .add_argument ("--custom-ld-label" , type = str , help = "Label of user-provided LD" )
297
316
parser .add_argument ("--export-r" , action = "store_true" , help = "Export signed r values instead of r2" )
298
317
parser .add_argument ("--weighted-average-r" , type = str , nargs = "+" , action = ParseKwargs , help = "" )
299
318
parser .add_argument ("--dentist-s" , action = "store_true" , help = "Annotate DENTIST-S statistics" )
@@ -323,4 +342,11 @@ def main(args):
323
342
if args .out_summary is None :
324
343
args .out_summary = f"{ os .path .splitext (args .out )[0 ]} .summary.txt"
325
344
345
+ if args .ld_reference == "custom" and (
346
+ (args .custom_ld_path is None ) or (args .custom_ld_variant_index_path is None ) or (args .custom_ld_label is None )
347
+ ):
348
+ raise argparse .ArgumentError (
349
+ "All of --custom-ld-path, --custom-ld-variant-index-path, and --custom-ld-label should be provided"
350
+ )
351
+
326
352
main (args )
0 commit comments