45
45
from ....models .fastq_list_row import FastqListRowData
46
46
from ....models .fastq_set import (
47
47
FastqSetData , FastqSetResponse , FastqSetListResponse , FastqSetCreate ,
48
- FastqSetQueryPaginatedResponse
48
+ FastqSetQueryPaginatedResponse , FastqSetResponseDict
49
49
)
50
50
from ....models .library import LibraryData
51
51
from ....models .merge_fastq_sets import MergePatch
54
54
is_orcabus_ulid ,
55
55
sanitise_fqs_orcabus_id ,
56
56
sanitise_fqr_orcabus_id ,
57
+ sanitise_fqs_orcabus_id_x ,
58
+ sanitise_fqs_orcabus_id_y
57
59
)
58
60
59
61
router = APIRouter ()
@@ -217,7 +219,7 @@ async def list_fastq_sets(
217
219
lambda fqs_iter_ : FastqSetData .from_response (** fqs_iter_ .to_dict ()),
218
220
query_lists [0 ]
219
221
)),
220
- include_s3_detail = include_s3_details
222
+ include_s3_details = include_s3_details
221
223
).model_dump (),
222
224
query_pagination = pagination ,
223
225
params_response = dict (filter (
@@ -253,7 +255,7 @@ async def list_fastq_sets(
253
255
query_lists [0 ]
254
256
)
255
257
)),
256
- include_s3_detail = include_s3_details
258
+ include_s3_details = include_s3_details
257
259
).model_dump (by_alias = True ),
258
260
query_pagination = pagination ,
259
261
params_response = dict (filter (
@@ -280,27 +282,38 @@ async def list_fastq_sets(
280
282
Please use the fastqSet endpoint if registering multiple fastqs simultaneously to reduce race conditions
281
283
""" )
282
284
)
283
- async def create_fastq (fastq_set_obj_create : FastqSetCreate ) -> FastqSetResponse :
285
+ async def create_fastq (fastq_set_obj_create : FastqSetCreate ) -> FastqSetResponseDict :
284
286
# Confirm that the library id matches those in the fastq objects
285
287
if len (set (list (map (
286
288
lambda fastq_obj : fastq_obj .library .orcabus_id ,
287
- fastq_set_obj_create .fastq_set
289
+ # Iterate over each object in the fastq set, 'get' object if of type 'string'
290
+ # Otherwise parse the object itself
291
+ list (map (
292
+ lambda fastq_obj_iter_ : (
293
+ FastqListRowData .get (fastq_obj_iter_ )
294
+ if isinstance (fastq_obj_iter_ , str )
295
+ else fastq_obj_iter_
296
+ ),
297
+ fastq_set_obj_create .fastq_set
298
+ ))
288
299
)))) > 1 :
289
300
raise HTTPException (
290
301
status_code = 409 ,
291
302
detail = "Got multiple different library ids in the fastq objects"
292
303
)
293
304
294
305
# Confirm that the library id matches the library id in the fastq set
295
- if fastq_set_obj_create .library .orcabus_id != fastq_set_obj_create .fastq_set [0 ].library .orcabus_id :
296
- raise HTTPException (
297
- status_code = 409 ,
298
- detail = "Fastq set library id does not match those of the fastq objects"
299
- )
306
+ first_fastq_obj = fastq_set_obj_create .fastq_set [0 ]
307
+ if isinstance (first_fastq_obj , str ):
308
+ first_fastq_obj = FastqListRowData .get (first_fastq_obj )
300
309
301
310
# Confirm that all fastq sets are unique
302
311
rgid_exts = list (set (list (map (
303
- lambda fastq_obj_iter_ : FastqListRowData (** dict (fastq_obj_iter_ .model_dump (by_alias = True ))).rgid_ext ,
312
+ lambda fastq_obj_iter_ : (
313
+ FastqListRowData .get (fastq_obj_iter_ ).rgid_ext
314
+ if isinstance (fastq_obj_iter_ , str )
315
+ else FastqListRowData (** dict (fastq_obj_iter_ .model_dump (by_alias = True ))).rgid_ext
316
+ ),
304
317
fastq_set_obj_create .fastq_set
305
318
))))
306
319
if len (rgid_exts ) != len (fastq_set_obj_create .fastq_set ):
@@ -398,6 +411,13 @@ async def create_fastq(fastq_set_obj_create: FastqSetCreate) -> FastqSetResponse
398
411
detail = "Fastq set contains invalid fastqs"
399
412
)
400
413
414
+ # Ensure that the library id matches the library id in the fastq set
415
+ if fastq_set_data_obj .library .orcabus_id != first_fastq_obj .library .orcabus_id :
416
+ raise HTTPException (
417
+ status_code = 409 ,
418
+ detail = "Fastq set library id does not match those of the fastq objects"
419
+ )
420
+
401
421
# Add the fastq_set_id to the fastq objects
402
422
for fastq_obj in fastq_data_objs :
403
423
fastq_obj .fastq_set_id = fastq_set_data_obj .id
@@ -430,18 +450,18 @@ async def create_fastq(fastq_set_obj_create: FastqSetCreate) -> FastqSetResponse
430
450
async def get_fastq (
431
451
fastq_set_id : str = Depends (sanitise_fqs_orcabus_id ),
432
452
# Include s3 uri - resolve the s3 uri if requested
433
- include_s3_detail : Optional [bool ] = Query (
453
+ include_s3_details : Optional [bool ] = Query (
434
454
default = False ,
435
- alias = "includeS3Detail " ,
455
+ alias = "includeS3Details " ,
436
456
description = "Include the s3 uris for the fastq objects"
437
457
)
438
- ) -> FastqSetResponse :
458
+ ) -> FastqSetResponseDict :
439
459
try :
440
460
return FastqSetListResponse (
441
461
fastq_set_list = [
442
462
FastqSetData .get (fastq_set_id )
443
463
],
444
- include_s3_detail = include_s3_detail
464
+ include_s3_details = include_s3_details
445
465
).model_dump (by_alias = True )[0 ]
446
466
except DoesNotExist as e :
447
467
raise HTTPException (status_code = 404 , detail = str (e ))
@@ -465,7 +485,7 @@ async def get_fastq_list_row(fastq_set_id: str = Depends(sanitise_fqs_orcabus_id
465
485
tags = ["fastqset update" ],
466
486
description = "Link a fastq object to this fastq set"
467
487
)
468
- async def link_fastq (fastq_set_id : str = Depends (sanitise_fqs_orcabus_id ), fastq_id = Depends (sanitise_fqr_orcabus_id )) -> FastqSetResponse :
488
+ async def link_fastq (fastq_set_id : str = Depends (sanitise_fqs_orcabus_id ), fastq_id = Depends (sanitise_fqr_orcabus_id )) -> FastqSetResponseDict :
469
489
fastq_set_obj = FastqSetData .get (fastq_set_id )
470
490
fastq_obj = FastqListRowData .get (fastq_id )
471
491
@@ -574,7 +594,7 @@ async def unlink_fastq(fastq_set_id: str = Depends(sanitise_fqs_orcabus_id), fas
574
594
tags = ["fastqset update" ],
575
595
description = "Set this fastq set as the current fastq set for this library"
576
596
)
577
- async def set_current_fastq_set (fastq_set_id : str = Depends (sanitise_fqs_orcabus_id )) -> FastqSetResponse :
597
+ async def set_current_fastq_set (fastq_set_id : str = Depends (sanitise_fqs_orcabus_id )) -> FastqSetResponseDict :
578
598
fastq_set_obj = FastqSetData .get (fastq_set_id )
579
599
580
600
# Check fastq set exists
@@ -620,7 +640,7 @@ async def set_current_fastq_set(fastq_set_id: str = Depends(sanitise_fqs_orcabus
620
640
tags = ["fastqset update" ],
621
641
description = "Set current fastq set flag to false for this fastq set"
622
642
)
623
- async def set_current_fastq_set (fastq_set_id : str = Depends (sanitise_fqs_orcabus_id )) -> FastqSetResponse :
643
+ async def set_current_fastq_set (fastq_set_id : str = Depends (sanitise_fqs_orcabus_id )) -> FastqSetResponseDict :
624
644
fastq_set_obj = FastqSetData .get (fastq_set_id )
625
645
626
646
# Check fastq set exists
@@ -653,7 +673,7 @@ async def set_current_fastq_set(fastq_set_id: str = Depends(sanitise_fqs_orcabus
653
673
tags = ["fastqset update" ],
654
674
description = "Allow additional fastqs to this fastq set"
655
675
)
656
- async def set_allow_additional_fastqs (fastq_set_id : str = Depends (sanitise_fqs_orcabus_id )) -> FastqSetResponse :
676
+ async def set_allow_additional_fastqs (fastq_set_id : str = Depends (sanitise_fqs_orcabus_id )) -> FastqSetResponseDict :
657
677
fastq_set_obj = FastqSetData .get (fastq_set_id )
658
678
659
679
# Check fastq set exists
@@ -702,7 +722,7 @@ async def set_allow_additional_fastqs(fastq_set_id: str = Depends(sanitise_fqs_o
702
722
tags = ["fastqset update" ],
703
723
description = "Disallow additional fastqs to this fastq set"
704
724
)
705
- async def set_allow_additional_fastqs_to_false (fastq_set_id : str = Depends (sanitise_fqs_orcabus_id )) -> FastqSetResponse :
725
+ async def set_allow_additional_fastqs_to_false (fastq_set_id : str = Depends (sanitise_fqs_orcabus_id )) -> FastqSetResponseDict :
706
726
fastq_set_obj = FastqSetData .get (fastq_set_id )
707
727
708
728
# Check fastq set exists
@@ -736,7 +756,7 @@ async def set_allow_additional_fastqs_to_false(fastq_set_id: str = Depends(sanit
736
756
tags = ["fastqset merge" ],
737
757
description = "Merge multiple fastq sets into a single fastq set"
738
758
)
739
- async def merge_fastq_sets (fastq_set_ids : MergePatch = Depends ()) -> FastqSetResponse :
759
+ async def merge_fastq_sets (fastq_set_ids : MergePatch = Depends ()) -> FastqSetResponseDict :
740
760
# Check that the fastq set ids are unique
741
761
fastq_set_ids = fastq_set_ids .fastq_set_ids
742
762
if len (list (set (fastq_set_ids ))) != len (fastq_set_ids ):
@@ -856,7 +876,7 @@ async def validate_ntsm_internal(fastq_set_id: str = Depends(sanitise_fqs_orcabu
856
876
857
877
# Get the fastq list rows
858
878
fastq_list_rows = list (map (
859
- lambda fastq_obj_iter_ : FastqListRowData .get (fastq_obj_iter_ . id ),
879
+ lambda fastq_set_id_iter : FastqListRowData .get (fastq_set_id_iter ),
860
880
fastq_set_obj .fastq_set_ids
861
881
))
862
882
@@ -882,7 +902,7 @@ async def validate_ntsm_internal(fastq_set_id: str = Depends(sanitise_fqs_orcabu
882
902
tags = ["fastqset ntsm" ],
883
903
description = "Validate all fastq list rows in the ntsm match, run all-by-all on the ntsms in the fastq set"
884
904
)
885
- async def validate_ntsm_internal (fastq_set_id_x : str = Depends (sanitise_fqs_orcabus_id ), fastq_set_id_y = Depends (sanitise_fqs_orcabus_id )) -> Dict :
905
+ async def validate_ntsm_internal (fastq_set_id_x : str = Depends (sanitise_fqs_orcabus_id_x ), fastq_set_id_y = Depends (sanitise_fqs_orcabus_id_y )) -> Dict :
886
906
# Get the fastq set object
887
907
fastq_set_obj_x = FastqSetData .get (fastq_set_id_x )
888
908
fastq_set_obj_y = FastqSetData .get (fastq_set_id_y )
@@ -896,7 +916,7 @@ async def validate_ntsm_internal(fastq_set_id_x: str = Depends(sanitise_fqs_orca
896
916
897
917
# Get the fastq list rows
898
918
fastq_list_rows_x = list (map (
899
- lambda fastq_obj_iter_ : FastqListRowData .get (fastq_obj_iter_ . id ),
919
+ lambda fastq_obj_iter_ : FastqListRowData .get (fastq_obj_iter_ ),
900
920
fastq_set_obj_x .fastq_set_ids
901
921
))
902
922
@@ -919,7 +939,7 @@ async def validate_ntsm_internal(fastq_set_id_x: str = Depends(sanitise_fqs_orca
919
939
920
940
# Get the fastq list rows
921
941
fastq_list_rows_y = list (map (
922
- lambda fastq_obj_iter_ : FastqListRowData .get (fastq_obj_iter_ . id ),
942
+ lambda fastq_obj_iter_ : FastqListRowData .get (fastq_obj_iter_ ),
923
943
fastq_set_obj_y .fastq_set_ids
924
944
))
925
945
0 commit comments