Skip to content

Commit 58062a7

Browse files
Final linting
1 parent 62fd1a8 commit 58062a7

File tree

3 files changed

+43
-29
lines changed

3 files changed

+43
-29
lines changed

pyproject.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,4 @@ ignore = [
133133
"PT006", # Wrong type passed to first argument of `pytest.mar
134134
"PT007", # Wrong values type in `pytest.mark.parametrize`
135135
"PT009", # Use a regular `assert` instead of unittest-style
136-
# FIXME - line too long in debug.py
137-
"E501",
138-
139136
]
140-

sc2ts/debug.py

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def line_cell(pos, prev_pos, next_pos):
112112
dist_to_left = 0
113113
if dist_to_right > 2:
114114
dist_to_right = 0
115-
return f'<td title="{pos}" "class="run-{int(dist_to_left)}-{int(dist_to_right)}"></td>'
115+
return f'<td title="{pos}" "class="run-{int(dist_to_left)}-{int(dist_to_right)}"></td>' # noqa E501
116116

117117
def node_mutations(self):
118118
muts = {}
@@ -306,19 +306,20 @@ def label(allele, default=""):
306306
runlength_cols = ("white", "red", "orange")
307307
bg_im_src = (
308308
"background-image:linear-gradient(to right, {0} 50%, {1} 50%);"
309-
"background-image:-webkit-linear-gradient(left, {0} 50%, {1} 50%);" # for imgkit/wkhtmltopdf
309+
# for imgkit/wkhtmltopdf
310+
"background-image:-webkit-linear-gradient(left, {0} 50%, {1} 50%);"
310311
)
311312
html += "<style>"
312313
if font_family is not None:
313314
html += f".copying-table {{font-family: '{font_family}'}}"
314315
html += ".copying-table .position {text-align: center; font-size: 7px}"
315-
html += ".copying-table .pattern td {border:0px solid black; text-align: center; width:1em}"
316+
html += ".copying-table .pattern td {border:0px solid black; text-align: center; width:1em}" # noqa: E501
316317
html += ".copying-table .mut {text-align: center; font-size: 7px}"
317318
html += ".copying-table .ref {text-align: center; font-size: 9px}"
318319
html += ".copying-table {border-spacing: 0px; border-collapse: collapse}"
319320
html += ".copying-table .runlengths {font-size:3px; height:3px;}"
320321
html += ".copying-table .child-rgt {text-align: left;}"
321-
html += ".copying-table .runlengths td {border-style: solid; background: white; border-width:0px 1px; border-color: black}"
322+
html += ".copying-table .runlengths td {border-style: solid; background: white; border-width:0px 1px; border-color: black}" # noqa: E501
322323
for left in range(len(runlength_cols)):
323324
for right in range(len(runlength_cols)):
324325
html += (
@@ -935,7 +936,8 @@ def node_info(node, label):
935936
interval_left = interval[0][0]
936937
if interval_left >= interval_right:
937938
logger.warning(
938-
f"RE: {u} interval_right >= interval_left; moving from {interval_left}"
939+
f"RE: {u} interval_right >= interval_left; "
940+
f"moving from {interval_left}"
939941
f"to {interval_right - 1}"
940942
)
941943
interval_left = interval_right - 1
@@ -1984,22 +1986,26 @@ def draw_svg(
19841986
**kwargs,
19851987
):
19861988
"""
1987-
Draw an SVG representation of the tree of samples that trace to a single origin.
1989+
Draw an SVG representation of the tree of samples that trace to a
1990+
single origin.
19881991
19891992
The default style is to colour mutations such that sites with a single
1990-
mutation in the tree are dark red, whereas sites with multiple mutations
1991-
show those mutations in red or magenta (magenta when a mutation immediately
1992-
reverts its parent mutation). Any identical mutations (from the same inherited
1993-
to derived state at the same site, i.e. recurrent mutations) have the count of
1994-
recurrent mutations appended to the label, e.g. "C842T (1/2)".
1995-
1996-
If highlight_universal_mutations is set, then mutations in the ancestry of all
1997-
the samples (i.e. between the root and the MRCA of all the samples) are highlighted
1993+
mutation in the tree are dark red, whereas sites with multiple
1994+
mutations show those mutations in red or magenta (magenta when a
1995+
mutation immediately reverts its parent mutation). Any identical
1996+
mutations (from the same inherited to derived state at the same site,
1997+
i.e. recurrent mutations) have the count of recurrent mutations
1998+
appended to the label, e.g. "C842T (1/2)".
1999+
2000+
If highlight_universal_mutations is set, then mutations in the ancestry
2001+
of all the samples (i.e. between the root and the MRCA of all the
2002+
samples) are highlighted
19982003
in bold and with thicker symbol lines
19992004
2000-
If genetic_regions is set, it should be a dictionary mapping (start, end) tuples
2001-
to region names. These will be drawn as coloured rectangles on the x-axis. If None,
2002-
a default selection of SARS-CoV-2 genes will be used.
2005+
If genetic_regions is set, it should be a dictionary mapping (start,
2006+
end) tuples to region names. These will be drawn as coloured rectangles
2007+
on the x-axis. If None, a default selection of SARS-CoV-2 genes will be
2008+
used.
20032009
"""
20042010
if x_regions is None:
20052011
x_regions = {
@@ -2034,7 +2040,7 @@ def draw_svg(
20342040
}
20352041
elif node_labels == "pango+country":
20362042
node_labels = {
2037-
n.id: f"{n.metadata.get(pango_md, '')}:{country_abbr(n.metadata.get('Country', ''))}"
2043+
n.id: f"{n.metadata.get(pango_md, '')}:{country_abbr(n.metadata.get('Country', ''))}" # noqa E501
20382044
for n in ts.nodes()
20392045
if pango_md in n.metadata or "Country" in n.metadata
20402046
}
@@ -2082,7 +2088,10 @@ def draw_svg(
20822088
}
20832089
# some default styles
20842090
styles = [
2085-
".mut .lab {fill: darkred} .mut .sym {stroke: darkred} .background path {fill: white}"
2091+
(
2092+
".mut .lab {fill: darkred} .mut .sym {stroke: darkred} "
2093+
".background path {fill: white}"
2094+
)
20862095
]
20872096
if len(multiple_mutations) > 0:
20882097
lab_css = ", ".join(f".mut.m{m} .lab" for m in multiple_mutations)
@@ -2130,14 +2139,20 @@ def draw_svg(
21302139

21312140
# Find SVG positions of the X axis
21322141
m = re.search(
2133-
r'class="x-axis".*?class="ax-line" x1="([\d\.]+)" x2="([\d\.]+)" y1="([\d\.]+)"',
2142+
r'class="x-axis".*?class="ax-line" x1="([\d\.]+)" x2="([\d\.]+)" y1="([\d\.]+)"', # noqa E501
21342143
svg,
21352144
)
21362145
assert m is not None
21372146
x1, x2, y1 = float(m.group(1)), float(m.group(2)), float(m.group(3))
21382147
xdiff = x2 - x1
2139-
x_box_svg = '<rect fill="yellow" stroke="black" x="{x}" width="{w}" y="{y}" height="{h}" />'
2140-
x_name_svg = '<text text-anchor="middle" alignment-baseline="hanging" x="{x}" y="{y}">{name}</text>'
2148+
x_box_svg = (
2149+
'<rect fill="yellow" stroke="black" x="{x}" '
2150+
'width="{w}" y="{y}" height="{h}" />'
2151+
)
2152+
x_name_svg = (
2153+
'<text text-anchor="middle" alignment-baseline="hanging" '
2154+
'x="{x}" y="{y}">{name}</text>'
2155+
)
21412156
x_scale = xdiff / ts.sequence_length
21422157
x_boxes = [
21432158
x_box_svg.format(

tests/sc2ts_fixtures.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ def fx_ts_map(tmp_path, fx_data_cache, fx_dataset, fx_match_db):
170170
**extra_kwargs,
171171
)
172172
print(
173-
f"INFERRED {date} nodes={last_ts.num_nodes} mutations={last_ts.num_mutations}"
173+
f"INFERRED {date} nodes={last_ts.num_nodes} "
174+
f"mutations={last_ts.num_mutations}"
174175
)
175176
cache_path = fx_data_cache / f"{date}.ts"
176177
last_ts.dump(cache_path)
@@ -289,7 +290,8 @@ def recombinant_example_2(tmp_path, fx_ts_map, fx_dataset, ds_path):
289290
ts_path = tmp_path / "intermediate.ts"
290291
ts.dump(ts_path)
291292

292-
# Now run again with the recombinant of these two, encoding the interval in the # name
293+
# Now run again with the recombinant of these two, encoding the interval
294+
# in the name
293295
date = "2020-03-02"
294296
left = start + 3 + 1
295297
right = end - 3 + 1
@@ -367,7 +369,8 @@ def recombinant_example_3(tmp_path, fx_ts_map, fx_dataset, ds_path):
367369
ts_path = tmp_path / "intermediate.ts"
368370
ts.dump(ts_path)
369371

370-
# Now run again with the recombinant of these three, encoding the intervals in the name
372+
# Now run again with the recombinant of these three, encoding the intervals
373+
# in the name
371374
date = "2020-03-02"
372375
left = start + 3 + 1
373376
right = end - 3 + 1

0 commit comments

Comments
 (0)