Browse code

to lowercase

Emanuel Soda authored on 13/05/2022 18:21:12
Showing10 changed files

... ...
@@ -58,7 +58,7 @@ Collate:
58 58
     'compute_metrics.R'
59 59
     'count_mapped_reads.R'
60 60
     'count_table.R'
61
-    'create_edger_obj.R'
61
+    'create_screenr_obj.R'
62 62
     'create_screenr_object.R'
63 63
     'distribution_mapped_reads.R'
64 64
     'filter_by.R'
65 65
deleted file mode 100644
... ...
@@ -1,31 +0,0 @@
1
-#' @title Create edgeR Object
2
-#' @description Utility function that using the screenr-class
3
-#'              object create the corresponding edgeR object.
4
-#'              This function and other utility function enables the user to
5
-#'              not worry abut the implementation and just focus
6
-#'              on the analysis. The ScreenR package will take care of the rest.
7
-#' @param screenR_Object The ScreenR object obtained using the
8
-#'                       \code{\link{create_screenr_object}}
9
-#' @importFrom  edgeR DGEList
10
-#' @return The edgeR object will all the needed information for the analysis.
11
-#' @concept objects
12
-#' @export
13
-#' @examples
14
-#' object <- get0("object", envir = asNamespace("ScreenR"))
15
-#' create_edger_obj(object)
16
-create_edger_obj <- function(screenR_Object) {
17
-    # First create the Matrix of the Count table
18
-    counts <- screenR_Object@normalized_count_table
19
-    counts <- as.matrix(dplyr::select_if(counts, is.numeric))
20
-    # The group for the treatment
21
-    groups <- screenR_Object@groups
22
-
23
-    # The annotation
24
-    genes <- screenR_Object@annotation_table
25
-
26
-    # Create the edgeR object
27
-    DGEList <- edgeR::DGEList(counts = counts,
28
-                              group = groups,
29
-                              genes = genes)
30
-    return(DGEList)
31
-}
32 0
similarity index 100%
33 1
rename from R/create_ScreenR_object.R
34 2
rename to R/create_screenR_object.R
35 3
similarity index 100%
36 4
rename from R/create_edgeR_obj.R
37 5
rename to R/create_screenr_obj.R
38 6
deleted file mode 100644
... ...
@@ -1,163 +0,0 @@
1
-#' @title Multidimensional Scaling Plot
2
-#' @description Plot samples on a two-dimensional scatterplot so that
3
-#'              distances on the plot approximate the typical log2 fold
4
-#'              changes between the samples.
5
-#' @param screenR_Object The Object of the package
6
-#'                       \code{\link{create_screenr_object}}
7
-#' @param groups The vector that has to be used to fill the plot if NULL the
8
-#'               function will use the default groups slot in the object passed
9
-#'               as input.
10
-#' @param alpha The opacity of the labels.
11
-#'              Possible value are in a range from 0 to 1.
12
-#' @param size The dimension of the labels. The default value is 2.5
13
-#' @param color The color of the labels. The default value is black
14
-#' @importFrom ggplot2 geom_label labs
15
-#' @importFrom ggplot2 scale_y_continuous
16
-#' @importFrom limma plotMDS
17
-#' @return The MDS Plot
18
-#' @export
19
-#' @examples
20
-#' object <- get0("object", envir = asNamespace("ScreenR"))
21
-#'
22
-#' plot_mds(object)
23
-plot_mds <- function(screenR_Object, groups = NULL, alpha = 0.8, size = 2.5,
24
-    color = "black") {
25
-    # We have to convert the screenR obj into an edgeR obj
26
-    DGEList <- create_edger_obj(screenR_Object)
27
-
28
-    # The Standard plotMDS
29
-    plotMDS <- limma::plotMDS(DGEList, plot = FALSE, ndim = 2)
30
-
31
-    # Create the Updated plot MDS
32
-    PLTdata <- data.frame(
33
-        Sample = rownames(plotMDS$distance.matrix.squared),
34
-        x = plotMDS$x, y = plotMDS$y
35
-    )
36
-
37
-    if (is.null(groups)) {
38
-        PLTdata$group <- DGEList$samples$group
39
-    } else {
40
-        PLTdata$group <- groups
41
-    }
42
-
43
-    plot <- ggplot2::ggplot(PLTdata, aes(
44
-        x = .data$x, y = .data$y,
45
-        fill = .data$group
46
-    )) +
47
-        ggplot2::geom_label(aes(label = .data$Sample),
48
-            color = color, size = size, alpha = alpha
49
-        ) +
50
-        ggplot2::labs(x = "First Dimension", y = "Second Dimension")
51
-
52
-    return(plot)
53
-}
54
-
55
-#' @title Plot the explained variance by the PC
56
-#' @description This function plot the explained variance by the
57
-#'              Principal Component analysis.
58
-#' @param screenR_Object The ScreenR object obtained using the
59
-#'                       \code{\link{create_screenr_object}}
60
-#' @param cumulative A boolean value which indicates whether or not to plot
61
-#'                   the cumulative variance. The default value is FALSE.
62
-#' @param color The color to fill the barplot the default value is steelblue
63
-#' @importFrom  scales percent
64
-#' @return The explained variance plot
65
-#' @export
66
-#' @examples
67
-#' object <- get0("object", envir = asNamespace("ScreenR"))
68
-#'
69
-#' plot_explained_variance(object)
70
-#'
71
-#' # For the cumulative plot
72
-#' plot_explained_variance(object, cumulative = TRUE)
73
-plot_explained_variance <- function(screenR_Object, cumulative = FALSE,
74
-    color = "steelblue") {
75
-    PC <- compute_explained_variance(screenR_Object)
76
-    # Remove the Standard deviation row
77
-    PC <- filter(PC, .data$Name != "Standard deviation")
78
-
79
-    # Get only the numeric columns which corresponds to the PCs
80
-    numeric_col <- colnames(PC[, unlist(lapply(PC, is.numeric))])
81
-
82
-    # Transform the data in a longer format
83
-    PC <- tidyr::pivot_longer(
84
-        data = PC, cols = all_of(numeric_col),
85
-        names_to = "name"
86
-    )
87
-    PC <- dplyr::mutate(PC, name = factor(
88
-        x = .data$name,
89
-        levels = unique(.data$name)
90
-    ))
91
-    plot <- NULL
92
-
93
-
94
-    if (cumulative) {
95
-        # Select only the Cumulative Proportion
96
-        PC <- dplyr::filter(PC, .data$Name == "Cumulative Proportion")
97
-
98
-        plot <- ggplot2::ggplot(PC, aes(x = .data$name, y = .data$value)) +
99
-            geom_bar(stat = "identity", fill = color, col = "black") +
100
-            geom_point() +
101
-            geom_line(aes(group = .data$Name)) +
102
-            scale_y_continuous(labels = scales::percent) +
103
-            labs(
104
-                x = NULL,
105
-                y = "Cumulative Expressed Variance (%)"
106
-            )
107
-    } else {
108
-        # Select only the Proportion of Variance
109
-        PC <- dplyr::filter(PC, .data$Name == "Proportion of Variance")
110
-
111
-        plot <- ggplot2::ggplot(PC, aes(x = .data$name, y = .data$value)) +
112
-            geom_bar(stat = "identity", fill = color, col = "black") +
113
-            geom_point() +
114
-            geom_line(aes(group = .data$Name)) +
115
-            scale_y_continuous(labels = percent) +
116
-            labs(x = NULL, y = "Expressed Variance (%)")
117
-    }
118
-
119
-    return(plot)
120
-}
121
-
122
-#' @title Compute explained variance
123
-#' @description This  is an internal function  used to compute
124
-#'              the explained variance by each of the Principal Components.
125
-#' @importFrom stats  prcomp
126
-#' @param screenR_Object The Object of the package
127
-#' @return A data.frame containing all the information of the variance
128
-#'         expressed by the components
129
-#' @keywords internal
130
-#' @export
131
-#' @examples
132
-#' object <- get0("object", envir = asNamespace("ScreenR"))
133
-#'
134
-#' compute_explained_variance(object)
135
-compute_explained_variance <- function(screenR_Object) {
136
-    data <- screenR_Object@count_table
137
-    # Get only the numeric columns
138
-    numeric_col <- unlist(lapply(data, is.numeric))
139
-
140
-    # The data for the PC corresponds only on the numeric column
141
-    data_PC <- data[, numeric_col]
142
-
143
-    # To compute the PC the features has to be columns
144
-    data_PC <- t(data_PC)
145
-
146
-    # Rename the columns
147
-    colnames(data_PC) <- data$Barcode
148
-
149
-    # Computing the PCS
150
-    PC <- prcomp(data_PC)
151
-
152
-    # Extract the importance ad create a data.frame
153
-    PC <- data.frame(summary(PC)$importance)
154
-
155
-    PC <- tibble::rownames_to_column(PC, var = "Name")
156
-
157
-    PC <- dplyr::mutate(PC, Name = factor(
158
-        x = .data$Name,
159
-        levels = unique(.data$Name)
160
-    ))
161
-
162
-    return(PC)
163
-}
164 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
-}
... ...
@@ -161,3 +161,7 @@ compute_explained_variance <- function(screenR_Object) {
161 161
 
162 162
     return(PC)
163 163
 }
