@@ -86,15 +86,7 @@ def merge_diseases(
86
86
[d ["@class" ] == "Disease" for d in diseases ]
87
87
):
88
88
words = sorted (
89
- list (
90
- set (
91
- [
92
- get_displayname (s )
93
- for s in diseases
94
- if s ["@rid" ] in disease_matches
95
- ]
96
- )
97
- )
89
+ list (set ([get_displayname (s ) for s in diseases if s ["@rid" ] in disease_matches ]))
98
90
)
99
91
words .append (OTHER_DISEASES )
100
92
return natural_join (words )
@@ -132,18 +124,12 @@ def substitute_sentence_template(
132
124
# remove subject from the conditions replacements
133
125
subjects_ids = convert_to_rid_set (subjects )
134
126
disease_conditions = [
135
- cast (Ontology , d )
136
- for d in disease_conditions
137
- if d ["@rid" ] not in subjects_ids
127
+ cast (Ontology , d ) for d in disease_conditions if d ["@rid" ] not in subjects_ids
138
128
]
139
129
variant_conditions = [
140
- cast (Ontology , d )
141
- for d in variant_conditions
142
- if d ["@rid" ] not in subjects_ids
143
- ]
144
- other_conditions = [
145
- d for d in other_conditions if d ["@rid" ] not in subjects_ids
130
+ cast (Ontology , d ) for d in variant_conditions if d ["@rid" ] not in subjects_ids
146
131
]
132
+ other_conditions = [d for d in other_conditions if d ["@rid" ] not in subjects_ids ]
147
133
148
134
result = result .replace (r"{subject}" , merge_diseases (subjects , disease_matches ))
149
135
@@ -155,9 +141,7 @@ def substitute_sentence_template(
155
141
other_conditions .extend (disease_conditions )
156
142
157
143
if r"{conditions:variant}" in template :
158
- result = result .replace (
159
- r"{conditions:variant}" , natural_join_records (variant_conditions )
160
- )
144
+ result = result .replace (r"{conditions:variant}" , natural_join_records (variant_conditions ))
161
145
else :
162
146
other_conditions .extend (variant_conditions )
163
147
@@ -188,9 +172,7 @@ def aggregate_statements(
188
172
def generate_key (statement : Statement ) -> Tuple :
189
173
result = [
190
174
cond .get ("displayName" , cond ["@rid" ])
191
- for cond in filter_by_record_class (
192
- statement ["conditions" ], "Disease" , exclude = True
193
- )
175
+ for cond in filter_by_record_class (statement ["conditions" ], "Disease" , exclude = True )
194
176
if cond ["@rid" ] != statement ["subject" ]["@rid" ]
195
177
]
196
178
if statement .get ("subject" , {}).get ("@class" , "Disease" ) != "Disease" :
@@ -250,9 +232,7 @@ def display_variant(variant: IprVariant) -> str:
250
232
# Use chosen legacy 'proteinChange' or an hgvs description of lowest detail.
251
233
hgvs = variant .get (
252
234
"proteinChange" ,
253
- variant .get (
254
- "hgvsProtein" , variant .get ("hgvsCds" , variant .get ("hgvsGenomic" , "" ))
255
- ),
235
+ variant .get ("hgvsProtein" , variant .get ("hgvsCds" , variant .get ("hgvsGenomic" , "" ))),
256
236
)
257
237
258
238
if gene and hgvs :
@@ -264,16 +244,14 @@ def display_variant(variant: IprVariant) -> str:
264
244
265
245
266
246
def display_variants (gene_name : str , variants : List [IprVariant ]) -> str :
267
- result = sorted (
268
- list ({v for v in [display_variant (e ) for e in variants ] if gene_name in v })
269
- )
247
+ result = sorted (list ({v for v in [display_variant (e ) for e in variants ] if gene_name in v }))
270
248
variants_text = natural_join (result )
271
249
if len (result ) > 1 :
272
- return f"Multiple variants of the gene { gene_name } were observed in this case: { variants_text } "
273
- elif result :
274
250
return (
275
- f"{ variants_text [ 0 ]. upper () } { variants_text [ 1 :] } was observed in this case. "
251
+ f"Multiple variants of the gene { gene_name } were observed in this case: { variants_text } "
276
252
)
253
+ elif result :
254
+ return f"{ variants_text [0 ].upper ()} { variants_text [1 :]} was observed in this case."
277
255
return ""
278
256
279
257
@@ -344,11 +322,7 @@ def create_section_html(
344
322
for section in [
345
323
{s for (s , v ) in sentence_categories .items () if v == "diagnostic" },
346
324
{s for (s , v ) in sentence_categories .items () if v == "biological" },
347
- {
348
- s
349
- for (s , v ) in sentence_categories .items ()
350
- if v in ["therapeutic" , "prognostic" ]
351
- },
325
+ {s for (s , v ) in sentence_categories .items () if v in ["therapeutic" , "prognostic" ]},
352
326
{
353
327
s
354
328
for (s , v ) in sentence_categories .items ()
@@ -490,14 +464,10 @@ def auto_analyst_comments(
490
464
# aggregate similar sentences
491
465
sentences = {}
492
466
for template , group in templates .items ():
493
- sentences .update (
494
- aggregate_statements (graphkb_conn , template , group , disease_matches )
495
- )
467
+ sentences .update (aggregate_statements (graphkb_conn , template , group , disease_matches ))
496
468
497
469
# section statements by genes
498
- statements_by_genes = section_statements_by_genes (
499
- graphkb_conn , list (statements .values ())
500
- )
470
+ statements_by_genes = section_statements_by_genes (graphkb_conn , list (statements .values ()))
501
471
502
472
output : List [str ] = [
503
473
"<h3>The comments below were automatically generated from matches to GraphKB and have not been manually reviewed</h3>"
0 commit comments