Coverage for biobb_pdb_tools/pdb_tools/biobb_pdb_fixinsert.py: 95%
38 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 Pdbfixinsert 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 Pdbfixinsert(BiobbObject):
12 """
13 | biobb_pdb_tools Pdbfixinsert
14 | Deletes insertion codes and shifts the residue numbering of downstream residues.
15 | Works by deleting an insertion code and shifting the residue numbering of downstream residues. Allows for picking specific residues to delete insertion codes for.
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/1IGY.pdb>`_. Accepted formats: pdb (edam:format_1476).
19 output_file_path (str): PDB file with fixed insertion codes. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_pdb_tools/master/biobb_pdb_tools/test/reference/pdb_tools/ref_pdb_fixinsert.pdb>`_. Accepted formats: pdb (edam:format_1476).
20 properties (dic):
21 * **residues** (*string*) - (None) Specific residues to delete insertion codes for, format: "A9,B12" (chain and residue number).
22 * **binary_path** (*str*) - ("pdb_fixinsert") Path to the pdb_fixinsert 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_fixinsert import biobb_pdb_fixinsert
31 # Delete specific insertion codes
32 prop = {
33 'residues': 'A9,B12'
34 }
35 biobb_pdb_fixinsert(input_file_path='/path/to/input.pdb',
36 output_file_path='/path/to/output.pdb',
37 properties=prop)
39 Info:
40 * wrapped_software:
41 * name: pdb_tools
42 * version: >=2.5.0
43 * license: Apache-2.0
44 * ontology:
45 * name: EDAM
46 * schema: http://edamontology.org/EDAM.owl
48 """
50 def __init__(
51 self, input_file_path, output_file_path, properties=None, **kwargs
52 ) -> None:
53 properties = properties or {}
55 super().__init__(properties)
56 self.locals_var_dict = locals().copy()
58 self.io_dict = {
59 "in": {"input_file_path": input_file_path},
60 "out": {"output_file_path": output_file_path},
61 }
63 self.binary_path = properties.get("binary_path", "pdb_fixinsert")
64 self.residues = properties.get("residues", None)
65 self.properties = properties
67 self.check_properties(properties)
68 self.check_arguments()
70 @launchlogger
71 def launch(self) -> int:
72 """Execute the :class:`Pdbfixinsert <biobb_pdb_tools.pdb_tools.pdb_fixinsert>` object."""
74 if self.check_restart():
75 return 0
76 self.stage_files()
78 instructions = []
79 if self.residues:
80 instructions.append("-" + str(self.residues))
81 fu.log("Appending specific residues to delete insertion codes for",
82 self.out_log, self.global_log)
84 self.cmd = [
85 self.binary_path,
86 " ".join(instructions),
87 self.stage_io_dict["in"]["input_file_path"],
88 ">",
89 self.io_dict["out"]["output_file_path"],
90 ]
92 fu.log(" ".join(self.cmd), self.out_log, self.global_log)
94 fu.log(
95 "Creating command line with instructions and required arguments",
96 self.out_log,
97 self.global_log,
98 )
100 self.run_biobb()
101 self.copy_to_host()
102 self.remove_tmp_files()
103 self.check_arguments(output_files_created=True, raise_exception=False)
105 return self.return_code
108def biobb_pdb_fixinsert(
109 input_file_path: str,
110 output_file_path: str,
111 properties: Optional[dict] = None,
112 **kwargs,
113) -> int:
114 """Create :class:`Pdbfixinsert <biobb_pdb_tools.pdb_tools.pdb_fixinsert>` class and
115 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_fixinsert.launch>` method."""
117 return Pdbfixinsert(**dict(locals())).launch()
120main = Pdbfixinsert.get_main(biobb_pdb_fixinsert, "Deletes insertion codes and shifts the residue numbering of downstream residues.")
121biobb_pdb_fixinsert.__doc__ = Pdbfixinsert.__doc__
123if __name__ == "__main__":
124 main()