Coverage for biobb_flexserv/pcasuite/pcz_unzip.py: 88%
40 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 PCZunzip 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 PCZunzip(BiobbObject):
11 """
12 | biobb_flexserv PCZunzip
13 | Wrapper of the pcaunzip tool from the PCAsuite FlexServ module.
14 | Uncompress Molecular Dynamics (MD) trajectories compressed using Principal Component Analysis (PCA) algorithms.
16 Args:
17 input_pcz_path (str): Input compressed trajectory. 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_crd_path (str): Output uncompressed trajectory. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexserv/raw/master/biobb_flexserv/test/reference/pcasuite/traj.crd>`_. Accepted formats: crd (edam:format_3878), mdcrd (edam:format_3878), inpcrd (edam:format_3878), pdb (edam:format_1476).
19 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
20 * **binary_path** (*str*) - ("pcaunzip") pcaunzip binary path to be used.
21 * **verbose** (*bool*) - (False) Make output verbose
22 * **pdb** (*bool*) - (False) Use PDB format for output trajectory
23 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
24 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
25 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
26 * **container_path** (*str*) - (None) Container path definition.
27 * **container_image** (*str*) - ('afandiadib/ambertools:serial') Container image definition.
28 * **container_volume_path** (*str*) - ('/tmp') Container volume path definition.
29 * **container_working_dir** (*str*) - (None) Container working directory definition.
30 * **container_user_id** (*str*) - (None) Container user_id definition.
31 * **container_shell_path** (*str*) - ('/bin/bash') Path to default shell inside the container.
33 Examples:
34 This is a use example of how to use the building block from Python::
36 from biobb_flexserv.pcasuite.pcz_unzip import pcz_unzip
37 prop = {
38 'pdb': False
39 }
40 pcz_unzip( input_pcz_path='/path/to/pcazip_input.pcz',
41 output_crd_path='/path/to/pcazip_traj.crd',
42 properties=prop)
44 Info:
45 * wrapped_software:
46 * name: FlexServ PCAsuite
47 * version: >=1.0
48 * license: Apache-2.0
49 * ontology:
50 * name: EDAM
51 * schema: http://edamontology.org/EDAM.owl
53 """
55 def __init__(self, input_pcz_path: str,
56 output_crd_path: str, properties: Optional[dict] = None, **kwargs) -> None:
58 properties = properties or {}
60 # Call parent class constructor
61 super().__init__(properties)
62 self.locals_var_dict = locals().copy()
64 # Input/Output files
65 self.io_dict = {
66 'in': {'input_pcz_path': input_pcz_path},
67 'out': {'output_crd_path': output_crd_path}
68 }
70 # Properties specific for BB
71 self.properties = properties
72 self.binary_path = properties.get('binary_path', 'pcaunzip')
73 self.verbose = properties.get('verbose', False)
74 self.pdb = properties.get('pdb', False)
76 # Check the properties
77 self.check_properties(properties)
78 self.check_arguments()
80 @launchlogger
81 def launch(self):
82 """Launches the execution of the FlexServ pcaunzip module."""
84 # Setup Biobb
85 if self.check_restart():
86 return 0
87 self.stage_files()
89 if self.container_path:
90 working_dir = self.container_volume_path if self.container_volume_path else "/data"
91 else:
92 working_dir = self.stage_io_dict.get("unique_dir", "")
94 # Command line
95 # pcaunzip -i infile [-o outfile] [--pdb] [--verbose] [--help]
96 # self.cmd = [self.binary_path,
97 # "-i", input_pcz,
98 # "-o", output_crd
99 # ]
101 self.cmd = ['cd', working_dir, ';',
102 self.binary_path,
103 "-i", PurePath(self.stage_io_dict["in"]["input_pcz_path"]).name,
104 "-o", PurePath(self.stage_io_dict["out"]["output_crd_path"]).name
105 ]
107 if self.verbose:
108 self.cmd.append('-v')
110 if self.pdb:
111 self.cmd.append('--pdb')
113 # Run Biobb block
114 self.run_biobb()
116 # Copy files to host
117 self.copy_to_host()
119 # Remove temporary folder(s)
120 self.remove_tmp_files()
122 self.check_arguments(output_files_created=True, raise_exception=False)
124 return self.return_code
127def pcz_unzip(input_pcz_path: str,
128 output_crd_path: str,
129 properties: Optional[dict] = None, **kwargs) -> int:
130 """Create :class:`PCZunzip <flexserv.pcasuite.PCZunzip>`flexserv.pcasuite.PCZunzip class and
131 execute :meth:`launch() <flexserv.pcasuite.PCZunzip.launch>` method"""
132 return PCZunzip(**dict(locals())).launch()
135pcz_unzip.__doc__ = PCZunzip.__doc__
136main = PCZunzip.get_main(pcz_unzip, "Uncompress Molecular Dynamics (MD) compressed trajectories using Principal Component Analysis (PCA) algorithms.")
138if __name__ == '__main__':
139 main()