B
BarCodeR documentationEmbedded documentation — works offline
/

Filtration — Methodological guide

1. General purpose of the tab#

The Filtration tab builds a subset of a phyloseq object already loaded in BarCodeR. It can remove taxa according to taxonomy, low-abundance or low-prevalence ASVs, samples according to depth, richness, name or metadata, and sequences that fail technical criteria.

The result is first built as a temporary reactive object:

ps_filtered

It can then be reviewed in the summary, saved under a new name, used to replace its parent dataset, inspected in Description, compared with other datasets and exported.

Difference from Data Edition#

Data Edition Filtration
Directly changes the selected dataset tables First builds a temporary derived object
Changes are immediate in datasets() The parent remains unchanged while parameters are adjusted
Intended for cell and structural corrections Intended for removing samples or taxa using criteria
Records edits in edit_log Records filtering in filtration_log

Until the result is saved, it does not appear in Datasets, is not available to other modules, is not written to disk and may be lost if the session is reloaded.

2. Automatic operation and result life cycle#

There is no Apply filters button. Filtering is recalculated automatically whenever an active parameter changes: enabling a block, changing a threshold, selecting a taxonomic value, adding a metadata condition or changing the dataset.

On a large dataset, each change may read the OTU table, recalculate abundance and prevalence, run several prune_taxa() or prune_samples() calls, inspect sequences and rebuild the log and summary. Change settings progressively and allow recalculation to finish.

The parent remains intact while settings are adjusted#

parent dataset
      ↓
reactive calculation
      ↓
temporary filtered dataset

The parent is replaced only when the result is saved under the same name.

Empty save name warning#

The save field is empty by default. An empty value means:

Save the result using the parent name and replace the parent.

No additional confirmation is requested. To preserve raw data, enter a distinct name such as COI_raw and COI_filtered.

Saving only changes BarCodeR memory. Use Datasets → Save project afterwards to persist the result.

3. Fixed order of filters#

Filters are always applied in this order:

1. Taxonomy
2. ASV abundance
3. Samples
4. Sequences

This order is fixed and does not depend on the order in which boxes were opened or configured.

Consequences#

Each block works on the output of the previous block. For example:

  1. chloroplasts are removed;
  2. totals and prevalence are recalculated for remaining ASVs;
  3. sample reads and richness are recalculated;
  4. insufficient samples are removed;
  5. sequences failing technical criteria are removed.

Sample thresholds therefore do not necessarily use the raw values shown in Description.

One pass only, no convergence loop#

The pipeline does not restart from the beginning after the final step. Consequently:

  • removing samples may lower ASV prevalence below the threshold without a second ASV pass;
  • sequence filtering may lower sample reads or richness below thresholds without a second sample pass;
  • zero-read samples or zero-abundance taxa may remain in the final result.

A second filtering pass may therefore remove more items than the first.

4. Dataset selection and persistence of settings#

The main selector is synchronized with the global active dataset. Changing the dataset in Filtration updates active_ds(), changes the default dataset in other tabs and may mark the project as unsaved.

Settings are not all reset#

After a dataset change, the following may remain active:

  • abundance thresholds;
  • sample thresholds;
  • sequence criteria;
  • taxonomy keywords;
  • advanced conditions;
  • save name.

Dataset-dependent lists are refreshed, including taxonomic ranks and values, sample names and metadata variables.

An advanced condition may remain even when its variable does not exist in the new dataset. Filtering can then be blocked until the condition is corrected or deleted.

Review every block after changing datasets and before saving.

5. Reading interface states#

Each block has a visual state.

Colour Meaning
Grey No active or modified parameter
Orange Parameters were modified but the block is disabled
Green The block activation checkbox is selected

A green border does not guarantee that anything is removed. For example, the ASV block may be enabled with all thresholds set to zero: the block is green, but its criteria are neutral.

The global banner tries to identify genuinely configured blocks, but a dataset can still receive a filtration_log without any item being removed.

Graphical previews#

Threshold histograms are calculated from the selected parent dataset, not from the progressively filtered object. They include total reads per ASV, prevalence, maximum relative abundance, reads per sample, richness per sample, length and GC.

