Skip to content

Commit

Permalink
pub version 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
edikedik committed Jul 21, 2023
1 parent 284f8e9 commit e88c6b3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion kinactive/__about__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__author__ = "Ivan Reveguk"
__author_email__ = "<ivan.reveguk@gmail.com>"
__version__ = "0.1.dev1"
__version__ = "0.1"
51 changes: 27 additions & 24 deletions kinactive/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
ChainList,
ChainSequence,
ChainStructure,
read_chains,
ChainIOConfig,
)
from lXtractor.ext import PDB, PyHMMer, SIFTS, fetch_uniprot, filter_by_method
from lXtractor.util import get_files, read_fasta, write_fasta
from more_itertools import ilen, take, consume, unzip
from more_itertools import ilen, consume, unzip
from toolz import curry, groupby, itemmap, keyfilter, keymap
from tqdm.auto import tqdm

Expand Down Expand Up @@ -53,13 +51,13 @@ def _get_remaining(names: abc.Iterable[str], dir_: Path) -> set[str]:


def _is_sequence_of_chain_seqs(
s: abc.Sequence[t.Any],
s: abc.Sequence[t.Any],
) -> t.TypeGuard[abc.Sequence[ChainSequence]]:
return all(isinstance(x, ChainSequence) for x in s)


def _stage_chain_init(
seq: T, pdb_chains: abc.Iterable[str], pdb_dir: Path, fmt: str
seq: T, pdb_chains: abc.Iterable[str], pdb_dir: Path, fmt: str
) -> tuple[T, list[tuple[Path, list[str]]]]:
id2chains = groupby(op.itemgetter(0), map(lambda x: x.split(":"), pdb_chains))
path2chains = itemmap(
Expand All @@ -71,7 +69,7 @@ def _stage_chain_init(


def _filter_by_size(
structures: list[ChainStructure], cfg: DBConfig
structures: list[ChainStructure], cfg: DBConfig
) -> list[ChainStructure]:
return [s for s in structures if len(s.seq) >= cfg.pdb_str_min_size]

Expand Down Expand Up @@ -173,10 +171,10 @@ def _get_sifts_xray(self) -> list[str]:
return filter_by_method(sifts.pdb_ids, pdb=pdb, method="X-ray")

def build(
self,
uniprot_ids: abc.Collection[str] | None = None,
pdb_chain_ids: abc.Collection[str] | None = None,
n_domains: int = 0,
self,
uniprot_ids: abc.Collection[str] | None = None,
pdb_chain_ids: abc.Collection[str] | None = None,
n_domains: int = 0,
) -> ChainList[Chain]:
"""
Build a new lXt-PK data collection.
Expand Down Expand Up @@ -204,8 +202,8 @@ def filter_domain_str_by_canon_seq_match(c: Chain) -> Chain:
match_name = "Match_seq1_seq1_canonical"
c = c.apply_structures(match_seq).filter_structures(
lambda s: (
len(s.seq) >= self.cfg.pk_min_str_domain_size
and s.seq.meta[match_name] >= self.cfg.pk_min_str_seq_match
len(s.seq) >= self.cfg.pk_min_str_domain_size
and s.seq.meta[match_name] >= self.cfg.pk_min_str_seq_match
)
)
return c
Expand Down Expand Up @@ -370,12 +368,12 @@ def filter_domain_str_by_canon_seq_match(c: Chain) -> Chain:
return chains

def save(
self,
dest: Path | None = None,
chains: abc.Iterable[Chain] | None = None,
*,
overwrite: bool = False,
summary: bool = True,
self,
dest: Path | None = None,
chains: abc.Iterable[Chain] | None = None,
*,
overwrite: bool = False,
summary: bool = True,
) -> None:
"""
Save DB sequence to file system.
Expand Down Expand Up @@ -407,7 +405,7 @@ def save(
LOGGER.info(f"Saved summary file {name} to {dest}")

def load(
self, dump: Path | abc.Iterable[Path]
self, dump: Path | abc.Iterable[Path]
) -> ChainList[Chain]:
"""
Load prepared db.
Expand All @@ -422,12 +420,17 @@ def load(
dump = list(dump)
LOGGER.info(f"Got {len(dump)} initial paths to read")

chains = read_chains(
dump,
children=True,
seq_cfg=ChainIOConfig(verbose=self.cfg.verbose),
str_cfg=ChainIOConfig(verbose=self.cfg.verbose, num_proc=self.cfg.io_cpus),
io = ChainIO(
num_proc=self.cfg.io_cpus,
verbose=self.cfg.verbose,
tolerate_failures=True,
)
chain_read_it = io.read_chain(
dump, callbacks=[chain_tree.recover], search_children=True
)

chains = ChainList(chain_read_it)

chains = chains.apply(
chain_tree.recover,
verbose=self.cfg.verbose,
Expand Down
4 changes: 2 additions & 2 deletions kinactive/distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ def superpose(
to this output (inplace).
"""
try:
_key = {'min': min, 'max': max}[key]
_key = {"min": min, "max": max}[key]
except KeyError as e:
raise ValueError('Invalid key') from e
raise ValueError("Invalid key") from e

structures = ChainList(structures)
if len(structures) == 1:
Expand Down

0 comments on commit e88c6b3

Please sign in to comment.