Coverage for biobb_model/model/fix_backbone.py: 0%

54 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-03-13 17:26 +0000

1#!/usr/bin/env python3 

2 

3"""Module containing the FixBackbone 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 

9 

10 

11class FixBackbone(BiobbObject): 

12 """ 

13 | biobb_model FixBackbone 

14 | Class to model the missing atoms in the backbone of a PDB structure. 

15 | 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/>`_. 

16 

17 Args: 

18 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). 

19 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). 

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_pdb_path.pdb>`_. Accepted formats: pdb (edam:format_1476). 

21 properties (dict - Python dictionary object containing the tool parameters, not input/output files): 

22 * **add_caps** (*bool*) - (False) Add caps to terminal residues. 

23 * **modeller_key** (*str*) - (None) Modeller license key. 

24 * **binary_path** (*str*) - ("check_structure") Path to the check_structure executable binary. 

25 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files. 

26 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist. 

27 

28 Examples: 

29 This is a use example of how to use the building block from Python:: 

30 

31 from biobb_model.model.fix_backbone import fix_backbone 

32 prop = { 'restart': False } 

33 fix_backbone(input_pdb_path='/path/to/myStructure.pdb', 

34 input_fasta_canonical_sequence_path='/path/to/myCanonicalSequence.fasta', 

35 output_pdb_path='/path/to/newStructure.pdb', 

36 properties=prop) 

37 

38 Info: 

39 * wrapped_software: 

40 * name: In house 

41 * license: Apache-2.0 

42 * ontology: 

43 * name: EDAM 

44 * schema: http://edamontology.org/EDAM.owl 

45 """ 

46 

47 def __init__(self, input_pdb_path: str, input_fasta_canonical_sequence_path: str, output_pdb_path: str, 

48 properties: dict = None, **kwargs) -> None: 

49 properties = properties or {} 

50 

51 # Call parent class constructor 

52 super().__init__(properties) 

53 self.locals_var_dict = locals().copy() 

54 

55 # Input/Output files 

56 self.io_dict = { 

57 "in": {"input_pdb_path": input_pdb_path, 

58 "input_fasta_canonical_sequence_path": input_fasta_canonical_sequence_path}, 

59 "out": {"output_pdb_path": output_pdb_path} 

60 } 

61 

62 # Properties specific for BB 

63 self.binary_path = properties.get('binary_path', 'check_structure') 

64 self.add_caps = properties.get('add_caps', False) 

65 self.modeller_key = properties.get('modeller_key') 

66 

67 # Check the properties 

68 self.check_properties(properties) 

69 self.check_arguments() 

70 

71 @launchlogger 

72 def launch(self) -> int: 

73 """Execute the :class:`FixBackbone <model.fix_backbone.FixBackbone>` object.""" 

74 

75 self.io_dict['in']['stdin_file_path'] = fu.create_stdin_file(f'{self.io_dict["in"]["input_fasta_canonical_sequence_path"]}') 

76 

77 # Setup Biobb 

78 if self.check_restart(): 

79 return 0 

80 self.stage_files() 

81 

82 # Create command line 

83 self.cmd = [self.binary_path, 

84 '-i', self.io_dict["in"]["input_pdb_path"], 

85 '-o', self.io_dict["out"]["output_pdb_path"], 

86 '--force_save', 'backbone', 

87 '--fix_atoms', 'All', 

88 '--fix_chain', 'All', 

89 '--add_caps'] 

90 

91 if self.modeller_key: 

92 self.cmd.insert(5, self.modeller_key) 

93 self.cmd.insert(5, '--modeller_key') 

94 

95 if self.add_caps: 

96 self.cmd.append('All') 

97 else: 

98 self.cmd.append('None') 

99 

100 # Add stdin input file 

101 self.cmd.append('<') 

102 self.cmd.append(self.stage_io_dict["in"]["stdin_file_path"]) 

103 

104 # if not modeller_installed(self.out_log, self.global_log): 

105 # fu.log(f"Modeller is not installed, the execution of this block will be interrupted", self.out_log, self.global_log) 

106 # return 1 

107 

108 # Run Biobb block 

109 self.run_biobb() 

110 

111 # Copy files to host 

112 self.copy_to_host() 

113 

114 # Remove temporal files 

115 self.tmp_files.extend([self.io_dict['in'].get("stdin_file_path")]) 

116 self.tmp_files.extend([self.stage_io_dict.get("unique_dir")]) 

117 self.remove_tmp_files() 

118 

119 self.check_arguments(output_files_created=True, raise_exception=False) 

120 return self.return_code 

121 

122 

123def fix_backbone(input_pdb_path: str, input_fasta_canonical_sequence_path: str, output_pdb_path: str, 

124 properties: dict = None, **kwargs) -> int: 

125 """Create :class:`FixBackbone <model.fix_backbone.FixBackbone>` class and 

126 execute the :meth:`launch() <model.fix_backbone.FixBackbone.launch>` method.""" 

127 return FixBackbone(input_pdb_path=input_pdb_path, 

128 input_fasta_canonical_sequence_path=input_fasta_canonical_sequence_path, 

129 output_pdb_path=output_pdb_path, 

130 properties=properties, **kwargs).launch() 

131 

132 

133def main(): 

134 parser = argparse.ArgumentParser(description="Model the missing atoms in the backbone of a PDB structure.", 

135 formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999)) 

136 parser.add_argument('-c', '--config', required=False, help="This file can be a YAML file, JSON file or JSON string") 

137 

138 # Specific args of each building block 

139 required_args = parser.add_argument_group('required arguments') 

140 required_args.add_argument('-i', '--input_pdb_path', required=True, help="Input PDB file name") 

141 required_args.add_argument('-f', '--input_fasta_canonical_sequence_path', required=True, help="Input FASTA file name") 

142 required_args.add_argument('-o', '--output_pdb_path', required=True, help="Output PDB file name") 

143 

144 args = parser.parse_args() 

145 config = args.config if args.config else None 

146 properties = settings.ConfReader(config=config).get_prop_dic() 

147 

148 # Specific call of each building block 

149 fix_backbone(input_pdb_path=args.input_pdb_path, 

150 input_fasta_canonical_sequence_path=args.input_fasta_canonical_sequence_path, 

151 output_pdb_path=args.output_pdb_path, 

152 properties=properties) 

153 

154 

155if __name__ == '__main__': 

156 main()