Coverage for biobb_io/api/structure_info.py: 38%

34 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-04 08:31 +0000

1#!/usr/bin/env python 

2 

3"""Module containing the StructureInfo class and the command line interface.""" 

4 

5from typing import Optional 

6from biobb_common.generic.biobb_object import BiobbObject 

7from biobb_common.tools.file_utils import launchlogger 

8 

9from biobb_io.api.common import ( 

10 check_mandatory_property, 

11 check_output_path, 

12 download_str_info, 

13 write_json, 

14) 

15 

16 

17class StructureInfo(BiobbObject): 

18 """ 

19 | biobb_io StructureInfo 

20 | This class is a wrapper for getting all the available information of a structure from the Protein Data Bank. 

21 | Wrapper for the `MMB PDB mirror <http://mmb.irbbarcelona.org/api/>`_ for getting all the available information of a structure from the Protein Data Bank. 

22 

23 Args: 

24 output_json_path (str): Path to the output JSON file with all the structure information. File type: output. `Sample file <https://github.com/bioexcel/biobb_io/raw/master/biobb_io/test/reference/api/ref_str_info.json>`_. Accepted formats: json (edam:format_3464). 

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

26 * **pdb_code** (*str*) - (None) RSCB PDB structure code. 

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

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

29 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory. 

30 

31 Examples: 

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

33 

34 from biobb_io.api.structure_info import structure_info 

35 prop = { 

36 'pdb_code': '2vgb' 

37 } 

38 structure_info(output_json_path='/path/to/newStructure.sdf', 

39 properties=prop) 

40 

41 Info: 

42 * wrapped_software: 

43 * name: Protein Data Bank 

44 * license: Apache-2.0 

45 * ontology: 

46 * name: EDAM 

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

48 

49 """ 

50 

51 def __init__(self, output_json_path, properties=None, **kwargs) -> None: 

52 properties = properties or {} 

53 

54 # Call parent class constructor 

55 super().__init__(properties) 

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

57 

58 # Input/Output files 

59 self.io_dict = {"out": {"output_json_path": output_json_path}} 

60 

61 # Properties specific for BB 

62 self.pdb_code = properties.get("pdb_code", None) 

63 self.properties = properties 

64 

65 # Check the properties 

66 self.check_properties(properties) 

67 self.check_arguments() 

68 

69 def check_data_params(self, out_log, err_log): 

70 """Checks all the input/output paths and parameters""" 

71 self.output_json_path = check_output_path( 

72 self.io_dict["out"]["output_json_path"], 

73 "output_json_path", 

74 False, 

75 out_log, 

76 self.__class__.__name__, 

77 ) 

78 

79 @launchlogger 

80 def launch(self) -> int: 

81 """Execute the :class:`StructureInfo <api.structure_info.StructureInfo>` api.structure_info.StructureInfo object.""" 

82 

83 # check input/output paths and parameters 

84 self.check_data_params(self.out_log, self.err_log) 

85 

86 # Setup Biobb 

87 if self.check_restart(): 

88 return 0 

89 

90 check_mandatory_property( 

91 self.pdb_code, "pdb_code", self.out_log, self.__class__.__name__ 

92 ) 

93 

94 self.pdb_code = self.pdb_code.strip().lower() 

95 url = "http://mmb.irbbarcelona.org/api/pdb/%s.json" 

96 

97 # Downloading PDB file 

98 json_string = download_str_info( 

99 self.pdb_code, url, self.out_log, self.global_log 

100 ) 

101 write_json(json_string, self.output_json_path, self.out_log, self.global_log) 

102 

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

104 

105 return 0 

106 

107 

108def structure_info( 

109 output_json_path: str, properties: Optional[dict] = None, **kwargs 

110) -> int: 

111 """Execute the :class:`StructureInfo <api.structure_info.StructureInfo>` class and 

112 execute the :meth:`launch() <api.structure_info.StructureInfo.launch>` method.""" 

113 return StructureInfo(**dict(locals())).launch() 

114 

115 

116structure_info.__doc__ = StructureInfo.__doc__ 

117main = StructureInfo.get_main(structure_info, "This class is a wrapper for getting all the available information of a structure from the Protein Data Bank.") 

118 

119if __name__ == "__main__": 

120 main()