1 #!/usr/bin/env python3
2
3 """Module containing the Pdbseg class and the command line interface."""
4
5 import argparse
6 from typing import Optional
7
8 from biobb_common.configuration import settings
9 from biobb_common.generic.biobb_object import BiobbObject
10 from biobb_common.tools import file_utils as fu
11 from biobb_common.tools.file_utils import launchlogger
12
13
14 # 1. Rename class as required
15 class 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.
20
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.
29
30 Examples:
31 This is a use example of how to use the building block from Python::
32
33 from biobb_pdb_tools.pdb_tools.biobb_pdb_seg import biobb_pdb_seg
34
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)
41
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
50
51 """
52
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 }
63
64 self.binary_path = properties.get("binary_path", "pdb_seg")
65 self.segment = properties.get("segment", False)
66 self.properties = properties
67
68 self.check_properties(properties)
69 self.check_arguments()
70
71 @launchlogger
72 def launch(self) -> int:
73 """Execute the :class:`Pdbseg <biobb_pdb_tools.pdb_tools.pdb_seg>` object."""
74
75 if self.check_restart():
76 return 0
77 self.stage_files()
78
79 instructions = []
80 if self.segment:
81 instructions.append("-" + str(self.segment))
82 fu.log("Appending optional boolean property", self.out_log, self.global_log)
83
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 ]
91
92 fu.log(" ".join(self.cmd), self.out_log, self.global_log)
93
94 fu.log(
95 "Creating command line with instructions and required arguments",
96 self.out_log,
97 self.global_log,
98 )
99 self.run_biobb()
100 self.copy_to_host()
101
102 self.tmp_files.extend([self.stage_io_dict.get("unique_dir", "")])
103 self.remove_tmp_files()
104 self.check_arguments(output_files_created=True, raise_exception=False)
105
106 return self.return_code
107
108
109 def biobb_pdb_seg(
110 input_file_path: str,
111 output_file_path: str,
112 properties: Optional[dict] = None,
113 **kwargs,
114 ) -> int:
115 """Create :class:`Pdbseg <biobb_pdb_tools.pdb_tools.pdb_seg>` class and
116 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_seg.launch>` method."""
117
118 return Pdbseg(
119 input_file_path=input_file_path,
120 output_file_path=output_file_path,
121 properties=properties,
122 **kwargs,
123 ).launch()
124
-
E305
Expected 2 blank lines after class or function definition, found 1
125 biobb_pdb_seg.__doc__ = Pdbseg.__doc__
126
127
128 def main():
129 """Command line execution of this building block. Please check the command line documentation."""
130 parser = argparse.ArgumentParser(
131 description="Modifies the segment identifier column of a PDB file.",
132 formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999),
133 )
134 parser.add_argument("--config", required=True, help="Configuration file")
135
136 required_args = parser.add_argument_group("required arguments")
137 required_args.add_argument(
138 "--input_file_path",
139 required=True,
140 help="Description for the first input file path. Accepted formats: pdb.",
141 )
142 required_args.add_argument(
143 "--output_file_path",
144 required=True,
145 help="Description for the output file path. Accepted formats: pdb.",
146 )
147
148 args = parser.parse_args()
149 args.config = args.config or "{}"
150 properties = settings.ConfReader(config=args.config).get_prop_dic()
151
152 biobb_pdb_seg(
153 input_file_path=args.input_file_path,
154 output_file_path=args.output_file_path,
155 properties=properties,
156 )
157
158
159 if __name__ == "__main__":
160 main()