Browse code

one round of styler on recent R source files

Federico Marini authored on 30/03/2022 13:00:28
Showing1 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
-
Browse code

fixing example

Federico Marini authored on 30/03/2022 10:11:00
Showing1 changed files
... ...
@@ -16,7 +16,6 @@
16 16
 #' # res_enrich object
17 17
 #' data(res_enrich_macrophage, package = "GeneTonic")
18 18
 #' res_enrich <- shake_topGOtableResult(topgoDE_macrophage_IFNg_vs_naive)
19
-#' res_enrich <- get_aggrscores(res_enrich, res_de, anno_df)
20 19
 #'
21 20
 #' create_upsetdata(res_enrich[1:20, ])
22 21
 #' dim(create_upsetdata(res_enrich[1:20, ]))
Browse code

added functionality to plot geneset upset plots

Federico Marini authored on 30/03/2022 09:58:00
Showing1 changed files
... ...
@@ -1,11 +1,11 @@
1 1
 #' Create a geneset upset dataset
2
-#' 
2
+#'
3 3
 #' Create a data frame that can be fed to the upset function
4 4
 #'
5 5
 #' @param res_enrich A `data.frame` object, storing the result of the functional
6 6
 #' enrichment analysis. See more in the main function, [GeneTonic()], to see the
7 7
 #' formatting requirements.
8
-#' @param use_ids Logical - whether to use the `gs_id`entifiers as names, or the 
8
+#' @param use_ids Logical - whether to use the `gs_id`entifiers as names, or the
9 9
 #' values provided as `gs_description`. Defaults to FALSE, using the full
10 10
 #' descriptions
11 11
 #'
... ...
@@ -13,35 +13,43 @@
13 13
 #' @export
14 14
 #'
15 15
 #' @examples
16
-#' # TODO
16
+#' # res_enrich object
17
+#' data(res_enrich_macrophage, package = "GeneTonic")
18
+#' res_enrich <- shake_topGOtableResult(topgoDE_macrophage_IFNg_vs_naive)
19
+#' res_enrich <- get_aggrscores(res_enrich, res_de, anno_df)
20
+#'
21
+#' create_upsetdata(res_enrich[1:20, ])
22
+#' dim(create_upsetdata(res_enrich[1:20, ]))
23
+#'
24
+#' create_upsetdata(res_enrich[1:5, ], use_ids = TRUE)
17 25
 create_upsetdata <- function(res_enrich, use_ids = FALSE) {
18 26
   my_gs_ids <- res_enrich$gs_id
19 27
   my_gs_desc <- res_enrich$gs_description
20 28
   my_gs_genes <- res_enrich$gs_genes
21
-  
29
+
22 30
   gsg_list <- strsplit(my_gs_genes, ",")
23 31
   if (use_ids) {
24 32
     names(gsg_list) <- my_gs_ids
25 33
   } else {
26 34
     names(gsg_list) <- my_gs_desc
27 35
   }
28
-  
36
+
29 37
   all_genes <- unique(unlist(gsg_list))
30 38
   upgsg <- unlist(lapply(gsg_list, function(x) {
31 39
     x <- as.vector(match(all_genes, x))
32 40
   }))
33
-  
41
+
34 42
   upgsg[is.na(upgsg)] <- as.integer(0)
35 43
   upgsg[upgsg != 0] <- as.integer(1)
36
-  
44
+
37 45
   upgsg <- data.frame(
38 46
     matrix(upgsg, ncol = length(gsg_list), byrow = FALSE)
39 47
   )
40
-  
48
+
41 49
   upgsg <- upgsg[which(rowSums(upgsg) != 0), ]
42 50
   names(upgsg) <- names(gsg_list)
43 51
   rownames(upgsg) <- all_genes
44
-  
52
+
45 53
   return(upgsg)
46 54
 }
47 55
 
