Skip to content

Commit

Permalink
[FIX] Fix all type hints of the project
Browse files Browse the repository at this point in the history
  • Loading branch information
PauAndrio committed May 28, 2024
1 parent 139e4c4 commit 1e41f6a
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 75 deletions.
1 change: 1 addition & 0 deletions biobb_haddock/haddock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from . import rigid_body
from . import sele_top
from . import topology
from . import sele_top_clusts

name = "haddock"
__all__ = ["capri_eval", "clust_fcc", "em_ref", "flex_ref", "rigid_body", "sele_top_clusts", "sele_top", "topology"]
17 changes: 9 additions & 8 deletions biobb_haddock/haddock/capri_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import argparse
import shutil
from pathlib import Path
from typing import Optional, Dict
from biobb_common.generic.biobb_object import BiobbObject
from biobb_common.configuration import settings
from biobb_common.tools import file_utils as fu
Expand Down Expand Up @@ -58,8 +59,8 @@ class CapriEval(BiobbObject):
"""

def __init__(self, input_haddock_wf_data_zip: str, output_evaluation_zip_path: str,
reference_pdb_path: str = None, output_haddock_wf_data_zip: str = None,
haddock_config_path: str = None, properties: dict = None, **kwargs) -> None:
reference_pdb_path: Optional[str] = None, output_haddock_wf_data_zip: Optional[str] = None,
haddock_config_path: Optional[str] = None, properties: Optional[Dict] = None, **kwargs) -> None:
properties = properties or {}

# Call parent class constructor
Expand Down Expand Up @@ -118,11 +119,11 @@ def launch(self) -> int:
if self.container_path:
fu.log('Container execution enabled', self.out_log)

shutil.copy2(self.output_cfg_path, self.stage_io_dict.get("unique_dir"))
shutil.copy2(self.output_cfg_path, self.stage_io_dict.get("unique_dir", ''))
self.output_cfg_path = str(Path(self.container_volume_path).joinpath(Path(self.output_cfg_path).name))

shutil.copytree(run_dir, str(Path(self.stage_io_dict.get("unique_dir")).joinpath(Path(run_dir).name)))
run_dir = str(Path(self.stage_io_dict.get("unique_dir")).joinpath(Path(run_dir).name))
shutil.copytree(run_dir, str(Path(self.stage_io_dict.get("unique_dir", '')).joinpath(Path(run_dir).name)))
run_dir = str(Path(self.stage_io_dict.get("unique_dir", '')).joinpath(Path(run_dir).name))

self.cmd = [self.binary_path, self.output_cfg_path, '--extend-run', run_dir]

Expand Down Expand Up @@ -151,9 +152,9 @@ def launch(self) -> int:


def capri_eval(input_haddock_wf_data_zip: str, output_evaluation_zip_path: str,
reference_pdb_path: str = None, output_haddock_wf_data_zip: str = None,
haddock_config_path: str = None,
properties: dict = None, **kwargs) -> int:
reference_pdb_path: Optional[str] = None, output_haddock_wf_data_zip: Optional[str] = None,
haddock_config_path: Optional[str] = None,
properties: Optional[Dict] = None, **kwargs) -> int:
"""Create :class:`haddock <haddock.haddock.haddock>` class and
execute the :meth:`launch() <haddock.haddock.haddock.launch>` method."""

Expand Down
15 changes: 8 additions & 7 deletions biobb_haddock/haddock/clust_fcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import argparse
import shutil
from pathlib import Path
from typing import Optional, Dict
from biobb_common.generic.biobb_object import BiobbObject
from biobb_common.configuration import settings
from biobb_common.tools import file_utils as fu
Expand Down Expand Up @@ -57,8 +58,8 @@ class ClustFCC(BiobbObject):
"""

def __init__(self, input_haddock_wf_data_zip: str, output_cluster_zip_path: str,
output_haddock_wf_data_zip: str = None, haddock_config_path: str = None,
properties: dict = None, **kwargs) -> None:
output_haddock_wf_data_zip: Optional[str] = None, haddock_config_path: Optional[str] = None,
properties: Optional[Dict] = None, **kwargs) -> None:
properties = properties or {}

