Coverage for biobb_model/model/fix_amides.py: 70%

44 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 FixAmides 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.file_utils import launchlogger 

8 

9 

10class FixAmides(BiobbObject): 

11 """ 

12 | biobb_model FixAmides 

13 | Fix amide groups from residues. 

14 | Flip the clashing amide groups to avoid clashes. 

15 

16 Args: 

17 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/5s2z.pdb>`_. Accepted formats: pdb (edam:format_1476). 

18 output_pdb_path (str): Output PDB file path. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_model/master/biobb_model/test/reference/model/output_amide_pdb_path.pdb>`_. Accepted formats: pdb (edam:format_1476). 

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

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

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

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

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

24 

25 Examples: 

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

27 

28 from biobb_model.model.fix_amides import fix_amides 

29 prop = { 'restart': False } 

30 fix_amides(input_pdb_path='/path/to/myStructure.pdb', 

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

32 properties=prop) 

33 

34 Info: 

35 * wrapped_software: 

36 * name: In house 

37 * license: Apache-2.0 

38 * ontology: 

39 * name: EDAM 

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

41 """ 

42 

43 def __init__(self, input_pdb_path: str, output_pdb_path: str, properties: dict = None, **kwargs) -> None: 

44 properties = properties or {} 

45 

46 # Call parent class constructor 

47 super().__init__(properties) 

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

49 

50 # Input/Output files 

51 self.io_dict = { 

52 "in": {"input_pdb_path": input_pdb_path}, 

53 "out": {"output_pdb_path": output_pdb_path} 

54 } 

55 

56 # Properties specific for BB 

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

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

59 

60 # Check the properties 

61 self.check_properties(properties) 

62 self.check_arguments() 

63 

64 @launchlogger 

65 def launch(self) -> int: 

66 """Execute the :class:`FixAmides <model.fix_amides.FixAmides>` object.""" 

67 

68 # Setup Biobb 

69 if self.check_restart(): 

70 return 0 

71 self.stage_files() 

72 

73 self.cmd = [self.binary_path, 

74 '-i', self.stage_io_dict["in"]["input_pdb_path"], 

75 '-o', self.stage_io_dict["out"]["output_pdb_path"], 

76 '--force_save', 

77 'amide', '--fix', 'All'] 

78 

79 if self.modeller_key: 

80 self.cmd.insert(1, self.modeller_key) 

81 self.cmd.insert(1, '--modeller_key') 

82 

83 # Run Biobb block 

84 self.run_biobb() 

85 

86 # Copy files to host 

87 self.copy_to_host() 

88 

89 # Remove temporal files 

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

91 self.remove_tmp_files() 

92 

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

94 return self.return_code 

95 

96 

97def fix_amides(input_pdb_path: str, output_pdb_path: str, properties: dict = None, **kwargs) -> int: 

98 """Create :class:`FixAmides <model.fix_amides.FixAmides>` class and 

99 execute the :meth:`launch() <model.fix_amides.FixAmides.launch>` method.""" 

100 return FixAmides(input_pdb_path=input_pdb_path, 

101 output_pdb_path=output_pdb_path, 

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

103 

104 

105def main(): 

106 parser = argparse.ArgumentParser(description="Flip the clashing amide groups to avoid clashes.", 

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

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

109 

110 # Specific args of each building block 

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

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

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

114 

115 args = parser.parse_args() 

116 config = args.config if args.config else None 

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

118 

119 # Specific call of each building block 

120 fix_amides(input_pdb_path=args.input_pdb_path, 

121 output_pdb_path=args.output_pdb_path, 

122 properties=properties) 

123 

124 

125if __name__ == '__main__': 

126 main()