Skip to content

Commit f84ff97

Browse files
reduced number of dependencies
1 parent 5122b57 commit f84ff97

File tree

9 files changed

+156
-95
lines changed

9 files changed

+156
-95
lines changed

DESCRIPTION

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,11 @@ Imports:
2020
stringr,
2121
ggplot2,
2222
igraph,
23-
scales,
2423
grid,
2524
taxize,
2625
seqinr,
27-
reshape2,
28-
zoo,
29-
traits,
30-
RColorBrewer,
3126
RCurl,
3227
ape,
33-
reshape,
3428
stats,
3529
grDevices,
3630
utils,
@@ -39,26 +33,23 @@ Imports:
3933
magrittr,
4034
readr,
4135
rlang,
42-
phylotate,
4336
ggfittext,
4437
vegan,
45-
ggrepel,
4638
cowplot,
4739
GA,
4840
Rcpp,
4941
crayon,
50-
svglite,
51-
viridisLite,
5242
tibble,
53-
R6,
54-
jsonlite
43+
R6
5544
Suggests:
5645
knitr,
5746
rmarkdown,
5847
testthat,
5948
zlibbioc,
6049
BiocManager,
6150
phyloseq,
51+
phylotate,
52+
traits,
6253
biomformat
6354
VignetteBuilder: knitr
6455
RoxygenNote: 7.1.1

NAMESPACE

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@ export(write_rdp)
238238
export(write_silva_fasta)
239239
export(write_unite_general)
240240
export(zero_low_counts)
241-
import(R6)
242-
import(jsonlite)
243241
importFrom(Rcpp,sourceCpp)
244242
importFrom(dplyr,contains)
245243
importFrom(dplyr,ends_with)

