Coverage for biobb_model / model / mutate.py: 84%
44 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-22 13:18 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-22 13:18 +0000
1#!/usr/bin/env python3
3"""Module containing the Mutate class and the command line interface."""
5from typing import Optional
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
11from biobb_model.model.common import modeller_installed
14class Mutate(BiobbObject):
15 """
16 | biobb_model Mutate
17 | Class to mutate one amino acid by another in a 3d structure.
18 | Mutate side chain with minimal atom replacement. if the use_modeller property is added the `Modeller suite <https://salilab.org/modeller/>`_ will be used to optimize the side chains.
20 Args:
21 input_pdb_path (str): Input PDB file path. File type: input. `Sample file <https://github.com/bioexcel/biobb_model/raw/master/biobb_model/test/data/model/2ki5.pdb>`_. Accepted formats: pdb (edam:format_1476).
22 output_pdb_path (str): Output PDB file path. File type: output. `Sample file <https://github.com/bioexcel/biobb_model/raw/master/biobb_model/test/reference/model/output_mutated_pdb_path.pdb>`_. Accepted formats: pdb (edam:format_1476).
23 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
24 * **mutation_list** (*str*) - (None) Mutation list in the format "Chain:WT_AA_ThreeLeterCode Resnum MUT_AA_ThreeLeterCode" (no spaces between the elements) separated by commas. If no chain is provided as chain code all the chains in the pdb file will be mutated. ie: "A:ALA15CYS"
25 * **use_modeller** (*bool*) - (False) Use `Modeller suite <https://salilab.org/modeller/>`_ to optimize the side chains.
26 * **modeller_key** (*str*) - (None) Modeller license key.
27 * **binary_path** (*str*) - ("check_structure") Path to the check_structure executable binary.
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_model.model.mutate import mutate
36 prop = { 'mutation_list': 'A:Val2Ala',
37 'use_modeller': True }
38 mutate(input_pdb_path='/path/to/myStructure.pdb',
39 output_pdb_path='/path/to/newStructure.pdb',
40 properties=prop)
42 Info:
43 * wrapped_software:
44 * name: In house
45 * license: Apache-2.0
46 * ontology:
47 * name: EDAM
48 * schema: http://edamontology.org/EDAM.owl
49 """
51 def __init__(
52 self,
53 input_pdb_path: str,
54 output_pdb_path: str,
55 properties: Optional[dict] = None,
56 **kwargs,
57 ) -> 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_pdb_path": input_pdb_path},
67 "out": {"output_pdb_path": output_pdb_path},
68 }
70 # Properties specific for BB
71 self.binary_path = properties.get("binary_path", "check_structure")
72 self.mutation_list = properties.get("mutation_list", "").replace(" ", "")
73 self.use_modeller = properties.get("use_modeller", False)
74 self.modeller_key = properties.get("modeller_key")
76 # Check the properties
77 self.check_properties(properties)
78 self.check_arguments()
80 @launchlogger
81 def launch(self) -> int:
82 """Execute the :class:`Mutate <model.mutate.Mutate>` object."""
84 # Setup Biobb
85 if self.check_restart():
86 return 0
87 self.stage_files()
89 # Create command line
90 self.cmd = [
91 self.binary_path,
92 "-i",
93 self.stage_io_dict["in"]["input_pdb_path"],
94 "-o",
95 self.stage_io_dict["out"]["output_pdb_path"],
96 "--force_save",
97 "--non_interactive",
98 "mutateside",
99 ]
101 if self.mutation_list:
102 self.cmd.append("--mut")
103 self.cmd.append(self.mutation_list)
105 if self.modeller_key:
106 self.cmd.insert(1, self.modeller_key)
107 self.cmd.insert(1, "--modeller_key")
109 if self.use_modeller:
110 if modeller_installed(self.out_log, self.global_log):
111 self.cmd.append("--rebuild")
112 else:
113 fu.log(
114 "Modeller is not installed --rebuild option can not be used proceeding without using it",
115 self.out_log,
116 self.global_log,
117 )
119 # Run Biobb block
120 self.run_biobb()
122 # Copy files to host
123 self.copy_to_host()
125 # Remove temporal files
126 self.remove_tmp_files()
128 self.check_arguments(output_files_created=True, raise_exception=False)
129 return self.return_code
132def mutate(
133 input_pdb_path: str,
134 output_pdb_path: str,
135 properties: Optional[dict] = None,
136 **kwargs,
137) -> int:
138 """Create :class:`Mutate <model.mutate.Mutate>` class and
139 execute the :meth:`launch() <model.mutate.Mutate.launch>` method."""
140 return Mutate(**dict(locals())).launch()
143mutate.__doc__ = Mutate.__doc__
144main = Mutate.get_main(mutate, "Model the missing atoms in aminoacid side chains of a PDB.")
146if __name__ == "__main__":
147 main()