Coverage for biobb_pdb_tools/pdb_tools/biobb_pdb_selaltloc.py: 74%
50 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 12:37 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 12:37 +0000
1#!/usr/bin/env python3
3"""Module containing the Pdbselaltloc 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
14class Pdbselaltloc(BiobbObject):
15 """
16 | biobb_pdb_tools Pdbselaltloc
17 | Selects alternative locations from a PDB file.
18 | By default, selects the label with the highest occupancy value for each atom, but the user can define a specific altloc label to select. Selecting by highest occupancy removes all altloc labels for all atoms. If the user provides an option (e.g. -A), only atoms with conformers with an altloc A are processed by the script.
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/9INS.pdb>`_. Accepted formats: pdb (edam:format_1476).
22 output_file_path (str): PDB file with selected alternative locations. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_pdb_tools/master/biobb_pdb_tools/test/reference/pdb_tools/ref_pdb_selaltloc.pdb>`_. Accepted formats: pdb (edam:format_1476).
23 properties (dic):
24 * **altloc** (*string*) - (None) Specific alternative location label to select (e.g. "A").
25 * **binary_path** (*str*) - ("pdb_selaltloc") Path to the pdb_selaltloc 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.
29 Examples:
30 This is a use example of how to use the building block from Python::
32 from biobb_pdb_tools.pdb_tools.biobb_pdb_selaltloc import biobb_pdb_selaltloc
34 # Select the highest occupancy alternative locations
35 biobb_pdb_selaltloc(input_file_path='/path/to/input.pdb',
36 output_file_path='/path/to/output.pdb')
38 # Select a specific alternative location label
39 prop = {
40 'altloc': 'A'
41 }
42 biobb_pdb_selaltloc(input_file_path='/path/to/input.pdb',
43 output_file_path='/path/to/output.pdb',
44 properties=prop)
46 Info:
47 * wrapped_software:
48 * name: pdb_tools
49 * version: >=2.5.0
50 * license: Apache-2.0
51 * ontology:
52 * name: EDAM
53 * schema: http://edamontology.org/EDAM.owl
55 """
57 def __init__(
58 self, input_file_path, output_file_path, properties=None, **kwargs
59 ) -> None:
60 properties = properties or {}
62 super().__init__(properties)
63 self.locals_var_dict = locals().copy()
65 self.io_dict = {
66 "in": {"input_file_path": input_file_path},
67 "out": {"output_file_path": output_file_path},
68 }
70 self.binary_path = properties.get("binary_path", "pdb_selaltloc")
71 self.altloc = properties.get("altloc", None)
72 self.properties = properties
74 self.check_properties(properties)
75 self.check_arguments()
77 @launchlogger
78 def launch(self) -> int:
79 """Execute the :class:`Pdbselaltloc <biobb_pdb_tools.pdb_tools.pdb_selaltloc>` object."""
81 if self.check_restart():
82 return 0
83 self.stage_files()
85 instructions = []
86 if self.altloc:
87 instructions.append("-" + str(self.altloc))
88 fu.log("Selecting alternative location label: " + self.altloc, self.out_log, self.global_log)
90 self.cmd = [
91 self.binary_path,
92 " ".join(instructions),
93 self.stage_io_dict["in"]["input_file_path"],
94 ">",
95 self.io_dict["out"]["output_file_path"],
96 ]
98 fu.log(" ".join(self.cmd), self.out_log, self.global_log)
100 fu.log(
101 "Creating command line with instructions and required arguments",
102 self.out_log,
103 self.global_log,
104 )
106 self.run_biobb()
107 self.copy_to_host()
108 self.tmp_files.extend([self.stage_io_dict.get("unique_dir", "")])
109 self.remove_tmp_files()
110 self.check_arguments(output_files_created=True, raise_exception=False)
112 return self.return_code
115def biobb_pdb_selaltloc(
116 input_file_path: str,
117 output_file_path: str,
118 properties: Optional[dict] = None,
119 **kwargs,
120) -> int:
121 """Create :class:`Pdbselaltloc <biobb_pdb_tools.pdb_tools.pdb_selaltloc>` class and
122 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_selaltloc.launch>` method."""
124 return Pdbselaltloc(
125 input_file_path=input_file_path,
126 output_file_path=output_file_path,
127 properties=properties,
128 **kwargs,
129 ).launch()
131biobb_pdb_selaltloc.__doc__ = Pdbselaltloc.__doc__
134def main():
135 """Command line execution of this building block. Please check the command line documentation."""
136 parser = argparse.ArgumentParser(
137 description="Selects alternative locations from a PDB file.",
138 formatter_class=lambda prog: argparse.RawTextHelpFormatter(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 selected alternative locations. 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_selaltloc(
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()