R/heat_tree--mapping.R

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' Rescale numeric vector to have specified minimum and maximum.
22
#'
33
#' Rescale numeric vector to have specified minimum and maximum, but allow for hard boundaries.
4-
#' Light wrapper for scales::rescale
4+
#' It is a slightly modified version of scales::rescale, incorporating scales::zero_range, both by Hadley Wickham used under the conditions of the MIT license.
55
#'
66
#' @param x values to rescale
77
#' @param to range to scale to
@@ -11,7 +11,38 @@
1111
#' @keywords internal
1212
rescale <- function (x, to = c(0, 1), from = range(x, na.rm = TRUE, finite = TRUE), hard_bounds = TRUE)
1313
{
14-
result <- scales::rescale(x, to, from)
14+
# COPIED FROM scales::zero_range by Hadley Wickham
15+
zero_range <- function(x, tol = 1000 * .Machine$double.eps) {
16+
if (length(x) == 1) return(TRUE)
17+
if (length(x) != 2) stop("x must be length 1 or 2")
18+
if (any(is.na(x))) return(NA)
19+
20+
# Special case: if they are equal as determined by ==, then there
21+
# is zero range. Also handles (Inf, Inf) and (-Inf, -Inf)
22+
if (x[1] == x[2]) return(TRUE)
23+
24+
# If we reach this, then x must be (-Inf, Inf) or (Inf, -Inf)
25+
if (all(is.infinite(x))) return(FALSE)
26+
27+
# Take the smaller (in magnitude) value of x, and use it as the scaling
28+
# factor.
29+
m <- min(abs(x))
30+
31+
# If we get here, then exactly one of the x's is 0. Return FALSE
32+
if (m == 0) return(FALSE)
33+
34+
# If x[1] - x[2] (scaled to 1) is smaller than tol, then return
35+
# TRUE; otherwise return FALSE
36+
abs((x[1] - x[2]) / m) < tol
37+
}
38+
39+
# COPIED FROM scales::rescale by Hadley Wickham
40+
if (zero_range(from) || zero_range(to)) {
41+
return(ifelse(is.na(x), NA, mean(to)))
42+
}
43+
result <- (x - from[1]) / diff(from) * diff(to) + to[1]
44+
45+
# Hard bound implementations
1546
if (hard_bounds) {
1647
result[result > max(to)] <- max(to)
1748
result[result < min(to)] <- min(to)
@@ -64,7 +95,9 @@ apply_color_scale <- function(values, color_series, interval = NULL, no_color_in
6495
#'
6596
#' @export
6697
quantative_palette <- function() {
67-
return(c("#BBBBBB", rev(viridisLite::viridis(7, begin = .4, end = .9))))
98+
# produced with: c("#BBBBBB", rev(viridisLite::viridis(7, begin = .4, end = .9)))
99+
return(c("#BBBBBB", "#BBDF27FF", "#85D44AFF", "#54C568FF", "#2FB47CFF",
100+
"#1FA188FF", "#228C8DFF", "#2A788EFF"))
68101
}
69102

70103

@@ -79,7 +112,10 @@ quantative_palette <- function() {
79112
#'
80113
#' @export
81114
qualitative_palette <- function() {
82-
return(c(RColorBrewer::brewer.pal(9, "Set1"), RColorBrewer::brewer.pal(9, "Pastel1")))
115+
# produced with c(RColorBrewer::brewer.pal(9, "Set1"), RColorBrewer::brewer.pal(9, "Pastel1"))
116+
return(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#FFFF33",
117+
"#A65628", "#F781BF", "#999999", "#FBB4AE", "#B3CDE3", "#CCEBC5",
118+
"#DECBE4", "#FED9A6", "#FFFFCC", "#E5D8BD", "#FDDAEC", "#F2F2F2"))
83119
}
84120

85121
#' The default diverging color palette

R/heat_tree--vertex_size.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
molten_dist <- function(x, y) {
1818
data <- as.matrix(stats::dist(cbind(x, y)))
1919
data[!lower.tri(data)] <- NA
20-
data <- reshape2::melt(data)
21-
names(data) <- c("index_1", "index_2", "distance")
22-
data[!is.na(data$distance), ]
20+
molten_data <- data.frame(index_1 = rep(1:nrow(data), ncol(data)), index_2 = rep(1:nrow(data), each = ncol(data)))
21+
molten_data$distance <- mapply(function(i1, i2) data[i1, i2], molten_data$index_1, molten_data$index_2)
22+
molten_data[!is.na(molten_data$distance), ]
2323
}
2424

2525
#===================================================================================================

R/old_taxa--package.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@
208208
#' Checkout the vignette
209209
#' (`browseVignettes("taxa")`) for detailed introduction and examples.
210210
#'
211-
#' @import R6 jsonlite
212211
#' @name taxa-package
213212
#' @docType package
214213
#' @keywords package

R/parsers.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ parse_qiime_biom <- function(file, class_regex = "(.*)",
399399
#'
400400
#' @export
401401
parse_newick <- function(file = NULL, text = NULL) {
402+
# Check that the "phylotate" package has been installed
403+
check_for_pkg("phylotate")
404+
402405
# Check that `file` and `text` and `table` are not used together
403406
if (sum(c(is.null(file), is.null(text))) != 1) {
404407
stop(paste0('Either "file" or "text" must be supplied, but not both.'))

R/sequence_download.R

Lines changed: 63 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,63 @@
11
#' Download representative sequences for a taxon
2-
#'
3-
#' Downloads a sample of sequences meant to evenly capture the diversity of a given taxon.
4-
#' Can be used to get a shallow sampling of vast groups.
5-
#' \strong{CAUTION:} This function can make MANY queries to Genbank depending on arguments given and
6-
#' can take a very long time.
7-
#' Choose your arguments carefully to avoid long waits and needlessly stressing NCBI's servers.
8-
#' Use a downloaded database and a parser from the \code{taxa} package when possible.
9-
#'
10-
#' @param name (\code{character} of length 1) The taxon to download a sample of sequences for.
11-
#' @param id (\code{character} of length 1) The taxon id to download a sample of sequences for.
12-
#' @param target_rank (\code{character} of length 1) The finest taxonomic rank at which
13-
#' to sample. The finest rank at which replication occurs. Must be a finer rank than
14-
#' \code{taxon}.
15-
#' @param min_counts (named \code{numeric}) The minimum number of sequences to download for each
16-
#' taxonomic rank. The names correspond to taxonomic ranks.
17-
#' @param max_counts (named \code{numeric}) The maximum number of sequences to download for each
18-
#' taxonomic rank. The names correspond to taxonomic ranks.
19-
#' @param interpolate_min (\code{logical}) If \code{TRUE}, values supplied to \code{min_counts}
20-
#' and \code{min_children} will be used to infer the values of intermediate ranks not
21-
#' specified. Linear interpolation between values of specified ranks will be used to determine
22-
#' values of unspecified ranks.
23-
#' @param interpolate_max (\code{logical}) If \code{TRUE}, values supplied to \code{max_counts}
24-
#' and \code{max_children} will be used to infer the values of intermediate ranks not
25-
#' specified. Linear interpolation between values of specified ranks will be used to determine
26-
#' values of unspecified ranks.
27-
#' @param min_children (named \code{numeric}) The minimum number sub-taxa of taxa for a given
28-
#' rank must have for its sequences to be searched. The names correspond to taxonomic ranks.
29-
#' @param max_children (named \code{numeric}) The maximum number sub-taxa of taxa for a given
30-
#' rank must have for its sequences to be searched. The names correspond to taxonomic ranks.
31-
#' @param verbose (\code{logical}) If \code{TRUE}, progress messages will be printed.
32-
#' @inheritParams traits::ncbi_searcher
33-
#'
2+
#'
3+
#' Downloads a sample of sequences meant to evenly capture the diversity of a
4+
#' given taxon. Can be used to get a shallow sampling of vast groups.
5+
#' \strong{CAUTION:} This function can make MANY queries to Genbank depending on
6+
#' arguments given and can take a very long time. Choose your arguments
7+
#' carefully to avoid long waits and needlessly stressing NCBI's servers. Use a
8+
#' downloaded database and a parser from the \code{taxa} package when possible.
9+
#'
10+
#' @param name (\code{character} of length 1) The taxon to download a sample of
11+
#' sequences for.
12+
#' @param id (\code{character} of length 1) The taxon id to download a sample of
13+
#' sequences for.
14+
#' @param target_rank (\code{character} of length 1) The finest taxonomic rank
15+
#' at which to sample. The finest rank at which replication occurs. Must be a
16+
#' finer rank than \code{taxon}.
17+
#' @param min_counts (named \code{numeric}) The minimum number of sequences to
18+
#' download for each taxonomic rank. The names correspond to taxonomic ranks.
19+
#' @param max_counts (named \code{numeric}) The maximum number of sequences to
20+
#' download for each taxonomic rank. The names correspond to taxonomic ranks.
21+
#' @param interpolate_min (\code{logical}) If \code{TRUE}, values supplied to
22+
#' \code{min_counts} and \code{min_children} will be used to infer the values
23+
#' of intermediate ranks not specified. Linear interpolation between values of
24+
#' specified ranks will be used to determine values of unspecified ranks.
25+
#' @param interpolate_max (\code{logical}) If \code{TRUE}, values supplied to
26+
#' \code{max_counts} and \code{max_children} will be used to infer the values
27+
#' of intermediate ranks not specified. Linear interpolation between values of
28+
#' specified ranks will be used to determine values of unspecified ranks.
29+
#' @param min_children (named \code{numeric}) The minimum number sub-taxa of
30+
#' taxa for a given rank must have for its sequences to be searched. The names
31+
#' correspond to taxonomic ranks.
32+
#' @param max_children (named \code{numeric}) The maximum number sub-taxa of
33+
#' taxa for a given rank must have for its sequences to be searched. The names
34+
#' correspond to taxonomic ranks.
35+
#' @param seqrange (character) Sequence range, as e.g., "1:1000". This is the
36+
#' range of sequence lengths to search for. So "1:1000" means search for
37+
#' sequences from 1 to 1000 characters in length.
38+
#' @param getrelated (logical) If TRUE, gets the longest sequences of a species
39+
#' in the same genus as the one searched for. If FALSE, returns nothing if no
40+
#' match found.
41+
#' @param fuzzy (logical) Whether to do fuzzy taxonomic ID search or exact
42+
#' search. If \code{TRUE}, we use \code{xXarbitraryXx[porgn:__txid<ID>]}, but
43+
#' if \code{FALSE}, we use \code{txid<ID>}. Default: \code{FALSE}
44+
#' @param limit (\code{numeric}) Number of sequences to search for and return.
45+
#' Max of 10,000. If you search for 6000 records, and only 5000 are found, you
46+
#' will of course only get 5000 back.
47+
#' @param entrez_query (\code{character}; length 1) An Entrez-format query to
48+
#' filter results with. This is useful to search for sequences with specific
49+
#' characteristics. The format is the same as the one used to seach genbank.
50+
#' (\url{https://www.ncbi.nlm.nih.gov/books/NBK3837/#EntrezHelp.Entrez_Searching_Options})
51+
#'
52+
#'
53+
#' @param hypothetical (\code{logical}; length 1) If \code{FALSE}, an attempt
54+
#' will be made to not return hypothetical or predicted sequences judging from
55+
#' accession number prefixs (XM and XR). This can result in less than the
56+
#' \code{limit} being returned even if there are more sequences available,
57+
#' since this filtering is done after searching NCBI.
58+
#' @param verbose (\code{logical}) If \code{TRUE}, progress messages will be
59+
#' printed.
60+
#'
3461
#' @examples
3562
#'
3663
#' \dontrun{
@@ -54,6 +81,8 @@ ncbi_taxon_sample <- function(name = NULL, id = NULL, target_rank,
5481
seqrange = "1:3000", getrelated = FALSE,
5582
fuzzy = TRUE, limit = 10, entrez_query = NULL,
5683
hypothetical = FALSE, verbose = TRUE) {
84+
# Check that the "traits" package has been installed
85+
check_for_pkg("traits")
5786

5887
run_once <- function(name, id) {
5988
default_target_max <- 20
@@ -115,7 +144,7 @@ ncbi_taxon_sample <- function(name = NULL, id = NULL, target_rank,
115144
along.with = between))
116145
return(NULL)
117146
}
118-
zoo::rollapply(names(user_limits), width = 2, set_default_counts)
147+
lapply(seq_len(length(names(user_limits)) - 1), function(i) set_default_counts(names(user_limits)[i:(i+1)]))
119148
}
120149

121150
# Extend boundry values to adjacent undefined values - - - - - - - - - - - - - - - - - - - - - -
@@ -142,7 +171,7 @@ ncbi_taxon_sample <- function(name = NULL, id = NULL, target_rank,
142171
level_min_children <- get_level_limit(min_children, 0, target_rank, interpolate_min,
143172
extend_min = TRUE)
144173

145-
# Recursivly sample taxon ------------------------------------------------------------------------
174+
# Recursively sample taxon ------------------------------------------------------------------------
146175
recursive_sample <- function(id, rank, name) {
147176
cat("Processing '", name, "' (uid: ", id, ", rank: ", as.character(rank), ")", "\n",
148177
sep = "")

man/ncbi_taxon_sample.Rd

Lines changed: 43 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)