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

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

13 

14 

15class MemProtMDSimSearch(BiobbObject): 

16 """ 

17 | biobb_io MemProtMDSimSearch 

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

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

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

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

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

25 * **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. 

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

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

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

29 

30 Examples: 

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

32 

33 from biobb_io.api.memprotmd_sim_search import memprotmd_sim_search 

34 prop = { 

35 'collection_name': 'refs', 

36 'keyword': 'porin' 

37 } 

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

39 properties=prop).launch() 

40 

41 Info: 

42 * wrapped_software: 

43 * name: MemProtMD DB 

44 * license: Creative Commons 

45 * ontology: 

46 * name: EDAM 

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

48 

49 """ 

50 

51 def __init__(self, output_simulations, 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_simulations": output_simulations}} 

60 

61 # Properties specific for BB 

62 self.collection_name = properties.get("collection_name", "refs") 

63 self.keyword = properties.get("keyword", None) 

64 self.properties = properties 

65 

66 # Check the properties 

67 self.check_properties(properties) 

68 self.check_arguments() 

69 

70 def check_data_params(self, out_log, err_log): 

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

72 self.output_simulations = check_output_path( 

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

74 "output_simulations", 

75 False, 

76 out_log, 

77 self.__class__.__name__, 

78 ) 

79 

80 @launchlogger 

81 def launch(self) -> int: 

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

83 

84 # check input/output paths and parameters 

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

86 

87 # Setup Biobb 

88 if self.check_restart(): 

89 return 0 

90 

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

92 

93 # get JSON object 

94 json_string = get_memprotmd_sim_search( 

95 self.collection_name, self.keyword, self.out_log, self.global_log 

96 ) 

97 

98 # write JSON file 

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

100 

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

102 

103 return 0 

104 

105 

106def memprotmd_sim_search( 

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

108) -> int: 

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

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

111 

112 return MemProtMDSimSearch( 

113 output_simulations=output_simulations, properties=properties, **kwargs 

114 ).launch() 

115 

116 

117def main(): 

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

119 parser = argparse.ArgumentParser( 

120 description="Wrapper for the MemProtMD DB REST API (http://memprotmd.bioch.ox.ac.uk/) to perform advanced searches.", 

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

122 ) 

123 parser.add_argument( 

124 "-c", 

125 "--config", 

126 required=False, 

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

128 ) 

129 

130 # Specific args of each building block 

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

132 required_args.add_argument( 

133 "-o", 

134 "--output_simulations", 

135 required=True, 

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

137 ) 

138 

139 args = parser.parse_args() 

140 config = args.config if args.config else None 

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

142 

143 # Specific call of each building block 

144 memprotmd_sim_search( 

145 output_simulations=args.output_simulations, properties=properties 

146 ) 

147 

148 

149if __name__ == "__main__": 

150 main()