Coverage for biobb_pdb_tools/pdb_tools/biobb_pdb_reres.py: 95%
37 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-04 08:26 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-04 08:26 +0000
1#!/usr/bin/env python3
3"""Module containing the Pdbreres class and the command line interface."""
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
11class Pdbreres(BiobbObject):
12 """
13 | biobb_pdb_tools Pdbreres
14 | Renumbers the residues of the PDB file starting from a given number (default 1).
15 | This tool renumbers the residues of the PDB file starting from a given number (default 1). It can be used to renumber the residues of a PDB file starting from a given number.
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/1AKI.pdb>`_. Accepted formats: pdb (edam:format_1476).
19 output_file_path (str): Renumbered PDB file by number of redisue selected. File type: output. `Sample file <https://github.com/bioexcel/biobb_pdb_tools/blob/master/biobb_pdb_tools/test/reference/pdb_tools/ref_pdb_reres.pdb>`_. Accepted formats: pdb (edam:format_1476).
20 properties (dic):
21 * **number** (*int*) - (4) Number of the protein residue.
22 * **binary_path** (*str*) - ("pdb_reres") Path to the pdb_reres 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.
26 Examples:
27 This is a use example of how to use the building block from Python::
29 from biobb_pdb_tools.pdb_tools.biobb_pdb_reres import biobb_pdb_reres
31 prop = {
32 'number': 4
33 }
34 biobb_pdb_reres(input_file_path='/path/to/input.pdb',
35 output_file_path='/path/to/output.pdb',
36 properties=prop)
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()
56 self.io_dict = {
57 "in": {"input_file_path": input_file_path},
58 "out": {"output_file_path": output_file_path},
59 }
61 self.binary_path = properties.get("binary_path", "pdb_reres")
62 self.number = properties.get("number", False)
63 self.properties = properties
64 self.check_init(properties)
66 @launchlogger
67 def launch(self) -> int:
68 """Execute the :class:`Pdbreres <biobb_pdb_tools.pdb_tools.pdb_reres>` object."""
70 if self.check_restart():
71 return 0
72 self.stage_files()
74 instructions = []
75 if self.number:
76 instructions.append("-" + str(self.number))
77 fu.log("Appending optional boolean property",
78 self.out_log, self.global_log)
80 self.cmd = [
81 self.binary_path,
82 " ".join(instructions),
83 self.stage_io_dict["in"]["input_file_path"],
84 ">",
85 self.io_dict["out"]["output_file_path"],
86 ]
88 fu.log(" ".join(self.cmd), self.out_log, self.global_log)
90 fu.log(
91 "Creating command line with instructions and required arguments",
92 self.out_log,
93 self.global_log,
94 )
96 self.run_biobb()
97 self.copy_to_host()
99 self.remove_tmp_files()
100 self.check_arguments(output_files_created=True, raise_exception=False)
102 return self.return_code
105def biobb_pdb_reres(
106 input_file_path: str,
107 output_file_path: str,
108 properties: Optional[dict] = None,
109 **kwargs,
110) -> int:
111 """Create :class:`Pdbreres <biobb_pdb_tools.pdb_tools.pdb_reres>` class and
112 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_reres.launch>` method."""
114 return Pdbreres(**dict(locals())).launch()
117biobb_pdb_reres.__doc__ = Pdbreres.__doc__
118main = Pdbreres.get_main(biobb_pdb_reres, "Renumbers the residues of the PDB file starting from a given number (default 1).")
120if __name__ == "__main__":
121 main()