-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdb.py
More file actions
979 lines (849 loc) · 35.7 KB
/
Copy pathdb.py
File metadata and controls
979 lines (849 loc) · 35.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
"""
Contains classes that are used to store information on the metadata and status of jobs
of the sessions that Murfey is overseeing, along with the relationships between them.
"""
from datetime import datetime
from typing import TYPE_CHECKING, List, Optional
import sqlalchemy
from sqlmodel import Field, Relationship, SQLModel, create_engine
if TYPE_CHECKING:
from murfey.util.processing_db import (
CTF,
MotionCorrection,
ParticleClassificationGroup,
ParticlePicker,
RelativeIceThickness,
TiltImageAlignment,
Tomogram,
)
"""
GENERAL
"""
mapper_registry = sqlalchemy.orm.registry()
class MurfeyUser(SQLModel, table=True): # type: ignore
username: str = Field(primary_key=True)
hashed_password: str
class MagnificationLookup(SQLModel, table=True): # type: ignore
magnification: int = Field(primary_key=True)
pixel_size: float = Field(primary_key=True)
class ClientEnvironment(SQLModel, table=True): # type: ignore
client_id: Optional[int] = Field(primary_key=True, unique=True)
visit: str = Field(default="")
session_id: Optional[int] = Field(foreign_key="session.id")
connected: bool
class RsyncInstance(SQLModel, table=True): # type: ignore
source: str = Field(primary_key=True)
destination: str = Field(primary_key=True, default="")
session_id: int = Field(foreign_key="session.id", primary_key=True)
tag: str = Field(default="")
files_transferred: int = Field(default=0)
files_counted: int = Field(default=0)
transferring: bool = Field(default=False)
session: Optional["Session"] = Relationship(back_populates="rsync_instances")
class Session(SQLModel, table=True): # type: ignore
id: int = Field(primary_key=True)
name: str
visit: str = Field(default="")
started: bool = Field(default=False)
current_gain_ref: str = Field(default="")
instrument_name: str = Field(default="")
process: bool = Field(default=True)
visit_end_time: Optional[datetime] = Field(default=None)
# CLEM Workflow
# LIF files collected, if any
lif_files: List["CLEMLIFFile"] = Relationship(
back_populates="session",
sa_relationship_kwargs={"cascade": "delete"},
)
# TIFF files collected, if any
tiff_files: List["CLEMTIFFFile"] = Relationship(
back_populates="session",
sa_relationship_kwargs={"cascade": "delete"},
)
# Metadata files generated
metadata_files: List["CLEMImageMetadata"] = Relationship(
back_populates="session", sa_relationship_kwargs={"cascade": "delete"}
)
# Image series associated with this session
image_series: List["CLEMImageSeries"] = Relationship(
back_populates="session",
sa_relationship_kwargs={"cascade": "delete"},
)
# Image stacks associated with this session
image_stacks: List["CLEMImageStack"] = Relationship(
back_populates="session",
sa_relationship_kwargs={"cascade": "delete"},
)
# TEM Workflow
tilt_series: List["TiltSeries"] = Relationship(
back_populates="session", sa_relationship_kwargs={"cascade": "delete"}
)
data_collection_groups: List["DataCollectionGroup"] = Relationship(
back_populates="session", sa_relationship_kwargs={"cascade": "delete"}
)
preprocess_stashes: List["PreprocessStash"] = Relationship(
back_populates="session", sa_relationship_kwargs={"cascade": "delete"}
)
grid_squares: List["GridSquare"] = Relationship(
back_populates="session", sa_relationship_kwargs={"cascade": "delete"}
)
foil_holes: List["FoilHole"] = Relationship(
back_populates="session", sa_relationship_kwargs={"cascade": "delete"}
)
search_maps: List["SearchMap"] = Relationship(
back_populates="session", sa_relationship_kwargs={"cascade": "delete"}
)
rsync_instances: List[RsyncInstance] = Relationship(
back_populates="session", sa_relationship_kwargs={"cascade": "delete"}
)
session_processing_parameters: List["SessionProcessingParameters"] = Relationship(
back_populates="session", sa_relationship_kwargs={"cascade": "delete"}
)
"""
CLEM WORKFLOW
"""
class CLEMLIFFile(SQLModel, table=True): # type: ignore
"""
Database recording the different LIF files acquired during the CLEM session, as
well as the different image series stored within them.
"""
id: Optional[int] = Field(default=None, primary_key=True)
file_path: str = Field(index=True) # Path to LIF file
# The CLEM session this series belongs to
session: Optional["Session"] = Relationship(
back_populates="lif_files"
) # Many to one
session_id: Optional[int] = Field(
foreign_key="session.id",
default=None,
)
master_metadata: Optional[str] = Field(
index=True
) # Path to master metadata generated from LIF file
# Offspring
child_metadata: List["CLEMImageMetadata"] = Relationship(
back_populates="parent_lif",
sa_relationship_kwargs={"cascade": "delete"},
) # One to many
child_series: List["CLEMImageSeries"] = Relationship(
back_populates="parent_lif",
sa_relationship_kwargs={"cascade": "delete"},
) # One to many
child_stacks: List["CLEMImageStack"] = Relationship(
back_populates="parent_lif",
sa_relationship_kwargs={"cascade": "delete"},
) # One to many
class CLEMTIFFFile(SQLModel, table=True): # type: ignore
"""
Database to record each raw TIFF file acquired during a CLEM session, which are
used to create an image stack
"""
id: Optional[int] = Field(default=None, primary_key=True)
file_path: str = Field(index=True) # File path to TIFF file on system
session: Optional["Session"] = Relationship(
back_populates="tiff_files"
) # Many to one
session_id: Optional[int] = Field(
foreign_key="session.id",
default=None,
)
# Metadata associated with this TIFF file
associated_metadata: Optional["CLEMImageMetadata"] = Relationship(
back_populates="associated_tiffs",
) # Many to one
metadata_id: Optional[int] = Field(
foreign_key="clemimagemetadata.id",
default=None,
)
# Image series it contributes to
child_series: Optional["CLEMImageSeries"] = Relationship(
back_populates="parent_tiffs"
) # Many to one
series_id: Optional[int] = Field(
foreign_key="clemimageseries.id",
default=None,
)
# Image stack it contributes to
child_stack: Optional["CLEMImageStack"] = Relationship(
back_populates="parent_tiffs"
) # Many to one
stack_id: Optional[int] = Field(
foreign_key="clemimagestack.id",
default=None,
)
class CLEMImageMetadata(SQLModel, table=True): # type: ignore
id: Optional[int] = Field(default=None, primary_key=True)
file_path: str = Field(index=True) # Full path to metadata file
session: Optional["Session"] = Relationship(back_populates="metadata_files")
session_id: Optional[int] = Field(foreign_key="session.id") # Many to one
# The parent LIF file this metadata originates from, if any
parent_lif: Optional[CLEMLIFFile] = Relationship(
back_populates="child_metadata",
) # Many to one
parent_lif_id: Optional[int] = Field(
foreign_key="clemliffile.id",
default=None,
)
# The TIFF files related to this file
associated_tiffs: List["CLEMTIFFFile"] = Relationship(
back_populates="associated_metadata",
sa_relationship_kwargs={"cascade": "delete"},
) # One to many
# Associated series
associated_series: Optional["CLEMImageSeries"] = Relationship(
back_populates="associated_metadata",
sa_relationship_kwargs={"cascade": "delete"},
) # One to one
# Associated image stacks
associated_stacks: List["CLEMImageStack"] = Relationship(
back_populates="associated_metadata",
sa_relationship_kwargs={"cascade": "delete"},
) # One to many
class CLEMImageSeries(SQLModel, table=True): # type: ignore
"""
Database recording the files and metadata associated with a series, which are to be
processed together as a group. These files could stem from a parent LIF file, or
have been compiled together from individual TIFF files.
"""
id: Optional[int] = Field(default=None, primary_key=True)
series_name: str = Field(
index=True
) # Name of the series, as determined from the metadata
image_search_string: Optional[str] = Field(default=None)
thumbnail_search_string: Optional[str] = Field(default=None)
session: Optional["Session"] = Relationship(
back_populates="image_series"
) # Many to one
session_id: Optional[int] = Field(
foreign_key="session.id", default=None, unique=False
)
# Type of data (atlas/overview or grid square)
data_type: Optional[str] = Field(default=None) # "atlas" or "grid_square"
# Link to data collection group
data_collection_group: Optional["DataCollectionGroup"] = Relationship(
back_populates="clem_image_series"
)
dcg_id: Optional[int] = Field(foreign_key="datacollectiongroup.id", default=None)
dcg_name: Optional[str] = Field(default=None)
# Link to grid squares
grid_square: Optional["GridSquare"] = Relationship(
back_populates="clem_image_series"
)
grid_square_id: Optional[int] = Field(foreign_key="gridsquare.id", default=None)
# The parent LIF file this series originates from, if any
parent_lif: Optional["CLEMLIFFile"] = Relationship(
back_populates="child_series",
) # Many to one
parent_lif_id: Optional[int] = Field(
foreign_key="clemliffile.id",
default=None,
)
# The parent TIFF files used to build up the image stacks in the series, if any
parent_tiffs: List["CLEMTIFFFile"] = Relationship(
back_populates="child_series", sa_relationship_kwargs={"cascade": "delete"}
) # One to many
# Metadata file for this series
associated_metadata: Optional["CLEMImageMetadata"] = Relationship(
back_populates="associated_series",
) # One to one
metadata_id: Optional[int] = Field(
foreign_key="clemimagemetadata.id",
default=None,
)
# Image stack entries that are part of this series
child_stacks: List["CLEMImageStack"] = Relationship(
back_populates="parent_series",
sa_relationship_kwargs={"cascade": "delete"},
) # One to many
number_of_members: Optional[int] = Field(default=None)
# Shape and resolution information
image_pixels_x: Optional[int] = Field(default=None)
image_pixels_y: Optional[int] = Field(default=None)
image_pixel_size: Optional[float] = Field(default=None)
thumbnail_pixels_x: Optional[int] = Field(default=None)
thumbnail_pixels_y: Optional[int] = Field(default=None)
thumbnail_pixel_size: Optional[float] = Field(default=None)
units: Optional[str] = Field(default=None)
# Extent of the imaged area in real space
x0: Optional[float] = Field(default=None)
x1: Optional[float] = Field(default=None)
y0: Optional[float] = Field(default=None)
y1: Optional[float] = Field(default=None)
# Composite images
composite_created: bool = False # Has a composite image been created?
class CLEMImageStack(SQLModel, table=True): # type: ignore
"""
Database to keep track of the processing status of a single image stack.
"""
id: Optional[int] = Field(default=None, primary_key=True)
file_path: str = Field(index=True) # Full path to the file
channel_name: Optional[str] = None # Color associated with stack
session: Optional["Session"] = Relationship(
back_populates="image_stacks"
) # Many to one
session_id: Optional[int] = Field(foreign_key="session.id")
# LIF file this stack originated from
parent_lif: Optional["CLEMLIFFile"] = Relationship(
back_populates="child_stacks",
) # Many to one
parent_lif_id: Optional[int] = Field(foreign_key="clemliffile.id", default=None)
# TIFF files used to build this stack
parent_tiffs: List["CLEMTIFFFile"] = Relationship(
back_populates="child_stack",
sa_relationship_kwargs={"cascade": "delete"},
) # One to many
# Metadata associated with statck
associated_metadata: Optional["CLEMImageMetadata"] = Relationship(
back_populates="associated_stacks",
) # Many to one
metadata_id: Optional[int] = Field(
foreign_key="clemimagemetadata.id",
default=None,
)
# Image series this image stack belongs to
parent_series: Optional["CLEMImageSeries"] = Relationship(
back_populates="child_stacks",
) # Many to one
series_id: Optional[int] = Field(
foreign_key="clemimageseries.id",
default=None,
)
"""
TEM SESSION AND PROCESSING WORKFLOW
"""
class SessionProcessingParameters(SQLModel, table=True): # type: ignore
session_id: int = Field(foreign_key="session.id", primary_key=True)
gain_ref: str
dose_per_frame: float
eer_fractionation: int = 20
eer_fractionation_file: str = ""
symmetry: str = "C1"
run_class3d: bool = True
session: Optional[Session] = Relationship(
back_populates="session_processing_parameters"
)
class TiltSeries(SQLModel, table=True): # type: ignore
id: int = Field(primary_key=True)
ispyb_id: Optional[int] = None
tag: str
rsync_source: str
session_id: int = Field(foreign_key="session.id")
search_map_id: Optional[int] = Field(
foreign_key="searchmap.id",
default=None,
)
tilt_series_length: int = -1
processing_requested: bool = False
x_location: Optional[float] = None
y_location: Optional[float] = None
session: Optional[Session] = Relationship(back_populates="tilt_series")
tilts: List["Tilt"] = Relationship(
back_populates="tilt_series", sa_relationship_kwargs={"cascade": "delete"}
)
search_map: Optional["SearchMap"] = Relationship(back_populates="tilt_series")
class Tilt(SQLModel, table=True): # type: ignore
id: int = Field(primary_key=True)
movie_path: str
tilt_series_id: int = Field(foreign_key="tiltseries.id")
motion_corrected: bool = False
tilt_series: Optional[TiltSeries] = Relationship(back_populates="tilts")
class DataCollectionGroup(SQLModel, table=True): # type: ignore
id: int = Field(primary_key=True, unique=True)
session_id: int = Field(foreign_key="session.id", primary_key=True)
tag: str = Field(primary_key=True)
atlas_id: Optional[int] = None
atlas_pixel_size: Optional[float] = None
atlas: str = ""
sample: Optional[int] = None
session: Optional["Session"] = Relationship(back_populates="data_collection_groups")
data_collections: List["DataCollection"] = Relationship(
back_populates="data_collection_group",
sa_relationship_kwargs={"cascade": "delete"},
)
clem_image_series: List["CLEMImageSeries"] = Relationship(
back_populates="data_collection_group",
sa_relationship_kwargs={"cascade": "delete"},
)
notification_parameters: List["NotificationParameter"] = Relationship(
back_populates="data_collection_group",
sa_relationship_kwargs={"cascade": "delete"},
)
tomography_processing_parameters: List["TomographyProcessingParameters"] = (
Relationship(
back_populates="data_collection_group",
sa_relationship_kwargs={"cascade": "delete"},
)
)
grid_squares: Optional[List["GridSquare"]] = Relationship(
back_populates="data_collection_group",
sa_relationship_kwargs={"cascade": "delete"},
)
search_maps: Optional[List["SearchMap"]] = Relationship(
back_populates="data_collection_group",
sa_relationship_kwargs={"cascade": "delete"},
)
class NotificationParameter(SQLModel, table=True): # type: ignore
id: Optional[int] = Field(default=None, primary_key=True)
dcg_id: int = Field(foreign_key="datacollectiongroup.id")
name: str
min_value: float
max_value: float
num_instances_since_triggered: int = 0
notification_active: bool = False
data_collection_group: Optional[DataCollectionGroup] = Relationship(
back_populates="notification_parameters"
)
notification_values: List["NotificationValue"] = Relationship(
back_populates="notification_parameter",
sa_relationship_kwargs={"cascade": "delete"},
)
class NotificationValue(SQLModel, table=True): # type: ignore
id: Optional[int] = Field(default=None, primary_key=True)
notification_parameter_id: int = Field(foreign_key="notificationparameter.id")
index: int
within_bounds: bool
notification_parameter: Optional[NotificationParameter] = Relationship(
back_populates="notification_values"
)
class DataCollection(SQLModel, table=True): # type: ignore
id: int = Field(primary_key=True, unique=True)
tag: str = Field(primary_key=True)
dcg_id: int = Field(foreign_key="datacollectiongroup.id")
data_collection_group: Optional[DataCollectionGroup] = Relationship(
back_populates="data_collections"
)
processing_jobs: List["ProcessingJob"] = Relationship(
back_populates="data_collection", sa_relationship_kwargs={"cascade": "delete"}
)
movies: List["Movie"] = Relationship(
back_populates="data_collection", sa_relationship_kwargs={"cascade": "delete"}
)
motion_correction: Optional[List["MotionCorrection"]] = Relationship(
back_populates="data_collection"
)
tomogram: Optional[List["Tomogram"]] = Relationship(
back_populates="data_collection"
)
class ProcessingJob(SQLModel, table=True): # type: ignore
id: int = Field(primary_key=True, unique=True)
recipe: str = Field(primary_key=True)
dc_id: int = Field(foreign_key="datacollection.id")
data_collection: Optional[DataCollection] = Relationship(
back_populates="processing_jobs"
)
auto_proc_programs: List["AutoProcProgram"] = Relationship(
back_populates="processing_job", sa_relationship_kwargs={"cascade": "delete"}
)
selection_stash: List["SelectionStash"] = Relationship(
back_populates="processing_job", sa_relationship_kwargs={"cascade": "delete"}
)
particle_sizes: List["ParticleSizes"] = Relationship(
back_populates="processing_job", sa_relationship_kwargs={"cascade": "delete"}
)
spa_parameters: List["SPARelionParameters"] = Relationship(
back_populates="processing_job", sa_relationship_kwargs={"cascade": "delete"}
)
classification_feedback_parameters: List["ClassificationFeedbackParameters"] = (
Relationship(
back_populates="processing_job",
sa_relationship_kwargs={"cascade": "delete"},
)
)
ctf_parameters: List["CtfParameters"] = Relationship(
back_populates="processing_job", sa_relationship_kwargs={"cascade": "delete"}
)
tomogram_picks: List["TomogramPicks"] = Relationship(
back_populates="processing_job", sa_relationship_kwargs={"cascade": "delete"}
)
class2d_parameters: List["Class2DParameters"] = Relationship(
back_populates="processing_job", sa_relationship_kwargs={"cascade": "delete"}
)
class3d_parameters: List["Class3DParameters"] = Relationship(
back_populates="processing_job", sa_relationship_kwargs={"cascade": "delete"}
)
refine_parameters: List["RefineParameters"] = Relationship(
back_populates="processing_job", sa_relationship_kwargs={"cascade": "delete"}
)
class2ds: List["Class2D"] = Relationship(
back_populates="processing_job", sa_relationship_kwargs={"cascade": "delete"}
)
class3ds: List["Class3D"] = Relationship(
back_populates="processing_job", sa_relationship_kwargs={"cascade": "delete"}
)
refine3ds: List["Refine3D"] = Relationship(
back_populates="processing_job", sa_relationship_kwargs={"cascade": "delete"}
)
class PreprocessStash(SQLModel, table=True): # type: ignore
file_path: str = Field(primary_key=True)
tag: str = Field(primary_key=True)
session_id: int = Field(primary_key=True, foreign_key="session.id")
foil_hole_id: Optional[int] = Field(foreign_key="foilhole.id", default=None)
image_number: int
mrc_out: str
eer_fractionation_file: Optional[str]
group_tag: Optional[str]
session: Optional[Session] = Relationship(back_populates="preprocess_stashes")
foil_hole: Optional["FoilHole"] = Relationship(back_populates="preprocess_stashes")
class SelectionStash(SQLModel, table=True): # type: ignore
id: Optional[int] = Field(default=None, primary_key=True)
class_selection_score: float
pj_id: int = Field(foreign_key="processingjob.id")
processing_job: Optional[ProcessingJob] = Relationship(
back_populates="selection_stash"
)
class TomographyProcessingParameters(SQLModel, table=True): # type: ignore
dcg_id: int = Field(primary_key=True, foreign_key="datacollectiongroup.id")
pixel_size: float
dose_per_frame: float
frame_count: int
tilt_axis: float
voltage: int
particle_diameter: Optional[float] = None
eer_fractionation_file: Optional[str] = None
motion_corr_binning: int = 1
gain_ref: Optional[str] = None
data_collection_group: Optional[DataCollectionGroup] = Relationship(
back_populates="tomography_processing_parameters"
)
class AutoProcProgram(SQLModel, table=True): # type: ignore
id: int = Field(primary_key=True, unique=True)
pj_id: int = Field(foreign_key="processingjob.id")
processing_job: Optional[ProcessingJob] = Relationship(
back_populates="auto_proc_programs"
)
murfey_ids: List["MurfeyLedger"] = Relationship(
back_populates="auto_proc_program", sa_relationship_kwargs={"cascade": "delete"}
)
motion_correction: Optional[List["MotionCorrection"]] = Relationship(
back_populates="data_collection"
)
tomogram: Optional[List["Tomogram"]] = Relationship(
back_populates="auto_proc_program"
)
ctf: Optional[List["CTF"]] = Relationship(back_populates="auto_proc_program")
particle_picker: Optional[List["ParticlePicker"]] = Relationship(
back_populates="auto_proc_program"
)
relative_ice_thickness: Optional[List["RelativeIceThickness"]] = Relationship(
back_populates="auto_proc_program"
)
particle_classification_group: Optional[List["ParticleClassificationGroup"]] = (
Relationship(back_populates="auto_proc_program")
)
class MurfeyLedger(SQLModel, table=True): # type: ignore
id: Optional[int] = Field(primary_key=True, default=None)
app_id: int = Field(foreign_key="autoprocprogram.id")
auto_proc_program: Optional[AutoProcProgram] = Relationship(
back_populates="murfey_ids"
)
class2ds: Optional["Class2D"] = Relationship(
back_populates="murfey_ledger", sa_relationship_kwargs={"cascade": "delete"}
)
class3ds: Optional["Class3D"] = Relationship(
back_populates="murfey_ledger", sa_relationship_kwargs={"cascade": "delete"}
)
refine3ds: Optional["Refine3D"] = Relationship(
back_populates="murfey_ledger", sa_relationship_kwargs={"cascade": "delete"}
)
class2d_parameters: Optional["Class2DParameters"] = Relationship(
back_populates="murfey_ledger", sa_relationship_kwargs={"cascade": "delete"}
)
class3d_parameters: Optional["Class3DParameters"] = Relationship(
back_populates="murfey_ledger", sa_relationship_kwargs={"cascade": "delete"}
)
refine_parameters: Optional["RefineParameters"] = Relationship(
back_populates="murfey_ledger", sa_relationship_kwargs={"cascade": "delete"}
)
classification_feedback_parameters: Optional["ClassificationFeedbackParameters"] = (
Relationship(
back_populates="murfey_ledger", sa_relationship_kwargs={"cascade": "delete"}
)
)
movies: Optional["Movie"] = Relationship(
back_populates="murfey_ledger", sa_relationship_kwargs={"cascade": "delete"}
)
class GridSquare(SQLModel, table=True): # type: ignore
id: Optional[int] = Field(primary_key=True, default=None)
session_id: int = Field(foreign_key="session.id")
name: int
tag: str
x_location: Optional[float]
y_location: Optional[float]
x_stage_position: Optional[float]
y_stage_position: Optional[float]
readout_area_x: Optional[int]
readout_area_y: Optional[int]
thumbnail_size_x: Optional[int]
thumbnail_size_y: Optional[int]
pixel_size: Optional[float] = None
image: str = ""
session: Optional[Session] = Relationship(back_populates="grid_squares")
clem_image_series: List["CLEMImageSeries"] = Relationship(
back_populates="grid_square", sa_relationship_kwargs={"cascade": "delete"}
)
foil_holes: List["FoilHole"] = Relationship(
back_populates="grid_square", sa_relationship_kwargs={"cascade": "delete"}
)
atlas_id: Optional[int] = Field(foreign_key="datacollectiongroup.id")
scaled_pixel_size: Optional[float] = None
pixel_location_x: Optional[int] = None
pixel_location_y: Optional[int] = None
height: Optional[int] = None
width: Optional[int] = None
angle: Optional[float] = None
quality_indicator: Optional[float] = None
data_collection_group: Optional["DataCollectionGroup"] = Relationship(
back_populates="grid_squares"
)
class FoilHole(SQLModel, table=True): # type: ignore
id: Optional[int] = Field(primary_key=True, default=None)
grid_square_id: int = Field(foreign_key="gridsquare.id")
session_id: int = Field(foreign_key="session.id")
name: int
x_location: Optional[float]
y_location: Optional[float]
x_stage_position: Optional[float]
y_stage_position: Optional[float]
readout_area_x: Optional[int]
readout_area_y: Optional[int]
thumbnail_size_x: Optional[int]
thumbnail_size_y: Optional[int]
pixel_size: Optional[float] = None
image: str = ""
grid_square: Optional[GridSquare] = Relationship(back_populates="foil_holes")
session: Optional[Session] = Relationship(back_populates="foil_holes")
movies: List["Movie"] = Relationship(
back_populates="foil_hole", sa_relationship_kwargs={"cascade": "delete"}
)
preprocess_stashes: List[PreprocessStash] = Relationship(
back_populates="foil_hole", sa_relationship_kwargs={"cascade": "delete"}
)
scaled_pixel_size: Optional[float] = None
pixel_location_x: Optional[int] = None
pixel_location_y: Optional[int] = None
diameter: Optional[int] = None
quality_indicator: Optional[float] = None
class SearchMap(SQLModel, table=True): # type: ignore
id: Optional[int] = Field(primary_key=True, default=None)
session_id: int = Field(foreign_key="session.id")
name: str
tag: str
x_location: Optional[float] = None
y_location: Optional[float] = None
x_stage_position: Optional[float] = None
y_stage_position: Optional[float] = None
pixel_size: Optional[float] = None
image: str = ""
binning: Optional[float] = None
reference_matrix_m11: Optional[float] = None
reference_matrix_m12: Optional[float] = None
reference_matrix_m21: Optional[float] = None
reference_matrix_m22: Optional[float] = None
stage_correction_m11: Optional[float] = None
stage_correction_m12: Optional[float] = None
stage_correction_m21: Optional[float] = None
stage_correction_m22: Optional[float] = None
image_shift_correction_m11: Optional[float] = None
image_shift_correction_m12: Optional[float] = None
image_shift_correction_m21: Optional[float] = None
image_shift_correction_m22: Optional[float] = None
width: Optional[int] = None
height: Optional[int] = None
session: Optional[Session] = Relationship(back_populates="search_maps")
tilt_series: List["TiltSeries"] = Relationship(
back_populates="search_map", sa_relationship_kwargs={"cascade": "delete"}
)
atlas_id: Optional[int] = Field(foreign_key="datacollectiongroup.id")
scaled_pixel_size: Optional[float] = None
pixel_location_x: Optional[int] = None
pixel_location_y: Optional[int] = None
scaled_height: Optional[int] = None
scaled_width: Optional[int] = None
angle: Optional[float] = None
quality_indicator: Optional[float] = None
data_collection_group: Optional["DataCollectionGroup"] = Relationship(
back_populates="search_maps"
)
tomogram: Optional[List["Tomogram"]] = Relationship(back_populates="search_map")
class Movie(SQLModel, table=True): # type: ignore
murfey_id: int = Field(primary_key=True, foreign_key="murfeyledger.id")
data_collection_id: Optional[int] = Field(foreign_key="datacollection.id")
foil_hole_id: int = Field(foreign_key="foilhole.id", nullable=True, default=None)
path: str
image_number: int
tag: str
preprocessed: bool = False
murfey_ledger: Optional[MurfeyLedger] = Relationship(back_populates="movies")
data_collection: Optional["DataCollection"] = Relationship(back_populates="movies")
foil_hole: Optional[FoilHole] = Relationship(back_populates="movies")
motion_correction: Optional[List["MotionCorrection"]] = Relationship(
back_populates="movie"
)
tilt_image_alignment: Optional[List["TiltImageAlignment"]] = Relationship(
back_populates="movie"
)
class CtfParameters(SQLModel, table=True): # type: ignore
id: Optional[int] = Field(default=None, primary_key=True)
pj_id: int = Field(foreign_key="processingjob.id")
micrographs_file: str
coord_list_file: str
extract_file: str
ctf_image: str
ctf_max_resolution: float
ctf_figure_of_merit: float
defocus_u: float
defocus_v: float
defocus_angle: float
processing_job: Optional[ProcessingJob] = Relationship(
back_populates="ctf_parameters"
)
class TomogramPicks(SQLModel, table=True): # type: ignore
tomogram: str = Field(primary_key=True)
pj_id: int = Field(foreign_key="processingjob.id")
cbox_3d: str
particle_count: int
tomogram_pixel_size: float
processing_job: Optional[ProcessingJob] = Relationship(
back_populates="tomogram_picks"
)
class ParticleSizes(SQLModel, table=True): # type: ignore
id: Optional[int] = Field(default=None, primary_key=True)
pj_id: int = Field(foreign_key="processingjob.id")
particle_size: float
processing_job: Optional[ProcessingJob] = Relationship(
back_populates="particle_sizes"
)
class SPARelionParameters(SQLModel, table=True): # type: ignore
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
angpix: float
dose_per_frame: float
gain_ref: Optional[str]
voltage: int
motion_corr_binning: int
eer_fractionation_file: str = ""
symmetry: str
particle_diameter: Optional[float]
downscale: bool = True
do_icebreaker_jobs: bool = True
boxsize: Optional[int] = 256
small_boxsize: Optional[int] = 64
mask_diameter: Optional[float] = 190
processing_job: Optional[ProcessingJob] = Relationship(
back_populates="spa_parameters"
)
class ClassificationFeedbackParameters(SQLModel, table=True): # type: ignore
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
estimate_particle_diameter: bool = True
hold_class2d: bool = False
rerun_class2d: bool = False
hold_class3d: bool = False
hold_refine: bool = False
class_selection_score: float
star_combination_job: int
initial_model: str
next_job: int
picker_murfey_id: Optional[int] = Field(default=None, foreign_key="murfeyledger.id")
picker_ispyb_id: Optional[int] = None
processing_job: Optional[ProcessingJob] = Relationship(
back_populates="classification_feedback_parameters"
)
murfey_ledger: Optional[MurfeyLedger] = Relationship(
back_populates="classification_feedback_parameters"
)
class Class2DParameters(SQLModel, table=True): # type: ignore
particles_file: str = Field(primary_key=True)
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
murfey_id: int = Field(foreign_key="murfeyledger.id")
class2d_dir: str
batch_size: int
complete: bool = True
processing_job: Optional[ProcessingJob] = Relationship(
back_populates="class2d_parameters"
)
murfey_ledger: Optional[MurfeyLedger] = Relationship(
back_populates="class2d_parameters"
)
class Class2D(SQLModel, table=True): # type: ignore
class_number: int = Field(primary_key=True)
particles_file: str = Field(
primary_key=True,
)
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
murfey_id: int = Field(foreign_key="murfeyledger.id")
processing_job: Optional[ProcessingJob] = Relationship(back_populates="class2ds")
murfey_ledger: Optional[MurfeyLedger] = Relationship(back_populates="class2ds")
class Class3DParameters(SQLModel, table=True): # type: ignore
particles_file: str = Field(primary_key=True)
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
murfey_id: int = Field(foreign_key="murfeyledger.id")
class3d_dir: str
batch_size: int
run: bool = False
processing_job: Optional[ProcessingJob] = Relationship(
back_populates="class3d_parameters"
)
murfey_ledger: Optional[MurfeyLedger] = Relationship(
back_populates="class3d_parameters"
)
# class3ds: List["Class3D"] = Relationship(
# back_populates="class3d_parameters",
# sa_relationship_kwargs={"cascade": "delete"},
# )
class Class3D(SQLModel, table=True): # type: ignore
class_number: int = Field(primary_key=True)
particles_file: str = Field(primary_key=True)
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
murfey_id: int = Field(foreign_key="murfeyledger.id")
# class3d_parameters: Optional[Class3DParameters] = Relationship(
# back_populates="class3ds"
# )
processing_job: Optional[ProcessingJob] = Relationship(back_populates="class3ds")
murfey_ledger: Optional[MurfeyLedger] = Relationship(back_populates="class3ds")
class RefineParameters(SQLModel, table=True): # type: ignore
tag: str = Field(primary_key=True)
refine_dir: str = Field(primary_key=True)
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
murfey_id: int = Field(foreign_key="murfeyledger.id")
class3d_dir: str
class_number: int
run: bool = False
processing_job: Optional[ProcessingJob] = Relationship(
back_populates="refine_parameters"
)
murfey_ledger: Optional[MurfeyLedger] = Relationship(
back_populates="refine_parameters"
)
class Refine3D(SQLModel, table=True): # type: ignore
tag: str = Field(primary_key=True)
refine_dir: str = Field(primary_key=True)
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
murfey_id: int = Field(foreign_key="murfeyledger.id")
processing_job: Optional[ProcessingJob] = Relationship(back_populates="refine3ds")
murfey_ledger: Optional[MurfeyLedger] = Relationship(back_populates="refine3ds")
class BFactorParameters(SQLModel, table=True): # type: ignore
project_dir: str = Field(primary_key=True)
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
batch_size: int
refined_grp_uuid: int
refined_class_uuid: int
class_reference: str
class_number: int
mask_file: str
run: bool = True
class BFactors(SQLModel, table=True): # type: ignore
bfactor_directory: str = Field(primary_key=True)
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
number_of_particles: int
resolution: float
"""
FUNCTIONS
"""
def setup(url: str):
engine = create_engine(url)
SQLModel.metadata.create_all(engine)
def clear(url: str):
engine = create_engine(url)
metadata = sqlalchemy.MetaData()
metadata.create_all(engine)
metadata.reflect(engine)
metadata.drop_all(engine)