@orcabus/platform-cdk-constructs 0.0.6 → 0.0.7-alpha.4

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.
Files changed (83) hide show
  1. package/.jsii +858 -6
  2. package/api-gateway/api-gateway.js +22 -4
  3. package/deployment-stack-pipeline/pipeline.js +6 -4
  4. package/dynamodb/config.d.ts +3 -0
  5. package/dynamodb/config.js +7 -0
  6. package/dynamodb/index.d.ts +27 -0
  7. package/dynamodb/index.js +106 -0
  8. package/ecs/config.d.ts +4 -0
  9. package/ecs/config.js +8 -0
  10. package/ecs/index.d.ts +46 -0
  11. package/ecs/index.js +103 -0
  12. package/index.d.ts +5 -2
  13. package/index.js +47 -5
  14. package/index.ts +16 -2
  15. package/lambda/build_python/Dockerfile +60 -0
  16. package/lambda/config.d.ts +11 -0
  17. package/lambda/config.js +19 -0
  18. package/lambda/index.d.ts +59 -0
  19. package/lambda/index.js +242 -0
  20. package/lambda/layers/mart_tools/poetry.lock +303 -0
  21. package/lambda/layers/mart_tools/pyproject.toml +27 -0
  22. package/lambda/layers/mart_tools/src/mart_tools/__init__.py +0 -0
  23. package/lambda/layers/mart_tools/src/mart_tools/mart/__init__.py +8 -0
  24. package/lambda/layers/mart_tools/src/mart_tools/mart/aws_helpers.py +79 -0
  25. package/lambda/layers/mart_tools/src/mart_tools/mart/dataframe_helpers.py +29 -0
  26. package/lambda/layers/mart_tools/src/mart_tools/mart/globals.py +5 -0
  27. package/lambda/layers/mart_tools/src/mart_tools/mart/models.py +71 -0
  28. package/lambda/layers/orcabus_api_tools/poetry.lock +273 -0
  29. package/lambda/layers/orcabus_api_tools/pyproject.toml +27 -0
  30. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/__init__.py +0 -0
  31. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq/__init__.py +172 -0
  32. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq/create_helpers.py +47 -0
  33. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq/globals.py +13 -0
  34. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq/job_helpers.py +53 -0
  35. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq/models.py +253 -0
  36. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq/query_helpers.py +248 -0
  37. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq/update_helpers.py +221 -0
  38. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq/workflow_helpers.py +25 -0
  39. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq_unarchiving/__init__.py +92 -0
  40. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq_unarchiving/create_helpers.py +27 -0
  41. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq_unarchiving/globals.py +21 -0
  42. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq_unarchiving/models.py +51 -0
  43. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq_unarchiving/query_helpers.py +52 -0
  44. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/fastq_unarchiving/update_helpers.py +45 -0
  45. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/filemanager/__init__.py +98 -0
  46. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/filemanager/errors.py +45 -0
  47. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/filemanager/file_helpers.py +341 -0
  48. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/filemanager/globals.py +70 -0
  49. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/filemanager/models.py +59 -0
  50. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/mart/__init__.py +8 -0
  51. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/mart/aws_helpers.py +79 -0
  52. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/mart/dataframe_helpers.py +29 -0
  53. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/mart/globals.py +5 -0
  54. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/mart/models.py +71 -0
  55. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/__init__.py +250 -0
  56. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/contact_helpers.py +109 -0
  57. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/errors.py +104 -0
  58. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/globals.py +16 -0
  59. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/individual_helpers.py +139 -0
  60. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/library_helpers.py +196 -0
  61. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/lims_helpers.py +36 -0
  62. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/models.py +112 -0
  63. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/project_helpers.py +129 -0
  64. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/sample_helpers.py +132 -0
  65. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/metadata/subject_helpers.py +151 -0
  66. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/sequence/__init__.py +15 -0
  67. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/sequence/globals.py +2 -0
  68. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/sequence/models.py +44 -0
  69. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/sequence/sequence_helpers.py +62 -0
  70. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/utils/__init__.py +0 -0
  71. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/utils/aws_helpers.py +123 -0
  72. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/utils/miscell.py +17 -0
  73. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/utils/requests_helpers.py +163 -0
  74. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/workflow/__init__.py +0 -0
  75. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/workflow/errors.py +37 -0
  76. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/workflow/metadata_helpers.py +28 -0
  77. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/workflow/models.py +85 -0
  78. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/workflow/payload_helpers.py +64 -0
  79. package/lambda/layers/orcabus_api_tools/src/orcabus_api_tools/workflow/workflow_run_helpers.py +80 -0
  80. package/package.json +13 -7
  81. package/typedoc.json +3 -0
  82. package/utils/index.d.ts +3 -0
  83. package/utils/index.js +50 -1
