Coverage for biobb_model/model/checking_log.py: 70%
44 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-13 17:26 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-13 17:26 +0000
1#!/usr/bin/env python3
3"""Module containing the CheckingLog class and the command line interface."""
4import argparse
5from biobb_common.generic.biobb_object import BiobbObject
6from biobb_common.configuration import settings
7from biobb_common.tools.file_utils import launchlogger
10class CheckingLog(BiobbObject):
11 """
12 | biobb_model CheckingLog
13 | Class to check the errors of a PDB structure.
14 | Check the errors of a PDB structure and create a report log file.
16 Args:
17 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).
18 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).
19 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
20 * **modeller_key** (*str*) - (None) Modeller license key.
21 * **binary_path** (*str*) - ("check_structure") Path to the check_structure executable binary.
22 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
23 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
25 Examples:
26 This is a use example of how to use the building block from Python::
28 from biobb_model.model.checking_log import checking_log
29 prop = { 'restart': False }
30 checking_log(input_pdb_path='/path/to/myStructure.pdb',
31 output_log_path='/path/to/myReport.log',
32 properties=prop)
34 Info:
35 * wrapped_software:
36 * name: In house
37 * license: Apache-2.0
38 * ontology:
39 * name: EDAM
40 * schema: http://edamontology.org/EDAM.owl
41 """
43 def __init__(self, input_pdb_path: str, output_log_path: str, properties: dict = None, **kwargs) -> None:
44 properties = properties or {}
46 # Call parent class constructor
47 super().__init__(properties)
48 self.locals_var_dict = locals().copy()
50 # Input/Output files
51 self.io_dict = {
52 "in": {"input_pdb_path": input_pdb_path},
53 "out": {"output_log_path": output_log_path}
54 }
56 # Properties specific for BB
57 self.binary_path = properties.get('binary_path', 'check_structure')
58 self.modeller_key = properties.get('modeller_key')
60 # Check the properties
61 self.check_properties(properties)
62 self.check_arguments()
64 @launchlogger
65 def launch(self) -> int:
66 """Execute the :class:`CheckingLog <model.checking_log.CheckingLog>` object."""
68 # Setup Biobb
69 if self.check_restart():
70 return 0
71 self.stage_files()
73 # Create command line
74 self.cmd = [self.binary_path,
75 '-i', self.stage_io_dict["in"]["input_pdb_path"],
76 "checkall",
77 '>', self.stage_io_dict["out"]["output_log_path"]]
79 if self.modeller_key:
80 self.cmd.insert(1, self.modeller_key)
81 self.cmd.insert(1, '--modeller_key')
83 # Run Biobb block
84 self.run_biobb()
86 # Copy files to host
87 self.copy_to_host()
89 # Remove temporal files
90 self.tmp_files.extend([self.stage_io_dict.get("unique_dir")])
91 self.remove_tmp_files()
93 self.check_arguments(output_files_created=True, raise_exception=False)
94 return self.return_code
97def checking_log(input_pdb_path: str, output_log_path: str, properties: dict = None, **kwargs) -> int:
98 """Create :class:`CheckingLog <model.checking_log.CheckingLog>` class and
99 execute the :meth:`launch() <model.checking_log.CheckingLog.launch>` method."""
100 return CheckingLog(input_pdb_path=input_pdb_path,
101 output_log_path=output_log_path,
102 properties=properties, **kwargs).launch()
105def main():
106 parser = argparse.ArgumentParser(description="Check the errors of a PDB structure and create a report log file.",
107 formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999))
108 parser.add_argument('-c', '--config', required=False, help="This file can be a YAML file, JSON file or JSON string")
110 # Specific args of each building block
111 required_args = parser.add_argument_group('required arguments')
112 required_args.add_argument('-i', '--input_pdb_path', required=True, help="Input PDB file name")
113 required_args.add_argument('-o', '--output_log_path', required=True, help="Output log file name")
115 args = parser.parse_args()
116 config = args.config if args.config else None
117 properties = settings.ConfReader(config=config).get_prop_dic()
119 # Specific call of each building block
120 checking_log(input_pdb_path=args.input_pdb_path,
121 output_log_path=args.output_log_path,
122 properties=properties)
125if __name__ == '__main__':
126 main()