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

39 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-09-07 10:41 +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 

23 Examples: 

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

25 

26 from biobb_io.api.memprotmd_sim_list import memprotmd_sim_list 

27 prop = { } 

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

29 properties=prop) 

30 

31 Info: 

32 * wrapped_software: 

33 * name: MemProtMD DB 

34 * license: Creative Commons 

35 * ontology: 

36 * name: EDAM 

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

38 

39 """ 

40 

41 def __init__(self, output_simulations, 

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

52 } 

53 

54 # Properties specific for BB 

55 self.properties = properties 

56 

57 # Check the properties 

58 self.check_properties(properties) 

59 self.check_arguments() 

60 

61 def check_data_params(self, out_log, err_log): 

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

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

64 

65 @launchlogger 

66 def launch(self) -> int: 

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

68 

69 # check input/output paths and parameters 

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

71 

72 # Setup Biobb 

73 if self.check_restart(): 

74 return 0 

75 

76 # get JSON object 

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

78 

79 # write JSON file 

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

81 

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

83 

84 return 0 

85 

86 

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

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

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

90 

91 return MemProtMDSimList(output_simulations=output_simulations, 

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

93 

94 

95def main(): 

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

97 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)) 

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

99 

100 # Specific args of each building block 

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

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

103 

104 args = parser.parse_args() 

105 config = args.config if args.config else None 

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

107 

108 # Specific call of each building block 

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

110 

111 

112if __name__ == '__main__': 

113 main()