@orcabus/platform-cdk-constructs 0.0.5 → 0.0.7-alpha.3
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.
- package/.jsii +859 -10
- package/api-gateway/api-gateway.js +22 -4
- package/deployment-stack-pipeline/pipeline.js +8 -5
- package/dynamodb/config.d.ts +3 -0
- package/dynamodb/config.js +7 -0
- package/dynamodb/index.d.ts +27 -0
- package/dynamodb/index.js +106 -0
- package/ecs/config.d.ts +4 -0
- package/ecs/config.js +8 -0
- package/ecs/index.d.ts +46 -0
- package/ecs/index.js +103 -0
- package/index.d.ts +5 -2
- package/index.js +47 -5
- package/index.ts +16 -2
- package/lambda/build_python/Dockerfile +60 -0
- package/lambda/config.d.ts +11 -0
- package/lambda/config.js +19 -0
- package/lambda/index.d.ts +59 -0
- package/lambda/index.js +242 -0
- package/lambda/layers/mart_tools/poetry.lock +303 -0
- package/lambda/layers/mart_tools/pyproject.toml +27 -0
- package/lambda/layers/mart_tools/src/mart_tools/__init__.py +0 -0
- package/lambda/layers/mart_tools/src/mart_tools/mart/__init__.py +8 -0
- package/lambda/layers/mart_tools/src/mart_tools/mart/aws_helpers.py +79 -0
- package/lambda/layers/mart_tools/src/mart_tools/mart/dataframe_helpers.py +29 -0
- package/lambda/layers/mart_tools/src/mart_tools/mart/globals.py +5 -0
- package/lambda/layers/mart_tools/src/mart_tools/mart/models.py +71 -0
- package/lambda/layers/orcabus_api_tools/poetry.lock +273 -0
- package/lambda/layers/orcabus_api_tools/pyproject.toml +27 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/__init__.py +0 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq/__init__.py +172 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq/create_helpers.py +47 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq/globals.py +13 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq/job_helpers.py +53 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq/models.py +253 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq/query_helpers.py +248 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq/update_helpers.py +221 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq/workflow_helpers.py +25 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq_unarchiving/__init__.py +92 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq_unarchiving/create_helpers.py +27 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq_unarchiving/globals.py +21 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq_unarchiving/models.py +51 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq_unarchiving/query_helpers.py +52 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq_unarchiving/update_helpers.py +45 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/filemanager/__init__.py +98 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/filemanager/errors.py +45 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/filemanager/file_helpers.py +341 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/filemanager/globals.py +70 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/filemanager/models.py +59 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/mart/__init__.py +8 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/mart/aws_helpers.py +79 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/mart/dataframe_helpers.py +29 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/mart/globals.py +5 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/mart/models.py +71 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/__init__.py +250 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/contact_helpers.py +109 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/errors.py +104 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/globals.py +16 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/individual_helpers.py +139 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/library_helpers.py +196 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/lims_helpers.py +36 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/models.py +112 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/project_helpers.py +129 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/sample_helpers.py +132 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/subject_helpers.py +151 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/sequence/__init__.py +15 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/sequence/globals.py +2 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/sequence/models.py +44 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/sequence/sequence_helpers.py +62 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/utils/__init__.py +0 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/utils/aws_helpers.py +123 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/utils/miscell.py +17 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/utils/requests_helpers.py +163 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/workflow/__init__.py +0 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/workflow/errors.py +37 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/workflow/metadata_helpers.py +28 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/workflow/models.py +85 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/workflow/payload_helpers.py +64 -0
- package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/workflow/workflow_run_helpers.py +80 -0
- package/package.json +14 -11
- package/typedoc.json +3 -0
- package/utils/index.d.ts +3 -0
- package/utils/index.js +50 -1
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
from typing import Union, List
|
|
3
|
+
|
|
4
|
+
from requests import HTTPError
|
|
5
|
+
|
|
6
|
+
from .globals import LIBRARY_ENDPOINT, ORCABUS_ULID_REGEX_MATCH
|
|
7
|
+
from .models import Library, Subject
|
|
8
|
+
from . import get_metadata_request_response_results, get_item_objs_from_item_id_list
|
|
9
|
+
from .errors import LibraryNotFoundError
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_library_from_library_id(library_id: str) -> Library:
|
|
13
|
+
"""
|
|
14
|
+
Get library from the library id
|
|
15
|
+
:param library_id:
|
|
16
|
+
:return:
|
|
17
|
+
"""
|
|
18
|
+
# Get library id
|
|
19
|
+
# We have an internal id, convert to int
|
|
20
|
+
params = {
|
|
21
|
+
"library_id": library_id
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
# Get library
|
|
25
|
+
try:
|
|
26
|
+
query_results = get_metadata_request_response_results(LIBRARY_ENDPOINT, params)
|
|
27
|
+
assert len(query_results) == 1
|
|
28
|
+
return query_results[0]
|
|
29
|
+
except (HTTPError, AssertionError) as e:
|
|
30
|
+
raise LibraryNotFoundError(
|
|
31
|
+
library_id=library_id,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def get_libraries_list_from_library_id_list(library_id_list: List[str], accept_missing: bool = False) -> List[Library]:
|
|
36
|
+
# We have an internal id, convert to int
|
|
37
|
+
return list(map(
|
|
38
|
+
lambda library_iter_: Library(**library_iter_),
|
|
39
|
+
get_item_objs_from_item_id_list(
|
|
40
|
+
item_id_list=library_id_list,
|
|
41
|
+
item_identifier="libraryId",
|
|
42
|
+
endpoint=LIBRARY_ENDPOINT,
|
|
43
|
+
accept_missing=accept_missing
|
|
44
|
+
)
|
|
45
|
+
))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def get_library_orcabus_id_from_library_id(library_id: str) -> str:
|
|
49
|
+
"""
|
|
50
|
+
Get library from the library id
|
|
51
|
+
:param library_id:
|
|
52
|
+
:return:
|
|
53
|
+
"""
|
|
54
|
+
# Get library id
|
|
55
|
+
return get_library_from_library_id(library_id)['orcabusId']
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def get_library_id_from_library_orcabus_id(library_id: str) -> str:
|
|
59
|
+
"""
|
|
60
|
+
Get library from the library id
|
|
61
|
+
:param library_id:
|
|
62
|
+
:return:
|
|
63
|
+
"""
|
|
64
|
+
# Get library id
|
|
65
|
+
return get_library_from_library_orcabus_id(library_id)['libraryId']
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def coerce_library_id_or_orcabus_id_to_library_orcabus_id(id_: str) -> str:
|
|
69
|
+
if ORCABUS_ULID_REGEX_MATCH.match(id_):
|
|
70
|
+
return id_
|
|
71
|
+
else :
|
|
72
|
+
return get_library_orcabus_id_from_library_id(id_)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def get_library_from_library_orcabus_id(library_orcabus_id: str) -> Library:
|
|
76
|
+
"""
|
|
77
|
+
Get library from the library id
|
|
78
|
+
:param library_orcabus_id:
|
|
79
|
+
:return:
|
|
80
|
+
"""
|
|
81
|
+
# Get library id
|
|
82
|
+
# We have an internal id, convert to int
|
|
83
|
+
params = {
|
|
84
|
+
"orcabus_id": library_orcabus_id
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
# Get library
|
|
88
|
+
try:
|
|
89
|
+
query_list = get_metadata_request_response_results(LIBRARY_ENDPOINT, params)
|
|
90
|
+
assert len(query_list) == 1
|
|
91
|
+
return query_list[0]
|
|
92
|
+
except (HTTPError, AssertionError) as e:
|
|
93
|
+
raise LibraryNotFoundError(
|
|
94
|
+
library_orcabus_id=library_orcabus_id,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def get_libraries_from_library_orcabus_id_list(library_orcabus_id_list: List[str], accept_missing: bool = False) -> List[Library]:
|
|
99
|
+
# We have an internal id, convert to int
|
|
100
|
+
return list(map(
|
|
101
|
+
lambda library_iter_: Library(**library_iter_),
|
|
102
|
+
get_item_objs_from_item_id_list(
|
|
103
|
+
item_id_list=library_orcabus_id_list,
|
|
104
|
+
item_identifier="orcabusId",
|
|
105
|
+
endpoint=LIBRARY_ENDPOINT,
|
|
106
|
+
accept_missing=accept_missing
|
|
107
|
+
)
|
|
108
|
+
))
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def get_subject_from_library_id(library_id: str) -> Subject:
|
|
112
|
+
"""
|
|
113
|
+
Given a library id, collect the subject id
|
|
114
|
+
:param library_id:
|
|
115
|
+
:return:
|
|
116
|
+
"""
|
|
117
|
+
from .subject_helpers import get_subject_from_subject_orcabus_id
|
|
118
|
+
|
|
119
|
+
# Get the subject linked to this library id
|
|
120
|
+
subject_orcabus_id = get_library_from_library_id(library_id)["subject"]["orcabusId"]
|
|
121
|
+
|
|
122
|
+
return get_subject_from_subject_orcabus_id(subject_orcabus_id)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def get_library_type(library_id: str) -> Union[str | None]:
|
|
126
|
+
"""
|
|
127
|
+
Given a library id, collect the library id type
|
|
128
|
+
:param library_id:
|
|
129
|
+
:return:
|
|
130
|
+
"""
|
|
131
|
+
library = get_library_from_library_id(library_id)
|
|
132
|
+
|
|
133
|
+
return library.get("type")
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def get_library_assay_type(library_id: str) -> Union[str | None]:
|
|
137
|
+
"""
|
|
138
|
+
Given a library id, collect the library assay type
|
|
139
|
+
:param library_id:
|
|
140
|
+
:return:
|
|
141
|
+
"""
|
|
142
|
+
library = get_library_from_library_id(library_id)
|
|
143
|
+
|
|
144
|
+
return library.get("assay")
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def get_library_phenotype(library_id: str) -> Union[str | None]:
|
|
148
|
+
"""
|
|
149
|
+
Given a library id, collect the library phenotype
|
|
150
|
+
:param library_id:
|
|
151
|
+
:return:
|
|
152
|
+
"""
|
|
153
|
+
library = get_library_from_library_id(library_id)
|
|
154
|
+
|
|
155
|
+
return library.get("phenotype")
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def get_library_workflow(library_id: str) -> Union[str | None]:
|
|
159
|
+
"""
|
|
160
|
+
Given a library id, collect the library workflow
|
|
161
|
+
:param library_id:
|
|
162
|
+
:return:
|
|
163
|
+
"""
|
|
164
|
+
library = get_library_from_library_id(library_id)
|
|
165
|
+
|
|
166
|
+
return library.get("workflow")
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
# def get_library_project_owner(library_id: str) -> Union[str | None]:
|
|
170
|
+
# """
|
|
171
|
+
# Given a library id, collect the library project owner
|
|
172
|
+
# :param library_id:
|
|
173
|
+
# :return:
|
|
174
|
+
# """
|
|
175
|
+
# library = get_library_from_library_id(library_id)
|
|
176
|
+
#
|
|
177
|
+
# return library.get("projectOwner")
|
|
178
|
+
#
|
|
179
|
+
#
|
|
180
|
+
# def get_library_project_name(library_id: str) -> Union[str | None]:
|
|
181
|
+
# """
|
|
182
|
+
# Given a library id, collect the library workflow
|
|
183
|
+
# :param library_id:
|
|
184
|
+
# :return:
|
|
185
|
+
# """
|
|
186
|
+
# library = get_library_from_library_id(library_id)
|
|
187
|
+
#
|
|
188
|
+
# return library.get("projectName")
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def get_all_libraries() -> List[Library]:
|
|
192
|
+
"""
|
|
193
|
+
Collect all libraries from the database
|
|
194
|
+
:return:
|
|
195
|
+
"""
|
|
196
|
+
return get_metadata_request_response_results(LIBRARY_ENDPOINT)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Custom helpers, for use in generating a 'lims row' given a library id
|
|
5
|
+
"""
|
|
6
|
+
from .models import LimsRow
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def generate_lims_row(library_id: str, instrument_run_id: str) -> LimsRow:
|
|
10
|
+
"""
|
|
11
|
+
Generate a 'lims row' given a library id, we return the following:
|
|
12
|
+
"""
|
|
13
|
+
from .library_helpers import get_library_from_library_id
|
|
14
|
+
from .subject_helpers import get_subject_from_subject_orcabus_id
|
|
15
|
+
from .individual_helpers import get_individual_from_individual_orcabus_id
|
|
16
|
+
from .project_helpers import get_project_from_project_orcabus_id
|
|
17
|
+
from .sample_helpers import get_sample_from_sample_orcabus_id
|
|
18
|
+
|
|
19
|
+
library_obj = get_library_from_library_id(library_id)
|
|
20
|
+
sample_obj = get_sample_from_sample_orcabus_id(library_obj['sample']['orcabusId'])
|
|
21
|
+
subject_obj = get_subject_from_subject_orcabus_id(library_obj['subject']['orcabusId'])
|
|
22
|
+
individual_obj = get_individual_from_individual_orcabus_id(subject_obj['individualSet'][0]['orcabusId'])
|
|
23
|
+
project_obj = get_project_from_project_orcabus_id(library_obj['projectSet'][0]['orcabusId'])
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
'externalSubjectId': subject_obj['subjectId'],
|
|
27
|
+
'externalSampleId': sample_obj['externalSampleId'],
|
|
28
|
+
'individualId': individual_obj['individualId'],
|
|
29
|
+
'sampleId': sample_obj['sampleId'],
|
|
30
|
+
'libraryId': library_obj['libraryId'],
|
|
31
|
+
'instrumentRunId': instrument_run_id,
|
|
32
|
+
'projectName': project_obj['projectId'],
|
|
33
|
+
'sampleType': library_obj['type'],
|
|
34
|
+
'assay': library_obj['assay'],
|
|
35
|
+
'phenotype': library_obj['phenotype'],
|
|
36
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
from typing import (
|
|
4
|
+
TypedDict,
|
|
5
|
+
Optional, List
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# Base Objects
|
|
10
|
+
class MetadataBase(TypedDict):
|
|
11
|
+
orcabusId: str
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class LibraryBase(MetadataBase):
|
|
15
|
+
libraryId: str
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class SampleBase(MetadataBase):
|
|
19
|
+
sampleId: str
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class SubjectBase(MetadataBase):
|
|
23
|
+
subjectId: str
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class IndividualBase(MetadataBase):
|
|
27
|
+
individualId: str
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ProjectBase(MetadataBase):
|
|
31
|
+
projectId: str
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ContactBase(MetadataBase):
|
|
35
|
+
contactId: str
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# Detailed Objects - Often outputs of API calls from other metadata endpoints
|
|
39
|
+
class LibraryDetail(LibraryBase):
|
|
40
|
+
phenotype: Optional[str]
|
|
41
|
+
workflow: Optional[str]
|
|
42
|
+
quality: Optional[str]
|
|
43
|
+
type: Optional[str]
|
|
44
|
+
assay: Optional[str]
|
|
45
|
+
coverage: Optional[float]
|
|
46
|
+
overrideCycles: Optional[str]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class SampleDetail(SampleBase):
|
|
50
|
+
externalSampleId: Optional[str]
|
|
51
|
+
source: Optional[str]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class SubjectDetail(SubjectBase):
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class IndividualDetail(IndividualBase):
|
|
59
|
+
source: Optional[str]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class ProjectDetail(ProjectBase):
|
|
63
|
+
name: Optional[str]
|
|
64
|
+
description: Optional[str]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class ContactDetail(ContactBase):
|
|
68
|
+
name: Optional[str]
|
|
69
|
+
email: Optional[str]
|
|
70
|
+
description: Optional[str]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# Add complete objects
|
|
74
|
+
# These contain the sets of other metadata objects
|
|
75
|
+
class Library(LibraryDetail):
|
|
76
|
+
sample: Optional[SampleDetail]
|
|
77
|
+
subject: Optional[SubjectDetail]
|
|
78
|
+
projectSet: Optional[List[ProjectDetail]]
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class Sample(SampleDetail):
|
|
82
|
+
librarySet: Optional[List[LibraryDetail]]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class Subject(SubjectDetail):
|
|
86
|
+
librarySet: Optional[List[LibraryDetail]]
|
|
87
|
+
individualSet: Optional[List[IndividualDetail]]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class Individual(IndividualDetail):
|
|
91
|
+
subjectSet: Optional[List[SubjectDetail]]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class Project(ProjectDetail):
|
|
95
|
+
contactSet: Optional[List[ContactDetail]]
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class Contact(ContactDetail):
|
|
99
|
+
projectSet: Optional[List[ProjectDetail]]
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class LimsRow(TypedDict):
|
|
103
|
+
externalSubjectId: Optional[str]
|
|
104
|
+
externalSampleId: Optional[str]
|
|
105
|
+
individualId: Optional[str]
|
|
106
|
+
sampleId: Optional[str]
|
|
107
|
+
libraryId: Optional[str]
|
|
108
|
+
instrumentRunId: Optional[str]
|
|
109
|
+
projectName: Optional[str]
|
|
110
|
+
sampleType: Optional[str]
|
|
111
|
+
assay: Optional[str]
|
|
112
|
+
phenotype: Optional[str]
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Helpers for using the project API endpoint
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
# Standard imports
|
|
8
|
+
from typing import List
|
|
9
|
+
from requests import HTTPError
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# Local imports
|
|
13
|
+
from . import get_metadata_request_response_results, get_item_objs_from_item_id_list
|
|
14
|
+
from .errors import ProjectNotFoundError
|
|
15
|
+
from .globals import PROJECT_ENDPOINT, LIBRARY_ENDPOINT, ORCABUS_ULID_REGEX_MATCH
|
|
16
|
+
from .models import Project, Library
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def get_project_from_project_id(project_id: str) -> Project:
|
|
21
|
+
"""
|
|
22
|
+
Get project from the project id
|
|
23
|
+
:param project_id:
|
|
24
|
+
:return:
|
|
25
|
+
"""
|
|
26
|
+
# We have an internal id, convert to int
|
|
27
|
+
params = {
|
|
28
|
+
"projectId": project_id
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# Get project
|
|
32
|
+
try:
|
|
33
|
+
query_results = get_metadata_request_response_results(PROJECT_ENDPOINT, params)
|
|
34
|
+
assert len(query_results) == 1
|
|
35
|
+
return query_results[0]
|
|
36
|
+
except (HTTPError, AssertionError) as e:
|
|
37
|
+
raise ProjectNotFoundError(
|
|
38
|
+
project_id=project_id,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def get_projects_list_from_project_id_list(project_id_list: List[str], accept_missing: bool = False) -> List[Project]:
|
|
43
|
+
"""
|
|
44
|
+
Get project from the project id
|
|
45
|
+
:param project_id:
|
|
46
|
+
:return:
|
|
47
|
+
"""
|
|
48
|
+
# We have an internal id, convert to int
|
|
49
|
+
return list(map(
|
|
50
|
+
lambda project_iter_: Project(**project_iter_),
|
|
51
|
+
get_item_objs_from_item_id_list(
|
|
52
|
+
item_id_list=project_id_list,
|
|
53
|
+
item_identifier="projectId",
|
|
54
|
+
endpoint=PROJECT_ENDPOINT,
|
|
55
|
+
accept_missing=accept_missing
|
|
56
|
+
)
|
|
57
|
+
))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def get_project_orcabus_id_from_project_id(project_id: str) -> str:
|
|
61
|
+
return get_project_from_project_id(project_id)["orcabusId"]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def coerce_project_id_or_orcabus_id_to_project_orcabus_id(id_: str) -> str:
|
|
65
|
+
if ORCABUS_ULID_REGEX_MATCH.match(id_):
|
|
66
|
+
return id_
|
|
67
|
+
else :
|
|
68
|
+
return get_project_orcabus_id_from_project_id(id_)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def get_project_from_project_orcabus_id(project_orcabus_id: str) -> Project:
|
|
72
|
+
"""
|
|
73
|
+
Get project from the project id
|
|
74
|
+
:param project_orcabus_id:
|
|
75
|
+
:return:
|
|
76
|
+
"""
|
|
77
|
+
params = {
|
|
78
|
+
"orcabusId": project_orcabus_id.split(".")[1]
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# Get project
|
|
82
|
+
try:
|
|
83
|
+
query_results = get_metadata_request_response_results(PROJECT_ENDPOINT, params)
|
|
84
|
+
assert len(query_results) == 1
|
|
85
|
+
return query_results[0]
|
|
86
|
+
except (HTTPError, AssertionError) as e:
|
|
87
|
+
raise ProjectNotFoundError(
|
|
88
|
+
project_id=project_orcabus_id,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def get_projects_list_from_project_orcabus_id_list(project_orcabus_id_list: List[str], accept_missing: bool = False) -> List[Project]:
|
|
93
|
+
"""
|
|
94
|
+
Get project from the project id
|
|
95
|
+
:param project_id:
|
|
96
|
+
:return:
|
|
97
|
+
"""
|
|
98
|
+
# We have an internal id, convert to int
|
|
99
|
+
return list(map(
|
|
100
|
+
lambda project_iter_: Project(**project_iter_),
|
|
101
|
+
get_item_objs_from_item_id_list(
|
|
102
|
+
item_id_list=project_orcabus_id_list,
|
|
103
|
+
item_identifier="orcabusId",
|
|
104
|
+
endpoint=PROJECT_ENDPOINT,
|
|
105
|
+
accept_missing=accept_missing
|
|
106
|
+
)
|
|
107
|
+
))
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def get_all_projects() -> List[Project]:
|
|
111
|
+
"""
|
|
112
|
+
Get all projects
|
|
113
|
+
:return:
|
|
114
|
+
"""
|
|
115
|
+
return get_metadata_request_response_results(PROJECT_ENDPOINT)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def list_libraries_in_project(project_orcabus_id: str) -> List[Library]:
|
|
119
|
+
"""
|
|
120
|
+
List all libraries in a project
|
|
121
|
+
Use the projectSet__orcabusId query
|
|
122
|
+
|
|
123
|
+
:return:
|
|
124
|
+
"""
|
|
125
|
+
params = {
|
|
126
|
+
"projectSet__orcabusId": project_orcabus_id
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return get_metadata_request_response_results(LIBRARY_ENDPOINT, params)
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# !/usr/bin/env python3
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Helper functions for a subject
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
# Standard imports
|
|
12
|
+
from typing import List
|
|
13
|
+
from requests.exceptions import HTTPError
|
|
14
|
+
|
|
15
|
+
# Local imports
|
|
16
|
+
from . import get_metadata_request_response_results, get_item_objs_from_item_id_list
|
|
17
|
+
from .errors import SampleNotFoundError
|
|
18
|
+
from .globals import SAMPLE_ENDPOINT, ORCABUS_ULID_REGEX_MATCH
|
|
19
|
+
from .models import Sample, LibraryDetail
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_sample_from_sample_id(sample_id: str) -> Sample:
|
|
24
|
+
"""
|
|
25
|
+
Get sample from the sample id
|
|
26
|
+
:param sample_id:
|
|
27
|
+
:return:
|
|
28
|
+
"""
|
|
29
|
+
# We have an internal id
|
|
30
|
+
params = {
|
|
31
|
+
"sampleId": sample_id
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# Get sample
|
|
35
|
+
try:
|
|
36
|
+
query_results = get_metadata_request_response_results(SAMPLE_ENDPOINT, params)
|
|
37
|
+
assert len(query_results) == 1
|
|
38
|
+
return query_results[0]
|
|
39
|
+
except (HTTPError, AssertionError):
|
|
40
|
+
raise SampleNotFoundError(
|
|
41
|
+
sample_id=sample_id
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def get_samples_list_from_sample_id_list(sample_id_list: List[str], accept_missing: bool = False) -> List[Sample]:
|
|
46
|
+
"""
|
|
47
|
+
Get sample from the sample id
|
|
48
|
+
:param sample_id:
|
|
49
|
+
:return:
|
|
50
|
+
"""
|
|
51
|
+
# We have an internal id, convert to int
|
|
52
|
+
return list(map(
|
|
53
|
+
lambda sample_iter_: Sample(**sample_iter_),
|
|
54
|
+
get_item_objs_from_item_id_list(
|
|
55
|
+
item_id_list=sample_id_list,
|
|
56
|
+
item_identifier="sampleId",
|
|
57
|
+
endpoint=SAMPLE_ENDPOINT,
|
|
58
|
+
accept_missing=accept_missing
|
|
59
|
+
)
|
|
60
|
+
))
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def get_sample_orcabus_id_from_sample_id(sample_id: str) -> str:
|
|
64
|
+
return get_sample_from_sample_id(sample_id)["orcabusId"]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def get_sample_from_sample_orcabus_id(sample_orcabus_id: str) -> Sample:
|
|
68
|
+
"""
|
|
69
|
+
Get sample from the sample id
|
|
70
|
+
:param sample_orcabus_id:
|
|
71
|
+
:return:
|
|
72
|
+
"""
|
|
73
|
+
# We have an internal id
|
|
74
|
+
params = {
|
|
75
|
+
"orcabusId": sample_orcabus_id
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
# Get sample
|
|
79
|
+
try:
|
|
80
|
+
query_results = get_metadata_request_response_results(SAMPLE_ENDPOINT, params)
|
|
81
|
+
assert len(query_results) == 1
|
|
82
|
+
return query_results[0]
|
|
83
|
+
except (HTTPError, AssertionError):
|
|
84
|
+
raise SampleNotFoundError(
|
|
85
|
+
sample_orcabus_id=sample_orcabus_id
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def get_samples_list_from_sample_orcabus_id_list(sample_orcabus_id_list: List[str], accept_missing: bool = False) -> List[Project]:
|
|
90
|
+
"""
|
|
91
|
+
Get sample from the sample id
|
|
92
|
+
:param sample_id:
|
|
93
|
+
:return:
|
|
94
|
+
"""
|
|
95
|
+
# We have an internal id, convert to int
|
|
96
|
+
return list(map(
|
|
97
|
+
lambda sample_iter_: Sample(**sample_iter_),
|
|
98
|
+
get_item_objs_from_item_id_list(
|
|
99
|
+
item_id_list=sample_orcabus_id_list,
|
|
100
|
+
item_identifier="orcabusId",
|
|
101
|
+
endpoint=SAMPLE_ENDPOINT,
|
|
102
|
+
accept_missing=accept_missing
|
|
103
|
+
)
|
|
104
|
+
))
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def coerce_sample_id_or_orcabus_id_to_sample_orcabus_id(id_: str) -> str:
|
|
108
|
+
if ORCABUS_ULID_REGEX_MATCH.match(id_):
|
|
109
|
+
return id_
|
|
110
|
+
else :
|
|
111
|
+
return get_sample_orcabus_id_from_sample_id(id_)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def list_libraries_in_sample(sample_orcabus_id: str) -> List[LibraryDetail]:
|
|
115
|
+
"""
|
|
116
|
+
Given a sample id, return the list of library objects in the sample
|
|
117
|
+
:param sample_orcabus_id:
|
|
118
|
+
:return:
|
|
119
|
+
"""
|
|
120
|
+
# Get ID For Subject
|
|
121
|
+
sample = get_sample_from_sample_orcabus_id(sample_orcabus_id)
|
|
122
|
+
|
|
123
|
+
# Get the sample
|
|
124
|
+
return sample.get("librarySet", [])
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def get_all_samples():
|
|
128
|
+
"""
|
|
129
|
+
Get all samples from the sample database
|
|
130
|
+
:return:
|
|
131
|
+
"""
|
|
132
|
+
return get_metadata_request_response_results(SAMPLE_ENDPOINT)
|