# Call parent class constructor
Expand Down Expand Up @@ -111,11 +112,11 @@ def launch(self) -> int:
if self.container_path:
fu.log('Container execution enabled', self.out_log)

shutil.copy2(self.output_cfg_path, self.stage_io_dict.get("unique_dir"))
shutil.copy2(self.output_cfg_path, str(self.stage_io_dict.get("unique_dir", "")))
self.output_cfg_path = str(Path(self.container_volume_path).joinpath(Path(self.output_cfg_path).name))

shutil.copytree(run_dir, str(Path(self.stage_io_dict.get("unique_dir")).joinpath(Path(run_dir).name)))
run_dir = str(Path(self.stage_io_dict.get("unique_dir")).joinpath(Path(run_dir).name))
shutil.copytree(run_dir, str(Path(self.stage_io_dict.get("unique_dir", '')).joinpath(Path(run_dir).name)))
run_dir = str(Path(self.stage_io_dict.get("unique_dir", '')).joinpath(Path(run_dir).name))

self.cmd = [self.binary_path, self.output_cfg_path, '--extend-run', run_dir]

Expand Down Expand Up @@ -144,8 +145,8 @@ def launch(self) -> int:


def clust_fcc(input_haddock_wf_data_zip: str, output_cluster_zip_path: str,
output_haddock_wf_data_zip: str = None, haddock_config_path: str = None,
properties: dict = None, **kwargs) -> int:
output_haddock_wf_data_zip: Optional[str] = None, haddock_config_path: Optional[str] = None,
properties: Optional[Dict] = None, **kwargs) -> int:
"""Create :class:`haddock <haddock.haddock.haddock>` class and
execute the :meth:`launch() <haddock.haddock.haddock.launch>` method."""

Expand Down
20 changes: 9 additions & 11 deletions biobb_haddock/haddock/common.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
""" Common functions for package biobb_haddock.haddock """
import re
# import uuid
# import json
import logging
# from pathlib import Path
from typing import List, Dict, Mapping # , Union, Tuple, Sequence
from typing import List, Dict, Optional, Any
import biobb_common.tools.file_utils as fu


def create_cfg(output_cfg_path: str, workflow_dict: Mapping[str, str], input_cfg_path: str = None, preset_dict: Mapping[str, str] = None,
cfg_properties_dict: Mapping[str, str] = None) -> str:
def create_cfg(output_cfg_path: str, workflow_dict: Dict[str, Any],
input_cfg_path: Optional[str] = None, preset_dict: Optional[Dict[str, str]] = None,
cfg_properties_dict: Optional[Dict[str, str]] = None) -> str:
"""Creates an CFG file using the following hierarchy cfg_properties_dict > input_cfg_path > preset_dict"""
cfg_dict: Mapping[str, str] = {}
cfg_dict: Dict[str, str] = {}

