Coverage for biobb_pdb_tools/pdb_tools/biobb_pdb_selres.py: 95%
37 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-04 08:26 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-04 08:26 +0000
1#!/usr/bin/env python3
3"""Module containing the Pdbselres class and the command line interface."""
5from typing import Optional
6from biobb_common.generic.biobb_object import BiobbObject
7from biobb_common.tools import file_utils as fu
8from biobb_common.tools.file_utils import launchlogger
11class Pdbselres(BiobbObject):
12 """
13 | biobb_pdb_tools Pdbselres
14 | Selects residues by their index, piecewise or in a range.
15 | Works by selecting residues based on their index. Can select individual residues, a range of residues, or residues at regular intervals.
17 Args:
18 input_file_path (str): Input PDB file. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_pdb_tools/master/biobb_pdb_tools/test/data/pdb_tools/1IGY.pdb>`_. Accepted formats: pdb (edam:format_1476).
19 output_file_path (str): PDB file with selected residues. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_pdb_tools/master/biobb_pdb_tools/test/reference/pdb_tools/ref_pdb_selres.pdb>`_. Accepted formats: pdb (edam:format_1476).
20 properties (dic):
21 * **selection** (*string*) - (None) Residue selection format: individual residues "1,2,4,6", range "1:10", multiple ranges "1:10,20:30", open ranges "1:", ":5", or intervals "::5", "1:10:5".
22 * **binary_path** (*str*) - ("pdb_selres") Path to the pdb_selres executable binary.
23 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
24 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
26 Examples:
27 This is a use example of how to use the building block from Python::
29 from biobb_pdb_tools.pdb_tools.biobb_pdb_selres import biobb_pdb_selres
31 prop = {
32 'selection': '1:20:2'
33 }
34 biobb_pdb_selres(input_file_path='/path/to/input.pdb',
35 output_file_path='/path/to/output.pdb',
36 properties=prop)
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
47 """
49 def __init__(
50 self, input_file_path, output_file_path, properties=None, **kwargs
51 ) -> None:
52 properties = properties or {}
54 super().__init__(properties)
55 self.locals_var_dict = locals().copy()
57 self.io_dict = {
58 "in": {"input_file_path": input_file_path},
59 "out": {"output_file_path": output_file_path},
60 }
62 self.binary_path = properties.get("binary_path", "pdb_selres")
63 self.selection = properties.get("selection", None)
64 self.properties = properties
65 self.check_init(properties)
67 @launchlogger
68 def launch(self) -> int:
69 """Execute the :class:`Pdbselres <biobb_pdb_tools.pdb_tools.pdb_selres>` object."""
71 if self.check_restart():
72 return 0
73 self.stage_files()
75 instructions = []
76 if self.selection:
77 instructions.append("-" + str(self.selection))
78 fu.log("Selecting residues with pattern: " + self.selection, self.out_log, self.global_log)
80 self.cmd = [
81 self.binary_path,
82 " ".join(instructions),
83 self.stage_io_dict["in"]["input_file_path"],
84 ">",
85 self.io_dict["out"]["output_file_path"],
86 ]
88 fu.log(" ".join(self.cmd), self.out_log, self.global_log)
90 fu.log(
91 "Creating command line with instructions and required arguments",
92 self.out_log,
93 self.global_log,
94 )
96 self.run_biobb()
97 self.copy_to_host()
98 self.remove_tmp_files()
99 self.check_arguments(output_files_created=True, raise_exception=False)
101 return self.return_code
104def biobb_pdb_selres(
105 input_file_path: str,
106 output_file_path: str,
107 properties: Optional[dict] = None,
108 **kwargs,
109) -> int:
110 """Create :class:`Pdbselres <biobb_pdb_tools.pdb_tools.pdb_selres>` class and
111 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_selres.launch>` method."""
113 return Pdbselres(**dict(locals())).launch()
116biobb_pdb_selres.__doc__ = Pdbselres.__doc__
117main = Pdbselres.get_main(biobb_pdb_selres, "Selects residues by their index, piecewise or in a range.")
119if __name__ == "__main__":
120 main()