/
__init__.py
2493 lines (2153 loc) · 119 KB
/
__init__.py
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
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""The application's model objects"""
import os, re
from collections import defaultdict
from datetime import datetime
from sqlalchemy import schema, types, orm, and_, or_
from sqlalchemy.dialects.mysql.base import BIGINT as BigInt
from sqlalchemy.dialects.mysql.base import MSEnum, MSSet
from sqlalchemy.dialects.mysql.base import MEDIUMTEXT as MediumText
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.orm import joinedload_all
from qtools.model.meta import Session, Base
from qtools.lib.bio import reverse_complement, SequenceGroup
# special case
metadata = Base.metadata
def init_model(engine, **kwargs):
"""Call me before using any of the tables or classes in the model"""
Session.configure(bind=engine, autoflush=True, autocommit=False)
def prevent_real_flush(*args, **kwargs):
print 'Attempted write to read-only DB connection.'
return
def init_model_readonly(engine, **kwargs):
Session.configure(bind=engine, autoflush=False, autocommit=False)
Session.flush = prevent_real_flush
def property_attr_wrapper(bind_func='fget', **kwargs):
"""
Creates a getter/setter property derived properties the same column attribute capability
as mapped SQLAlchemy Columns.
:param bind_func: Which function on the property to bind to (default: getter).
If there is no getter on the property, set to 'fset' or 'fdel'.
"""
def wrapper(prop):
func = getattr(prop, bind_func)
for k, v in kwargs.items():
# do not allow override
if hasattr(func, k):
raise ValueError, "Cannot override preexisting function attribute: %s" % k
setattr(func, k, v)
return prop
return wrapper
def now():
return datetime.now()
lot_number_plate_table = schema.Table('lot_number_plate', metadata,
schema.Column('id', types.Integer, schema.Sequence('lot_number_plate_seq_id', optional=True), primary_key=True),
schema.Column('plate_id', types.Integer, schema.ForeignKey('plate.id')),
schema.Column('lot_number_id', types.Integer, schema.ForeignKey('lot_number.id')),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
plate_tag_plate_table = schema.Table('plate_tag_plate', metadata,
schema.Column('id', types.Integer, schema.Sequence('plate_tag_plate_seq_id', optional=True), primary_key=True),
schema.Column('plate_id', types.Integer, schema.ForeignKey('plate.id')),
schema.Column('plate_tag_id', types.Integer, schema.ForeignKey('plate_tag.id')),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
assay_tag_assay_table = schema.Table('assay_tag_assay', metadata,
schema.Column('id', types.Integer, schema.Sequence('assay_tag_assay_seq_id', optional=True), primary_key=True),
schema.Column('assay_id', types.Integer, schema.ForeignKey('assay.id')),
schema.Column('assay_tag_id', types.Integer, schema.ForeignKey('assay_tag.id')),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
analysis_group_plate_table = schema.Table('analysis_group_plate', metadata,
schema.Column('id', types.Integer, schema.Sequence('analysis_group_plate_seq_id', optional=True), primary_key=True),
schema.Column('analysis_group_id', types.Integer, schema.ForeignKey('analysis_group.id')),
schema.Column('plate_id', types.Integer, schema.ForeignKey('plate.id')),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
analysis_group_reprocess_table = schema.Table('analysis_group_reprocess', metadata,
schema.Column('id', types.Integer, schema.Sequence('analysis_group_reprocess_seq_id', optional=True), primary_key=True),
schema.Column('analysis_group_id', types.Integer, schema.ForeignKey('analysis_group.id')),
schema.Column('reprocess_config_id', types.Integer, schema.ForeignKey('reprocess_config.id')),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
class AssayCacheMixin(object):
"""
Declarative mixin for assay caches.
"""
def cached(self, padding_pos5, padding_pos3):
"""
Determine whether the cache object has records for the
specified padding.
"""
return padding_pos5 <= self.seq_padding_pos5 and padding_pos3 <= self.seq_padding_pos3
class PercentAttributeMixin(object):
"""
Declarative mixin for computing the right values for percentages,
when the underlying attribute is absolute.
"""
def percent(self, val):
if val is None:
return None
else:
return val*100
class AssaySampleCNV(Base):
__tablename__ = "assay_sample_cnv"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('assay_sample_cnv_id', optional=True), primary_key=True)
sample_id = schema.Column(types.Integer, schema.ForeignKey('sample.id'), nullable=False)
target_assay_id = schema.Column(types.Integer, schema.ForeignKey('assay.id'), nullable=False)
reference_assay_id = schema.Column(types.Integer, schema.ForeignKey('assay.id'), nullable=True)
cnv = schema.Column(types.Integer, nullable=False, default=1)
source_plate_id = schema.Column(types.Integer, schema.ForeignKey('plate.id'), nullable=True)
source_external_url = schema.Column(types.String(255), nullable=True)
notes = schema.Column(types.UnicodeText(), nullable=True)
author_id = schema.Column(types.Integer, schema.ForeignKey('person.id'), nullable=True)
time_created = schema.Column(types.DateTime, default=now)
class AssayTag(Base):
__tablename__ = "assay_tag"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('assay_tag_seq_id', optional=True), primary_key=True)
name = schema.Column('name', types.Unicode(50), nullable=False)
class Assay(Base):
__tablename__ = 'assay'
__table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}
TYPE_PRIMER = 'primer'
TYPE_LOCATION = 'location'
TYPE_SNP = 'snp'
TYPE_INCOMPLETE = 'incomplete'
id = schema.Column(types.Integer,
schema.Sequence('assay_seq_id', optional=True), primary_key=True)
name = schema.Column(types.Unicode(50), nullable=False, unique=True)
gene = schema.Column(types.Unicode(50), nullable=True)
owner_id = schema.Column(types.Integer, schema.ForeignKey('person.id'), nullable=True)
primer_fwd = schema.Column(types.Unicode(50), nullable=True)
primer_rev = schema.Column(types.Unicode(50), nullable=True)
probe_pos = schema.Column(types.Integer, default=0)
probe_seq = schema.Column(types.Unicode(100), nullable=True)
dye = schema.Column(types.Unicode(10), nullable=True)
quencher = schema.Column(types.Unicode(10), nullable=True)
chromosome = schema.Column(types.Unicode(4), nullable=True)
amplicon_width = schema.Column(types.Integer, default=0)
snp_rsid = schema.Column(types.Unicode(50), nullable=True)
# TODO: this probably should be a many-to-many (hg18 vs hg19 seq; multiple results for rsid)
added = schema.Column(types.DateTime(), default=now)
cached_sequences = orm.relation('HG19AssayCache', backref='assay', cascade='all, delete-orphan')
sample_cnvs = orm.relation('AssaySampleCNV', backref='target_assay', primaryjoin=id == AssaySampleCNV.target_assay_id, cascade='all, delete-orphan')
reference_cnvs = orm.relation('AssaySampleCNV', backref='reference_assay', primaryjoin=id == AssaySampleCNV.reference_assay_id, cascade='all, delete-orphan')
enzyme_concentrations = orm.relation('EnzymeConcentration', backref='assay')
forward_primer_tm = schema.Column(types.Numeric(precision=5, scale=2), nullable=True)
reverse_primer_tm = schema.Column(types.Numeric(precision=5, scale=2), nullable=True)
probe_tm = schema.Column(types.Numeric(precision=5, scale=2), nullable=True)
forward_primer_dG = schema.Column(types.Numeric(precision=5, scale=2), nullable=True)
reverse_primer_dG = schema.Column(types.Numeric(precision=5, scale=2), nullable=True)
probe_dG = schema.Column(types.Numeric(precision=5, scale=2), nullable=True)
secondary_structure = schema.Column(types.Boolean, nullable=True)
notes = schema.Column(types.UnicodeText(), nullable=True)
reference_source = schema.Column(types.String(255), nullable=True)
optimal_anneal_temp = schema.Column(types.Numeric(precision=4, scale=1), nullable=True)
rejected = schema.Column(types.Boolean, default=False, nullable=True)
tags = orm.relation('AssayTag', secondary=assay_tag_assay_table)
# TODO: make this type explicit?
@property
def assay_type(self):
if self.primer_fwd and self.primer_rev is not None:
return Assay.TYPE_PRIMER
elif self.probe_pos and self.chromosome and self.amplicon_width is not None:
return Assay.TYPE_LOCATION
elif self.snp_rsid and self.amplicon_width is not None:
return Assay.TYPE_SNP
else:
return Assay.TYPE_INCOMPLETE
@property
def assay_type_display(self):
return {Assay.TYPE_PRIMER: 'PCR Primer',
Assay.TYPE_LOCATION: 'PCR Probe Location',
Assay.TYPE_SNP: 'PCR SNP Target',
Assay.TYPE_INCOMPLETE: 'Unknown'}[self.assay_type]
@classmethod
def primer_query(cls, session):
return session.query(cls).filter(and_(cls.primer_fwd != None, cls.primer_rev != None))
@classmethod
def location_query(cls, session):
return session.query(cls).filter(and_(cls.primer_fwd == None, cls.chromosome != None, cls.probe_pos != None))
@classmethod
def snp_query(cls, session):
return session.query(cls).filter(and_(cls.snp_rsid != None, cls.amplicon_width != None))
@classmethod
def populated_valid_query(cls, session):
"""
Include assays with some information.
"""
return session.query(cls).filter(and_(or_(cls.primer_fwd != None, cls.chromosome != None, cls.snp_rsid != None), cls.rejected != True))
class Enzyme(Base):
__tablename__ = "enzyme"
__table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}
name = schema.Column(types.Unicode(20), primary_key=True)
cutseq = schema.Column(types.Unicode(50), nullable=True)
methylation_sensitivity = schema.Column(types.String(50), nullable=True)
vendor_specs = orm.relation('VendorEnzyme', backref='enzyme', cascade='all, delete-orphan')
class Vendor(Base):
__tablename__ = "vendor"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer,
schema.Sequence('vendor_seq_id', optional=True), primary_key=True)
name = schema.Column(types.Unicode(50), nullable=False, unique=True)
website = schema.Column(types.Unicode(50))
enzymes = orm.relation('VendorEnzyme', backref='vendor')
# TODO: add additional parameters.
class Buffer(Base):
__tablename__ = "buffer"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer,
schema.Sequence('buffer_seq_id', optional=True), primary_key=True)
name = schema.Column(types.Unicode(50), nullable=False, unique=True)
enzymes = orm.relation('VendorEnzyme', backref='buffer')
# TODO: add additional parameters; add relation to vendor?
class VendorEnzyme(Base):
__tablename__ = "vendor_enzyme"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
BIN_CHEAP_ENZYME = 1
BIN_MEDIUM_ENZYME = 2
BIN_EXPENSIVE_ENZYME = 3
BIN_DISPLAY = {BIN_CHEAP_ENZYME: 'Low',
BIN_MEDIUM_ENZYME: 'Medium',
BIN_EXPENSIVE_ENZYME: 'High'}
id = schema.Column(types.Integer,
schema.Sequence('vendor_enzyme_seq_id', optional=True), primary_key=True)
enzyme_id = schema.Column(types.Unicode(20), schema.ForeignKey('enzyme.name'), nullable=False)
vendor_id = schema.Column(types.Integer, schema.ForeignKey('vendor.id'), nullable=False)
buffer_id = schema.Column(types.Integer, schema.ForeignKey('buffer.id'))
unit_cost_1 = schema.Column(types.Numeric(precision=6, scale=2))
unit_cost_2 = schema.Column(types.Numeric(precision=6, scale=2))
stock_units = schema.Column(types.Integer, default=0)
vendor_serial = schema.Column(types.Unicode(32), nullable=True)
unit_serial_1 = schema.Column(types.Unicode(32), nullable=True)
unit_serial_2 = schema.Column(types.Unicode(32), nullable=True)
@property
def unit_cost_bin(self):
if self.unit_cost_1 < 10:
return self.__class__.BIN_CHEAP_ENZYME
elif self.unit_cost_1 < 50:
return self.__class__.BIN_MEDIUM_ENZYME
else:
return self.__class__.BIN_EXPENSIVE_ENZYME
@classmethod
def unit_cost_bin_gettext(cls, bin):
return cls.BIN_DISPLAY.get(bin, 'Unknown')
@property
def unit_cost_bin_display(self):
return self.__class__.unit_cost_bin_text(self.unit_cost_bin)
class Box2(Base):
__tablename__ = "box2"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
READER_TYPE_WHOLE = 0
READER_TYPE_FLUIDICS_MODULE = 1
READER_TYPE_DETECTOR_MODULE = 2
id = schema.Column(types.Integer, schema.Sequence('box2_seq_id', optional=True), primary_key=True)
name = schema.Column(types.Unicode(20), nullable=False, unique=True)
code = schema.Column(types.Unicode(20), nullable=False, unique=True)
os_name = schema.Column(types.String(40))
src_dir = schema.Column(types.String(255), nullable=True)
status = schema.Column(types.Integer, nullable=True)
status_comment = schema.Column(types.Unicode(140), nullable=True)
active = schema.Column(types.Boolean, nullable=False, default=True)
# real = schema.Column(types.Boolean, nullable=False, default=True) # TODO: also remove column after this propagates
alt_name = schema.Column(types.Unicode(50), nullable=True)
fileroot = schema.Column(types.String(50), nullable=False, default='main')
reader_type = schema.Column(types.Integer, nullable=False, default=0)
dr_group_id = schema.Column(types.Integer, schema.ForeignKey('dr_group.id'), nullable=True)
reference = schema.Column(types.Boolean, default=False, nullable=False)
plates = orm.relation('Plate', backref='box2')
serials = orm.relation('EquipmentSerialBox2', backref='box2')
logs = orm.relation('Box2Log', backref='box2')
files = orm.relation('Box2File', backref='box2', primaryjoin='and_(Box2.id == Box2File.box2_id, Box2File.deleted != True)')
@property
def display_name(self):
if self.alt_name:
return "%s (%s)" % (self.name, self.alt_name)
else:
return self.name
@property
def is_prod(self):
"""
For now...
"""
return self.fileroot in ('prod','site6000')
@staticmethod
def prod_query():
return Box2.fileroot.in_(('prod','site6000'))
@staticmethod
def reader_query():
return and_(Box2.fileroot.in_(('prod','site6000')), Box2.reader_type == Box2.READER_TYPE_WHOLE)
@staticmethod
def lab_query():
return and_(Box2.fileroot.in_(('main','archive')), Box2.reader_type == Box2.READER_TYPE_WHOLE)
@staticmethod
def fluidics_module_query():
return and_(Box2.fileroot.in_(('prod','site6000')), Box2.reader_type == Box2.READER_TYPE_FLUIDICS_MODULE)
@staticmethod
def detector_module_query():
return and_(Box2.fileroot.in_(('prod','site6000')), Box2.reader_type == Box2.READER_TYPE_DETECTOR_MODULE)
@staticmethod
def whole_readers_only_query():
return Box2.reader_type == Box2.READER_TYPE_WHOLE
@staticmethod
def fluidics_modules_only_query():
return Box2.reader_type == Box2.READER_TYPE_FLUIDICS_MODULE
@staticmethod
def detector_modules_only_query():
return Box2.reader_type == Box2.READER_TYPE_DETECTOR_MODULE
class Box2File(Base):
__tablename__ = "box2_file"
__table_args__ = {"mysql_engine": "InnoDB", "mysql_charset": 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('box2_file_seq_id', optional=True), primary_key=True)
box2_id = schema.Column(types.Integer, schema.ForeignKey('box2.id'), nullable=False)
name = schema.Column(types.String(255), nullable=False)
deleted = schema.Column(types.Boolean, default=False)
path = schema.Column(types.String(255), nullable=False)
updated = schema.Column(types.DateTime, nullable=False, default=now)
size = schema.Column(types.Integer, nullable=True)
mime_type = schema.Column(types.String(50), nullable=True)
description = schema.Column(types.UnicodeText, nullable=True)
class DRGroup(Base):
__tablename__ = "dr_group"
__table_args__ = {"mysql_engine": "InnoDB", "mysql_charset": 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('dr_group_seq_id', optional=True), primary_key=True)
name = schema.Column(types.String(255), nullable=False)
active = schema.Column(types.Boolean, nullable=False, default=True)
drs = orm.relation('Box2', backref='dr_group')
class EquipmentSerialBox2(Base):
__tablename__ = "equipment_serial_box2"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('equipment_serial_box2_seq_id', optional=True), primary_key=True)
box2_id = schema.Column(types.Integer, schema.ForeignKey('box2.id'), nullable=False)
equipment_serial = schema.Column(types.String(40), nullable=False)
class Project(Base):
__tablename__ = "project"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('project_seq_id', optional=True), primary_key=True)
name = schema.Column(types.Unicode(100), nullable=False)
code = schema.Column(types.Unicode(20), nullable=True)
description = schema.Column(types.UnicodeText(), nullable=True)
active = schema.Column(types.Boolean, default=True)
plates = orm.relation('Plate', backref='project')
plate_setups = orm.relation('PlateSetup', backref='project')
class Experiment(Base):
__tablename__ = "experiment"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('experiment_seq_id', optional=True), primary_key=True)
name = schema.Column(types.Unicode(100), nullable=False)
code = schema.Column(types.Unicode(20), nullable=True)
description = schema.Column(types.UnicodeText(), nullable=True)
plates = orm.relation('Plate', backref='experiment')
WELL_NAME_RE = re.compile(r'[aAbBcCdDeEfFgGhH](\d\d)')
def __well_name_match(matchobj):
"""
TODO: verify with nick that this may only be at the end of the sample/target name
"""
well_num = int(matchobj.group(1))
if well_num >= 0 and well_num <= 12:
return ''
else:
return matchobj.group(0)
def excise_well_name(str):
return re.sub(WELL_NAME_RE, __well_name_match, str)
class PlateSetup(Base):
__tablename__ = "plate_setup"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('plate_setup_seq_id', optional=True), primary_key=True)
prefix = schema.Column(types.String(72), nullable=True)
name = schema.Column(types.String(40), nullable=False)
setup = schema.Column(MediumText(), nullable=True)
time_updated = schema.Column(types. DateTime(), nullable=True, default=now)
locked = schema.Column(types.Boolean, default=False)
completed = schema.Column(types.Boolean, nullable=True, default=False)
project_id = schema.Column(types.Integer, schema.ForeignKey('project.id'), nullable=True)
author_id = schema.Column(types.Integer, schema.ForeignKey('person.id'), nullable=True)
dr_oil = schema.Column(types.Integer, nullable=True)
dg_oil = schema.Column(types.Integer, nullable=True)
master_mix = schema.Column(types.Integer, nullable=True)
droplet_generation_method = schema.Column(types.Integer, nullable=True)
droplet_generator_id = schema.Column(types.Integer, schema.ForeignKey('droplet_generator.id'), nullable=True)
#dg_used_id = schema.Column(types.Integer, schema.ForeignKey('dg_used.id'), nullable=True)
droplet_generation_time = schema.Column(types.DateTime(), nullable=True)
thermal_cycler_id = schema.Column(types.Integer, schema.ForeignKey('thermal_cycler.id'), nullable=True)
droplet_maker_id = schema.Column(types.Integer, schema.ForeignKey('person.id'), nullable=True)
notes = schema.Column(types.UnicodeText(), nullable=True)
skin_type = schema.Column(types.Integer, nullable=True)
chemistry_type = schema.Column(types.Integer, nullable=True)
donotrun = schema.Column(types.Boolean, nullable=True, default=False)
plate_type_id = schema.Column(types.Integer, schema.ForeignKey('plate_type.id'), nullable=True)
# TODO: should it be a single plate? unless the consumables are still
# tied to the individual plate (and not a batch)
plates = orm.relation('Plate', backref='setup')
plate_type = orm.relation('PlateType')
@property
def chemistry_type_display(self):
return dict(Plate.chemistry_type_display_options()).get(self.chemistry_type, '')
@property
def skin_type_display(self):
return dict(Plate.skin_type_display_options()).get(self.skin_type, '')
class Plate(Base):
__tablename__ = "plate"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
CHEMISTRY_TYPE_TAQMAN = 1
CHEMISTRY_TYPE_GREEN = 2
SKIN_TYPE_SKINNED = 1
SKIN_TYPE_SKINLESS = 2
id = schema.Column(types.Integer, schema.Sequence('plate_seq_id', optional=True), primary_key=True)
name = schema.Column(types.Unicode(255), nullable=False)
type = schema.Column(types.Integer, nullable=False, default=0)
plate_type_id = schema.Column(types.Integer, schema.ForeignKey('plate_type.id'), nullable=True)
description = schema.Column(types.UnicodeText(), nullable=True)
box2_id = schema.Column(types.Integer, schema.ForeignKey('box2.id'), nullable=True)
operator_id = schema.Column(types.Integer, schema.ForeignKey('person.id'), nullable=True)
run_time = schema.Column(types.DateTime(), nullable=True, default=now)
project_id = schema.Column(types.Integer, schema.ForeignKey('project.id'), nullable=True)
experiment_id = schema.Column(types.Integer, schema.ForeignKey('experiment.id'), nullable=True)
score = schema.Column(types.Integer, nullable=True, default=0)
lot_numbers = orm.relation('LotNumber', secondary=lot_number_plate_table)
tags = orm.relation('PlateTag', secondary=plate_tag_plate_table)
qlbplate = orm.relation('QLBPlate', backref='plate', uselist=False)
dr_oil = schema.Column(types.Integer, nullable=True)
dg_oil = schema.Column(types.Integer, nullable=True)
master_mix = schema.Column(types.Integer, nullable=True)
gasket = schema.Column(types.Integer, nullable=True)
droplet_generation_method = schema.Column(types.Integer, nullable=True)
droplet_maker_id = schema.Column(types.Integer, schema.ForeignKey('person.id'), nullable=True)
fluidics_routine = schema.Column(types.Integer, nullable=True)
mfg_exclude = schema.Column(types.Boolean, default=False)
chemistry_type = schema.Column(types.Integer, nullable=True)
skin_type = schema.Column(types.Integer, nullable=True)
# convert these to enums?
dg_used_id = schema.Column(types.Integer, schema.ForeignKey('dg_used.id'), nullable=True)
droplet_generator = schema.Column(types.Integer, nullable=True, default=0)
thermal_cycler = schema.Column(types.Integer, nullable=True, default=0)
program_version = schema.Column(types.Unicode(20), nullable=True)
plate_setup_id = schema.Column(types.Integer, schema.ForeignKey('plate_setup.id'), nullable=True)
physical_plate_id = schema.Column(types.Integer, nullable=True)
onsite = schema.Column(types.Boolean, default=False, nullable=True)
dropship = schema.Column(types.Boolean, default=False, nullable=True)
evidence_cnvs = orm.relation('AssaySampleCNV', backref='plate')
enzyme_concentrations = orm.relation('EnzymeConcentration', backref='plate')
metrics = orm.relation('PlateMetric', backref='plate',cascade='all, delete-orphan')
analysis_groups = orm.relation('AnalysisGroup', secondary=analysis_group_plate_table)
@classmethod
def compute_score(cls, plate):
"""
A plate's "score." The formula is as follows:
1 point for stealth/low event well (< 5000 events)
2 points for normal quality well (5-15k events)
3 points for high quality well (15k+ events)
.5 points for well labeled with target and at least one sample
4 points for distinct sample name
4 points for distinct target name
wrinkle: well name excised from sample/target names.
"""
# Careful. This property will trigger additional queries (it is lazily
# loaded). If you are showing multiple plates at a time, it may be
# a good idea to eagerly load the underlying structure (including
# wells, well channels)
wells = [well for well in plate.qlbplate.wells if well.file_id and well.file_id != -1]
score = 0
score += sum([1 for well in wells if well.event_count < 5000])
score += sum([2 for well in wells if well.event_count >= 5000 and well.event_count < 15000])
score += sum([3 for well in wells if well.event_count >= 15000])
event_score = score
labeled_wells = len([well for well in wells if well.sample_name and len([chan for chan in well.channels if chan.target]) > 0])
distinct_samples = set([excise_well_name(well.sample_name) for well in wells if well.sample_name])
#raise Exception, distinct_samples
distinct_channels = set([tuple([excise_well_name(chan.target) for chan in well.channels if chan.target]) for well in wells])
score += 4*len(distinct_samples)
score += 4*len([channel for channel in distinct_channels if channel])
score += labeled_wells/2
return score
@property
def plate_type_code(self):
if self.plate_type_id:
return self.plate_type.code
else:
return None
@property
def physical_plate_display(self):
# loose FK
if self.physical_plate_id is not None:
pp = Session.query(PhysicalPlate).get(self.physical_plate_id)
if not pp:
return 'Unknown'
else:
return pp.name
@property
def is_auto_validation_plate(self):
return self.plate_type_code == PlateType.AUTO_VALIDATION_CODE
@property
def mfg_record(self):
from qtools.model.batchplate import ManufacturingPlate
mfg_records = Session.query(ManufacturingPlate).filter(or_(ManufacturingPlate.plate_id==self.id,
ManufacturingPlate.secondary_plate_id==self.id)).all()
if mfg_records:
return mfg_records[0]
else:
return None
@property
def is_mfg_qc_plate(self):
mfg_record = self.mfg_record
if mfg_record:
return mfg_record.qc_plate
else:
return False
def original_metrics(self, load_eager=True):
"""
Returns the original plate metrics object (not reprocessed)
If load_eager is True, will return the entire tree (PlateMetric->WellMetric->WellChannelMetric)
"""
return self.metrics_for_reprocess_config_id(reprocess_config_id=None, load_eager=load_eager)
def metrics_for_reprocess_config_id(self, reprocess_config_id=None, load_eager=True):
"""
Returns the plate metrics that were computed using the specified reprocess configuration,
which in turn specifies a signal processing version and set of input algorithms.
If load_eager is True, this will return the entire Tree (PlateMetric->WellMetric->WellChannelMetric)
"""
query = Session.query(PlateMetric).filter(and_(PlateMetric.plate_id == self.id,
PlateMetric.reprocess_config_id == reprocess_config_id))
if load_eager:
query = query.options(joinedload_all(PlateMetric.well_metrics, WellMetric.well_channel_metrics, innerjoin=True))
return query.first()
@classmethod
def chemistry_type_display_options(cls):
return [(Plate.CHEMISTRY_TYPE_TAQMAN, 'TaqMan'),
(Plate.CHEMISTRY_TYPE_GREEN, 'EvaGreen')]
@classmethod
def skin_type_display_options(cls):
return [(Plate.SKIN_TYPE_SKINNED, 'Skinned'),
(Plate.SKIN_TYPE_SKINLESS, 'Skinless')]
@property
def chemistry_type_display(self):
return dict(self.__class__.chemistry_type_display_options()).get(self.chemistry_type, '')
@property
def skin_type_display(self):
return dict(self.__class__.skin_type_display_options()).get(self.skin_type, '')
class PhysicalPlate(Base):
__tablename__ = "physical_plate"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('physical_plate_seq_id', optional=True), primary_key=True)
name = schema.Column(types.String(100), nullable=False)
active = schema.Column(types.Boolean, default=True)
class Person(Base):
__tablename__ = "person"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('person_seq_id', optional=True), primary_key=True)
first_name = schema.Column(types.Unicode(30), nullable=False)
last_name = schema.Column(types.Unicode(30), nullable=False)
name_code = schema.Column(types.Unicode(31), nullable=False, unique=True)
email = schema.Column(types.Unicode(40), nullable=True)
active = schema.Column(types.Boolean, default=True)
plates = orm.relation('Plate', backref='operator', primaryjoin=id == Plate.operator_id)
droplet_plates = orm.relation('Plate', backref='droplet_maker', primaryjoin=id == Plate.droplet_maker_id)
assays = orm.relation('Assay', backref='owner')
samples = orm.relation('Sample', backref='owner')
assay_cnvs = orm.relation('AssaySampleCNV', backref='reporter')
enzyme_concentrations = orm.relation('EnzymeConcentration', backref='reporter')
plate_setups = orm.relation('PlateSetup', backref='author', primaryjoin=id == PlateSetup.author_id)
droplet_plate_setups = orm.relation('PlateSetup', backref='droplet_maker', primaryjoin=id == PlateSetup.droplet_maker_id)
dr_statuses = orm.relation('DRStatusLog', backref='reporter')
dr_fixes = orm.relation('DRFixLog', backref='reporter')
@property
def full_name(self):
return "%s %s" % (self.first_name, self.last_name)
class PlateTemplate(Base):
__tablename__ = 'plate_template'
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('plate_template_seq_id', optional=True), primary_key=True)
prefix = schema.Column(types.String(72), unique=True, nullable=False)
project_id = schema.Column(types.Integer, schema.ForeignKey('project.id'), nullable=True)
operator_id = schema.Column(types.Integer, schema.ForeignKey('person.id'), nullable=True)
dr_oil = schema.Column(types.Integer, nullable=True)
dg_oil = schema.Column(types.Integer, nullable=True)
master_mix = schema.Column(types.Integer, nullable=True)
fluidics_routine = schema.Column(types.Integer, nullable=True)
physical_plate_id = schema.Column(types.Integer, nullable=True)
droplet_generation_method = schema.Column(types.Integer, nullable=True)
droplet_maker_id = schema.Column(types.Integer, schema.ForeignKey('person.id'), nullable=True)
plate_type_id = schema.Column(types.Integer, nullable=True)
created_time = schema.Column(types.DateTime(), default=now)
dg_used_id = schema.Column(types.Integer, schema.ForeignKey('dg_used.id'), nullable=True)
class PlateType(Base):
__tablename__ = 'plate_type'
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
AUTO_VALIDATION_CODE = "av"
id = schema.Column(types.Integer, schema.Sequence('plate_type_seq_id', optional=True), primary_key=True)
name = schema.Column(types.Unicode(30), unique=True, nullable=False)
code = schema.Column(types.Unicode(8), unique=True, nullable=False)
plates = orm.relation('Plate', backref='plate_type')
class PlateTag(Base):
__tablename__ = "plate_tag"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('plate_tag_seq_id', optional=True), primary_key=True)
name = schema.Column(types.Unicode(50), nullable=False)
class WellTag(Base):
__tablename__ = "well_tag"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('well_tag_seq_id', optional=True), primary_key=True)
name = schema.Column(types.Unicode(50), nullable=False)
wells = association_proxy('tag_wells', 'well', creator=lambda w: QLBWellTag(well=w))
class Sample(Base):
__tablename__ = "sample"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('sample_seq_id', optional=True), primary_key=True)
name = schema.Column(types.Unicode(50), unique=True, nullable=False)
source = schema.Column(types.Unicode(255), nullable=True)
ethnicity = schema.Column(types.Unicode(50), nullable=True)
sex = schema.Column(MSEnum('M','F','?'), nullable=True)
notes = schema.Column(types.UnicodeText(), nullable=True)
person_id = schema.Column(types.Integer, schema.ForeignKey('person.id'), nullable=True)
time_created = schema.Column(types.DateTime(), default=now)
assay_cnvs = orm.relation('AssaySampleCNV', backref='sample', cascade='all, delete-orphan')
class LotNumber(Base):
__tablename__ = "lot_number"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('lot_number_seq_id', optional=True), primary_key=True)
# TODO: make this enum instead?
type = schema.Column(types.Integer, nullable=False, default=0)
name = schema.Column(types.Unicode(50), nullable=False)
class HG19AssayCache(Base, AssayCacheMixin):
__tablename__ = "hg19_assay_cache"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('hg19_assay_seq_id', optional=True), primary_key=True)
assay_id = schema.Column(types.Integer, schema.ForeignKey('assay.id'), nullable=False)
chromosome = schema.Column(types.String(4), nullable=False)
start_pos = schema.Column(types.Integer, nullable=False)
end_pos = schema.Column(types.Integer, nullable=False)
seq_padding_pos5 = schema.Column(types.Integer, nullable=False, default=0)
seq_padding_pos3 = schema.Column(types.Integer, nullable=False, default=0)
positive_sequence = schema.Column(types.Text)
negative_sequence = schema.Column(types.Text)
amplicon_tm = schema.Column(types.Numeric(precision=5, scale=2), nullable=True)
amplicon_dG = schema.Column(types.Numeric(precision=5, scale=2), nullable=True)
added = schema.Column(types.DateTime(), default=now)
snps = orm.relation('SNP131AssayCache', backref='sequence', cascade='all, delete-orphan')
@property
def positive_amplicon(self):
return self.cached_seq(0, 0, '+')
@property
def negative_amplicon(self):
return self.cached_seq(0, 0, '-')
@property
def amplicon_length(self):
return (self.end_pos - self.start_pos) + 1
def padding_pos5(self, length, strand='+'):
return self.cached_seq(length, -self.amplicon_length, strand)
def padding_pos3(self, length, strand='+'):
return self.cached_seq(-self.amplicon_length, length, strand)
def cached_seq(self, padding_pos5, padding_pos3, strand='+'):
"""
Returns the cached sequence in the positive strand direction.
@param padding_pos5 The amount of padding (left) in the 5' end
on the positive strand
@param padding_pos3 The amount of padding (right) on the 3' end
on the positive strand
"""
start_idx = self.seq_padding_pos5 - padding_pos5
end_idx = -1*(self.seq_padding_pos3 - padding_pos3) or None # if 0, then None-- pass into idx
if start_idx < 0:
raise ValueError, "Have not yet cached sequence to -%sbp" % padding_pos5
elif end_idx > 0:
raise ValueError, "Have not yet cached sequence to +%sbp" % padding_pos3
if self.negative_sequence:
seq = reverse_complement(self.negative_sequence)
else:
seq = self.positive_sequence
substr = seq[start_idx:end_idx]
if strand == '+':
return substr
else:
return reverse_complement(substr)
class SNP131AssayCache(Base):
__tablename__ = "snp131_assay_cache"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('snp131_assay_seq_id', optional=True), primary_key=True)
sequence_id = schema.Column(types.Integer, schema.ForeignKey('hg19_assay_cache.id'), nullable=False)
bin = schema.Column(types.Integer)
chrom = schema.Column(types.String(31))
chromStart = schema.Column(types.Integer)
chromEnd = schema.Column(types.Integer)
name = schema.Column(types.String(15))
score = schema.Column(types.SmallInteger)
strand = schema.Column(MSEnum('+','-'))
refNCBI = schema.Column(types.Text)
refUCSC = schema.Column(types.Text)
observed = schema.Column(types.String(255))
molType = schema.Column(MSEnum('unknown','genomic','cDNA'))
class_ = schema.Column(MSEnum('unknown','single','in-del','het','microsatellite','named','mixed','mnp','insertion','deletion'))
valid = schema.Column(MSSet('unknown','by-cluster','by-frequency','by-submitter','by-2hit-2allele','by-hapmap','by-1000genomes'))
avHet = schema.Column(types.Float)
avHetSE = schema.Column(types.Float)
func = schema.Column(MSSet("'unknown'","'coding-synon'","'intron'","'coding-synonymy-unknown'","'near-gene-3'","'near-gene-5'","'nonsense'",
"'missense'","'frameshift'","'cds-indel'","'untranslated-3'","'untranslated-5'","'splice-3'","'splice-5'"))
locType = schema.Column(MSEnum('range','exact','between','rangeInsertion','rangeSubstitution','rangeDeletion'))
weight = schema.Column(types.Integer)
added = schema.Column(types.DateTime(), default=now)
def equals(self, other):
"""
not ==, which factors in id (which I did not want to
override for SQLA purposes). But tests basic
mutation equivalence.
"""
if not other or not isinstance(other, self.__class__):
return False
return self.chrom == other.chrom \
and self.chromStart == other.chromStart \
and self.chromEnd == other.chromEnd \
and self.name == other.name \
and self.class_ == other.class_
class SystemVersion(Base):
__tablename__ = "system_version"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('system_version_seq_id', optional=True),primary_key=True)
type = schema.Column(types.String(5), nullable=False)
desc = schema.Column(types.String(100), nullable=False)
#qlbplates = orm.relation('QLBPlate', backref='system_version')
#qlbwells = orm.relation('QLBWell', backref='system_version')
class QLBFile(Base):
__tablename__ = "qlbfile"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
id = schema.Column(types.Integer, schema.Sequence('qlbfile_seq_id', optional=True), primary_key=True)
run_id = schema.Column(types.String(255), nullable=False, unique=True)
dirname = schema.Column(types.String(255), nullable=False)
basename = schema.Column(types.String(255), nullable=False)
type = schema.Column(MSEnum('processed','raw','template','unknown'), nullable=False)
version = schema.Column(types.String(30), nullable=True)
mtime = schema.Column(types.DateTime(), nullable=False)
runtime = schema.Column(types.DateTime(), nullable=True)
read_status = schema.Column(types.Integer(), default=0)
plate = orm.relation('QLBPlate', backref='file', uselist=False, cascade='all, delete-orphan')
well = orm.relation('QLBWell', backref='file', uselist=False, cascade='all')
@property
def path(self):
return os.path.join(self.dirname, self.basename)
@property
def version_tuple(self):
real_version = self.version.split('_')[0]
major = real_version.split('.')[0]
# hack for 01.00
if major == "01":
return (0,0)
else:
# QuantaSoft has added a letter version because they are sadists
parts = [part for part in real_version.split('.')]
if not parts[-1].isdigit():
char = parts[-1][-1]
ver = parts[-1][:-1]
subversion = 1+(ord(char)-ord('A'))
return tuple([int(part) for part in parts[:-1]]+[int(ver), subversion])
else:
return tuple([int(part) for part in parts])
class QLBPlate(Base):
__tablename__ = "qlbplate"
__table_args__ = {"mysql_engine": 'InnoDB', 'mysql_charset': 'utf8'}
DYESET_UNKNOWN = -1
DYESET_FAM_VIC = 0
DYESET_FAM_HEX = 1
DYESET_EVA = 2
ALGORITHM_MAP = defaultdict(lambda: '?', {
'QuantaSoftBeta 0.1.2.0': '0.14',
'QuantaSoftBeta 0.1.3.0': '0.20',
'QuantaSoftBeta 0.1.3.1': '0.20',
'QuantaSoftBeta 0.1.4.0': '0.22',
'QuantaSoftBeta 0.1.4.1': '0.22',
'QuantaSoftBeta 0.1.4.4': '0.24',
'QuantaSoftBeta 0.1.4.5': '0.25',
'QuantaSoftBeta 0.1.4.6': '0.25',
'QuantaSoftBeta 0.1.4.7': '0.25',
'QuantaSoftBeta 0.1.4.8': '0.25',
'QuantaSoftBeta 0.1.4.9': '0.26',
'QuantaSoftBeta 0.1.5.3': '0.27',
'QuantaSoftBeta 0.1.5.5': '0.27',
'QuantaSoft 0.1.8.6': '0.31',
'QuantaSoft 0.1.8.10': '0.31',
'QuantaSoft 0.1.8.12': '0.31',
'QuantaSoft 0.1.8.15': '0.31',
'QuantaSoft 0.2.0.1': '0.31',
'QuantaSoft 0.2.0.2': '0.31',
'QuantaSoft 0.2.0.4': '0.32',
'QuantaSoft 0.2.0.5': '0.32',
'QuantaSoft 0.2.0.6': '0.32',
'QuantaSoft 0.2.0.7': '0.32',
'QuantaSoft 0.2.0.8': '0.32',
'QuantaSoft 0.2.0.9': '0.32',
# try to make this the last hack
'QuantaSoft 0.2.0.12': '0.3332',
'QuantaSoft 0.2.0.15': '0.3332',
'QuantaSoft 0.2.1.0': '0.3332',
'QuantaSoft 0.2.1.1': '0.3332',
'QuantaSoft 0.2.1.5': '0.3332',
'QuantaSoft 0.2.1.6': '0.3332',
'QuantaSoft 0.2.1.7': '0.3332',
'QuantaSoft 0.2.2.0': '0.3433',
'QuantaSoft 0.2.3.0': '0.3434',
'QuantaSoft 0.2.4.0': '0.3434',
'QuantaSoft 0.2.4.2': '0.3435',
'QuantaSoft 0.2.5.0': '0.3436',
'QuantaSoft 0.2.5.7': '0.3436',
'QLPReprocessor 0.2.5.0': '0.3436'
# TODO: add db column for peak, post analysis version (prob per well)
})
id = schema.Column(types.Integer, schema.Sequence('qlbplate_seq_id', optional=True), primary_key=True)
file_id = schema.Column(types.Integer, schema.ForeignKey('qlbfile.id'), nullable=False)
host_datetime = schema.Column(types.DateTime(), nullable=True)
host_machine = schema.Column(types.String(40), nullable=True)
host_software = schema.Column(types.String(40), nullable=True)
host_user = schema.Column(types.String(40), nullable=True)
color_compensation_matrix_11 = schema.Column(types.Numeric(precision=7, scale=4), nullable=True)
color_compensation_matrix_12 = schema.Column(types.Numeric(precision=7, scale=4), nullable=True)
color_compensation_matrix_21 = schema.Column(types.Numeric(precision=7, scale=4), nullable=True)
color_compensation_matrix_22 = schema.Column(types.Numeric(precision=7, scale=4), nullable=True)
equipment_make = schema.Column(types.String(40), nullable=True)
equipment_model = schema.Column(types.String(40), nullable=True)
equipment_serial = schema.Column(types.String(40), nullable=True)
file_desc = schema.Column(types.String(255), nullable=True)
channel_map = schema.Column(types.String(40), nullable=True)
plate_id = schema.Column(types.Integer, schema.ForeignKey('plate.id'), nullable=True)
dyeset = schema.Column(types.Integer, nullable=False, default=DYESET_FAM_VIC)
system_version = schema.Column(types.Integer, schema.ForeignKey('system_version.id'), nullable=True)
plate_holder_id = schema.Column(types.Integer, nullable=True) ## maybe add plateholder table???
wells = orm.relation('QLBWell', backref='plate')
algorithm_wells = orm.relation('AlgorithmWell', backref='plate')
def algorithm_wells_by_version(self, major_version, minor_version):
return [well for well in self.algorithm_wells if well.algorithm_major_version == major_version and well.algorithm_minor_version == minor_version]
@classmethod
def filter_by_host_datetime(cls, query, start_time, end_time):
return query.filter(and_(cls.host_datetime >= start_time, cls.host_datetime <= end_time))
@property
def well_name_map(self):
return dict([(well.well_name, well) for well in self.wells])
@property
def quantitation_algorithm(self):
# TODO: defer to plate/store on read
return self.__class__.ALGORITHM_MAP[self.host_software]
@property
def quantitation_algorithm_tuple(self):
alg = self.quantitation_algorithm
if alg != '?':
return tuple([int(tok) for tok in alg.split('.')])
else:
# for now -- hack bugfix; fix in analyzing PyQLB