Coverage for biobb_model / model / checking_log.py: 88%

33 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-22 13:18 +0000

1#!/usr/bin/env python3 

2 

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

4 

5from typing import Optional 

6 

7from biobb_common.generic.biobb_object import BiobbObject 

8from biobb_common.tools.file_utils import launchlogger 

9 

10 

11class CheckingLog(BiobbObject): 

12 """ 

13 | biobb_model CheckingLog 

14 | Class to check the errors of a PDB structure. 

15 | Check the errors of a PDB structure and create a report log file. 

16 

17 Args: 

18 input_pdb_path (str): Input PDB file path. File type: input. `Sample file <https://github.com/bioexcel/biobb_model/raw/master/biobb_model/test/data/model/2ki5.pdb>`_. Accepted formats: pdb (edam:format_1476). 

19 output_log_path (str): Output report log file path. File type: output. `Sample file <https://github.com/bioexcel/biobb_model/raw/master/biobb_model/test/reference/model/checking.log>`_. Accepted formats: log (edam:format_2330). 

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

21 * **modeller_key** (*str*) - (None) Modeller license key. 

22 * **binary_path** (*str*) - ("check_structure") Path to the check_structure 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 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory. 

26 

27 Examples: 

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

29 

30 from biobb_model.model.checking_log import checking_log 

31 prop = { 'restart': False } 

32 checking_log(input_pdb_path='/path/to/myStructure.pdb', 

33 output_log_path='/path/to/myReport.log', 

34 properties=prop) 

35 

36 Info: 

37 * wrapped_software: 

38 * name: In house 

39 * license: Apache-2.0 

40 * ontology: 

41 * name: EDAM 

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

43 """ 

44 

45 def __init__( 

46 self, 

47 input_pdb_path: str, 

48 output_log_path: str, 

49 properties: Optional[dict] = None, 

50 **kwargs, 

51 ) -> None: 

52 properties = properties or {} 

53 

54 # Call parent class constructor 

55 super().__init__(properties) 

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

57 

58 # Input/Output files 

59 self.io_dict = { 

60 "in": {"input_pdb_path": input_pdb_path}, 

61 "out": {"output_log_path": output_log_path}, 

62 } 

63 

64 # Properties specific for BB 

65 self.binary_path = properties.get("binary_path", "check_structure") 

66 self.modeller_key = properties.get("modeller_key") 

67 

68 # Check the properties 

69 self.check_properties(properties) 

70 self.check_arguments() 

71 

72 @launchlogger 

73 def launch(self) -> int: 

74 """Execute the :class:`CheckingLog <model.checking_log.CheckingLog>` object.""" 

75 

76 # Setup Biobb 

77 if self.check_restart(): 

78 return 0 

79 self.stage_files() 

80 

81 # Create command line 

82 self.cmd = [ 

83 self.binary_path, 

84 "-i", 

85 self.stage_io_dict["in"]["input_pdb_path"], 

86 "checkall", 

87 ">", 

88 self.stage_io_dict["out"]["output_log_path"], 

89 ] 

90 

91 if self.modeller_key: 

92 self.cmd.insert(1, self.modeller_key) 

93 self.cmd.insert(1, "--modeller_key") 

94 

95 # Run Biobb block 

96 self.run_biobb() 

97 

98 # Copy files to host 

99 self.copy_to_host() 

100 

101 # Remove temporal files 

102 self.remove_tmp_files() 

103 

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

105 return self.return_code 

106 

107 

108def checking_log( 

109 input_pdb_path: str, 

110 output_log_path: str, 

111 properties: Optional[dict] = None, 

112 **kwargs, 

113) -> int: 

114 """Create :class:`CheckingLog <model.checking_log.CheckingLog>` class and 

115 execute the :meth:`launch() <model.checking_log.CheckingLog.launch>` method.""" 

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

117 

118 

119checking_log.__doc__ = CheckingLog.__doc__ 

120main = CheckingLog.get_main(checking_log, "Check the errors of a PDB structure and create a report log file.") 

121 

122if __name__ == "__main__": 

123 main()