1 #!/usr/bin/env python3
2
3 """Module containing the Chainxseg 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 class Chainxseg(BiobbObject):
15 """
16 | biobb_pdb_tools Pdbtidy
17 | Swaps the segment identifier for the chain identifier.
18 | This tool swaps the segment identifier for the chain identifier in 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.
19
20 Args:
21 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/1AKI.pdb>`_. Accepted formats: pdb (edam:format_1476).
22 output_file_path (str): PDB file with exchanged segment and string identifier. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_pdb_tools/master/biobb_pdb_tools/test/reference/pdb_tools/ref_pdb_chainxseg.pdb>`_. Accepted formats: pdb (edam:format_1476).
23 properties (dic):
24 * **binary_path** (*str*) - ("pdb_chainxseg") Path to the pdb_chainxseg executable binary.
25 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
26 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
27
28 Examples:
29 This is a use example of how to use the building block from Python::
30
31 from biobb_pdb_tools.pdb_tools.biobb_pdb_chainxseg import biobb_pdb_chainxseg
32
33 biobb_pdb_chainxseg(input_file_path='/path/to/input.pdb',
34 output_file_path='/path/to/output.pdb')
35
36 Info:
37 * wrapped_software:
38 * name: pdb_tools
39 * version: >=2.5.0
40 * license: Apache-2.0
41 * ontology:
42 * name: EDAM
43 * schema: http://edamontology.org/EDAM.owl
44
45 """
46
47 def __init__(
48 self, input_file_path, output_file_path, properties=None, **kwargs
49 ) -> None:
50 properties = properties or {}
51
52 super().__init__(properties)
53 self.locals_var_dict = locals().copy()
54
55 self.io_dict = {
56 "in": {"input_file_path": input_file_path},
57 "out": {"output_file_path": output_file_path},
58 }
59
60 self.binary_path = properties.get("binary_path", "pdb_chainxseg")
61 self.properties = properties
62
63 self.check_properties(properties)
64 self.check_arguments()
65
66 @launchlogger
67 def launch(self) -> int:
68 """Execute the :class:`Chainxseg <biobb_pdb_tools.pdb_tools.pdb_chainxseg>` object."""
69
70 if self.check_restart():
71 return 0
72 self.stage_files()
73
74 self.cmd = [
75 self.binary_path,
76 self.stage_io_dict["in"]["input_file_path"],
77 ">",
78 self.io_dict["out"]["output_file_path"],
79 ]
80
81 fu.log(" ".join(self.cmd), self.out_log, self.global_log)
82
83 fu.log(
84 "Creating command line with instructions and required arguments",
85 self.out_log,
86 self.global_log,
87 )
88
89 self.run_biobb()
90
91 self.copy_to_host()
92
93 self.tmp_files.extend([self.stage_io_dict.get("unique_dir", "")])
94 self.remove_tmp_files()
95
96 self.check_arguments(output_files_created=True, raise_exception=False)
97
98 return self.return_code
99
100
101 def biobb_pdb_chainxseg(
102 input_file_path: str,
103 output_file_path: str,
104 properties: Optional[dict] = None,
105 **kwargs,
106 ) -> int:
107 """Create :class:`biobb_pdb_tools.pdb_tools.pdb_chainxseg>` class and
108 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_chainxseg.launch>` method."""
109 return Chainxseg(
110 input_file_path=input_file_path,
111 output_file_path=output_file_path,
112 properties=properties,
113 **kwargs,
114 ).launch()
115
-
E305
Expected 2 blank lines after class or function definition, found 1
116 biobb_pdb_chainxseg.__doc__ = Chainxseg.__doc__
117
118
119 def main():
120 """Command line execution of this building block. Please check the command line documentation."""
121 parser = argparse.ArgumentParser(
122 description="Swaps the segment identifier for the chain identifier.",
123 formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999),
124 )
125 parser.add_argument("--config", required=True, help="Configuration file")
126
127 required_args = parser.add_argument_group("required arguments")
128 required_args.add_argument(
129 "--input_file_path",
130 required=True,
131 help="Description for the first input file path. Accepted formats: pdb.",
132 )
133 required_args.add_argument(
134 "--output_file_path",
135 required=True,
136 help="Description for the output file path. Accepted formats: pdb.",
137 )
138
139 args = parser.parse_args()
140 args.config = args.config or "{}"
141 properties = settings.ConfReader(config=args.config).get_prop_dic()
142
143 biobb_pdb_chainxseg(
144 input_file_path=args.input_file_path,
145 output_file_path=args.output_file_path,
146 properties=properties,
147 )
148
149
150 if __name__ == "__main__":
151 main()