Reference database report

knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)

Reference library overview

refdb:::check_fields(x, c("sequence", "taxonomy"))
x_seq <- x[[attributes(x)$refdb$sequence]]

Total number of sequences: r sum(!is.na(x_seq))

Number of unique sequences: r sum(!duplicated(x_seq[!is.na(x_seq)]))

refdb_plot_tax_barplot(x)

refdb_plot_tax_treemap(x)

if(all(c("latitude", "longitude") %in%
       names(refdb_get_fields(x, silent = TRUE)))
   ){
refdb_plot_map(x)
}

Check for spelling errors

check_typo <- refdb_check_tax_typo(x)
check_typo <- dplyr::bind_rows(check_typo, .id = "Level")

DT::datatable(check_typo,
              rownames = FALSE,
              options = list(searching = FALSE,
                             pageLength = 10
                             )
)

Check for taxonomic conflicts

check_taxo <- refdb_check_tax_conflict(x)
check_taxo <- dplyr::bind_rows(check_taxo, .id = "Level")
check_taxo <- dplyr::group_by(check_taxo, Level, Taxon)



format_taxo <- function(y) {
  tax <- stringr::str_split(y, " > ")
  tax <- do.call("rbind", tax)
  tax_test <- apply(tax, 2, function(x) length(unique(x)) == 1)
  sel <- seq(min(which(tax_test == FALSE)) - 1, length(tax_test))
  res <- apply(tax[, sel], 1, paste, collapse = " > ")
  if(min(sel) > 1) {
    res <- paste("... >", res)
  }
  res <- paste(res, collapse = "<br/>")
  return(res)
}

if(nrow(check_taxo) > 0) {
  check_taxo <- dplyr::summarise(check_taxo, Taxonomy = format_taxo(Taxonomy))
}

DT::datatable(check_taxo,
              rownames = FALSE,
              escape = FALSE,
              options = list(searching = FALSE,
                             pageLength = 10
                             )
)

Check for sequence conflicts

check_seqs <- refdb_check_seq_conflict(x)

if(nrow(check_seqs) == 0) {
  cat("No sequence conflict detected.")
} else {
  check_seqs <- dplyr::group_by(check_seqs, level_conflict, sequence)
  check_seqs <- dplyr::summarise(check_seqs, taxonomy = format_taxo(taxonomy))
  check_seqs <- dplyr::select(check_seqs, sequence, level_conflict, taxonomy)

  check_seqs$sequence <- paste('<span style="width: 250px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display:inline-block;">', check_seqs$sequence,'</span>')

  check_seqs <- setNames(check_seqs, c("Sequence", "Level", "Taxonomy"))

  DT::datatable(check_seqs,
                escape = FALSE,
                rownames = FALSE,
                options = list(searching = FALSE,
                               pageLength = 10))

}


Try the refdb package in your browser

Any scripts or data that you put into this service are public.

refdb documentation built on Sept. 22, 2022, 5:07 p.m.