Coverage for biobb_pdb_tools/pdb_tools/biobb_pdb_seg.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 Pdbseg 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 Pdbseg(BiobbObject):
16 """
17 | biobb_pdb_tools Pdbseg
18 | Modifies the segment identifier column of a PDB file.
19 | This tool modifies the segment identifier column of a PDB file. It can be used to change the segment identifier of a PDB file or to remove the segment identifier 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/input_pdb_seg.pdb>`_. Accepted formats: pdb (edam:format_1476).
23 output_file_path (str): PDB file with segment identifier column modified. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_pdb_tools/master/biobb_pdb_tools/test/reference/pdb_tools/ref_pdb_seg.pdb>`_. Accepted formats: pdb (edam:format_1476).
24 properties (dic):
25 * **segment** (*str*) - ('B') Default is an empty segment.
26 * **binary_path** (*str*) - ("pdb_seg") Path to the pdb_seg 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_seg import biobb_pdb_seg
35 prop = {
36 'segment': 'A'
37 }
38 biobb_pdb_seg(input_file_path='/path/to/input.pdb',
39 output_file_path='/path/to/output.pdb',
40 properties=prop)
42 Info:
43 * wrapped_software:
44 * name: pdb_tools
45 * version: >=2.5.0
46 * license: Apache-2.0
47 * ontology:
48 * name: EDAM
49 * schema: http://edamontology.org/EDAM.owl
51 """
53 def __init__(
54 self, input_file_path, output_file_path, properties=None, **kwargs
55 ) -> None:
56 properties = properties or {}
57 super().__init__(properties)
58 self.locals_var_dict = locals().copy()
59 self.io_dict = {
60 "in": {"input_file_path": input_file_path},
61 "out": {"output_file_path": output_file_path},
62 }
64 self.binary_path = properties.get("binary_path", "pdb_seg")
65 self.segment = properties.get("segment", False)
66 self.properties = properties
68 self.check_properties(properties)
69 self.check_arguments()
71 @launchlogger
72 def launch(self) -> int:
73 """Execute the :class:`Pdbseg <biobb_pdb_tools.pdb_tools.pdb_seg>` object."""
75 if self.check_restart():
76 return 0
77 self.stage_files()
79 instructions = []
80 if self.segment:
81 instructions.append("-" + str(self.segment))
82 fu.log("Appending optional boolean property",
83 self.out_log, self.global_log)
85 self.cmd = [
86 self.binary_path,
87 " ".join(instructions),
88 self.stage_io_dict["in"]["input_file_path"],
89 ">",
90 self.io_dict["out"]["output_file_path"],
91 ]
93 fu.log(" ".join(self.cmd), self.out_log, self.global_log)
95 fu.log(
96 "Creating command line with instructions and required arguments",
97 self.out_log,
98 self.global_log,
99 )
100 self.run_biobb()
101 self.copy_to_host()
103 self.tmp_files.extend([self.stage_io_dict.get("unique_dir", "")])
104 self.remove_tmp_files()
105 self.check_arguments(output_files_created=True, raise_exception=False)
107 return self.return_code
110def biobb_pdb_seg(
111 input_file_path: str,
112 output_file_path: str,
113 properties: Optional[dict] = None,
114 **kwargs,
115) -> int:
116 """Create :class:`Pdbseg <biobb_pdb_tools.pdb_tools.pdb_seg>` class and
117 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_seg.launch>` method."""
119 return Pdbseg(
120 input_file_path=input_file_path,
121 output_file_path=output_file_path,
122 properties=properties,
123 **kwargs,
124 ).launch()
127biobb_pdb_seg.__doc__ = Pdbseg.__doc__
130def main():
131 """Command line execution of this building block. Please check the command line documentation."""
132 parser = argparse.ArgumentParser(
133 description="Modifies the segment identifier column of a PDB file.",
134 formatter_class=lambda prog: argparse.RawTextHelpFormatter(
135 prog, width=99999),
136 )
137 parser.add_argument("--config", required=True, help="Configuration file")
139 required_args = parser.add_argument_group("required arguments")
140 required_args.add_argument(
141 "--input_file_path",
142 required=True,
143 help="Description for the first input file path. Accepted formats: pdb.",
144 )
145 required_args.add_argument(
146 "--output_file_path",
147 required=True,
148 help="Description for the output file path. Accepted formats: pdb.",
149 )
151 args = parser.parse_args()
152 args.config = args.config or "{}"
153 properties = settings.ConfReader(config=args.config).get_prop_dic()
155 biobb_pdb_seg(
156 input_file_path=args.input_file_path,
157 output_file_path=args.output_file_path,
158 properties=properties,
159 )
162if __name__ == "__main__":
163 main()