Skip to content

Commit

Permalink
additional ipr2viz() global variable definitions
Browse files Browse the repository at this point in the history
- .data for NSE
- reference internal MolEvolvR pkg data for`iprscan_cols` and `lookup_table_cols`
- add Rd tags for `stats::as.formula()` and `ggplot2::unit()`

Resolves: https://github.com/JRaviLab/MolEvolvR/pull/64/files#r1793916461
  • Loading branch information
the-mayer committed Oct 9, 2024
1 parent 730842f commit 2998172
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ importFrom(ggplot2,theme)
importFrom(ggplot2,theme_classic)
importFrom(ggplot2,theme_grey)
importFrom(ggplot2,theme_minimal)
importFrom(ggplot2,unit)
importFrom(ggplot2,xlab)
importFrom(ggplot2,ylab)
importFrom(grDevices,adjustcolor)
Expand Down Expand Up @@ -237,6 +238,7 @@ importFrom(sendmailR,sendmail)
importFrom(seqinr,dist.alignment)
importFrom(seqinr,read.alignment)
importFrom(shiny,showNotification)
importFrom(stats,as.formula)
importFrom(stats,complete.cases)
importFrom(stats,logLik)
importFrom(stats,na.omit)
Expand Down
31 changes: 16 additions & 15 deletions R/ipr2viz.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ find_top_acc <- function(infile_full,
#'
#' @importFrom dplyr distinct filter select
#' @importFrom gggenes geom_gene_arrow geom_subgene_arrow
#' @importFrom ggplot2 aes aes_string as_labeller element_text facet_wrap ggplot guides margin scale_fill_manual theme theme_minimal ylab
#' @importFrom ggplot2 aes aes_string as_labeller element_text facet_wrap ggplot guides margin scale_fill_manual theme theme_minimal unit ylab
#' @importFrom readr read_tsv
#' @importFrom tidyr pivot_wider
#' @importFrom stats as.formula
#'
#' @return
#' @export
Expand All @@ -135,10 +136,10 @@ ipr2viz <- function(infile_ipr = NULL, infile_full = NULL, accessions = c(),
ADDITIONAL_COLORS <- sample(CPCOLS, 1000, replace = TRUE)
CPCOLS <- append(x = CPCOLS, values = ADDITIONAL_COLORS)
## Read IPR file
ipr_out <- read_tsv(infile_ipr, col_names = T, col_types = iprscan_cols)
ipr_out <- ipr_out %>% filter(Name %in% accessions)
ipr_out <- read_tsv(infile_ipr, col_names = T, col_types = MolEvolvR::iprscan_cols)
ipr_out <- ipr_out %>% filter(.data$Name %in% accessions)
analysis_cols <- paste0("DomArch.", analysis)
infile_full <- infile_full %>% select(analysis_cols, Lineage_short, QueryName, PcPositive, AccNum)
infile_full <- infile_full %>% select(.data$analysis_cols, .data$Lineage_short, .data$QueryName, .data$PcPositive, .data$AccNum)
## To filter by Analysis
analysis <- paste(analysis, collapse = "|")
## @SAM: This can't be set in stone since the analysis may change!
Expand All @@ -158,22 +159,22 @@ ipr2viz <- function(infile_ipr = NULL, infile_full = NULL, accessions = c(),
## Need to fix this eventually based on the 'real' gene orientation! :)
ipr_out$Strand <- rep("forward", nrow(ipr_out))

ipr_out <- ipr_out %>% arrange(AccNum, StartLoc, StopLoc)
ipr_out <- ipr_out %>% arrange(.data$AccNum, .data$StartLoc, .data$StopLoc)
ipr_out_sub <- filter(
ipr_out,
grepl(pattern = analysis, x = Analysis)
grepl(pattern = analysis, x = .data$Analysis)
)
# dynamic analysis labeller
analyses <- ipr_out_sub %>%
select(Analysis) %>%
select(.data$Analysis) %>%
distinct()
analysis_labeler <- analyses %>%
pivot_wider(names_from = Analysis, values_from = Analysis)
pivot_wider(names_from = .data$Analysis, values_from = .data$Analysis)

lookup_tbl_path <- "/data/research/jravilab/common_data/cln_lookup_tbl.tsv"
lookup_tbl <- read_tsv(lookup_tbl_path, col_names = T, col_types = lookup_table_cols)
lookup_tbl <- read_tsv(lookup_tbl_path, col_names = T, col_types = MolEvolvR::lookup_table_cols)

lookup_tbl <- lookup_tbl %>% select(-ShortName) # Already has ShortName -- Just needs SignDesc
lookup_tbl <- lookup_tbl %>% select(-.data$ShortName) # Already has ShortName -- Just needs SignDesc
# ipr_out_sub = ipr_out_sub %>% select(-ShortName)
# TODO: Fix lookup table and uncomment below
# ipr_out_sub <- merge(ipr_out_sub, lookup_tbl, by.x = "DB.ID", by.y = "DB.ID")
Expand All @@ -196,7 +197,7 @@ ipr2viz <- function(infile_ipr = NULL, infile_full = NULL, accessions = c(),
), color = "white") +
geom_gene_arrow(fill = NA, color = "grey") +
# geom_blank(data = dummies) +
facet_wrap(~Analysis,
facet_wrap(~.data$Analysis,
strip.position = "top", ncol = 5,
labeller = as_labeller(analysis_labeler)
) +
Expand All @@ -217,9 +218,9 @@ ipr2viz <- function(infile_ipr = NULL, infile_full = NULL, accessions = c(),
plot <- ggplot(
ipr_out_sub,
aes(
xmin = 1, xmax = SLength,
y = Analysis, # y = AccNum
label = ShortName
xmin = 1, xmax = .data$SLength,
y = .data$Analysis, # y = AccNum
label = .data$ShortName
)
) +
geom_subgene_arrow(data = ipr_out_sub, aes_string(
Expand Down Expand Up @@ -296,7 +297,7 @@ ipr2viz_web <- function(infile_ipr,
## @SAM, colnames, merges, everything neeeds to be done now based on the
## combined lookup table from "common_data"
lookup_tbl_path <- "/data/research/jravilab/common_data/cln_lookup_tbl.tsv"
lookup_tbl <- read_tsv(lookup_tbl_path, col_names = T, col_types = .data$lookup_table_cols)
lookup_tbl <- read_tsv(lookup_tbl_path, col_names = T, col_types = MolEvolvR::lookup_table_cols)

## Read IPR file and subset by Accessions
ipr_out <- read_tsv(infile_ipr, col_names = T)
Expand Down

0 comments on commit 2998172

Please sign in to comment.