File size: 1,577 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
"""API simple MSA search call wrappers."""

from contextlib import ExitStack
from pathlib import Path

import requests
import typer
from rich import print  # pylint:disable=redefined-builtin

from folding_studio.config import API_URL, REQUEST_TIMEOUT
from folding_studio.utils.data_model import MSARequestParams
from folding_studio.utils.headers import get_auth_headers
from folding_studio.utils.project_validation import define_project_code_or_raise


def simple_msa(
    file: Path,
    params: MSARequestParams,
    project_code: str | None = None,
) -> dict:
    """Make a simple MSA calculation from a file.

    Args:
        file (Path): Data source file path.
        params (MSARequestParams): API request parameters.
        project_code (str|None): Project code under which the jobs are billed.

    Raises:
        typer.Exit: If an error occurs during the API call.
    """
    project_code = define_project_code_or_raise(project_code=project_code)
    url = API_URL + "searchMSA"

    with ExitStack() as stack:
        fasta_file = [("fasta_file", stack.enter_context(file.open("rb")))]
        files = fasta_file
        response = requests.post(
            url,
            data=params.model_dump(mode="json"),
            headers=get_auth_headers(),
            files=files,
            timeout=REQUEST_TIMEOUT,
            params={"project_code": project_code},
        )

    if not response.ok:
        print(f"An error occurred: {response.content.decode()}")
        raise typer.Exit(code=1)

    response_json = response.json()
    return response_json