Skip to content

Commit 91ed294

Browse files
d-j-hattonstephen-riggsKoldstream
authored
Align column names with ISPyB where relevant (#750)
This is to facilitate easier use of tools designed to collect data from ISPyB. For minimal code changes we use column name alises --------- Co-authored-by: Stephen Riggs <122790971+stephen-riggs@users.noreply.github.com> Co-authored-by: George <43497768+Koldstream@users.noreply.github.com> Co-authored-by: yxd92326 <stephen.riggs@diamond.ac.uk>
1 parent 5c3f1a6 commit 91ed294

1 file changed

Lines changed: 116 additions & 41 deletions

File tree

src/murfey/util/db.py

Lines changed: 116 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@ class CLEMImageSeries(SQLModel, table=True): # type: ignore
256256
data_collection_group: Optional["DataCollectionGroup"] = Relationship(
257257
back_populates="clem_image_series"
258258
)
259-
dcg_id: Optional[int] = Field(foreign_key="datacollectiongroup.id", default=None)
259+
dcg_id: Optional[int] = Field(
260+
foreign_key="datacollectiongroup.dataCollectionGroupId", default=None
261+
)
260262
dcg_name: Optional[str] = Field(default=None)
261263

262264
# Link to grid squares
@@ -415,7 +417,12 @@ class Tilt(SQLModel, table=True): # type: ignore
415417

416418

417419
class DataCollectionGroup(SQLModel, table=True): # type: ignore
418-
id: int = Field(primary_key=True, unique=True)
420+
id: int = Field(
421+
primary_key=True,
422+
unique=True,
423+
alias="dataCollectionGroupId",
424+
sa_column_kwargs={"name": "dataCollectionGroupId"},
425+
)
419426
session_id: int = Field(foreign_key="session.id", primary_key=True)
420427
tag: str = Field(primary_key=True)
421428
atlas_id: Optional[int] = None
@@ -453,7 +460,7 @@ class DataCollectionGroup(SQLModel, table=True): # type: ignore
453460

454461
class NotificationParameter(SQLModel, table=True): # type: ignore
455462
id: Optional[int] = Field(default=None, primary_key=True)
456-
dcg_id: int = Field(foreign_key="datacollectiongroup.id")
463+
dcg_id: int = Field(foreign_key="datacollectiongroup.dataCollectionGroupId")
457464
name: str
458465
min_value: float
459466
max_value: float
@@ -479,9 +486,18 @@ class NotificationValue(SQLModel, table=True): # type: ignore
479486

480487

481488
class DataCollection(SQLModel, table=True): # type: ignore
482-
id: int = Field(primary_key=True, unique=True)
489+
id: int = Field(
490+
primary_key=True,
491+
unique=True,
492+
alias="dataCollectionId",
493+
sa_column_kwargs={"name": "dataCollectionId"},
494+
)
483495
tag: str = Field(primary_key=True)
484-
dcg_id: int = Field(foreign_key="datacollectiongroup.id")
496+
dcg_id: int = Field(
497+
foreign_key="datacollectiongroup.dataCollectionGroupId",
498+
alias="dataCollectionGroupId",
499+
sa_column_kwargs={"name": "dataCollectionGroupId"},
500+
)
485501
data_collection_group: Optional[DataCollectionGroup] = Relationship(
486502
back_populates="data_collections"
487503
)
@@ -500,9 +516,18 @@ class DataCollection(SQLModel, table=True): # type: ignore
500516

501517

502518
class ProcessingJob(SQLModel, table=True): # type: ignore
503-
id: int = Field(primary_key=True, unique=True)
519+
id: int = Field(
520+
primary_key=True,
521+
unique=True,
522+
alias="processingJobId",
523+
sa_column_kwargs={"name": "processingJobId"},
524+
)
504525
recipe: str = Field(primary_key=True)
505-
dc_id: int = Field(foreign_key="datacollection.id")
526+
dc_id: int = Field(
527+
foreign_key="datacollection.dataCollectionId",
528+
alias="dataCollectionId",
529+
sa_column_kwargs={"name": "dataCollectionId"},
530+
)
506531
data_collection: Optional[DataCollection] = Relationship(
507532
back_populates="processing_jobs"
508533
)
@@ -567,14 +592,16 @@ class PreprocessStash(SQLModel, table=True): # type: ignore
567592
class SelectionStash(SQLModel, table=True): # type: ignore
568593
id: Optional[int] = Field(default=None, primary_key=True)
569594
class_selection_score: float
570-
pj_id: int = Field(foreign_key="processingjob.id")
595+
pj_id: int = Field(foreign_key="processingjob.processingJobId")
571596
processing_job: Optional[ProcessingJob] = Relationship(
572597
back_populates="selection_stash"
573598
)
574599

575600

576601
class TomographyProcessingParameters(SQLModel, table=True): # type: ignore
577-
dcg_id: int = Field(primary_key=True, foreign_key="datacollectiongroup.id")
602+
dcg_id: int = Field(
603+
primary_key=True, foreign_key="datacollectiongroup.dataCollectionGroupId"
604+
)
578605
pixel_size: float
579606
dose_per_frame: float
580607
frame_count: int
@@ -590,8 +617,17 @@ class TomographyProcessingParameters(SQLModel, table=True): # type: ignore
590617

591618

592619
class AutoProcProgram(SQLModel, table=True): # type: ignore
593-
id: int = Field(primary_key=True, unique=True)
594-
pj_id: int = Field(foreign_key="processingjob.id")
620+
id: int = Field(
621+
primary_key=True,
622+
unique=True,
623+
alias="autoProcProgramId",
624+
sa_column_kwargs={"name": "autoProcProgramId"},
625+
)
626+
pj_id: int = Field(
627+
foreign_key="processingjob.processingJobId",
628+
alias="processingJobId",
629+
sa_column_kwargs={"name": "processingJobId"},
630+
)
595631
processing_job: Optional[ProcessingJob] = Relationship(
596632
back_populates="auto_proc_programs"
597633
)
@@ -618,7 +654,7 @@ class AutoProcProgram(SQLModel, table=True): # type: ignore
618654

619655
class MurfeyLedger(SQLModel, table=True): # type: ignore
620656
id: Optional[int] = Field(primary_key=True, default=None)
621-
app_id: int = Field(foreign_key="autoprocprogram.id")
657+
app_id: int = Field(foreign_key="autoprocprogram.autoProcProgramId")
622658
auto_proc_program: Optional[AutoProcProgram] = Relationship(
623659
back_populates="murfey_ids"
624660
)
@@ -672,7 +708,9 @@ class GridSquare(SQLModel, table=True): # type: ignore
672708
foil_holes: List["FoilHole"] = Relationship(
673709
back_populates="grid_square", sa_relationship_kwargs={"cascade": "delete"}
674710
)
675-
atlas_id: Optional[int] = Field(foreign_key="datacollectiongroup.id")
711+
atlas_id: Optional[int] = Field(
712+
foreign_key="datacollectiongroup.dataCollectionGroupId"
713+
)
676714
scaled_pixel_size: Optional[float] = None
677715
pixel_location_x: Optional[int] = None
678716
pixel_location_y: Optional[int] = None
@@ -745,7 +783,9 @@ class SearchMap(SQLModel, table=True): # type: ignore
745783
tilt_series: List["TiltSeries"] = Relationship(
746784
back_populates="search_map", sa_relationship_kwargs={"cascade": "delete"}
747785
)
748-
atlas_id: Optional[int] = Field(foreign_key="datacollectiongroup.id")
786+
atlas_id: Optional[int] = Field(
787+
foreign_key="datacollectiongroup.dataCollectionGroupId"
788+
)
749789
scaled_pixel_size: Optional[float] = None
750790
pixel_location_x: Optional[int] = None
751791
pixel_location_y: Optional[int] = None
@@ -760,13 +800,36 @@ class SearchMap(SQLModel, table=True): # type: ignore
760800

761801

762802
class Movie(SQLModel, table=True): # type: ignore
763-
murfey_id: int = Field(primary_key=True, foreign_key="murfeyledger.id")
764-
data_collection_id: Optional[int] = Field(foreign_key="datacollection.id")
803+
murfey_id: int = Field(
804+
primary_key=True,
805+
foreign_key="murfeyledger.id",
806+
alias="movieId",
807+
sa_column_kwargs={"name": "movieId"},
808+
)
809+
data_collection_id: Optional[int] = Field(
810+
foreign_key="datacollection.dataCollectionId",
811+
alias="dataCollectionId",
812+
sa_column_kwargs={"name": "dataCollectionId"},
813+
)
765814
foil_hole_id: int = Field(foreign_key="foilhole.id", nullable=True, default=None)
766-
path: str
767-
image_number: int
815+
image_number: int = Field(
816+
alias="movieNumber", sa_column_kwargs={"name": "movieNumber"}
817+
)
818+
path: str = Field(alias="imageFullPath", sa_column_kwargs={"name": "imageFullPath"})
819+
creation_time: datetime = Field(
820+
alias="createdTimeStamp",
821+
sa_column_kwargs={"name": "createdTimeStamp"},
822+
default_factory=datetime.now,
823+
)
768824
tag: str
769825
preprocessed: bool = False
826+
positionX: Optional[float] = None
827+
positionY: Optional[float] = None
828+
nominalDefocus: Optional[float] = None
829+
angle: Optional[float] = None
830+
fluence: Optional[float] = None
831+
numberOfFrames: Optional[int] = None
832+
templateLabel: Optional[str] = None
770833
murfey_ledger: Optional[MurfeyLedger] = Relationship(back_populates="movies")
771834
data_collection: Optional["DataCollection"] = Relationship(back_populates="movies")
772835
foil_hole: Optional[FoilHole] = Relationship(back_populates="movies")
@@ -780,7 +843,7 @@ class Movie(SQLModel, table=True): # type: ignore
780843

781844
class CtfParameters(SQLModel, table=True): # type: ignore
782845
id: Optional[int] = Field(default=None, primary_key=True)
783-
pj_id: int = Field(foreign_key="processingjob.id")
846+
pj_id: int = Field(foreign_key="processingjob.processingJobId")
784847
micrographs_file: str
785848
coord_list_file: str
786849
extract_file: str
@@ -797,7 +860,7 @@ class CtfParameters(SQLModel, table=True): # type: ignore
797860

798861
class TomogramPicks(SQLModel, table=True): # type: ignore
799862
tomogram: str = Field(primary_key=True)
800-
pj_id: int = Field(foreign_key="processingjob.id")
863+
pj_id: int = Field(foreign_key="processingjob.processingJobId")
801864
cbox_3d: str
802865
particle_count: int
803866
tomogram_pixel_size: float
@@ -808,15 +871,15 @@ class TomogramPicks(SQLModel, table=True): # type: ignore
808871

809872
class ParticleSizes(SQLModel, table=True): # type: ignore
810873
id: Optional[int] = Field(default=None, primary_key=True)
811-
pj_id: int = Field(foreign_key="processingjob.id")
874+
pj_id: int = Field(foreign_key="processingjob.processingJobId")
812875
particle_size: float
813876
processing_job: Optional[ProcessingJob] = Relationship(
814877
back_populates="particle_sizes"
815878
)
816879

817880

818881
class SPARelionParameters(SQLModel, table=True): # type: ignore
819-
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
882+
pj_id: int = Field(primary_key=True, foreign_key="processingjob.processingJobId")
820883
angpix: float
821884
dose_per_frame: float
822885
gain_ref: Optional[str]
@@ -836,7 +899,7 @@ class SPARelionParameters(SQLModel, table=True): # type: ignore
836899

837900

838901
class ClassificationFeedbackParameters(SQLModel, table=True): # type: ignore
839-
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
902+
pj_id: int = Field(primary_key=True, foreign_key="processingjob.processingJobId")
840903
estimate_particle_diameter: bool = True
841904
hold_class2d: bool = False
842905
rerun_class2d: bool = False
@@ -858,7 +921,7 @@ class ClassificationFeedbackParameters(SQLModel, table=True): # type: ignore
858921

859922
class Class2DParameters(SQLModel, table=True): # type: ignore
860923
particles_file: str = Field(primary_key=True)
861-
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
924+
pj_id: int = Field(primary_key=True, foreign_key="processingjob.processingJobId")
862925
murfey_id: int = Field(foreign_key="murfeyledger.id")
863926
class2d_dir: str
864927
batch_size: int
@@ -876,15 +939,15 @@ class Class2D(SQLModel, table=True): # type: ignore
876939
particles_file: str = Field(
877940
primary_key=True,
878941
)
879-
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
942+
pj_id: int = Field(primary_key=True, foreign_key="processingjob.processingJobId")
880943
murfey_id: int = Field(foreign_key="murfeyledger.id")
881944
processing_job: Optional[ProcessingJob] = Relationship(back_populates="class2ds")
882945
murfey_ledger: Optional[MurfeyLedger] = Relationship(back_populates="class2ds")
883946

884947

885948
class Class3DParameters(SQLModel, table=True): # type: ignore
886949
particles_file: str = Field(primary_key=True)
887-
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
950+
pj_id: int = Field(primary_key=True, foreign_key="processingjob.processingJobId")
888951
murfey_id: int = Field(foreign_key="murfeyledger.id")
889952
class3d_dir: str
890953
batch_size: int
@@ -904,7 +967,7 @@ class Class3DParameters(SQLModel, table=True): # type: ignore
904967
class Class3D(SQLModel, table=True): # type: ignore
905968
class_number: int = Field(primary_key=True)
906969
particles_file: str = Field(primary_key=True)
907-
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
970+
pj_id: int = Field(primary_key=True, foreign_key="processingjob.processingJobId")
908971
murfey_id: int = Field(foreign_key="murfeyledger.id")
909972
# class3d_parameters: Optional[Class3DParameters] = Relationship(
910973
# back_populates="class3ds"
@@ -916,7 +979,7 @@ class Class3D(SQLModel, table=True): # type: ignore
916979
class RefineParameters(SQLModel, table=True): # type: ignore
917980
tag: str = Field(primary_key=True)
918981
refine_dir: str = Field(primary_key=True)
919-
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
982+
pj_id: int = Field(primary_key=True, foreign_key="processingjob.processingJobId")
920983
murfey_id: int = Field(foreign_key="murfeyledger.id")
921984
class3d_dir: str
922985
class_number: int
@@ -932,15 +995,15 @@ class RefineParameters(SQLModel, table=True): # type: ignore
932995
class Refine3D(SQLModel, table=True): # type: ignore
933996
tag: str = Field(primary_key=True)
934997
refine_dir: str = Field(primary_key=True)
935-
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
998+
pj_id: int = Field(primary_key=True, foreign_key="processingjob.processingJobId")
936999
murfey_id: int = Field(foreign_key="murfeyledger.id")
9371000
processing_job: Optional[ProcessingJob] = Relationship(back_populates="refine3ds")
9381001
murfey_ledger: Optional[MurfeyLedger] = Relationship(back_populates="refine3ds")
9391002

9401003

9411004
class BFactorParameters(SQLModel, table=True): # type: ignore
9421005
project_dir: str = Field(primary_key=True)
943-
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
1006+
pj_id: int = Field(primary_key=True, foreign_key="processingjob.processingJobId")
9441007
batch_size: int
9451008
refined_grp_uuid: int
9461009
refined_class_uuid: int
@@ -952,15 +1015,19 @@ class BFactorParameters(SQLModel, table=True): # type: ignore
9521015

9531016
class BFactors(SQLModel, table=True): # type: ignore
9541017
bfactor_directory: str = Field(primary_key=True)
955-
pj_id: int = Field(primary_key=True, foreign_key="processingjob.id")
1018+
pj_id: int = Field(primary_key=True, foreign_key="processingjob.processingJobId")
9561019
number_of_particles: int
9571020
resolution: float
9581021

9591022

9601023
class MotionCorrection(SQLModel, table=True): # type: ignore
9611024
motionCorrectionId: int = Field(primary_key=True, unique=True)
962-
dataCollectionId: Optional[int] = Field(foreign_key="datacollection.id")
963-
autoProcProgramId: Optional[int] = Field(foreign_key="autoprocprogram.id")
1025+
dataCollectionId: Optional[int] = Field(
1026+
foreign_key="datacollection.dataCollectionId"
1027+
)
1028+
autoProcProgramId: Optional[int] = Field(
1029+
foreign_key="autoprocprogram.autoProcProgramId"
1030+
)
9641031
imageNumber: Optional[int] = None
9651032
firstFrame: Optional[int] = None
9661033
lastFrame: Optional[int] = None
@@ -976,7 +1043,7 @@ class MotionCorrection(SQLModel, table=True): # type: ignore
9761043
fftFullPath: Optional[str] = None
9771044
fftCorrectedFullPath: Optional[str] = None
9781045
comments: Optional[str] = None
979-
movieId: Optional[int] = Field(foreign_key="movie.murfey_id")
1046+
movieId: Optional[int] = Field(foreign_key="movie.movieId")
9801047
auto_proc_program: Optional["AutoProcProgram"] = Relationship(
9811048
back_populates="motion_correction"
9821049
)
@@ -998,7 +1065,9 @@ class CTF(SQLModel, table=True): # type: ignore
9981065
motionCorrectionId: Optional[int] = Field(
9991066
foreign_key="motioncorrection.motionCorrectionId"
10001067
)
1001-
autoProcProgramId: Optional[int] = Field(foreign_key="autoprocprogram.id")
1068+
autoProcProgramId: Optional[int] = Field(
1069+
foreign_key="autoprocprogram.autoProcProgramId"
1070+
)
10021071
boxSizeX: Optional[float] = None
10031072
boxSizeY: Optional[float] = None
10041073
minResolution: Optional[float] = None
@@ -1021,7 +1090,7 @@ class CTF(SQLModel, table=True): # type: ignore
10211090

10221091
class ParticlePicker(SQLModel, table=True): # type: ignore
10231092
particlePickerId: int = Field(primary_key=True, unique=True)
1024-
programId: Optional[int] = Field(foreign_key="autoprocprogram.id")
1093+
programId: Optional[int] = Field(foreign_key="autoprocprogram.autoProcProgramId")
10251094
firstMotionCorrectionId: Optional[int] = Field(
10261095
foreign_key="motioncorrection.motionCorrectionId"
10271096
)
@@ -1042,8 +1111,12 @@ class ParticlePicker(SQLModel, table=True): # type: ignore
10421111

10431112
class Tomogram(SQLModel, table=True): # type: ignore
10441113
tomogramId: int = Field(primary_key=True, unique=True)
1045-
dataCollectionId: Optional[int] = Field(foreign_key="datacollection.id")
1046-
autoProcProgramId: Optional[int] = Field(foreign_key="autoprocprogram.id")
1114+
dataCollectionId: Optional[int] = Field(
1115+
foreign_key="datacollection.dataCollectionId"
1116+
)
1117+
autoProcProgramId: Optional[int] = Field(
1118+
foreign_key="autoprocprogram.autoProcProgramId"
1119+
)
10471120
volumeFile: Optional[str] = None
10481121
stackFile: Optional[str] = None
10491122
sizeX: Optional[int] = None
@@ -1094,7 +1167,9 @@ class RelativeIceThickness(SQLModel, table=True): # type: ignore
10941167
motionCorrectionId: Optional[int] = Field(
10951168
foreign_key="motioncorrection.motionCorrectionId"
10961169
)
1097-
autoProcProgramId: Optional[int] = Field(foreign_key="autoprocprogram.id")
1170+
autoProcProgramId: Optional[int] = Field(
1171+
foreign_key="autoprocprogram.autoProcProgramId"
1172+
)
10981173
minimum: Optional[float] = None
10991174
q1: Optional[float] = None
11001175
median: Optional[float] = None
@@ -1109,7 +1184,7 @@ class RelativeIceThickness(SQLModel, table=True): # type: ignore
11091184

11101185

11111186
class TiltImageAlignment(SQLModel, table=True): # type: ignore
1112-
movieId: int = Field(foreign_key="movie.murfey_id", primary_key=True)
1187+
movieId: int = Field(foreign_key="movie.movieId", primary_key=True)
11131188
tomogramId: int = Field(foreign_key="tomogram.tomogramId", primary_key=True)
11141189
defocusU: Optional[float] = None
11151190
defocusV: Optional[float] = None
@@ -1129,7 +1204,7 @@ class ParticleClassificationGroup(SQLModel, table=True): # type: ignore
11291204
particlePickerId: Optional[int] = Field(
11301205
foreign_key="particlepicker.particlePickerId"
11311206
)
1132-
programId: Optional[int] = Field(foreign_key="autoprocprogram.id")
1207+
programId: Optional[int] = Field(foreign_key="autoprocprogram.autoProcProgramId")
11331208
type: Optional[str] = Enum("2D", "3D")
11341209
batchNumber: Optional[int] = None
11351210
numberOfParticlesPerBatch: Optional[int] = None

0 commit comments

Comments
 (0)