Coverage for biobb_io/api/memprotmd_sim_list.py: 36%

39 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-10 15:33 +0000

1#!/usr/bin/env python 

2 

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

4 

5import argparse 

6from typing import Optional 

7 

8from biobb_common.configuration import settings 

9from biobb_common.generic.biobb_object import BiobbObject 

10from biobb_common.tools.file_utils import launchlogger 

11 

12from biobb_io.api.common import check_output_path, get_memprotmd_sim_list, write_json 

13 

14 

15class MemProtMDSimList(BiobbObject): 

16 """ 

17 | biobb_io MemProtMDSimList 

18 | This class is a wrapper of the MemProtMD to get all available membrane-protein systems from its REST API. 

19 | Wrapper for the `MemProtMD DB REST API <http://memprotmd.bioch.ox.ac.uk/>`_ to get all available membrane-protein systems (simulations). 

20 

21 Args: 

22 output_simulations (str): Path to the output JSON file. File type: output. `Sample file <https://github.com/bioexcel/biobb_io/raw/master/biobb_io/test/reference/api/output_sim_list.json>`_. Accepted formats: json (edam:format_3464). 

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

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

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

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

27 

28 Examples: 

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

30 

31 from biobb_io.api.memprotmd_sim_list import memprotmd_sim_list 

32 prop = { } 

33 memprotmd_sim_list(output_simulations='/path/to/newSimulationlist.json', 

34 properties=prop) 

35 

36 Info: 

37 * wrapped_software: 

38 * name: MemProtMD DB 

39 * license: Creative Commons 

40 * ontology: 

41 * name: EDAM 

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

43 

44 """ 

45 

46 def __init__(self, output_simulations, properties=None, **kwargs) -> None: 

47 properties = properties or {} 

48 

49 # Call parent class constructor 

50 super().__init__(properties) 

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

52 

53 # Input/Output files 

54 self.io_dict = {"out": {"output_simulations": output_simulations}} 

55 

56 # Properties specific for BB 

57 self.properties = properties 

58 

59 # Check the properties 

60 self.check_properties(properties) 

61 self.check_arguments() 

62 

63 def check_data_params(self, out_log, err_log): 

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

65 self.output_simulations = check_output_path( 

66 self.io_dict["out"]["output_simulations"], 

67 "output_simulations", 

68 False, 

69 out_log, 

70 self.__class__.__name__, 

71 ) 

72 

73 @launchlogger 

74 def launch(self) -> int: 

75 """Execute the :class:`MemProtMDSimList <api.memprotmd_sim_list.MemProtMDSimList>` api.memprotmd_sim_list.MemProtMDSimList object.""" 

76 

77 # check input/output paths and parameters 

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

79 

80 # Setup Biobb 

81 if self.check_restart(): 

82 return 0 

83 

84 # get JSON object 

85 json_string = get_memprotmd_sim_list(self.out_log, self.global_log) 

86 

87 # write JSON file 

88 write_json(json_string, self.output_simulations, self.out_log, self.global_log) 

89 

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

91 

92 return 0 

93 

94 

95def memprotmd_sim_list( 

96 output_simulations: str, properties: Optional[dict] = None, **kwargs 

97) -> int: 

98 """Execute the :class:`MemProtMDSimList <api.memprotmd_sim_list.MemProtMDSimList>` class and 

99 execute the :meth:`launch() <api.memprotmd_sim_list.MemProtMDSimList.launch>` method.""" 

100 

101 return MemProtMDSimList( 

102 output_simulations=output_simulations, properties=properties, **kwargs 

103 ).launch() 

104 

105 

106def main(): 

107 """Command line execution of this building block. Please check the command line documentation.""" 

108 parser = argparse.ArgumentParser( 

109 description="Wrapper for the MemProtMD DB REST API (http://memprotmd.bioch.ox.ac.uk/) to get all available membrane-protein systems (simulations).", 

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

111 ) 

112 parser.add_argument( 

113 "-c", 

114 "--config", 

115 required=False, 

116 help="This file can be a YAML file, JSON file or JSON string", 

117 ) 

118 

119 # Specific args of each building block 

120 required_args = parser.add_argument_group("required arguments") 

121 required_args.add_argument( 

122 "-o", 

123 "--output_simulations", 

124 required=True, 

125 help="Path to the output JSON file. Accepted formats: json.", 

126 ) 

127 

128 args = parser.parse_args() 

129 config = args.config if args.config else None 

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

131 

132 # Specific call of each building block 

133 memprotmd_sim_list( 

134 output_simulations=args.output_simulations, properties=properties 

135 ) 

136 

137 

138if __name__ == "__main__": 

139 main()