|
1 | 1 | #' Score samples using the ASCI tool |
2 | 2 | #' |
3 | 3 | #' @param taxain \code{data.frame} for input taxonomy data |
4 | | -#' @param sitein \code{data.frame} for input site data |
5 | 4 | #' @param tax chr string indicating output to return from a specific taxa, must one to many of \code{'diatoms'}, \code{'sba'}, or \code{'hybrid'}, defaults to all |
6 | | -#' @param ... additional arguments passed to other funcions, e.g., \code{\link{rfpred}} |
| 5 | +#' @param ... additional arguments passed to other funcions |
7 | 6 | #' |
8 | 7 | #' @details |
9 | | -#' Two indices for three taxonomy types are scored, pMMI and O/E for diatoms, soft-bodied algae, and hybrid. This function combines output from the \code{\link{pmmifun}} and \code{\link{oefun}} functions in a user-friendly format. |
| 8 | +#' One index for three taxonomy types are scored, MMI for diatoms, soft-bodied algae, and hybrid. |
| 9 | +#' This function outputs the reulsts of \code{\link{mmifun}} functions in a user-friendly format. |
10 | 10 | #' |
11 | 11 | #' @return |
12 | 12 | #' A \code{\link{asci}} object with specific methods. See the examples for accessing. |
13 | | -#' |
| 13 | +#' |
14 | 14 | #' @export |
15 | 15 | #' |
16 | 16 | #' @importFrom dplyr bind_rows mutate select |
|
19 | 19 | #' @import purrr |
20 | 20 | #' @import tibble |
21 | 21 | #' |
22 | | -#' @seealso \code{\link{pmmifun}}, \code{\link{oefun}} |
| 22 | +#' @seealso \code{\link{mmifun}} |
23 | 23 | #' |
24 | 24 | #' @examples |
25 | | -#' results <- ASCI(demo_algae_tax, demo_algae_sitedata) |
| 25 | +#' results <- ASCI(demo_algae_tax) |
26 | 26 | #' scores(results) |
27 | 27 | #' Supp1_mmi(results) |
28 | | -#' Supp1_OE(results) |
29 | | -#' Supp2_OE(results) |
30 | | -ASCI <- function(taxain, sitein, tax = c('diatoms', 'sba', 'hybrid'), ...){ |
31 | | - |
32 | | - ## sanity checks |
| 28 | +ASCI <- function(taxain, tax = c('diatoms', 'sba', 'hybrid'), ...){ |
33 | 29 |
|
34 | 30 | # check tax argument |
35 | 31 | if(any(!tax %in% c('diatoms', 'sba', 'hybrid'))) |
36 | 32 | stop('tax must match diatoms, sba, and/or hybrid') |
37 | 33 |
|
38 | 34 | # run all other checks, get output if passed |
39 | | - dat <- chkinp(taxain, sitein) |
| 35 | + dat <- chkinp(taxain) |
40 | 36 |
|
41 | | - ## |
42 | | - # individual output |
| 37 | + # mmi |
| 38 | + mmind <- mmifun(dat, ...) |
43 | 39 |
|
44 | | - # oe |
45 | | - oeind <- oefun(dat$taxa, dat$site, ...) |
46 | | - |
47 | | - # pmmi |
48 | | - pmmind <- pmmifun(dat$taxa, dat$site, ...) |
49 | | - |
50 | 40 | ## |
51 | 41 | # main output (scores) |
52 | | - |
53 | | - # oe |
54 | | - oescr <- oeind %>% |
55 | | - map(function(x){ |
56 | | - |
57 | | - x$OE_scores %>% |
58 | | - select(SampleID, O, E, OoverE, OoverE_Percentile) %>% |
59 | | - gather('met', 'val', -SampleID) |
60 | | - |
61 | | - }) %>% |
62 | | - enframe('taxa') %>% |
63 | | - unnest |
64 | | - |
65 | | - # pmmi |
66 | | - pmmiscr <- pmmind %>% |
| 42 | + mmiscr <- mmind %>% |
67 | 43 | map(~ .x$MMI_scores) %>% |
68 | 44 | map(gather, 'met', 'val', -SampleID) %>% |
69 | 45 | enframe('taxa') %>% |
70 | | - unnest |
71 | | - |
72 | | - # combine scrs, long format |
73 | | - scr <- bind_rows(oescr, pmmiscr) %>% |
74 | | - spread(met, val) %>% |
75 | | - select(taxa, SampleID, MMI, MMI_Percentile, O, E, OoverE, OoverE_Percentile) |
| 46 | + unnest %>% |
| 47 | + spread(met, val) |
76 | 48 |
|
77 | 49 | ## |
78 | 50 | # supplementary info |
79 | | - |
80 | | - # pmmi |
81 | | - Supp1_mmi <- pmmind %>% |
| 51 | + Supp1_mmi <- mmind %>% |
82 | 52 | map(~ .x$MMI_supp) %>% |
83 | 53 | map(gather, 'Metric', 'Value', -SampleID) %>% |
84 | 54 | enframe('taxa') %>% |
85 | 55 | unnest |
86 | 56 |
|
87 | | - # oe capture probs |
88 | | - Supp1_OE <- oeind %>% |
89 | | - map(~ .x$Capture_Probs) %>% |
90 | | - enframe('taxa') %>% |
91 | | - unnest |
92 | | - |
93 | | - # oe group occurrence probs |
94 | | - Supp2_OE <- oeind %>% |
95 | | - map(~ .x$Group_Occurrence_Probs) %>% |
96 | | - map(gather, 'pGroup', 'Prob', -SampleID) %>% |
97 | | - enframe('taxa') %>% |
98 | | - unnest |
99 | | - |
100 | | - # oe null |
101 | | - null_OE <- oeind %>% |
102 | | - map(function(x){ |
103 | | - |
104 | | - x$OE_scores %>% |
105 | | - select(SampleID, Onull, Enull, OoverE.null) %>% |
106 | | - gather('met', 'val', -SampleID) |
107 | | - |
108 | | - }) %>% |
109 | | - enframe('taxa') %>% |
110 | | - unnest |
111 | | - |
112 | 57 | # subset taxa if needed |
113 | 58 | if(length(tax) < 3){ |
114 | 59 |
|
115 | | - scr <- scr %>% |
| 60 | + mmiscr <- mmiscr %>% |
116 | 61 | filter(taxa %in% tax) |
117 | 62 |
|
118 | 63 | Supp1_mmi <- Supp1_mmi %>% |
119 | 64 | filter(taxa %in% tax) |
120 | 65 |
|
121 | | - Supp1_OE <- Supp1_OE %>% |
122 | | - filter(taxa %in% tax) |
123 | | - |
124 | | - Supp2_OE <- Supp2_OE %>% |
125 | | - filter(taxa %in% tax) |
126 | | - |
127 | | - null_OE <- null_OE %>% |
128 | | - filter(taxa %in% tax) |
129 | | - |
130 | 66 | } |
131 | | - |
| 67 | + |
132 | 68 | ## |
133 | 69 | # create asci class output |
134 | | - out <- asci(scores = scr, Supp1_mmi = Supp1_mmi, Supp1_OE = Supp1_OE, |
135 | | - Supp2_OE = Supp2_OE, null_OE = null_OE, taxa = tax) |
| 70 | + out <- asci(scores = mmiscr, Supp1_mmi = Supp1_mmi, taxa = tax) |
136 | 71 |
|
137 | 72 | return(out) |
138 | 73 |
|
|
0 commit comments