... ...
@@ -49,7 +57,7 @@ create_upsetdata <- function(res_enrich, use_ids = FALSE) {
49 57
 
50 58
 
51 59
 #' Upset plot for genesets
52
-#' 
60
+#'
53 61
 #' Create an upset plot for genesets
54 62
 #'
55 63
 #' @param res_enrich A `data.frame` object, storing the result of the functional
... ...
@@ -66,7 +74,7 @@ create_upsetdata <- function(res_enrich, use_ids = FALSE) {
66 74
 #' @param gs_ids Character vector, containing a subset of `gs_id` as they are
67 75
 #' available in `res_enrich`. Lists the gene sets to be included in addition to
68 76
 #' the top ones (via `n_gs`)
69
-#' @param add_de_direction Logical, whether to add an annotation with info on the 
77
+#' @param add_de_direction Logical, whether to add an annotation with info on the
70 78
 #' DE direction of single genes
71 79
 #' @param add_de_gsgenes Logical, if set to TRUE adds an annotation with detail
72 80
 #' on the single components of each defined subset
... ...
@@ -77,7 +85,7 @@ create_upsetdata <- function(res_enrich, use_ids = FALSE) {
77 85
 #' @param upset_geom A geom specification to be used in the upset chart. Defaults
78 86
 #' sensibly to `geom_point(size = 2)`
79 87
 #' @param return_upsetgsg Logical, controlling the returned value. If set to TRUE,
80
-#' this function will not generate the plot but only create the corresponding 
88
+#' this function will not generate the plot but only create the corresponding
81 89
 #' data.frame, in case the user wants to proceed with a custom call to create an
82 90
 #' upset plot.
83 91
 #'
... ...
@@ -85,9 +93,57 @@ create_upsetdata <- function(res_enrich, use_ids = FALSE) {
85 93
 #' @export
86 94
 #'
87 95
 #' @examples
88
-#' # TODO
96
+#' library("macrophage")
97
+#' library("DESeq2")
98
+#' library("org.Hs.eg.db")
99
+#' library("AnnotationDbi")
100
+#'
101
+#' # dds object
102
+#' data("gse", package = "macrophage")
103
+#' dds_macrophage <- DESeqDataSet(gse, design = ~ line + condition)
104
+#' rownames(dds_macrophage) <- substr(rownames(dds_macrophage), 1, 15)
105
+#' dds_macrophage <- estimateSizeFactors(dds_macrophage)
106
+#'
107
+#' # annotation object
108
+#' anno_df <- data.frame(
109
+#'   gene_id = rownames(dds_macrophage),
110
+#'   gene_name = mapIds(org.Hs.eg.db,
111
+#'     keys = rownames(dds_macrophage),
112
+#'     column = "SYMBOL",
113
+#'     keytype = "ENSEMBL"
114
+#'   ),
115
+#'   stringsAsFactors = FALSE,
116
+#'   row.names = rownames(dds_macrophage)
117
+#' )
118
+#'
119
+#' # res object
120
+#' data(res_de_macrophage, package = "GeneTonic")
121
+#' res_de <- res_macrophage_IFNg_vs_naive
122
+#'
123
+#' # res_enrich object
124
+#' data(res_enrich_macrophage, package = "GeneTonic")
125
+#' res_enrich <- shake_topGOtableResult(topgoDE_macrophage_IFNg_vs_naive)
126
+#' res_enrich <- get_aggrscores(res_enrich, res_de, anno_df)
127
+#' gs_upset(res_enrich,
128
+#'          n_gs = 10)
129
+#'
130
+#' gs_upset(res_enrich, res_de = res_de, annotation_obj = anno_df,
131
+#'          n_gs = 8,
132
+#'          add_de_direction = TRUE, add_de_gsgenes = TRUE)
133
+#'
134
+#' # or using the practical gtl (GeneTonicList)
135
+#' gtl_macrophage <- GeneTonic_list(
136
+#'   dds = dds_macrophage,
137
+#'   res_de = res_de,
138
+#'   res_enrich = res_enrich,
139
+#'   annotation_obj = anno_df
140
+#' )
141
+#'
142
+#' gs_upset(gtl = gtl_macrophage,
143
+#'          n_gs = 15,
144
+#'          add_de_direction = TRUE, add_de_gsgenes = TRUE)
89 145
 gs_upset <- function(res_enrich,
90
-                     res_de,
146
+                     res_de = NULL,
91 147
                      annotation_obj = NULL,
92 148
                      n_gs = 10,
93 149
                      gtl = NULL,
... ...
@@ -98,7 +154,7 @@ gs_upset <- function(res_enrich,
98 154
                      col_downDE = "#377EB8",
99 155
                      upset_geom = geom_point(size = 2),
100 156
                      return_upsetgsg = FALSE) {
101
-  
157
+
102 158
   if (!is.null(gtl)) {
103 159
     checkup_gtl(gtl)
104 160
     # dds <- gtl$dds
... ...
@@ -106,56 +162,64 @@ gs_upset <- function(res_enrich,
106 162
     res_enrich <- gtl$res_enrich
107 163
     annotation_obj <- gtl$annotation_obj
108 164
   }
109
-  
165
+
110 166
   stopifnot(is.numeric(n_gs))
111
-  
167
+
112 168
   n_gs <- min(n_gs, nrow(res_enrich))
113
-  
169
+
114 170
   gs_to_use <- unique(
115 171
     c(
116 172
       res_enrich$gs_id[seq_len(n_gs)], # the ones from the top
117 173
       gs_ids[gs_ids %in% res_enrich$gs_id] # the ones specified from the custom list
118 174
     )
119 175
   )
120
-  
176
+
121 177
   re <- res_enrich[gs_to_use, ]
122
-  
178
+
123 179
   upgsg <- create_upsetdata(re)
124
-  
125
-  if(add_de_direction) { # TODO extra checks, need DE and annot
180
+
181
+  if (add_de_direction) {
182
+    if (is.null(res_de) | is.null(annotation_obj))
183
+      stop("DE results and annotation required if `add_de_direction` is TRUE, please provide them as `res_de` and `annotation_obj`")
126 184
     upgsg$logFC <- res_de[annotation_obj$gene_id[
127 185
       match(rownames(upgsg), annotation_obj$gene_name)], "log2FoldChange"]
128 186
     upgsg$logFCsign <- upgsg$logFC >= 0
129
-    
187
+
130 188
     param_upset_baseanno <- list(
131 189
       'Intersection size' = intersection_size(
132 190
         counts = FALSE,
133 191
         mapping = aes_string(fill = "logFCsign")
134
-      ) + 
192
+      ) +
135 193
         scale_fill_manual(
136 194
           values=c('FALSE' = col_downDE, 'TRUE' = col_upDE),
137 195
           labels = c("logFC<0", "logFC>0"),
138
-          name = "") + 
196
+          name = "") +
139 197
         theme(legend.position="bottom")
140 198
     )
141 199
   } else {
142 200
     param_upset_baseanno <- "auto"
143 201
   }
144
-  
202
+
145 203
   if (add_de_gsgenes){
204
+    if (is.null(res_de) | is.null(annotation_obj))
205
+      stop("DE results and annotation required if `add_de_gsgenes` is TRUE, please provide them as `res_de` and `annotation_obj`")
206
+    upgsg$logFC <- res_de[annotation_obj$gene_id[
207
+      match(rownames(upgsg), annotation_obj$gene_name)], "log2FoldChange"]
208
+    upgsg$logFCsign <- upgsg$logFC >= 0
209
+
146 210
     param_upset_anno <- list(
147 211
       'logFC' = (
148
-        ggplot(mapping = aes_string(x = "intersection", y = "logFC")) +  
149
-          geom_jitter(aes_string(color = "logFC"), na.rm = TRUE) + 
150
-          # geom_violin(alpha = 0.5, na.rm = TRUE) + 
151
-          theme(legend.position = "none") + 
212
+        ggplot(mapping = aes_string(x = "intersection", y = "logFC")) +
213
+          geom_jitter(aes_string(color = "logFC"), na.rm = TRUE) +
214
+          # geom_violin(alpha = 0.5, na.rm = TRUE) +
215
+          theme(legend.position = "none") +
152 216
           scale_colour_gradient2(low = col_downDE, high = col_upDE)
153 217
       )
154 218
     )
155 219
   } else {
156 220
     param_upset_anno <- NULL
157 221
   }
158
-  
222
+
159 223
   # if desired to work on this separately
160 224
   if (return_upsetgsg) {
161 225
     return(upgsg)
... ...
@@ -173,7 +237,7 @@ gs_upset <- function(res_enrich,
173 237
     annotations = param_upset_anno,
174 238
     width_ratio=0.1
175 239
   )
176
-  
240
+
177 241
 }
178 242
 
179 243
 
Browse code

first stub of geneset upset plot implementation

Federico Marini authored on 19/01/2022 10:32:48
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,179 @@
1
+#' Create a geneset upset dataset
2
+#' 
3
+#' Create a data frame that can be fed to the upset function
4
+#'
5
+#' @param res_enrich A `data.frame` object, storing the result of the functional
6
+#' enrichment analysis. See more in the main function, [GeneTonic()], to see the
7
+#' formatting requirements.
8
+#' @param use_ids Logical - whether to use the `gs_id`entifiers as names, or the 
9
+#' values provided as `gs_description`. Defaults to FALSE, using the full
10
+#' descriptions
11
+#'
12
+#' @return A data.frame to be used in `ComplexUpset::upset()`
13
+#' @export
14
+#'
15
+#' @examples
16
+#' # TODO
17
+create_upsetdata <- function(res_enrich, use_ids = FALSE) {
18
+  my_gs_ids <- res_enrich$gs_id
19
+  my_gs_desc <- res_enrich$gs_description
20
+  my_gs_genes <- res_enrich$gs_genes
21
+  
22
+  gsg_list <- strsplit(my_gs_genes, ",")
23
+  if (use_ids) {
24
+    names(gsg_list) <- my_gs_ids
25
+  } else {
26
+    names(gsg_list) <- my_gs_desc
27
+  }
28
+  
29
+  all_genes <- unique(unlist(gsg_list))
30
+  upgsg <- unlist(lapply(gsg_list, function(x) {
31
+    x <- as.vector(match(all_genes, x))
32
+  }))
33
+  
34
+  upgsg[is.na(upgsg)] <- as.integer(0)
35
+  upgsg[upgsg != 0] <- as.integer(1)
36
+  
37
+  upgsg <- data.frame(
38
+    matrix(upgsg, ncol = length(gsg_list), byrow = FALSE)
39
+  )
40
+  
41
+  upgsg <- upgsg[which(rowSums(upgsg) != 0), ]
42
+  names(upgsg) <- names(gsg_list)
43
+  rownames(upgsg) <- all_genes
44
+  
45
+  return(upgsg)
46
+}
47
+
48
+
49
+
50
+
51
+#' Upset plot for genesets
52
+#' 
53
+#' Create an upset plot for genesets
54
+#'
55
+#' @param res_enrich A `data.frame` object, storing the result of the functional
56
+#' enrichment analysis. See more in the main function, [GeneTonic()], to check the
57
+#' formatting requirements (a minimal set of columns should be present).
58
+#' @param res_de A `DESeqResults` object.
59
+#' @param annotation_obj A `data.frame` object with the feature annotation
60
+#' information, with at least two columns, `gene_id` and `gene_name`.
61
+#' @param n_gs Integer value, corresponding to the maximal number of gene sets to
62
+#' be included
63
+#' @param gtl A `GeneTonic`-list object, containing in its slots the arguments
64
+#' specified above: `dds`, `res_de`, `res_enrich`, and `annotation_obj` - the names
65
+#' of the list _must_ be specified following the content they are expecting
66
+#' @param gs_ids Character vector, containing a subset of `gs_id` as they are
67
+#' available in `res_enrich`. Lists the gene sets to be included in addition to
68
+#' the top ones (via `n_gs`)
69
+#' @param add_de_direction Logical, whether to add an annotation with info on the 
70
+#' DE direction of single genes
71
+#' @param add_de_gsgenes Logical, if set to TRUE adds an annotation with detail
72
+#' on the single components of each defined subset
73
+#' @param col_upDE Character, specifying the color value to be used to mark
74
+#' upregulated genes
75
+#' @param col_downDE Character, specifying the color value to be used to mark
76
+#' downregulated genes
77
+#' @param upset_geom A geom specification to be used in the upset chart. Defaults
78
+#' sensibly to `geom_point(size = 2)`
79
+#' @param return_upsetgsg Logical, controlling the returned value. If set to TRUE,
80
+#' this function will not generate the plot but only create the corresponding 
81
+#' data.frame, in case the user wants to proceed with a custom call to create an
82
+#' upset plot.
83
+#'
84
+#' @return A `ggplot` object (if plotting), or alternatively a data.frame
85
+#' @export
86
+#'
87
+#' @examples
88
+#' # TODO
89
+gs_upset <- function(res_enrich,
90
+                     res_de,
91
+                     annotation_obj = NULL,
92
+                     n_gs = 10,
93
+                     gtl = NULL,
94
+                     gs_ids = NULL,
95
+                     add_de_direction = FALSE,
96
+                     add_de_gsgenes = FALSE,
97
+                     col_upDE = "#E41A1C",
98
+                     col_downDE = "#377EB8",
99
+                     upset_geom = geom_point(size = 2),
100
+                     return_upsetgsg = FALSE) {
101
+  
102
+  if (!is.null(gtl)) {
103
+    checkup_gtl(gtl)
104
+    # dds <- gtl$dds
105
+    res_de <- gtl$res_de
106
+    res_enrich <- gtl$res_enrich
107
+    annotation_obj <- gtl$annotation_obj
108
+  }
109
+  
110
+  stopifnot(is.numeric(n_gs))
111
+  
112
+  n_gs <- min(n_gs, nrow(res_enrich))
113
+  
114
+  gs_to_use <- unique(
115
+    c(
116
+      res_enrich$gs_id[seq_len(n_gs)], # the ones from the top
117
+      gs_ids[gs_ids %in% res_enrich$gs_id] # the ones specified from the custom list
118
+    )
119
+  )
120
+  
121
+  re <- res_enrich[gs_to_use, ]
122
+  
123
+  upgsg <- create_upsetdata(re)
124
+  
125
+  if(add_de_direction) { # TODO extra checks, need DE and annot
126
+    upgsg$logFC <- res_de[annotation_obj$gene_id[
127
+      match(rownames(upgsg), annotation_obj$gene_name)], "log2FoldChange"]
128
+    upgsg$logFCsign <- upgsg$logFC >= 0
129
+    
130
+    param_upset_baseanno <- list(
131
+      'Intersection size' = intersection_size(
132
+        counts = FALSE,
133
+        mapping = aes_string(fill = "logFCsign")
134
+      ) + 
135
+        scale_fill_manual(
136
+          values=c('FALSE' = col_downDE, 'TRUE' = col_upDE),
137
+          labels = c("logFC<0", "logFC>0"),
138
+          name = "") + 
139
+        theme(legend.position="bottom")
140
+    )
141
+  } else {
142
+    param_upset_baseanno <- "auto"
143
+  }
144
+  
145
+  if (add_de_gsgenes){
146
+    param_upset_anno <- list(
147
+      'logFC' = (
148
+        ggplot(mapping = aes_string(x = "intersection", y = "logFC")) +  
149
+          geom_jitter(aes_string(color = "logFC"), na.rm = TRUE) + 
150
+          # geom_violin(alpha = 0.5, na.rm = TRUE) + 
151
+          theme(legend.position = "none") + 
152
+          scale_colour_gradient2(low = col_downDE, high = col_upDE)
153
+      )
154
+    )
155
+  } else {
156
+    param_upset_anno <- NULL
157
+  }
158
+  
159
+  # if desired to work on this separately
160
+  if (return_upsetgsg) {
161
+    return(upgsg)
162
+  }
163
+
164
+  # ready to plot
165
+  ComplexUpset::upset(
166
+    data = upgsg,
167
+    intersect = names(upgsg)[seq_len(length(gs_to_use))],
168
+    name = "gsg upset",
169
+    matrix = intersection_matrix(
170
+      geom = upset_geom
171
+    ) + scale_y_discrete(position="right"),
172
+    base_annotations = param_upset_baseanno,
173
+    annotations = param_upset_anno,
174
+    width_ratio=0.1
175
+  )
176
+  
177
+}
178
+
179
+