Coverage for biobb_haddock/haddock_restraints/haddock3_actpass_to_ambig.py: 76%

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

4 

5from typing import Optional 

6from biobb_common.generic.biobb_object import BiobbObject 

7from biobb_common.tools.file_utils import launchlogger 

8 

9 

10class Haddock3ActpassToAmbig(BiobbObject): 

11 """ 

12 | biobb_haddock Haddock3ActpassToAmbig 

13 | Wrapper class for the Haddock-Restraints active_passive_to_ambig module. 

14 | `Haddock-Restraints active_passive_to_ambig <https://www.bonvinlab.org/haddock3/clients/haddock.clis.restraints.active_passive_to_ambig.html>`_ generates a corresponding ambig.tbl file to be used by HADDOCK from two given files containing active (in the first line) and passive (second line) residues. 

15 

16 Args: 

17 input_actpass1_path (str): Path to the first input HADDOCK active-passive file containing active (in the first line) and passive (second line) residues. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/data/haddock/haddock_actpass1.txt>`_. Accepted formats: txt (edam:format_2330), dat (edam:format_2330), in (edam:format_2330), pass (edam:format_2330). 

18 input_actpass2_path (str): Path to the second input HADDOCK active-passive file containing active (in the first line) and passive (second line) residues. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/data/haddock/haddock_actpass2.txt>`_. Accepted formats: txt (edam:format_2330), dat (edam:format_2330), in (edam:format_2330), pass (edam:format_2330). 

19 output_tbl_path (str): Path to the output HADDOCK tbl file with Ambiguous Interaction Restraints (AIR) information. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/reference/haddock_restraints/haddock_actpass.tbl>`_. Accepted formats: tbl (edam:format_2330), txt (edam:format_2330), out (edam:format_2330). 

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

21 * **pass_to_act** (*bool*) - (False) Path to the haddock haddock executable binary. 

22 * **segid_one** (*str*) - (None) Segid of the first model. 

23 * **segid_two** (*str*) - (None) Segid of the second model. 

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

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

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

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

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

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

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

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

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

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

34 

35 

36 Examples: 

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

38 

39 from biobb_haddock.haddock_restraints.haddock3_actpass_to_ambig import haddock3_actpass_to_ambig 

40 haddock3_actpass_to_ambig( 

41 input_actpass1_path='/path/to/haddock_actpass1.txt', 

42 input_actpass2_path='/path/to/haddock_actpass2.txt', 

43 output_tbl_path='/path/to/output_AIR.tbl' 

44 ) 

45 

46 Info: 

47 * wrapped_software: 

48 * name: Haddock3-restraints 

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_actpass1_path: str, 

59 input_actpass2_path: str, 

60 output_tbl_path: str, 

61 properties: Optional[dict] = None, 

62 **kwargs, 

63 ) -> None: 

64 properties = properties or {} 

65 

66 # Call parent class constructor 

67 super().__init__(properties) 

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

69 

70 # Input/Output files 

71 self.io_dict = { 

72 "in": { 

73 "input_actpass1_path": input_actpass1_path, 

74 "input_actpass2_path": input_actpass2_path, 

75 }, 

76 "out": { 

77 "output_tbl_path": output_tbl_path, 

78 }, 

79 } 

80 

81 # Properties specific for BB 

82 self.binary_path = properties.get("binary_path", "haddock3-restraints") 

83 self.pass_to_act = properties.get("pass_to_act", False) 

84 self.segid_one = properties.get("segid_one", None) 

85 self.segid_two = properties.get("segid_two", None) 

86 

87 # Check the properties 

88 self.check_init(properties) 

89 

90 @launchlogger 

91 def launch(self) -> int: 

92 """Execute the :class:`Haddock3ActpassToAmbig <biobb_haddock.haddock_restraints.haddock3_actpass_to_ambig>` object.""" 

93 

94 # Setup Biobb 

95 if self.check_restart(): 

96 return 0 

97 self.stage_files() 

98 

99 if self.pass_to_act: 

100 with open(self.stage_io_dict['in']['input_actpass1_path'], 'r') as file1, \ 

101 open(self.stage_io_dict['in']['input_actpass2_path'], 'r') as file2: 

102 actpass1_lines = file1.readlines() 

103 actpass2_lines = file2.readlines() 

104 

105 with open(self.stage_io_dict['in']['input_actpass1_path'], 'w') as file1, \ 

106 open(self.stage_io_dict['in']['input_actpass2_path'], 'w') as file2: 

107 file1.writelines([actpass1_lines[1], actpass1_lines[0], '\n']) 

108 file2.writelines([actpass2_lines[1], actpass2_lines[0], '\n']) 

109 

110 # haddock3-restraints active_passive_to_ambig haddock_actpass.txt 

111 self.cmd = [self.binary_path, "active_passive_to_ambig", self.stage_io_dict['in'] 

112 ['input_actpass1_path'], self.stage_io_dict['in']['input_actpass2_path']] 

113 

114 if self.segid_one is not None: 

115 self.cmd.extend(["--segid-one", self.segid_one]) 

116 if self.segid_two is not None: 

117 self.cmd.extend(["--segid-two", self.segid_two]) 

118 

119 self.cmd.append(">") 

120 self.cmd.append(self.stage_io_dict['out']['output_tbl_path']) 

121 self.cmd.append("2>&1") 

122 

123 # Run Biobb block 

124 self.run_biobb() 

125 

126 # Remove deprecation warning if present 

127 with open(self.stage_io_dict['out']['output_tbl_path'], 'r') as file: 

128 lines = file.readlines() 

129 if lines and "DEPRECATION NOTICE" in lines[0]: 

130 with open(self.stage_io_dict['out']['output_tbl_path'], 'w') as file: 

131 file.writelines(lines[1:]) 

132 

133 # Copy files to host 

134 self.copy_to_host() 

135 

136 # Remove temporal files 

137 self.remove_tmp_files() 

138 

139 return self.return_code 

140 

141 

142def haddock3_actpass_to_ambig( 

143 input_actpass1_path: str, 

144 input_actpass2_path: str, 

145 output_tbl_path: str, 

146 properties: Optional[dict] = None, 

147 **kwargs, 

148) -> int: 

149 """Create :class:`Haddock3ActpassToAmbig <biobb_haddock.haddock_restraints.haddock3_actpass_to_ambig>` class and 

150 execute the :meth:`launch() <biobb_haddock.haddock_restraints.haddock3_actpass_to_ambig.launch>` method.""" 

151 return Haddock3ActpassToAmbig(**dict(locals())).launch() 

152 

153 

154haddock3_actpass_to_ambig.__doc__ = Haddock3ActpassToAmbig.__doc__ 

155main = Haddock3ActpassToAmbig.get_main( 

156 haddock3_actpass_to_ambig, 

157 "Wrapper of the Haddock-Restraints active_passive_to_ambig module." 

158) 

159 

160 

161if __name__ == "__main__": 

162 main()