miga-base 1.2.17.1 → 1.2.17.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/miga/remote_dataset/download.rb +1 -1
- data/lib/miga/remote_dataset.rb +9 -4
- data/lib/miga/version.rb +2 -2
- data/utils/enveomics/Manifest/Tasks/mapping.json +39 -11
- data/utils/enveomics/Manifest/Tasks/remote.json +2 -1
- data/utils/enveomics/Scripts/BedGraph.tad.rb +98 -53
- data/utils/enveomics/Scripts/SRA.download.bash +14 -2
- data/utils/enveomics/Tests/low-cov.bg.gz +0 -0
- data/utils/enveomics/enveomics.R/DESCRIPTION +5 -5
- data/utils/enveomics/enveomics.R/R/autoprune.R +99 -87
- data/utils/enveomics/enveomics.R/R/barplot.R +116 -97
- data/utils/enveomics/enveomics.R/R/cliopts.R +65 -59
- data/utils/enveomics/enveomics.R/R/df2dist.R +96 -58
- data/utils/enveomics/enveomics.R/R/growthcurve.R +166 -148
- data/utils/enveomics/enveomics.R/R/recplot.R +201 -136
- data/utils/enveomics/enveomics.R/R/recplot2.R +371 -304
- data/utils/enveomics/enveomics.R/R/tribs.R +318 -263
- data/utils/enveomics/enveomics.R/R/utils.R +30 -20
- data/utils/enveomics/enveomics.R/man/enve.TRIBS-class.Rd +4 -3
- data/utils/enveomics/enveomics.R/man/enve.TRIBS.merge.Rd +2 -2
- data/utils/enveomics/enveomics.R/man/enve.TRIBStest-class.Rd +3 -3
- data/utils/enveomics/enveomics.R/man/enve.__prune.iter.Rd +7 -4
- data/utils/enveomics/enveomics.R/man/enve.__prune.reduce.Rd +7 -4
- data/utils/enveomics/enveomics.R/man/enve.__tribs.Rd +4 -0
- data/utils/enveomics/enveomics.R/man/enve.barplot.Rd +25 -17
- data/utils/enveomics/enveomics.R/man/enve.col.alpha.Rd +10 -0
- data/utils/enveomics/enveomics.R/man/enve.col2alpha.Rd +8 -2
- data/utils/enveomics/enveomics.R/man/enve.df2dist.Rd +14 -0
- data/utils/enveomics/enveomics.R/man/enve.df2dist.group.Rd +20 -1
- data/utils/enveomics/enveomics.R/man/enve.df2dist.list.Rd +2 -3
- data/utils/enveomics/enveomics.R/man/enve.growthcurve.Rd +5 -2
- data/utils/enveomics/enveomics.R/man/enve.recplot.Rd +50 -42
- data/utils/enveomics/enveomics.R/man/enve.recplot2.ANIr.Rd +5 -2
- data/utils/enveomics/enveomics.R/man/enve.recplot2.__counts.Rd +3 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.__peakHist.Rd +3 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.__whichClosestPeak.Rd +3 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.changeCutoff.Rd +3 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.compareIdentities.Rd +9 -4
- data/utils/enveomics/enveomics.R/man/enve.recplot2.corePeak.Rd +3 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.extractWindows.Rd +3 -3
- data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.Rd +0 -2
- data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.__em_e.Rd +4 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.__em_m.Rd +5 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.__emauto_one.Rd +11 -7
- data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.__mow_one.Rd +5 -1
- data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.__mower.Rd +3 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.mower.Rd +2 -2
- data/utils/enveomics/enveomics.R/man/enve.recplot2.windowDepthThreshold.Rd +3 -3
- data/utils/enveomics/enveomics.R/man/enve.tribs.Rd +2 -2
- data/utils/enveomics/enveomics.R/man/plot.enve.GrowthCurve.Rd +3 -0
- data/utils/enveomics/enveomics.R/man/plot.enve.TRIBS.Rd +3 -0
- data/utils/enveomics/enveomics.R/man/plot.enve.TRIBStest.Rd +6 -3
- data/utils/enveomics/enveomics.R/man/plot.enve.recplot2.Rd +2 -2
- data/utils/enveomics/enveomics.R/man/summary.enve.GrowthCurve.Rd +3 -0
- data/utils/enveomics/enveomics.R/man/summary.enve.TRIBS.Rd +3 -0
- data/utils/enveomics/enveomics.R/man/summary.enve.TRIBStest.Rd +3 -0
- metadata +3 -37
- data/utils/enveomics/Pipelines/assembly.pbs/CONFIG.mock.bash +0 -69
- data/utils/enveomics/Pipelines/assembly.pbs/FastA.N50.pl +0 -1
- data/utils/enveomics/Pipelines/assembly.pbs/FastA.filterN.pl +0 -1
- data/utils/enveomics/Pipelines/assembly.pbs/FastA.length.pl +0 -1
- data/utils/enveomics/Pipelines/assembly.pbs/README.md +0 -189
- data/utils/enveomics/Pipelines/assembly.pbs/RUNME-2.bash +0 -112
- data/utils/enveomics/Pipelines/assembly.pbs/RUNME-3.bash +0 -23
- data/utils/enveomics/Pipelines/assembly.pbs/RUNME-4.bash +0 -44
- data/utils/enveomics/Pipelines/assembly.pbs/RUNME.bash +0 -50
- data/utils/enveomics/Pipelines/assembly.pbs/kSelector.R +0 -37
- data/utils/enveomics/Pipelines/assembly.pbs/newbler.pbs +0 -68
- data/utils/enveomics/Pipelines/assembly.pbs/newbler_preparator.pl +0 -49
- data/utils/enveomics/Pipelines/assembly.pbs/soap.pbs +0 -80
- data/utils/enveomics/Pipelines/assembly.pbs/stats.pbs +0 -57
- data/utils/enveomics/Pipelines/assembly.pbs/velvet.pbs +0 -63
- data/utils/enveomics/Pipelines/blast.pbs/01.pbs.bash +0 -38
- data/utils/enveomics/Pipelines/blast.pbs/02.pbs.bash +0 -73
- data/utils/enveomics/Pipelines/blast.pbs/03.pbs.bash +0 -21
- data/utils/enveomics/Pipelines/blast.pbs/BlastTab.recover_job.pl +0 -72
- data/utils/enveomics/Pipelines/blast.pbs/CONFIG.mock.bash +0 -98
- data/utils/enveomics/Pipelines/blast.pbs/FastA.split.pl +0 -1
- data/utils/enveomics/Pipelines/blast.pbs/README.md +0 -127
- data/utils/enveomics/Pipelines/blast.pbs/RUNME.bash +0 -109
- data/utils/enveomics/Pipelines/blast.pbs/TASK.check.bash +0 -128
- data/utils/enveomics/Pipelines/blast.pbs/TASK.dry.bash +0 -16
- data/utils/enveomics/Pipelines/blast.pbs/TASK.eo.bash +0 -22
- data/utils/enveomics/Pipelines/blast.pbs/TASK.pause.bash +0 -26
- data/utils/enveomics/Pipelines/blast.pbs/TASK.run.bash +0 -89
- data/utils/enveomics/Pipelines/blast.pbs/sentinel.pbs.bash +0 -29
- data/utils/enveomics/Pipelines/idba.pbs/README.md +0 -49
- data/utils/enveomics/Pipelines/idba.pbs/RUNME.bash +0 -95
- data/utils/enveomics/Pipelines/idba.pbs/run.pbs +0 -56
- data/utils/enveomics/Pipelines/trim.pbs/README.md +0 -54
- data/utils/enveomics/Pipelines/trim.pbs/RUNME.bash +0 -70
- data/utils/enveomics/Pipelines/trim.pbs/run.pbs +0 -130
@@ -36,9 +36,10 @@
|
|
36
36
|
#' selection occur in the same transformed space. However, it's useful to
|
37
37
|
#' compare randomly subsampled sets against a selected set of objects. This
|
38
38
|
#' is intended to identify overdispersion or overclustering (see
|
39
|
-
#' \code{\link{enve.TRIBStest}}) of a subset against the entire collection of
|
40
|
-
#' with minimum impact of sampling biases. This object can be produced
|
41
|
-
#' \code{\link{enve.tribs}} and supports S4 methods \code{plot} and
|
39
|
+
#' \code{\link{enve.TRIBStest}}) of a subset against the entire collection of
|
40
|
+
#' objects with minimum impact of sampling biases. This object can be produced
|
41
|
+
#' by \code{\link{enve.tribs}} and supports S4 methods \code{plot} and
|
42
|
+
#' \code{summary}.
|
42
43
|
#'
|
43
44
|
#' @slot distance \code{(numeric)} Centrality measurement of the distances
|
44
45
|
#' between the selected objects (without subsampling).
|
@@ -73,9 +74,9 @@ enve.TRIBS <- setClass("enve.TRIBS",
|
|
73
74
|
#' Enveomics: TRIBS Test S4 Class
|
74
75
|
#'
|
75
76
|
#' Test of significance of overclustering or overdispersion in a selected
|
76
|
-
#' set of objects with respect to the entire set (see \code{\link{enve.TRIBS}}).
|
77
|
-
#' object can be produced by \code{\link{enve.tribs.test}} and supports S4
|
78
|
-
#' \code{plot} and \code{summary}.
|
77
|
+
#' set of objects with respect to the entire set (see \code{\link{enve.TRIBS}}).
|
78
|
+
#' This object can be produced by \code{\link{enve.tribs.test}} and supports S4
|
79
|
+
#' methods \code{plot} and \code{summary}.
|
79
80
|
#'
|
80
81
|
#' @slot pval.gt \code{(numeric)}
|
81
82
|
#' P-value for the overdispersion test.
|
@@ -101,18 +102,19 @@ enve.TRIBS <- setClass("enve.TRIBS",
|
|
101
102
|
#'
|
102
103
|
#' @exportClass
|
103
104
|
|
104
|
-
enve.TRIBStest <- setClass(
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
)
|
105
|
+
enve.TRIBStest <- setClass(
|
106
|
+
"enve.TRIBStest",
|
107
|
+
representation(
|
108
|
+
pval.gt = "numeric",
|
109
|
+
pval.lt = "numeric",
|
110
|
+
all.dist = "numeric",
|
111
|
+
sel.dist = "numeric",
|
112
|
+
diff.dist = "numeric",
|
113
|
+
dist.mids = "numeric",
|
114
|
+
diff.mids = "numeric",
|
115
|
+
call = "call"
|
116
|
+
), package = "enveomics.R"
|
117
|
+
)
|
116
118
|
|
117
119
|
#==============> Define S4 methods
|
118
120
|
|
@@ -125,24 +127,22 @@ enve.TRIBStest <- setClass("enve.TRIBStest",
|
|
125
127
|
#' @param ...
|
126
128
|
#' No additional parameters are currently supported.
|
127
129
|
#'
|
130
|
+
#' @return No return value.
|
131
|
+
#'
|
128
132
|
#' @author Luis M. Rodriguez-R [aut, cre]
|
129
133
|
#'
|
130
134
|
#' @method summary enve.TRIBS
|
131
|
-
#' @export
|
132
|
-
|
133
|
-
|
134
|
-
(object,
|
135
|
-
|
136
|
-
)
|
137
|
-
cat(
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
cat(
|
142
|
-
nrow(attr(object,'distances')),'replicates each.\n');
|
143
|
-
cat('------------------------------------------\n');
|
144
|
-
cat('call:',as.character(attr(object,'call')),'\n');
|
145
|
-
cat('------------------------------------------\n');
|
135
|
+
#' @export
|
136
|
+
summary.enve.TRIBS <- function(object, ...) {
|
137
|
+
cat("===[ enve.TRIBS ]-------------------------\n")
|
138
|
+
cat("Selected", attr(object, "selSize"), "of",
|
139
|
+
attr(object, "spaceSize"), "objects in",
|
140
|
+
attr(object, "dimensions"), "dimensions.\n")
|
141
|
+
cat("Collected", length(attr(object, "subsamples")), "subsamples with",
|
142
|
+
nrow(attr(object, "distances")), "replicates each.\n")
|
143
|
+
cat("------------------------------------------\n")
|
144
|
+
cat("call:", as.character(attr(object, "call")), "\n")
|
145
|
+
cat("------------------------------------------\n")
|
146
146
|
}
|
147
147
|
|
148
148
|
#' Enveomics: TRIBS Plot
|
@@ -171,46 +171,57 @@ summary.enve.TRIBS <- function
|
|
171
171
|
#' @param ...
|
172
172
|
#' Any additional parameters supported by \code{plot}.
|
173
173
|
#'
|
174
|
+
#' @return No return value.
|
175
|
+
#'
|
174
176
|
#' @author Luis M. Rodriguez-R [aut, cre]
|
175
177
|
#'
|
176
178
|
#' @method plot enve.TRIBS
|
177
179
|
#' @export
|
178
180
|
|
179
|
-
plot.enve.TRIBS <- function
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
){
|
190
|
-
type <- match.arg(type)
|
191
|
-
plot.opts <- list(
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
181
|
+
plot.enve.TRIBS <- function(
|
182
|
+
x,
|
183
|
+
new = TRUE,
|
184
|
+
type = c("boxplot", "points"),
|
185
|
+
col = "#00000044",
|
186
|
+
pt.cex = 1/2,
|
187
|
+
pt.pch = 19,
|
188
|
+
pt.col = col,
|
189
|
+
ln.col = col,
|
190
|
+
...
|
191
|
+
) {
|
192
|
+
type <- match.arg(type)
|
193
|
+
plot.opts <- list(
|
194
|
+
xlim = range(attr(x, "subsamples")) * attr(x, "selSize"),
|
195
|
+
ylim = range(attr(x, "distances")), ..., t = "n", x = 1
|
196
|
+
)
|
197
|
+
if (new) do.call(plot, plot.opts)
|
198
|
+
abline(h = attr(x, "distance"), lty = 3, col = ln.col)
|
199
|
+
replicates <- nrow(attr(x, "distances"))
|
200
|
+
if (type == "points") {
|
201
|
+
for (i in 1:ncol(attr(x, "distances")))
|
202
|
+
points(
|
203
|
+
rep(round(attr(x, "subsamples")[i] * attr(x, "selSize")), replicates),
|
204
|
+
attr(x, "distances")[, i],
|
205
|
+
cex = pt.cex, pch = pt.pch, col = pt.col
|
206
|
+
)
|
207
|
+
} else {
|
208
|
+
stats <- matrix(NA, nrow = 7, ncol = ncol(attr(x, "distances")))
|
209
|
+
for (i in 1:ncol(attr(x, "distances"))) {
|
210
|
+
b <- boxplot.stats(attr(x, "distances")[, i])
|
211
|
+
points(
|
212
|
+
rep(
|
213
|
+
round(attr(x, "subsamples")[i] * attr(x, "selSize")), length(b$out)
|
214
|
+
),
|
215
|
+
b$out, cex = pt.cex, pch = pt.pch, col = pt.col
|
216
|
+
)
|
217
|
+
stats[, i] <- c(b$conf, b$stats[c(1, 5, 2, 4, 3)])
|
208
218
|
}
|
209
|
-
x <- round(attr(x,
|
210
|
-
for(i in c(1,3,5))
|
211
|
-
polygon(
|
212
|
-
|
213
|
-
|
219
|
+
x <- round(attr(x, "subsamples") * attr(x, "selSize"))
|
220
|
+
for (i in c(1, 3, 5))
|
221
|
+
polygon(
|
222
|
+
c(x, rev(x)), c(stats[i, ], rev(stats[i + 1, ])), border = NA, col = col
|
223
|
+
)
|
224
|
+
lines(x, stats[7, ], col = ln.col, lwd = 2)
|
214
225
|
}
|
215
226
|
}
|
216
227
|
|
@@ -223,37 +234,36 @@ plot.enve.TRIBS <- function
|
|
223
234
|
#' @param ...
|
224
235
|
#' No additional parameters are currently supported.
|
225
236
|
#'
|
237
|
+
#' @return No return value.
|
238
|
+
#'
|
226
239
|
#' @author Luis M. Rodriguez-R [aut, cre]
|
227
240
|
#'
|
228
241
|
#' @method summary enve.TRIBStest
|
229
|
-
#' @export
|
242
|
+
#' @export
|
230
243
|
|
231
|
-
summary.enve.TRIBStest <- function
|
232
|
-
(
|
233
|
-
|
234
|
-
)
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
cat(' smaller than in the entire dataset\n (overclustering)\n');
|
240
|
-
}else{
|
241
|
-
cat(' larger than in the entire dataset\n (overdispersion)\n');
|
244
|
+
summary.enve.TRIBStest <- function(object, ...) {
|
245
|
+
cat("===[ enve.TRIBStest ]---------------------\n")
|
246
|
+
cat("Alternative hypothesis:\n")
|
247
|
+
cat(" The distances in the selection are\n")
|
248
|
+
if (attr(object, "pval.gt") > attr(object, "pval.lt")) {
|
249
|
+
cat(" smaller than in the entire dataset\n (overclustering)\n")
|
250
|
+
} else {
|
251
|
+
cat(" larger than in the entire dataset\n (overdispersion)\n")
|
242
252
|
}
|
243
|
-
p.val <- min(attr(object,
|
244
|
-
if(p.val==0){
|
245
|
-
diff.dist <- attr(object,
|
246
|
-
p.val.lim <- min(diff.dist[diff.dist>0])
|
247
|
-
cat(
|
248
|
-
}else{
|
249
|
-
p.val.lim <- p.val
|
250
|
-
cat(
|
253
|
+
p.val <- min(attr(object, "pval.gt"), attr(object, "pval.lt"))
|
254
|
+
if (p.val == 0) {
|
255
|
+
diff.dist <- attr(object, "diff.dist")
|
256
|
+
p.val.lim <- min(diff.dist[diff.dist > 0])
|
257
|
+
cat("\n P-value <= ", signif(p.val.lim, 4), sep = "")
|
258
|
+
} else {
|
259
|
+
p.val.lim <- p.val
|
260
|
+
cat("\n P-value: ", signif(p.val, 4), sep = "")
|
251
261
|
}
|
252
|
-
cat(
|
253
|
-
|
254
|
-
cat(
|
255
|
-
cat(
|
256
|
-
cat(
|
262
|
+
cat(" ", ifelse(p.val.lim <= 0.01, "**",
|
263
|
+
ifelse(p.val.lim<=0.05, "*", "")), "\n", sep = "")
|
264
|
+
cat("------------------------------------------\n")
|
265
|
+
cat("call:", as.character(attr(object, "call")), "\n")
|
266
|
+
cat("------------------------------------------\n")
|
257
267
|
}
|
258
268
|
|
259
269
|
#' Enveomics: TRIBS Plot Test
|
@@ -263,9 +273,9 @@ summary.enve.TRIBStest <- function
|
|
263
273
|
#' @param x
|
264
274
|
#' \code{\link{enve.TRIBStest}} object to plot.
|
265
275
|
#' @param type
|
266
|
-
#' What to plot. \code{overlap} generates a plot of the two contrasting
|
267
|
-
#' PDFs (to compare against each other), \code{difference} produces a
|
268
|
-
#' differences between the empirical PDFs (to compare against zero).
|
276
|
+
#' What to plot. \code{overlap} generates a plot of the two contrasting
|
277
|
+
#' empirical PDFs (to compare against each other), \code{difference} produces a
|
278
|
+
#' plot of the differences between the empirical PDFs (to compare against zero).
|
269
279
|
#' @param col
|
270
280
|
#' Main color of the plot if type=\code{difference}.
|
271
281
|
#' @param col1
|
@@ -281,48 +291,61 @@ summary.enve.TRIBStest <- function
|
|
281
291
|
#' @param ...
|
282
292
|
#' Any other graphical arguments.
|
283
293
|
#'
|
294
|
+
#' @return No return value.
|
295
|
+
#'
|
284
296
|
#' @author Luis M. Rodriguez-R [aut, cre]
|
285
297
|
#'
|
286
298
|
#' @method plot enve.TRIBStest
|
287
299
|
#' @export
|
288
300
|
|
289
|
-
plot.enve.TRIBStest <- function
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
){
|
300
|
-
type <- match.arg(type)
|
301
|
-
if(type==
|
302
|
-
plot.opts <- list(
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
301
|
+
plot.enve.TRIBStest <- function(
|
302
|
+
x,
|
303
|
+
type =c("overlap", "difference"),
|
304
|
+
col = "#00000044",
|
305
|
+
col1 = col,
|
306
|
+
col2 = "#44001144",
|
307
|
+
ylab = "Probability",
|
308
|
+
xlim = range(attr(x, "dist.mids")),
|
309
|
+
ylim = c(0, max(c(attr(x, "all.dist"), attr(x, "sel.dist")))),
|
310
|
+
...
|
311
|
+
) {
|
312
|
+
type <- match.arg(type)
|
313
|
+
if (type == "overlap") {
|
314
|
+
plot.opts <- list(
|
315
|
+
xlim = xlim, ylim = ylim, ylab = ylab, ..., t = "n", x = 1
|
316
|
+
)
|
317
|
+
do.call(plot, plot.opts)
|
318
|
+
bins <- length(attr(x, "dist.mids"))
|
319
|
+
polygon(
|
320
|
+
attr(x, "dist.mids")[c(1, 1:bins, bins)],
|
321
|
+
c(0, attr(x, "all.dist"), 0), col = col1,
|
322
|
+
border = do.call(rgb, as.list(c(col2rgb(col1) / 256, 0.5)))
|
323
|
+
)
|
324
|
+
polygon(
|
325
|
+
attr(x, "dist.mids")[c(1, 1:bins, bins)],
|
326
|
+
c(0, attr(x, "sel.dist"), 0), col = col2,
|
327
|
+
border = do.call(rgb, as.list(c(col2rgb(col2) / 256, 0.5)))
|
328
|
+
)
|
329
|
+
} else {
|
330
|
+
plot.opts <- list(
|
331
|
+
xlim = range(attr(x, "diff.mids")),
|
332
|
+
ylim = c(0,max(attr(x, 'diff.dist'))),
|
333
|
+
ylab = ylab, ..., t = "n", x = 1
|
334
|
+
)
|
335
|
+
do.call(plot, plot.opts)
|
336
|
+
bins <- length(attr(x, "diff.mids"))
|
337
|
+
polygon(
|
338
|
+
attr(x, "diff.mids")[c(1, 1:bins, bins)],
|
339
|
+
c(0, attr(x, "diff.dist"), 0), col = col,
|
340
|
+
border = do.call(rgb, as.list(c(col2rgb(col) / 256, 0.5)))
|
341
|
+
)
|
319
342
|
}
|
320
343
|
}
|
321
344
|
|
322
345
|
#' Enveomics: TRIBS Merge
|
323
346
|
#'
|
324
|
-
#' Merges two \code{\link{enve.TRIBS}} objects generated from the same objects
|
325
|
-
#' different subsampling levels.
|
347
|
+
#' Merges two \code{\link{enve.TRIBS}} objects generated from the same objects
|
348
|
+
#' at different subsampling levels.
|
326
349
|
#'
|
327
350
|
#' @param x
|
328
351
|
#' First \code{\link{enve.TRIBS}} object.
|
@@ -335,35 +358,35 @@ plot.enve.TRIBStest <- function
|
|
335
358
|
#'
|
336
359
|
#' @export
|
337
360
|
|
338
|
-
enve.TRIBS.merge <- function
|
339
|
-
(x,
|
340
|
-
y
|
341
|
-
){
|
361
|
+
enve.TRIBS.merge <- function(x, y) {
|
342
362
|
# Check consistency
|
343
|
-
if(attr(x,
|
344
|
-
stop(
|
345
|
-
if(any(attr(x,
|
346
|
-
stop(
|
347
|
-
if(attr(x,
|
348
|
-
stop(
|
349
|
-
if(attr(x,
|
350
|
-
stop(
|
351
|
-
if(attr(x,
|
352
|
-
stop(
|
353
|
-
if(nrow(attr(x,
|
354
|
-
stop(
|
363
|
+
if (attr(x, "distance") != attr(y, "distance"))
|
364
|
+
stop("Total distances in objects are different.")
|
365
|
+
if (any(attr(x, "points") != attr(y, "points")))
|
366
|
+
stop("Points in objects are different.")
|
367
|
+
if (attr(x, "spaceSize") != attr(y, "spaceSize"))
|
368
|
+
stop("Space size in objects are different.")
|
369
|
+
if (attr(x, "selSize") != attr(y, "selSize"))
|
370
|
+
stop("Selection size in objects are different.")
|
371
|
+
if (attr(x, "dimensions") != attr(y, "dimensions"))
|
372
|
+
stop("Dimensions in objects are different.")
|
373
|
+
if (nrow(attr(x, "distances")) != nrow(attr(y, "distances")))
|
374
|
+
stop("Replicates in objects are different.")
|
375
|
+
|
355
376
|
# Merge
|
356
|
-
a <- attr(x,
|
357
|
-
b <- attr(y,
|
358
|
-
o <- order(c(a,b))
|
359
|
-
o <- o[!duplicated(c(a,b)[o])]
|
360
|
-
d <- cbind(attr(x,
|
361
|
-
z <- new(
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
377
|
+
a <- attr(x, "subsamples")
|
378
|
+
b <- attr(y, "subsamples")
|
379
|
+
o <- order(c(a, b))
|
380
|
+
o <- o[!duplicated(c(a, b)[o])]
|
381
|
+
d <- cbind(attr(x, "distances"), attr(y, "distances"))[, o]
|
382
|
+
z <- new(
|
383
|
+
"enve.TRIBS",
|
384
|
+
distance = attr(x, "distance"), points = attr(x, "points"),
|
385
|
+
distances = d, spaceSize = attr(x, "spaceSize"),
|
386
|
+
selSize = attr(x, "selSize"), dimensions = attr(x, "dimensions"),
|
387
|
+
subsamples = c(a, b)[o], call = match.call()
|
388
|
+
)
|
389
|
+
return(z)
|
367
390
|
}
|
368
391
|
|
369
392
|
#==============> Define core functions
|
@@ -389,44 +412,53 @@ enve.TRIBS.merge <- function
|
|
389
412
|
#'
|
390
413
|
#' @export
|
391
414
|
|
392
|
-
enve.tribs.test <- function
|
393
|
-
(dist,
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
a.
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
zp.f <- c()
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
415
|
+
enve.tribs.test <- function(dist, selection, bins = 50, ...) {
|
416
|
+
s.tribs <- enve.tribs(dist, selection, subsamples = c(0,1), ...)
|
417
|
+
a.tribs <- enve.tribs(
|
418
|
+
dist,
|
419
|
+
subsamples = c(0, attr(s.tribs, "selSize") / attr(s.tribs, "spaceSize")),
|
420
|
+
...
|
421
|
+
)
|
422
|
+
s.dist <- attr(s.tribs, "distances")[, 2]
|
423
|
+
a.dist <- attr(a.tribs, "distances")[, 2]
|
424
|
+
range <- range(c(s.dist, a.dist))
|
425
|
+
a.f <- hist(
|
426
|
+
a.dist, breaks = seq(range[1], range[2], length.out = bins), plot = FALSE
|
427
|
+
)
|
428
|
+
s.f <- hist(
|
429
|
+
s.dist, breaks = seq(range[1], range[2], length.out = bins), plot = FALSE
|
430
|
+
)
|
431
|
+
zp.f <- c()
|
432
|
+
zz.f <- 0
|
433
|
+
zn.f <- c()
|
434
|
+
p.x <- a.f$counts / sum(a.f$counts)
|
435
|
+
p.y <- s.f$counts / sum(s.f$counts)
|
436
|
+
for (z in 1:length(a.f$mids)) {
|
437
|
+
zn.f[z] <- 0
|
438
|
+
zz.f <- 0
|
439
|
+
zp.f[z] <- 0
|
440
|
+
for (k in 1:length(a.f$mids)) {
|
441
|
+
if (z < k) {
|
442
|
+
zp.f[z] <- zp.f[z] + p.x[k] * p.y[k-z]
|
443
|
+
zn.f[z] <- zn.f[z] + p.x[k-z] * p.y[k]
|
419
444
|
}
|
420
|
-
zz.f <- zz.f + p.x[k]*p.y[k]
|
445
|
+
zz.f <- zz.f + p.x[k] * p.y[k]
|
421
446
|
}
|
422
447
|
}
|
423
|
-
return(
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
448
|
+
return(
|
449
|
+
new(
|
450
|
+
"enve.TRIBStest",
|
451
|
+
pval.gt = sum(c(zz.f, zp.f)), pval.lt = sum(c(zz.f, zn.f)),
|
452
|
+
all.dist = p.x, sel.dist = p.y, diff.dist = c(rev(zn.f), zz.f, zp.f),
|
453
|
+
dist.mids = a.f$mids,
|
454
|
+
diff.mids = seq(
|
455
|
+
diff(range(a.f$mids)),
|
456
|
+
-diff(range(a.f$mids)),
|
457
|
+
length.out = 1 + 2 * length(a.f$mids)
|
458
|
+
),
|
459
|
+
call=match.call()
|
460
|
+
)
|
461
|
+
)
|
430
462
|
}
|
431
463
|
|
432
464
|
#' Enveomics: TRIBS
|
@@ -468,8 +500,8 @@ enve.tribs.test <- function
|
|
468
500
|
#' dimensions as columns.
|
469
501
|
#' @param pre.tribs
|
470
502
|
#' Optional. If passed, the points are recovered from this object (except if
|
471
|
-
#' \code{points} is also passed. This should be an \code{\link{enve.TRIBS}}
|
472
|
-
#' estimated on the same objects (the selection is unimportant).
|
503
|
+
#' \code{points} is also passed. This should be an \code{\link{enve.TRIBS}}
|
504
|
+
#' object estimated on the same objects (the selection is unimportant).
|
473
505
|
#'
|
474
506
|
#' @return Returns an \code{\link{enve.TRIBS}} object.
|
475
507
|
#'
|
@@ -477,69 +509,87 @@ enve.tribs.test <- function
|
|
477
509
|
#'
|
478
510
|
#' @export
|
479
511
|
|
480
|
-
enve.tribs <- function
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
){
|
494
|
-
|
495
|
-
|
512
|
+
enve.tribs <- function(
|
513
|
+
dist,
|
514
|
+
selection = labels(dist),
|
515
|
+
replicates = 1000,
|
516
|
+
summary.fx = median,
|
517
|
+
dist.method = "euclidean",
|
518
|
+
subsamples = seq(0, 1, by = 0.01),
|
519
|
+
dimensions = ceiling(length(selection) * 0.05),
|
520
|
+
metaMDS.opts = list(),
|
521
|
+
threads = 2,
|
522
|
+
verbosity = 1,
|
523
|
+
points,
|
524
|
+
pre.tribs
|
525
|
+
) {
|
526
|
+
# Sanity checks
|
527
|
+
if (!is(dist, "dist"))
|
528
|
+
stop("`dist` parameter must be a `dist` object.")
|
529
|
+
|
496
530
|
# 1. NMDS
|
497
|
-
if(missing(points)){
|
498
|
-
if(missing(pre.tribs)){
|
499
|
-
if(verbosity > 0)
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
531
|
+
if (missing(points)) {
|
532
|
+
if (missing(pre.tribs)) {
|
533
|
+
if (verbosity > 0) cat("===[ Estimating NMDS ]\n")
|
534
|
+
if (!suppressPackageStartupMessages(
|
535
|
+
requireNamespace("vegan", quietly=TRUE))
|
536
|
+
) stop("Unavailable required package: `vegan`.")
|
537
|
+
mds.args <- c(
|
538
|
+
metaMDS.opts,
|
539
|
+
list(comm = dist, k = dimensions, trace = verbosity)
|
540
|
+
)
|
541
|
+
points <- do.call(vegan::metaMDS, mds.args)$points
|
542
|
+
} else {
|
543
|
+
points <- attr(pre.tribs, "points")
|
544
|
+
dimensions <- ncol(points)
|
510
545
|
}
|
511
|
-
}else{
|
512
|
-
points <- as.matrix(points)
|
513
|
-
dimensions <- ncol(points)
|
546
|
+
} else {
|
547
|
+
points <- as.matrix(points)
|
548
|
+
dimensions <- ncol(points)
|
514
549
|
}
|
550
|
+
|
515
551
|
# 2. Pad ranges
|
516
|
-
if(verbosity > 0) cat(
|
517
|
-
dots <- matrix(
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
552
|
+
if (verbosity > 0) cat("===[ Padding ranges ]\n")
|
553
|
+
dots <- matrix(
|
554
|
+
NA, nrow = nrow(points), ncol = dimensions,
|
555
|
+
dimnames = list(rownames(points), 1:dimensions)
|
556
|
+
)
|
557
|
+
selection <- selection[!is.na(match(selection, rownames(dots)))]
|
558
|
+
for (dim in 1:dimensions) {
|
559
|
+
dimRange <- range(points[, dim]) + c(-1, 1) *
|
560
|
+
diff(range(points[, 1])) / length(selection)
|
561
|
+
dots[, dim] <- (points[, dim] - dimRange[1]) / diff(dimRange)
|
524
562
|
}
|
563
|
+
|
525
564
|
# 3. Select points and summarize distances
|
526
|
-
if(verbosity > 0) cat(
|
527
|
-
distances <- matrix(
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
565
|
+
if (verbosity > 0) cat("===[ Sub-sampling ]\n")
|
566
|
+
distances <- matrix(
|
567
|
+
NA, nrow = replicates, ncol = length(subsamples),
|
568
|
+
dimnames = list(1:replicates, as.character(subsamples))
|
569
|
+
)
|
570
|
+
cl <- makeCluster(threads)
|
571
|
+
for (frx in subsamples) {
|
572
|
+
if (verbosity > 1) cat("Sub-sampling at ", (frx * 100), "%\n", sep = "")
|
573
|
+
distances[, as.character(frx)] <- parSapply(
|
574
|
+
cl, 1:replicates, enve.__tribs, frx,
|
575
|
+
match(selection, rownames(dots)), dimensions, dots, dist.method,
|
576
|
+
summary.fx, dist
|
577
|
+
)
|
535
578
|
}
|
536
|
-
stopCluster(cl)
|
579
|
+
stopCluster(cl)
|
580
|
+
|
537
581
|
# 4. Build object and return
|
538
|
-
return(
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
582
|
+
return(
|
583
|
+
new(
|
584
|
+
"enve.TRIBS",
|
585
|
+
distance = do.call(
|
586
|
+
summary.fx, list(as.matrix(dist)[selection, selection])
|
587
|
+
),
|
588
|
+
points = points, distances = distances, spaceSize = nrow(points),
|
589
|
+
selSize = length(selection), dimensions = dimensions,
|
590
|
+
subsamples = subsamples, call = match.call()
|
591
|
+
)
|
592
|
+
)
|
543
593
|
}
|
544
594
|
|
545
595
|
#' Enveomics: TRIBS - Internal Ancillary Function
|
@@ -555,29 +605,34 @@ enve.tribs <- function
|
|
555
605
|
#' @param summary.fx Summary function
|
556
606
|
#' @param dist Distance
|
557
607
|
#'
|
608
|
+
#' @return A numeric indicating the \code{summary.fx} value applied to the
|
609
|
+
#' distance matrix subset
|
610
|
+
#'
|
558
611
|
#' @author Luis M. Rodriguez-R [aut, cre]
|
559
612
|
#'
|
560
613
|
#' @export
|
561
614
|
|
562
|
-
enve.__tribs <- function
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
closest.
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
615
|
+
enve.__tribs <- function(
|
616
|
+
rep, frx, selection, dimensions, dots, dist.method, summary.fx, dist
|
617
|
+
) {
|
618
|
+
sample <- c()
|
619
|
+
if (frx == 0) return(0)
|
620
|
+
for (point in 1:round(frx * length(selection))) {
|
621
|
+
rand.point <- runif(dimensions)
|
622
|
+
closest.dot <- ""
|
623
|
+
closest.dist <- Inf
|
624
|
+
for (dot in selection) {
|
625
|
+
dot.dist <- as.numeric(
|
626
|
+
dist(matrix(c(rand.point, dots[dot,]), nrow = 2, byrow = TRUE),
|
627
|
+
method = dist.method)
|
628
|
+
)
|
629
|
+
if (dot.dist < closest.dist) {
|
630
|
+
closest.dot <- dot
|
631
|
+
closest.dist <- dot.dist
|
576
632
|
}
|
577
633
|
}
|
578
|
-
sample <- c(sample, closest.dot)
|
634
|
+
sample <- c(sample, closest.dot)
|
579
635
|
}
|
580
|
-
return(
|
636
|
+
return(do.call(summary.fx, list(as.matrix(dist)[sample, sample])))
|
581
637
|
}
|
582
638
|
|
583
|
-
|