11
11
from api .utils .dates import parse_date_only_string
12
12
from api .utils .db import (
13
13
Connection ,
14
- get_project_read_connection ,
15
- get_project_write_connection ,
14
+ get_project_db_connection ,
16
15
get_projectless_db_connection ,
17
16
)
18
17
from api .utils .export import ExportType
19
18
from db .python .layers .analysis import AnalysisLayer
20
19
from db .python .tables .analysis import AnalysisFilter
21
- from db .python .tables .project import ProjectPermissionsTable
22
20
from db .python .utils import GenericFilter
23
21
from models .enums import AnalysisStatus
24
- from models .models .analysis import (
25
- Analysis ,
26
- AnalysisInternal ,
27
- ProportionalDateTemporalMethod ,
28
- )
29
- from models .models .group import ReadAccessRoles
22
+ from models .models .analysis import Analysis , ProportionalDateTemporalMethod
23
+ from models .models .project import FullWriteAccessRoles , ReadAccessRoles
30
24
from models .utils .sequencing_group_id_format import (
31
25
sequencing_group_id_format ,
32
26
sequencing_group_id_format_list ,
@@ -96,7 +90,8 @@ def to_filter(self, project_id_map: dict[str, int]) -> AnalysisFilter:
96
90
97
91
@router .put ('/{project}/' , operation_id = 'createAnalysis' , response_model = int )
98
92
async def create_analysis (
99
- analysis : Analysis , connection : Connection = get_project_write_connection
93
+ analysis : Analysis ,
94
+ connection : Connection = get_project_db_connection (FullWriteAccessRoles ),
100
95
) -> int :
101
96
"""Create a new analysis"""
102
97
@@ -136,14 +131,14 @@ async def update_analysis(
136
131
)
137
132
async def get_all_sample_ids_without_analysis_type (
138
133
analysis_type : str ,
139
- connection : Connection = get_project_read_connection ,
134
+ connection : Connection = get_project_db_connection ( ReadAccessRoles ) ,
140
135
):
141
136
"""get_all_sample_ids_without_analysis_type"""
142
137
atable = AnalysisLayer (connection )
143
- assert connection .project
138
+ assert connection .project_id
144
139
sequencing_group_ids = (
145
140
await atable .get_all_sequencing_group_ids_without_analysis_type (
146
- connection .project , analysis_type
141
+ connection .project_id , analysis_type
147
142
)
148
143
)
149
144
return {
@@ -156,12 +151,12 @@ async def get_all_sample_ids_without_analysis_type(
156
151
operation_id = 'getIncompleteAnalyses' ,
157
152
)
158
153
async def get_incomplete_analyses (
159
- connection : Connection = get_project_read_connection ,
154
+ connection : Connection = get_project_db_connection ( ReadAccessRoles ) ,
160
155
):
161
156
"""Get analyses with status queued or in-progress"""
162
157
atable = AnalysisLayer (connection )
163
- assert connection .project
164
- results = await atable .get_incomplete_analyses (project = connection .project )
158
+ assert connection .project_id
159
+ results = await atable .get_incomplete_analyses (project = connection .project_id )
165
160
return [r .to_external () for r in results ]
166
161
167
162
@@ -171,13 +166,13 @@ async def get_incomplete_analyses(
171
166
)
172
167
async def get_latest_complete_analysis_for_type (
173
168
analysis_type : str ,
174
- connection : Connection = get_project_read_connection ,
169
+ connection : Connection = get_project_db_connection ( ReadAccessRoles ) ,
175
170
):
176
171
"""Get (SINGLE) latest complete analysis for some analysis type"""
177
172
alayer = AnalysisLayer (connection )
178
- assert connection .project
173
+ assert connection .project_id
179
174
analysis = await alayer .get_latest_complete_analysis_for_type (
180
- project = connection .project , analysis_type = analysis_type
175
+ project = connection .project_id , analysis_type = analysis_type
181
176
)
182
177
return analysis .to_external ()
183
178
@@ -189,16 +184,16 @@ async def get_latest_complete_analysis_for_type(
189
184
async def get_latest_complete_analysis_for_type_post (
190
185
analysis_type : str ,
191
186
meta : dict [str , Any ] = Body (..., embed = True ), # type: ignore[assignment]
192
- connection : Connection = get_project_read_connection ,
187
+ connection : Connection = get_project_db_connection ( ReadAccessRoles ) ,
193
188
):
194
189
"""
195
190
Get SINGLE latest complete analysis for some analysis type
196
191
(you can specify meta attributes in this route)
197
192
"""
198
193
alayer = AnalysisLayer (connection )
199
- assert connection .project
194
+ assert connection .project_id
200
195
analysis = await alayer .get_latest_complete_analysis_for_type (
201
- project = connection .project ,
196
+ project = connection .project_id ,
202
197
analysis_type = analysis_type ,
203
198
meta = meta ,
204
199
)
@@ -229,11 +224,8 @@ async def query_analyses(
229
224
if not query .projects :
230
225
raise ValueError ('Must specify "projects"' )
231
226
232
- pt = ProjectPermissionsTable (connection )
233
- projects = await pt .get_and_check_access_to_projects_for_names (
234
- user = connection .author ,
235
- project_names = query .projects ,
236
- allowed_roles = ReadAccessRoles ,
227
+ projects = connection .get_and_check_access_to_projects_for_names (
228
+ query .projects , ReadAccessRoles
237
229
)
238
230
project_name_map = {p .name : p .id for p in projects }
239
231
atable = AnalysisLayer (connection )
@@ -243,27 +235,24 @@ async def query_analyses(
243
235
244
236
@router .get ('/analysis-runner' , operation_id = 'getAnalysisRunnerLog' )
245
237
async def get_analysis_runner_log (
246
- project_names : list [str ] = Query (None ), # type: ignore
247
- # author: str = None, # not implemented yet, uncomment when we do
248
- output_dir : str = None ,
249
- ar_guid : str = None ,
238
+ project_names : list [str ],
239
+ output_dir : str ,
240
+ ar_guid : str | None = None ,
250
241
connection : Connection = get_projectless_db_connection ,
251
- ) -> list [AnalysisInternal ]:
242
+ ) -> list [Analysis ]:
252
243
"""
253
244
Get log for the analysis-runner, useful for checking this history of analysis
254
245
"""
255
246
atable = AnalysisLayer (connection )
256
247
project_ids = None
257
- if project_names :
258
- pt = ProjectPermissionsTable (connection )
259
- projects = await pt .get_and_check_access_to_projects_for_names (
260
- connection .author , project_names , allowed_roles = ReadAccessRoles
261
- )
262
- project_ids = [p .id for p in projects ]
248
+
249
+ projects = connection .get_and_check_access_to_projects_for_names (
250
+ project_names , allowed_roles = ReadAccessRoles
251
+ )
252
+ project_ids = [p .id for p in projects ]
263
253
264
254
results = await atable .get_analysis_runner_log (
265
255
project_ids = project_ids ,
266
- # author=author,
267
256
output_dir = output_dir ,
268
257
ar_guid = ar_guid ,
269
258
)
@@ -278,7 +267,7 @@ async def get_analysis_runner_log(
278
267
async def get_sample_reads_map (
279
268
export_type : ExportType = ExportType .JSON ,
280
269
sequencing_types : list [str ] = Query (None ), # type: ignore
281
- connection : Connection = get_project_read_connection ,
270
+ connection : Connection = get_project_db_connection ( ReadAccessRoles ) ,
282
271
):
283
272
"""
284
273
Get map of ExternalSampleId pathToCram InternalSeqGroupID for seqr
@@ -293,9 +282,9 @@ async def get_sample_reads_map(
293
282
"""
294
283
295
284
at = AnalysisLayer (connection )
296
- assert connection .project
285
+ assert connection .project_id
297
286
objs = await at .get_sample_cram_path_map_for_seqr (
298
- project = connection .project , sequencing_types = sequencing_types
287
+ project = connection .project_id , sequencing_types = sequencing_types
299
288
)
300
289
301
290
for r in objs :
@@ -311,7 +300,7 @@ async def get_sample_reads_map(
311
300
writer = csv .writer (output , delimiter = export_type .get_delimiter ())
312
301
writer .writerows (rows )
313
302
314
- basefn = f'{ connection .project } -seqr-igv-paths-{ date .today ().isoformat ()} '
303
+ basefn = f'{ connection .project_id } -seqr-igv-paths-{ date .today ().isoformat ()} '
315
304
316
305
return StreamingResponse (
317
306
iter ([output .getvalue ()]),
@@ -345,9 +334,8 @@ async def get_proportionate_map(
345
334
}
346
335
}
347
336
"""
348
- pt = ProjectPermissionsTable (connection )
349
- project_list = await pt .get_and_check_access_to_projects_for_names (
350
- connection .author , projects , allowed_roles = ReadAccessRoles
337
+ project_list = connection .get_and_check_access_to_projects_for_names (
338
+ projects , allowed_roles = ReadAccessRoles
351
339
)
352
340
project_ids = [p .id for p in project_list ]
353
341
0 commit comments