From ad5568f43ed2cdf2f406cc3b18953a573ef9b076 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 16 Oct 2024 22:04:01 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../databases/kinase_schema.py | 21 +++++++-------- .../databases/klifs.py | 27 +++++++++---------- 2 files changed, 22 insertions(+), 26 deletions(-) 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 ec15ec6..c28ec93 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 @@ -6,12 +6,12 @@ from pydantic import BaseModel, ValidationError, constr, model_validator from typing_extensions import Self +from missense_kinase_toolkit.databases import klifs from missense_kinase_toolkit.databases.kincore import ( align_kincore2uniprot, extract_pk_fasta_info_as_dict, ) from missense_kinase_toolkit.databases.utils import get_repo_root -from missense_kinase_toolkit.databases import klifs logger = logging.getLogger(__name__) @@ -154,7 +154,7 @@ class KinaseInfo(BaseModel): Pfam: Pfam | None KinCore: KinCore | None bool_offset: bool = True - KLIFS2UniProt: dict[str, int] | None = None + KLIFS2UniProt: dict[str, int] | None = None # https://docs.pydantic.dev/latest/examples/custom_validators/#validating-nested-model-fields @model_validator(mode="after") @@ -185,30 +185,27 @@ def validate_uniprot_length(cls, values): "UniProt sequence length does not match Pfam protein length." ) return values - + @model_validator(mode="after") def generate_klifs2uniprot_dict(self) -> Self: """Generate dictionary mapping KLIFS to UniProt indices.""" if self.KinCore is not None: - kd_idx = (self.KinCore.start-1, self.KinCore.end-1) + kd_idx = (self.KinCore.start - 1, self.KinCore.end - 1) else: kd_idx = (None, None) if self.KLIFS is not None and self.KLIFS.pocket_seq is not None: temp_obj = klifs.KLIFSPocket( - uniprotSeq = self.UniProt.canonical_seq, - klifsSeq = self.KLIFS.pocket_seq, - idx_kd = kd_idx, - offset_bool = self.bool_offset + uniprotSeq=self.UniProt.canonical_seq, + klifsSeq=self.KLIFS.pocket_seq, + idx_kd=kd_idx, + offset_bool=self.bool_offset, ) if temp_obj.list_align is not None: self.KLIFS2UniProt = dict( - zip( - klifs.LIST_KLIFS_REGION, - temp_obj.list_align - ) + zip(klifs.LIST_KLIFS_REGION, temp_obj.list_align) ) return self diff --git a/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/klifs.py b/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/klifs.py index 078ffd0..b455bdc 100644 --- a/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/klifs.py +++ b/missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/klifs.py @@ -1,7 +1,7 @@ import logging import re -from itertools import chain from dataclasses import dataclass, field +from itertools import chain import numpy as np from Bio import Align @@ -139,12 +139,15 @@ LIST_KLIFS_REGION = list( chain( - *[[f"{key}:{i}" for i in range(val["start"], val["end"] + 1)] \ - for key, val in DICT_POCKET_KLIFS_REGIONS.items()] + *[ + [f"{key}:{i}" for i in range(val["start"], val["end"] + 1)] + for key, val in DICT_POCKET_KLIFS_REGIONS.items() + ] ) ) """list[str]: List of string of all KLIFS pocket regions in format region:idx.""" + class KLIFS(SwaggerAPIClient): """Class to interact with the KLIFS API.""" @@ -327,6 +330,7 @@ class KLIFSPocket: List of final alignments to UniProt sequence """ + uniprotSeq: str klifsSeq: str idx_kd: tuple[int | None, int | None] @@ -475,7 +479,6 @@ def select_correct_alignment( else: alignment = alignments[list_idx[0]] - return self.return_idx_of_alignment_match(alignment) def align_klifs_pocket_to_uniprot_seq( @@ -713,12 +716,9 @@ def iterate_klifs_alignment( i + start_global for i in list_global ] - def generate_alignment_list( - self, - bool_offset: bool - ) -> list[str | None]: + def generate_alignment_list(self, bool_offset: bool) -> list[str | None]: """Generate and validate alignment list. - + Parameters ---------- bool_offset : bool @@ -731,8 +731,7 @@ def generate_alignment_list( """ list_align = [] for list_idx, list_seq in zip( - self.list_substring_idxs, - self.list_klifs_substr_actual + self.list_substring_idxs, self.list_klifs_substr_actual ): if list_idx is not None and len(list_idx) == 1: if bool_offset: @@ -744,7 +743,7 @@ def generate_alignment_list( list_align.append(None) else: list_align.append(temp_idx) - temp_idx+=1 + temp_idx += 1 elif list_idx is None: list_align.extend([None] * len(list_seq)) else: @@ -757,7 +756,7 @@ def generate_alignment_list( list_align.append(list_idx[idx] + 1) else: list_align.append(list_idx[idx]) - idx+=1 + idx += 1 for idx, i in enumerate(list_align): if i is not None: @@ -778,5 +777,5 @@ def generate_alignment_list( f"KLIFS: {self.klifsSeq[idx]}\n" ) return None - + self.list_align = list_align