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 Oct 16, 2024
1 parent adc17a1 commit ad5568f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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."""

Expand Down Expand Up @@ -327,6 +330,7 @@ class KLIFSPocket:
List of final alignments to UniProt sequence
"""

uniprotSeq: str
klifsSeq: str
idx_kd: tuple[int | None, int | None]
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -778,5 +777,5 @@ def generate_alignment_list(
f"KLIFS: {self.klifsSeq[idx]}\n"
)
return None

self.list_align = list_align

0 comments on commit ad5568f

Please sign in to comment.