The threshold line helps inspect the initial distribution but may not represent the values used after earlier blocks. The before/after summary is the main preview of the final result.

6. Taxonomic filtering#

Taxonomic filtering requires a tax_table. It can exclude values at a selected rank, keep only selected values and exclude annotations containing keywords.

Preselected parameters#

The following keywords are selected by default:

chloroplast
mitochondria

They are not applied until the block is enabled. However, simply selecting Enable filtering may immediately remove taxa containing these terms.

These keywords are not universal contaminants. Depending on the marker and study aim, they may represent the biological signal of interest.

Exclude and keep by rank#

For the selected rank:

  • Exclude removes ASVs whose value exactly matches a selected value;
  • Keep only retains ASVs matching selected values.

The internal order is:

1. Exclusion
2. Retention
3. Keyword search

Contradictory rules may remove all taxa.

Keywords are searched in every taxonomy column, case-insensitively, as substrings, using a combined | pattern.

Thus chloroplast may match Chloroplast, chloroplastidae or Unclassified chloroplast sequence. The search is not restricted to the selected rank.

Missing taxonomy#

If the block is enabled without a taxonomy table, the taxonomic filter is skipped. Other blocks may still produce a result. Read the actual summary rather than relying only on the green box state.

7. ASV abundance filtering#

Three criteria are available and applied sequentially:

1. Total reads
2. Prevalence
3. Maximum relative abundance

They assume that OTU-table values are meaningful abundances. They may be misleading for CLR data, relative abundances, logarithmic values, negative values or already normalized matrices.

Total reads per ASV#

For each ASV:

Total = sum of abundances across samples remaining at this stage

The rule is strict:

Total > threshold

With a threshold of 10, a total of 10 is removed and a total of 11 is retained.

Prevalence#

Prevalence is the number of samples where abundance is strictly greater than zero. The rule is:

Prevalence ≥ threshold

With a threshold of 3, an ASV present in exactly three samples is retained.

An absolute threshold must be interpreted relative to the number of samples. Presence in three samples means 30% of a ten-sample project but only 3% of a hundred-sample project.

Maximum relative abundance#

For each ASV, BarCodeR calculates its relative abundance in every sample and retains the maximum:

Maximum of: ASV abundance / total sample abundance × 100

The rule is:

Maximum relative abundance ≥ threshold

This preserves an ASV that is rare globally but important in at least one sample.

The calculation occurs after total-read and prevalence filters. Removing taxa changes denominators and mechanically increases the relative share of remaining taxa.

8. Sample filtering#

Criteria are applied in this order:

1. Minimum reads
2. Minimum richness
3. Sample names
4. Simple metadata condition
5. Advanced conditions

Minimum reads#

Reads are recalculated after taxonomic and abundance filtering:

Reads = sum of abundances of taxa still present

The rule is inclusive:

Reads ≥ threshold

Minimum richness#

Richness is the number of taxa with abundance strictly greater than zero. The rule is:

Richness ≥ threshold

This richness may differ from the parent-dataset value shown in Description.

Filtering by name#

Names correspond exactly to sample_names(ps). There is no partial or case-insensitive search.

  • Keep retains only selected names;
  • Exclude removes selected names.

This step occurs after read and richness thresholds. A sample selected for retention may already have been removed earlier.

Simple metadata condition#

The module mainly distinguishes numeric columns from factors or character strings. Dates, logical columns and special classes may not be handled correctly by the simple filter.

Numeric variables

Available operators are ≥, >, ≤, < and between. Between includes both limits. If limits are reversed, BarCodeR automatically uses the lower and higher value.

Initial values such as the median or quartiles are conveniences only, not scientific recommendations.

With Keep, missing values are generally removed. With Exclude, they are generally retained because they do not satisfy the condition before inversion.

Categorical variables

Comparisons are exact after conversion to text and are sensitive to case, spaces and spelling.

Multiple values in one condition are combined using OR.

Missing values are generally removed with Keep and retained with Exclude.

9. Advanced metadata conditions#

Each advanced condition defines a variable, a Keep or Exclude action, a comparison or values and a delete button.

All advanced conditions are combined with AND.

Example:

Keep Campaign = 2026
AND
Exclude Site = control
AND
Keep Depth ≥ 50