164
+
165
+
166
+
167
+
164 168
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
-)
266 0
deleted file mode 100644
... ...
@@ -1,27 +0,0 @@
1
-% Generated by roxygen2: do not edit by hand
2
-% Please edit documentation in R/create_edger_obj.R
3
-\name{create_edger_obj}
4
-\alias{create_edger_obj}
5
-\title{Create edgeR Object}
6
-\usage{
7
-create_edger_obj(screenR_Object)
8
-}
9
-\arguments{
10
-\item{screenR_Object}{The ScreenR object obtained using the
11
-\code{\link{create_screenr_object}}}
12
-}
13
-\value{
14
-The edgeR object will all the needed information for the analysis.
15
-}
16
-\description{
17
-Utility function that using the screenr-class
18
-             object create the corresponding edgeR object.
19
-             This function and other utility function enables the user to
20
-             not worry abut the implementation and just focus
21
-             on the analysis. The ScreenR package will take care of the rest.
22
-}
23
-\examples{
24
-object <- get0("object", envir = asNamespace("ScreenR"))
25
-create_edger_obj(object)
26
-}
27
-\concept{objects}
... ...
@@ -1,5 +1,5 @@
1 1
 % Generated by roxygen2: do not edit by hand
2
-% Please edit documentation in R/create_edger_obj.R
2
+% Please edit documentation in R/create_screenr_obj.R
3 3
 \name{create_edger_obj}
4 4
 \alias{create_edger_obj}
5 5
 \title{Create edgeR Object}