Coverage for biobb_pdb_tools/pdb_tools/biobb_pdb_chainxseg.py: 76%

45 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-20 08:28 +0000

1#!/usr/bin/env python3 

2 

3"""Module containing the Chainxseg class and the command line interface.""" 

4 

5import argparse 

6from typing import Optional 

7 

8from biobb_common.configuration import settings 

9from biobb_common.generic.biobb_object import BiobbObject 

10from biobb_common.tools import file_utils as fu 

11from biobb_common.tools.file_utils import launchlogger 

12 

13 

14class Chainxseg(BiobbObject): 

15 """ 

16 | biobb_pdb_tools Pdbtidy 

17 | Swaps the segment identifier for the chain identifier. 

18 | This tool swaps the segment identifier for the chain identifier in a PDB file. It can be used to change the segment identifier of a PDB file or to remove the segment identifier from a PDB file. 

19 

20 Args: 

21 input_file_path (str): PDB file. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_pdb_tools/master/biobb_pdb_tools/test/data/pdb_tools/1AKI.pdb>`_. Accepted formats: pdb (edam:format_1476). 

22 output_file_path (str): PDB file with exchanged segment and string identifier. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_pdb_tools/master/biobb_pdb_tools/test/reference/pdb_tools/ref_pdb_chainxseg.pdb>`_. Accepted formats: pdb (edam:format_1476). 

23 properties (dic): 

24 * **binary_path** (*str*) - ("pdb_chainxseg") Path to the pdb_chainxseg 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 

28 Examples: 

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

30 

31 from biobb_pdb_tools.pdb_tools.biobb_pdb_chainxseg import biobb_pdb_chainxseg 

32 

33 biobb_pdb_chainxseg(input_file_path='/path/to/input.pdb', 

34 output_file_path='/path/to/output.pdb') 

35 

36 Info: 

37 * wrapped_software: 

38 * name: pdb_tools 

39 * version: >=2.5.0 

40 * license: Apache-2.0 

41 * ontology: 

42 * name: EDAM 

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

44 

45 """ 

46 

47 def __init__( 

48 self, input_file_path, output_file_path, properties=None, **kwargs 

49 ) -> None: 

50 properties = properties or {} 

51 

52 super().__init__(properties) 

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

54 

55 self.io_dict = { 

56 "in": {"input_file_path": input_file_path}, 

57 "out": {"output_file_path": output_file_path}, 

58 } 

59 

60 self.binary_path = properties.get("binary_path", "pdb_chainxseg") 

61 self.properties = properties 

62 

63 self.check_properties(properties) 

64 self.check_arguments() 

65 

66 @launchlogger 

67 def launch(self) -> int: 

68 """Execute the :class:`Chainxseg <biobb_pdb_tools.pdb_tools.pdb_chainxseg>` object.""" 

69 

70 if self.check_restart(): 

71 return 0 

72 self.stage_files() 

73 

74 self.cmd = [ 

75 self.binary_path, 

76 self.stage_io_dict["in"]["input_file_path"], 

77 ">", 

78 self.io_dict["out"]["output_file_path"], 

79 ] 

80 

81 fu.log(" ".join(self.cmd), self.out_log, self.global_log) 

82 

83 fu.log( 

84 "Creating command line with instructions and required arguments", 

85 self.out_log, 

86 self.global_log, 

87 ) 

88 

89 self.run_biobb() 

90 

91 self.copy_to_host() 

92 

93 self.tmp_files.extend([self.stage_io_dict.get("unique_dir", "")]) 

94 self.remove_tmp_files() 

95 

96 self.check_arguments(output_files_created=True, raise_exception=False) 

97 

98 return self.return_code 

99 

100 

101def biobb_pdb_chainxseg( 

102 input_file_path: str, 

103 output_file_path: str, 

104 properties: Optional[dict] = None, 

105 **kwargs, 

106) -> int: 

107 """Create :class:`biobb_pdb_tools.pdb_tools.pdb_chainxseg>` class and 

108 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_chainxseg.launch>` method.""" 

109 return Chainxseg( 

110 input_file_path=input_file_path, 

111 output_file_path=output_file_path, 

112 properties=properties, 

113 **kwargs, 

114 ).launch() 

115 

116 

117biobb_pdb_chainxseg.__doc__ = Chainxseg.__doc__ 

118 

119 

120def main(): 

121 """Command line execution of this building block. Please check the command line documentation.""" 

122 parser = argparse.ArgumentParser( 

123 description="Swaps the segment identifier for the chain identifier.", 

124 formatter_class=lambda prog: argparse.RawTextHelpFormatter( 

125 prog, width=99999), 

126 ) 

127 parser.add_argument("--config", required=True, help="Configuration file") 

128 

129 required_args = parser.add_argument_group("required arguments") 

130 required_args.add_argument( 

131 "--input_file_path", 

132 required=True, 

133 help="Description for the first input file path. Accepted formats: pdb.", 

134 ) 

135 required_args.add_argument( 

136 "--output_file_path", 

137 required=True, 

138 help="Description for the output file path. Accepted formats: pdb.", 

139 ) 

140 

141 args = parser.parse_args() 

142 args.config = args.config or "{}" 

143 properties = settings.ConfReader(config=args.config).get_prop_dic() 

144 

145 biobb_pdb_chainxseg( 

146 input_file_path=args.input_file_path, 

147 output_file_path=args.output_file_path, 

148 properties=properties, 

149 ) 

150 

151 

152if __name__ == "__main__": 

153 main()