35
35
create_key_alterations ,
36
36
filter_structural_variants ,
37
37
germline_kb_matches ,
38
+ multi_variant_filtering ,
38
39
select_expression_plots ,
39
40
)
40
41
from .summary import auto_analyst_comments , get_ipr_analyst_comments
@@ -251,6 +252,7 @@ def ipr_report(
251
252
include_nonspecific_disease : bool = False ,
252
253
include_nonspecific_project : bool = False ,
253
254
include_nonspecific_template : bool = False ,
255
+ multi_variant_filter : bool = True ,
254
256
) -> Dict :
255
257
"""Run the matching and create the report JSON for upload to IPR.
256
258
@@ -278,6 +280,7 @@ def ipr_report(
278
280
include_nonspecific_disease: if include_ipr_variant_text is True, if no disease match is found use disease-nonspecific variant comment
279
281
include_nonspecific_project: if include_ipr_variant_text is True, if no project match is found use project-nonspecific variant comment
280
282
include_nonspecific_template: if include_ipr_variant_text is True, if no template match is found use template-nonspecific variant comment
283
+ multi_variant_filter: filters out matches that doesn't match to all required variants on multi-variant statements
281
284
282
285
Returns:
283
286
ipr_conn.upload_report return dictionary
@@ -309,10 +312,11 @@ def ipr_report(
309
312
small_mutations , expression_variants , copy_variants , structural_variants
310
313
)
311
314
312
- # Setup connections
315
+ # IPR CONNECTION
313
316
ipr_conn = IprConnection (username , password , ipr_url )
314
317
ipr_spec = ipr_conn .get_spec ()
315
318
319
+ # GKB CONNECTION
316
320
if graphkb_url :
317
321
logger .info (f"connecting to graphkb: { graphkb_url } " )
318
322
graphkb_conn = GraphKBConnection (graphkb_url )
@@ -324,9 +328,10 @@ def ipr_report(
324
328
325
329
graphkb_conn .login (gkb_user , gkb_pass )
326
330
331
+ # GKB MATCHING
327
332
gkb_matches : List [Hashabledict ] = []
328
333
329
- # Signature category variants
334
+ # MATCHING TMB
330
335
tmb_variant : IprVariant = {} # type: ignore
331
336
tmb_matches = []
332
337
if "tmburMutationBurden" in content .keys ():
@@ -360,6 +365,7 @@ def ipr_report(
360
365
gkb_matches .extend ([Hashabledict (tmb_statement ) for tmb_statement in tmb_matches ])
361
366
logger .debug (f"\t gkb_matches: { len (gkb_matches )} " )
362
367
368
+ # MATCHING MSI
363
369
msi = content .get ("msi" , [])
364
370
msi_matches = []
365
371
msi_variant : IprVariant = {} # type: ignore
@@ -383,6 +389,7 @@ def ipr_report(
383
389
gkb_matches .extend ([Hashabledict (msi ) for msi in msi_matches ])
384
390
logger .debug (f"\t gkb_matches: { len (gkb_matches )} " )
385
391
392
+ # MATCHING SMALL MUTATIONS
386
393
logger .info (f"annotating { len (small_mutations )} small mutations" )
387
394
gkb_matches .extend (
388
395
annotate_positional_variants (
@@ -391,6 +398,7 @@ def ipr_report(
391
398
)
392
399
logger .debug (f"\t gkb_matches: { len (gkb_matches )} " )
393
400
401
+ # MATCHING STRUCTURAL VARIANTS
394
402
logger .info (f"annotating { len (structural_variants )} structural variants" )
395
403
gkb_matches .extend (
396
404
annotate_positional_variants (
@@ -399,6 +407,7 @@ def ipr_report(
399
407
)
400
408
logger .debug (f"\t gkb_matches: { len (gkb_matches )} " )
401
409
410
+ # MATCHING COPY VARIANTS
402
411
logger .info (f"annotating { len (copy_variants )} copy variants" )
403
412
gkb_matches .extend (
404
413
[
@@ -410,6 +419,7 @@ def ipr_report(
410
419
)
411
420
logger .debug (f"\t gkb_matches: { len (gkb_matches )} " )
412
421
422
+ # MATCHING EXPRESSION VARIANTS
413
423
logger .info (f"annotating { len (expression_variants )} expression variants" )
414
424
gkb_matches .extend (
415
425
[
@@ -421,13 +431,15 @@ def ipr_report(
421
431
)
422
432
logger .debug (f"\t gkb_matches: { len (gkb_matches )} " )
423
433
434
+ # ALL VARIANTS
424
435
all_variants : Sequence [IprVariant ]
425
436
all_variants = expression_variants + copy_variants + structural_variants + small_mutations # type: ignore
426
437
if msi_matches :
427
438
all_variants .append (msi_variant ) # type: ignore
428
439
if tmb_matches :
429
440
all_variants .append (tmb_variant ) # type: ignore
430
441
442
+ # GKB_MATCHES FILTERING
431
443
if match_germline :
432
444
# verify germline kb statements matched germline observed variants, not somatic variants
433
445
org_len = len (gkb_matches )
@@ -443,17 +455,28 @@ def ipr_report(
443
455
gkb_matches = [Hashabledict (match ) for match in custom_kb_match_filter (gkb_matches )]
444
456
logger .info (f"\t custom_kb_match_filter left { len (gkb_matches )} variants" )
445
457
458
+ if multi_variant_filter :
459
+ logger .info (
460
+ f"Filtering out incomplete matches on multi-variant statements for { len (gkb_matches )} matches"
461
+ )
462
+ gkb_matches = multi_variant_filtering (graphkb_conn , gkb_matches )
463
+ logger .info (f"multi_variant_filtering left { len (gkb_matches )} matches" )
464
+
465
+ # KEY ALTERATIONS
446
466
key_alterations , variant_counts = create_key_alterations (gkb_matches , all_variants )
447
467
468
+ # GENE INFORMATION
448
469
logger .info ("fetching gene annotations" )
449
470
gene_information = get_gene_information (graphkb_conn , sorted (genes_with_variants ))
450
471
472
+ # THERAPEUTIC OPTIONS
451
473
if generate_therapeutics :
452
474
logger .info ("generating therapeutic options" )
453
475
targets = create_therapeutic_options (graphkb_conn , gkb_matches , all_variants )
454
476
else :
455
477
targets = []
456
478
479
+ # ANALYST COMMENTS
457
480
logger .info ("generating analyst comments" )
458
481
459
482
comments_list = []
@@ -477,6 +500,7 @@ def ipr_report(
477
500
comments_list .append (ipr_comments )
478
501
comments = "\n " .join (comments_list )
479
502
503
+ # OUTPUT CONTENT
480
504
# thread safe deep-copy the original content
481
505
output = json .loads (json .dumps (content ))
482
506
output .update (
@@ -513,6 +537,7 @@ def ipr_report(
513
537
ipr_result = None
514
538
upload_error = None
515
539
540
+ # UPLOAD TO IPR
516
541
if ipr_upload :
517
542
try :
518
543
logger .info (f"Uploading to IPR { ipr_conn .url } " )
@@ -522,11 +547,14 @@ def ipr_report(
522
547
except Exception as err :
523
548
upload_error = err
524
549
logger .error (f"ipr_conn.upload_report failed: { err } " , exc_info = True )
550
+
551
+ # SAVE TO JSON FILE
525
552
if output_json_path :
526
553
if always_write_output_json or not ipr_result :
527
554
logger .info (f"Writing IPR upload json to: { output_json_path } " )
528
555
with open (output_json_path , "w" ) as fh :
529
556
fh .write (json .dumps (output ))
557
+
530
558
logger .info (f"made { graphkb_conn .request_count } requests to graphkb" )
531
559
logger .info (f"average load { int (graphkb_conn .load or 0 )} req/s" )
532
560
if upload_error :
0 commit comments