Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 12, 2024
1 parent c014aa4 commit d7f599d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,3 @@ def try_except_middle_int(str_in):
return int(str_in[1:-1])
except ValueError:
return None

Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ def create_kinase_models_from_df(

return dict_kinase_models

def get_sequence_max_with_exception(list_in: list[int| None]) -> int:

def get_sequence_max_with_exception(list_in: list[int | None]) -> int:
"""Get maximum sequence length from dictionary of dictionaries.
Parameters
Expand All @@ -543,9 +544,12 @@ def get_sequence_max_with_exception(list_in: list[int| None]) -> int:
except ValueError:
return 0


def replace_none_with_max_len(dict_in):
dict_max_len = {
key1: get_sequence_max_with_exception([len(val2) for val2 in val1.values() if val2 is not None])
key1: get_sequence_max_with_exception(
[len(val2) for val2 in val1.values() if val2 is not None]
)
for key1, val1 in dict_in.items()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import numpy as np
from pydantic.dataclasses import dataclass
from bokeh.plotting import figure
from bokeh.layouts import gridplot

# from bokeh.models import ColumnDataSource, Plot, Grid, Range1d
from bokeh.models import ColumnDataSource, Range1d
from bokeh.models.glyphs import Text, Rect
from bokeh.layouts import gridplot
from bokeh.models.glyphs import Rect, Text
from bokeh.plotting import figure
from pydantic.dataclasses import dataclass


@dataclass
class SequenceAlignment():
class SequenceAlignment:
list_sequences: list[str]
"""List of sequences to show in aligner."""
list_ids: list[str]
Expand All @@ -28,22 +30,22 @@ def get_colors(
dict_colors: dict[str, str],
) -> list[str]:
"""Get colors for residue in a given sequence.
Parameters
----------
list_str : str
List of residues in a sequence.
dict_colors : dict[str, str]
Dictionary of colors for each residue.
Returns
-------
list[str]
List of colors for each residue.
"""
list_colors = [dict_colors[i] for i in list_str]
return list_colors

def generate_alignment(self) -> None:
"""Generate sequence alignment plot adapted from https://dmnfarrell.github.io/bioinformatics/bokeh-sequence-aligner."""

Expand All @@ -52,9 +54,9 @@ def generate_alignment(self) -> None:
colors = self.get_colors(list_text, self.dict_colors)

N = len(self.list_sequences[0])
S = len(self.list_sequences)
S = len(self.list_sequences)

x = np.arange(1, N+1)
x = np.arange(1, N + 1)
y = np.arange(0, S, 1)
# creates a 2D grid of coords from the 1D arrays
xx, yy = np.meshgrid(x, y)
Expand All @@ -66,74 +68,74 @@ def generate_alignment(self) -> None:
# now we can create the ColumnDataSource with all the arrays
source = ColumnDataSource(
dict(
x = gx,
y = gy,
recty = recty,
text = list_text,
colors = colors,
x=gx,
y=gy,
recty=recty,
text=list_text,
colors=colors,
)
)
x_range = Range1d(0, N+1, bounds="auto")
x_range = Range1d(0, N + 1, bounds="auto")
if N > 100:
viewlen = 100
else:
viewlen = N

# entire sequence view (no text, with zoom)
p = figure(
title = None,
frame_width = self.plot_width,
frame_height = 50,
x_range = x_range,
y_range = (0, S),
tools = "xpan, xwheel_zoom, reset, save",
min_border = 0,
toolbar_location = "below",
title=None,
frame_width=self.plot_width,
frame_height=50,
x_range=x_range,
y_range=(0, S),
tools="xpan, xwheel_zoom, reset, save",
min_border=0,
toolbar_location="below",
)
rects = Rect(
x = "x",
y = "recty",
width = 1,
height = 1,
fill_color = "colors",
line_color = None,
fill_alpha = 0.6,
x="x",
y="recty",
width=1,
height=1,
fill_color="colors",
line_color=None,
fill_alpha=0.6,
)
p.add_glyph(source, rects)
p.yaxis.visible = False
p.grid.visible = False
p.grid.visible = False

# sequence text view with ability to scroll along x axis
# view_range is for the close up view
view_range = (0, viewlen)
plot_height = S * 15 + 50
p1 = figure(
title = None,
frame_width = self.plot_width,
frame_height = plot_height,
x_range = view_range,
y_range = self.list_ids[::-1],
tools = "xpan,reset",
min_border = 0,
toolbar_location = "below",
)
title=None,
frame_width=self.plot_width,
frame_height=plot_height,
x_range=view_range,
y_range=self.list_ids[::-1],
tools="xpan,reset",
min_border=0,
toolbar_location="below",
)
glyph = Text(
x = "x",
y = "y",
text = "text",
text_align = "center",
text_color = "black",
x="x",
y="y",
text="text",
text_align="center",
text_color="black",
# text_font = "monospace",
text_font_size = f"{str(self.font_size)}pt",
text_font_size=f"{str(self.font_size)}pt",
)
rects = Rect(
x = "x",
y = "recty",
width = 1,
height = 1,
fill_color = "colors",
line_color = None,
fill_alpha = 0.4,
x="x",
y="recty",
width=1,
height=1,
fill_color="colors",
line_color=None,
fill_alpha=0.4,
)
p1.add_glyph(source, glyph)
p1.add_glyph(source, rects)
Expand All @@ -142,7 +144,7 @@ def generate_alignment(self) -> None:
p1.yaxis.minor_tick_line_width = 0
p1.yaxis.major_tick_line_width = 0

self.plot = gridplot([[p],[p1]], toolbar_location="below")
self.plot = gridplot([[p], [p1]], toolbar_location="below")

def show_plot(self) -> None:
"""Show sequence alignment plot via Bokeh."""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import json
import logging
from enum import Enum

from pydantic.dataclasses import dataclass

from missense_kinase_toolkit.databases import requests_wrapper
Expand All @@ -11,6 +12,7 @@

class ScoreDatabase(str, Enum):
"""Enum class to define the score database."""

Conservation = "CONSERV"
EVE = "EVE"
ESM1b = "ESM"
Expand All @@ -20,7 +22,7 @@ class ScoreDatabase(str, Enum):
@dataclass
class ProtvarScore(RESTAPIClient):
"""Class to interact with Protvar API."""

database: ScoreDatabase
"""Database to query for score: Conservation (CONSERV), EVE (EVE), ESM1b (ESM) and AlphaMissense (AM) scores."""
uniprot_id: str
Expand All @@ -47,12 +49,11 @@ def create_query_url(self):
mut_new = self.mut

self.url_query = (
self.url
.replace("<UNIPROT>", self.uniprot_id)
.replace("<POS>", str(self.pos))
.replace(mut_old, mut_new)
.replace("<DATABASE>", self.database)
)
self.url.replace("<UNIPROT>", self.uniprot_id)
.replace("<POS>", str(self.pos))
.replace(mut_old, mut_new)
.replace("<DATABASE>", self.database)
)

def query_api(self) -> dict:
header = {"Accept": "application/json"}
Expand All @@ -62,4 +63,4 @@ def query_api(self) -> dict:
self._protvar_score = json.loads(res.text)
else:
print(f"Error: {res.status_code}")
self._protvar_scores = None
self._protvar_scores = None

0 comments on commit d7f599d

Please sign in to comment.