divbase-lib 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- divbase_lib/__init__.py +1 -0
- divbase_lib/api_schemas/__init__.py +0 -0
- divbase_lib/api_schemas/announcements.py +18 -0
- divbase_lib/api_schemas/auth.py +37 -0
- divbase_lib/api_schemas/personal_access_tokens.py +42 -0
- divbase_lib/api_schemas/project_versions.py +90 -0
- divbase_lib/api_schemas/queries.py +210 -0
- divbase_lib/api_schemas/s3.py +359 -0
- divbase_lib/api_schemas/task_history.py +51 -0
- divbase_lib/api_schemas/vcf_dimensions.py +67 -0
- divbase_lib/divbase_constants.py +66 -0
- divbase_lib/exceptions.py +154 -0
- divbase_lib/metadata_validator.py +827 -0
- divbase_lib/s3_checksums.py +120 -0
- divbase_lib/utils.py +133 -0
- divbase_lib-0.1.0.dist-info/METADATA +38 -0
- divbase_lib-0.1.0.dist-info/RECORD +18 -0
- divbase_lib-0.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Custom exceptions for DivBase packages.
|
|
3
|
+
|
|
4
|
+
These are raised by lover-level functions/methods which understand the context of the error.
|
|
5
|
+
|
|
6
|
+
Note: By adding the `__str__` method to each exception,
|
|
7
|
+
we ensure that when you manually raise a specific exception the error message looks good
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class BcftoolsEnvironmentError(Exception):
|
|
14
|
+
"""Raised when there's an issue with the execution environment (Docker, etc.)."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, container_name: str):
|
|
17
|
+
self.container_name = container_name
|
|
18
|
+
error_message = (
|
|
19
|
+
f"No running container found with name {self.container_name}. Ensure the Docker image is available.\n"
|
|
20
|
+
)
|
|
21
|
+
super().__init__(error_message)
|
|
22
|
+
self.error_message = error_message
|
|
23
|
+
|
|
24
|
+
def __str__(self) -> str:
|
|
25
|
+
return self.error_message
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class BcftoolsCommandError(Exception):
|
|
29
|
+
"""Raised when a bcftools command fails to execute properly."""
|
|
30
|
+
|
|
31
|
+
def __init__(self, command: str, error_details: str | None = None):
|
|
32
|
+
self.command = command
|
|
33
|
+
self.error_details = error_details
|
|
34
|
+
|
|
35
|
+
error_message = f"bcftools command failed: '{command}'"
|
|
36
|
+
if error_details:
|
|
37
|
+
error_message += f" with error details: {error_details}"
|
|
38
|
+
|
|
39
|
+
super().__init__(error_message)
|
|
40
|
+
self.error_message = error_message
|
|
41
|
+
|
|
42
|
+
def __str__(self) -> str:
|
|
43
|
+
return self.error_message
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class BcftoolsPipeEmptyCommandError(Exception):
|
|
47
|
+
"""Raised when an empty command is provided to the bcftools pipe."""
|
|
48
|
+
|
|
49
|
+
def __init__(self):
|
|
50
|
+
error_message = "Empty command provided. Please specify at least one valid bcftools command."
|
|
51
|
+
super().__init__(error_message)
|
|
52
|
+
self.error_message = error_message
|
|
53
|
+
|
|
54
|
+
def __str__(self) -> str:
|
|
55
|
+
return self.error_message
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class BcftoolsPipeUnsupportedCommandError(Exception):
|
|
59
|
+
"""Raised when a bcftools command unsupported by the BcftoolsQueryManager class is provided."""
|
|
60
|
+
|
|
61
|
+
def __init__(self, command: str, position: int, valid_commands: list[str]):
|
|
62
|
+
self.command = command
|
|
63
|
+
self.position = position
|
|
64
|
+
self.valid_commands = valid_commands
|
|
65
|
+
|
|
66
|
+
message = (
|
|
67
|
+
f"Unsupported bcftools command '{command}' at position {position}. "
|
|
68
|
+
f"Only the following commands are supported: {', '.join(valid_commands)}"
|
|
69
|
+
)
|
|
70
|
+
super().__init__(message)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class SidecarNoDataLoadedError(Exception):
|
|
74
|
+
"""Raised when no data is loaded in SidecarQueryManager."""
|
|
75
|
+
|
|
76
|
+
def __init__(self, file_path: Path, submethod: str, error_details: str | None = None):
|
|
77
|
+
self.file_path = file_path
|
|
78
|
+
self.error_details = error_details
|
|
79
|
+
|
|
80
|
+
error_message = f"No data loaded from file '{file_path}', as raised in submethod '{submethod}'."
|
|
81
|
+
if error_details:
|
|
82
|
+
error_message += f"More details about the error: {error_details}"
|
|
83
|
+
super().__init__(error_message)
|
|
84
|
+
self.error_message = error_message
|
|
85
|
+
|
|
86
|
+
def __str__(self) -> str:
|
|
87
|
+
return self.error_message
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class SidecarInvalidFilterError(Exception):
|
|
91
|
+
"""Raised when an invalid filter is provided to SidecarQueryManager."""
|
|
92
|
+
|
|
93
|
+
pass
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class SidecarColumnNotFoundError(Exception):
|
|
97
|
+
"""Raised when a requested column is not found in the query result."""
|
|
98
|
+
|
|
99
|
+
pass
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class SidecarSampleIDError(Exception):
|
|
103
|
+
"""Raised when a Sample_ID is invalid or duplicated when loading sidecar data."""
|
|
104
|
+
|
|
105
|
+
pass
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class SidecarMetadataFormatError(Exception):
|
|
109
|
+
"""Raised when the sidecar metadata TSV file has formatting issues (duplicate columns, empty columns, commas in values, etc.)."""
|
|
110
|
+
|
|
111
|
+
pass
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class TaskUserError(Exception):
|
|
115
|
+
"""
|
|
116
|
+
Raised in Celery tasks when an error needs to propagate back to the CLI user.
|
|
117
|
+
|
|
118
|
+
This is intentionally kept as a simple Exception subclass (no custom __init__)
|
|
119
|
+
to avoid UnpicklableExceptionWrapper when passing through Celery's JSON serialization/deserialization.
|
|
120
|
+
Complex exception types such as those inheriting from DivBaseAPIException seem to trigger UnpicklableExceptionWrapper.
|
|
121
|
+
|
|
122
|
+
This class is essentially a wrapper to allow to use more complex exceptions in Celery tasks and catch them
|
|
123
|
+
in the API route handlers to return user-friendly error messages to the CLI.
|
|
124
|
+
In the Celery task use it like:
|
|
125
|
+
raise TaskUserError(str(SomeComplexError(...))) from None
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
pass
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class NoVCFFilesFoundError(Exception):
|
|
132
|
+
"""Raised when no VCF files are found in the project bucket."""
|
|
133
|
+
|
|
134
|
+
pass
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class DimensionsNotUpToDateWithBucketError(Exception):
|
|
138
|
+
"""Raised when VCF files in a bucket are missing or outdated in the dimensions cache."""
|
|
139
|
+
|
|
140
|
+
pass
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class ChecksumVerificationError(Exception):
|
|
144
|
+
"""Raised when a calculated file's checksum does not match the expected value."""
|
|
145
|
+
|
|
146
|
+
def __init__(self, expected_checksum: str, calculated_checksum: str):
|
|
147
|
+
self.expected_checksum = expected_checksum
|
|
148
|
+
self.calculated_checksum = calculated_checksum
|
|
149
|
+
|
|
150
|
+
message = (
|
|
151
|
+
f"Checksum verification failed. Expected: {expected_checksum}, Calculated: {calculated_checksum}"
|
|
152
|
+
f" The file has been deleted to avoid accidental use of a corrupted file."
|
|
153
|
+
)
|
|
154
|
+
super().__init__(message)
|