if preset_dict:
for k, v in preset_dict.items():
Expand All @@ -29,7 +27,7 @@ def create_cfg(output_cfg_path: str, workflow_dict: Mapping[str, str], input_cfg
return write_cfg(output_cfg_path, workflow_dict, cfg_dict)


def write_cfg(output_cfg_path: str, workflow_dict: Mapping[str, str], cfg_dict: Mapping[str, str]):
def write_cfg(output_cfg_path: str, workflow_dict: Dict[str, str], cfg_dict: Dict[str, str]):
cfg_list: List[str] = []
if workflow_dict.get('run_dir'):
cfg_list.append(f"run_dir = '{workflow_dict['run_dir']}'")
Expand Down Expand Up @@ -70,8 +68,8 @@ def read_cfg(input_mdp_path: str) -> Dict[str, str]:
return cfg_dict


def cfg_preset(haddock_step_name: str) -> Dict[str, str]:
cfg_dict = {}
def cfg_preset(haddock_step_name: str) -> Dict[str, Any]:
cfg_dict: Dict[str, Any] = {}
if not haddock_step_name:
return cfg_dict

Expand Down Expand Up @@ -104,7 +102,7 @@ def cfg_preset(haddock_step_name: str) -> Dict[str, str]:
return cfg_dict


def unzip_workflow_data(zip_file: str, out_log: logging.Logger = None) -> str:
def unzip_workflow_data(zip_file: str, out_log: Optional[logging.Logger] = None) -> str:
""" Extract all files in the zip_file and return the directory.
Args:
Expand Down
15 changes: 8 additions & 7 deletions biobb_haddock/haddock/em_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import argparse
import shutil
from pathlib import Path
from typing import Optional, Dict
from biobb_common.generic.biobb_object import BiobbObject
from biobb_common.configuration import settings
from biobb_common.tools import file_utils as fu
Expand Down Expand Up @@ -59,8 +60,8 @@ class EMRef(BiobbObject):
"""

def __init__(self, input_haddock_wf_data_zip: str, refinement_output_zip_path: str,
restraints_table_path: str = None, output_haddock_wf_data_zip: str = None,
haddock_config_path: str = None, properties: dict = None, **kwargs) -> None:
restraints_table_path: Optional[str] = None, output_haddock_wf_data_zip: Optional[str] = None,
haddock_config_path: Optional[str] = None, properties: Optional[Dict] = None, **kwargs) -> None:
properties = properties or {}

# Call parent class constructor
Expand Down Expand Up @@ -118,11 +119,11 @@ def launch(self) -> int:
if self.container_path:
fu.log('Container execution enabled', self.out_log)

shutil.copy2(self.output_cfg_path, self.stage_io_dict.get("unique_dir"))
shutil.copy2(self.output_cfg_path, self.stage_io_dict.get("unique_dir", ""))
self.output_cfg_path = str(Path(self.container_volume_path).joinpath(Path(self.output_cfg_path).name))

shutil.copytree(run_dir, str(Path(self.stage_io_dict.get("unique_dir")).joinpath(Path(run_dir).name)))
run_dir = str(Path(self.stage_io_dict.get("unique_dir")).joinpath(Path(run_dir).name))
shutil.copytree(run_dir, str(Path(self.stage_io_dict.get("unique_dir", "")).joinpath(Path(run_dir).name)))
run_dir = str(Path(self.stage_io_dict.get("unique_dir", "")).joinpath(Path(run_dir).name))

self.cmd = [self.binary_path, self.output_cfg_path, '--extend-run', run_dir]

Expand Down Expand Up @@ -152,8 +153,8 @@ def launch(self) -> int:


def em_ref(input_haddock_wf_data_zip: str, refinement_output_zip_path: str,
restraints_table_path: str = None, output_haddock_wf_data_zip: str = None,
haddock_config_path: str = None, properties: dict = None, **kwargs) -> int:
restraints_table_path: Optional[str] = None, output_haddock_wf_data_zip: Optional[str] = None,
haddock_config_path: Optional[str] = None, properties: Optional[Dict] = None, **kwargs) -> int:
"""Create :class:`haddock <haddock.haddock.haddock>` class and
execute the :meth:`launch() <haddock.haddock.haddock.launch>` method."""

