💪
Omics data visualization in R and Python
  • Introduction
    • From Authors
    • Virtual environments - let's begin
    • Getting started with Python
    • Getting started with R
    • Example data sets
  • PERFORMING FUNDAMENTAL OPERATIONS ON OMICs DATA USING R
    • Fundamental data structures
    • Loading data into R
    • Preferred formats in metabolomics and lipidomics analysis
    • Preprocess data type using Tidyverse package
    • Useful R tricks and features in OMICs mining
      • Application of pipe (%>%) functions
      • Changing data frames format with pivot_longer()
      • Data wrangling syntaxes useful in OMICs mining
      • Writing functions in R
      • The 'for' loop in R (advanced)
  • PERFORMING FUNDAMENTAL OPERATIONS ON OMICs DATA USING PYTHON
    • Fundamental data structures
    • Loading data into Python
  • Missing values handling in R
    • Missing values – Introduction
    • Detecting missing values (DataExplorer R package)
    • Filtering out columns containing mostly NAs
    • Data imputation by different available R libraries
      • Basic data imputation in R with dplyr and tidyr (tidyverse)
      • Data imputation using recipes library (tidymodels)
      • Replacing NAs via k-nearest neighbor (kNN) model (VIM library)
      • Replacing NAs via random forest (RF) model (randomForest library)
  • Missing values handling in Python
    • Detecting missing values
    • Filtering out columns containing mostly NAs
    • Data imputation
  • Data transformation, scaling, and normalization in R
    • Data normalization in R - fundamentals
    • Data normalization to the internal standards (advanced)
    • Batch effect corrections in R (advanced)
    • Data transformation and scaling - introduction
    • Data transformation and scaling using different available R packages
      • Data transformation and scaling using mutate()
      • Data transformation and scaling using recipes R package
      • Data Normalization – bestNormalize R package
  • Data transformation, scaling, and normalization in Python
    • Data Transformation and scaling in Python
  • Metabolites and lipids descriptive statistical analysis in R
    • Computing descriptive statistics in R
    • Using gtsummary to create publication-ready tables
    • Basic plotting in R
      • Bar charts
      • Box plots
      • Histograms
      • Density plots
      • Scatter plots
      • Dot plots with ggplot2 and tidyplots
      • Correlation heat maps
    • Customizing ggpubr and ggplot2 charts in R
    • Creating interactive plots with ggplotly
    • GGally for quick overviews
  • Metabolites and lipids descriptive statistics analysis in Python
    • Basic plotting
    • Scatter plots and linear regression
    • Correlation analysis
  • Metabolites and lipids univariate statistics in R
    • Two sample comparisons in R
    • Multi sample comparisons in R
    • Adjustments of p-values for multiple comparisons
    • Effect size computation and interpretation
    • Graphical representation of univariate statistics
      • Results of tests as annotations in the charts
      • Volcano plots
      • Lipid maps and acyl-chain plots
  • Metabolites and lipids univariate statistical analysis in Python
    • Two sample comparisons in Python
    • Multi-sample comparisons in Python
    • Statistical annotations on plots
  • Metabolites and lipids multivariate statistical analysis in R
    • Principal Component Analysis (PCA)
    • t-Distributed Stochastic Neighbor Embedding (t-SNE)
    • Uniform Manifold Approximation and Projection (UMAP)
    • Partial Least Squares (PLS)
    • Orthogonal Partial Least Squares (OPLS)
    • Hierarchical Clustering (HC)
      • Dendrograms
      • Heat maps with clustering
      • Interactive heat maps
  • Metabolites and lipids multivariate statistical analysis in Python
    • Principal Component Analysis
    • t-Distributed Stochastic Neighbor Embedding
    • Uniform Manifold Approximation and Projection
    • PLS Discriminant Analysis
    • Clustered heatmaps
  • OMICS IN MACHINE LEARNING APPROACHES IN R AND PYTHON
    • Application of selected models to OMICs data
    • OMICs machine learning – Examples
  • References
    • Library versions
Powered by GitBook
On this page
  • Required packages
  • Loading the data
  • Boxplots
  1. Metabolites and lipids univariate statistical analysis in Python

Statistical annotations on plots

PreviousMulti-sample comparisons in PythonNextPrincipal Component Analysis (PCA)

Last updated 7 months ago

Required packages

The required package for this section is statannotations, which will also automatically install the pandas and seaborn packages, on which it is dependent. As of statannotations version 0.6, it unfortunately relies on outdated versions of pandas and seaborn. These can be installed with the following command in the command window (Windows) / terminal (Mac).

pip install statannotations

On Windows systems, the above command to install statannotations may give an error stating that the building of the wheels has failed. To fix this error the Visual studio C++ build tools have to be installed. You can use and check the options as shown in the screenshot below:

After the installation has completed run the following commands in the terminal:

pip install --upgrade setuptools
pip install statannotations

The statsannotations library should now have installed correctly.

Loading the data

We will again use the demo lipidomics dataset:

Load the dataset into a Pandas DataFrame named df as described in the basic plotting section:

import pandas as pd
df = pd.read_excel("Lipidomics_dataset.xlsx")
df.set_index("Sample Name", inplace=True)

Boxplots

To get the annotations of a statistical test drawn automatically on a plot, the statsanotations package can be used in combination with seaborn. We'll have to define, which column of our dataframe contains the x-axis variable (the "Label" column), and the y-variable is the lipid species of choice. We'll define the order in which we want the different "Label" groups to appear and which pairs we want to compare. Finally we'll also pass to the configurator which statistical test we want to use, Mann-Whitney in this case:

import seaborn as sns
from statannotations.Annotator import Annotator
import matplotlib.pyplot as plt

x = "Label"
y = "PC 36:5"
order = ['N', 'PAN', 'T']
pairs = [("N", "PAN"), ("N", "T"), ("PAN", "T")]
ax = sns.boxplot(data=df, x=x, y=y, order=order)
annot = Annotator(ax, pairs=pairs, data=df, x=x, y=y, order=order)
annot.configure(test='Mann-Whitney', loc='inside')
annot.apply_test()
annot.annotate()
plt.show()

this installer
348KB
Lipidomics_dataset.xlsx