Coverage for biobb_pdb_tools/pdb_tools/biobb_pdb_fixinsert.py: 95%

38 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-04 08:26 +0000

1#!/usr/bin/env python3 

2 

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

4 

5from typing import Optional 

6from biobb_common.generic.biobb_object import BiobbObject 

7from biobb_common.tools import file_utils as fu 

8from biobb_common.tools.file_utils import launchlogger 

9 

10 

11class Pdbfixinsert(BiobbObject): 

12 """ 

13 | biobb_pdb_tools Pdbfixinsert 

14 | Deletes insertion codes and shifts the residue numbering of downstream residues. 

15 | Works by deleting an insertion code and shifting the residue numbering of downstream residues. Allows for picking specific residues to delete insertion codes for. 

16 

17 Args: 

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

19 output_file_path (str): PDB file with fixed insertion codes. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_pdb_tools/master/biobb_pdb_tools/test/reference/pdb_tools/ref_pdb_fixinsert.pdb>`_. Accepted formats: pdb (edam:format_1476). 

20 properties (dic): 

21 * **residues** (*string*) - (None) Specific residues to delete insertion codes for, format: "A9,B12" (chain and residue number). 

22 * **binary_path** (*str*) - ("pdb_fixinsert") Path to the pdb_fixinsert executable binary. 

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

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

25 

26 Examples: 

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

28 

29 from biobb_pdb_tools.pdb_tools.biobb_pdb_fixinsert import biobb_pdb_fixinsert 

30 

31 # Delete specific insertion codes 

32 prop = { 

33 'residues': 'A9,B12' 

34 } 

35 biobb_pdb_fixinsert(input_file_path='/path/to/input.pdb', 

36 output_file_path='/path/to/output.pdb', 

37 properties=prop) 

38 

39 Info: 

40 * wrapped_software: 

41 * name: pdb_tools 

42 * version: >=2.5.0 

43 * license: Apache-2.0 

44 * ontology: 

45 * name: EDAM 

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

47 

48 """ 

49 

50 def __init__( 

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

52 ) -> None: 

53 properties = properties or {} 

54 

55 super().__init__(properties) 

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

57 

58 self.io_dict = { 

59 "in": {"input_file_path": input_file_path}, 

60 "out": {"output_file_path": output_file_path}, 

61 } 

62 

63 self.binary_path = properties.get("binary_path", "pdb_fixinsert") 

64 self.residues = properties.get("residues", None) 

65 self.properties = properties 

66 

67 self.check_properties(properties) 

68 self.check_arguments() 

69 

70 @launchlogger 

71 def launch(self) -> int: 

72 """Execute the :class:`Pdbfixinsert <biobb_pdb_tools.pdb_tools.pdb_fixinsert>` object.""" 

73 

74 if self.check_restart(): 

75 return 0 

76 self.stage_files() 

77 

78 instructions = [] 

79 if self.residues: 

80 instructions.append("-" + str(self.residues)) 

81 fu.log("Appending specific residues to delete insertion codes for", 

82 self.out_log, self.global_log) 

83 

84 self.cmd = [ 

85 self.binary_path, 

86 " ".join(instructions), 

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

88 ">", 

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

90 ] 

91 

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

93 

94 fu.log( 

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

96 self.out_log, 

97 self.global_log, 

98 ) 

99 

100 self.run_biobb() 

101 self.copy_to_host() 

102 self.remove_tmp_files() 

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

104 

105 return self.return_code 

106 

107 

108def biobb_pdb_fixinsert( 

109 input_file_path: str, 

110 output_file_path: str, 

111 properties: Optional[dict] = None, 

112 **kwargs, 

113) -> int: 

114 """Create :class:`Pdbfixinsert <biobb_pdb_tools.pdb_tools.pdb_fixinsert>` class and 

115 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_fixinsert.launch>` method.""" 

116 

117 return Pdbfixinsert(**dict(locals())).launch() 

118 

119 

120main = Pdbfixinsert.get_main(biobb_pdb_fixinsert, "Deletes insertion codes and shifts the residue numbering of downstream residues.") 

121biobb_pdb_fixinsert.__doc__ = Pdbfixinsert.__doc__ 

122 

123if __name__ == "__main__": 

124 main()