Coverage for biobb_model/model/mutate.py: 71%
56 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-13 17:26 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-13 17:26 +0000
1#!/usr/bin/env python3
3"""Module containing the Mutate class and the command line interface."""
4import argparse
5from biobb_common.generic.biobb_object import BiobbObject
6from biobb_common.configuration import settings
7from biobb_common.tools import file_utils as fu
8from biobb_common.tools.file_utils import launchlogger
9from biobb_model.model.common import modeller_installed
12class Mutate(BiobbObject):
13 """
14 | biobb_model Mutate
15 | Class to mutate one amino acid by another in a 3d structure.
16 | 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.
18 Args:
19 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).
20 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).
21 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
22 * **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"
23 * **use_modeller** (*bool*) - (False) Use `Modeller suite <https://salilab.org/modeller/>`_ to optimize the side chains.
24 * **modeller_key** (*str*) - (None) Modeller license key.
25 * **binary_path** (*str*) - ("check_structure") Path to the check_structure executable binary.
26 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
27 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
29 Examples:
30 This is a use example of how to use the building block from Python::
32 from biobb_model.model.mutate import mutate
33 prop = { 'mutation_list': 'A:Val2Ala',
34 'use_modeller': True }
35 mutate(input_pdb_path='/path/to/myStructure.pdb',
36 output_pdb_path='/path/to/newStructure.pdb',
37 properties=prop)
39 Info:
40 * wrapped_software:
41 * name: In house
42 * license: Apache-2.0
43 * ontology:
44 * name: EDAM
45 * schema: http://edamontology.org/EDAM.owl
46 """
48 def __init__(self, input_pdb_path: str, output_pdb_path: str, properties: dict = None, **kwargs) -> None:
49 properties = properties or {}
51 # Call parent class constructor
52 super().__init__(properties)
53 self.locals_var_dict = locals().copy()
55 # Input/Output files
56 self.io_dict = {
57 "in": {"input_pdb_path": input_pdb_path},
58 "out": {"output_pdb_path": output_pdb_path}
59 }
61 # Properties specific for BB
62 self.binary_path = properties.get('binary_path', 'check_structure')
63 self.mutation_list = properties.get('mutation_list', '').replace(" ", "")
64 self.use_modeller = properties.get('use_modeller', False)
65 self.modeller_key = properties.get('modeller_key')
67 # Check the properties
68 self.check_properties(properties)
69 self.check_arguments()
71 @launchlogger
72 def launch(self) -> int:
73 """Execute the :class:`Mutate <model.mutate.Mutate>` object."""
75 # Setup Biobb
76 if self.check_restart():
77 return 0
78 self.stage_files()
80 # Create command line
81 self.cmd = [self.binary_path,
82 '-i', self.stage_io_dict["in"]["input_pdb_path"],
83 '-o', self.stage_io_dict["out"]["output_pdb_path"],
84 '--force_save',
85 '--non_interactive',
86 'mutateside']
88 if self.mutation_list:
89 self.cmd.append('--mut')
90 self.cmd.append(self.mutation_list)
92 if self.modeller_key:
93 self.cmd.insert(1, self.modeller_key)
94 self.cmd.insert(1, '--modeller_key')
96 if self.use_modeller:
97 if modeller_installed(self.out_log, self.global_log):
98 self.cmd.append('--rebuild')
99 else:
100 fu.log("Modeller is not installed --rebuild option can not be used proceeding without using it",
101 self.out_log, self.global_log)
103 # Run Biobb block
104 self.run_biobb()
106 # Copy files to host
107 self.copy_to_host()
109 # Remove temporal files
110 self.tmp_files.append(self.stage_io_dict.get("unique_dir"))
111 self.tmp_files.extend([self.stage_io_dict.get("unique_dir")])
112 self.remove_tmp_files()
114 self.check_arguments(output_files_created=True, raise_exception=False)
115 return self.return_code
118def mutate(input_pdb_path: str, output_pdb_path: str, properties: dict = None, **kwargs) -> int:
119 """Create :class:`Mutate <model.mutate.Mutate>` class and
120 execute the :meth:`launch() <model.mutate.Mutate.launch>` method."""
121 return Mutate(input_pdb_path=input_pdb_path,
122 output_pdb_path=output_pdb_path,
123 properties=properties, **kwargs).launch()
126def main():
127 parser = argparse.ArgumentParser(description="Model the missing atoms in aminoacid side chains of a PDB.",
128 formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999))
129 parser.add_argument('-c', '--config', required=False, help="This file can be a YAML file, JSON file or JSON string")
131 # Specific args of each building block
132 required_args = parser.add_argument_group('required arguments')
133 required_args.add_argument('-i', '--input_pdb_path', required=True, help="Input PDB file name")
134 required_args.add_argument('-o', '--output_pdb_path', required=True, help="Output PDB file name")
136 args = parser.parse_args()
137 config = args.config if args.config else None
138 properties = settings.ConfReader(config=config).get_prop_dic()
140 # Specific call of each building block
141 mutate(input_pdb_path=args.input_pdb_path,
142 output_pdb_path=args.output_pdb_path,
143 properties=properties)
146if __name__ == '__main__':
147 main()