> ## 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.

# Bar Charts on Cosmos-Hub 2.0

> Bar charts are simple visualizations that let you compare the abundance of compounds detected and quantified in a metabolomics experiment across your samples.

Available for

The **Bar Chart** module lets you inspect and compare the measured values of single compounds across metabolomic samples. Use it to check the quality of a measurement against its limits, to spot outlier samples, and to visually assess whether the amount of a compound is different across your groups of interest.

This module generates a bar chart for each compound, with one bar per sample. Each chart shows how the amount of one compound varies across the samples of the current Data Table. To learn how metabolomics Data Tables are structured, see [Metabolomics Data](https://docs.cosmosid.com/metabolomics-data.md).

# Run the analysis

## 1. Set Pre-processing parameters

Depending on the type of Metabolomics Data Table (targeted quantified or peak values, untargeted peak values ), set the pre-processing parameters, following the [recommended parameters](#recommended-parameters). See [Pre-processing Metabolomics Data](https://docs.cosmosid.com/pre-processing-of-metabolomics-data.md) for more details on the pre-processing parameters for metabolomics.

## 2. Choose the value scale

Set [**Value scale**](#value-scale) to choose whether the y-axis of the bars reports the abundance of the compound in its original scale (`raw`) or after pre-processing (`processed`, after normalization, transformation and scaling). Each compound is measured on its own scale and in its own units, so the module draws one chart per compound.

* Use `raw` to read amounts in their original units, for example the concentrations of a targeted panel, and to check each sample against the limits of detection and quantification of the compound.
* Use `processed` when the raw values of different samples are not directly comparable, for example peak areas that also depend on the amount of sample extracted. It also shows the compound as the other metabolomics modules analyse it, which helps to explain their results.

Try both options in the [interactive bar chart](#bar-charts) below.

> [card] raw (default)
>
> The scale of the bar chart is as reported in the Data Table, for example concentrations in mM. Use it to read amounts in their original units and to compare them with the LOD.

> [card] processed
>
> The values after **Normalization**, **Transformation** and **Scaling**, the same values that the other metabolomics modules analyse.

With `raw`, check [**Show LOD/LOQ/ULOQ reference lines**](#show-lod-loq-uloq-reference-lines) to draw the limits of the compound on each chart.

> [!NOTE]
>
> Reference lines are drawn only with `raw` values. After normalization, each sample is divided by its own factor, so a single limit no longer sits at the same height for every sample.

## 3. Choose which compounds to show

A Metabolomics Data Table can hold measurements for thousands of compounds. The Bar Chart module displays charts for a limited number of top-ranked compounds.

* Set [**Feature ranking method**](#feature-ranking-method) to choose how the compounds are ranked.
  * `mean` puts first the compounds with the highest average amount, the most abundant ones.
  * `prevalence` puts first the compounds detected in the most samples, above the LOD.
  * `variance` puts first the compounds whose amount varies most between samples, which are often those that differ between groups.
  * `percentile` puts first the compounds with the highest 90th percentile, which also catches compounds that are high in a subset of samples only.
* Set [**Top features (N)**](#top-features-n) to choose how many compounds, from the top of this ranking, get a chart. All N charts are created and exported.
* Set [**Max Figures to Display**](#max-figures-to-display) to choose how many of these N charts are shown on screen. The charts that are not shown are still included in the export.

> [!NOTE]
>
> **Example** With **Feature ranking method** set to `mean`, **Top features (N)** set to `10` and **Max Figures to Display** set to `5`, the module ranks the compounds by their mean across the cohort and creates charts for the top 10. It shows the first 5 on screen and exports all 10.

## 4. Annotate and arrange the samples

Set [**Sample Annotation**](#sample-annotation) to the metadata fields of your study design, such as treatment or time point. Each field becomes a coloured track above the bars, so you can tell at a glance whether high or low values of a compound come from one group, for example treated mice or a single visit.

By default, the samples follow the order of the Data Table, so the samples of one group can be scattered along the x-axis. Arranging the samples by metadata places the samples of each group next to each other, which makes differences between groups and trends over time easier to see. Set [**Sample arrangement**](#sample-arrangement) to:

* `sort` to order the samples by the fields in [**Sample ordering metadata**](#sample-ordering-metadata), for example by visit to follow a time course.
* `facet` to split the samples into one panel per value of [**Metadata column for faceting**](#metadata-column-for-faceting), for example coffee drinkers and non-coffee drinkers. The samples are sorted within each panel, and all panels share the same y-axis, so their bars can be compared directly.

## 5. Customise the charts

* Set [**Feature color palette**](#feature-color-palette) to choose the colours of the bars.
* Uncheck [**Show sample labels**](#show-sample-labels) to hide the sample names when there are too many to read.

# Module outputs and how to read them

> [card] [Bar charts](#bar-charts)
>
> One chart per selected compound, with one bar per sample.

> [card] [Selected features table](#selected-features-table)
>
> The compounds charted and their reference limits.

> [card] [Exported files](#exported-files)
>
> The charts, the tables and the data behind them.

## Bar charts

Change the parameters on the right of the chart to see how each one changes the bars, and hover over any part of the chart to see what it shows.

> [!NOTE]
>
> The chart uses example data from a targeted panel. Each sample also has its own sample amount, as if some extracts were more diluted than others, and this amount scales all its compounds. Set **Value scale** to `processed` and choose a **Normalization** to see how normalization removes this effect.

### Why is this plot useful?

* **Check the quality of the measurement.** See how many samples are close to or below the LOD before you analyse a compound.
* **Spot outlier samples.** A sample with a value far above the others can drive a group difference on its own.
* **See patterns across samples.** Sort or facet the samples by group or time point to see whether the amount of a compound follows them.
* **Explain a result from another module.** Look at the values of a compound found by [Univariate comparison](https://docs.cosmosid.com/DAP_docs/univariate-comparison.md) or by a model, sample by sample.

## Selected features table

The module also shows a table with one row per charted compound. It reports the LOD, LOQ and ULOQ of each compound, when the Data Table has them, and whether reference lines were drawn on its chart. The table is exported as `selected_features.csv`.

`selected_features.csv`
One row per charted compound, with its reference limits.

<table>
  <thead>
    <tr />
  </thead>

  <tbody />
</table>

## Exported files

Click **Export** to download the charts together with the tables behind them.

| File | What it contains |
| :- | :- |
| `<feature>_barchart.png` | One chart for each selected compound, including the charts not shown on screen. |
| `selected_features.csv` | The selected compounds and their reference limits. |
| `parameters.txt` | The parameter values used. |
| `input_features.csv` and `input_metadata.csv` | The Data Table and the sample metadata before pre-processing. |
| `transformed_features.csv` | The values shown in the charts, raw or processed depending on **Value scale**. |
| `transformed_metadata.csv` | The sample metadata of the samples in the charts. |
| `transformed_presence_matrix.csv` and `transformed_status_matrix.csv` | Whether each compound is detected in each sample, and why (for example below the LOD or missing), for the compounds and samples in the charts. |
| `prefilter_presence_matrix.csv` and `prefilter_status_matrix.csv` | The same information before features and samples are filtered. |
| `excluded_samples.csv` | The samples removed by pre-processing or by missing annotation values. |

## Recommended parameters

Choose the type of your Data Table. Hover an underlined value to see why it is recommended. For the pre-processing parameters, see [Recommended Pre-processing parameters](https://docs.cosmosid.com/pre-processing-of-metabolomics-data.md#recommended-pre-processing-parameters).

> [tab] Targeted counts
>
> > [!TIP]
> >
> > **Suitable and interpretable.** Each compound is a known metabolite with its own LOD, LOQ and ULOQ, so the raw bars can be read directly against these limits.
>
> | Parameter | Recommended value |
> | :- | :- |
> | Prevalence threshold | `0` (A targeted panel is short and chosen in advance, so every compound is usually worth a chart.) |
> | Value scale | `raw` |
> | Show LOD/LOQ/ULOQ reference lines | ✅ |
> | Feature ranking method | `mean` |
> | Top features (N) | The number of compounds in the panel (With N equal to the number of compounds in the panel, every compound gets a chart.) |
> | Max Figures to Display | The same as **Top features (N)** |
> | Sample Annotation | The metadata fields of your study design, such as group and time point |
> | Sample arrangement | `facet` by the main group, or `sort` by time point |

> [tab] Targeted peak areas
>
> > [!WARNING]
> >
> > **Interpretable with care.** Peak areas are signal intensities, not concentrations. They also depend on the amount of sample and on the instrument, so raw bars of different samples are not directly comparable.
>
> | Parameter | Recommended value |
> | :- | :- |
> | Prevalence threshold | `0` to `0.1` |
> | Value scale | <ul><li>`raw` to check the signal against the LOD</li><li>`processed` (Normalization corrects for differences in sample amount and instrument response between samples.) to compare samples</li></ul> |
> | Normalization (with `processed`) | `Total sum` or `Probabilistic quotient (PQN)` |
> | Transformation (with `processed`) | None (Bars of untransformed values are easier to read. A log scale compresses high values.) |
> | Show LOD/LOQ/ULOQ reference lines | ✅ when the Data Table has an LOD column |
> | Feature ranking method | `mean` |
> | Top features (N) | The number of compounds in the panel |
> | Sample Annotation | The metadata fields of your study design |

> [tab] Untargeted peak areas
>
> > [!WARNING]
> >
> > **Interpretable with care.** An untargeted table holds hundreds to thousands of features, so the module charts only the top N. Raw peak areas depend on the amount of sample, and an untargeted LOD is less formal than a targeted one.
>
> | Parameter | Recommended value |
> | :- | :- |
> | Level of Annotation | `1` and `2a` (Features at levels 1 and 2a have a confirmed or well supported name, so the charts are easier to interpret.) |
> | Collapse features by | `name` (One metabolite can appear as several features. Collapsing avoids charting the same molecule twice. Reference lines are hidden when features are collapsed.) |
> | Value scale | `processed` |
> | Normalization | `Total sum` or `Probabilistic quotient (PQN)` |
> | Transformation | None |
> | Feature ranking method | <ul><li>`mean` for the most abundant features</li><li>`variance` for the features that vary most between samples</li></ul> |
> | Top features (N) | `10` to `20` |
> | Sample Annotation | The metadata fields of your study design |

## Analysis parameter reference

> [accordion] Value scale
>
> Sets which values the bars show.
>
> **Options**
>
> * `raw` shows the values as reported in the Data Table, in their original units. Cells with a text code such as `<LOD` have no bar.
> * `processed` shows the values after **Normalization**, **Transformation** and **Scaling**.
>
> **Default** · `raw`
>
> **Suggested** · `raw` for targeted quantified data and to compare values with the LOD. `processed` for peak areas, to correct for differences in sample amount.
>
> > [!NOTE]
> >
> > Pre-processing decides which compounds and samples are charted with both options. The steps that replace values, such as **Below LOD** or **NA handling**, change only the `processed` values. Reference lines are hidden with `processed`.

> [accordion] Show LOD/LOQ/ULOQ reference lines
>
> Draws horizontal lines at the limits of each compound, the limit of detection (LOD, dotted), the limit of quantification (LOQ, dashed) and the upper limit of quantification (ULOQ, dash-dot). Available when **Value scale** is `raw` and **Collapse features by** is empty.
>
> **Options** · `TRUE` or `FALSE`
>
> **Default** · `TRUE`
>
> > [!NOTE]
> >
> > A line is drawn only when the Data Table has a value for that limit and compound. Targeted tables usually report LOD, LOQ and ULOQ for each compound. Untargeted tables can report an LOD only. Lines are hidden when features are collapsed, because a group of compounds has no single limit.

> [accordion] Sample Annotation
>
> Shows one or more metadata fields as coloured tracks above the bars, one row per field. The fields chosen here are also the ones available to sort and facet the samples.
>
> **Options** · The metadata fields of the samples. Several fields can be selected.
>
> **Default** · `None`
>
> **Suggested** · The fields of your study design, such as `treatment`, `time point` or `subject`.

> [accordion] Drop samples with missing annotation
>
> Removes the samples that have no value in the fields chosen in [**Sample Annotation**](#sample-annotation). Available when a field is selected.
>
> **Options** · `TRUE` or `FALSE`
>
> **Default** · `TRUE`
>
> > [!NOTE]
> >
> > With `FALSE`, missing values are shown as a group called `NaN_group`. Removed samples are listed in `excluded_samples.csv`.

> [accordion] Feature ranking method
>
> Sets how the compounds are ranked before the top N are charted.
>
> **Options**
>
> * `mean` ranks by the average value across samples.
> * `prevalence` ranks by the share of samples in which the compound is detected. A compound is not detected when its value is zero, below the LOD or missing.
> * `variance` ranks by how much the values vary between samples.
> * `percentile` ranks by the 90th percentile of the values, the value that 90% of the samples do not exceed.
>
> **Default** · `mean`
>
> **Suggested** · `mean` for a targeted panel. `variance` to find the untargeted features that differ most between samples.

> [accordion] Top features (N)
>
> Sets how many top-ranked compounds get a chart.
>
> **Options** · Integer from `1` to `30`
>
> **Default** · `10`
>
> **Suggested** · The number of compounds in a targeted panel, or `10` to `20` for untargeted data.

> [accordion] Max Figures to Display
>
> Sets how many charts are shown on screen. The export always contains the charts of all the selected compounds.
>
> **Options** · Integer from `0` to `20`
>
> **Default** · `5`

> [accordion] Feature color palette
>
> Sets the colour palette of the bars. Each compound gets its own colour from the palette, so consecutive charts are easy to tell apart.
>
> **Options** · Qualitative palettes, such as `tab20` or `Set2`, and sequential palettes, such as `viridis` or `Blues`
>
> **Default** · `tab20`

> [accordion] Show sample labels
>
> Shows the sample names under the bars.
>
> **Options** · `TRUE` or `FALSE`
>
> **Default** · `TRUE`
>
> **Suggested** · `FALSE` when there are too many samples for the names to be readable.

> [accordion] Sample arrangement
>
> Sets how the samples are arranged along the x-axis. Available when at least one field is selected in [**Sample Annotation**](#sample-annotation).
>
> **Options**
>
> * `None` keeps the order of the samples in the Data Table.
> * `sort` orders the samples by the fields in [**Sample ordering metadata**](#sample-ordering-metadata).
> * `facet` splits the samples into panels, one for each value of [**Metadata column for faceting**](#metadata-column-for-faceting), and sorts them within each panel. The panels share the same y-axis.
>
> **Default** · `None`
>
> > [!NOTE]
> >
> > `sort` and `facet` need at least one field in **Sample ordering metadata**. If the faceting field has only one value, the samples are sorted without panels.

> [accordion] Sample ordering metadata
>
> Sets the fields used to order the samples, among those chosen in [**Sample Annotation**](#sample-annotation). Available when **Sample arrangement** is `sort` or `facet`.
>
> **Options** · The fields selected in **Sample Annotation**. Several fields can be selected, and the samples are sorted by the first one, then by the next.
>
> **Default** · `None`

> [accordion] Samples in ascending order
>
> Sets the direction of the sorting. Available when a field is selected in [**Sample ordering metadata**](#sample-ordering-metadata).
>
> **Options** · `TRUE` (ascending) or `FALSE` (descending)
>
> **Default** · `TRUE`

> [accordion] Metadata column for faceting
>
> Sets the field that splits the samples into panels, among those chosen in [**Sample ordering metadata**](#sample-ordering-metadata). Available when **Sample arrangement** is `facet`.
>
> **Options** · The fields selected in **Sample ordering metadata**
>
> **Default** · `None`. When empty, the first field in **Sample ordering metadata** is used.


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