OR between distinct variables is not available.

For a categorical variable, selecting several values in one row provides an internal OR, for example Site = A or B.

Variables not recognized as numeric are handled as text. A date may therefore be selected as a category, but cannot be filtered as a true time interval.

Incomplete condition#

An incomplete advanced condition may completely prevent creation of the temporary result even when all other filters are valid. Complete or delete the condition.

10. Technical sequence filtering#

Technical filtering uses refseq(ps) and can apply length, GC, ambiguous-base and homopolymer criteria. It is applied last.

Missing or misaligned sequences#

If refseq is absent, the block is skipped and a line is added to the log.

BarCodeR attempts to align sequences with taxa_names(ps):

  • unnamed sequences are assumed to follow taxon order when counts match exactly;
  • named sequences are matched by identifier.

If no sequence can be aligned, the block is skipped.

If coverage is partial, ASVs with a sequence are evaluated and ASVs without a sequence are retained without testing.

Length and GC plots use a stricter alignment and may be absent even when filtering is partially applied.

Length#

Limits are inclusive:

Minimum length ≤ length ≤ maximum length

A maximum of zero disables the upper limit. If the minimum exceeds the maximum, all sequences may be rejected.

GC#

GC used by the filter is calculated from A, C, G and T:

G + C
────────────── × 100
A + C + G + T

Ambiguous bases are excluded from this denominator. Minimum and maximum limits are inclusive. Neutral values are 0% and 100%.

Ambiguous bases#

Counted characters are:

N R Y S W K M B D H V

Gaps, dots and other symbols are not explicitly counted by this criterion.

In the current implementation, Maximum ambiguities = 0 disables the filter. It cannot be used to enforce strictly zero ambiguous bases.

Homopolymers#

BarCodeR finds the longest run of identical consecutive characters. For example, AAAATCG has a maximum homopolymer length of 4.

All characters may be counted, including ambiguous bases and repeated symbols. A sequence is retained when the longest run is less than or equal to the threshold. Zero also disables this criterion.

Consequence of filter order#

Sample thresholds are not recalculated after technical filtering. Samples may therefore end below the read threshold, below the richness threshold or with zero reads.

11. Protection against empty results and validation limits#

Before an operation that would remove all taxa or all samples, BarCodeR stops the calculation and displays an error.

This only guarantees that at least one taxon and one sample remain. It does not guarantee enough replicates, a final minimum depth or richness, absence of zero-read samples or zero-abundance taxa, or suitability for statistical analysis.

Check the final result in Description.

12. Filtering log and provenance#

The result receives an attribute:

attr(ps, "filtration_log")

It may contain the parent name, date, before and after dimensions, descriptive lines, structured parameters, removed taxa and removed samples.

Structured parameters#

Parameters are stored in:

filtration_log$params

They include enabled blocks, taxonomic rank, excluded or retained values, keywords, abundance thresholds, name filters, metadata conditions and sequence parameters.

This structure is the most reliable source for reproducing or auditing filtering.

Log language#

Text is recorded in the active language at calculation time and is not translated later.

The Active blocks column currently searches for some French expressions in the text log. It may therefore display — for a dataset filtered in another language. Structured parameters are more reliable.

Removed-item tables#

removed_taxa and removed_samples use metrics from the unfiltered parent before any filter.

A sample removed because it has only 800 reads after taxonomic removal may therefore appear with 5,000 reads in the removed-sample table.

Tables do not always provide an exact per-item cause. Log steps mainly report global effects.

Successive filtering#

A new pass replaces the previous filtration_log; logs are not stacked.

Keep stages under separate names:

COI_raw
COI_tax
COI_abundance
COI_final

Preserved and potentially lost attributes#

BarCodeR explicitly copies openmetabar_run and edit_log.

Pruning operations may drop other non-standard attributes, including dataset_meta, notes, tags or custom attributes. Check them after filtering.

13. Saving results and overwrite risks#

Three cases are possible.

Entered name Behaviour
Empty field or parent name Immediate replacement of the parent
New name Creation of a new dataset
Name of another dataset Confirmation before replacement

The name is normalized with the common BarCodeR helper. Unlike Input data, no _2 suffix is automatically added after a collision.

