Return subsets of a metabarlist object which meet user-defined conditions.

subset_metabarlist(metabarlist, table, indices)

Arguments

metabarlist

a metabarlist object

table

the table where the information on which the subsetting is based. Can be one of `reads`, `motus`, `pcrs`, or `samples`.

indices

a boolean vector indicating the elements, i.e. rows or columns to keep. Elements to keep should be encoded TRUE.

Value

a metabarlist object similar to the initial `metabarlist` except that it contains only the selected elements.

Details

Subsetting a metabarlist will select specific rows from the `reads`, `motus`, `pcrs`, or `samples` tables. Factor levels that are unused after selection are dropped. Note however that:

  • If the selection is done on `reads`, `pcrs` or `samples`, the MOTUs not occurring in the pcrs or samples selected (i.e. those having a total number of reads of 0) are dropped.

  • If the selection is done on `motus`, the pcrs and samples where none of the selected MOTUs are found are kept.

See also

Author

Lucie Zinger

Examples


data(soil_euk)


## Create a subset of soil_euk containing only annelid MOTUs
# i.e. by searching for "Annelida" in MOTUs taxonomic assignments
annelids <- subset_metabarlist(soil_euk,
                               table = "motus",
                               indices = grepl("Annelida", soil_euk$motus$path))
#> Warning: Some PCRs in out have a number of reads of zero in table `reads`!
summary_metabarlist(annelids)
#> $dataset_dimension
#>         n_row n_col
#> reads     384   338
#> motus     338    15
#> pcrs      384    11
#> samples    64     8
#> 
#> $dataset_statistics
#>         nb_reads nb_motus avg_reads sd_reads avg_motus sd_motus
#> pcrs      247553      338  644.6693 909.0428  10.69271 9.802453
#> samples   247346      338  966.1953 964.2296  15.95703 7.782466
#> 

## Create a subset of soil_euk containing only pcrs conducted in plate 1
plate1 <- subset_metabarlist(soil_euk,
                             table = "pcrs",
                             indices = (soil_euk$pcrs$plate_no == 1))
#> Warning: Some PCRs in out have a number of reads of zero in table `reads`!
summary_metabarlist(plate1)
#> $dataset_dimension
#>         n_row n_col
#> reads      96  7900
#> motus    7900    15
#> pcrs       96    11
#> samples    64     8
#> 
#> $dataset_statistics
#>         nb_reads nb_motus avg_reads sd_reads avg_motus sd_motus
#> pcrs     1019783     7900  10622.74 11545.62  336.7917 278.5738
#> samples   771321     7730  12051.89 10578.45  495.0938 200.8483
#> 

## Create a subset of soil_euk containing only positive controls
# i.e. excluding biological samples too that are NA in soil_euk$pcrs$control_type
poscontrols <- subset_metabarlist(soil_euk,
                                  table = "pcrs",
                                  indices = (soil_euk$pcrs$control_type == "positive" &
                                             !is.na(soil_euk$pcrs$control_type)))
#> Warning: None of the selected elements are described in the initial samples table;
#>               an empty sample data.frame is returned
summary_metabarlist(poscontrols)
#> $dataset_dimension
#>         n_row n_col
#> reads      32   484
#> motus     484    15
#> pcrs       32    11
#> samples     8     0
#> 
#> $dataset_statistics
#>         nb_reads nb_motus avg_reads sd_reads avg_motus sd_motus
#> pcrs      342205      484  10693.91  9250.06    55.375 24.44711
#> samples        0        0       NaN       NA       NaN       NA
#>