Skip to content

Commit

Permalink
added pre-commit config file
Browse files Browse the repository at this point in the history
  • Loading branch information
perrin-isir committed Jan 2, 2025
1 parent 9964603 commit d106bfc
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 36 deletions.
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
exclude: ^tmp/
language_version: python3
- repo: https://github.com/PYCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
exclude: ^tmp/
args: ['--max-line-length=88', '--extend-ignore=E203']
13 changes: 6 additions & 7 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''# Configuration file for the Sphinx documentation builder.
"""# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
Expand Down Expand Up @@ -26,13 +26,12 @@
html_theme = 'alabaster'
html_static_path = ['_static']
'''
"""

# Licensed under the BSD 3-Clause License.

import re
import sys
from os.path import abspath, dirname, join
from os.path import abspath

sys.path.insert(0, abspath(".."))

Expand Down Expand Up @@ -89,15 +88,15 @@
# The full version, including alpha/beta/rc tags.
release = ""

''' #Read version info directly from the module's __init__.py
""" #Read version info directly from the module's __init__.py
init_path = join(dirname(dirname(str(abspath(__file__)))), "yomix")
with open(f"{init_path}/__init__.py", "r") as fh:
for line in fh:
match = re.match('__version__ = "((\\d.\\d).\\d)[a-z0-9\\-]*".*', line)
if match is not None:
release = match.group(1)
version = match.group(2)
break'''
break"""

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -135,4 +134,4 @@
html_theme_options = {}

# Output file base name for HTML help builder.
htmlhelp_basename = "yomixdoc"
htmlhelp_basename = "yomixdoc"
8 changes: 4 additions & 4 deletions yomix/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def build_figure(embedding_key):
obs_numerical,
source_rotmatrix_etc,
resize_width_input,
bt_slider_range
bt_slider_range,
)

offset_text_feature_color, offset_label = (
Expand All @@ -198,7 +198,7 @@ def build_figure(embedding_key):
hidden_checkbox_B,
resize_width_input_bis,
resize_height_input_bis,
bt_slider_range
bt_slider_range,
)
)
offset_label.visible = False
Expand Down Expand Up @@ -314,7 +314,7 @@ def build_figure(embedding_key):
resize_height_input, resize_width_input
),
points_bokeh_plot,
bt_slider_range
bt_slider_range,
),
bokeh.layouts.row(
bokeh.layouts.column(
Expand Down Expand Up @@ -356,7 +356,7 @@ def build_figure(embedding_key):
resize_height_input, resize_width_input
),
points_bokeh_plot,
bt_slider_range
bt_slider_range,
),
bokeh.layouts.row(
bokeh.layouts.column(
Expand Down
23 changes: 14 additions & 9 deletions yomix/plotting/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def color_by_feature_value(
hidden_checkbox_B,
resize_w_input,
resize_h_input,
bt_slider_range
bt_slider_range,
):
source = points_bokeh_plot.select(dict(name="scatterplot"))[0].data_source

Expand All @@ -32,7 +32,9 @@ def color_by_feature_value(
for i, featname in enumerate(adata.var_names):
feature_dict[featname] = [i, feat_min[i], feat_max[i]]

def color_modif(stringval, htlc, rwi, hlw, label_stringval, resize_w, resize_h, bt_slider_range):
def color_modif(
stringval, htlc, rwi, hlw, label_stringval, resize_w, resize_h, bt_slider_range
):
stringval_modif = (" + " + stringval).replace(" + - ", " - ").replace(
" + + ", " + "
).replace(" + ", "§§§§§§§§§§ + ").replace(
Expand Down Expand Up @@ -154,12 +156,15 @@ def simple_shrink(s_in, size):
select_color_by.value = ""
current_style = bt_slider_range.stylesheets[0].css
pattern = r"\{margin: 32px 0px 0px -\d+px;\}"
new_style = re.sub(pattern,
"{margin: 32px 0px 0px -" + str(int(legend_width)) + "px;}", current_style)
new_style = re.sub(
pattern,
"{margin: 32px 0px 0px -" + str(int(legend_width)) + "px;}",
current_style,
)
bt_slider_range.stylesheets = [InlineStyleSheet(css=new_style)]
bt_slider_range.start = 0.
bt_slider_range.end = 1.
bt_slider_range.value = (0., 1.)
bt_slider_range.start = 0.0
bt_slider_range.end = 1.0
bt_slider_range.value = (0.0, 1.0)
bt_slider_range.step = 0.01
bt_slider_range.visible = True

Expand Down Expand Up @@ -200,7 +205,7 @@ def simple_shrink(s_in, size):
offset_label.value, # Include the current label value
resize_w_input,
resize_h_input,
bt_slider_range
bt_slider_range,
),
)

Expand All @@ -215,7 +220,7 @@ def simple_shrink(s_in, size):
new_label, # Pass the new label value to color_modif
resize_w_input,
resize_h_input,
bt_slider_range
bt_slider_range,
),
)

Expand Down
18 changes: 11 additions & 7 deletions yomix/plotting/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ def main_figure(adata, embedding_key, width=900, height=600, title=""):

stylesheet2 = InlineStyleSheet(
css=".noUi-vertical .noUi-origin {top: 0%;} .noUi-base .noUi-connects "
"{height: " + str(height - 55) + "px;} .noUi-target.noUi-vertical {margin: 32px 0px 0px -55px;}"
"{height: "
+ str(height - 55)
+ "px;} .noUi-target.noUi-vertical {margin: 32px 0px 0px -55px;}"
)

bt_slider_point_size = bokeh.models.Slider(
Expand Down Expand Up @@ -386,14 +388,14 @@ def main_figure(adata, embedding_key, width=900, height=600, title=""):
bt_slider_range = bokeh.models.RangeSlider(
start=0.0,
end=1.0,
value=(0., 1.0),
value=(0.0, 1.0),
step=0.01,
orientation="vertical",
stylesheets=[stylesheet2],
width=100,
show_value=False,
direction="rtl",
visible=False
visible=False,
)

callback_js_slider_range = bokeh.models.CustomJS(
Expand Down Expand Up @@ -1397,7 +1399,8 @@ def main_figure(adata, embedding_key, width=900, height=600, title=""):
args=dict(
pbp=points_bokeh_plot,
source_rotmatrix_etc=source_rotmatrix_etc,
slider_range=bt_slider_range),
slider_range=bt_slider_range,
),
code="""
var parsed_int = parseInt(this.value);
if (!isNaN(parsed_int)) {
Expand All @@ -1415,12 +1418,13 @@ def main_figure(adata, embedding_key, width=900, height=600, title=""):
def modif_slider_range(attr, old, new):
current_style = bt_slider_range.stylesheets[0].css
pattern = r"\{height: \d+px;\}"
new_style = re.sub(pattern, "{height: " + str(max(int(new)-55, 0)) + "px;}", current_style)
new_style = re.sub(
pattern, "{height: " + str(max(int(new) - 55, 0)) + "px;}", current_style
)
bt_slider_range.stylesheets = [InlineStyleSheet(css=new_style)]

resize_height_input.on_change(
"value",
lambda attr, old, new: modif_slider_range(attr, old, new)
"value", lambda attr, old, new: modif_slider_range(attr, old, new)
)

sample_search_input = bokeh.models.TextInput(
Expand Down
33 changes: 24 additions & 9 deletions yomix/plotting/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@


def setup_legend(
pb_plot, obs_string, obs_numerical, source_rotmatrix_etc, resize_width_input, bt_slider_range
pb_plot,
obs_string,
obs_numerical,
source_rotmatrix_etc,
resize_width_input,
bt_slider_range,
):
source = pb_plot.select(dict(name="scatterplot"))[0].data_source

Expand Down Expand Up @@ -71,7 +76,16 @@ def setup_legend(
)

def redefine_custom_legend(
bokeh_plot, htls, htlc, hlw, obs_col, legend_dict, rwi, obs_s, obs_n, bt_slider_range
bokeh_plot,
htls,
htlc,
hlw,
obs_col,
legend_dict,
rwi,
obs_s,
obs_n,
bt_slider_range,
):
if obs_col in obs_s:
bokeh_plot.right = []
Expand Down Expand Up @@ -191,9 +205,7 @@ def all_values(arr) -> np.ndarray:
min_val = cbar.ticker.ticks[0]
max_val = cbar.ticker.ticks[-1]
legend_width = legend_dict[obs_col][1]
rwi.value = str(
int(bokeh_plot.width - float(hlw.value) + legend_width)
)
rwi.value = str(int(bokeh_plot.width - float(hlw.value) + legend_width))
hlw.value = str(legend_width)
else:
data = bokeh_plot.select(dict(name="scatterplot"))[0].data_source.data
Expand Down Expand Up @@ -238,13 +250,16 @@ def all_values(arr) -> np.ndarray:
legend_dict[obs_col] = ([cbar], legend_width)
current_style = bt_slider_range.stylesheets[0].css
pattern = r"\{margin: 32px 0px 0px -\d+px;\}"
new_style = re.sub(pattern,
"{margin: 32px 0px 0px -" + str(int(legend_width)) + "px;}", current_style)
new_style = re.sub(
pattern,
"{margin: 32px 0px 0px -" + str(int(legend_width)) + "px;}",
current_style,
)
bt_slider_range.stylesheets = [InlineStyleSheet(css=new_style)]
bt_slider_range.start = min_val
bt_slider_range.end = max_val
bt_slider_range.value = (min_val, max_val)
bt_slider_range.step = (max_val - min_val)/100.
bt_slider_range.step = (max_val - min_val) / 100.0
bt_slider_range.visible = True

hidden_text_label_search = bokeh.models.TextInput(
Expand Down Expand Up @@ -347,7 +362,7 @@ def all_values(arr) -> np.ndarray:
resize_width_input,
obs_string,
obs_numerical,
bt_slider_range
bt_slider_range,
),
)

Expand Down

0 comments on commit d106bfc

Please sign in to comment.