{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "(fcb-notebook-2)=\n", "# Structuring data\n", "````{panels}\n", ":container: container-lg pb-3
\n", ":column: col-lg-3 col-md-4 col-sm-6 col-xs-12 p-1
\n", ":card: rounded
\n", "\n", "
\n", "^^^\n", "

Recipe metadata

\n", " identifier: FCB039\n", " version: v1.0\n", "\n", "---\n", "\n", "^^^\n", "

Difficulty level

\n", "\n", "\n", "\n", "\n", "\n", "\n", "---\n", "\n", "^^^\n", "

Reading Time

\n", " 30 minutes\n", "

Recipe Type

\n", " Hands-on\n", "

Executable Code

\n", " Yes\n", "\n", "---\n", "\n", "^^^\n", "

Intended Audience

\n", "\n", "

Data Manager

\n", "

Data Scientist

\n", "````\n", "---\n", "\n", "Background:\n", "\n", "Experimental results such as metabolite profiling data published in [1,2] can be straightfowardly reported using [OKFN Data Packages](https://frictionlessdata.io/specs/tabular-data-package/). Such components can be easily parsed as data frames and exploited for data visualization purpose using libraries implementing graphical grammar concepts.\n", "Here, we show how to use the python equivalent of ggplot2: the rich R graphical libraries (https://ggplot2.tidyverse.org/).\n", "A few lines of code allow to query datasets and rapidly explore the information. Most importantly, this rapid exploration is possible because of independent variables and because their levels have been clearly and unambiguously declared in the Tabular Data Package itself." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "1. Let's begin by installing the Python packages allowing easy access and use of data formatted as JSON Data Package" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "from plotnine import *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2. Reading the data\n", "\n", "We now simply read in the comma-separated-file associated with the tabular data package (a \"long\" table)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "data = pd.read_csv(\"../data/processed/rose-data/rose-aroma-naturegenetics2018-treatment-group-mean-sem-report-table-example.csv\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alternately, one could read the relevant data file from the corresponding zenodo dataset" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "#data = pd.read_csv(\"https://zenodo.org/api/files/ba3fbc84-14af-4858-a9ed-e6cfe8d4efd2/rose-aroma-naturegenetics2018-treatment-group-mean-sem-report-table-example.csv\") " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "data.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "3. Plotting the data: We then generate a barplot using the python plotnine library, which delivers a similar functionality as the R ggplot2 package" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "# width = figure_size[0]\n", "# height = figure_size[0] * aspect_ratio\n", "gray = '#666666'\n", "orange = '#FF8000'\n", "blue = '#3333FF'\n", "\n", "p1 = (ggplot(data)\n", " + aes('chemical_name', 'sample_mean',fill='factor(treatment)')\n", " + geom_col()\n", " \n", " + theme(axis_text_x=element_text(rotation=90, hjust=1, fontsize=6, color=blue))\n", " + theme(axis_text_y=element_text(rotation=90, hjust=2, fontsize=6, color=orange))\n", " + scale_y_continuous(expand = (0,0)) \n", " + facet_wrap('~treatment', dir='v',ncol=1)\n", " + theme(figure_size = (8, 16)) \n", ")\n", "\n", "p1 + theme(panel_background=element_rect(fill=blue)\n", " )\n", "\n", "p1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "4. Let's now compare the dataset generated in 2015 and the dataset generated in 2018\n", "\n", "Both datasets have been generated by the same team, on the same genotype (Rosa Chinensis 'Old Blush') and organism part ('sepals'). Both datasets are held in a Tabular Data Package with the same structure. To perform the comparison, we have simply created another tabular data package, which retains the exact same structure and that simply holds the measurements for the relevant conditions extracted from each dataset (the function to create such file is omitted)." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "ng2018sc2015 = pd.read_csv(\"../data/processed/rose-data/rose_aroma_compound_science2015_vs_NG2018_data_integration.csv\")\n", "# ng2018sc2015 = pd.read_csv(\"https://zenodo.org/api/files/268f29fc-8ead-4049-bb86-181b72073682/rose_aroma_compound_science2015_vs_NG2018_data_integration.csv\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "5. We generate another barplot, which shows the concentration of the chemicals targeted by the GC-MS profiling assay" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "(ggplot(ng2018sc2015)\n", " + aes('chemical_name', 'normalized_to_total_sum_concentration',fill='factor(publication_year)')\n", " + geom_col()\n", " + facet_wrap('~publication_year', dir='h', ncol=1)\n", " + theme(axis_text_x=element_text(rotation=90, hjust=1, fontsize=6))\n", "\n", ")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What do we see? The figure shows how consistent the chemical profile of the scent between the 2 studies is, and which prevalent compounds such as X, Y, and Z show roughly similar relative amount within and across studies." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Bibliographic References**\n", "\n", "[1. Magnard JL, Roccia A, Caissard JC, Vergne P, Sun P, Hecquet R, Dubois A, Hibrand-Saint Oyant L, Jullien F, Nicolè F, Raymond O, Huguet S, Baltenweck R, Meyer S, Claudel P, Jeauffre J, Rohmer M, Foucher F, Hugueney P, Bendahmane M, Baudino S. PLANT VOLATILES. Biosynthesis of monoterpene scent compounds in roses. Science. 2015 Jul 3;349(6243):81-3.](https://doi.org/10.1126/science.aab0696)\n", "\n", "[2. Raymond O, Gouzy J, Just J, Badouin H, Verdenaud M, Lemainque A, Vergne P, Moja S, Choisne N, Pont C, Carrère S, Caissard JC, Couloux A, Cottret L, Aury JM, Szécsi J, Latrasse D, Madoui MA, François L, Fu X, Yang SH, Dubois A, Piola F, Larrieu A, Perez M, Labadie K, Perrier L, Govetto B, Labrousse Y, Villand P, Bardoux C, Boltz V, Lopez-Roques C, Heitzler P, Vernoux T, Vandenbussche M, Quesneville H, Boualem A, Bendahmane A, Liu C, Le Bris M, Salse J, Baudino S, Benhamed M, Wincker P, Bendahmane M. The Rosa genome provides new insights into the domestication of modern roses. Nat Genet. 2018 Jun;50(6):772-777.](https://doi.org/10.1038/s41588-018-0110-3)\n" ] } ], "metadata": { "kernelspec": { "display_name": "venv372", "language": "python", "name": "venv372" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.2" } }, "nbformat": 4, "nbformat_minor": 2 }