> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cosmosid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pre-processing Metabolomics Data - Parameters

> The pre-processing steps of metabolomics Data Tables on Cosmos-Hub 2.0, the parameters available for each table type, and their options.

Metabolomics Data Tables have their own pre-processing parameters, in the **PREPROC** section of each analysis module.  To learn more about Metabolomics Data Tables supported on Cosmos-Hub and see how they are structured, see [Metabolomics Data](https://docs.cosmosid.com/metabolomics-data.md).

Metabolomics Data Tables have properties that most statistical methods do not expect, so they need to be pre-processed before any analysis. The main ones are:

* **Sparsity.** Some metabolites are too low to be measured in part of the samples, so the table contains zeros, empty cells and codes such as `<LOD`. Many methods cannot use a table with gaps, and the way the gaps are filled changes the result.
* **Technical variation between samples.** Samples differ for reasons that are not biological, for example when one stool extract is more concentrated than another, or when the instrument signal drifts during a long run. These differences can hide a biological effect or create one that does not exist.
* **Wide range of values.** Metabolite values cover several orders of magnitude and are usually skewed, so a few very abundant metabolites can dominate a distance or a model.

## Three types of Metabolomics Data Tables

The defaults of the pre-processing parameters depend on the type of Data Table selected in **Analysis metric**. The defaults for each Data Table are listed in [Recommended Pre-processing parameters](#recommended-pre-processing-parameters).

> [card] [Targeted quantified](https://docs.cosmosid.com/metabolomics-data.md#targeted-counts)
>
> Calibrated concentrations of known metabolites, for example in ng/mL, usually with LOD, LOQ and ULOQ values. Imported as **Targeted Counts**.

> [card] [Targeted peak areas](https://docs.cosmosid.com/metabolomics-data.md#targeted-peak-values)
>
> Signal intensities of known metabolites, not converted into concentrations.

> [card] [Untargeted peak areas](https://docs.cosmosid.com/metabolomics-data.md#untargeted-peak-values)
>
> Signal intensities of all detected features, each with an annotation level.

## MBS Pre-processing Pipeline

Each pre-processing parameter controls one step of the pre-processing pipeline. The diagram below shows the order in which the steps run. Hover over a step to see what it does, and click it to open its section.

## Analysis metric

● Input
Sets the defaults

**Analysis metric** selects the Data Table used for the analysis, by the metric in which it expresses metabolite abundance (concentrations, targeted peak areas or untargeted peak areas). The defaults of the other pre-processing parameters depend on this choice, as listed in [Recommended Pre-processing parameters](#recommended-pre-processing-parameters).

![Analysis Metric in the PREPROC section](https://docs.cosmosid.com/images/mbs_analysis_metric.jpg)

Analysis Metric in the PREPROC section

## Level of Annotation

● Select features
Feature filtering · Untargeted only

**Level of Annotation** keeps only the features with the selected annotation levels, among the levels present in your Data Table. In an untargeted MBS Data Table, each feature has an annotation level, which describes how confident the annotation of the molecule is, based on the type of evidence available. Level 1 is the highest confidence, where the identity of the molecule is fully confirmed with an authentic standard (a pure reference compound measured with the same method). Each higher level means lower confidence, down to features identified only by their accurate mass. Features without a level (NA) were detected but not annotated.

| Option | What it changes |
| :- | :- |
| All levels selected (default) | No filtering. |
| A selected level, for example `1` or `2a` | Features at this level are kept. |
| A level that is not selected | Features at this level are removed before all other steps. |
| `NA` | Features without an annotation level. Deselect to remove them. |

![Level Of Annotation in the PREPROC section](https://docs.cosmosid.com/images/image-39.png)

Level Of Annotation in the PREPROC section

#### What each annotation level contains

Information available at each annotation level.

| Level | Name | Formula | Compound class | HMDB / ChEBI IDs | In-house ID (`msid`) | MS/MS spectrum |
| :- | :- | :- | :- | :- | :- | :- |
| `1` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| `2a` | ✓ | ✓ | ✓ | ✓ | ✓ | – |
| `2b` | ✓ | ✓ | – | – | – | ✓ |
| `3` | ✓ | ✓ | – | – | – | – |
| `NA` | Partly | Mostly | – | – | – | – |

> [!NOTE]
>
> **Level of Annotation** is shown only for untargeted peak areas, when the Data Table has an `annotation_level` column. If none of the features has a selected level, the analysis stops with an error, so select at least one level present in your data.

## Zero handling

● Handle values
Data transformation

**Zero handling** decides whether metabolites reported with zero abundance in the Data Table should be treated as missing values (NA) or as values below the limit of detection (LOD).

| Option | What it changes |
| :- | :- |
| `Missing at random: set zeros to NA` | Zeros become NA and follow **NA handling**. |
| `Missing not at random: treat zeros as below LOD` | Zeros are set to LOD/2 and follow **Below LOD**. Requires an LOD column. |

With both options, a zero counts as "not detected" in the **Prevalence threshold** step.

![Zero handling in the PREPROC section](https://docs.cosmosid.com/images/image-40.png)

Zero handling in the PREPROC section

## Below LOD

● Handle values
Data transformation

**Below LOD** sets whether values below the limit of detection (LOD) of each metabolite are kept as measured, set to missing (NA), or imputed with a fraction of the LOD. The LOD is the lowest amount of a metabolite that the instrument can distinguish from the background noise. Below the LOD, the metabolite cannot be told apart from the noise, so it may be absent or present at a very low level. A value is below the LOD when the table reports `<LOD` (or `ND`, `not detected`) instead of a number, or when the number is lower than the LOD of that metabolite.

| Option | What it changes |
| :- | :- |
| `Keep and flag` | Numeric values are kept. `<LOD` codes become NA and follow **NA handling**. |
| `Set to NA` | Values below the LOD become NA and follow **NA handling**. |
| `Replace with LOD/2` | Values below the LOD are imputed with LOD/2. |
| `Replace with LOD/√2` | Values below the LOD are imputed with LOD/√2. |

`LOD/2` and `LOD/√2` are both common conventions. `LOD/√2` is often used when the values of a metabolite are not strongly skewed, and `LOD/2` when they are. With every option, values below the LOD count as "not detected" in the **Prevalence threshold** step.

![Below LOD in the PREPROC section](https://docs.cosmosid.com/images/belowLOD_MBS.jpg)

Below LOD in the PREPROC section

> [!NOTE]
>
> The LOD, LOQ and ULOQ steps run only when the table has at least one of these columns. Without them, cells with `<LOD` become missing values and follow **NA handling**.

## Between LOD and LOQ

● Handle values
Data transformation · Needs an LOQ column

**Between LOD and LOQ** sets whether values between the limit of detection (LOD) and the limit of quantification (LOQ) of each metabolite are kept as measured, set to missing (NA), or imputed with half the LOQ. The LOQ is the lowest amount of a metabolite that can be measured with acceptable precision. Between the LOD and the LOQ, the metabolite is present, but its amount has a larger measurement error. The table reports `<LOQ`, or a number equal to or above the LOD and below the LOQ.

Keeping these values uses more of the data, including the signal of low abundance metabolites. Removing them leaves only precise values, but can remove a large part of the measurements for these metabolites.

| Option | What it changes |
| :- | :- |
| `Keep and flag` | Numeric values are kept. `<LOQ` codes become NA and follow **NA handling**. |
| `Set to NA` | Values between the LOD and the LOQ become NA and follow **NA handling**. |
| `Replace with LOQ/2` | Values between the LOD and the LOQ are imputed with LOQ/2. |

With every option, values between the LOD and the LOQ count as "detected" in the **Prevalence threshold** step.

![Between LOD and LOQ in the PREPROC section](https://docs.cosmosid.com/images/betweenlodandqod_MBS.jpg)

Between LOD and LOQ in the PREPROC section

## Above ULOQ

● Handle values
Data transformation · Needs a ULOQ column

**Above ULOQ** sets whether values above the upper limit of quantification (ULOQ) of each metabolite are kept as measured, set to missing (NA), or capped at the ULOQ. The ULOQ is the highest amount of a metabolite that can be measured reliably, which is the highest point of the calibration curve. Above the ULOQ, the detector can be saturated, so the reported amount is often lower than the true one. The table reports `>ULOQ`, or a number above the ULOQ.

The choice matters when a metabolite is very abundant in some samples, for example a dietary compound after an intervention.

| Option | What it changes |
| :- | :- |
| `Keep and flag` | Numeric values are kept. `>ULOQ` codes become NA and follow **NA handling**. |
| `Set to NA` | Values above the ULOQ become NA and follow **NA handling**. |
| `Replace with ULOQ` | Values above the ULOQ are capped at the ULOQ. |

With every option, values above the ULOQ count as "detected". If many samples are above the ULOQ, measuring diluted samples again in the lab gives more reliable values than any of these options.

![Above ULOQ in the PREPROC section](https://docs.cosmosid.com/images/mbs_above_uloq.png)

Above ULOQ in the PREPROC section

## NA handling

● Handle values
Data transformation or filtering

**NA handling** sets whether the missing values (NA) left after the previous steps are kept, imputed, or removed by dropping the features or samples that contain them. Several methods, such as PCA, PLS-DA and the machine learning models, cannot use a table with gaps.

| Option | What it changes |
| :- | :- |
| `Keep as missing` | NA values are kept. Before a log, CLR or Box-Cox **Transformation**, they are imputed with the feature LOD, or with half the feature minimum without an LOD column. |
| `Remove features with missing values` | Features with at least one NA are removed. |
| `Remove samples with missing values` | Samples with at least one NA are removed and listed in `excluded_samples.csv`. |
| `Replace with half the feature minimum` | NA values are imputed with half the lowest positive value of the feature. |
| `Replace with a random value between 0 and the feature minimum` | NA values are imputed with random values between 0 and the lowest positive value of the feature. |
| `Replace with a constant value` | NA values are imputed with the **NA constant value**. |

> [!WARNING]
>
> `Remove features with missing values` and `Remove samples with missing values` can remove a large part of the table when missing values are common. Check how many features and samples are left before you interpret the results.

#### **Random seed** *(available when NA handling is set to Replace with a random value)*

**Random seed** (called **Imputation seed** in PLS-DA) sets the seed of the random number generator used for random imputation. The same seed always returns the same imputed values, so the analysis is reproducible.

**Default** · `42`

![Random Seed, shown when NA handling is set to Replace with a random value](https://docs.cosmosid.com/images/mbs_na_random_seed.png)

Random Seed, shown when NA handling is set to Replace with a random value

#### **NA constant value** *(available when NA handling is set to Replace with a constant value)*

**NA constant value** sets the constant used to impute every missing value, from `0` to `1`.

**Default** · `0`

![NA Constant Value, shown when NA handling is set to Replace with a constant value](https://docs.cosmosid.com/images/mbs_na_constant_value.png)

NA Constant Value, shown when NA handling is set to Replace with a constant value

## Collapse features by

● Merge and filter
Feature aggregation

**Collapse features by** aggregates the features that share the same value in the selected feature column, for example the same name, by summing their abundances. One metabolite can appear as several features, for example as different ions of the same molecule in untargeted data. These duplicates count the same metabolite more than once in distances, models and statistical tests.

| Option | What it changes |
| :- | :- |
| None | No aggregation. |
| `name` | Features with the same name are summed into one. |
| A column ending in `_id`, for example `compound_id`, `smiles_id` or `chebi_id` | Features with the same identifier are summed into one. More reliable than `name` when a molecule has synonyms. |
| `msid` | Features with the same `msid` are summed into one. |

![Collapse features by in the PREPROC section](https://docs.cosmosid.com/images/mbs_collapse_features_by.png)

Collapse features by in the PREPROC section

> [!WARNING]
>
> Features with no value in the selected column are merged together into one feature called `unknown`. In untargeted data, for example, collapsing by name merges all the features that have no name.

## Prevalence threshold

● Merge and filter
Feature filtering

**Prevalence threshold** filters out the features detected in fewer than the selected proportion of samples. Prevalence is the proportion of samples in which a feature is detected. A feature is detected in a sample when its value is not zero, not below the LOD and not missing. Values between the LOD and the LOQ and values above the ULOQ count as detected.

Features detected in only a few samples carry little information. Most of their values are replaced or missing, and each of them adds a statistical test, which makes the correction for multiple testing stricter. Removing them makes the results more robust. A threshold that is too high can remove metabolites present in only one group, for example a drug metabolite found only in treated mice.

| Value | What it changes |
| :- | :- |
| `0` | No filtering. |
| `0.1` | Features detected in fewer than 10% of samples are removed. |
| `0.2` | Features detected in fewer than 20% of samples are removed. |
| Higher values | Stricter filtering. |

After this step, the features and the samples left with no values are removed from the table.

![Prevalence threshold in the PREPROC section](https://docs.cosmosid.com/images/mbs_prevalence_threshold.png)

Prevalence threshold in the PREPROC section

## Normalization

● Make samples comparable
Data transformation

**Normalization** rescales each sample by a sample-specific factor, to correct for differences between samples that are not biological, such as sample amount or dilution. The total signal of a sample depends on technical factors, such as the amount of material extracted, the dilution of the extract and the sensitivity of the instrument on that day. Without a correction, a sample with more material shows higher values for all metabolites, and this can look like a biological effect.

| Option | What it changes |
| :- | :- |
| None | No normalization. |
| `Total sum` | Each sample is divided by its total, so it sums to 1. Values become compositional. |
| `Probabilistic quotient (PQN)` | Each sample is divided by the median of its ratios to a reference profile, the median sample. Robust to a few dominant features. |
| `External factor (metadata column)` | Each sample is divided by its value in **External factor column**. |
| `Internal standard feature` | Each sample is divided by its value of the **Internal standard feature**. |

![Normalization in the PREPROC section](https://docs.cosmosid.com/images/mbs_normalization.png)

Normalization in the PREPROC section

#### **External factor column** *(available when Normalization is set to External factor)*

**External factor column** selects the sample metadata column used as the normalization factor, for example the mass of each stool sample.

#### **Internal standard feature** *(available when Normalization is set to Internal standard feature)*

**Internal standard feature** selects the feature used as the normalization factor in each sample. An internal standard is a known amount of a compound added to every sample before the measurement.

## Transformation

● Make samples comparable
Data transformation

**Transformation** applies a mathematical function, such as a logarithm, to every value, to reduce skewness and stabilise the variance. Metabolite values are usually skewed, with many low values and a few very high ones, and the variation of a metabolite often grows with its level. Many statistical tests and models work better with values that are more symmetric and have a similar variation across the range.

A logarithm gives this, and it turns fold changes into differences, so a doubling has the same size at any level.

| Option | What it changes |
| :- | :- |
| None | No transformation. |
| `Log2` | log₂(x). A difference of 1 is a twofold change. |
| `Log10` | log₁₀(x). A difference of 1 is a tenfold change. |
| `Natural log (ln)` | ln(x). |
| `Centered log-ratio (CLR)` | ln(x / geometric mean of the sample). Values become relative to the other features in the sample. |
| `Box-Cox` | Power transformation with λ fitted per feature to approximate normality. Features with fewer than 8 positive values get ln(x). |

A logarithm cannot take zero or missing values. Before the transformation, zeros, negative values and missing values are replaced with the LOD of the feature. When the table has no LOD column, they are replaced with half the lowest positive value of that feature.

![Transformation in the PREPROC section](https://docs.cosmosid.com/images/mbs_transformation.png)

Transformation in the PREPROC section

## Scaling

● Make samples comparable
Data transformation

**Scaling** rescales each feature to a comparable range, which sets how much weight each feature has in the analysis. After the transformation, the features can still have very different variation. Methods based on variation, such as PCA and PLS-DA, are then driven by the features that vary the most, which are not always the most relevant ones in biology.

| Option | What it changes |
| :- | :- |
| None | No scaling. Features with high variance dominate. |
| `Unit variance (autoscaling)` | (x − mean) / SD per feature. All features get unit variance and equal weight. |
| `Pareto` | (x − mean) / √SD per feature. Differences in variance are reduced but kept. |
| `Binary (presence/absence)` | 1 if x > 0, otherwise 0. |

![Scaling in the PREPROC section](https://docs.cosmosid.com/images/mbs_scaling.png)

Scaling in the PREPROC section

## Recommended Pre-processing parameters

Select the type of Data Table to see the recommended value of each pre-processing parameter. These values are also the defaults that the modules set for each Data Table.

> [tab] Targeted quantified
>
> | Parameter | Recommended value |
> | :- | :- |
> | Level of Annotation | Not available |
> | Zero handling | `Missing at random: set zeros to NA` |
> | Below LOD | `Replace with LOD/2` |
> | Between LOD and LOQ | `Keep and flag` |
> | Above ULOQ | `Replace with ULOQ` |
> | NA handling | `Keep as missing` |
> | Collapse features by | None |
> | Prevalence threshold | `0` |
> | Normalization | None |
> | Transformation | `Log2` |
> | Scaling | None |

> [tab] Targeted peak areas
>
> | Parameter | Recommended value |
> | :- | :- |
> | Level of Annotation | Not available |
> | Zero handling | `Missing at random: set zeros to NA` |
> | Below LOD | `Replace with LOD/2` |
> | Between LOD and LOQ | `Keep and flag` |
> | Above ULOQ | `Replace with ULOQ` |
> | NA handling | `Keep as missing` |
> | Collapse features by | None |
> | Prevalence threshold | `0.1` |
> | Normalization | `Total sum` |
> | Transformation | `Log2` |
> | Scaling | None |

> [tab] Untargeted peak areas
>
> | Parameter | Recommended value |
> | :- | :- |
> | Level of Annotation | All levels |
> | Zero handling | `Missing at random: set zeros to NA` |
> | Below LOD | `Keep and flag` |
> | Between LOD and LOQ | `Keep and flag` |
> | Above ULOQ | `Keep and flag` |
> | NA handling | `Keep as missing` |
> | Collapse features by | None |
> | Prevalence threshold | `0.2` |
> | Normalization | `Total sum` |
> | Transformation | `Log2` |
> | Scaling | None |

> [!NOTE]
>
> Some analysis modules change these defaults because their method needs it:
>
> * **PCA Explorer** removes the features with missing values, applies no normalization and no transformation, and uses `Unit variance (autoscaling)`.
> * **PLS-DA** applies no normalization and no transformation, and uses `Unit variance (autoscaling)`.
> * **ML Classification** uses `Unit variance (autoscaling)`.
> * **ML Regression** uses `Unit variance (autoscaling)` and removes the samples with no value for the target variable.
> * **Alpha diversity** skips zero handling, keeps missing values and applies no normalization, transformation or scaling, because richness only counts which metabolites are detected. Its PREPROC section shows only **Analysis metric**, **Level of Annotation**, **Collapse features by** and **Prevalence threshold**.
>
> **Heatmap**, **Bar Charts** and **Univariate comparison** use the defaults of the Data Table.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.