Coverage for biobb_model/model/fix_backbone.py: 24%
54 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-28 11:32 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-28 11:32 +0000
1#!/usr/bin/env python3
3"""Module containing the FixBackbone class and the command line interface."""
5import argparse
6from typing import Optional
8from biobb_common.configuration import settings
9from biobb_common.generic.biobb_object import BiobbObject
10from biobb_common.tools import file_utils as fu
11from biobb_common.tools.file_utils import launchlogger
14class FixBackbone(BiobbObject):
15 """
16 | biobb_model FixBackbone
17 | Class to model the missing atoms in the backbone of a PDB structure.
18 | Model the missing atoms in the backbone of a PDB structure using `biobb_structure_checking <https://anaconda.org/bioconda/biobb_structure_checking>`_ and the `Modeller suite <https://salilab.org/modeller/>`_.
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 input_fasta_canonical_sequence_path (str): Input FASTA file path. File type: input. `Sample file <https://github.com/bioexcel/biobb_model/raw/master/biobb_model/test/data/model/2ki5.fasta>`_. Accepted formats: fasta (edam:format_1476).
23 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_pdb_path.pdb>`_. Accepted formats: pdb (edam:format_1476).
24 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
25 * **add_caps** (*bool*) - (False) Add caps to terminal residues.
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.fix_backbone import fix_backbone
36 prop = { 'restart': False }
37 fix_backbone(input_pdb_path='/path/to/myStructure.pdb',
38 input_fasta_canonical_sequence_path='/path/to/myCanonicalSequence.fasta',
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 input_fasta_canonical_sequence_path: str,
55 output_pdb_path: str,
56 properties: Optional[dict] = None,
57 **kwargs,
58 ) -> None:
59 properties = properties or {}
61 # Call parent class constructor
62 super().__init__(properties)
63 self.locals_var_dict = locals().copy()
65 # Input/Output files
66 self.io_dict = {
67 "in": {
68 "input_pdb_path": input_pdb_path,
69 "input_fasta_canonical_sequence_path": input_fasta_canonical_sequence_path,
70 },
71 "out": {"output_pdb_path": output_pdb_path},
72 }
74 # Properties specific for BB
75 self.binary_path = properties.get("binary_path", "check_structure")
76 self.add_caps = properties.get("add_caps", False)
77 self.modeller_key = properties.get("modeller_key")
79 # Check the properties
80 self.check_properties(properties)
81 self.check_arguments()
83 @launchlogger
84 def launch(self) -> int:
85 """Execute the :class:`FixBackbone <model.fix_backbone.FixBackbone>` object."""
87 self.io_dict["in"]["stdin_file_path"] = fu.create_stdin_file(
88 f'{self.io_dict["in"]["input_fasta_canonical_sequence_path"]}'
89 )
91 # Setup Biobb
92 if self.check_restart():
93 return 0
94 self.stage_files()
96 # Create command line
97 self.cmd = [
98 self.binary_path,
99 "-i",
100 self.io_dict["in"]["input_pdb_path"],
101 "-o",
102 self.io_dict["out"]["output_pdb_path"],
103 "--force_save",
104 "backbone",
105 "--fix_atoms",
106 "All",
107 "--fix_chain",
108 "All",
109 "--add_caps",
110 ]
112 if self.modeller_key:
113 self.cmd.insert(5, self.modeller_key)
114 self.cmd.insert(5, "--modeller_key")
116 if self.add_caps:
117 self.cmd.append("All")
118 else:
119 self.cmd.append("None")
121 # Add stdin input file
122 self.cmd.append("<")
123 self.cmd.append(self.stage_io_dict["in"]["stdin_file_path"])
125 # if not modeller_installed(self.out_log, self.global_log):
126 # fu.log(f"Modeller is not installed, the execution of this block will be interrupted", self.out_log, self.global_log)
127 # return 1
129 # Run Biobb block
130 self.run_biobb()
132 # Copy files to host
133 self.copy_to_host()
135 # Remove temporal files
136 self.tmp_files.extend([self.io_dict["in"].get("stdin_file_path", "")])
137 # self.tmp_files.extend([self.stage_io_dict.get("unique_dir", "")])
138 self.remove_tmp_files()
140 self.check_arguments(output_files_created=True, raise_exception=False)
141 return self.return_code
144def fix_backbone(
145 input_pdb_path: str,
146 input_fasta_canonical_sequence_path: str,
147 output_pdb_path: str,
148 properties: Optional[dict] = None,
149 **kwargs,
150) -> int:
151 """Create :class:`FixBackbone <model.fix_backbone.FixBackbone>` class and
152 execute the :meth:`launch() <model.fix_backbone.FixBackbone.launch>` method."""
153 return FixBackbone(
154 input_pdb_path=input_pdb_path,
155 input_fasta_canonical_sequence_path=input_fasta_canonical_sequence_path,
156 output_pdb_path=output_pdb_path,
157 properties=properties,
158 **kwargs,
159 ).launch()
161 fix_backbone.__doc__ = FixBackbone.__doc__
164def main():
165 parser = argparse.ArgumentParser(
166 description="Model the missing atoms in the backbone of a PDB structure.",
167 formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999),
168 )
169 parser.add_argument(
170 "-c",
171 "--config",
172 required=False,
173 help="This file can be a YAML file, JSON file or JSON string",
174 )
176 # Specific args of each building block
177 required_args = parser.add_argument_group("required arguments")
178 required_args.add_argument(
179 "-i", "--input_pdb_path", required=True, help="Input PDB file name"
180 )
181 required_args.add_argument(
182 "-f",
183 "--input_fasta_canonical_sequence_path",
184 required=True,
185 help="Input FASTA file name",
186 )
187 required_args.add_argument(
188 "-o", "--output_pdb_path", required=True, help="Output PDB file name"
189 )
191 args = parser.parse_args()
192 config = args.config if args.config else None
193 properties = settings.ConfReader(config=config).get_prop_dic()
195 # Specific call of each building block
196 fix_backbone(
197 input_pdb_path=args.input_pdb_path,
198 input_fasta_canonical_sequence_path=args.input_fasta_canonical_sequence_path,
199 output_pdb_path=args.output_pdb_path,
200 properties=properties,
201 )
204if __name__ == "__main__":
205 main()