Coverage for biobb_model/model/fix_ssbonds.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 FixSSBonds 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 FixSSBonds(BiobbObject): 

11 """ 

12 | biobb_model FixSSBonds 

13 | Fix SS bonds from residues. 

14 

15 Args: 

16 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/1aki.pdb>`_. Accepted formats: pdb (edam:format_1476). 

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

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

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

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

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

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

23 

24 Examples: 

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

26 

27 from biobb_model.model.fix_ssbonds import fix_ssbonds 

28 prop = { 'restart': False } 

29 fix_ssbonds(input_pdb_path='/path/to/myStructure.pdb', 

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

31 properties=prop) 

32 

33 Info: 

34 * wrapped_software: 

35 * name: In house 

36 * license: Apache-2.0 

37 * ontology: 

38 * name: EDAM 

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

40 """ 

41 

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

43 properties = properties or {} 

44 

45 # Call parent class constructor 

46 super().__init__(properties) 

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

48 

49 # Input/Output files 

50 self.io_dict = { 

51 "in": {"input_pdb_path": input_pdb_path}, 

52 "out": {"output_pdb_path": output_pdb_path} 

53 } 

54 

55 # Properties specific for BB 

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

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

58 

59 # Check the properties 

60 self.check_properties(properties) 

61 self.check_arguments() 

62 

63 @launchlogger 

64 def launch(self) -> int: 

65 """Execute the :class:`FixSSBonds <model.fix_ssbonds.FixSSBonds>` object.""" 

66 

67 # Setup Biobb 

68 if self.check_restart(): 

69 return 0 

70 self.stage_files() 

71 

72 self.cmd = [self.binary_path, 

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

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

75 '--force_save', 

76 '--non_interactive', 

77 'getss', '--mark', '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_ssbonds(input_pdb_path: str, output_pdb_path: str, properties: dict = None, **kwargs) -> int: 

98 """Create :class:`FixSSBonds <model.fix_ssbonds.FixSSBonds>` class and 

99 execute the :meth:`launch() <model.fix_ssbonds.FixSSBonds.launch>` method.""" 

100 return FixSSBonds(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="Fix SS bonds from residues", 

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_ssbonds(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()