@@ -193,6 +193,50 @@ update_live_igdata <- function(check.only=FALSE)
193193}
194194
195195
196+ # ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
197+ # ## .make_aux_data_md5sum_df()
198+ # ##
199+
200+ .compute_aux_files_md5sums <- function (which = c(" live" , " original" ))
201+ {
202+ aux_dir <- file.path(.path_to_igdata(which ), " optional_file" )
203+ aux_files <- list.files(aux_dir , pattern = " \\ .(aux|frame)$" )
204+ setNames(md5sum(file.path(aux_dir , aux_files )), aux_files )
205+ }
206+
207+ .make_aux_data_md5sum_df <- function ()
208+ {
209+ live_md5sums <- .compute_aux_files_md5sums(" live" )
210+ orig_md5sums <- .compute_aux_files_md5sums(" original" )
211+ files <- sort(union(names(live_md5sums ), names(orig_md5sums )))
212+ ans <- data.frame (file = files ,
213+ live = unname(live_md5sums [files ]),
214+ original = unname(orig_md5sums [files ]))
215+ class(ans ) <- c(" aux_data_md5sum_df" , class(ans ))
216+ ans
217+ }
218+
219+ .aux_data_md5sum_df_as_character <- function (x )
220+ {
221+ EXPECTED_COLNAMES <- c(" file" , " live" , " original" )
222+ stopifnot(is.data.frame(x ), identical(colnames(x ), EXPECTED_COLNAMES ))
223+ note <- character (nrow(x ))
224+ note [x $ live != x $ original ] <- " (updated)"
225+ note [is.na(x $ original )] <- " (new)"
226+ ans <- character (3L * nrow(x ))
227+ ans [3L * seq_len(nrow(x )) - 2L ] <- paste0(" - file '" , x $ file , " '" )
228+ ans [3L * seq_len(nrow(x )) - 1L ] <- paste0(" live: " , x $ live , note )
229+ ans [3L * seq_len(nrow(x )) ] <- paste0(" original: " , x $ original )
230+ ans
231+ }
232+
233+ print.aux_data_md5sum_df <- function (x , margin = " " , ... )
234+ {
235+ y <- .aux_data_md5sum_df_as_character(x )
236+ cat(paste0(margin , y ), sep = " \n " )
237+ }
238+
239+
196240# ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
197241# ## time_since_live_igdata_last_checked()
198242# ## igdata_info()
@@ -212,56 +256,75 @@ update_live_igdata <- function(check.only=FALSE)
212256 if (file.exists(path )) readLines(path ) else NA_character_
213257}
214258
259+ .how_old <- function (datetime , units = " days" )
260+ {
261+ stopifnot(isSingleNonWhiteString(datetime ))
262+ as.double(difftime(Sys.time(), as.POSIXct(datetime ), units = units ))
263+ }
264+
265+ # ## Used in .onLoad() hook.
215266# ## By default, time is returned in number of days.
216267time_since_live_igdata_last_checked <- function (units = " days" )
217268{
218269 igdata_subdir <- file.path(igblastr_cache(LIVE_IGDATA ), " optional_file" )
219270 last_checked <- .get_last_checked(igdata_subdir )
220271 if (is.na(last_checked ))
221272 return (Inf )
222- as.double(difftime(Sys.time(), as.POSIXct( last_checked ) , units = units ) )
273+ .how_old( last_checked , units = units )
223274}
224275
225- .dt2msg <- function (dt )
276+ .annotate_how_old <- function (dt )
226277{
227- if (is.infinite(dt ))
228- return (" n/a" )
229- msg <- paste0(sprintf(" %.2f" , dt ), " days" )
278+ msg <- paste0(sprintf(" %.2f" , dt ), " days ago" )
230279 if (dt > 30 )
231280 msg <- paste0(msg , " --> time to run 'update_live_igdata()' again" )
232281 msg
233282}
234283
235- print.igdata_info <- function (x , ... )
284+ .annotate_last_checked <- function (last_checked )
236285{
237- cat(named_list_as_character(x ), sep = " \n " )
286+ if (is.na(last_checked ))
287+ return (paste0(" not checked yet --> " ,
288+ " run 'update_live_igdata()' to check for " ,
289+ " new updates available at NCBI" ))
290+ dt <- .how_old(last_checked )
291+ paste0(last_checked , " (" , .annotate_how_old(dt ), " )" )
238292}
239293
240294igdata_info <- function ()
241295{
242296 live_igdata <- .path_to_igdata(" live" )
243297 igdata_subdir <- file.path(live_igdata , " optional_file" )
244298 last_checked <- .get_last_checked(igdata_subdir )
245- if (is.na(last_checked ))
246- last_checked <- paste0(" not checked yet --> " ,
247- " run 'update_live_igdata()' to check for\n " ,
248- " new updates available at NCBI" )
249299 last_updated <- .get_last_updated(igdata_subdir )
250- dt <- time_since_live_igdata_last_checked()
251300 if (is.na(last_updated ))
252301 last_updated <- " not updated yet"
253- original_igdata <- .path_to_igdata(" original" )
254302 ans <- list (
255303 live_igdata = live_igdata ,
256- last_checked = last_checked ,
257- time_since_last_checked = .dt2msg(dt ),
304+ last_checked = .annotate_last_checked(last_checked ),
258305 last_updated = last_updated ,
259- original_igdata = original_igdata
306+ original_igdata = .path_to_igdata(" original" ),
307+ aux_data_md5sums = .make_aux_data_md5sum_df()
260308 )
261309 class(ans ) <- " igdata_info"
262310 ans
263311}
264312
313+ print.igdata_info <- function (x , ... )
314+ {
315+ stopifnot(is.list(x ))
316+ md5sum_df <- x $ aux_data_md5sums
317+ if (! is.null(md5sum_df ))
318+ x $ aux_data_md5sums <- NULL
319+ keyvals <- named_list_as_pretty_keyvals(x )
320+ if (! is.null(md5sum_df )) {
321+ y <- .aux_data_md5sum_df_as_character(md5sum_df )
322+ keyval <- paste0(" aux_data_md5sums:\n " , paste0(" " , y , collapse = " \n " ))
323+ keyvals <- c(keyvals , keyval )
324+ }
325+ cat(keyvals , sep = " \n " )
326+ }
327+
265328
266329# ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
267330# ## get_igblast_auxiliary_data()
@@ -271,11 +334,11 @@ get_igblast_auxiliary_data <- function(organism, which=c("live", "original"))
271334{
272335 organism <- normalize_igblast_organism(organism )
273336 which <- match.arg(which )
274- dirpath <- file.path(.path_to_igdata(which ), " optional_file" )
275- auxiliary_data <- file.path(dirpath , paste0(organism , " _gl.aux" ))
276- if (! file.exists(auxiliary_data ))
277- stop(wmsg(" no auxiliary data found in " , dirpath , " for " , organism ))
278- auxiliary_data
337+ aux_dir <- file.path(.path_to_igdata(which ), " optional_file" )
338+ aux_file <- file.path(aux_dir , paste0(organism , " _gl.aux" ))
339+ if (! file.exists(aux_file ))
340+ stop(wmsg(" no auxiliary data found in " , aux_dir , " for " , organism ))
341+ aux_file
279342}
280343
281344
0 commit comments