-
Notifications
You must be signed in to change notification settings - Fork 1
/
screenr-class.R
268 lines (239 loc) · 6.55 KB
/
screenr-class.R
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
#' @include generics.R
#' @title S4 ScreenR object class
#' The screenr_object class is the main object of the package, it is passed
#' to a series of function to perform the analysis.
#'
#' @slot count_table It is used to store the count table to perform the
#' analysis
#' @slot annotation_table It is used to store the annotation of the shRNA
#' @slot groups It is used to store the vector of treated and untreated
#' @slot replicates It is used to store information about the replicates
#' @slot normalized_count_table It is used to store a normalized version of
#' the count table
#' @slot data_table It is used to store a tidy format of the count table
#' @exportClass screenr_object
#' @concept objects
#' @rdname get_count_table
#' @examples
#' data("count_table", package = "ScreenR")
#' data("annotation_table", package = "ScreenR")
#'
#' groups <- factor(c(
#' "T1/T2", "T1/T2", "Treated", "Treated", "Treated",
#' "Control", "Control", "Control", "Treated", "Treated",
#' "Treated", "Control", "Control", "Control"
#' ))
#'
#' obj <- create_screenr_object(
#' table = count_table,
#' annotation = annotation_table,
#' groups = groups,
#' replicates = c("")
#' )
screenr_object <- setClass("screenr_object", methods::representation(
count_table = "data.frame",
annotation_table = "data.frame",
groups = "factor",
replicates = "vector",
normalized_count_table = "data.frame",
data_table = "data.frame"
))
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# S4 methods
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#' @rdname get_count_table
#' @aliases get_count_table,screenr_object
#' @export
setMethod(
f = "get_count_table",
signature = "screenr_object",
definition = function(object) {
if (is.null(object)) {
stop("The object is not defined!")
}
count_table <- slot(object = object, name = "count_table")
cat(
"ScreenR count table containing:\n",
nrow(x = count_table), "rows\n",
ncol(x = count_table), "columns\n"
)
return(count_table)
}
)
#' @rdname get_annotation_table
#' @aliases get_annotation_table,screenr_object
#' @export
setMethod(
f = "get_annotation_table",
signature = "screenr_object",
definition = function(object) {
if (is.null(object)) {
stop("The object is not defined!")
}
annotation_table <- slot(object = object, name = "annotation_table")
cat(
"ScreenR annotation table containing:\n",
nrow(annotation_table),
"rows\n",
ncol(annotation_table),
"columns\n"
)
return(annotation_table)
}
)
#' @export
#' @aliases get_groups,screenr_object
#' @rdname get_groups
setMethod(
f = "get_groups",
signature = "screenr_object",
definition = function(object) {
if (is.null(object)) {
stop("The object is not defined!")
}
return(slot(object = object, name = "groups"))
}
)
#' @export
#' @aliases get_replicates,screenr_object
#' @rdname get_replicates
setMethod(
f = "get_replicates",
signature = "screenr_object",
definition = function(object) {
if (is.null(object)) {
stop("The object is not defined!")
}
return(slot(object = object, name = "replicates"))
}
)
#' @export
#' @aliases get_normalized_count_table,screenr_object
#' @rdname get_normalized_count_table
setMethod(
f = "get_normalized_count_table",
signature = "screenr_object",
definition = function(object) {
if (is.null(object)) {
stop("The object is not defined!")
}
normalized_count_table <-
slot(object = object, name = "normalized_count_table")
cat(
"ScreenR normalized count table containing:\n",
nrow(x = normalized_count_table), "rows\n",
ncol(x = normalized_count_table), "columns\n"
)
return(normalized_count_table)
}
)
#' @export
#' @aliases get_data_table,screenr_object
#' @rdname get_data_table
setMethod(
f = "get_data_table",
signature = "screenr_object",
definition = function(object) {
if (is.null(object)) {
stop("The object is not defined!")
}
data_table <-
slot(object = object, name = "data_table")
cat(
"ScreenR normalized data table containing:\n",
nrow(x = data_table), "rows\n",
ncol(x = data_table), "columns\n"
)
return(data_table)
}
)
#' @export
#' @aliases set_count_table,screenr_object
#' @rdname set_count_table
setMethod(
f = "set_count_table",
signature = "screenr_object",
definition = function(object, count_table) {
if (is.null(object)) {
stop("The object is not defined!")
}
slot(object = object, name = "count_table") <- count_table
return(object)
}
)
#' @export
#' @aliases set_annotation_table,screenr_object
#' @rdname set_annotation_table
setMethod(
f = "set_annotation_table",
signature = "screenr_object",
definition = function(object, annotation_table) {
if (is.null(object)) {
stop("The object is not defined!")
}
slot(object = object, name = "annotation_table") <- annotation_table
return(object)
}
)
#' @export
#' @aliases set_groups,screenr_object
#' @rdname set_groups
setMethod(
f = "set_groups",
signature = "screenr_object",
definition = function(object, groups) {
if (is.null(object)) {
stop("The object is not defined!")
}
slot(object = object, name = "groups") <- groups
return(object)
}
)
#' @export
#' @aliases set_replicates,screenr_object
#' @rdname set_replicates
setMethod(
f = "set_replicates",
signature = "screenr_object",
definition = function(object, replicates) {
if (is.null(object)) {
stop("The object is not defined!")
}
slot(object = object, name = "replicates") <- replicates
return(object)
}
)
#' @export
#' @aliases set_normalized_count_table,screenr_object
#' @rdname set_normalized_count_table
setMethod(
f = "set_normalized_count_table",
signature = "screenr_object",
definition = function(object, normalized_count_table) {
if (is.null(object)) {
stop("The object is not defined!")
}
slot(
object = object,
name = "normalized_count_table"
) <- normalized_count_table
return(object)
}
)
#' @export
#' @aliases set_data_table,screenr_object
#' @rdname set_data_table
setMethod(
f = "set_data_table",
signature = "screenr_object",
definition = function(object, data_table) {
if (is.null(object)) {
stop("The object is not defined!")
}
slot(
object = object,
name = "data_table"
) <- data_table
return(object)
}
)