Expand Down
15 changes: 8 additions & 7 deletions biobb_haddock/haddock/flex_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import argparse
import shutil
from pathlib import Path
from typing import Optional, Dict
from biobb_common.generic.biobb_object import BiobbObject
from biobb_common.configuration import settings
from biobb_common.tools import file_utils as fu
Expand Down Expand Up @@ -59,8 +60,8 @@ class FlexRef(BiobbObject):
"""

def __init__(self, input_haddock_wf_data_zip: str, refinement_output_zip_path: str,
restraints_table_path: str = None, output_haddock_wf_data_zip: str = None,
haddock_config_path: str = None, properties: dict = None, **kwargs) -> None:
restraints_table_path: Optional[str] = None, output_haddock_wf_data_zip: Optional[str] = None,
haddock_config_path: Optional[str] = None, properties: Optional[Dict] = None, **kwargs) -> None:
properties = properties or {}

# Call parent class constructor
Expand Down Expand Up @@ -118,11 +119,11 @@ def launch(self) -> int:
if self.container_path:
fu.log('Container execution enabled', self.out_log)

shutil.copy2(self.output_cfg_path, self.stage_io_dict.get("unique_dir"))
shutil.copy2(self.output_cfg_path, self.stage_io_dict.get("unique_dir", ""))
self.output_cfg_path = str(Path(self.container_volume_path).joinpath(Path(self.output_cfg_path).name))

shutil.copytree(run_dir, str(Path(self.stage_io_dict.get("unique_dir")).joinpath(Path(run_dir).name)))
run_dir = str(Path(self.stage_io_dict.get("unique_dir")).joinpath(Path(run_dir).name))
shutil.copytree(run_dir, str(Path(self.stage_io_dict.get("unique_dir", "")).joinpath(Path(run_dir).name)))
run_dir = str(Path(self.stage_io_dict.get("unique_dir", "")).joinpath(Path(run_dir).name))

self.cmd = [self.binary_path, self.output_cfg_path, '--extend-run', run_dir]

Expand Down Expand Up @@ -152,8 +153,8 @@ def launch(self) -> int:


def flex_ref(input_haddock_wf_data_zip: str, refinement_output_zip_path: str,
restraints_table_path: str = None, output_haddock_wf_data_zip: str = None,
haddock_config_path: str = None, properties: dict = None, **kwargs) -> int:
restraints_table_path: Optional[str] = None, output_haddock_wf_data_zip: Optional[str] = None,
haddock_config_path: Optional[str] = None, properties: Optional[Dict] = None, **kwargs) -> int:
"""Create :class:`haddock <haddock.haddock.haddock>` class and
execute the :meth:`launch() <haddock.haddock.haddock.launch>` method."""

Expand Down
21 changes: 11 additions & 10 deletions biobb_haddock/haddock/rigid_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import argparse
import shutil
from pathlib import Path
from typing import Optional, Dict
from biobb_common.generic.biobb_object import BiobbObject
from biobb_common.configuration import settings
from biobb_common.tools import file_utils as fu
Expand Down Expand Up @@ -62,9 +63,9 @@ class RigidBody(BiobbObject):
"""

def __init__(self, input_haddock_wf_data_zip: str, docking_output_zip_path: str,
ambig_restraints_table_path: str = None, unambig_restraints_table_path: str = None,
hb_restraints_table_path: str = None, output_haddock_wf_data_zip: str = None,
haddock_config_path: str = None, properties: dict = None, **kwargs) -> None:
ambig_restraints_table_path: Optional[str] = None, unambig_restraints_table_path: Optional[str] = None,
hb_restraints_table_path: Optional[str] = None, output_haddock_wf_data_zip: Optional[str] = None,
haddock_config_path: Optional[str] = None, properties: Optional[Dict] = None, **kwargs) -> None:
properties = properties or {}

# Call parent class constructor
Expand Down Expand Up @@ -131,11 +132,11 @@ def launch(self) -> int:
if self.container_path:
fu.log('Container execution enabled', self.out_log)

shutil.copy2(self.output_cfg_path, self.stage_io_dict.get("unique_dir"))
shutil.copy2(self.output_cfg_path, self.stage_io_dict.get("unique_dir", ""))
self.output_cfg_path = str(Path(self.container_volume_path).joinpath(Path(self.output_cfg_path).name))

shutil.copytree(run_dir, str(Path(self.stage_io_dict.get("unique_dir")).joinpath(Path(run_dir).name)))
run_dir = str(Path(self.stage_io_dict.get("unique_dir")).joinpath(Path(run_dir).name))
shutil.copytree(run_dir, str(Path(self.stage_io_dict.get("unique_dir", "")).joinpath(Path(run_dir).name)))
run_dir = str(Path(self.stage_io_dict.get("unique_dir", "")).joinpath(Path(run_dir).name))

