File size: 5,125 Bytes
44459bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
"""Helper methods for validating cli entries."""

from enum import Enum
from pathlib import Path

import typer

from folding_studio.utils.path_helpers import extract_files


class SupportedCustomTemplateFile(str, Enum):
    """Supported custom template file extensions."""

    CIF = ".cif"


class SupportedCustomMSAFile(str, Enum):
    """Supported custom msa file extensions."""

    STO = ".sto"
    A3M = ".a3m"


class SupportedTemplateMaskFile(str, Enum):
    """Supported custom template file extensions."""

    JSON = ".json"


def extract_and_validate_custom_templates(
    paths: list[Path],
) -> list[Path]:
    """Extract and validate a list of path to use as custom templates.

    Before checking the files, if a directory path is in the list, its files are extracted.

    Args:
        paths (list[Path]): List of paths.

    Raises:
        typer.BadParameter: If a file is not supported.

    Returns:
        list[Path]: Extracted and validated custom template files path.
    """
    extracted_paths = extract_files(paths)
    supported_files = [item.value for item in SupportedCustomTemplateFile]
    for path in extracted_paths:
        if path.suffix not in supported_files:
            raise typer.BadParameter(
                f"The file '{path}' is not supported. "
                f"Only {supported_files} are supported for custom templates."
            )
    return extracted_paths


def extract_and_validate_custom_msas(paths: list[Path]) -> list[Path]:
    """Extract and validate a list of path to use as custom msas.

    Before checking the files, if a directory path is in the list, its files are extracted.

    Args:
        paths (list[Path]): List of paths.

    Raises:
        typer.BadParameter: If a file is not supported.

    Returns:
        list[Path]: Extracted and validated custom msas files path.
    """
    extracted_paths = extract_files(paths)
    supported_files = [item.value for item in SupportedCustomMSAFile]
    for path in extracted_paths:
        if path.suffix not in supported_files:
            raise typer.BadParameter(
                f"The file '{path}' is not supported. "
                f"Only {supported_files} are supported for custom msas."
            )
    return extracted_paths


def validate_initial_guess(
    initial_guess_file: Path | None,
) -> Path:
    """Extract and validate the file used for initial guess.

    Args:
        path (Path | None): Initial guess file parameter.

    Raises:
        typer.BadParameter: If a file is not supported.

    Returns:
        Path | None: Validated initial guess file path or None.
    """
    if not initial_guess_file:
        return None
    supported_files = [
        item.value for item in SupportedCustomTemplateFile
    ]  # initial guess files are equivalent to template files
    if initial_guess_file.suffix not in supported_files:
        raise typer.BadParameter(
            f"The file '{initial_guess_file}' is not supported. "
            f"Only {supported_files} are supported for initial guess."
        )
    return initial_guess_file


def validate_template_mask(
    template_mask_file: Path | None,
) -> Path:
    """Extract and validate the file used for template masks.g.

    Args:
        path (Path | None): template masks.g file parameter.

    Raises:
        typer.BadParameter: If a file is not supported.

    Returns:
        Path | None: Validated template masks.g file path or None.
    """
    if not template_mask_file:
        return None
    supported_files = [
        item.value for item in SupportedTemplateMaskFile
    ]  # template masks.g files are equivalent to template files
    if template_mask_file.suffix not in supported_files:
        raise typer.BadParameter(
            f"The file '{template_mask_file}' is not supported. "
            f"Only {supported_files} are supported for template masks.g."
        )
    return template_mask_file


def validate_list_initial_guess(ig_files: list[Path]) -> list[Path]:
    """Extract and validate a list of initial guess files.

    Args:
        ig_files (list[Path]): List of initial guess files path.

    Returns:
        list[Path]: Extracted and validated initial guess files path.

    """
    extracted_paths = extract_files(ig_files)
    initial_guess_files = []
    for path in extracted_paths:
        validated_ig_path = validate_initial_guess(initial_guess_file=path)
        if validated_ig_path:
            initial_guess_files.append(validated_ig_path)

    return initial_guess_files


def validate_list_template_mask(tm_files: list[Path]) -> list[Path]:
    """Extract and validate a list of template mask

    Args:
        tm_files (list[Path]): List of template mask files path.

    Returns:
        list[Path]: Extracted and validated template mask files path.

    """
    extracted_paths = extract_files(tm_files)
    template_mask_files = []
    for path in extracted_paths:
        validated_tm_path = validate_template_mask(template_mask_file=path)
        if validated_tm_path:
            template_mask_files.append(validated_tm_path)

    return template_mask_files