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

38 statements  

« prev     ^ index     » next       coverage.py v7.5.3, created at 2024-06-14 18:20 +0000

1#!/usr/bin/env python 

2 

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

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

9 

10 

11class MemProtMDSimList(BiobbObject): 

12 """ 

13 | biobb_io MemProtMDSimList 

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

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

16 

17 Args: 

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

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

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

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

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

23 

24 Examples: 

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

26 

27 from biobb_io.api.memprotmd_sim_list import memprotmd_sim_list 

28 prop = { } 

29 memprotmd_sim_list(output_simulations='/path/to/newSimulationList.json', 

30 properties=prop) 

31 

32 Info: 

33 * wrapped_software: 

34 * name: MemProtMD DB 

35 * license: Creative Commons 

36 * ontology: 

37 * name: EDAM 

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

39 

40 """ 

41 

42 def __init__(self, output_simulations, 

43 properties=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 "out": {"output_simulations": output_simulations} 

53 } 

54 

55 # Properties specific for BB 

56 self.properties = properties 

57 

58 # Check the properties 

59 self.check_properties(properties) 

60 self.check_arguments() 

61 

62 def check_data_params(self, out_log, err_log): 

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

64 self.output_simulations = check_output_path(self.io_dict["out"]["output_simulations"], "output_simulations", False, out_log, self.__class__.__name__) 

65 

66 @launchlogger 

67 def launch(self) -> int: 

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

69 

70 # check input/output paths and parameters 

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

72 

73 # Setup Biobb 

74 if self.check_restart(): 

75 return 0 

76 

77 # get JSON object 

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

79 

80 # write JSON file 

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

82 

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

84 

85 return 0 

86 

87 

88def memprotmd_sim_list(output_simulations: str, properties: dict = None, **kwargs) -> int: 

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

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

91 

92 return MemProtMDSimList(output_simulations=output_simulations, 

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

94 

95 

96def main(): 

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

98 parser = argparse.ArgumentParser(description="Wrapper for the MemProtMD DB REST API (http://memprotmd.bioch.ox.ac.uk/) to get all available membrane-protein systems (simulations).", formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999)) 

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

100 

101 # Specific args of each building block 

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

103 required_args.add_argument('-o', '--output_simulations', required=True, help="Path to the output JSON file. Accepted formats: json.") 

104 

105 args = parser.parse_args() 

106 config = args.config if args.config else None 

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

108 

109 # Specific call of each building block 

110 memprotmd_sim_list(output_simulations=args.output_simulations, properties=properties) 

111 

112 

113if __name__ == '__main__': 

114 main()