diff --git a/DESCRIPTION b/DESCRIPTION index a477e1df..a6701ae8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,16 +1,16 @@ Package: covmuller Type: Package Title: A tool to model COVID19 variant prevalence using data from GISAID -Version: 0.1.2.0001 -Date: 2023-09-19 +Version: 0.1.2.0002 +Date: 2024-01-12 Author: Saket Choudhary Maintainer: Saket Choudhary Description: covmuller can be used to process data from GISAID and perform modeling on variant prevalence with lots of supported visualisation. -License: MIT +License: MIT + file LICENSE Encoding: UTF-8 LazyData: true -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.0 URL: https://saketkc.github.io/covmuller BugReports: https://github.com/saketkc/covmuller/issues Depends: @@ -30,6 +30,7 @@ Imports: magrittr, nnet, patchwork, + readr, reshape2, RJSONIO, scales, diff --git a/NAMESPACE b/NAMESPACE index ddd866d7..b04981a1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -51,6 +51,7 @@ importFrom(dplyr,mutate) importFrom(dplyr,pull) importFrom(dplyr,recode) importFrom(dplyr,rename) +importFrom(dplyr,select) importFrom(dplyr,select_if) importFrom(dplyr,summarise) importFrom(dplyr,summarise_all) @@ -77,7 +78,9 @@ importFrom(ggplot2,ggtitle) importFrom(ggplot2,guide_axis) importFrom(ggplot2,guides) importFrom(ggplot2,labs) +importFrom(ggplot2,position_dodge) importFrom(ggplot2,scale_color_identity) +importFrom(ggplot2,scale_color_manual) importFrom(ggplot2,scale_fill_brewer) importFrom(ggplot2,scale_fill_gradient2) importFrom(ggplot2,scale_x_date) @@ -101,7 +104,11 @@ importFrom(scales,cut_short_scale) importFrom(scales,label_number) importFrom(scales,label_percent) importFrom(splines,ns) +importFrom(stats,as.formula) +importFrom(stats,median) +importFrom(stats,predict) importFrom(stringi,stri_split_fixed) +importFrom(stringr,str_count) importFrom(stringr,str_split_fixed) importFrom(stringr,str_squish) importFrom(stringr,str_to_title) @@ -114,4 +121,6 @@ importFrom(tsibble,scale_x_yearweek) importFrom(tsibble,yearmonth) importFrom(tsibble,yearweek) importFrom(utils,URLencode) +importFrom(utils,read.csv) +importFrom(utils,untar) importFrom(zoo,as.yearmon) diff --git a/R/fetch_data.R b/R/fetch_data.R index 49720646..fb57113d 100644 --- a/R/fetch_data.R +++ b/R/fetch_data.R @@ -118,7 +118,7 @@ GetIndiaHospitalization <- function(url = "") { #' @returns A data frame containing monthly cases for each state in long form #' @importFrom magrittr %>% -#' @importFrom dplyr arrange group_by summarise_all rename +#' @importFrom dplyr arrange group_by select summarise_all rename #' @importFrom readr read_csv #' @importFrom reshape2 melt #' @export diff --git a/R/gisaid.R b/R/gisaid.R index 329dea81..5f9901ee 100644 --- a/R/gisaid.R +++ b/R/gisaid.R @@ -8,6 +8,7 @@ #' @importFrom stringr str_split_fixed str_trim #' @importFrom tools file_ext #' @importFrom data.table fread +#' @importFrom utils untar #' @export ReadGISAIDMetada <- function(path, showProgress = FALSE, ...) { file.ext <- file_ext(path) @@ -85,6 +86,7 @@ FormatGISAIDMetadata <- function(df, collection_col = "Collection date", submiss #' @returns A dataframe with all the instrument related metadata #' @importFrom stringi stri_split_fixed #' @importFrom dplyr bind_rows distinct +#' @importFrom utils read.csv #' @export ReadAuspiceInstrument <- function(path) { metadata <- list() @@ -94,7 +96,7 @@ ReadAuspiceInstrument <- function(path) { )) { date_path <- unlist(stri_split_fixed(str = file, pattern = "/")) date_path <- date_path[length(date_path) - 1] - metadata[[date_path]] <- read.csv(file, sep = "\t") + metadata[[date_path]] <- read.csv(file = file, sep = "\t") } seq_metadata <- bind_rows(metadata) %>% distinct() diff --git a/R/model.R b/R/model.R index 7d94b485..b1e79914 100644 --- a/R/model.R +++ b/R/model.R @@ -1,3 +1,4 @@ +#' @importFrom stats as.formula #' @importFrom magrittr %>% #' @importFrom tibble deframe #' @importFrom nnet multinom @@ -14,6 +15,7 @@ FitMultinom <- function(data, return(fit) } +#' @importFrom stats predict #' @importFrom magrittr %>% #' @importFrom tibble deframe #' @importFrom nnet multinom diff --git a/R/utilities.R b/R/utilities.R index c8e86958..5cc81bfd 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -5,8 +5,15 @@ #' @returns A vector with dates converted to MonthYear format (zoo::as.yearmon) #' @importFrom dplyr pull #' @importFrom zoo as.yearmon +#' @importFrom stringr str_count #' @export GetMonthYear <- function(datecol, datefmt = "%Y-%m-%d") { + number_dashes <- str_count(string = datecol, pattern = "-") + if (datefmt == "%Y-%m-%d"){ + datecol[number_dashes == 1] <- paste0(datecol[number_dashes == 1], "-01") + } else if (datefmt == "%d-%m-%Y"){ + datecol[number_dashes == 1] <- paste0("01-", datecol[number_dashes == 1]) + } Date <- as.Date(datecol, format = datefmt) Month <- strftime(Date, "%m") Year <- strftime(Date, "%Y") diff --git a/R/visualization.R b/R/visualization.R index 5ef6eac6..2a75ff2e 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -31,6 +31,7 @@ CovmullerTheme <- function() { #' @importFrom hrbrthemes theme_ipsum #' @importFrom ggtext element_markdown #' @importFrom patchwork wrap_plots +#' @importFrom stats median #' @export PlotTotalHeatmap <- function(df, color_legend = "Total cases") { df_india <- df %>% filter(State == "India") @@ -111,7 +112,7 @@ PlotSequencedPropHeatmap <- function(df) { #' @importFrom magrittr %>% #' @importFrom tibble deframe -#' @importFrom ggplot2 aes_string coord_cartesian ggplot geom_bar geom_text labs scale_y_continuous scale_x_discrete xlab ylab guide_axis +#' @importFrom ggplot2 aes_string coord_cartesian ggplot geom_bar geom_text labs scale_y_continuous scale_x_discrete xlab ylab guide_axis position_dodge #' @importFrom scales comma label_percent label_number cut_short_scale #' @importFrom ggtext element_markdown #' @importFrom patchwork wrap_plots @@ -189,7 +190,7 @@ BarPlot <- function(df, xaxis = "MonthYear", return(wrap_plots(p)) } -#' @importFrom ggplot2 ggplot geom_bar labs scale_fill_brewer scale_x_discrete xlab ylab guide_axis +#' @importFrom ggplot2 ggplot geom_bar labs scale_fill_brewer scale_x_discrete xlab ylab guide_axis scale_color_manual #' @importFrom scales label_number cut_short_scale #' @importFrom ggtext element_markdown #' @importFrom patchwork wrap_plots @@ -234,7 +235,7 @@ PlotMullerDailyPrevalence <- function(df, ncol = 4) { wrap_plots(p) } -#' @importFrom ggplot2 ggplot geom_line geom_label scale_fill_brewer scale_y_continuous xlab ylab labs ggtitle guide_axis theme element_text +#' @importFrom ggplot2 ggplot geom_line geom_label scale_fill_brewer scale_y_continuous xlab ylab labs ggtitle guide_axis theme element_text scale_color_manual #' @importFrom scales label_number cut_short_scale #' @importFrom gganimate transition_reveal view_follow animate gifski_renderer #' @importFrom tsibble scale_x_yearweek @@ -254,7 +255,7 @@ PlotVariantPrevalenceAnimated <- function(df, title = NULL, caption = "**Source: ) + geom_line() + scale_x_yearweek(date_breaks = date_breaks, date_labels = "%d %b %Y", guide = guide_axis(angle = 90)) + - scale_y_continuous(label = label_number(accuracy = 1, scale_cut = cut_short_scale())) + # , trans = trans_y) + + scale_y_continuous(labels = label_number(accuracy = 1, scale_cut = cut_short_scale())) + # , trans = trans_y) + geom_label(hjust = 0, aes(label = variant), nudge_x = 10, show.legend = FALSE) + geom_point() + coord_cartesian(ylim = c(0, NA), clip = "off") + diff --git a/docs/articles/USA_animated.gif b/docs/articles/USA_animated.gif index a536af28..afa8f6d2 100644 Binary files a/docs/articles/USA_animated.gif and b/docs/articles/USA_animated.gif differ diff --git a/docs/articles/VariantAnimation-USA_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/VariantAnimation-USA_files/figure-html/unnamed-chunk-5-1.png index dc0209f6..e8466b8c 100644 Binary files a/docs/articles/VariantAnimation-USA_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/VariantAnimation-USA_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html index e984a43d..720838eb 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -16,7 +16,7 @@ covmuller - 0.1.2.0001 + 0.1.2.0002