self.cmd = [self.binary_path, self.output_cfg_path, '--extend-run', run_dir]

Expand Down Expand Up @@ -165,10 +166,10 @@ def launch(self) -> int:


def rigid_body(input_haddock_wf_data_zip: str, docking_output_zip_path: str,
ambig_restraints_table_path: str = None, unambig_restraints_table_path: str = None,
hb_restraints_table_path: str = None, output_haddock_wf_data_zip: str = None,
haddock_config_path: str = None,
properties: dict = None, **kwargs) -> int:
ambig_restraints_table_path: Optional[str] = None, unambig_restraints_table_path: Optional[str] = None,
hb_restraints_table_path: Optional[str] = None, output_haddock_wf_data_zip: Optional[str] = None,
haddock_config_path: Optional[str] = None,
properties: Optional[Dict] = None, **kwargs) -> int:
"""Create :class:`haddock <haddock.haddock.haddock>` class and
execute the :meth:`launch() <haddock.haddock.haddock.launch>` method."""

Expand Down
15 changes: 8 additions & 7 deletions biobb_haddock/haddock/sele_top.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import argparse
import shutil
from pathlib import Path
from typing import Optional, Dict
from biobb_common.generic.biobb_object import BiobbObject
from biobb_common.configuration import settings
from biobb_common.tools import file_utils as fu
Expand Down Expand Up @@ -57,8 +58,8 @@ class SeleTop(BiobbObject):
"""

def __init__(self, input_haddock_wf_data_zip: str, output_selection_zip_path: str,
reference_pdb_path: str = None, output_haddock_wf_data_zip: str = None,
haddock_config_path: str = None, properties: dict = None, **kwargs) -> None:
reference_pdb_path: Optional[str] = None, output_haddock_wf_data_zip: Optional[str] = None,
haddock_config_path: Optional[str] = None, properties: Optional[Dict] = None, **kwargs) -> None:
properties = properties or {}

# Call parent class constructor
Expand Down Expand Up @@ -111,11 +112,11 @@ def launch(self) -> int:
if self.container_path:
fu.log('Container execution enabled', self.out_log)

shutil.copy2(self.output_cfg_path, self.stage_io_dict.get("unique_dir"))
shutil.copy2(self.output_cfg_path, self.stage_io_dict.get("unique_dir", ""))
self.output_cfg_path = str(Path(self.container_volume_path).joinpath(Path(self.output_cfg_path).name))

shutil.copytree(run_dir, str(Path(self.stage_io_dict.get("unique_dir")).joinpath(Path(run_dir).name)))
run_dir = str(Path(self.stage_io_dict.get("unique_dir")).joinpath(Path(run_dir).name))
shutil.copytree(run_dir, str(Path(self.stage_io_dict.get("unique_dir", "")).joinpath(Path(run_dir).name)))
run_dir = str(Path(self.stage_io_dict.get("unique_dir", "")).joinpath(Path(run_dir).name))

self.cmd = [self.binary_path, self.output_cfg_path, '--extend-run', run_dir]

Expand Down Expand Up @@ -144,8 +145,8 @@ def launch(self) -> int:


def sele_top(input_haddock_wf_data_zip: str, output_selection_zip_path: str,
output_haddock_wf_data_zip: str = None, haddock_config_path: str = None,
properties: dict = None, **kwargs) -> int:
output_haddock_wf_data_zip: Optional[str] = None, haddock_config_path: Optional[str] = None,
properties: Optional[Dict] = None, **kwargs) -> int:
"""Create :class:`haddock <haddock.haddock.haddock>` class and
execute the :meth:`launch() <haddock.haddock.haddock.launch>` method."""

Expand Down
Loading

0 comments on commit 1e41f6a

Please sign in to comment.