Coverage for biobb_io/api/memprotmd_sim_search.py: 74%

42 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 MemProtMDSimSearch 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_search, write_json 

9 

10 

11class MemProtMDSimSearch(BiobbObject): 

12 """ 

13 | biobb_io MemProtMDSimSearch 

14 | This class is a wrapper of the MemProtMD to perform advanced searches in the MemProtMD DB using its REST API. 

15 | Wrapper for the `MemProtMD DB REST API <http://memprotmd.bioch.ox.ac.uk/>`_ to perform advanced searches. 

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_search.json>`_. Accepted formats: json (edam:format_3464). 

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

20 * **collection_name** (*str*) - ("refs") Name of the collection to query. 

21 * **keyword** (*str*) - (None) String to search for in the database metadata. Examples are families like gpcr or porin. Values: porin, outer membrane protein, membrane protein, gpcr (7-transmembrane domain receptors transducing extracellular signals into cells), ion channels, rhodopsin (The most famous GPCRs), abc, mip (Major Intrinsic Protein (MIP)/FNT superfamily: specific for the transport of water and small neutral solutes), ligand-gated (Ligand-dependent signal conversion from chemical signals to electric signals), ammonia (Regulating transepithelial ammonia secretion), mapeg (Eicosanoid and Glutathione metabolism proteins), transmembrane (Heme biosynthesis), protein, kinase (Tyrosine-protein kinases: regulate central nervous system; gene transcription and cell differentiation), glycoprotein (Expression of TCR complex), immunoglobulin (Recognition; binding and adhesion process of cells), integrin (Bridges for cell-cell and cell-extracellular matrix interaction), bnip3 (BNip3 protein family: protect cell from apoptosis), bcl-2 (Regulating cell-death; either induce apoptotic or inhibit apoptosis), atpase (ATPase regulators; P-P-bond hydrolysis-driven transporter), cytochrome (Terminal oxidase enzyme in electron transfer chain), nadp (Transmembrane proteins with NAD(P)-binding Rossmann-fold domains: monoamine oxidase; deaminates norepinephrine; epinephrine; serotonin and dopamine), a4 (Amyloid beta A4 protein; involved in alzheimer's diseases), lysosome (Lysosome-associated membrane glycoprotein: specific to lysosomes; CD107), necrosis (Tumor necrosis factor recepto: binding with TNF and NGF; interacting with a variety of signal molecules; highly associated with apoptosis), oxidoreductase (DHODH; biosynthesis of orotate), ceramidase (Neutral/alkaline ceramidase: converting sphingolipid to sphingosine), dehydrogenase (Aldehyde dehydrogenase:ALDH; Oxidation of aldehydes), mitochondrial, plastid. 

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

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

24 

25 Examples: 

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

27 

28 from biobb_io.api.memprotmd_sim_search import memprotmd_sim_search 

29 prop = { 

30 'collection_name': 'refs', 

31 'keyword': 'porin' 

32 } 

33 memprotmd_sim_search(output_simulations='/path/to/newSimulationSearch.json', 

34 properties=prop).launch() 

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, 

47 properties=None, **kwargs) -> None: 

48 properties = properties or {} 

49 

50 # Call parent class constructor 

51 super().__init__(properties) 

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

53 

54 # Input/Output files 

55 self.io_dict = { 

56 "out": {"output_simulations": output_simulations} 

57 } 

58 

59 # Properties specific for BB 

60 self.collection_name = properties.get('collection_name', 'refs') 

61 self.keyword = properties.get('keyword', None) 

62 self.properties = properties 

63 

64 # Check the properties 

65 self.check_properties(properties) 

66 self.check_arguments() 

67 

68 def check_data_params(self, out_log, err_log): 

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

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

71 

72 @launchlogger 

73 def launch(self) -> int: 

74 """Execute the :class:`MemProtMDSimSearch <api.memprotmd_sim_search.MemProtMDSimSearch>` api.memprotmd_sim_search.MemProtMDSimSearch object.""" 

75 

76 # check input/output paths and parameters 

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

78 

79 # Setup Biobb 

80 if self.check_restart(): 

81 return 0 

82 

83 self.keyword = self.keyword.strip().lower() 

84 

85 # get JSON object 

86 json_string = get_memprotmd_sim_search(self.collection_name, self.keyword, self.out_log, self.global_log) 

87 

88 # write JSON file 

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

90 

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

92 

93 return 0 

94 

95 

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

97 """Execute the :class:`MemProtMDSimSearch <api.memprotmd_sim_search.MemProtMDSimSearch>` class and 

98 execute the :meth:`launch() <api.memprotmd_sim_search.MemProtMDSimSearch.launch>` method.""" 

99 

100 return MemProtMDSimSearch(output_simulations=output_simulations, 

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

102 

103 

104def main(): 

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

106 parser = argparse.ArgumentParser(description="Wrapper for the MemProtMD DB REST API (http://memprotmd.bioch.ox.ac.uk/) to perform advanced searches.", formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999)) 

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

108 

109 # Specific args of each building block 

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

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

112 

113 args = parser.parse_args() 

114 config = args.config if args.config else None 

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

116 

117 # Specific call of each building block 

118 memprotmd_sim_search(output_simulations=args.output_simulations, 

119 properties=properties) 

120 

121 

122if __name__ == '__main__': 

123 main()