Coverage for biobb_model/model/common.py: 36%
22 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-28 11:32 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-28 11:32 +0000
1"""Common functions for package biobb_model.model"""
3import logging
4from typing import Optional, Union
6from biobb_common.tools import file_utils as fu
9def modeller_installed(
10 out_log: Optional[logging.Logger] = None,
11 global_log: Optional[logging.Logger] = None,
12) -> bool:
13 try:
14 import modeller # type: ignore
15 from modeller import automodel
17 fu.log(
18 f"Modeller is installed in your environment. Modeller version: {modeller.__version__}",
19 out_log,
20 global_log,
21 )
22 fu.log(f"Modeller automodel class: {automodel.automodel}", local_log=out_log)
23 except ImportError:
24 fu.log(
25 "Modeller is not installed in your environment.\nPlease install it by typing:\n\nconda install -c salilab modeller\n",
26 out_log,
27 global_log,
28 )
29 return False
31 return True
34# TODO: Move this function to biobb_common.tools.file_utils
35def _from_string_to_list(input_data: Optional[Union[str, list[str]]]) -> list[str]:
36 """
37 Converts a string to a list, splitting by commas or spaces. If the input is already a list, returns it as is.
38 Returns an empty list if input_data is None.
40 Parameters:
41 input_data (str, list, or None): The string, list, or None value to convert.
43 Returns:
44 list: A list of string elements or an empty list if input_data is None.
45 """
46 if input_data is None:
47 return []
49 if isinstance(input_data, list):
50 # If input is already a list, return it
51 return input_data
53 # If input is a string, determine the delimiter based on presence of commas
54 delimiter = "," if "," in input_data else " "
55 items = input_data.split(delimiter)
57 # Remove whitespace from each item and ignore empty strings
58 processed_items = [item.strip() for item in items if item.strip()]
60 return processed_items