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 25, 2024
1 parent 1f76f84 commit 964fefd
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 89 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from abc import ABC, abstractmethod
from dataclasses import dataclass


class CustomAligner(ABC):
Expand All @@ -22,27 +22,22 @@ class ClustalOmegaAligner(CustomAligner):
"""list[str]: List of sequences to align."""
path_bin: str = "/usr/local/bin/clustalo"
"""str: Path to clustalo binary. Default is "/usr/local/bin/clustalo"."""

def __post_init__(self):
from biotite.sequence import ProteinSequence, align

self.alphabet = ProteinSequence.alphabet
self.matrix_substitution = align.SubstitutionMatrix(
self.alphabet,
self.alphabet,
self.substitution_matrix
self.alphabet, self.alphabet, self.substitution_matrix
)
self.list_sequences = [ProteinSequence(seq) for seq in self.list_sequences]
self.align()


def align(self) -> str:
from biotite.application import clustalo

app = clustalo.ClustalOmegaApp(
self.list_sequences,
self.path_bin,
self.matrix_substitution
self.list_sequences, self.path_bin, self.matrix_substitution
)

app.start()
Expand All @@ -54,6 +49,7 @@ def align(self) -> str:
@dataclass
class BioAligner(CustomAligner):
"""BioPython aligner class for aligning sequences. Initialized without sequences"""

from Bio import Align

mode: str = "local"
Expand All @@ -65,7 +61,7 @@ class BioAligner(CustomAligner):

def __post_init__(self):
from Bio import Align