Memory only#

The Save button changes datasets(). It does not persist the project to disk.

The saved result becomes the active dataset.

Automatic reapplication of filters#

Because the Filtration selector follows the active dataset, the saved result immediately becomes the module’s new parent. Active filters are applied again:

raw parent
    ↓
first saved result
    ↓
same filters still active
    ↓
new temporary result

A second click on Save may therefore remove additional items.

After saving:

  1. do not click Save again immediately;
  2. disable filters or leave the tab;
  3. inspect the result in Description;
  4. save the project in Datasets.

14. Dataset inspection and exports#

The lower section shows datasets in the registry, but not the unsaved temporary result.

The table may show name, filtered status, parent, date, before/after dimensions, removed counts and active blocks.

A dataset is marked as filtered as soon as a filtration_log exists, even if nothing was removed.

If a result overwrites its parent under the same name, it may be shown as its own parent.

If the dataset is later modified in Data Edition, current dimensions may no longer reflect filtering alone.

Detail panel#

The panel can display the log, parameters, removed taxa and samples, OTU table, taxonomy, metadata, sequences and histograms.

Important details:

  • the plot called Reads actually shows totals by taxon;
  • the logarithmic histogram uses log10(total + 1);
  • GC in the detail panel divides by total string length and may differ from filtering GC;
  • the OTU table is always transposed for display, without reliable orientation normalization;
  • panels may be empty or error when the corresponding component is absent.

TSV exports#

File names are generic:

otu_table.tsv
taxonomy.tsv
metadata.tsv

They do not include the dataset name or date. Row names are exported as the first column, sometimes without an explicit header.

The OTU table is also always transposed for this export, so orientation depends on the original phyloseq orientation.

BIOM export#

The BIOM file contains only the abundance matrix. Taxonomy, metadata, sequences, tree and log are not automatically included.

Stored orientation is used directly. If taxa are in columns, the file may be reversed.

If biomformat is unavailable, BarCodeR currently creates a file with a .biom extension containing a text message. It is not a valid BIOM file.

15. Scientific interpretation and recommended strategy#

BarCodeR cannot determine appropriate thresholds automatically. They depend on marker, technology, protocol, sample number, depth, controls, expected diversity, pipeline and scientific objective.

Rare taxa#

A rare ASV may be an error, contamination, artefact, genuine rare taxon or important biological event. Rarity alone does not justify removal.

Experimental groups#

A global threshold can strongly unbalance groups. After filtering, check samples per group, retained controls, replicate numbers and group depth.

Comparing strategies#

Compare filtering methods from the same parent:

COI_raw → method A
COI_raw → method B

Avoid COI_raw → method A → method B unless progressive filtering is the explicit goal.

  1. Save the project.
  2. Keep the raw dataset.
  3. Select the parent.
  4. Review inherited settings.
  5. Enable one block at a time.
  6. Inspect dimensions after each block.
  7. Add other criteria progressively.
  8. Check groups and controls.
  9. Enter a new name.
  10. Save once.
  11. Leave the tab or disable filters.
  12. Inspect the result in Description.
  13. Check zeros, notes, tags and provenance.
  14. Save the project.
  15. Export the final dataset.

16. Troubleshooting and checks#

Parameter problems#

Symptom Likely cause Action
Old filters apply to a new dataset Settings persist Review all blocks after changing datasets
Green box but no removal Enabled block with neutral criteria Check thresholds and summary
Orange box Modified parameters, disabled block Enable it or restore neutral values
Enabling taxonomy immediately removes ASVs Preselected keywords Check chloroplast and mitochondria
No result Incomplete advanced condition or overly strict filter Complete, delete or relax it
All taxa or samples would be removed Contradictory or excessive criteria Lower thresholds and check values

Threshold problems#

Symptom Explanation
An ASV exactly at the total threshold is removed Total uses >
A low-total ASV passes the relative threshold It is important in at least one sample
A sample above the plotted threshold is removed The actual threshold is applied after taxon removal
A missing value is removed with Keep It does not satisfy the condition
A missing value remains with Exclude It does not match the criterion before inversion
Advanced conditions are highly restrictive They are combined with AND
OR between variables cannot be created This logic is not directly supported

