Newer
Older
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
#' @export
Well <- R6Class(
classname = "Well",
lock_class = TRUE,
public = list(
dbConnection = NULL,
plate_ID = NULL,
position = NULL,
label = NULL,
temperature = NULL,
initialize = function(dbConnection = NA, plate_ID = NA, position = NA,
label = NA, temperature = NA) {
if(!("DBConnection" %in% class(dbConnection))) {
stop("DB connection object required to create Well object")
}
if(is.na(plate_ID) || is.na(position)) { stop("Plate ID and well position required to create Well object") }
if(is.na(label)) { warning("Consider giving a label to new Well object") }
self$dbConnection <- dbConnection
if("Plate" %in% class(plate_ID)) {
plate_ID <- plate_ID$ID
}
self$plate_ID <- plate_ID
self$position <- position
self$label <- label
self$temperature <- temperature
},
print = function() {
cat(paste0(paste0("Plate ID: ", self$plate_ID), "\n",
paste0("Well position: ", self$position), "\n",
paste0("Label: ", self$label), "\n",
paste0("Samples: ", length(self$samples)), "\n",
paste0("Compounds: ", length(self$compounds)), "\n",
paste0("Temperature: ", self$temperature), "\n",
paste0("Quality control: ", length(self$qc)), "\n",
paste0("Phenotypes: ", length(self$phenotypes)), "\n",
paste0("Data files: ", length(self$datafiles)), "\n"))
},
store = function() {
wh <- WellHandle$new(self$dbConnection)
status <- wh$store(list(self))
}
),
private = list(
sample_list = NULL,
compound_list = NULL,
qc_list = NULL,
datafile_list = NULL,
phenotype_list = NULL
),
active = list(
samples = function(s) {
if(missing(s)) {
if(length(private$sample_list) == 0) {
sh <- SampleHandle$new(self$dbConnection)
private$sample_list <- sh$get_all_by_well(self)
}
return(private$sample_list)
} else {
for(item in s) {
if(!("Sample" %in% class(item))) {
stop("Well samples must be Sample objects.")
}
}
private$sample_list <- s
}
},
compounds = function(c) {
if(missing(c)) {
if(length(private$compound_list) == 0) {
ch <- CompoundHandle$new(self$dbConnection)
private$compound_list <- ch$get_all_by_well(self)
}
return(private$compound_list)
} else {
for(item in c) {
if(!("Compound" %in% class(item))) {
stop("Well compounds must be Compound objects.")
}
}
private$compound_list <- c
}
},
qc = function(qctrl) {
qh <- QCHandle$new(self$dbConnection)
if(missing(qctrl)) {
if(length(private$qc_list) == 0) {
private$qc_list <- qh$get_all_by_well(self)
}
return(private$qc_list)
} else {
for(item in qctrl) {
if(!("QC" %in% class(item))) {
stop("Well qc must be QC objects.")
}
}
private$qc_list <- qctrl
}
},
datafiles = function(d) {
if(missing(d)) {
if(length(private$datafile_list) == 0) {
dh <- DatafileHandle$new(self$dbConnection)
private$datafile_list <- dh$get_all_by_well(self)
}
return(private$datafile_list)
} else {
for(item in d) {
if(!("Datafile" %in% class(item))) {
stop("Well datafiles must be Datafile objects.")
}
}
private$datafile_list <- d
}
},
phenotypes = function(p) {
if(missing(p)) {
if(length(private$phenotype_list) == 0) {
ph <- PhenotypeHandle$new(self$dbConnection)
private$phenotype_list <- ph$get_all_by_well(self)
}
return(private$phenotype_list)
} else {
for(item in p) {
if(!("Phenotype" %in% class(item))) {
stop("Well phenotypes must be Phenotype objects.")
}
}
private$phenotype_list <- p
}
}
)
)