Coverage for biobb_flexserv/pcasuite/pcz_bfactor.py: 92%
39 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-05-28 11:28 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-05-28 11:28 +0000
1#!/usr/bin/env python3
3"""Module containing the PCZbfactor class and the command line interface."""
4from typing import Optional
5from pathlib import PurePath
6from biobb_common.generic.biobb_object import BiobbObject
7from biobb_common.tools.file_utils import launchlogger
10class PCZbfactor(BiobbObject):
11 """
12 | biobb_flexserv PCZbfactor
13 | Extract residue bfactors x PCA mode from a compressed PCZ file.
14 | Wrapper of the pczdump tool from the PCAsuite FlexServ module.
16 Args:
17 input_pcz_path (str): Input compressed trajectory file. File type: input. `Sample file <https://github.com/bioexcel/biobb_flexserv/raw/master/biobb_flexserv/test/data/pcasuite/pcazip.pcz>`_. Accepted formats: pcz (edam:format_3874).
18 output_dat_path (str): Output Bfactor x residue x PCA mode file. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexserv/raw/master/biobb_flexserv/test/reference/pcasuite/bfactors.dat>`_. Accepted formats: dat (edam:format_1637), txt (edam:format_2330), csv (edam:format_3752).
19 output_pdb_path (str) (Optional): Output PDB with Bfactor x residue x PCA mode file. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexserv/raw/master/biobb_flexserv/test/reference/pcasuite/bfactors.pdb>`_. Accepted formats: pdb (edam:format_1476).
20 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
21 * **binary_path** (*str*) - ("pczdump") pczdump binary path to be used.
22 * **eigenvector** (*int*) - (0) PCA mode (eigenvector) from which to extract bfactor values per residue (0 means average over all modes).
23 * **pdb** (*bool*) - (False) Generate a PDB file with the computed bfactors (to be easily represented with colour scale)
24 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
25 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
26 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
27 * **container_path** (*str*) - (None) Container path definition.
28 * **container_image** (*str*) - ('afandiadib/ambertools:serial') Container image definition.
29 * **container_volume_path** (*str*) - ('/tmp') Container volume path definition.
30 * **container_working_dir** (*str*) - (None) Container working directory definition.
31 * **container_user_id** (*str*) - (None) Container user_id definition.
32 * **container_shell_path** (*str*) - ('/bin/bash') Path to default shell inside the container.
34 Examples:
35 This is a use example of how to use the building block from Python::
37 from biobb_flexserv.pcasuite.pcz_bfactor import pcz_bfactor
38 prop = {
39 'eigenvector': 1,
40 'pdb': True
41 }
42 pcz_bfactor( input_pcz_path='/path/to/pcazip_input.pcz',
43 output_dat_path='/path/to/bfactors_mode1.dat',
44 output_pdb_path='/path/to/bfactors_mode1.pdb',
45 properties=prop)
47 Info:
48 * wrapped_software:
49 * name: FlexServ PCAsuite
50 * version: >=1.0
51 * license: Apache-2.0
52 * ontology:
53 * name: EDAM
54 * schema: http://edamontology.org/EDAM.owl
56 """
58 def __init__(self, input_pcz_path: str, output_dat_path: str,
59 output_pdb_path: str, properties: Optional[dict] = None, **kwargs) -> None:
61 properties = properties or {}
63 # Call parent class constructor
64 super().__init__(properties)
65 self.locals_var_dict = locals().copy()
67 # Input/Output files
68 self.io_dict = {
69 'in': {'input_pcz_path': input_pcz_path},
70 'out': {'output_dat_path': output_dat_path,
71 'output_pdb_path': output_pdb_path}
72 }
74 # Properties specific for BB
75 self.properties = properties
76 self.binary_path = properties.get('binary_path', 'pczdump')
77 self.eigenvector = properties.get('eigenvector', 1)
78 self.pdb = properties.get('pdb', False)
80 # Check the properties
81 self.check_properties(properties)
82 self.check_arguments()
84 @launchlogger
85 def launch(self):
86 """Launches the execution of the FlexServ pcz_bfactor module."""
88 # Setup Biobb
89 if self.check_restart():
90 return 0
91 self.stage_files()
93 if self.container_path:
94 working_dir = self.container_volume_path if self.container_volume_path else "/data"
95 else:
96 working_dir = self.stage_io_dict.get("unique_dir", "")
98 # Command line (1: dat file)
99 # pczdump -i structure.ca.std.pcz --fluc=1 -o bfactor_1.dat
100 # self.cmd = [self.binary_path,
101 # "-i", input_pcz,
102 # "-o", output_dat,
103 # "--bfactor",
104 # "--fluc={}".format(self.eigenvector)
105 # ]
107 self.cmd = ['cd', working_dir, ';',
108 self.binary_path,
109 '-i', PurePath(self.stage_io_dict["in"]["input_pcz_path"]).name,
110 '-o', PurePath(self.stage_io_dict["out"]["output_dat_path"]).name,
111 "--bfactor",
112 "--fluc={}".format(self.eigenvector)
113 ]
115 # Run Biobb block
116 self.run_biobb()
118 if self.pdb:
119 # Command line (2: pdb file)
120 # pczdump -i structure.ca.std.pcz --fluc=1 --pdb -o bfactor_1.pdb
121 # self.cmd = [self.binary_path,
122 # "-i", input_pcz,
123 # "-o", output_pdb,
124 # "--bfactor",
125 # "--fluc={}".format(self.eigenvector),
126 # "--pdb"
127 # ]
129 self.cmd = ['cd', working_dir, ';',
130 self.binary_path,
131 '-i', PurePath(self.stage_io_dict["in"]["input_pcz_path"]).name,
132 '-o', PurePath(self.stage_io_dict["out"]["output_pdb_path"]).name,
133 "--bfactor",
134 "--fluc={}".format(self.eigenvector),
135 "--pdb"
136 ]
138 # Run Biobb block
139 self.run_biobb()
141 # Copy files to host
142 self.copy_to_host()
144 # Remove temporary folder(s)
145 self.remove_tmp_files()
147 self.check_arguments(output_files_created=True, raise_exception=False)
149 return self.return_code
152def pcz_bfactor(input_pcz_path: str, output_dat_path: str, output_pdb_path: str,
153 properties: Optional[dict] = None, **kwargs) -> int:
154 """Create :class:`PCZbfactor <flexserv.pcasuite.pcz_bfactor>`flexserv.pcasuite.PCZbfactor class and
155 execute :meth:`launch() <flexserv.pcasuite.pcz_bfactor.launch>` method"""
156 return PCZbfactor(**dict(locals())).launch()
159pcz_bfactor.__doc__ = PCZbfactor.__doc__
160main = PCZbfactor.get_main(pcz_bfactor, "Extract residue bfactors x PCA mode from a compressed PCZ file.")
162if __name__ == '__main__':
163 main()