Coverage for biobb_pdb_tools/pdb_tools/biobb_pdb_selaltloc.py: 89%

37 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 Pdbselaltloc 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 Pdbselaltloc(BiobbObject): 

12 """ 

13 | biobb_pdb_tools Pdbselaltloc 

14 | Selects alternative locations from a PDB file. 

15 | By default, selects the label with the highest occupancy value for each atom, but the user can define a specific altloc label to select. Selecting by highest occupancy removes all altloc labels for all atoms. If the user provides an option (e.g. -A), only atoms with conformers with an altloc A are processed by the script. 

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/9INS.pdb>`_. Accepted formats: pdb (edam:format_1476). 

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

20 properties (dic): 

21 * **altloc** (*string*) - (None) Specific alternative location label to select (e.g. "A"). 

22 * **binary_path** (*str*) - ("pdb_selaltloc") Path to the pdb_selaltloc 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_selaltloc import biobb_pdb_selaltloc 

30 

31 # Select the highest occupancy alternative locations 

32 biobb_pdb_selaltloc(input_file_path='/path/to/input.pdb', 

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

34 

35 # Select a specific alternative location label 

36 prop = { 

37 'altloc': 'A' 

38 } 

39 biobb_pdb_selaltloc(input_file_path='/path/to/input.pdb', 

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

41 properties=prop) 

42 

43 Info: 

44 * wrapped_software: 

45 * name: pdb_tools 

46 * version: >=2.5.0 

47 * license: Apache-2.0 

48 * ontology: 

49 * name: EDAM 

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

51 

52 """ 

53 

54 def __init__( 

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

56 ) -> None: 

57 properties = properties or {} 

58 

59 super().__init__(properties) 

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

61 

62 self.io_dict = { 

63 "in": {"input_file_path": input_file_path}, 

64 "out": {"output_file_path": output_file_path}, 

65 } 

66 

67 self.binary_path = properties.get("binary_path", "pdb_selaltloc") 

68 self.altloc = properties.get("altloc", None) 

69 self.properties = properties 

70 self.check_init(properties) 

71 

72 @launchlogger 

73 def launch(self) -> int: 

74 """Execute the :class:`Pdbselaltloc <biobb_pdb_tools.pdb_tools.pdb_selaltloc>` object.""" 

75 

76 if self.check_restart(): 

77 return 0 

78 self.stage_files() 

79 

80 instructions = [] 

81 if self.altloc: 

82 instructions.append("-" + str(self.altloc)) 

83 fu.log("Selecting alternative location label: " + self.altloc, self.out_log, self.global_log) 

84 

85 self.cmd = [ 

86 self.binary_path, 

87 " ".join(instructions), 

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

89 ">", 

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

91 ] 

92 

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

94 

95 fu.log( 

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

97 self.out_log, self.global_log) 

98 

99 self.run_biobb() 

100 self.copy_to_host() 

101 self.remove_tmp_files() 

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

103 

104 return self.return_code 

105 

106 

107def biobb_pdb_selaltloc( 

108 input_file_path: str, 

109 output_file_path: str, 

110 properties: Optional[dict] = None, 

111 **kwargs, 

112) -> int: 

113 """Create :class:`Pdbselaltloc <biobb_pdb_tools.pdb_tools.pdb_selaltloc>` class and 

114 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_selaltloc.launch>` method.""" 

115 

116 return Pdbselaltloc(**dict(locals())).launch() 

117 

118 

119biobb_pdb_selaltloc.__doc__ = Pdbselaltloc.__doc__ 

120main = Pdbselaltloc.get_main(biobb_pdb_selaltloc, "Selects alternative locations from a PDB file.") 

121 

122if __name__ == "__main__": 

123 main()