Structuring data



Recipe Overview
Reading Time
30 minutes
Executable Code
Yes
Difficulty
FAIRifying Data Matrices - Step2 - Structuring data matrices
FAIRPlus logo
Recipe Type
Hands-on
Maturity Level & Indicator
DSM-1-C0DSM-1-C1
hover me Tooltip text

Background:

Experimental results such as metabolite profiling data published in [1,2] can be straightforwardly reported using OKFN Data Packages. Such components can be easily parsed as data frames and exploited for data visualization purpose using libraries implementing graphical grammar concepts. Here, we show how to use the python equivalent of ggplot2: the rich R graphical libraries (https://ggplot2.tidyverse.org/). A few lines of code allow querying 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.

1. Let’s begin by installing the Python packages allowing easy access and use of data formatted as JSON Data Package

import pandas as pd
import numpy as np
from plotnine import *

2. Reading the data

We now simply read in the comma-separated-file associated with the tabular data package (a “long” table)

data = pd.read_csv("../data/processed/rose-data/rose-aroma-naturegenetics2018-treatment-group-mean-sem-report-table-example.csv")

Alternately, one could read the relevant data file from the corresponding zenodo dataset

#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") 
data.head()

3. Plotting the data:

We then generate a barplot using the python plotnine library, which delivers a similar functionality as the R ggplot2 package

# width = figure_size[0]
# height = figure_size[0] * aspect_ratio
gray = '#666666'
orange = '#FF8000'
blue = '#3333FF'

p1 = (ggplot(data)
 + aes('chemical_name', 'sample_mean',fill='factor(treatment)')
 + geom_col()
 
 + theme(axis_text_x=element_text(rotation=90, hjust=1, fontsize=6, color=blue))
 + theme(axis_text_y=element_text(rotation=90, hjust=2, fontsize=6, color=orange))
 + scale_y_continuous(expand = (0,0))   
 + facet_wrap('~treatment', dir='v',ncol=1)
 + theme(figure_size = (8, 16))      
)

p1 + theme(panel_background=element_rect(fill=blue)
       )

p1

4. Let’s now compare the dataset generated in 2015 and the dataset generated in 2018

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

ng2018sc2015 = pd.read_csv("../data/processed/rose-data/rose_aroma_compound_science2015_vs_NG2018_data_integration.csv")
# ng2018sc2015 = pd.read_csv("https://zenodo.org/api/files/268f29fc-8ead-4049-bb86-181b72073682/rose_aroma_compound_science2015_vs_NG2018_data_integration.csv")

5. We generate another barplot, which shows the concentration of the chemicals targeted by the GC-MS profiling assay

(ggplot(ng2018sc2015)
 + aes('chemical_name', 'normalized_to_total_sum_concentration',fill='factor(publication_year)')
 + geom_col()
 + facet_wrap('~publication_year', dir='h', ncol=1)
 + theme(axis_text_x=element_text(rotation=90, hjust=1, fontsize=6))

)

Conclusion

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.

Authors