Coverage for biobb_haddock/haddock/capri_eval.py: 92%

26 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 CapriEval class and the command line interface.""" 

4 

5from os.path import abspath 

6from typing import Optional 

7import biobb_haddock.haddock.common as common 

8 

9 

10class CapriEval(common.HaddockStepBase): 

11 """ 

12 | biobb_haddock CapriEval 

13 | Wrapper class for the HADDOCK3 CapriEval module. 

14 | The CapriEval module. `HADDOCK3 CapriEval module <https://www.bonvinlab.org/haddock3/modules/analysis/haddock.modules.analysis.caprieval.html>`_ computes Capri evaluation for a docking. 

15 

16 Args: 

17 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). 

18 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_caprieval.zip>`_. Accepted formats: directory (edam:format_1915). 

19 output_evaluation_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_caprieval.zip>`_. Accepted formats: zip (edam:format_3987). 

20 reference_pdb_path (str) (Optional): Path to the input PDB file containing an structure for reference. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/data/haddock/e2a-hpr_1GGR.pdb>`_. Accepted formats: pdb (edam:format_1476). 

21 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). 

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

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

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

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

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

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

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

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

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

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

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

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

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

35 

36 

37 Examples: 

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

39 

40 from biobb_haddock.haddock.capri_eval import capri_eval 

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

42 capri_eval(input_haddock_wf_data='/path/to/myInputData', 

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

44 properties=prop) 

45 

46 Info: 

47 * wrapped_software: 

48 * name: HADDOCK3 

49 * version: 2025.5 

50 * license: Apache-2.0 

51 * ontology: 

52 * name: EDAM 

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

54 """ 

55 

56 def __init__( 

57 self, 

58 input_haddock_wf_data: str, 

59 output_haddock_wf_data: str, 

60 output_evaluation_zip_path: Optional[str] = None, 

61 reference_pdb_path: Optional[str] = None, 

62 haddock_config_path: Optional[str] = None, 

63 properties: Optional[dict] = None, 

64 **kwargs, 

65 ) -> None: 

66 properties = properties or {} 

67 

68 # Call parent class constructor 

69 super().__init__(properties) 

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

71 

72 # Input/Output files 

73 self.io_dict = { 

74 "in": { 

75 "input_haddock_wf_data": input_haddock_wf_data, 

76 "haddock_config_path": haddock_config_path, 

77 "reference_pdb_path": reference_pdb_path, 

78 }, 

79 "out": { 

80 "output_haddock_wf_data": output_haddock_wf_data, 

81 "output_evaluation_zip_path": output_evaluation_zip_path, 

82 }, 

83 } 

84 

85 # Properties specific for HADDOCK Step 

86 self.haddock_step_name = "caprieval" 

87 # Handle configuration options from properties 

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

89 # Global HADDOCK configuration options 

90 self.global_cfg = properties.get("global_cfg", dict(postprocess=True)) 

91 # Properties specific for BB 

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

93 # Check the properties 

94 self.check_init(properties) 

95 

96 def _handle_config_arguments(self): 

97 """Handle configuration options from arguments.""" 

98 if self.io_dict["in"].get("reference_fname"): 

99 self.cfg["reference_fname"] = abspath(self.stage_io_dict["in"].get("reference_fname")) 

100 

101 def _handle_step_output(self): 

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

103 if output_evaluation_zip_path := self.io_dict["out"].get("output_evaluation_zip_path"): 

104 self.copy_step_output( 

105 lambda path: str(path).endswith(("izone", "aln", "tsv")), 

106 output_evaluation_zip_path 

107 ) 

108 

109 

110def capri_eval( 

111 input_haddock_wf_data: str, 

112 output_haddock_wf_data: str, 

113 output_evaluation_zip_path: Optional[str] = None, 

114 reference_pdb_path: Optional[str] = None, 

115 haddock_config_path: Optional[str] = None, 

116 properties: Optional[dict] = None, 

117 **kwargs, 

118) -> int: 

119 """Create :class:`CapriEval <biobb_haddock.haddock.capri_eval>` class and 

120 execute the :meth:`launch() <biobb_haddock.haddock.capri_eval.launch>` method.""" 

121 # Launch method inherited from HaddockStepBase 

122 return CapriEval(**dict(locals())).launch() 

123 

124 

125capri_eval.__doc__ = CapriEval.__doc__ 

126main = CapriEval.get_main(capri_eval, 'Wrapper of the HADDOCK3 CapriEval module.') 

127 

128 

129if __name__ == "__main__": 

130 main()