Skip to content

Commit e289257

Browse files
Update lint for pre-commit
Update stuff Astuff Fixup
1 parent 625fb49 commit e289257

File tree

12 files changed

+77
-152
lines changed

12 files changed

+77
-152
lines changed

app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import sys
2-
import pathlib
31
import logging
2+
import pathlib
3+
import sys
44

55
import panel as pn
66
import tskit

config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Global plot settings
22
PLOT_WIDTH = 1000
33
PLOT_HEIGHT = 600
4-
THRESHOLD = 1000 # max number of points to overlay on a plot
4+
THRESHOLD = 1000 # max number of points to overlay on a plot

model.py

Lines changed: 4 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from functools import cached_property
22

3-
import tskit
4-
import numpy as np
53
import numba
4+
import numpy as np
65
import pandas as pd
6+
import tskit
77

88
spec = [
99
("num_edges", numba.int64),
@@ -43,7 +43,7 @@ def __init__(
4343
self.in_range = np.zeros(2, dtype=np.int64)
4444
self.out_range = np.zeros(2, dtype=np.int64)
4545

46-
def next(self):
46+
def next(self): # noqa
4747
left = self.interval[1]
4848
j = self.in_range[1]
4949
k = self.out_range[1]
@@ -220,7 +220,7 @@ def mutations_df(self):
220220
unknown = tskit.is_unknown_time(mutations_time)
221221
mutations_time[unknown] = self.ts.nodes_time[mutations_node[unknown]]
222222

223-
node_flag = ts.nodes_flags[mutations_node]
223+
# node_flag = ts.nodes_flags[mutations_node]
224224
position = ts.sites_position[ts.mutations_site]
225225

226226
tables = self.ts.tables
@@ -440,90 +440,6 @@ def make_sliding_windows(self, iterable, size, overlap=0):
440440
end += step
441441
yield iterable[start:]
442442

443-
def plot_polytomy_fractions(
444-
self, region_start=None, region_end=None, window_size=100_000, overlap=0
445-
):
446-
"""
447-
Plots the fraction of polytomies in windows actoss the genomic sequence
448-
"""
449-
if region_start is None:
450-
region_start = max(0, self.ts.tables.sites.position[0] - 50_000)
451-
if region_end is None:
452-
region_end = self.ts.tables.sites.position[-1] + 50_000
453-
fig, ax = plt.subplots(figsize=(20, 5))
454-
polytomy_fractions = self.calc_polytomy_fractions()
455-
poly_fracs_by_pos = self.map_stats_to_genome(polytomy_fractions)
456-
poly_fracs_means = []
457-
poly_fracs_sd = []
458-
genomic_positions = []
459-
for poly_win in self.make_sliding_windows(
460-
poly_fracs_by_pos, window_size, overlap
461-
):
462-
poly_fracs_means.append(np.mean(poly_win))
463-
poly_fracs_sd.append(np.std(poly_win))
464-
for gen_win in self.make_sliding_windows(
465-
np.arange(1, self.ts.sequence_length), window_size, overlap
466-
):
467-
genomic_positions.append(gen_win[0] / 1_000_000)
468-
ax.plot(
469-
genomic_positions,
470-
poly_fracs_means,
471-
label="mean",
472-
linewidth=0.5,
473-
)
474-
ax.fill_between(
475-
genomic_positions,
476-
np.array(poly_fracs_means) - np.array(poly_fracs_sd),
477-
np.array(poly_fracs_means) + np.array(poly_fracs_sd),
478-
alpha=0.3,
479-
label="mean +/- std",
480-
)
481-
missing_vals = np.take(genomic_positions, np.where(np.isnan(poly_fracs_means)))
482-
ax.plot(
483-
missing_vals,
484-
np.zeros(len(missing_vals)),
485-
color="red",
486-
marker="o",
487-
label="missing data",
488-
)
489-
ax.set_xlabel(f"Position on chr {self.chr}(Mb)", fontsize=10)
490-
ax.set_ylabel("Window mean", fontsize=10)
491-
ax.set_title("Polytomy score", fontsize=10)
492-
ax.set_ylim(0, 1)
493-
ax.set_xlim(region_start / 1_000_000, region_end / 1_000_000)
494-
handles, labels = ax.get_legend_handles_labels()
495-
unique = [
496-
(h, l)
497-
for i, (h, l) in enumerate(zip(handles, labels))
498-
if l not in labels[:i]
499-
]
500-
ax.legend(*zip(*unique))
501-
plt.show()
502-
503-
def plot_mutations_per_site_along_seq(
504-
self, region_start=None, region_end=None, hist_bins=1000
505-
):
506-
count = self.sites_num_mutations
507-
pos = self.ts.sites_position
508-
if region_start is None:
509-
region_start = pos[0]
510-
if region_end is None:
511-
region_end = pos[-1]
512-
grid = sns.jointplot(
513-
x=pos / 1_000_000,
514-
y=count,
515-
kind="scatter",
516-
marginal_ticks=True,
517-
alpha=0.5,
518-
marginal_kws=dict(bins=hist_bins),
519-
xlim=(region_start / 1_000_000, region_end / 1_000_000),
520-
)
521-
grid.ax_marg_y.remove()
522-
grid.fig.set_figwidth(20)
523-
grid.fig.set_figheight(8)
524-
grid.ax_joint.set_xlabel("Position on genome (Mb)")
525-
grid.ax_joint.set_ylabel("Number of mutations")
526-
527443
def calc_mean_node_arity(self):
528444
span_sums = np.bincount(
529445
self.ts.edges_parent,

pages/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import os
21
import importlib
2+
import os
33

44
# List all files in the current directory
55
for module_file in os.listdir(os.path.dirname(__file__)):
66
# Check if it's a python file and not this __init__ file
7-
if module_file.endswith('.py') and module_file != '__init__.py':
7+
if module_file.endswith(".py") and module_file != "__init__.py":
88
module_name = module_file[:-3] # remove the .py extension
9-
module = importlib.import_module('.' + module_name, package=__name__)
9+
module = importlib.import_module("." + module_name, package=__name__)
1010

1111
# Add the page function to the current module's namespace
1212
globals()[module_name] = module.page

pages/edge_explorer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import panel as pn
2-
import holoviews as hv
31
import bokeh.models as bkm
2+
import holoviews as hv
3+
import panel as pn
4+
45
import config
56

7+
68
def page(tsm):
79
hv.extension("bokeh")
810
edges_df = tsm.edges_df

pages/edges.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import bokeh.models as bkm
12
import holoviews as hv
23
import holoviews.operation.datashader as hd
34
import panel as pn
5+
46
import config
5-
import bokeh.models as bkm
6-
from plot_helpers import filter_points, hover_points
7+
from plot_helpers import filter_points
8+
from plot_helpers import hover_points
9+
710

811
def page(tsm):
912
hv.extension("bokeh")

pages/mutations.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import panel as pn
21
import holoviews as hv
32
import holoviews.operation.datashader as hd
43
import hvplot.pandas # noqa
54
import numpy as np
5+
import panel as pn
66

77
import config
8-
from plot_helpers import filter_points, hover_points
8+
from plot_helpers import filter_points
9+
from plot_helpers import hover_points
910

1011

1112
def make_hist_on_axis(dimension, points, num_bins=30):
12-
### Make histogram function for a specified axis of a scatter plot
13+
"""
14+
Make histogram function for a specified axis of a scatter plot
15+
"""
16+
1317
def compute_hist(x_range, y_range):
1418
filtered_points = filter_points(points, x_range, y_range)
1519
hist = hv.operation.histogram(
@@ -21,7 +25,9 @@ def compute_hist(x_range, y_range):
2125

2226

2327
def make_hist(data, title, bins_range, log_y=True, plot_width=800):
24-
### Make histogram from given count data
28+
"""
29+
Make histogram from given count data
30+
"""
2531
count, bins = np.histogram(data, bins=bins_range)
2632
ylabel = "log(Count)" if log_y else "Count"
2733
np.seterr(divide="ignore")
@@ -36,7 +42,9 @@ def make_hist(data, title, bins_range, log_y=True, plot_width=800):
3642

3743

3844
def make_hist_panel(tsm, log_y):
39-
### Make row of histograms for holoviews panel
45+
"""
46+
Make row of histograms for holoviews panel
47+
"""
4048
overall_site_hist = make_hist(
4149
tsm.sites_num_mutations,
4250
"Mutations per site",

pages/nodes.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import functools
22

3-
import numpy as np
4-
import hvplot.pandas # noqa
53
import holoviews as hv
64
import holoviews.operation.datashader as hd
5+
import hvplot.pandas # noqa
6+
import numpy as np
77
import panel as pn
88

99
import config
10-
from plot_helpers import filter_points, hover_points, make_hist_matplotlib
10+
from plot_helpers import filter_points
11+
from plot_helpers import hover_points
12+
from plot_helpers import make_hist_matplotlib
1113

1214

1315
def page(tsm):

pages/overview.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import panel as pn
22

3+
34
def page(tsm):
4-
return pn.pane.HTML(tsm.ts)
5+
return pn.pane.HTML(tsm.ts)

pages/trees.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import panel as pn
1+
import functools
2+
23
import holoviews as hv
34
import numpy as np
4-
import functools
5+
import panel as pn
56

67
from plot_helpers import make_hist_matplotlib
78

@@ -70,7 +71,7 @@ def page(tsm):
7071
mean_arity_hist_func = functools.partial(
7172
make_hist_matplotlib,
7273
df_trees.mean_internal_arity,
73-
f"Mean arity per tree \n(not yet implemented)",
74+
"Mean arity per tree \n(not yet implemented)",
7475
num_bins=bins,
7576
log_y=True,
7677
)

0 commit comments

Comments
 (0)