@@ -218,45 +218,9 @@ ContrastsPlotter <- R6::R6Class(
218218 # ' @param rank default FALSE, if TRUE then rank of avgAbd is used.
219219 # ' @return ggplot
220220 ma_plot = function (fc , colour , legend = TRUE , rank = TRUE ){
221- if ( missing(fc ))
222- fc <- self $ fcthresh
223- if (missing(colour )) {
224- colour <- self $ modelName
225- }
226- contrastDF <- self $ contrastDF
227- if (! is.null(contrastDF [[self $ avg.abundance ]])) {
228- # pdf version
229- if (rank ) {
230- rankcol <- paste0(" rank_" , self $ avg.abundance )
231-
232- contrastDF <- contrastDF | >
233- dplyr :: group_by(!! sym(self $ contrast )) | >
234- mutate(!! rankcol : = rank(!! sym(self $ avg.abundance )))
235-
236- # contrastDF[[ rankcol ]] <- rank(contrastDF[[self$avg.abundance]])
237- fig <- private $ .ma_plot(
238- contrastDF ,
239- rankcol ,
240- self $ diff ,
241- self $ contrast ,
242- fc ,
243- colour = colour ,
244- legend = legend )
245- }else {
246- fig <- private $ .ma_plot(
247- contrastDF ,
248- self $ avg.abundance ,
249- self $ diff ,
250- self $ contrast ,
251- fc ,
252- colour = colour ,
253- legend = legend )
254- }
255- }else {
256- warning(" no group_1 group_2 columns can't generate MA" )
257- fig <- NULL
258- }
259- return (fig )
221+ if (missing(fc )) fc <- self $ fcthresh
222+ if (missing(colour )) colour <- self $ modelName
223+ private $ .ma_fig(self $ contrastDF , fc , colour , legend , rank )
260224 },
261225 # ' @description
262226 # ' ma plotly
@@ -266,49 +230,11 @@ ContrastsPlotter <- R6::R6Class(
266230 # ' @param rank default FALSE, if TRUE then rank of avgAbd is used.
267231 # ' @return list of ggplots
268232 ma_plotly = function (fc , colour , legend = TRUE , rank = FALSE ){
269- # html version
270- if (missing(fc ))
271- fc <- self $ fcthresh
272- if (missing(colour ))
273- colour <- self $ modelName
274- contrastDF <- self $ contrastDF
275- if (! is.null(contrastDF [[self $ avg.abundance ]])) {
276- if (rank ) {
277- rankcol <- paste0(" rank_" , self $ avg.abundance )
278- contrastDF <- contrastDF | >
279- dplyr :: group_by(!! sym(self $ contrast )) | >
280- mutate(!! rankcol : = rank(!! sym(self $ avg.abundance )))
281-
282- fig <- private $ .ma_plot(
283- contrastDF ,
284- rankcol ,
285- self $ diff ,
286- self $ contrast ,
287- fc ,
288- colour = colour ,
289- legend = legend
290- )
291- } else {
292- contrastDF <- contrastDF | >
293- plotly :: highlight_key(~ subject_Id )
294- fig <- private $ .ma_plot(
295- contrastDF ,
296- self $ avg.abundance ,
297- self $ diff ,
298- self $ contrast ,
299- fc ,
300- colour = colour ,
301- legend = legend
302- )
303- }
304-
305- fig_plotly <- fig | >
306- plotly :: ggplotly(tooltip = " subject_Id" )
307-
308- return (fig_plotly )
309- }else {
310- return (NULL )
311- }
233+ if (missing(fc )) fc <- self $ fcthresh
234+ if (missing(colour )) colour <- self $ modelName
235+ fig <- private $ .ma_fig(self $ contrastDF , fc , colour , legend , rank , plotly_mode = TRUE )
236+ if (! is.null(fig )) fig <- fig | > plotly :: ggplotly(tooltip = " subject_Id" )
237+ fig
312238 },
313239 # ' @description
314240 # ' plot a score against the log2 fc e.g. t-statistic
@@ -383,6 +309,23 @@ ContrastsPlotter <- R6::R6Class(
383309 }
384310 ),
385311 private = list (
312+ .ma_fig = function (contrastDF , fc , colour , legend , rank , plotly_mode = FALSE ) {
313+ if (is.null(contrastDF [[self $ avg.abundance ]])) {
314+ if (! plotly_mode ) warning(" no group_1 group_2 columns can't generate MA" )
315+ return (NULL )
316+ }
317+ xcol <- self $ avg.abundance
318+ if (rank ) {
319+ xcol <- paste0(" rank_" , self $ avg.abundance )
320+ contrastDF <- contrastDF | >
321+ dplyr :: group_by(!! sym(self $ contrast )) | >
322+ dplyr :: mutate(!! xcol : = rank(!! sym(self $ avg.abundance )))
323+ } else if (plotly_mode ) {
324+ contrastDF <- contrastDF | > plotly :: highlight_key(~ subject_Id )
325+ }
326+ private $ .ma_plot(contrastDF , xcol , self $ diff , self $ contrast , fc ,
327+ colour = colour , legend = legend )
328+ },
386329 .volcano = function (contrasts ,
387330 scores ,
388331 colour = NULL ,
0 commit comments