rtk {rtk} | R Documentation |
Rarefy tables
Description
Rarefy datasets in R or from a path.
Usage
rtk(input, repeats = 10, depth = 1000, ReturnMatrix = 0, margin = 2,
verbose = FALSE, threads = 1, tmpdir = NULL, seed = 0)
Arguments
input |
This can be either a numeric matrix or a path to a text file in tab-delimited format on the locally available storage. The later option is for very big matrices, to avoid unnecessary memory consumption in R. |
repeats |
Number of times to compute diversity measures. ( |
depth |
Number of elements per row/column to rarefy to. The so called rarefaction depth or samplesize. Can also be a vector of ints. ( |
ReturnMatrix |
Number of rarefied matrices which are returned to R. Set to zero to only measure diversity. ( |
margin |
Indicates which margin in the matrix represents the Samples and Species. Default is to rarefy assuming columns represent single samples (margin=2). If margin=1, rows are assumed to be samples. (default: 2 (columns)) |
verbose |
If extra output should be printed to std::out or not to see progress of rarefaction. ( |
threads |
Number of threads to use during rarefaction |
tmpdir |
Location to store temporary files |
seed |
Set seed to integer > 0 to get reproducible results. |
Details
Function rare
takes a dataset and calcualtes the diversity measures, namely the shannon diversity, richness, simpson index, the inverse simpson index, chao1 and evenness.
If wished for the function can also return one or multiple rarefied matrices rarefied to one or multiple depths. Those can then also be used to create collectorcurves (see collectors.curve
).
Value
The function rare
returns an object of class 'rarefaction', containing the objects divvs
, raremat
, skipped
, div.median
and depths
. If more than one depth was computed the elements 1-4 are inside a list themself and can be acessed by the index of the desired depth.
The object divvs
contains a list of diversity measures for each sample provieded.
raremat
is one or multiple rarefied matrices. Samples with not enough counts are removed, thus not all raremat
-matrices for different depths might be of the same size. If and which sampels where excluded is denoted in the element skipped
using the names of the respective samples.
depths
just contains the input variable and might be usefull for further analysis of the results.
It is possible to plot the results of the rarefaction, depending on the parameters passed to rare
. See plot.rtk
for examples.
Author(s)
Paul Saary, Falk Hildebrand
References
Saary, Paul, et al. "RTK: efficient rarefaction analysis of large datasets." Bioinformatics (2017): btx206.
See Also
Examples
require("rtk")
# generate semi sparse example data
data <- matrix(sample(x = c(rep(0, 1500),rep(1:10, 500),1:1000),
size = 120, replace = TRUE), 10)
# find the column with the lowest aboundance
samplesize <- min(colSums(data))
# rarefy the dataset, so each column contains the same number of samples
data.rarefied <- rtk(input = data, depth = samplesize, ReturnMatrix = 1)
richness <- get.diversity(data.rarefied, div = "richness")
eveness <- get.diversity(data.rarefied, div = "eveness")