Coverage for biobb_pdb_tools/pdb_tools/biobb_pdb_chainxseg.py: 94%
32 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 Chainxseg 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 Chainxseg(BiobbObject):
12 """
13 | biobb_pdb_tools Pdbtidy
14 | Swaps the segment identifier for the chain identifier.
15 | 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.
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/1AKI.pdb>`_. Accepted formats: pdb (edam:format_1476).
19 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).
20 properties (dic):
21 * **binary_path** (*str*) - ("pdb_chainxseg") Path to the pdb_chainxseg executable binary.
22 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
23 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
25 Examples:
26 This is a use example of how to use the building block from Python::
28 from biobb_pdb_tools.pdb_tools.biobb_pdb_chainxseg import biobb_pdb_chainxseg
30 biobb_pdb_chainxseg(input_file_path='/path/to/input.pdb',
31 output_file_path='/path/to/output.pdb')
33 Info:
34 * wrapped_software:
35 * name: pdb_tools
36 * version: >=2.5.0
37 * license: Apache-2.0
38 * ontology:
39 * name: EDAM
40 * schema: http://edamontology.org/EDAM.owl
42 """
44 def __init__(
45 self, input_file_path, output_file_path, properties=None, **kwargs
46 ) -> None:
47 properties = properties or {}
49 super().__init__(properties)
50 self.locals_var_dict = locals().copy()
52 self.io_dict = {
53 "in": {"input_file_path": input_file_path},
54 "out": {"output_file_path": output_file_path},
55 }
57 self.binary_path = properties.get("binary_path", "pdb_chainxseg")
58 self.properties = properties
59 self.check_init(properties)
61 @launchlogger
62 def launch(self) -> int:
63 """Execute the :class:`Chainxseg <biobb_pdb_tools.pdb_tools.pdb_chainxseg>` object."""
65 if self.check_restart():
66 return 0
67 self.stage_files()
69 self.cmd = [
70 self.binary_path,
71 self.stage_io_dict["in"]["input_file_path"],
72 ">",
73 self.io_dict["out"]["output_file_path"],
74 ]
76 fu.log(" ".join(self.cmd), self.out_log, self.global_log)
78 fu.log(
79 "Creating command line with instructions and required arguments",
80 self.out_log,
81 self.global_log,
82 )
84 self.run_biobb()
86 self.copy_to_host()
88 self.remove_tmp_files()
90 self.check_arguments(output_files_created=True, raise_exception=False)
92 return self.return_code
95def biobb_pdb_chainxseg(
96 input_file_path: str,
97 output_file_path: str,
98 properties: Optional[dict] = None,
99 **kwargs,
100) -> int:
101 """Create :class:`biobb_pdb_tools.pdb_tools.pdb_chainxseg>` class and
102 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_chainxseg.launch>` method."""
103 return Chainxseg(**dict(locals())).launch()
106main = Chainxseg.get_main(biobb_pdb_chainxseg, "Swaps the segment identifier for the chain identifier.")
107biobb_pdb_chainxseg.__doc__ = Chainxseg.__doc__
109if __name__ == "__main__":
110 main()