Coverage for biobb_haddock/haddock/sele_top.py: 95%

22 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-03 15:55 +0000

1#!/usr/bin/env python3 

2 

3"""Module containing the HADDOCK3 SeleTop class and the command line interface.""" 

4 

5from typing import Optional 

6import biobb_haddock.haddock.common as common 

7 

8 

9class SeleTop(common.HaddockStepBase): 

10 """ 

11 | biobb_haddock SeleTop 

12 | Wrapper class for the HADDOCK3 SeleTop module. 

13 | The SeleTop module. `HADDOCK3 SeleTop module <https://www.bonvinlab.org/haddock3/modules/analysis/haddock.modules.analysis.seletop.html>`_ selects the top models of a docking. 

14 

15 Args: 

16 input_haddock_wf_data (dir): Path to the input directory containing all the current Haddock workflow data. File type: input. `Sample file <https://github.com/bioexcel/biobb_haddock/raw/master/biobb_haddock/test/data/haddock/haddock_wf_data_rigid.zip>`_. Accepted formats: directory (edam:format_1915). 

17 output_haddock_wf_data (dir): Path to the output directory containing all the current Haddock workflow data. File type: output. `Sample file <https://github.com/bioexcel/biobb_haddock/raw/master/biobb_haddock/test/data/haddock/haddock_wf_data_emref.zip>`_. Accepted formats: directory (edam:format_1915). 

18 output_selection_zip_path (str) (Optional): Path to the output PDB file collection in zip format. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/reference/haddock/ref_seletop.zip>`_. Accepted formats: zip (edam:format_3987). 

19 haddock_config_path (str) (Optional): Haddock configuration CFG file path. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/data/haddock/run.cfg>`_. Accepted formats: cfg (edam:format_1476). 

20 properties (dict - Python dictionary object containing the tool parameters, not input/output files): 

21 * **cfg** (*dict*) - ({}) Haddock configuration options specification. 

22 * **global_cfg** (*dict*) - ({"postprocess": False}) `Global configuration options <https://www.bonvinlab.org/haddock3-user-manual/global_parameters.html>`_ specification. 

23 * **binary_path** (*str*) - ("haddock") Path to the haddock haddock executable binary. 

24 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files. 

25 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist. 

26 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory. 

27 * **container_path** (*str*) - (None) Path to the binary executable of your container. 

28 * **container_image** (*str*) - (None) Container Image identifier. 

29 * **container_volume_path** (*str*) - ("/data") Path to an internal directory in the container. 

30 * **container_working_dir** (*str*) - (None) Path to the internal CWD in the container. 

31 * **container_user_id** (*str*) - (None) User number id to be mapped inside the container. 

32 * **container_shell_path** (*str*) - ("/bin/bash") Path to the binary executable of the container shell. 

33 

34 

35 Examples: 

36 This is a use example of how to use the building block from Python:: 

37 

38 from biobb_haddock.haddock.sele_top import sele_top 

39 prop = { 'binary_path': 'haddock' } 

40 sele_top(input_haddock_wf_data='/path/to/myInputData', 

41 output_haddock_wf_data='/path/to/myOutputData', 

42 properties=prop) 

43 

44 Info: 

45 * wrapped_software: 

46 * name: HADDOCK3 

47 * version: 2025.5 

48 * license: Apache-2.0 

49 * ontology: 

50 * name: EDAM 

51 * schema: http://edamontology.org/EDAM.owl 

52 """ 

53 

54 def __init__( 

55 self, 

56 input_haddock_wf_data: str, 

57 output_haddock_wf_data: str, 

58 output_selection_zip_path: Optional[str] = None, 

59 haddock_config_path: Optional[str] = None, 

60 properties: Optional[dict] = None, 

61 **kwargs, 

62 ) -> None: 

63 properties = properties or {} 

64 

65 # Call parent class constructor 

66 super().__init__(properties) 

67 self.locals_var_dict = locals().copy() 

68 

69 # Input/Output files 

70 self.io_dict = { 

71 "in": { 

72 "input_haddock_wf_data": input_haddock_wf_data, 

73 "haddock_config_path": haddock_config_path 

74 }, 

75 "out": { 

76 "output_haddock_wf_data": output_haddock_wf_data, 

77 "output_selection_zip_path": output_selection_zip_path 

78 }, 

79 } 

80 

81 # Properties specific for BB 

82 self.haddock_step_name = "seletop" 

83 # Handle configuration options from propierties 

84 self.cfg = {k: v for k, v in properties.get("cfg", dict()).items()} 

85 # Global HADDOCK configuration options 

86 self.global_cfg = properties.get("global_cfg", dict(postprocess=False)) 

87 # Properties specific for BB 

88 self.binary_path = properties.get("binary_path", "haddock3") 

89 # Check the properties 

90 self.check_init(properties) 

91 

92 def _handle_step_output(self): 

93 """Handle how the output files from the step are copied to host.""" 

94 if output_selection_zip_path := self.io_dict["out"].get("output_selection_zip_path"): 

95 self.copy_step_output( 

96 lambda path: str(path.name) not in ["io.json", "params.cfg"], 

97 output_selection_zip_path, 

98 sele_top=True 

99 ) 

100 

101 

102def sele_top( 

103 input_haddock_wf_data: str, 

104 output_haddock_wf_data: str, 

105 output_selection_zip_path: Optional[str] = None, 

106 haddock_config_path: Optional[str] = None, 

107 properties: Optional[dict] = None, 

108 **kwargs, 

109) -> int: 

110 """Create :class:`SeleTop <biobb_haddock.haddock.sele_top>` class and 

111 execute the :meth:`launch() <biobb_haddock.haddock.sele_top.launch>` method.""" 

112 # Launch method inherited from HaddockStepBase 

113 return SeleTop(**dict(locals())).launch() 

114 

115 

116sele_top.__doc__ = SeleTop.__doc__ 

117main = SeleTop.get_main(sele_top, "Wrapper of the HADDOCK3 SeleTop module.") 

118 

119 

120if __name__ == "__main__": 

121 main()