@@ -86,15 +86,7 @@ def merge_diseases(
8686 [d ["@class" ] == "Disease" for d in diseases ]
8787 ):
8888 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 ]))
9890 )
9991 words .append (OTHER_DISEASES )
10092 return natural_join (words )
@@ -132,18 +124,12 @@ def substitute_sentence_template(
132124 # remove subject from the conditions replacements
133125 subjects_ids = convert_to_rid_set (subjects )
134126 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
138128 ]
139129 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
146131 ]
132+ other_conditions = [d for d in other_conditions if d ["@rid" ] not in subjects_ids ]
147133
148134 result = result .replace (r"{subject}" , merge_diseases (subjects , disease_matches ))
149135
@@ -155,9 +141,7 @@ def substitute_sentence_template(
155141 other_conditions .extend (disease_conditions )
156142
157143 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 ))
161145 else :
162146 other_conditions .extend (variant_conditions )
163147
@@ -188,9 +172,7 @@ def aggregate_statements(
188172 def generate_key (statement : Statement ) -> Tuple :
189173 result = [
190174 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 )
194176 if cond ["@rid" ] != statement ["subject" ]["@rid" ]
195177 ]
196178 if statement .get ("subject" , {}).get ("@class" , "Disease" ) != "Disease" :
@@ -250,9 +232,7 @@ def display_variant(variant: IprVariant) -> str:
250232 # Use chosen legacy 'proteinChange' or an hgvs description of lowest detail.
251233 hgvs = variant .get (
252234 "proteinChange" ,
253- variant .get (
254- "hgvsProtein" , variant .get ("hgvsCds" , variant .get ("hgvsGenomic" , "" ))
255- ),
235+ variant .get ("hgvsProtein" , variant .get ("hgvsCds" , variant .get ("hgvsGenomic" , "" ))),
256236 )
257237
258238 if gene and hgvs :
@@ -264,16 +244,14 @@ def display_variant(variant: IprVariant) -> str:
264244
265245
266246def 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 }))
270248 variants_text = natural_join (result )
271249 if len (result ) > 1 :
272- return f"Multiple variants of the gene { gene_name } were observed in this case: { variants_text } "
273- elif result :
274250 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 } "
276252 )
253+ elif result :
254+ return f"{ variants_text [0 ].upper ()} { variants_text [1 :]} was observed in this case."
277255 return ""
278256
279257
@@ -344,11 +322,7 @@ def create_section_html(
344322 for section in [
345323 {s for (s , v ) in sentence_categories .items () if v == "diagnostic" },
346324 {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" ]},
352326 {
353327 s
354328 for (s , v ) in sentence_categories .items ()
@@ -490,14 +464,10 @@ def auto_analyst_comments(
490464 # aggregate similar sentences
491465 sentences = {}
492466 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 ))
496468
497469 # 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 ()))
501471
502472 output : List [str ] = [
503473 "<h3>The comments below were automatically generated from matches to GraphKB and have not been manually reviewed</h3>"
0 commit comments