Skip to content

Commit 308c453

Browse files
committed
lint with black
1 parent 4bc7dec commit 308c453

File tree

3 files changed

+35
-90
lines changed

3 files changed

+35
-90
lines changed

pori_python/ipr/summary.py

+14-44
Original file line numberDiff line numberDiff line change
@@ -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

266246
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}))
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>"

tests/test_ipr/test_main.py

+17-34
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,23 @@ def report_upload_content(tmp_path_factory) -> Dict:
4848
"patientId": "PATIENT001",
4949
"project": "TEST",
5050
"expressionVariants": json.loads(
51-
pd.read_csv(
52-
get_test_file("expression.short.tab"), sep="\t"
53-
).to_json(orient="records")
51+
pd.read_csv(get_test_file("expression.short.tab"), sep="\t").to_json(
52+
orient="records"
53+
)
5454
),
5555
"smallMutations": json.loads(
56-
pd.read_csv(
57-
get_test_file("small_mutations.short.tab"), sep="\t"
58-
).to_json(orient="records")
56+
pd.read_csv(get_test_file("small_mutations.short.tab"), sep="\t").to_json(
57+
orient="records"
58+
)
5959
),
6060
"copyVariants": json.loads(
61-
pd.read_csv(
62-
get_test_file("copy_variants.short.tab"), sep="\t"
63-
).to_json(orient="records")
64-
),
65-
"structuralVariants": json.loads(
66-
pd.read_csv(get_test_file("fusions.tab"), sep="\t").to_json(
61+
pd.read_csv(get_test_file("copy_variants.short.tab"), sep="\t").to_json(
6762
orient="records"
6863
)
6964
),
65+
"structuralVariants": json.loads(
66+
pd.read_csv(get_test_file("fusions.tab"), sep="\t").to_json(orient="records")
67+
),
7068
"kbDiseaseMatch": "colorectal cancer",
7169
},
7270
allow_nan=False,
@@ -105,9 +103,7 @@ def side_effect_function(*args, **kwargs):
105103
):
106104
with patch.object(IprConnection, "upload_report", new=mock):
107105
with patch.object(IprConnection, "get_spec", return_value=get_test_spec()):
108-
with patch.object(
109-
IprConnection, "get", side_effect=side_effect_function
110-
):
106+
with patch.object(IprConnection, "get", side_effect=side_effect_function):
111107
command_interface()
112108

113109
assert mock.called
@@ -116,9 +112,7 @@ def side_effect_function(*args, **kwargs):
116112
return report_content
117113

118114

119-
@pytest.mark.skipif(
120-
EXCLUDE_INTEGRATION_TESTS, reason="excluding long running integration tests"
121-
)
115+
@pytest.mark.skipif(EXCLUDE_INTEGRATION_TESTS, reason="excluding long running integration tests")
122116
class TestCreateReport:
123117
def test_main_sections_present(self, report_upload_content: Dict) -> None:
124118
sections = set(report_upload_content.keys())
@@ -134,10 +128,7 @@ def test_main_sections_present(self, report_upload_content: Dict) -> None:
134128
assert section in sections
135129

136130
def test_kept_low_quality_fusion(self, report_upload_content: Dict) -> None:
137-
fusions = [
138-
(sv["gene1"], sv["gene2"])
139-
for sv in report_upload_content["structuralVariants"]
140-
]
131+
fusions = [(sv["gene1"], sv["gene2"]) for sv in report_upload_content["structuralVariants"]]
141132
if (
142133
EXCLUDE_BCGSC_TESTS
143134
): # may be missing statements assoc with SUZ12 if no access to bcgsc data
@@ -154,17 +145,13 @@ def test_found_fusion_partner_gene(self, report_upload_content: Dict) -> None:
154145
# eg, A1BG
155146
assert any([g.get("knownFusionPartner", False) for g in genes])
156147

157-
@pytest.mark.skipif(
158-
EXCLUDE_ONCOKB_TESTS, reason="excluding tests that depend on oncokb data"
159-
)
148+
@pytest.mark.skipif(EXCLUDE_ONCOKB_TESTS, reason="excluding tests that depend on oncokb data")
160149
def test_found_oncogene(self, report_upload_content: Dict) -> None:
161150
genes = report_upload_content["genes"]
162151
# eg, ZBTB20
163152
assert any([g.get("oncogene", False) for g in genes])
164153

165-
@pytest.mark.skipif(
166-
EXCLUDE_ONCOKB_TESTS, reason="excluding tests that depend on oncokb data)"
167-
)
154+
@pytest.mark.skipif(EXCLUDE_ONCOKB_TESTS, reason="excluding tests that depend on oncokb data)")
168155
def test_found_tumour_supressor(self, report_upload_content: Dict) -> None:
169156
genes = report_upload_content["genes"]
170157
# eg, ZNRF3
@@ -174,11 +161,7 @@ def test_found_kb_statement_related_gene(self, report_upload_content: Dict) -> N
174161
genes = report_upload_content["genes"]
175162
assert any([g.get("kbStatementRelated", False) for g in genes])
176163

177-
@pytest.mark.skipif(
178-
EXCLUDE_ONCOKB_TESTS, reason="excluding tests that depend on oncokb data"
179-
)
180-
def test_found_cancer_gene_list_match_gene(
181-
self, report_upload_content: Dict
182-
) -> None:
164+
@pytest.mark.skipif(EXCLUDE_ONCOKB_TESTS, reason="excluding tests that depend on oncokb data")
165+
def test_found_cancer_gene_list_match_gene(self, report_upload_content: Dict) -> None:
183166
genes = report_upload_content["genes"]
184167
assert any([g.get("cancerGeneListMatch", False) for g in genes])

tests/test_ipr/test_probe.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,8 @@ def side_effect_function(*args, **kwargs):
5050
password=os.environ["IPR_PASS"],
5151
log_level="info",
5252
ipr_url="http://fake.url.ca",
53-
graphkb_username=os.environ.get(
54-
"GRAPHKB_USER", os.environ["IPR_USER"]
55-
),
56-
graphkb_password=os.environ.get(
57-
"GRAPHKB_PASS", os.environ["IPR_PASS"]
58-
),
53+
graphkb_username=os.environ.get("GRAPHKB_USER", os.environ["IPR_USER"]),
54+
graphkb_password=os.environ.get("GRAPHKB_PASS", os.environ["IPR_PASS"]),
5955
graphkb_url=os.environ.get("GRAPHKB_URL", False),
6056
)
6157

@@ -65,19 +61,15 @@ def side_effect_function(*args, **kwargs):
6561
return report_content
6662

6763

68-
@pytest.mark.skipif(
69-
EXCLUDE_INTEGRATION_TESTS, reason="excluding long running integration tests"
70-
)
64+
@pytest.mark.skipif(EXCLUDE_INTEGRATION_TESTS, reason="excluding long running integration tests")
7165
class TestCreateReport:
7266
def test_found_probe_small_mutations(self, probe_upload_content: Dict) -> None:
7367
assert probe_upload_content["smallMutations"]
7468

7569
@pytest.mark.skipif(
7670
EXCLUDE_BCGSC_TESTS, reason="excluding tests that depend on BCGSC-specific data"
7771
)
78-
def test_found_probe_small_mutations_match(
79-
self, probe_upload_content: Dict
80-
) -> None:
72+
def test_found_probe_small_mutations_match(self, probe_upload_content: Dict) -> None:
8173
# verify each probe had a KB match
8274
for sm_probe in probe_upload_content["smallMutations"]:
8375
match_list = [

0 commit comments

Comments
 (0)