self.aligner = Align.PairwiseAligner()
self.aligner.mode = self.mode
self.aligner.substitution_matrix = Align.substitution_matrices.load(
Expand All @@ -77,6 +73,7 @@ def __post_init__(self):
def align(self, seq1: str, seq2: str) -> Align.MultipleSeqAlignment:
return self.aligner.align(seq1, seq2)


@dataclass
class BL2UniProtAligner(BioAligner):
mode: str = "global"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,43 +210,41 @@ def generate_klifs2uniprot_dict(self) -> Self:

return self


def recursive_idx_search(
self,
idx: int,
idx: int,
decreasing: bool,
) -> int | str:
"""Recursively search for preceding or subsequent alignment index if current value is None.
Parameters
----------
idx : int
Current index
Returns
-------
idx : int
Index of alignment
"""
Parameters
----------
idx : int
Current index
Returns
-------
idx : int
Index of alignment
"""
if idx == 0:
return "NONE"
list_keys = list(self.KLIFS2UniProt.keys())
if self.KLIFS2UniProt[list_keys[idx]] is None:
if decreasing:
idx = self.recursive_idx_search(idx-1, self.KLIFS2UniProt, True)
idx = self.recursive_idx_search(idx - 1, self.KLIFS2UniProt, True)
else:
idx = self.recursive_idx_search(idx+1, self.KLIFS2UniProt, False)
idx = self.recursive_idx_search(idx + 1, self.KLIFS2UniProt, False)
return idx


def find_intra_gaps(
self,
self,
dict_temp: dict[str, int | None],
bool_bl: bool = True,
) -> tuple[int, int] | None:
"""Find intra-pocket gaps in KLIFS pocket region.
Parameters
----------
bool_bl : bool
Expand All @@ -259,29 +257,30 @@ def find_intra_gaps(
"""
if bool_bl:
region,idx_in, idx_out = "b.l", 1, 2
region, idx_in, idx_out = "b.l", 1, 2
else:
region, idx_in, idx_out = "linker", 0, 1

list_keys = list(self.KLIFS2UniProt.keys())
list_idx = [idx for idx, i in enumerate(self.KLIFS2UniProt.keys()) if region in i]

#TODO: ATR and CAMKK1 have inter hinge:linker region
list_idx = [
idx for idx, i in enumerate(self.KLIFS2UniProt.keys()) if region in i
]

# TODO: ATR and CAMKK1 have inter hinge:linker region
start = list_idx[idx_in]
end = list_idx[idx_out]

if dict_temp[list_keys[start]] is None:
start = self.recursive_idx_search(start-1, dict_temp, True)
start = self.recursive_idx_search(start - 1, dict_temp, True)
if dict_temp[list_keys[end]] is None:
end = self.recursive_idx_search(end+1, dict_temp, False)
end = self.recursive_idx_search(end + 1, dict_temp, False)

# STK40 has no b.l region or preceding
if start == "NONE":
return None

return (dict_temp[list_keys[start]], dict_temp[list_keys[end]])


def return_intra_gap_substr(
self,
bl_bool: bool = True,
Expand All @@ -294,50 +293,52 @@ def return_intra_gap_substr(
if end - start == 1:
return None
else:
return self.uniprotSeq[start-1:end-1]

return self.uniprotSeq[start - 1 : end - 1]

@staticmethod
def reverse_order_dict_of_dict(
dict_in: dict[str, dict[str, str | int | None]],
) -> dict[str, dict[str, str | int | None]]:
"""Reverse order of dictionary of dictionaries.
Parameters
----------
dict_in : dict[str, dict[str, str | int | None]]
Dictionary of dictionaries
Returns
-------
dict_out : dict[str, dict[str, str | int | None]]
Dictionary of dictionaries with reversed order
"""
dict_out = {key1: {key2 : dict_in[key2][key1] for key2 in dict_in.keys()}\
for key1 in set(chain(*[list(j.keys()) for j in dict_in.values()]))}
dict_out = {
key1: {key2: dict_in[key2][key1] for key2 in dict_in.keys()}
for key1 in set(chain(*[list(j.keys()) for j in dict_in.values()]))
}
return dict_out


@staticmethod
def replace_none_with_max_len_gap(
dict_in: dict[str, dict[str, str | int | None]],
) -> dict[str, dict[str, str | int | None]]:
"""Replace None values with maximum length gap in dictionary of dictionaries.
Parameters
----------
dict_in : dict[str, dict[str, str | int | None]]
Dictionary of dictionaries
Returns
-------
dict_out : dict[str, dict[str, str | int | None]]
Dictionary of dictionaries with None values replaced with maximum length gap
"""
dict_max_len = {key1: max([len(val2) for val2 in val1.values() if val2 is not None])\
for key1, val1 in dict_in.items()}
dict_max_len = {
key1: max([len(val2) for val2 in val1.values() if val2 is not None])
for key1, val1 in dict_in.items()
}

dict_out = deepcopy(dict_in)
for key1, length in dict_max_len.items():
Expand All @@ -347,17 +348,15 @@ def replace_none_with_max_len_gap(

return dict_out


def find_and_align_inter_and_intra_klifs_regions(
self,
list_cols: list[str] | None = None,
):
if list_cols is None:
['II:III', 'III:αC', 'IV:V', 'hinge:linker', 'αD:αE', 'αE:VI', 'VII:VIII']
["II:III", "III:αC", "IV:V", "hinge:linker", "αD:αE", "αE:VI", "VII:VIII"]
pass



def check_if_file_exists_then_load_dataframe(str_file: str) -> pd.DataFrame | None:
"""Check if file exists and load dataframe.
Expand Down Expand Up @@ -741,7 +740,7 @@ def create_kinase_models_from_df(
# .apply(lambda x: "".join(x) == "domain"), "name"]
# .tolist()
# )
#
#
# USED FOR INTER MAPPING ASSESSMENT
# dict_kinase = create_kinase_models_from_df()

Expand All @@ -761,9 +760,9 @@ def create_kinase_models_from_df(

# list_temp = []
# for idx, row in df_klifs_idx.iterrows():

# cols_start, cols_end = dict_cols[key], dict_cols[val]

# start = row.loc[cols_start].values
# if np.all(np.isnan(start)):
# max_start = None
Expand All @@ -775,9 +774,9 @@ def create_kinase_models_from_df(
# min_end = None
# else:
# min_end = np.nanmin(end)

# list_temp.append((max_start, min_end))

# list_inter.append(list_temp)

# df_inter = pd.DataFrame(list_inter,
Expand All @@ -786,6 +785,6 @@ def create_kinase_models_from_df(
# df_length = df_inter.map(lambda x: try_except_substraction(x[0], x[1]))

# df_multi = df_length.loc[:, df_length.apply(lambda x: any(x > 0))]
# # BUB1B has 1 residue in b.l intra region that was
# # BUB1B has 1 residue in b.l intra region that was
# # previously captured in αC:b.l since flanked by None
# list_cols = [i for i in df_multi.columns if i != "αC:b.l"]
# list_cols = [i for i in df_multi.columns if i != "αC:b.l"]
Loading

0 comments on commit 964fefd

Please sign in to comment.