@@ -45,13 +45,9 @@ def filter_structural_variants(
45
45
Filter structural variants to remove non-high quality events unless they are matched/annotated or
46
46
they involve a gene that is a known fusion partner
47
47
"""
48
- matched_svs = {
49
- match ["variant" ] for match in kb_matches if match ["variantType" ] == "sv"
50
- }
48
+ matched_svs = {match ["variant" ] for match in kb_matches if match ["variantType" ] == "sv" }
51
49
fusion_genes = {
52
- gene ["name" ]
53
- for gene in gene_annotations
54
- if gene .get ("knownFusionPartner" , False )
50
+ gene ["name" ] for gene in gene_annotations if gene .get ("knownFusionPartner" , False )
55
51
}
56
52
57
53
result = []
@@ -89,9 +85,7 @@ def get_evidencelevel_mapping(graphkb_conn: GraphKBConnection) -> Dict[str, str]
89
85
90
86
# Filter IPR EvidenceLevel and map each outgoing CrossReferenceOf to displayName
91
87
ipr_source_rid = graphkb_conn .get_source ("ipr" )["@rid" ]
92
- ipr_evidence_levels = filter (
93
- lambda d : d .get ("source" ) == ipr_source_rid , evidence_levels
94
- )
88
+ ipr_evidence_levels = filter (lambda d : d .get ("source" ) == ipr_source_rid , evidence_levels )
95
89
cross_references_mapping : Dict [str , str ] = dict ()
96
90
ipr_rids_to_displayname : Dict [str , str ] = dict ()
97
91
for level in ipr_evidence_levels :
@@ -139,9 +133,7 @@ def convert_statements_to_alterations(
139
133
"""
140
134
disease_matches = {
141
135
r ["@rid" ]
142
- for r in gkb_vocab .get_term_tree (
143
- graphkb_conn , disease_name , ontology_class = "Disease"
144
- )
136
+ for r in gkb_vocab .get_term_tree (graphkb_conn , disease_name , ontology_class = "Disease" )
145
137
}
146
138
147
139
if not disease_matches :
@@ -154,9 +146,7 @@ def convert_statements_to_alterations(
154
146
155
147
# get the recruitment status for any trial associated with a statement
156
148
clinical_trials = [
157
- s ["subject" ]["@rid" ]
158
- for s in statements
159
- if s ["subject" ]["@class" ] == "ClinicalTrial"
149
+ s ["subject" ]["@rid" ] for s in statements if s ["subject" ]["@class" ] == "ClinicalTrial"
160
150
]
161
151
recruitment_statuses = {}
162
152
if clinical_trials :
@@ -173,9 +163,7 @@ def convert_statements_to_alterations(
173
163
174
164
for statement in statements :
175
165
variants = [
176
- cast (Variant , c )
177
- for c in statement ["conditions" ]
178
- if c ["@class" ] in VARIANT_CLASSES
166
+ cast (Variant , c ) for c in statement ["conditions" ] if c ["@class" ] in VARIANT_CLASSES
179
167
]
180
168
diseases = [c for c in statement ["conditions" ] if c ["@class" ] == "Disease" ]
181
169
disease_match = len (diseases ) == 1 and diseases [0 ]["@rid" ] in disease_matches
@@ -196,25 +184,17 @@ def convert_statements_to_alterations(
196
184
197
185
evidence_level_str = display_evidence_levels (statement )
198
186
evidence_levels = statement .get ("evidenceLevel" ) or []
199
- ipr_evidence_levels = [
200
- ev_map [el .get ("@rid" , "" )] for el in evidence_levels if el
201
- ]
202
- ipr_evidence_levels_str = ";" .join (
203
- sorted (set ([el for el in ipr_evidence_levels ]))
204
- )
187
+ ipr_evidence_levels = [ev_map [el .get ("@rid" , "" )] for el in evidence_levels if el ]
188
+ ipr_evidence_levels_str = ";" .join (sorted (set ([el for el in ipr_evidence_levels ])))
205
189
206
190
for variant in variants :
207
191
if variant ["@rid" ] not in variant_matches :
208
192
continue
209
193
stmt = {
210
194
"approvedTherapy" : approved_therapy or False ,
211
195
"category" : ipr_section or "unknown" ,
212
- "context" : (
213
- statement ["subject" ]["displayName" ] if statement ["subject" ] else ""
214
- ),
215
- "kbContextId" : (
216
- statement ["subject" ]["@rid" ] if statement ["subject" ] else ""
217
- ),
196
+ "context" : (statement ["subject" ]["displayName" ] if statement ["subject" ] else "" ),
197
+ "kbContextId" : (statement ["subject" ]["@rid" ] if statement ["subject" ] else "" ),
218
198
"disease" : ";" .join (sorted (d .get ("displayName" , "" ) for d in diseases )),
219
199
"evidenceLevel" : evidence_level_str or "" ,
220
200
"iprEvidenceLevel" : ipr_evidence_levels_str or "" ,
@@ -224,9 +204,7 @@ def convert_statements_to_alterations(
224
204
"relevance" : statement ["relevance" ]["displayName" ],
225
205
"kbRelevanceId" : statement ["relevance" ]["@rid" ],
226
206
"externalSource" : (
227
- str (statement ["source" ].get ("displayName" , "" ))
228
- if statement ["source" ]
229
- else ""
207
+ str (statement ["source" ].get ("displayName" , "" )) if statement ["source" ] else ""
230
208
),
231
209
"externalStatementId" : statement .get ("sourceId" , "" ) or "" ,
232
210
"reviewStatus" : statement .get ("reviewStatus" , "" ) or "" ,
@@ -281,9 +259,7 @@ def select_expression_plots(
281
259
gene = str (variant .get ("gene" , "" ))
282
260
hist = str (variant .get ("histogramImage" , "" ))
283
261
if hist :
284
- images_by_gene [gene ] = ImageDefinition (
285
- {"key" : f"expDensity.{ gene } " , "path" : hist }
286
- )
262
+ images_by_gene [gene ] = ImageDefinition ({"key" : f"expDensity.{ gene } " , "path" : hist })
287
263
return [images_by_gene [gene ] for gene in selected_genes if gene in images_by_gene ]
288
264
289
265
@@ -307,9 +283,7 @@ def create_key_alterations(
307
283
variant_type = kb_match ["variantType" ]
308
284
variant_key = kb_match ["variant" ]
309
285
310
- match_categories = [
311
- item ["category" ] for item in kb_match ["kbMatchedStatements" ]
312
- ]
286
+ match_categories = [item ["category" ] for item in kb_match ["kbMatchedStatements" ]]
313
287
if list (set (match_categories )) == ["unknown" ]:
314
288
continue
315
289
@@ -330,9 +304,7 @@ def create_key_alterations(
330
304
counts [type_mapping [variant_type ]].add (variant_key )
331
305
332
306
if variant_type == "exp" :
333
- alterations .append (
334
- f'{ variant .get ("gene" ,"" )} ({ variant .get ("expressionState" )} )'
335
- )
307
+ alterations .append (f'{ variant .get ("gene" ,"" )} ({ variant .get ("expressionState" )} )' )
336
308
elif variant_type == "cnv" :
337
309
alterations .append (f'{ variant .get ("gene" ,"" )} ({ variant .get ("cnvState" )} )' )
338
310
elif any (item in GERMLINE_BASE_TERMS for item in match_categories ):
@@ -408,19 +380,15 @@ def germline_kb_matches(
408
380
# Remove any matches to germline events
409
381
for alt in somatic_alts :
410
382
var_list = [v for v in all_variants if v ["key" ] == alt ["variant" ]]
411
- somatic_var_list = [
412
- v for v in var_list if not v .get ("germline" , not assume_somatic )
413
- ]
383
+ somatic_var_list = [v for v in var_list if not v .get ("germline" , not assume_somatic )]
414
384
if var_list and not somatic_var_list :
415
385
logger .debug (
416
386
f"Dropping germline match to somatic statement kbStatementId:{ alt ['kbStatementId' ]} : { alt ['kbVariant' ]} { alt ['category' ]} "
417
387
)
418
388
elif somatic_var_list :
419
389
ret_list .append (alt ) # match to somatic variant
420
390
else :
421
- ret_list .append (
422
- alt
423
- ) # alteration not in any specific keys matches to check.
391
+ ret_list .append (alt ) # alteration not in any specific keys matches to check.
424
392
425
393
return ret_list
426
394
@@ -449,9 +417,7 @@ def multi_variant_filtering(
449
417
"""
450
418
# All matching statements & variants (GKB RIDs)
451
419
matching_statement_rids = {
452
- stmt ["kbStatementId" ]
453
- for match in gkb_matches
454
- for stmt in match ["kbMatchedStatements" ]
420
+ stmt ["kbStatementId" ] for match in gkb_matches for stmt in match ["kbMatchedStatements" ]
455
421
}
456
422
matching_variant_rids = {match ["kbVariantId" ] for match in gkb_matches }
457
423
0 commit comments