Coverage for biobb_pdb_tools/pdb_tools/biobb_pdb_fixinsert.py: 78%
50 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 Pdbfixinsert 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 Pdbfixinsert(BiobbObject):
16 """
17 | biobb_pdb_tools Pdbfixinsert
18 | Deletes insertion codes and shifts the residue numbering of downstream residues.
19 | Works by deleting an insertion code and shifting the residue numbering of downstream residues. Allows for picking specific residues to delete insertion codes for.
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/1IGY.pdb>`_. Accepted formats: pdb (edam:format_1476).
23 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).
24 properties (dic):
25 * **residues** (*string*) - (None) Specific residues to delete insertion codes for, format: "A9,B12" (chain and residue number).
26 * **binary_path** (*str*) - ("pdb_fixinsert") Path to the pdb_fixinsert executable binary.
27 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
28 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
30 Examples:
31 This is a use example of how to use the building block from Python::
33 from biobb_pdb_tools.pdb_tools.biobb_pdb_fixinsert import biobb_pdb_fixinsert
35 # Delete specific insertion codes
36 prop = {
37 'residues': 'A9,B12'
38 }
39 biobb_pdb_fixinsert(input_file_path='/path/to/input.pdb',
40 output_file_path='/path/to/output.pdb',
41 properties=prop)
43 Info:
44 * wrapped_software:
45 * name: pdb_tools
46 * version: >=2.5.0
47 * license: Apache-2.0
48 * ontology:
49 * name: EDAM
50 * schema: http://edamontology.org/EDAM.owl
52 """
54 def __init__(
55 self, input_file_path, output_file_path, properties=None, **kwargs
56 ) -> None:
57 properties = properties or {}
59 super().__init__(properties)
60 self.locals_var_dict = locals().copy()
62 self.io_dict = {
63 "in": {"input_file_path": input_file_path},
64 "out": {"output_file_path": output_file_path},
65 }
67 self.binary_path = properties.get("binary_path", "pdb_fixinsert")
68 self.residues = properties.get("residues", None)
69 self.properties = properties
71 self.check_properties(properties)
72 self.check_arguments()
74 @launchlogger
75 def launch(self) -> int:
76 """Execute the :class:`Pdbfixinsert <biobb_pdb_tools.pdb_tools.pdb_fixinsert>` object."""
78 if self.check_restart():
79 return 0
80 self.stage_files()
82 instructions = []
83 if self.residues:
84 instructions.append("-" + str(self.residues))
85 fu.log("Appending specific residues to delete insertion codes for",
86 self.out_log, self.global_log)
88 self.cmd = [
89 self.binary_path,
90 " ".join(instructions),
91 self.stage_io_dict["in"]["input_file_path"],
92 ">",
93 self.io_dict["out"]["output_file_path"],
94 ]
96 fu.log(" ".join(self.cmd), self.out_log, self.global_log)
98 fu.log(
99 "Creating command line with instructions and required arguments",
100 self.out_log,
101 self.global_log,
102 )
104 self.run_biobb()
105 self.copy_to_host()
106 self.tmp_files.extend([self.stage_io_dict.get("unique_dir", "")])
107 self.remove_tmp_files()
108 self.check_arguments(output_files_created=True, raise_exception=False)
110 return self.return_code
113def biobb_pdb_fixinsert(
114 input_file_path: str,
115 output_file_path: str,
116 properties: Optional[dict] = None,
117 **kwargs,
118) -> int:
119 """Create :class:`Pdbfixinsert <biobb_pdb_tools.pdb_tools.pdb_fixinsert>` class and
120 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_fixinsert.launch>` method."""
122 return Pdbfixinsert(
123 input_file_path=input_file_path,
124 output_file_path=output_file_path,
125 properties=properties,
126 **kwargs,
127 ).launch()
130biobb_pdb_fixinsert.__doc__ = Pdbfixinsert.__doc__
133def main():
134 """Command line execution of this building block. Please check the command line documentation."""
135 parser = argparse.ArgumentParser(
136 description="Deletes insertion codes and shifts the residue numbering of downstream residues.",
137 formatter_class=lambda prog: argparse.RawTextHelpFormatter(
138 prog, width=99999),
139 )
140 parser.add_argument("--config", required=True, help="Configuration file")
142 required_args = parser.add_argument_group("required arguments")
143 required_args.add_argument(
144 "--input_file_path",
145 required=True,
146 help="PDB file. Accepted formats: pdb.",
147 )
148 required_args.add_argument(
149 "--output_file_path",
150 required=True,
151 help="PDB file with fixed insertion codes. Accepted formats: pdb.",
152 )
154 args = parser.parse_args()
155 args.config = args.config or "{}"
156 properties = settings.ConfReader(config=args.config).get_prop_dic()
158 biobb_pdb_fixinsert(
159 input_file_path=args.input_file_path,
160 output_file_path=args.output_file_path,
161 properties=properties,
162 )
165if __name__ == "__main__":
166 main()