@@ -0,0 +1,253 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ {
5
+ "id": "fqr.01JJY7P1AVFGHGVMEDE8T4VWJG",
6
+ "rgid": "ATCCACTG+ACGCACCT.2",
7
+ "index": "ATCCACTG",
8
+ "index2": "ACGCACCT",
9
+ "lane": 2,
10
+ "instrumentRunId": "230223_A00130_0244_AHN3W3DSX5",
11
+ "library": {
12
+ "orcabusId": "lib.01JBMVFP45C2EZRVK67P8JY1D2",
13
+ "libraryId": "L2300223"
14
+ },
15
+ "readSet": {
16
+ "r1": {
17
+ "s3IngestId": "019387bd-2494-7c00-9e41-03e8b6a73306",
18
+ "gzipCompressionSizeInBytes": 49532847794,
19
+ "rawMd5sum": "19e339fdb3c42f0133f5f3b1f9d188e0", // pragma: allowlist secret
20
+ "s3Uri": "s3://archive-prod-fastq-503977275616-ap-southeast-2/v1/year=2023/month=02/230223_A00130_0244_AHN3W3DSX5/202411226f4f7af0/WGS_TsqNano/MDX230039_L2300223_S7_L002_R1_001.fastq.ora"
21
+ },
22
+ "r2": {
23
+ "s3IngestId": "019387bd-9177-79c1-a489-d940ecc11b11",
24
+ "gzipCompressionSizeInBytes": 53189277581,
25
+ "rawMd5sum": "e857de35a8ca008589d24b2e0f647cc7", // pragma: allowlist secret
26
+ "s3Uri": "s3://archive-prod-fastq-503977275616-ap-southeast-2/v1/year=2023/month=02/230223_A00130_0244_AHN3W3DSX5/202411226f4f7af0/WGS_TsqNano/MDX230039_L2300223_S7_L002_R2_001.fastq.ora"
27
+ },
28
+ "compressionFormat": "ORA"
29
+ },
30
+ "qc": null,
31
+ "readCount": null,
32
+ "baseCountEst": null,
33
+ "isValid": true,
34
+ "ntsm": null
35
+ }
36
+ """
37
+
38
+ from enum import Enum
39
+ from typing import (
40
+ TypedDict,
41
+ Optional,
42
+ Dict,
43
+ List, NotRequired, Union, Literal
44
+ )
45
+ from datetime import datetime
46
+
47
+
48
+ class JobType(Enum):
49
+ QC = 'QC'
50
+ FILE_COMPRESSION = 'FILE_COMPRESSION'
51
+ NTSM = 'NTSM'
52
+
53
+
54
+ class JobStatus(Enum):
55
+ PENDING = "PENDING"
56
+ RUNNING = "RUNNING"
57
+ FAILED = "FAILED"
58
+ SUCCEEDED = "SUCCEEDED"
59
+
60
+
61
+ class FileStorageObject(TypedDict):
62
+ s3IngestId: str
63
+ s3Uri: str
64
+ storageClass: str
65
+ sha256: str
66
+
67
+
68
+ class FastqStorageObject(FileStorageObject):
69
+ gzipCompressionSizeInBytes: int
70
+ rawMd5sum: str
71
+
72
+
73
+ class ReadSet(TypedDict):
74
+ r1: FastqStorageObject
75
+ r2: FastqStorageObject
76
+ compressionFormat: str
77
+
78
+
79
+ class Library(TypedDict):
80
+ orcabusId: str
81
+ libraryId: str
82
+
83
+
84
+ class FastqListRowCreate(TypedDict):
85
+ fastqSetId: Optional[str]
86
+ index: str
87
+ lane: int
88
+ instrumentRunId: str
89
+ library: Library
90
+ platform: Optional[str]
91
+ center: Optional[str]
92
+ date: Optional[datetime]
93
+ readSet: Optional[ReadSet]
94
+ qc: Optional[Dict]
95
+ readCount: Optional[int]
96
+ baseCountEst: Optional[int]
97
+ isValid: Optional[bool]
98
+ ntsm: Optional[FileStorageObject]
99
+
100
+
101
+ class FastqListRow(TypedDict):
102
+ id: str
103
+ fastqSetId: Optional[str]
104
+ index: str
105
+ lane: int
106
+ instrumentRunId: str
107
+ library: Library
108
+ platform: Optional[str]
109
+ center: Optional[str]
110
+ date: Optional[datetime]
111
+ readSet: Optional[ReadSet]
112
+ qc: Optional[Dict]
113
+ readCount: Optional[int]
114
+ baseCountEst: Optional[int]
115
+ isValid: Optional[bool]
116
+ ntsm: Optional[FileStorageObject]
117
+
118
+
119
+ class FastqSetCreate(TypedDict):
120
+ library: Library
121
+ fastqSet: List[Union[str, FastqListRow]]
122
+ allowAdditionalFastq: bool
123
+ isCurrentFastqSet: bool
124
+
125
+
126
+ class FastqSet(TypedDict):
127
+ id: str
128
+ library: Library
129
+ fastqSet: List[FastqListRow]
130
+ allowAdditionalFastq: bool
131
+ isCurrentFastqSet: bool
132
+
133
+
134
+ class QcStats(TypedDict):
135
+ insertSizeEstimate: int
136
+ rawWgsCoverageEstimate: int
137
+ r1Q20Fraction: float
138
+ r2Q20Fraction: float
139
+ r1GcFraction: float
140
+ r2GcFraction: float
141
+
142
+
143
+ class ReadCount(TypedDict):
144
+ readCount: int
145
+ baseCountEst: int
146
+
147
+
148
+ class FileCompressionInformation(TypedDict):
149
+ compressionFormat: str
150
+ r1GzipCompressionSizeInBytes: Optional[int]
151
+ r2GzipCompressionSizeInBytes: Optional[int]
152
+ r1RawMd5sum: Optional[int]
153
+ r2RawMd5sum: Optional[int]
154
+
155
+
156
+ class FastqListRowDict(TypedDict):
157
+ rgid: str
158
+ rglb: str
159
+ rgsm: str
160
+ lane: int
161
+ rgcn: str
162
+ rgds: str
163
+ rgdt: str
164
+ rgpl: str
165
+ read1FileUri: str
166
+ read2FileUri: str
167
+
168
+
169
+
170
+ class Job(TypedDict):
171
+ id: str
172
+ fastqId: str
173
+ jobType: JobType
174
+ stepsExecutionArn: str
175
+ status: JobStatus
176
+ startTime: datetime
177
+ endTime: Optional[datetime]
178
+
179
+
180
+ class BoolAllEnum(Enum):
181
+ ALL = "ALL"
182
+ true = True
183
+ false = False
184
+
185
+
186
+ class FastqGetResponseParameters(TypedDict):
187
+ includeS3Details: NotRequired[BoolAllEnum]
188
+
189
+
190
+ class StandardQueryParameters(TypedDict):
191
+ page: NotRequired[int]
192
+ rowsPerPage: NotRequired[int]
193
+
194
+
195
+ class MetadataQueryParameter(TypedDict):
196
+ library: NotRequired[str]
197
+ sample: NotRequired[str]
198
+ subject: NotRequired[str]
199
+ individual: NotRequired[str]
200
+ project: NotRequired[str]
201
+
202
+
203
+ MetadataQueryParametersList = TypedDict(
204
+ 'MetadataQueryParametersList',
205
+ {
206
+ 'library[]': NotRequired[List[str]],
207
+ 'sample[]': NotRequired[List[str]],
208
+ 'subject[]': NotRequired[List[str]],
209
+ 'individual[]': NotRequired[List[str]],
210
+ 'project[]': NotRequired[List[str]],
211
+ }
212
+ )
213
+
214
+ class InstrumentRunIdQueryParameters(TypedDict):
215
+ index: NotRequired[str]
216
+ lane: NotRequired[int]
217
+ instrumentRunId: NotRequired[str]
218
+
219
+ InstrumentRunIdQueryParametersList = TypedDict(
220
+ 'InstrumentRunIdQueryParametersList',
221
+ {
222
+ 'instrumentRunId[]': NotRequired[List[str]],
223
+ }
224
+ )
225
+
226
+
227
+ class FastqListRowQueryParameters(
228
+ StandardQueryParameters,
229
+ MetadataQueryParameter,
230
+ InstrumentRunIdQueryParameters,
231
+ MetadataQueryParametersList,
232
+ InstrumentRunIdQueryParametersList
233
+ ):
234
+ valid: NotRequired[BoolAllEnum]
235
+ includeS3Details: NotRequired[BoolAllEnum]
236
+ fastqSetId: NotRequired[str]
237
+
238
+
239
+ class FastqSetQueryParameters(
240
+ StandardQueryParameters,
241
+ MetadataQueryParameter,
242
+ MetadataQueryParametersList,
243
+ InstrumentRunIdQueryParameters
244
+ ):
245
+ currentFastqSet: NotRequired[BoolAllEnum]
246
+ allowAdditionalFastq: NotRequired[BoolAllEnum]
247
+ includeS3Details: NotRequired[BoolAllEnum]
248
+
249
+ # Additional types
250
+ VALID_BATCH_KEYS = Literal[
251
+ 'library', 'sample', 'subject',
252
+ 'individual', 'project', 'instrumentRunId'
253
+ ]
@@ -0,0 +1,248 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ Query helpers -
5
+
6
+ get_fastqs_in_instrument_run_id
7
+
8
+ get_fastqs_in_library
9
+
10
+ get_fastqs_in_sample
11
+
12
+ get_fastqs_in_subject
13
+
14
+ get_fastqs_in_individual
15
+
16
+ get_fastqs_in_project
17
+
18
+ get_fastq_by_rgid_and_instrument_run_id
19
+
20
+ """
21
+ from functools import reduce
22
+ from itertools import batched
23
+ from operator import concat
24
+ from typing import List, Unpack
25
+
26
+ from . import get_fastq_request_response_results, get_fastq_request
27
+ from .globals import FASTQ_LIST_ROW_ENDPOINT, FASTQ_SET_ENDPOINT
28
+ from .models import FastqListRow, FastqSet, Job, FastqListRowQueryParameters, FastqSetQueryParameters, \
29
+ FastqGetResponseParameters, VALID_BATCH_KEYS
30
+
31
+
32
+ def get_fastq(fastq_id: str, **kwargs: Unpack[FastqGetResponseParameters]) -> FastqListRow:
33
+ # Raise error if any of the kwargs are not in the FastqSetQueryParameters
34
+ for key in kwargs.keys():
35
+ if key not in FastqGetResponseParameters.__annotations__:
36
+ raise ValueError(f"Invalid parameter: {key}")
37
+
38
+ return FastqListRow(
39
+ **get_fastq_request(
40
+ f"{FASTQ_LIST_ROW_ENDPOINT}/{fastq_id}",
41
+ params=dict(kwargs)
42
+ )
43
+ )
44
+
45
+
46
+ def get_fastq_set(
47
+ fastq_set_id: str,
48
+ **kwargs: Unpack[FastqGetResponseParameters]
49
+ ) -> FastqSet:
50
+ """
51
+ Get the fastq set by id
52
+ :param fastq_set_id:
53
+ :param kwargs:
54
+ :return:
55
+ """
56
+ # Raise error if any of the kwargs are not in the FastqSetQueryParameters
57
+ for key in kwargs.keys():
58
+ if key not in FastqSetQueryParameters.__annotations__:
59
+ raise ValueError(f"Invalid parameter: {key}")
60
+
61
+ return FastqSet(
62
+ **get_fastq_request(
63
+ f"{FASTQ_SET_ENDPOINT}/{fastq_set_id}",
64
+ params=dict(kwargs)
65
+ )
66
+ )
67
+
68
+
69
+ def get_fastqs(**kwargs: Unpack[FastqListRowQueryParameters]) -> List[FastqListRow]:
70
+ """
71
+ Get all fastqs
72
+ """
73
+ # Raise error if any of the kwargs are not in the FastqListRowQueryParameters
74
+ for key in kwargs.keys():
75
+ if key not in FastqListRowQueryParameters.__annotations__:
76
+ raise ValueError(f"Invalid parameter: {key}")
77
+
78
+ return get_fastq_request_response_results(
79
+ FASTQ_LIST_ROW_ENDPOINT,
80
+ params=dict(kwargs)
81
+ )
82
+
83
+
84
+ def get_fastq_sets(**kwargs: Unpack[FastqSetQueryParameters]) -> List[FastqSet]:
85
+ """
86
+ Get the fastq set
87
+ :param args:
88
+ :param kwargs:
89
+ :return:
90
+ """
91
+ # Raise error if any of the kwargs are not in the FastqListRowQueryParameters
92
+ for key in kwargs.keys():
93
+ if key not in FastqSetQueryParameters.__annotations__:
94
+ raise ValueError(f"Invalid parameter: {key}")
95
+
96
+ return get_fastq_request_response_results(
97
+ FASTQ_SET_ENDPOINT,
98
+ params=dict(kwargs)
99
+ )
100
+
101
+
102
+ def get_fastqs_in_instrument_run_id(instrument_run_id: str):
103
+ """
104
+ Get all fastqs in an instrument run id
105
+ """
106
+ return get_fastqs(
107
+ instrumentRunId=instrument_run_id
108
+ )
109
+
110
+
111
+ def get_fastqs_in_library(library_id: str):
112
+ """
113
+ Get all fastqs in a library
114
+ """
115
+ return get_fastqs(
116
+ library=library_id,
117
+ )
118
+
119
+
120
+ def get_fastqs_batched(
121
+ item_key: VALID_BATCH_KEYS,
122
+ item_list: List[str],
123
+ batch_size: int = 100,
124
+ **kwargs
125
+ ) -> List[FastqListRow]:
126
+ """
127
+ Get all fastqs in a list of libraries
128
+ """
129
+ # Split by groups of 50
130
+ item_lists = batched(item_list, batch_size)
131
+
132
+ # Get the s3 objects
133
+ try:
134
+ return list(reduce(
135
+ concat,
136
+ list(map(
137
+ lambda item_batch_:
138
+ get_fastqs(
139
+ **{
140
+ f"{item_key}[]": list(item_batch_),
141
+ },
142
+ **kwargs,
143
+ rowsPerPage=100
144
+ ),
145
+ item_lists
146
+ ))
147
+ ))
148
+ except TypeError as e:
149
+ # TypeError: reduce() of empty iterable with no initial value
150
+ return []
151
+
152
+
153
+ def get_fastqs_in_library_list(
154
+ library_id_list: List[str]
155
+ ) -> List[FastqListRow]:
156
+ """
157
+ Get all fastqs in a list of libraries
158
+ """
159
+ return get_fastqs_batched(
160
+ item_key="library",
161
+ item_list=library_id_list,
162
+ batch_size=50
163
+ )
164
+
165
+
166
+ def get_fastqs_in_libraries_and_instrument_run_id(library_id_list, instrument_run_id):
167
+ """
168
+ Get all fastqs in a list of libraries and instrument run id
169
+ :param library_id_list:
170
+ :param instrument_run_id:
171
+ :return:
172
+ """
173
+ return get_fastqs(
174
+ instrumentRunId=instrument_run_id,
175
+ **{
176
+ "library[]": library_id_list,
177
+ }
178
+ )
179
+
180
+
181
+ def get_fastqs_in_sample(sample_id: str):
182
+ """
183
+ Get all fastqs in a sample
184
+ """
185
+ return get_fastqs(
186
+ sample=sample_id
187
+ )
188
+
189
+
190
+ def get_fastqs_in_sample_list(sample_id_list: List[str]):
191
+ """
192
+ Get all fastqs in a list of samples
193
+ :param sample_id_list:
194
+ :return:
195
+ """
196
+ return get_fastqs_batched(
197
+ item_key="sample",
198
+ item_list=sample_id_list,
199
+ batch_size=50
200
+ )
201
+
202
+
203
+ def get_fastqs_in_subject(subject_id):
204
+ """
205
+ Get all fastqs in a subject
206
+ """
207
+ return get_fastqs(
208
+ subject=subject_id
209
+ )
210
+
211
+
212
+ def get_fastqs_in_individual(individual_id):
213
+ """
214
+ Get all fastqs in an individual
215
+ """
216
+ return get_fastqs(
217
+ individual=individual_id
218
+ )
219
+
220
+
221
+ def get_fastqs_in_project(project_id):
222
+ """
223
+ Get all fastqs in a project
224
+ """
225
+ return get_fastqs(
226
+ project=project_id
227
+ )
228
+
229
+
230
+ def get_fastq_list_rows_in_fastq_set(fastq_set_id):
231
+ """
232
+ Get all fastqs in a fastq set
233
+ """
234
+ return get_fastqs(
235
+ fastqSetId=fastq_set_id
236
+ )
237
+
238
+
239
+ def get_fastq_jobs(fastq_id: str) -> List[Job]:
240
+ """
241
+ Get all fastqs in a fastq set
242
+ """
243
+ return list(map(
244
+ lambda job_iter_: Job(**job_iter_),
245
+ get_fastq_request_response_results(
246
+ f"{FASTQ_LIST_ROW_ENDPOINT}/{fastq_id}/jobs"
247
+ )
248
+ ))
@@ -0,0 +1,221 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ Update helpers for the update script.
5
+
6
+ - add_qc_stats
7
+ - add_read_count
8
+ - add_ntsm_storage_object / add_ntsm
9
+ - add_fastq_pair_storage_object / add_read_set
10
+ - detach_fastq_pair_storage_object / detach_read_set
11
+ - validate
12
+ - invalidate
13
+ """
14
+ # Standard imports
15
+
16
+ # Local imports
17
+ from . import fastq_patch_request
18
+ from .globals import FASTQ_LIST_ROW_ENDPOINT, FASTQ_SET_ENDPOINT
19
+ from .models import (
20
+ QcStats, FastqListRow, ReadCount,
21
+ FileCompressionInformation, FileStorageObject, ReadSet,
22
+ FastqSet
23
+ )
24
+
25
+
26
+ def add_qc_stats(fastq_id: str, qc_stats: QcStats) -> FastqListRow:
27
+ """
28
+ Add QC stats to a fastq_id.
29
+
30
+ :param fastq_id: Fastq str
31
+ :param qc_stats: Dictionary of QC stats
32
+ """
33
+ # Raise error if any of the kwargs are not in the QcStats
34
+ for key in qc_stats.keys():
35
+ if key not in QcStats.__annotations__:
36
+ raise ValueError(f"Invalid parameter: {key}")
37
+
38
+ return fastq_patch_request(
39
+ f"{FASTQ_LIST_ROW_ENDPOINT}/{fastq_id}/addQcStats",
40
+ params=dict(qc_stats)
41
+ )
42
+
43
+
44
+ def add_read_count(fastq_id: str, read_count: ReadCount) -> FastqListRow:
45
+ """
46
+ Add read count to a fastq id
47
+ :param fastq_id:
48
+ :param read_count:
49
+ :return:
50
+ """
51
+ for key in read_count.keys():
52
+ if key not in ReadCount.__annotations__:
53
+ raise ValueError(f"Invalid parameter: {key}")
54
+
55
+ return fastq_patch_request(
56
+ f"{FASTQ_LIST_ROW_ENDPOINT}/{fastq_id}/addReadCount",
57
+ params=dict(read_count)
58
+ )
59
+
60
+
61
+ def add_file_compression_information(fastq_id: str, file_compression_information: FileCompressionInformation) -> FastqListRow:
62
+ """
63
+ Add file compression information to a fastq id
64
+ :param fastq_id:
65
+ :param file_compression_information:
66
+ :return:
67
+ """
68
+ for key in file_compression_information.keys():
69
+ if key not in FileCompressionInformation.__annotations__:
70
+ raise ValueError(f"Invalid parameter: {key}")
71
+
72
+ return fastq_patch_request(
73
+ f"{FASTQ_LIST_ROW_ENDPOINT}/{fastq_id}/addFileCompressionInformation",
74
+ params=dict(file_compression_information)
75
+ )
76
+
77
+
78
+ def add_ntsm_storage_object(fastq_id: str, ntsm_fastq_storage_object: FileStorageObject) -> FastqListRow:
79
+ """
80
+ Add a Ntsm storage object to a fastq id.
81
+
82
+ :param fastq_id: Fastq str
83
+ :param ntsm_fastq_storage_object: Ntsm str
84
+ """
85
+ for key in ntsm_fastq_storage_object.keys():
86
+ if key not in FileStorageObject.__annotations__:
87
+ raise ValueError(f"Invalid parameter: {key}")
88
+
89
+ return fastq_patch_request(
90
+ f"{FASTQ_LIST_ROW_ENDPOINT}/{fastq_id}/addNtsmStorageObject",
91
+ params=dict(ntsm_fastq_storage_object)
92
+ )
93
+
94
+
95
+ def add_read_set(fastq_id: str, read_set: ReadSet) -> FastqListRow:
96
+ """
97
+ Add a read set to a fastq id.
98
+
99
+ :param fastq_id: Fastq str
100
+ :param read_set: ReadSet str
101
+ """
102
+ for key in read_set.keys():
103
+ if key not in ReadSet.__annotations__:
104
+ raise ValueError(f"Invalid parameter: {key}")
105
+
106
+ return fastq_patch_request(
107
+ f"{FASTQ_LIST_ROW_ENDPOINT}/{fastq_id}/addFastqPairStorageObject",
108
+ params=dict(read_set)
109
+ )
110
+
111
+
112
+ def detach_read_set(fastq_id: str, read_set: ReadSet) -> FastqListRow:
113
+ """
114
+ Detach a read set to a fastq id.
115
+
116
+ :param fastq_id: Fastq str
117
+ :param read_set: ReadSet str
118
+ """
119
+ for key in read_set.keys():
120
+ if key not in ReadSet.__annotations__:
121
+ raise ValueError(f"Invalid parameter: {key}")
122
+
123
+ return fastq_patch_request(
124
+ f"{FASTQ_LIST_ROW_ENDPOINT}/{fastq_id}/detachFastqPairStorageObject",
125
+ params=dict(read_set)
126
+ )
127
+
128
+
129
+ def validate_fastq(fastq_id: str) -> FastqListRow:
130
+ """
131
+ Validate a fastq id.
132
+
133
+ :param fastq_id: Fastq str
134
+ """
135
+ return fastq_patch_request(
136
+ f"{FASTQ_LIST_ROW_ENDPOINT}/{fastq_id}/validate"
137
+ )
138
+
139
+
140
+ def invalidate_fastq(fastq_id: str) -> FastqListRow:
141
+ """
142
+ Invalidate a fastq id.
143
+
144
+ :param fastq_id: Fastq str
145
+ """
146
+ return fastq_patch_request(
147
+ f"{FASTQ_LIST_ROW_ENDPOINT}/{fastq_id}/invalidate"
148
+ )
149
+
150
+
151
+ def link_fastq_list_row_to_fastq_set(fastq_id: str, fastq_set_id: str) -> FastqSet:
152
+ """
153
+ Link a fastq id to a fastq set.
154
+
155
+ :param fastq_id:
156
+ :param fastq_set_id:
157
+ :return:
158
+ """
159
+ return fastq_patch_request(
160
+ f"{FASTQ_SET_ENDPOINT}/{fastq_set_id}/linkFastq/{fastq_id}"
161
+ )
162
+
163
+
164
+ def unlink_fastq_list_row_from_fastq_set(fastq_id: str, fastq_set_id: str) -> FastqSet:
165
+ """
166
+ Unlink a fastq id from a fastq set.
167
+
168
+ :param fastq_id:
169
+ :param fastq_set_id:
170
+ :return:
171
+ """
172
+
173
+ return fastq_patch_request(
174
+ f"{FASTQ_SET_ENDPOINT}/{fastq_set_id}/unlinkFastq/{fastq_id}"
175
+ )
176
+
177
+
178
+ def allow_additional_fastqs_to_fastq_set(fastq_set_id: str) -> FastqSet:
179
+ """
180
+ Allow additional fastqs to be added to a fastq set.
181
+ :param fastq_set_id:
182
+ :return:
183
+ """
184
+
185
+ return fastq_patch_request(
186
+ f"{FASTQ_SET_ENDPOINT}/{fastq_set_id}/allowAdditionalFastqs"
187
+ )
188
+
189
+
190
+ def disallow_additional_fastqs_to_fastq_set(fastq_set_id: str) -> FastqSet:
191
+ """
192
+ Disallow additional fastqs to be added to a fastq set.
193
+ :param fastq_set_id:
194
+ :return:
195
+ """
196
+
197
+ return fastq_patch_request(
198
+ f"{FASTQ_SET_ENDPOINT}/{fastq_set_id}/disallowAdditionalFastqs"
199
+ )
200
+
201
+
202
+ def set_is_current_fastq_set(fastq_set_id: str) -> FastqSet:
203
+ """
204
+ Set a fastq set as current.
205
+ :param fastq_set_id:
206
+ :return:
207
+ """
208
+ return fastq_patch_request(
209
+ f"{FASTQ_SET_ENDPOINT}/{fastq_set_id}/currentFastqSet"
210
+ )
211
+
212
+
213
+ def set_is_not_current_fastq_set(fastq_set_id: str) -> FastqSet:
214
+ """
215
+ Set a fastq set as not current.
216
+ :param fastq_set_id:
217
+ :return:
218
+ """
219
+ return fastq_patch_request(
220
+ f"{FASTQ_SET_ENDPOINT}/{fastq_set_id}/notCurrentFastqSet"
221
+ )