Coverage for biobb_vs / fpocket / fpocket_run.py: 93%
58 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-22 13:24 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-22 13:24 +0000
1#!/usr/bin/env python3
3"""Module containing the FPocketRun class and the command line interface."""
4from typing import Optional
5import shutil
6from pathlib import PurePath
7from biobb_common.generic.biobb_object import BiobbObject
8from biobb_common.tools import file_utils as fu
9from biobb_common.tools.file_utils import launchlogger
10from biobb_vs.fpocket.common import check_input_path, check_output_path, process_output_fpocket
13class FPocketRun(BiobbObject):
14 """
15 | biobb_vs FPocketRun
16 | Wrapper of the fpocket software.
17 | Finds the binding site of the input_pdb_path file via the `fpocket <https://github.com/Discngine/fpocket>`_ software.
19 Args:
20 input_pdb_path (str): Path to the PDB structure where the binding site is to be found. File type: input. `Sample file <https://github.com/bioexcel/biobb_vs/raw/master/biobb_vs/test/data/fpocket/fpocket_input.pdb>`_. Accepted formats: pdb (edam:format_1476).
21 output_pockets_zip (str): Path to all the pockets found by fpocket in the input_pdb_path structure. File type: output. `Sample file <https://github.com/bioexcel/biobb_vs/raw/master/biobb_vs/test/reference/fpocket/ref_output_pockets.zip>`_. Accepted formats: zip (edam:format_3987).
22 output_summary (str): Path to the JSON summary file. File type: output. `Sample file <https://github.com/bioexcel/biobb_vs/raw/master/biobb_vs/test/reference/fpocket/ref_output_summary.json>`_. Accepted formats: json (edam:format_3464).
23 properties (dic - Python dictionary object containing the tool parameters, not input/output files):
24 * **min_radius** (*float*) - (None) [0.1~1000|0.1] The minimum radius in Ångstroms an alpha sphere might have in a binding pocket.
25 * **max_radius** (*float*) - (None) [2~1000|0.1] The maximum radius in Ångstroms of alpha spheres in a pocket.
26 * **num_spheres** (*int*) - (None) [1~1000|1] Indicates how many alpha spheres a pocket must contain at least in order to figure in the results.
27 * **sort_by** (*str*) - ('druggability_score') From which property the output will be sorted. Values: druggability_score (this score intends to assess the likeliness of the pocket to bind a small drug like molecule), score (fpocket score as defined in the `fpocket paper <https://doi.org/10.1186/1471-2105-10-168>`_), volume (volume of the pocket).
28 * **binary_path** (*string*) - ('fpocket') path to fpocket in your local computer.
29 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
30 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
31 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
32 * **container_path** (*str*) - (None) Container path definition.
33 * **container_image** (*str*) - ('fpocket/fpocket:latest') Container image definition.
34 * **container_volume_path** (*str*) - ('/tmp') Container volume path definition.
35 * **container_working_dir** (*str*) - (None) Container working directory definition.
36 * **container_user_id** (*str*) - (None) Container user_id definition.
37 * **container_shell_path** (*str*) - ('/bin/bash') Path to default shell inside the container.
39 Examples:
40 This is a use example of how to use the building block from Python::
42 from biobb_vs.fpocket.fpocket_run import fpocket_run
43 prop = {
44 'min_radius': 3,
45 'max_radius': 6,
46 'num_spheres': 35,
47 'sort_by': 'druggability_score'
48 }
49 fpocket_run(input_pdb_path='/path/to/myStructure.pdb',
50 output_pockets_zip='/path/to/newPockets.zip',
51 output_summary='/path/to/newSummary.json',
52 properties=prop)
54 Info:
55 * wrapped_software:
56 * name: fpocket
57 * version: ==4.1
58 * license: MIT
59 * ontology:
60 * name: EDAM
61 * schema: http://edamontology.org/EDAM.owl
63 """
65 def __init__(self, input_pdb_path, output_pockets_zip, output_summary,
66 properties=None, **kwargs) -> None:
67 properties = properties or {}
69 # Call parent class constructor
70 super().__init__(properties)
71 self.locals_var_dict = locals().copy()
73 # Input/Output files
74 self.io_dict = {
75 "in": {"input_pdb_path": input_pdb_path},
76 "out": {"output_pockets_zip": output_pockets_zip, "output_summary": output_summary}
77 }
79 # Properties specific for BB
80 self.binary_path = properties.get('binary_path', 'fpocket')
81 self.min_radius = properties.get('min_radius', None)
82 self.max_radius = properties.get('max_radius', None)
83 self.num_spheres = properties.get('num_spheres', None)
84 self.sort_by = properties.get('sort_by', 'druggability_score')
85 self.properties = properties
87 # Check the properties
88 self.check_properties(properties)
89 self.check_arguments()
91 def check_data_params(self, out_log, err_log):
92 """ Checks all the input/output paths and parameters """
93 self.io_dict["in"]["input_pdb_path"] = check_input_path(self.io_dict["in"]["input_pdb_path"], "input_pdb_path", out_log, self.__class__.__name__)
94 self.io_dict["out"]["output_pockets_zip"] = check_output_path(self.io_dict["out"]["output_pockets_zip"], "output_pockets_zip", False, out_log, self.__class__.__name__)
95 self.io_dict["out"]["output_summary"] = check_output_path(self.io_dict["out"]["output_summary"], "output_summary", True, out_log, self.__class__.__name__)
97 @launchlogger
98 def launch(self) -> int:
99 """Execute the :class:`FPocketRun <fpocket.fpocket_run.FPocketRun>` fpocket.fpocket_run.FPocketRun object."""
101 # check input/output paths and parameters
102 self.check_data_params(self.out_log, self.err_log)
104 # Setup Biobb
105 if self.check_restart():
106 return 0
107 self.stage_files()
109 if self.container_path:
110 tmp_input = str(PurePath(self.container_volume_path).joinpath(PurePath(self.io_dict["in"]["input_pdb_path"]).name))
111 tmp_folder = self.stage_io_dict['unique_dir']
112 else:
113 # create tmp_folder
114 tmp_folder = fu.create_unique_dir()
115 fu.log('Creating %s temporary folder' % tmp_folder, self.out_log)
116 tmp_input = str(PurePath(tmp_folder).joinpath('input.pdb'))
117 # copy input_pdb_path to tmp_folder
118 shutil.copy(self.io_dict["in"]["input_pdb_path"], tmp_input)
120 # create cmd
121 self.cmd = [self.binary_path,
122 '-f', tmp_input]
124 # adding extra properties
125 if self.min_radius:
126 self.cmd.extend(['-m', str(self.min_radius)])
128 if self.max_radius:
129 self.cmd.extend(['-M', str(self.max_radius)])
131 if self.num_spheres:
132 self.cmd.extend(['-i', str(self.num_spheres)])
134 fu.log('Executing fpocket', self.out_log, self.global_log)
136 # Run Biobb block
137 self.run_biobb()
139 # Copy files to host
140 self.copy_to_host()
142 process_output_fpocket(tmp_folder,
143 self.io_dict["out"]["output_pockets_zip"],
144 self.io_dict["out"]["output_summary"],
145 self.sort_by,
146 self.remove_tmp,
147 self.container_path,
148 self.out_log,
149 self.__class__.__name__)
151 self.tmp_files.append(tmp_folder)
152 self.remove_tmp_files()
154 return self.return_code
157def fpocket_run(input_pdb_path: str, output_pockets_zip: str, output_summary: str, properties: Optional[dict] = None, **kwargs) -> int:
158 """Create the :class:`FPocketRun <fpocket.fpocket_run.FPocketRun>` class and
159 execute the :meth:`launch() <fpocket.fpocket_run.FPocketRun.launch>` method."""
160 return FPocketRun(**dict(locals())).launch()
163fpocket_run.__doc__ = FPocketRun.__doc__
164main = FPocketRun.get_main(fpocket_run, "Finds the binding site of the input_pdb_path file via the fpocket software")
167if __name__ == '__main__':
168 main()