From d7f599dddf71c9bac52c2ef8f1d29bfec216e21a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Nov 2024 23:00:39 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../databases/cbioportal.py | 1 - .../databases/kinase_schema.py | 8 +- .../missense_kinase_toolkit/databases/plot.py | 112 +++++++++--------- .../databases/protvar.py | 19 +-- 4 files changed, 73 insertions(+), 67 deletions(-) diff --git a/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/cbioportal.py b/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/cbioportal.py index c0772a9..701d2bc 100644 --- a/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/cbioportal.py +++ b/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/cbioportal.py @@ -173,4 +173,3 @@ def try_except_middle_int(str_in): return int(str_in[1:-1]) except ValueError: return None - \ No newline at end of file diff --git a/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/kinase_schema.py b/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/kinase_schema.py index 5882289..910469a 100644 --- a/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/kinase_schema.py +++ b/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/kinase_schema.py @@ -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 @@ -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() } diff --git a/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/plot.py b/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/plot.py index 5e4ddb6..29c7563 100644 --- a/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/plot.py +++ b/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/plot.py @@ -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] @@ -28,14 +30,14 @@ 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] @@ -43,7 +45,7 @@ def get_colors( """ 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.""" @@ -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) @@ -66,14 +68,14 @@ 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: @@ -81,59 +83,59 @@ def generate_alignment(self) -> None: # 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) @@ -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.""" diff --git a/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/protvar.py b/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/protvar.py index d1c7b62..1aa7074 100644 --- a/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/protvar.py +++ b/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/protvar.py @@ -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 @@ -11,6 +12,7 @@ class ScoreDatabase(str, Enum): """Enum class to define the score database.""" + Conservation = "CONSERV" EVE = "EVE" ESM1b = "ESM" @@ -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 @@ -47,12 +49,11 @@ def create_query_url(self): mut_new = self.mut self.url_query = ( - self.url - .replace("", self.uniprot_id) - .replace("", str(self.pos)) - .replace(mut_old, mut_new) - .replace("", self.database) - ) + self.url.replace("", self.uniprot_id) + .replace("", str(self.pos)) + .replace(mut_old, mut_new) + .replace("", self.database) + ) def query_api(self) -> dict: header = {"Accept": "application/json"} @@ -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 \ No newline at end of file + self._protvar_scores = None