Coverage for biobb_pdb_tools/pdb_tools/biobb_pdb_keepcoord.py: 76%
45 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-20 08:28 +0000
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-20 08:28 +0000
1#!/usr/bin/env python3
3"""Module containing the Pdbkeepcoord 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 import file_utils as fu
11from biobb_common.tools.file_utils import launchlogger
14# 1. Rename class as required
15class Pdbkeepcoord(BiobbObject):
16 """
17 | biobb_pdb_tools Pdbkeepcoord
18 | Removes all non-coordinate records from the file.
19 | Keeps only MODEL, ENDMDL, END, ATOM, HETATM, CONECT records from a PDB file.
21 Args:
22 input_file_path (str): PDB file. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_pdb_tools/master/biobb_pdb_tools/test/data/pdb_tools/1AKI.pdb>`_. Accepted formats: pdb (edam:format_1476).
23 output_file_path (str): PDB file with only coordinate records. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_pdb_tools/master/biobb_pdb_tools/test/reference/pdb_tools/ref_pdb_keepcoord.pdb>`_. Accepted formats: pdb (edam:format_1476).
24 properties (dic):
25 * **binary_path** (*str*) - ("pdb_keepcoord") Path to the pdb_keepcoord executable binary.
26 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
27 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
29 Examples:
30 This is a use example of how to use the building block from Python::
32 from biobb_pdb_tools.pdb_tools.biobb_pdb_keepcoord import biobb_pdb_keepcoord
34 # Keep only coordinate records
35 biobb_pdb_keepcoord(input_file_path='/path/to/input.pdb',
36 output_file_path='/path/to/output.pdb')
38 Info:
39 * wrapped_software:
40 * name: pdb_tools
41 * version: >=2.5.0
42 * license: Apache-2.0
43 * ontology:
44 * name: EDAM
45 * schema: http://edamontology.org/EDAM.owl
47 """
49 def __init__(
50 self, input_file_path, output_file_path, properties=None, **kwargs
51 ) -> None:
52 properties = properties or {}
54 super().__init__(properties)
55 self.locals_var_dict = locals().copy()
57 self.io_dict = {
58 "in": {"input_file_path": input_file_path},
59 "out": {"output_file_path": output_file_path},
60 }
62 self.binary_path = properties.get("binary_path", "pdb_keepcoord")
63 self.properties = properties
65 self.check_properties(properties)
66 self.check_arguments()
68 @launchlogger
69 def launch(self) -> int:
70 """Execute the :class:`Pdbkeepcoord <biobb_pdb_tools.pdb_tools.pdb_keepcoord>` object."""
72 if self.check_restart():
73 return 0
74 self.stage_files()
76 self.cmd = [
77 self.binary_path,
78 self.stage_io_dict["in"]["input_file_path"],
79 ">",
80 self.io_dict["out"]["output_file_path"],
81 ]
83 fu.log(" ".join(self.cmd), self.out_log, self.global_log)
85 fu.log(
86 "Creating command line with instructions and required arguments",
87 self.out_log,
88 self.global_log,
89 )
91 self.run_biobb()
92 self.copy_to_host()
93 self.tmp_files.extend([self.stage_io_dict.get("unique_dir", "")])
94 self.remove_tmp_files()
95 self.check_arguments(output_files_created=True, raise_exception=False)
97 return self.return_code
100def biobb_pdb_keepcoord(
101 input_file_path: str,
102 output_file_path: str,
103 properties: Optional[dict] = None,
104 **kwargs,
105) -> int:
106 """Create :class:`Pdbkeepcoord <biobb_pdb_tools.pdb_tools.pdb_keepcoord>` class and
107 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_keepcoord.launch>` method."""
109 return Pdbkeepcoord(
110 input_file_path=input_file_path,
111 output_file_path=output_file_path,
112 properties=properties,
113 **kwargs,
114 ).launch()
117biobb_pdb_keepcoord.__doc__ = Pdbkeepcoord.__doc__
120def main():
121 """Command line execution of this building block. Please check the command line documentation."""
122 parser = argparse.ArgumentParser(
123 description="Removes all non-coordinate records from the file. Keeps only MODEL, ENDMDL, END, ATOM, HETATM, CONECT records.",
124 formatter_class=lambda prog: argparse.RawTextHelpFormatter(
125 prog, width=99999),
126 )
127 parser.add_argument("--config", required=True, help="Configuration file")
129 required_args = parser.add_argument_group("required arguments")
130 required_args.add_argument(
131 "--input_file_path",
132 required=True,
133 help="PDB file. Accepted formats: pdb.",
134 )
135 required_args.add_argument(
136 "--output_file_path",
137 required=True,
138 help="PDB file with only coordinate records. Accepted formats: pdb.",
139 )
141 args = parser.parse_args()
142 args.config = args.config or "{}"
143 properties = settings.ConfReader(config=args.config).get_prop_dic()
145 biobb_pdb_keepcoord(
146 input_file_path=args.input_file_path,
147 output_file_path=args.output_file_path,
148 properties=properties,
149 )
152if __name__ == "__main__":
153 main()