Sequence problems#

Symptom Cause or behaviour
No length or GC plot Missing RefSeq or incomplete alignment
Active block is skipped No alignable sequence
Some ASVs without sequences remain Coverage is partial
Maximum ambiguities set to zero does not filter Zero disables the filter
Maximum homopolymer set to zero does not filter Zero disables the filter
Zero-read samples remain Sample thresholds are not reapplied

Log and provenance problems#

Symptom Likely cause
Removed table shows metrics above the threshold Metrics were calculated on the raw parent
No exact reason per item The log mainly stores global effects
Old log disappeared A new pass replaced filtration_log
Notes or tags disappeared A custom attribute was dropped during pruning
Filtered status without removal The log’s presence is sufficient
Active blocks displayed as — Text log was written in another language

Save problems#

Symptom Cause or action
Parent was overwritten Name was empty or identical to the parent
No _2 suffix was added Filtration replaces rather than auto-renames
Result lost after closing Project was not saved in Datasets
Result changes after saving Filters were reapplied to the new active dataset
Second click is more destructive A second pass ran on the first result
Save rejected OTU, metadata or taxonomy identifiers are inconsistent

Inspection or export problems#

Symptom Likely cause
Temporary result is absent from the table It has not been saved
Reads histogram is based on ASVs The plot calculates totals by taxon
GC differs between plots Denominator formulas differ
OTU table is transposed The panel always calls t()
BIOM is reversed OTU orientation was not corrected
.biom file contains text biomformat is unavailable
Detail tab errors Required phyloseq component is missing

Checklist before filtering#

  • Confirm the active dataset and project.
  • Save the project.
  • Keep a raw version.
  • Confirm abundance values are suitable for thresholding.
  • Check OTU orientation.
  • Check taxonomy, metadata and RefSeq.
  • Define the scientific purpose of each filter.
  • Review settings inherited from another dataset.

Checklist before saving#

  • Read the full summary.
  • Check ASVs and samples before/after.
  • Check skipped steps.
  • Check advanced conditions.
  • Enter a new name to preserve the parent.
  • Click Save only once.
  • Do not confuse registry save with project persistence.

Checklist after saving#

  • Open Description.
  • Check dimensions.
  • Check reads and richness.
  • Check zero-abundance taxa and zero-read samples.
  • Check group sizes.
  • Check taxonomy, RefSeq and tree.
  • Check notes, tags and log.
  • Save in Datasets.
  • Export the final dataset.

17. Main module limitations#

Keep the following limitations in mind:

  • automatic recalculation may be expensive;
  • histograms are based on the raw parent;
  • filter order is fixed;
  • thresholds are not iteratively reevaluated;
  • no final zero cleanup is performed;
  • settings persist when datasets change;
  • taxonomy keywords are preselected;
  • dates and special classes have limited support;
  • advanced conditions only support AND between rows;
  • the current control cannot enforce zero ambiguities;
  • ASVs without sequences may be retained;
  • a new log replaces the previous log;
  • exact per-item causes are not always stored;
  • removed-item metrics come from the raw parent;
  • custom attributes may be lost;
  • an empty name overwrites the parent without confirmation;
  • filters are reapplied after saving;
  • Save does not write the project to disk;
  • active-block detection is imperfect across languages;
  • export orientations may be ambiguous;
  • BIOM export is minimal and depends on biomformat.

Verified internal sources#

This documentation is based on the current behaviour of:

  1. modules/filtration/mod_filtration_ui.R: main interface and four filtering blocks.
  2. modules/filtration/mod_filtration_server.R: numeric parsing, filter order, calculations, safeguards, log and temporary result.
  3. modules/filtration/io/mod_filtration_io_ui.R: saving, inspection and exports.
  4. modules/filtration/io/mod_filtration_io_server.R: overwrite, registry insertion, tables, details and BIOM export.
  5. modules/_shared/_provenance.R: preservation of attributes during pruning.
  6. modules/_shared/_dataset_naming.R: name normalization.
  7. modules/_shared/_ps_guard.R: integrity check before registry insertion.
  8. app.R: submodule assembly, global registry and active dataset.
  9. .claude/architecture/23-filtration.md: intended architecture checked against actual behaviour.