⬅ biobb_pdb_tools/pdb_tools/biobb_pdb_keepcoord.py source

1 #!/usr/bin/env python3
2  
3 """Module containing the Pdbkeepcoord 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 Pdbkeepcoord(BiobbObject):
16 """
17 | biobb_pdb_tools Pdbkeepcoord
18 | Removes all non-coordinate records from the file.
19 | Keeps only MODEL, ENDMDL, END, ATOM, HETATM, CONECT records 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/1AKI.pdb>`_. Accepted formats: pdb (edam:format_1476).
23 output_file_path (str): PDB file with only coordinate records. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_pdb_tools/master/biobb_pdb_tools/test/reference/pdb_tools/ref_pdb_keepcoord.pdb>`_. Accepted formats: pdb (edam:format_1476).
24 properties (dic):
25 * **binary_path** (*str*) - ("pdb_keepcoord") Path to the pdb_keepcoord executable binary.
26 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
27 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
28  
29 Examples:
30 This is a use example of how to use the building block from Python::
31  
32 from biobb_pdb_tools.pdb_tools.biobb_pdb_keepcoord import biobb_pdb_keepcoord
33  
34 # Keep only coordinate records
35 biobb_pdb_keepcoord(input_file_path='/path/to/input.pdb',
36 output_file_path='/path/to/output.pdb')
37  
38 Info:
39 * wrapped_software:
40 * name: pdb_tools
41 * version: >=2.5.0
42 * license: Apache-2.0
43 * ontology:
44 * name: EDAM
45 * schema: http://edamontology.org/EDAM.owl
46  
47 """
48  
49 def __init__(
50 self, input_file_path, output_file_path, properties=None, **kwargs
51 ) -> None:
52 properties = properties or {}
53  
54 super().__init__(properties)
55 self.locals_var_dict = locals().copy()
56  
57 self.io_dict = {
58 "in": {"input_file_path": input_file_path},
59 "out": {"output_file_path": output_file_path},
60 }
61  
62 self.binary_path = properties.get("binary_path", "pdb_keepcoord")
63 self.properties = properties
64  
65 self.check_properties(properties)
66 self.check_arguments()
67  
68 @launchlogger
69 def launch(self) -> int:
70 """Execute the :class:`Pdbkeepcoord <biobb_pdb_tools.pdb_tools.pdb_keepcoord>` object."""
71  
72 if self.check_restart():
73 return 0
74 self.stage_files()
75  
76 self.cmd = [
77 self.binary_path,
78 self.stage_io_dict["in"]["input_file_path"],
79 ">",
80 self.io_dict["out"]["output_file_path"],
81 ]
82  
83 fu.log(" ".join(self.cmd), self.out_log, self.global_log)
84  
85 fu.log(
86 "Creating command line with instructions and required arguments",
87 self.out_log,
88 self.global_log,
89 )
90  
91 self.run_biobb()
92 self.copy_to_host()
93 self.tmp_files.extend([self.stage_io_dict.get("unique_dir", "")])
94 self.remove_tmp_files()
95 self.check_arguments(output_files_created=True, raise_exception=False)
96  
97 return self.return_code
98  
99  
100 def biobb_pdb_keepcoord(
101 input_file_path: str,
102 output_file_path: str,
103 properties: Optional[dict] = None,
104 **kwargs,
105 ) -> int:
106 """Create :class:`Pdbkeepcoord <biobb_pdb_tools.pdb_tools.pdb_keepcoord>` class and
107 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_keepcoord.launch>` method."""
108  
109 return Pdbkeepcoord(
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_keepcoord.__doc__ = Pdbkeepcoord.__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="Removes all non-coordinate records from the file. Keeps only MODEL, ENDMDL, END, ATOM, HETATM, CONECT records.",
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="PDB file. Accepted formats: pdb.",
132 )
133 required_args.add_argument(
134 "--output_file_path",
135 required=True,
136 help="PDB file with only coordinate records. 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_keepcoord(
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()