Browse code

cose strane

Emanuel Soda authored on 13/05/2022 19:25:22
Showing3 changed files

1 1
deleted file mode 100644
... ...
@@ -1,50 +0,0 @@
1
-#' @title Create the ScreenR Object
2
-#' @description Initial function to create the Screen Object.
3
-#' @param table The count table obtained from the read alignment that
4
-#'                    contains the Barcodes as rows and samples as columns.
5
-#' @param annotation The annotation table containing the information
6
-#'                        for each Barcode and the association to the
7
-#'                        corresponding Gene
8
-#' @param groups A factor containing the experimental design label
9
-#' @param replicates A vector containing the replicates label
10
-#' @importFrom rlang .data
11
-#' @importFrom methods new
12
-#' @concept objects
13
-#' @return An object containing all the needed information for the analysis.
14
-#' @export
15
-#' @examples
16
-#' count_table <-
17
-#'     data.frame(
18
-#'         Barcode = c("Code_1", "Code_2", "Code_3", "Code_3"),
19
-#'         Time_3_rep1 = c("3520", "3020", "1507", "1400"),
20
-#'         Time_3_rep2 = c("3500", "3000", "1457", "1490"),
21
-#'         Time_3_TRT_rep1 = c("1200", "1100", "1300", "1350"),
22
-#'         Time_3_TRT_rep2 = c("1250", "1000", "1400", "1375")
23
-#'     )
24
-#' annotation_table <-
25
-#'     data.frame(
26
-#'         Gene = c("Gene_1", "Gene_1", "Code_2", "Code_2"),
27
-#'         Barcode = c("Code_1", "Code_2", "Code_3", "Code_3"),
28
-#'         Gene_ID = rep(NA, 4), Sequence = rep(NA, 4),
29
-#'         Library = rep(NA, 4)
30
-#'     )
31
-#'
32
-#' groups <- factor(c("Control", "Control", "Treated", "Treated"))
33
-#' obj <- create_screenr_object(
34
-#'     table = count_table,
35
-#'     annotation = annotation_table,
36
-#'     groups = groups, replicates = c("")
37
-#' )
38
-#' obj
39
-create_screenr_object <- function(table = NULL, annotation = NULL,
40
-    groups = NULL, replicates = c("")) {
41
-    # arcode <- as.factor(table$Barcode)
42
-    annotation$Barcode <- as.factor(annotation$Barcode)
43
-    object <- methods::new("screenr_object",
44
-        count_table = tibble(table),
45
-        annotation_table = tibble(annotation), groups = groups,
46
-        replicates = replicates, normalized_count_table = tibble(),
47
-        data_table = tibble()
48
-    )
49
-    return(object)
50
-}
51 0
deleted file mode 100644
... ...
@@ -1,33 +0,0 @@
1
-#' @title Plot distribution Z-score
2
-#' @description This function plots the Log2FC Z-score distribution of the
3
-#'              treated vs control in the different time points.
4
-#'
5
-#' @param time_point_measure A list containing the table for each time
6
-#'                           point. Each table contains for each barcode
7
-#'                           the counts for the treated and control the Log2FC,
8
-#'                           Zscore, ZscoreRobust, Day.
9
-#'
10
-#' @param alpha A value for the opacity of the plot.
11
-#'              Allowed values are in the range 0 to 1
12
-#' @importFrom rlang .data
13
-#' @return return the density plot of the distribution of the Z-score
14
-#' @export
15
-#' @examples
16
-#' object <- get0("object", envir = asNamespace("ScreenR"))
17
-#'
18
-#' table1 <- compute_metrics(object,
19
-#'     control = "TRT", treatment = "Time3",
20
-#'     day = "Time3"
21
-#' )
22
-#'
23
-#' table2 <- compute_metrics(object,
24
-#'     control = "TRT", treatment = "Time4",
25
-#'     day = "Time4"
26
-#' )
27
-#'
28
-#' plot_zscore_distribution(list(table1, table2), alpha = 0.5)
29
-plot_zscore_distribution <- function(time_point_measure, alpha = 1) {
30
-    dplyr::bind_rows(time_point_measure) %>%
31
-        ggplot(aes(x = .data$Log2FC, fill = .data$Day)) +
32
-        geom_density(alpha = alpha)
33
-}
34 0
deleted file mode 100644
... ...
@@ -1,265 +0,0 @@
1
-#' @include  generics.R
2
-
3
-#' @title S4 ScreenR object class
4
-#' The screenr_object class is the main object of the package, it is passed
5
-#' to a series of function to perform the analysis.
6
-#'
7
-#' @slot count_table It is used to store the count table to perform the
8
-#'                   analysis
9
-#' @slot annotation_table It is used to store the annotation of the shRNA
10
-#' @slot groups It is used to store the vector of treated and untreated
11
-#' @slot replicates It is used to store information about the replicates
12
-#' @slot normalized_count_table It is used to store a normalized version of
13
-#'                              the count table
14
-#' @slot data_table It is used to store a tidy format of the count table
15
-#' @exportClass screenr_object
16
-#' @concept objects
17
-#' @rdname get_count_table
18
-#' @examples
19
-#' data("count_table", package = "ScreenR")
20
-#' data("annotation_table", package = "ScreenR")
21
-#'
22
-#' groups <- factor(c(
23
-#'     "T1/T2", "T1/T2", "Treated", "Treated", "Treated",
24
-#'     "Control", "Control", "Control", "Treated", "Treated",
25
-#'     "Treated", "Control", "Control", "Control"
26
-#' ))
27
-#'
28
-#' obj <- create_screenr_object(
29
-#'     table = count_table,
30
-#'     annotation = annotation_table,
31
-#'     groups = groups,
32
-#'     replicates = c("")
33
-#' )
34
-screenr_object <- setClass("screenr_object", methods::representation(
35
-    count_table = "data.frame",
36
-    annotation_table = "data.frame", groups = "factor", replicates = "vector",
37
-    normalized_count_table = "data.frame", data_table = "data.frame"
38
-))
39
-
40
-
41
-
42
-
43
-# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44
-#                                 S4 methods
45
-# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46
-
47
-#' @rdname get_count_table
48
-#' @aliases get_count_table,screenr_object
49
-#' @export
50
-setMethod(
51
-    f = "get_count_table",
52
-    signature = "screenr_object",
53
-    definition = function(object) {
54
-        if (is.null(object)) {
55
-            stop("The object is not defined!")
56
-        }
57
-        count_table <- slot(object = object, name = "count_table")
58
-        cat(
59
-            "ScreenR count table containing:\n",
60
-            nrow(x = count_table), "rows\n",
61
-            ncol(x = count_table), "columns\n"
62
-        )
63
-        return(count_table)
64
-    }
65
-)
66
-
67
-
68
-#' @rdname get_annotation_table
69
-#' @aliases get_annotation_table,screenr_object
70
-#' @export
71
-setMethod(
72
-    f = "get_annotation_table",
73
-    signature = "screenr_object",
74
-    definition = function(object) {
75
-        if (is.null(object)) {
76
-            stop("The object is not defined!")
77
-        }
78
-        annotation_table <- slot(object = object, name = "annotation_table")
79
-        cat(
80
-            "ScreenR annotation table containing:\n",
81
-            nrow(annotation_table),
82
-            "rows\n",
83
-            ncol(annotation_table),
84
-            "columns\n"
85
-        )
86
-        return(annotation_table)
87
-    }
88
-)
89
-
90
-
91
-#' @export
92
-#' @aliases get_groups,screenr_object
93
-#' @rdname get_groups
94
-setMethod(
95
-    f = "get_groups",
96
-    signature = "screenr_object",
97
-    definition = function(object) {
98
-        if (is.null(object)) {
99
-            stop("The object is not defined!")
100
-        }
101
-        return(slot(object = object, name = "groups"))
102
-    }
103
-)
104
-
105
-
106
-#' @export
107
-#' @aliases get_replicates,screenr_object
108
-#' @rdname get_replicates
109
-setMethod(
110
-    f = "get_replicates",
111
-    signature = "screenr_object",
112
-    definition = function(object) {
113
-        if (is.null(object)) {
114
-            stop("The object is not defined!")
115
-        }
116
-        return(slot(object = object, name = "replicates"))
117
-    }
118
-)
119
-
120
-
121
-#' @export
122
-#' @aliases get_normalized_count_table,screenr_object
123
-#' @rdname get_normalized_count_table
124
-setMethod(
125
-    f = "get_normalized_count_table",
126
-    signature = "screenr_object",
127
-    definition = function(object) {
128
-        if (is.null(object)) {
129
-            stop("The object is not defined!")
130
-        }
131
-        normalized_count_table <-
132
-            slot(object = object, name = "normalized_count_table")
133
-        cat(
134
-            "ScreenR normalized count table containing:\n",
135
-            nrow(x = normalized_count_table), "rows\n",
136
-            ncol(x = normalized_count_table), "columns\n"
137
-        )
138
-        return(normalized_count_table)
139
-    }
140
-)
141
-
142
-
143
-#' @export
144
-#' @aliases get_data_table,screenr_object
145
-#' @rdname get_data_table
146
-setMethod(
147
-    f = "get_data_table",
148
-    signature = "screenr_object",
149
-    definition = function(object) {
150
-        if (is.null(object)) {
151
-            stop("The object is not defined!")
152
-        }
153
-        data_table <-
154
-            slot(object = object, name = "data_table")
155
-        cat(
156
-            "ScreenR normalized data table containing:\n",
157
-            nrow(x = data_table), "rows\n",
158
-            ncol(x = data_table), "columns\n"
159
-        )
160
-        return(data_table)
161
-    }
162
-)
163
-
164
-
165
-#' @export
166
-#' @aliases set_count_table,screenr_object
167
-#' @rdname set_count_table
168
-setMethod(
169
-    f = "set_count_table",
170
-    signature = "screenr_object",
171
-    definition = function(object, count_table) {
172
-        if (is.null(object)) {
173
-            stop("The object is not defined!")
174
-        }
175
-        slot(object = object, name = "count_table") <- count_table
176
-        return(object)
177
-    }
178
-)
179
-
180
-
181
-#' @export
182
-#' @aliases set_annotation_table,screenr_object
183
-#' @rdname set_annotation_table
184
-setMethod(
185
-    f = "set_annotation_table",
186
-    signature = "screenr_object",
187
-    definition = function(object, annotation_table) {
188
-        if (is.null(object)) {
189
-            stop("The object is not defined!")
190
-        }
191
-        slot(object = object, name = "annotation_table") <- annotation_table
192
-        return(object)
193
-    }
194
-)
195
-
196
-
197
-#' @export
198
-#' @aliases set_groups,screenr_object
199
-#' @rdname set_groups
200
-setMethod(
201
-    f = "set_groups",
202
-    signature = "screenr_object",
203
-    definition = function(object, groups) {
204
-        if (is.null(object)) {
205
-            stop("The object is not defined!")
206
-        }
207
-        slot(object = object, name = "groups") <- groups
208
-        return(object)
209
-    }
210
-)
211
-
212
-
213
-
214
-#' @export
215
-#' @aliases set_replicates,screenr_object
216
-#' @rdname set_replicates
217
-setMethod(
218
-    f = "set_replicates",
219
-    signature = "screenr_object",
220
-    definition = function(object, replicates) {
221
-        if (is.null(object)) {
222
-            stop("The object is not defined!")
223
-        }
224
-        slot(object = object, name = "replicates") <- replicates
225
-        return(object)
226
-    }
227
-)
228
-
229
-
230
-#' @export
231
-#' @aliases set_normalized_count_table,screenr_object
232
-#' @rdname set_normalized_count_table
233
-setMethod(
234
-    f = "set_normalized_count_table",
235
-    signature = "screenr_object",
236
-    definition = function(object, normalized_count_table) {
237
-        if (is.null(object)) {
238
-            stop("The object is not defined!")
239
-        }
240
-        slot(
241
-            object = object,
242
-            name = "normalized_count_table"
243
-        ) <- normalized_count_table
244
-        return(object)
245
-    }
246
-)
247
-
248
-
249
-#' @export
250
-#' @aliases set_data_table,screenr_object
251
-#' @rdname set_data_table
252
-setMethod(
253
-    f = "set_data_table",
254
-    signature = "screenr_object",
255
-    definition = function(object, data_table) {
256
-        if (is.null(object)) {
257
-            stop("The object is not defined!")
258
-        }
259
-        slot(
260
-            object = object,
261
-            name = "data_table"
262
-        ) <- data_table
263
-        return(object)
264
-    }
265
-)