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
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-10 15:33 +0000
1#!/usr/bin/env python
3"""Module containing the MemProtMDSimList class and the command line interface."""
5import argparse
6from typing import Optional
8from biobb_common.configuration import settings
9from biobb_common.generic.biobb_object import BiobbObject
10from biobb_common.tools.file_utils import launchlogger
12from biobb_io.api.common import check_output_path, get_memprotmd_sim_list, write_json
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).
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.
28 Examples:
29 This is a use example of how to use the building block from Python::
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)
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
44 """
46 def __init__(self, output_simulations, properties=None, **kwargs) -> None:
47 properties = properties or {}
49 # Call parent class constructor
50 super().__init__(properties)
51 self.locals_var_dict = locals().copy()
53 # Input/Output files
54 self.io_dict = {"out": {"output_simulations": output_simulations}}
56 # Properties specific for BB
57 self.properties = properties
59 # Check the properties
60 self.check_properties(properties)
61 self.check_arguments()
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 )
73 @launchlogger
74 def launch(self) -> int:
75 """Execute the :class:`MemProtMDSimList <api.memprotmd_sim_list.MemProtMDSimList>` api.memprotmd_sim_list.MemProtMDSimList object."""
77 # check input/output paths and parameters
78 self.check_data_params(self.out_log, self.err_log)
80 # Setup Biobb
81 if self.check_restart():
82 return 0
84 # get JSON object
85 json_string = get_memprotmd_sim_list(self.out_log, self.global_log)
87 # write JSON file
88 write_json(json_string, self.output_simulations, self.out_log, self.global_log)
90 self.check_arguments(output_files_created=True, raise_exception=False)
92 return 0
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."""
101 return MemProtMDSimList(
102 output_simulations=output_simulations, properties=properties, **kwargs
103 ).launch()
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 )
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 )
128 args = parser.parse_args()
129 config = args.config if args.config else None
130 properties = settings.ConfReader(config=config).get_prop_dic()
132 # Specific call of each building block
133 memprotmd_sim_list(
134 output_simulations=args.output_simulations, properties=properties
135 )
138if __name__ == "__main__":
139 main()