Coverage for biobb_haddock/haddock/folder_test.py: 0%
41 statements
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-07 08:48 +0000
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-07 08:48 +0000
1#!/usr/bin/env python3
3"""Module containing the haddock class and the command line interface."""
5import os
6import argparse
7from typing import Optional
9from biobb_common.configuration import settings
10from biobb_common.generic.biobb_object import BiobbObject
11# from biobb_common.tools import file_utils as fu
12from biobb_common.tools.file_utils import launchlogger
15class FolderTest(BiobbObject):
16 """
17 | biobb_haddock FolderTest
18 | Wrapper class for the FolderTest module.
19 | The FolderTest module.
21 Args:
22 output_folder (dir): Path of the output folder. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/reference/haddock/ref_caprieval.zip>`_. Accepted formats: format (edam:format_1915).
23 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
24 * **n** (*int*) - (4) Number of files create.
26 Examples:
27 This is a use example of how to use the building block from Python::
29 from biobb_haddock.haddock.folder_test import folder_test
30 folder_test(output_folder='/path/to/myfiles',
31 properties={'n': 4})
33 Info:
34 * wrapped_software:
35 * name: None
36 * version: None
37 * license: Apache-2.0
38 * ontology:
39 * name: EDAM
40 * schema: http://edamontology.org/EDAM.owl
41 """
43 def __init__(
44 self,
45 output_folder: str,
46 properties: Optional[dict] = None,
47 **kwargs,
48 ) -> None:
49 properties = properties or {}
51 # Call parent class constructor
52 super().__init__(properties)
54 # Input/Output files
55 self.io_dict = {
56 "out": {"output_folder": output_folder},
57 }
59 self.n = properties.get('n', 4)
60 # Check the properties
61 self.check_properties(properties)
62 self.check_arguments()
64 @launchlogger
65 def launch(self) -> int:
66 """Execute the :class:`FolderTest <biobb_haddock.haddock.folder_test>` object."""
67 # tmp_files = []
69 # Setup Biobb
70 if self.check_restart():
71 return 0
72 self.stage_files()
74 # Create n files in the output folder
75 sandbox_output_folder = f'{self.stage_io_dict["unique_dir"]}/{self.io_dict["out"]["output_folder"]}'
76 os.makedirs(sandbox_output_folder, exist_ok=True)
77 for i in range(1, self.n + 1):
78 with open(f'{sandbox_output_folder}/file_{i}.txt', 'w') as f:
79 f.write(f"This is file number {i}")
81 # Copy files to host
82 self.copy_to_host()
84 # Remove temporal files
85 # self.tmp_files.extend([])
86 self.remove_tmp_files()
88 return self.return_code
91def folder_test(
92 output_folder: str,
93 properties: Optional[dict] = None,
94 **kwargs,
95) -> int:
96 """Create :class:`FolderTest <biobb_haddock.haddock.folder_test>` class and
97 execute the :meth:`launch() <biobb_haddock.haddock.folder_test.launch>` method."""
99 return FolderTest(
100 output_folder=output_folder,
101 properties=properties,
102 **kwargs,
103 ).launch()
106folder_test.__doc__ = FolderTest.__doc__
109def main():
110 parser = argparse.ArgumentParser(
111 description="Wrapper of the haddock FolderTest module.",
112 formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999),
113 )
114 parser.add_argument(
115 "-c",
116 "--config",
117 required=False,
118 help="This file can be a YAML file, JSON file or JSON string",
119 )
121 # Specific args of each building block
122 required_args = parser.add_argument_group("required arguments")
123 required_args.add_argument("--output_folder", required=True)
125 args = parser.parse_args()
126 config = args.config if args.config else None
127 properties = settings.ConfReader(config=config).get_prop_dic()
129 # Specific call of each building block
130 folder_test(
131 output_folder=args.output_folder,
132 properties=properties,
133 )
136if __name__ == "__main__":
137 main()