Aggregate MOTUs in a metabarlist
object according to a grouping factor or vector
aggregate_motus(metabarlist, groups = NULL, FUN = FUN_agg_motus_sum)
FUN_agg_motus_sum(metabarlist, groups)
a metabarlist
object
a grouping vector or factor for MOTUs.
NA
values treated as a group level
a function of MOTU aggregation. Default is the sum of MOTUs read abundances for each grouping value.
A metabarlist
where the table `reads` contains MOTUs abundances aggregated according to a grouping vector/factor (e.g. taxonomic assignment at the phylum level), using a method defined in FUN
and where number of columns of tables `reads` will be equal to that of the number of groups in `groups`.
The function aggregate_motus
is typically used for aggregating MOTUs at a given taxonomic resolution. The user is free to use its own method of aggregation, but the most common aggregation method is to sum reads for each taxa and is therefore pre-encoded in FUN_agg_motus_sum
.
After aggregation, the information retained in the `motus` table corresponds to the information of the most abundant MOTU in a given group.
aggregate_motus
: Aggregate MOTUs in a metabarlist
object according to a grouping factor or vector for each pcr.
FUN_agg_motus_sum
: compute the sum of reads according to a grouping factor or vector for each pcr.
data(soil_euk)
## With MOTU phylum assignment as the grouping factor and
## default grouping aggregation (sum reads across replicates)
soil_euk_ag <- aggregate_motus(soil_euk, groups = soil_euk$motus$phylum_name)
#> Warning: Some PCRs in out have a number of reads of zero in table `reads`!
summary_metabarlist(soil_euk)
#> $dataset_dimension
#> n_row n_col
#> reads 384 12647
#> motus 12647 15
#> pcrs 384 11
#> samples 64 8
#>
#> $dataset_statistics
#> nb_reads nb_motus avg_reads sd_reads avg_motus sd_motus
#> pcrs 3538913 12647 9215.919 10283.45 333.6849 295.440
#> samples 2797294 12382 10926.930 10346.66 489.5117 239.685
#>
summary_metabarlist(soil_euk_ag)
#> $dataset_dimension
#> n_row n_col
#> reads 384 29
#> motus 29 15
#> pcrs 384 11
#> samples 64 8
#>
#> $dataset_statistics
#> nb_reads nb_motus avg_reads sd_reads avg_motus sd_motus
#> pcrs 3538913 29 9215.919 10283.45 10.45052 5.629802
#> samples 2797294 27 10926.930 10346.66 14.11719 2.092456
#>
## With a custom function (here equivalent to FUN_agg_sum,
## i.e. summing all MOTU abundances across groups)
soil_euk_ag <- aggregate_motus(soil_euk, groups = soil_euk$motus$phylum_name,
FUN = function(metabarlist, groups){
t(rowsum(t(metabarlist$reads), groups))})
#> Warning: Some PCRs in out have a number of reads of zero in table `reads`!