Coverage for biobb_io/api/alphafold.py: 94%
34 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-04 08:31 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-04 08:31 +0000
1#!/usr/bin/env python
3"""Module containing the AlphaFold class and the command line interface."""
5from typing import Optional
6from biobb_common.generic.biobb_object import BiobbObject
7from biobb_common.tools.file_utils import launchlogger
9from biobb_io.api.common import (
10 check_mandatory_property,
11 check_output_path,
12 check_uniprot_code,
13 download_af,
14 write_pdb,
15)
18class AlphaFold(BiobbObject):
19 """
20 | biobb_io AlphaFold
21 | This class is a wrapper for downloading a PDB structure from the AlphaFold Protein Structure Database.
22 | Wrapper for the `AlphaFold Protein Structure Database <https://alphafold.ebi.ac.uk/>`_ for downloading a single PDB structure from its corresponding Uniprot code.
24 Args:
25 output_pdb_path (str): Path to the output PDB file. File type: output. `Sample file <https://github.com/bioexcel/biobb_io/raw/master/biobb_io/test/reference/api/output_alphafold.pdb>`_. Accepted formats: pdb (edam:format_1476).
26 properties (dic - Python dictionary object containing the tool parameters, not input/output files):
27 * **uniprot_code** (*str*) - (None) Uniprot code.
28 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
29 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
30 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
32 Examples:
33 This is a use example of how to use the building block from Python::
35 from biobb_io.api.alphafold import alphafold
36 prop = {
37 'uniprot_code': 'P00489'
38 }
39 alphafold(output_pdb_path='/path/to/newStructure.pdb',
40 properties=prop)
42 Info:
43 * wrapped_software:
44 * name: AlphaFold Protein Structure Database
45 * license: Apache-2.0
46 * ontology:
47 * name: EDAM
48 * schema: http://edamontology.org/EDAM.owl
50 """
52 def __init__(self, output_pdb_path, properties=None, **kwargs) -> None:
53 properties = properties or {}
55 # Call parent class constructor
56 super().__init__(properties)
57 self.locals_var_dict = locals().copy()
59 # Input/Output files
60 self.io_dict = {"out": {"output_pdb_path": output_pdb_path}}
62 # Properties specific for BB
63 self.uniprot_code = properties.get("uniprot_code", None)
64 self.properties = properties
66 # Check the properties
67 self.check_properties(properties)
68 self.check_arguments()
70 def check_data_params(self, out_log, err_log):
71 """Checks all the input/output paths and parameters"""
72 self.output_pdb_path = check_output_path(
73 self.io_dict["out"]["output_pdb_path"],
74 "output_pdb_path",
75 False,
76 out_log,
77 self.__class__.__name__,
78 )
80 @launchlogger
81 def launch(self) -> int:
82 """Execute the :class:`AlphaFold <api.alphafold.AlphaFold>` api.alphafold.AlphaFold object."""
84 # check input/output paths and parameters
85 self.check_data_params(self.out_log, self.err_log)
87 # Setup Biobb
88 if self.check_restart():
89 return 0
91 check_mandatory_property(
92 self.uniprot_code, "uniprot_code", self.out_log, self.__class__.__name__
93 )
95 self.uniprot_code = self.uniprot_code.strip().upper()
97 check_uniprot_code(self.uniprot_code, self.out_log, self.__class__.__name__)
99 # Downloading PDB file
100 pdb_string = download_af(
101 self.uniprot_code, self.out_log, self.global_log, self.__class__.__name__
102 )
103 write_pdb(pdb_string, self.output_pdb_path, None, self.out_log, self.global_log)
105 self.check_arguments(output_files_created=True, raise_exception=False)
107 return 0
110def alphafold(output_pdb_path: str, properties: Optional[dict] = None, **kwargs) -> int:
111 """Execute the :class:`AlphaFold <api.alphafold.AlphaFold>` class and
112 execute the :meth:`launch() <api.alphafold.AlphaFold.launch>` method."""
113 return AlphaFold(**dict(locals())).launch()
116alphafold.__doc__ = AlphaFold.__doc__
117main = AlphaFold.get_main(alphafold, "This class is a wrapper for downloading a PDB structure from the Protein Data Bank.")
119if __name__ == "__main__":
120 main()