From 34218ab1ebf993083d98137962fbe5b3183b038c Mon Sep 17 00:00:00 2001 From: Klangina Date: Mon, 28 Oct 2024 21:00:51 +0530 Subject: [PATCH 1/7] =?UTF-8?q?[Fixed]=20condenseRepeatedDomains:=20no=20v?= =?UTF-8?q?isible=20binding=20for=20global=20variable=20=E2=80=98.?= =?UTF-8?q?=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/cleanup.R | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/R/cleanup.R b/R/cleanup.R index 4fe074ee..e93aa257 100755 --- a/R/cleanup.R +++ b/R/cleanup.R @@ -186,8 +186,9 @@ removeEmptyRows <- function(prot, by_column = "DomArch") { #' @return Describe return, in detail #' @export #' -#' @importFrom dplyr pull +#' @importFrom dplyr pull mutate #' @importFrom stringr str_replace_all +#' @importFrom rlang .data := #' #' @examples #' \dontrun{ @@ -202,36 +203,23 @@ condenseRepeatedDomains <- function(prot, by_column = "DomArch", excluded_prots regex_identify_repeats <- paste0("(?i)", regex_exclude, "\\b([a-z0-9_-]+)\\b(?:\\s+\\1\\b)+") # !! FUNS is soft-deprecated. FIX!!! - prot[, by_column] <- prot %>% - pull(by_column) %>% - str_replace_all(., pattern = "\\.", replacement = "_d_") %>% - # str_replace_all(., pattern = " ", replacement = "_s_") %>% - str_replace_all(., pattern = " ", replacement = "_") %>% - str_replace_all(., - pattern = "\\+", - replacement = " " - ) %>% # Use a different placeholder other than space - str_replace_all(., - pattern = "-", - replacement = "__" - ) %>% - str_replace_all(., - pattern = regex_identify_repeats, - replacement = "\\1(s)" - ) %>% - str_replace_all(., - pattern = "__", - replacement = "-" - ) %>% - str_replace_all(., - pattern = " ", - replacement = "+" - ) %>% - # str_replace_all(., pattern = "_s_", replacement = " ") %>% - str_replace_all(., pattern = "_d_", replacement = ".") - + prot <- prot %>% + dplyr::mutate(!!by_column := stringr::str_replace_all( + .data[[by_column]], + c( + "\\." = "_d_", + " " = "_", + "\\+" = " ", + "-" = "__", + regex_identify_repeats = "\\1(s)", + "__" = "-", + " " = "+", + "_d_" = "." + ) + )) return(prot) + } From 590c56877b581b69c10bf52f011575cafa322fba Mon Sep 17 00:00:00 2001 From: Klangina Date: Mon, 28 Oct 2024 21:25:03 +0530 Subject: [PATCH 2/7] =?UTF-8?q?[FIXED]=20plotEstimatedWallTimes=20:=20get?= =?UTF-8?q?=5Fpowerset=20:=20:=20no=20visible=20global=20=20=20?= =?UTF-8?q?=20=20=20function=20definition=20for=20=E2=80=98combn=E2=80=99?= =?UTF-8?q?=20=20=20=20plotEstimatedWallTimes:=20no=20visible=20binding=20?= =?UTF-8?q?for=20global=20variable=20=20=20=20=20=20=E2=80=98n=5Finputs?= =?UTF-8?q?=E2=80=99=20=20plotEstimatedWallTimes:=20no=20visible=20binding?= =?UTF-8?q?=20for=20global=20variable=20=20=20=20=20=20=E2=80=98advanced?= =?UTF-8?q?=5Fopts=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/assign_job_queue.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R/assign_job_queue.R b/R/assign_job_queue.R index 69609417..49d34ea8 100644 --- a/R/assign_job_queue.R +++ b/R/assign_job_queue.R @@ -339,6 +339,8 @@ assignJobQueue <- function( #' @importFrom dplyr mutate select #' @importFrom ggplot2 aes geom_line ggplot labs #' @importFrom tibble as_tibble +#' @importFrom utils combn +#' @importFrom rlang .data #' #' @return line plot object #' @@ -413,13 +415,13 @@ plotEstimatedWallTimes <- function() { df_walltimes <- tidyr::gather(df_walltimes, key = "advanced_opts", value = "est_walltime", - n_inputs) + .data$n_inputs) # sec to hrs df_walltimes <- df_walltimes |> dplyr::mutate(est_walltime = est_walltime / 3600) - p <- ggplot2::ggplot(df_walltimes, ggplot2::aes(x = n_inputs, - y = est_walltime, - color = advanced_opts)) + + p <- ggplot2::ggplot(df_walltimes, ggplot2::aes(x = .data$n_inputs, + y = .data$est_walltime, + color = .data$advanced_opts)) + ggplot2::geom_line() + ggplot2::labs( title = "MolEvolvR estimated runtimes", From 74d0e628228e43fbd118370dfec3a0e920e8172c Mon Sep 17 00:00:00 2001 From: Klangina Date: Tue, 29 Oct 2024 00:44:22 +0530 Subject: [PATCH 3/7] =?UTF-8?q?[FIXED]=20plotStackedLineage:=20no=20visibl?= =?UTF-8?q?e=20binding=20for=20global=20variable=20=E2=80=98cpcols?= =?UTF-8?q?=E2=80=99=20Added=20a=20random=20color-pallete=20as=20default,?= =?UTF-8?q?=20can=20be=20changed=20later=20on.=20(source=20for=20color=20p?= =?UTF-8?q?alette=20:=20https://www.colorcombos.com/color-schemes/16952/Co?= =?UTF-8?q?lorCombo16952.html)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/plotting.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/plotting.R b/R/plotting.R index 7191eace..5d95b546 100644 --- a/R/plotting.R +++ b/R/plotting.R @@ -804,6 +804,7 @@ plotLineageHeatmap <- function(prot, domains_of_interest, level = 3, label.size #' @param legend.size #' @param coord_flip #' @param legend +#' @param cpcols #' #' @importFrom dplyr pull select #' @importFrom ggplot2 aes_string coord_flip element_blank element_line element_rect element_text geom_bar ggplot guides guide_legend scale_fill_manual xlab ylab theme theme_minimal @@ -824,8 +825,13 @@ plotStackedLineage <- function(prot, column = "DomArch", cutoff, Lineage_col = " legend.text.size = 10, legend.cols = 2, legend.size = 0.7, - coord_flip = TRUE, legend = TRUE) { + coord_flip = TRUE, legend = TRUE, + cpcols = NULL) { col <- sym(column) + + if (is.null(cpcols)) { + cpcols <- c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#FFFF33", "#A65628", "#F781BF") + } if (reduce_lineage) { prot <- shortenLineage(prot, Lineage_col, abr_len = 3) From 84b80797fd5fc1ed4b99d74df7605818b8734823 Mon Sep 17 00:00:00 2001 From: Klangina Date: Tue, 29 Oct 2024 01:05:57 +0530 Subject: [PATCH 4/7] =?UTF-8?q?[FIXED]=20selectLongestDuplicate:=20no=20vi?= =?UTF-8?q?sible=20binding=20for=20global=20variable=20=E2=80=98AccNum?= =?UTF-8?q?=E2=80=99=20selectLongestDuplicate:=20no=20visible=20binding=20?= =?UTF-8?q?for=20global=20variable=20=20=E2=80=98row.orig=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Changes] Added @importFrom rlang .data to import the .data pronoun. Used .data$AccNum instead of AccNum to refer to the column within dplyr functions. Used .data$row.orig instead of row.orig to refer to the column within dplyr functions. Used mutate to initialise prot. Changed merge() to left_join() for consistency with dplyr. Used seq_len() instead of : for creating row numbers. Simplified the longest row selection using which.max(). Used filter() instead of negative indexing to remove rows. --- R/cleanup.R | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/R/cleanup.R b/R/cleanup.R index e93aa257..f7bf9eb9 100755 --- a/R/cleanup.R +++ b/R/cleanup.R @@ -668,8 +668,8 @@ cleanGeneDescription <- function(prot, column) { #' @param prot #' @param column #' -#' @importFrom dplyr arrange filter group_by pull n select summarize -#' @importFrom rlang sym +#' @importFrom dplyr arrange filter group_by pull n select summarize mutate +#' @importFrom rlang sym .data #' #' @return Describe return, in detail #' @export @@ -679,37 +679,38 @@ cleanGeneDescription <- function(prot, column) { #' selectLongestDuplicate() #' } selectLongestDuplicate <- function(prot, column) { - col <- sym(column) - - prot$row.orig <- 1:nrow(prot) + col <- rlang::sym(column) + prot <- prot %>% + mutate(row.orig = seq_len(n())) # Get list of duplicates dups <- prot %>% - group_by(AccNum) %>% - summarize("count" = n()) %>% + group_by(.data$AccNum) %>% + summarize(count = n()) %>% filter(count > 1) %>% - arrange(-count) %>% - merge(prot, by = "AccNum") + arrange(desc(count)) %>% + left_join(prot, by = "AccNum") - dup_acc <- dups$AccNum + dup_acc <- unique(dups$AccNum) - longest_rows <- c() - remove_rows <- c() + longest_rows <- integer() + remove_rows <- integer() for (acc in dup_acc) { - dup_rows <- dups %>% filter(AccNum == acc) + dup_rows <- dups %>% filter(.data$AccNum == acc) - longest <- dup_rows[which(nchar(pull(dup_rows, {{ col }})) == max(nchar(pull(dup_rows, {{ col }}))))[1], "row.orig"] + longest <- dup_rows$row.orig[which.max(nchar(pull(dup_rows, !!col)))] longest_rows <- c(longest_rows, longest) - to_remove <- dup_rows[which(dup_rows$row.orig != longest), "row.orig"][] + to_remove <- dup_rows$row.orig[dup_rows$row.orig != longest] - # dup_rows[which(nchar(pull(dup_rows,{{col}})) == max(nchar(pull(dup_rows,{{col}}))))[2:nrow(dup_rows)], "row.orig"] remove_rows <- c(remove_rows, to_remove) } # grab all the longest rows - unique_dups <- prot[-remove_rows, ] %>% select(-row.orig) + unique_dups <- prot %>% + filter(!.data$row.orig %in% remove_rows) %>% + select(-.data$row.orig) return(unique_dups) } From f62f69da68ec69c4ee8d40ab38b0f1840ef351b6 Mon Sep 17 00:00:00 2001 From: Klangina Date: Tue, 29 Oct 2024 01:11:18 +0530 Subject: [PATCH 5/7] Resolves Issue #114: Adding a blank commit to link PR to the issue --- R/cleanup.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/cleanup.R b/R/cleanup.R index f7bf9eb9..ba93a8b8 100755 --- a/R/cleanup.R +++ b/R/cleanup.R @@ -680,7 +680,6 @@ cleanGeneDescription <- function(prot, column) { #' } selectLongestDuplicate <- function(prot, column) { col <- rlang::sym(column) - prot <- prot %>% mutate(row.orig = seq_len(n())) # Get list of duplicates From 9cd85eb9b70f8bad0d3d8c10c4bf834eb3fc6e0b Mon Sep 17 00:00:00 2001 From: David Mayer Date: Wed, 30 Oct 2024 14:52:21 -0600 Subject: [PATCH 6/7] add additional .data prefix --- R/assign_job_queue.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/assign_job_queue.R b/R/assign_job_queue.R index 4dc58a54..e481f400 100644 --- a/R/assign_job_queue.R +++ b/R/assign_job_queue.R @@ -661,7 +661,7 @@ plotEstimatedWallTimes <- function() { .data$n_inputs) # sec to hrs df_walltimes <- df_walltimes |> - dplyr::mutate(est_walltime = est_walltime / 3600) + dplyr::mutate(est_walltime = .data$est_walltime / 3600) p <- ggplot2::ggplot(df_walltimes, ggplot2::aes(x = .data$n_inputs, y = .data$est_walltime, color = .data$advanced_opts)) + From 4667118b67889136182fc097c2cd2a323602f908 Mon Sep 17 00:00:00 2001 From: David Mayer Date: Wed, 30 Oct 2024 14:52:57 -0600 Subject: [PATCH 7/7] update docs/NAMESPACE --- NAMESPACE | 2 ++ man/plotStackedLineage.Rd | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index d858b069..6ae464f6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -232,6 +232,7 @@ importFrom(readr,write_file) importFrom(readr,write_lines) importFrom(readr,write_tsv) importFrom(rentrez,entrez_fetch) +importFrom(rlang,":=") importFrom(rlang,.data) importFrom(rlang,abort) importFrom(rlang,as_string) @@ -274,6 +275,7 @@ importFrom(tidyr,pivot_wider) importFrom(tidyr,replace_na) importFrom(tidyr,separate) importFrom(tidyr,unite) +importFrom(utils,combn) importFrom(viridis,scale_fill_viridis) importFrom(visNetwork,visEdges) importFrom(visNetwork,visGroups) diff --git a/man/plotStackedLineage.Rd b/man/plotStackedLineage.Rd index 63ae9b66..20acecd8 100644 --- a/man/plotStackedLineage.Rd +++ b/man/plotStackedLineage.Rd @@ -17,7 +17,8 @@ plotStackedLineage( legend.cols = 2, legend.size = 0.7, coord_flip = TRUE, - legend = TRUE + legend = TRUE, + cpcols = NULL ) } \arguments{ @@ -55,6 +56,8 @@ data (default is "Lineage").} (default is TRUE).} \item{legend}{Logical. Whether to display the legend (default is TRUE).} + +\item{cpcols}{} } \value{ A ggplot object representing a stacked bar plot showing the