Browse code

one round of styler on recent R source files

Federico Marini authored on 30/03/2022 13:00:28
Showing 1 changed files

... ...
@@ -124,11 +124,14 @@ create_upsetdata <- function(res_enrich, use_ids = FALSE) {
124 124
 #' res_enrich <- shake_topGOtableResult(topgoDE_macrophage_IFNg_vs_naive)
125 125
 #' res_enrich <- get_aggrscores(res_enrich, res_de, anno_df)
126 126
 #' gs_upset(res_enrich,
127
-#'          n_gs = 10)
127
+#'   n_gs = 10
128
+#' )
128 129
 #'
129
-#' gs_upset(res_enrich, res_de = res_de, annotation_obj = anno_df,
130
-#'          n_gs = 8,
131
-#'          add_de_direction = TRUE, add_de_gsgenes = TRUE)
130
+#' gs_upset(res_enrich,
131
+#'   res_de = res_de, annotation_obj = anno_df,
132
+#'   n_gs = 8,
133
+#'   add_de_direction = TRUE, add_de_gsgenes = TRUE
134
+#' )
132 135
 #'
133 136
 #' # or using the practical gtl (GeneTonicList)
134 137
 #' gtl_macrophage <- GeneTonic_list(
... ...
@@ -138,9 +141,11 @@ create_upsetdata <- function(res_enrich, use_ids = FALSE) {
138 141
 #'   annotation_obj = anno_df
139 142
 #' )
140 143
 #'
141
-#' gs_upset(gtl = gtl_macrophage,
142
-#'          n_gs = 15,
143
-#'          add_de_direction = TRUE, add_de_gsgenes = TRUE)
144
+#' gs_upset(
145
+#'   gtl = gtl_macrophage,
146
+#'   n_gs = 15,
147
+#'   add_de_direction = TRUE, add_de_gsgenes = TRUE
148
+#' )
144 149
 gs_upset <- function(res_enrich,
145 150
                      res_de = NULL,
146 151
                      annotation_obj = NULL,
... ...
@@ -153,7 +158,6 @@ gs_upset <- function(res_enrich,
153 158
                      col_downDE = "#377EB8",
154 159
                      upset_geom = geom_point(size = 2),
155 160
                      return_upsetgsg = FALSE) {
156
-
157 161
   if (!is.null(gtl)) {
158 162
     checkup_gtl(gtl)
159 163
     # dds <- gtl$dds
... ...
@@ -178,36 +182,41 @@ gs_upset <- function(res_enrich,
178 182
   upgsg <- create_upsetdata(re)
179 183
 
180 184
   if (add_de_direction) {
181
-    if (is.null(res_de) | is.null(annotation_obj))
185
+    if (is.null(res_de) | is.null(annotation_obj)) {
182 186
       stop("DE results and annotation required if `add_de_direction` is TRUE, please provide them as `res_de` and `annotation_obj`")
187
+    }
183 188
     upgsg$logFC <- res_de[annotation_obj$gene_id[
184
-      match(rownames(upgsg), annotation_obj$gene_name)], "log2FoldChange"]
189
+      match(rownames(upgsg), annotation_obj$gene_name)
190
+    ], "log2FoldChange"]
185 191
     upgsg$logFCsign <- upgsg$logFC >= 0
186 192
 
187 193
     param_upset_baseanno <- list(
188
-      'Intersection size' = intersection_size(
194
+      "Intersection size" = intersection_size(
189 195
         counts = FALSE,
190 196
         mapping = aes_string(fill = "logFCsign")
191 197
       ) +
192 198
         scale_fill_manual(
193
-          values=c('FALSE' = col_downDE, 'TRUE' = col_upDE),
199
+          values = c("FALSE" = col_downDE, "TRUE" = col_upDE),
194 200
           labels = c("logFC<0", "logFC>0"),
195
-          name = "") +
196
-        theme(legend.position="bottom")
201
+          name = ""
202
+        ) +
203
+        theme(legend.position = "bottom")
197 204
     )
198 205
   } else {
199 206
     param_upset_baseanno <- "auto"
200 207
   }
201 208
 
202
-  if (add_de_gsgenes){
203
-    if (is.null(res_de) | is.null(annotation_obj))
209
+  if (add_de_gsgenes) {
210
+    if (is.null(res_de) | is.null(annotation_obj)) {
204 211
       stop("DE results and annotation required if `add_de_gsgenes` is TRUE, please provide them as `res_de` and `annotation_obj`")
212
+    }
205 213
     upgsg$logFC <- res_de[annotation_obj$gene_id[
206
-      match(rownames(upgsg), annotation_obj$gene_name)], "log2FoldChange"]
214
+      match(rownames(upgsg), annotation_obj$gene_name)
215
+    ], "log2FoldChange"]
207 216
     upgsg$logFCsign <- upgsg$logFC >= 0
208 217
 
209 218
     param_upset_anno <- list(
210
-      'logFC' = (
219
+      "logFC" = (
211 220
         ggplot(mapping = aes_string(x = "intersection", y = "logFC")) +
212 221
           geom_jitter(aes_string(color = "logFC"), na.rm = TRUE) +
213 222
           # geom_violin(alpha = 0.5, na.rm = TRUE) +
... ...
@@ -231,12 +240,9 @@ gs_upset <- function(res_enrich,
231 240
     name = "gsg upset",
232 241
     matrix = intersection_matrix(
233 242
       geom = upset_geom
234
-    ) + scale_y_discrete(position="right"),
243
+    ) + scale_y_discrete(position = "right"),
235 244
     base_annotations = param_upset_baseanno,
236 245
     annotations = param_upset_anno,
237
-    width_ratio=0.1
246
+    width_ratio = 0.1
238 247
   )
239
-
240 248
 }
241
-
242
-