Coverage for biobb_model/model/checking_log.py: 68%
44 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-28 11:32 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-28 11:32 +0000
1#!/usr/bin/env python3
3"""Module containing the CheckingLog class and the command line interface."""
5import argparse
6from typing import Optional
8from biobb_common.configuration import settings
9from biobb_common.generic.biobb_object import BiobbObject
10from biobb_common.tools.file_utils import launchlogger
13class CheckingLog(BiobbObject):
14 """
15 | biobb_model CheckingLog
16 | Class to check the errors of a PDB structure.
17 | Check the errors of a PDB structure and create a report log file.
19 Args:
20 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).
21 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).
22 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
23 * **modeller_key** (*str*) - (None) Modeller license key.
24 * **binary_path** (*str*) - ("check_structure") Path to the check_structure 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.
29 Examples:
30 This is a use example of how to use the building block from Python::
32 from biobb_model.model.checking_log import checking_log
33 prop = { 'restart': False }
34 checking_log(input_pdb_path='/path/to/myStructure.pdb',
35 output_log_path='/path/to/myReport.log',
36 properties=prop)
38 Info:
39 * wrapped_software:
40 * name: In house
41 * license: Apache-2.0
42 * ontology:
43 * name: EDAM
44 * schema: http://edamontology.org/EDAM.owl
45 """
47 def __init__(
48 self,
49 input_pdb_path: str,
50 output_log_path: str,
51 properties: Optional[dict] = None,
52 **kwargs,
53 ) -> None:
54 properties = properties or {}
56 # Call parent class constructor
57 super().__init__(properties)
58 self.locals_var_dict = locals().copy()
60 # Input/Output files
61 self.io_dict = {
62 "in": {"input_pdb_path": input_pdb_path},
63 "out": {"output_log_path": output_log_path},
64 }
66 # Properties specific for BB
67 self.binary_path = properties.get("binary_path", "check_structure")
68 self.modeller_key = properties.get("modeller_key")
70 # Check the properties
71 self.check_properties(properties)
72 self.check_arguments()
74 @launchlogger
75 def launch(self) -> int:
76 """Execute the :class:`CheckingLog <model.checking_log.CheckingLog>` object."""
78 # Setup Biobb
79 if self.check_restart():
80 return 0
81 self.stage_files()
83 # Create command line
84 self.cmd = [
85 self.binary_path,
86 "-i",
87 self.stage_io_dict["in"]["input_pdb_path"],
88 "checkall",
89 ">",
90 self.stage_io_dict["out"]["output_log_path"],
91 ]
93 if self.modeller_key:
94 self.cmd.insert(1, self.modeller_key)
95 self.cmd.insert(1, "--modeller_key")
97 # Run Biobb block
98 self.run_biobb()
100 # Copy files to host
101 self.copy_to_host()
103 # Remove temporal files
104 # self.tmp_files.extend([self.stage_io_dict.get("unique_dir", "")])
105 self.remove_tmp_files()
107 self.check_arguments(output_files_created=True, raise_exception=False)
108 return self.return_code
111def checking_log(
112 input_pdb_path: str,
113 output_log_path: str,
114 properties: Optional[dict] = None,
115 **kwargs,
116) -> int:
117 """Create :class:`CheckingLog <model.checking_log.CheckingLog>` class and
118 execute the :meth:`launch() <model.checking_log.CheckingLog.launch>` method."""
119 return CheckingLog(
120 input_pdb_path=input_pdb_path,
121 output_log_path=output_log_path,
122 properties=properties,
123 **kwargs,
124 ).launch()
126 checking_log.__doc__ = CheckingLog.__doc__
129def main():
130 parser = argparse.ArgumentParser(
131 description="Check the errors of a PDB structure and create a report log file.",
132 formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999),
133 )
134 parser.add_argument(
135 "-c",
136 "--config",
137 required=False,
138 help="This file can be a YAML file, JSON file or JSON string",
139 )
141 # Specific args of each building block
142 required_args = parser.add_argument_group("required arguments")
143 required_args.add_argument(
144 "-i", "--input_pdb_path", required=True, help="Input PDB file name"
145 )
146 required_args.add_argument(
147 "-o", "--output_log_path", required=True, help="Output log file name"
148 )
150 args = parser.parse_args()
151 config = args.config if args.config else None
152 properties = settings.ConfReader(config=config).get_prop_dic()
154 # Specific call of each building block
155 checking_log(
156 input_pdb_path=args.input_pdb_path,
157 output_log_path=args.output_log_path,
158 properties=properties,
159 )
162if __name__ == "__main__":
163 main()