diff --git a/docs/examples/ex02_Amersfoort/amersfoort.xlsx b/docs/examples/ex02_Amersfoort/amersfoort.xlsx new file mode 100644 index 0000000..eab70e2 Binary files /dev/null and b/docs/examples/ex02_Amersfoort/amersfoort.xlsx differ diff --git a/docs/examples/ex02_Amersfoort/example_02_amersfoort_NAscreening.ipynb b/docs/examples/ex02_Amersfoort/example_02_amersfoort_NAscreening.ipynb new file mode 100644 index 0000000..b24f30d --- /dev/null +++ b/docs/examples/ex02_Amersfoort/example_02_amersfoort_NAscreening.ipynb @@ -0,0 +1,214 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d7cb246f-47ce-46b5-ba06-cd636bc6528a", + "metadata": {}, + "source": [ + "# MiBiPreT example: Electron Balance with Amersfoort data\n", + "\n", + "Diagnostic plots for data analysis on microbial biodegredation at the contaminant Amersfoort site. Author: Alraune Zech\n", + "\n", + "Data based on the PhD thesis of *Johan van Leeuwen*, 2021 'Biodegredation of mono- and polyaromatic hydrocarbons in a contaminated aquifer originating from a former Pintsch gas factory site' which is equivalent to the manuscript of van Leeuwen et al., 2022 'Anaerobic degradation of benzene and other aromatic hydrocarbons in a tar-derived plume: Nitrate versus iron reducing conditions', J. of Cont. Hydrol. The data was provided by Johan van Leeuwen.\n", + " \n", + "## Background: Amersfoort contaminant site\n", + "\n", + "Close to the train station in Amersfoort, the Netherlands, the subsurface is contaminated with organic hydrocarbons forming a NAPL. Contamination originates from decades of operating manufactured gas plant, which dumped tar by-products in waste lagoons. The tar is a DNAPL and has spread into the underlying shallow unconfined aquifer. Sample wells were installed to measure various characteristics of the subsurface. The raw data contains measurements on\n", + "* environmental conditions, such as pH, redox potential, concentrations of oxygen, nitrate, etc\n", + "* contaminant concentration such as BTEX, indene, indane, naphtalene and multiple other (typically cyclic) petroleum hydrocarbons\n", + "* metabolite concentration, i.e. byproducts of degredation processes of contaminant\n", + "* isotope measurments for specific contaminants and samples\n", + "* counts of genes (RNA/DNA) of mibrobiota that is know to perform biodegredation as well as functional enzymes know to be responsible for biodegredation" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9a2d3f66-c10e-45a5-9f8d-69bdde8f1092", + "metadata": {}, + "outputs": [], + "source": [ + "import mibiscreen as mbs" + ] + }, + { + "cell_type": "markdown", + "id": "db939a97-8819-445c-98b8-3898a4538af0", + "metadata": {}, + "source": [ + "## Data loading" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "21e1706b-6580-4e81-a35c-7cb472e46a59", + "metadata": {}, + "outputs": [], + "source": [ + "file_path = './amersfoort.xlsx'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e7d94627-1002-414a-8156-d816b5f4dad0", + "metadata": {}, + "outputs": [], + "source": [ + "contaminants_raw,_ = mbs.load_excel(file_path,\n", + " sheet_name = 'contaminants')\n", + "contaminants,units = mbs.standardize(contaminants_raw)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "15c5a3f6-7c64-4db7-a796-c13573f5e6be", + "metadata": {}, + "outputs": [], + "source": [ + "environment_raw,_ = mbs.load_excel(file_path,\n", + " sheet_name = 'environment')\n", + "environment,units = mbs.standardize(environment_raw)" + ] + }, + { + "cell_type": "markdown", + "id": "1d6a3481-0bfe-4629-bece-b8f767a4ad0a", + "metadata": {}, + "source": [ + "## Electron balance: Simple NA screening analysis" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "135c4dd4-a338-493e-8297-9b092992cb69", + "metadata": {}, + "outputs": [], + "source": [ + "mbs.reductors(environment,\n", + " include = True,\n", + " ea_group = 'ONS')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aa9a6619-31eb-4511-b0e1-758878f58919", + "metadata": {}, + "outputs": [], + "source": [ + "mbs.oxidators(contaminants,include = True,\n", + " contaminant_group='BTEX')\n", + "mbs.oxidators(contaminants,include = True,\n", + " contaminant_group='BTEXIIN')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "36b036a4-68a8-4f98-bb4b-8611f0f688b2", + "metadata": {}, + "outputs": [], + "source": [ + "data_NA = mbs.merge_data([environment,contaminants])\n", + "mbs.electron_balance(data_NA,include = True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "904908ca-40a3-4d79-9507-6e2d64b625ba", + "metadata": {}, + "outputs": [], + "source": [ + "na_traffic = mbs.sample_NA_traffic(data_NA,include = True)" + ] + }, + { + "cell_type": "markdown", + "id": "fc55c15b-c30a-40a7-9468-a6bfec642f4a", + "metadata": {}, + "source": [ + "### Electron balance as bar plot\n", + "\n", + "Preprocess data selecting all relevant quantities and save in dictionary (`electron_balance_bar_data_prep()`) as input for visualization rountine `electron_balance_bar()`. Applied here to all samples for electron acceptors *oxygen*, *nitrate*, and *sulfate* and electron reducing contaminant groups *BTEXIIN* and *BTEX*. Samples are sorted according to available electrons. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4aa744d1-84c9-47b7-b147-136363171a59", + "metadata": {}, + "outputs": [], + "source": [ + "#data_NA.total_reductors.iloc[[21,11,20,3,17,18]]\n", + "#data_NA.total_oxidators_BTEX.iloc[[21,11,20,3,17,18]]\n", + "data_NA.total_oxidators_BTEXIIN.iloc[[21,11,20,3,17,18]]\n", + "data_NA.e_balance.iloc[[21,11,20,3,17,18]]\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "34bd7170-369a-4024-aa39-23e4ff59ecf9", + "metadata": {}, + "outputs": [], + "source": [ + "electron_balance_bar_dict = mbs.electron_balance_bar_data_prep(data_NA)\n", + "mbs.electron_balance_bar(electron_balance_bar_dict,\n", + " sample_nr = True, \n", + " figsize = [12,3],\n", + " xtick_autorotate = True,\n", + " )\n", + "\n", + "print(electron_balance_bar_dict)" + ] + }, + { + "cell_type": "markdown", + "id": "49b8be90-4780-4f34-bb12-8b2a04776995", + "metadata": {}, + "source": [ + "#### Electron balance analysis for selected samples\n", + "\n", + "Preprocess data selecting quantities for specified sample selection, save in dictionary and visualize." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "275e43d0-41ed-4b8a-bf7b-30e4936b3a60", + "metadata": {}, + "outputs": [], + "source": [ + "electron_balance_bar_dict = mbs.electron_balance_bar_data_prep(data_NA,\n", + " list_samples = [21,11,20,3,17,18])\n", + "mbs.electron_balance_bar(electron_balance_bar_dict,\n", + " loc = 'upper right')" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/examples/ex02_Amersfoort/example_02_amersfoort_concentrations.ipynb b/docs/examples/ex02_Amersfoort/example_02_amersfoort_concentrations.ipynb new file mode 100644 index 0000000..0d23bfd --- /dev/null +++ b/docs/examples/ex02_Amersfoort/example_02_amersfoort_concentrations.ipynb @@ -0,0 +1,529 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "aec1962d-a737-4453-a3b5-fae36f566c12", + "metadata": {}, + "source": [ + "# MiBiPreT example: Contaminant Data Screening with Amersfoort data\n", + "\n", + "Diagnostic plots for data analysis on microbial biodegredation at the contaminant Amersfoort site. Author: Alraune Zech\n", + "\n", + "Data based on the PhD thesis of *Johan van Leeuwen*, 2021 'Biodegredation of mono- and polyaromatic hydrocarbons in a contaminated aquifer originating from a former Pintsch gas factory site' which is equivalent to the manuscript of van Leeuwen et al., 2022 'Anaerobic degradation of benzene and other aromatic hydrocarbons in a tar-derived plume: Nitrate versus iron reducing conditions', J. of Cont. Hydrol. The data was provided by Johan van Leeuwen.\n", + " \n", + "## Background: Amersfoort contaminant site\n", + "\n", + "Close to the train station in Amersfoort, the Netherlands, the subsurface is contaminated with organic hydrocarbons forming a NAPL. Contamination originates from decades of operating manufactured gas plant, which dumped tar by-products in waste lagoons. The tar is a DNAPL and has spread into the underlying shallow unconfined aquifer. Sample wells were installed to measure various characteristics of the subsurface. The raw data contains measurements on\n", + "* environmental conditions, such as pH, redox potential, concentrations of oxygen, nitrate, etc\n", + "* contaminant concentration such as BTEX, indene, indane, naphtalene and multiple other (typically cyclic) petroleum hydrocarbons\n", + "* metabolite concentration, i.e. byproducts of degredation processes of contaminant\n", + "* isotope measurments for specific contaminants and samples\n", + "* counts of genes (RNA/DNA) of mibrobiota that is know to perform biodegredation as well as functional enzymes know to be responsible for biodegredation" + ] + }, + { + "cell_type": "markdown", + "id": "31ae9c4a-5652-4d9e-9dbf-6049ddc397cc", + "metadata": {}, + "source": [ + "**Required packages**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5d7a3f49-dd14-4e73-94fb-5a44a30c9e25", + "metadata": {}, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c7b46e09-3c59-4edf-9012-20c49aadd76a", + "metadata": {}, + "outputs": [], + "source": [ + "import mibiscreen as mbs" + ] + }, + { + "cell_type": "markdown", + "id": "6e0c6fd7-8285-451c-8510-1b0b6cebace3", + "metadata": {}, + "source": [ + "## Data loading" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1d1c7d9f-ad38-435f-afae-4f76e9dd1117", + "metadata": {}, + "outputs": [], + "source": [ + "file_path = './amersfoort.xlsx'" + ] + }, + { + "cell_type": "markdown", + "id": "19bfd716-6f89-4905-a41e-92df83bb7540", + "metadata": {}, + "source": [ + "Load and standardize data of contaminants:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e7d94627-1002-414a-8156-d816b5f4dad0", + "metadata": {}, + "outputs": [], + "source": [ + "contaminants_raw,units = mbs.load_excel(file_path,\n", + " sheet_name = 'contaminants',\n", + " verbose = False)\n", + "contaminants,units = mbs.standardize(contaminants_raw,\n", + " reduce = False,\n", + " verbose = False)" + ] + }, + { + "cell_type": "markdown", + "id": "280d0eca-65bb-4d65-947d-e8baf737a8eb", + "metadata": {}, + "source": [ + "Load and standardize data of metabolites" + ] + }, + { + "cell_type": "markdown", + "id": "82d45de5-fd2f-4570-adf8-677c9905dee2", + "metadata": {}, + "source": [ + "## Basic analysis of contaminant concentrations per sample" + ] + }, + { + "cell_type": "markdown", + "id": "eb3846cc-f8a1-400c-ae0e-d54babafac1a", + "metadata": {}, + "source": [ + "### Concentrations of contaminants subsets" + ] + }, + { + "cell_type": "markdown", + "id": "921703d6-3794-4f23-97b1-87b460994b6e", + "metadata": {}, + "source": [ + "**Total concentration of all contaminants provided in Excel-sheet/Dataframe:**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "86745044-65f1-4656-920c-5d69322282dd", + "metadata": {}, + "outputs": [], + "source": [ + "contaminants_concentration = mbs.total_concentration(contaminants,\n", + " name_list = 'all',\n", + " #include_as = \"concentration_contaminants\",\n", + " verbose = True)" + ] + }, + { + "cell_type": "markdown", + "id": "527decd6-3e31-4073-8636-2385e2f01a94", + "metadata": {}, + "source": [ + "equivalent to: \n", + "\n", + "(now including results as own data column to data frame of *contaminants*)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1dc4507a-e62d-4d1e-9529-4e3e7ffb520c", + "metadata": {}, + "outputs": [], + "source": [ + "mbs.total_contaminant_concentration(contaminants,\n", + " include = True,\n", + " verbose = True,\n", + " )\n", + "#display(contaminants)" + ] + }, + { + "cell_type": "markdown", + "id": "654b78f7-37d7-4c2b-89bf-74e7a6a582d0", + "metadata": {}, + "source": [ + "**Total concentration of contaminant subgroup: BTEX (Benzene, Toluene, Ethylbenzene, Xylene)**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9f9c7d31-16c9-4519-b828-4c45492dc467", + "metadata": {}, + "outputs": [], + "source": [ + "contaminants_BTEX = mbs.total_concentration(contaminants,\n", + " name_list = 'BTEX',\n", + " #include_as = \"concentration_BTEX\",\n", + " verbose = True,\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "5c2fc077-6234-4d4f-8e06-11e744410fe6", + "metadata": {}, + "source": [ + "equivalent to:(now including results as own data column to data frame of *contaminants*)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8140fdfe-19aa-4ef8-9181-2615043d2bd0", + "metadata": {}, + "outputs": [], + "source": [ + "mbs.total_contaminant_concentration(contaminants,\n", + " contaminant_group = 'BTEX',\n", + " include = True,\n", + " verbose = False)" + ] + }, + { + "cell_type": "markdown", + "id": "ac59869c-dda3-4545-94c7-ad46c7f52c43", + "metadata": {}, + "source": [ + "**Total concentration of contaminant subgroup: BTEX + Indene,Indane and Naphthalene**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a9462f46-04fe-4f84-8f4b-32182ec1a462", + "metadata": {}, + "outputs": [], + "source": [ + "contaminants_BTEXIIN = mbs.total_concentration(contaminants,\n", + " name_list = 'BTEXIIN',\n", + " #include_as = \"concentration_BTEXIIN\",\n", + " verbose = True,\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "7835f56f-4827-4ea7-907b-d196b9baa2d6", + "metadata": {}, + "source": [ + "Using wrapper functions for specific type of data, the previous commands are equivalent to: \n", + "\n", + "(now including results as own data column with standard name to data frame of *contaminants*)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "47ed7d53-cf9a-4f11-ae91-f213172f75bb", + "metadata": {}, + "outputs": [], + "source": [ + "mbs.total_contaminant_concentration(contaminants,\n", + " contaminant_group = 'BTEXIIN',\n", + " include = True,\n", + " verbose = False)" + ] + }, + { + "cell_type": "markdown", + "id": "7a478bbd-83d3-4aff-8697-ca3d35000812", + "metadata": {}, + "source": [ + "**Summed concentration of selected subgroup of contaminants: benzene & toluene**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7a50f096-491d-413f-abe6-87d18ac6405e", + "metadata": {}, + "outputs": [], + "source": [ + "contaminants_BT = mbs.total_concentration(contaminants,\n", + " name_list = ['benzene','toluene'],\n", + " include_as = \"concentration_BT\",\n", + " verbose = True,\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "565a6188-a164-421a-8e2d-3771a233994d", + "metadata": {}, + "source": [ + "### Visualization of contaminant concentrations per sample\n", + "\n", + "**Using mibiscreen plotting routine for concentration bar plots**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cedd3464-21db-43db-aeb2-f5c75ddcba0a", + "metadata": {}, + "outputs": [], + "source": [ + "list_contaminants = ['concentration_contaminants','concentration_BTEXIIN',\n", + " 'concentration_BTEX','concentration_BT','benzene']\n", + "\n", + "mbs.contaminants_bar(contaminants,\n", + " list_contaminants,\n", + " list_labels = ['all','BTEXIIN','BTEX','BT','B'],\n", + " sort = True,\n", + " figsize = [5.2,3],\n", + " textsize = 12,\n", + " save_fig = 'contaminants_bar.png',\n", + " yscale = 'log',\n", + " loc='upper left',\n", + " title_text = False,\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "f2b4062a-5d23-412b-be7f-d97f8dfb6713", + "metadata": {}, + "source": [ + "Producing the plot individually using `matplotlib` and `numpy` for individual adaptions:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "68f61107-da2b-413b-8c90-b98353b182c6", + "metadata": {}, + "outputs": [], + "source": [ + "sort_args = np.argsort(contaminants_concentration.values)\n", + "#sort_args = np.arange(len(contaminants_concentration.values))\n", + "plt.bar(np.arange(len(contaminants_concentration.values)),contaminants_concentration.values[sort_args],label='all')\n", + "plt.bar(np.arange(len(contaminants_BTEXIIN.values)),contaminants_BTEXIIN.values[sort_args],label='BTEXIIN')\n", + "plt.bar(np.arange(len(contaminants_BTEX.values)),contaminants_BTEX.values[sort_args],label='BTEX')\n", + "plt.bar(np.arange(len(contaminants_BT.values)),contaminants_BT.values[sort_args],label='BT')\n", + "plt.bar(np.arange(len(contaminants['toluene'].values)),contaminants['toluene'].values[sort_args],label='T')\n", + "plt.xlabel('Samples')\n", + "plt.ylabel(r'Total concentration [$\\mu$g/l]')\n", + "plt.yscale('log')\n", + "plt.legend()\n", + "plt.title('Total concentration of contaminants per sample')" + ] + }, + { + "cell_type": "markdown", + "id": "498c1215-219e-407d-b483-e464aab43a4a", + "metadata": {}, + "source": [ + "### Analysis of number of contaminants per sample" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "df28de2a-b0c1-448b-a442-14bd2f1974d9", + "metadata": {}, + "outputs": [], + "source": [ + "count_contaminants = mbs.total_count(contaminants,\n", + " name_list = 'all_cont',\n", + " verbose = True)\n", + "\n", + "count_BTEXIIN = mbs.total_count(contaminants,\n", + " name_list = 'BTEXIIN',\n", + " verbose = True)\n", + "\n", + "count_BTEX = mbs.total_count(contaminants,\n", + " name_list = 'BTEX',\n", + " verbose = True)\n", + "\n", + "mbs.total_count(contaminants,\n", + " name_list = ['benzene'],\n", + " include_as = \"count_benzene\",\n", + " verbose = True)" + ] + }, + { + "cell_type": "markdown", + "id": "75ad31fe-246e-4639-a18f-409b160fee18", + "metadata": {}, + "source": [ + "Using wrapper functions for specific type of data, the previous commands are equivalent to: \n", + "\n", + "(now including results with standard names as own data column to data frame of *contaminants*)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b6bf8869-6808-4302-8909-b23746a6fdc7", + "metadata": {}, + "outputs": [], + "source": [ + "mbs.total_contaminant_count(contaminants,\n", + " contaminant_group = 'all',\n", + " include = True)\n", + "\n", + "mbs.total_contaminant_count(contaminants,\n", + " contaminant_group = 'BTEXIIN',\n", + " include = True)\n", + "\n", + "mbs.total_contaminant_count(contaminants,\n", + " contaminant_group = 'BTEX',\n", + " include = True)" + ] + }, + { + "cell_type": "markdown", + "id": "92b41f73-29d0-4ded-83bf-ccf6127de003", + "metadata": {}, + "source": [ + "### Visualization of number of contaminants per sample" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3c4c7a47-9904-4211-aaaf-3a399e78c64f", + "metadata": {}, + "outputs": [], + "source": [ + "list_counts = ['count_contaminants','count_BTEXIIN','count_BTEX','count_benzene']\n", + "\n", + "mbs.contaminants_bar(contaminants,\n", + " list_counts,\n", + " list_labels = ['all','BTEXIIN','BTEX','B'],\n", + " sort = True,\n", + " figsize = [5.2,3],\n", + " textsize = 12,\n", + " ylabel = 'Total count',\n", + " yscale = 'linear',\n", + " save_fig = 'count_bar.png',\n", + " loc='upper left',\n", + " title_text = False,\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "df7f4971-1cb3-438a-a370-887beaecb2c4", + "metadata": {}, + "source": [ + "Producing the plot individually using `matplotlib` and `numpy` for individual adaptions:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "086f4fe8-8822-410f-acad-dab987336747", + "metadata": {}, + "outputs": [], + "source": [ + "plt.figure(num=2)\n", + "plt.bar(np.arange(len(count_contaminants.values)),np.sort(count_contaminants.values),label='all')\n", + "plt.bar(np.arange(len(count_BTEXIIN.values)),np.sort(count_BTEXIIN.values),label='BTEXIIN')\n", + "plt.bar(np.arange(len(count_BTEX.values)),np.sort(count_BTEX.values),label='BTEX')\n", + "plt.xlabel('Samples')\n", + "plt.ylabel('Total number')\n", + "plt.title('Total number of contaminants per sample')\n", + "plt.legend()" + ] + }, + { + "cell_type": "markdown", + "id": "c60146aa-cec9-42cc-b2f4-6c5249b8b498", + "metadata": {}, + "source": [ + "## Evaluation of intervention threshold exceedance" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "201c8fb2-65d6-4452-985f-b4b3f2d77a1c", + "metadata": {}, + "outputs": [], + "source": [ + "data_thresh_ratio = mbs.thresholds_for_intervention_ratio(contaminants)\n", + "display(data_thresh_ratio)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a9aafc6e-1f7c-4af6-94bc-d55f406858f9", + "metadata": {}, + "outputs": [], + "source": [ + "fig,ax = mbs.threshold_ratio_bar(data_thresh_ratio,\n", + " list_samples = [31,9,11],\n", + " figsize = [12,3],\n", + " nrows=1,ncols=3,\n", + " list_colors = ['olive','lightblue','tomato'],\n", + " sharey = True,\n", + " grid = True,\n", + " )\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "48051295-7c61-4079-bbfd-b8321ec74b16", + "metadata": {}, + "outputs": [], + "source": [ + "quantities = ['toluene','naphthalene','indene','pm_xylene','ethylbenzene','o_xylene','benzene']\n", + "mbs.threshold_ratio_bar(data_thresh_ratio,\n", + " list_samples = [9],\n", + " list_labels = quantities,\n", + " figsize = [6,3],\n", + " unity_line = True,\n", + " title_text= 'Evaluation of threshold exceedance for BTEXIIN',\n", + " )" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/examples/ex02_Amersfoort/example_02_amersfoort_isotopes_lambda.ipynb b/docs/examples/ex02_Amersfoort/example_02_amersfoort_isotopes_lambda.ipynb new file mode 100644 index 0000000..7740c07 --- /dev/null +++ b/docs/examples/ex02_Amersfoort/example_02_amersfoort_isotopes_lambda.ipynb @@ -0,0 +1,223 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "8f9b02b6-8df1-4a06-8182-aeb8caec68bb", + "metadata": {}, + "source": [ + "# MiBiPreT example: Isotope Analysis with Amersfoort data\n", + "\n", + "Diagnostic plots for data analysis on microbial biodegredation at the contaminant Amersfoort site. Author: Alraune Zech\n", + "\n", + "Data based on the PhD thesis of *Johan van Leeuwen*, 2021 'Biodegredation of mono- and polyaromatic hydrocarbons in a contaminated aquifer originating from a former Pintsch gas factory site' which is equivalent to the manuscript of van Leeuwen et al., 2022 'Anaerobic degradation of benzene and other aromatic hydrocarbons in a tar-derived plume: Nitrate versus iron reducing conditions', J. of Cont. Hydrol. The data was provided by Johan van Leeuwen.\n", + " \n", + "## Background: Amersfoort contaminant site\n", + "\n", + "Close to the train station in Amersfoort, the Netherlands, the subsurface is contaminated with organic hydrocarbons forming a NAPL. Contamination originates from decades of operating manufactured gas plant, which dumped tar by-products in waste lagoons. The tar is a DNAPL and has spread into the underlying shallow unconfined aquifer. Sample wells were installed to measure various characteristics of the subsurface. The raw data contains measurements on\n", + "* environmental conditions, such as pH, redox potential, concentrations of oxygen, nitrate, etc\n", + "* contaminant concentration such as BTEX, indene, indane, naphtalene and multiple other (typically cyclic) petroleum hydrocarbons\n", + "* metabolite concentration, i.e. byproducts of degredation processes of contaminant\n", + "* isotope measurments for specific contaminants and samples\n", + "* counts of genes (RNA/DNA) of mibrobiota that is know to perform biodegredation as well as functional enzymes know to be responsible for biodegredation" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "71fa8ea6-ad3a-429f-a311-bdc4d1520c60", + "metadata": {}, + "outputs": [], + "source": [ + "import mibiscreen as mbs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1edd721b-e202-48d1-bf1a-52f7f1ec6f0b", + "metadata": {}, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "id": "d54a84d1-40ba-4449-b97a-586cb3288f62", + "metadata": {}, + "source": [ + "## Data loading" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d78167de-05f5-4693-9996-57a4aab5f17e", + "metadata": {}, + "outputs": [], + "source": [ + "file_path = './amersfoort.xlsx'" + ] + }, + { + "cell_type": "markdown", + "id": "5cb6a2c4-ef62-4147-8413-e3de461868ca", + "metadata": {}, + "source": [ + "Load and standardize data of isotopes:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6d8d3c99-c95c-40fd-a935-4383ad17697a", + "metadata": {}, + "outputs": [], + "source": [ + "isotopes_raw,units = mbs.load_excel(file_path,\n", + " sheet_name = 'isotopes',\n", + " verbose = False)\n", + "\n", + "isotopes,units = mbs.standardize(isotopes_raw,\n", + " reduce = True,\n", + " verbose=False)\n" + ] + }, + { + "cell_type": "markdown", + "id": "75d6278e-0343-4290-820b-ba76bf8f8c7e", + "metadata": {}, + "source": [ + "### Lambda regression and Lambda regression plot for single molecule" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "42c488d4-8cb7-4395-a022-369d1c3385ff", + "metadata": {}, + "outputs": [], + "source": [ + "C_data,H_data = mbs.extract_isotope_data(isotopes,'toluene')\n", + "results = mbs.Lambda_regression(C_data,\n", + " H_data,\n", + " validate_indices = True,\n", + " verbose = True,\n", + " )\n", + "mbs.Lambda_plot(**results,\n", + " title = 'toluene',\n", + " fit_color = 'k',\n", + " marker_color = 'C1')" + ] + }, + { + "cell_type": "markdown", + "id": "bf350ae1-6b17-46cd-b170-7cbce9a58be4", + "metadata": {}, + "source": [ + "### Lambda regression and Lambda regression plot for all molecules (separately)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "60e89a73-2e11-40b7-92a6-07003b904085", + "metadata": {}, + "outputs": [], + "source": [ + "molecules = ['benzene','toluene','ethylbenzene','pm_xylene','naphthalene','indene']\n", + "molecules_analysis = []\n", + "\n", + "for j,molecule in enumerate(molecules):\n", + "\n", + " C_data,H_data = mbs.extract_isotope_data(isotopes,molecule)\n", + "\n", + " results = mbs.Lambda_regression(C_data,\n", + " H_data,\n", + " validate_indices = True,\n", + " verbose = True,\n", + " )\n", + "\n", + " molecules_analysis.append(results)\n", + "\n", + " mbs.Lambda_plot(**results,title = molecule)\n", + " # Lambda_plot(**results,save_fig = 'Amersfoort_isotope_Lambda_{}.png'.format(molecule),dpi = 300)" + ] + }, + { + "cell_type": "markdown", + "id": "c1604b0a-85d1-4df0-8012-6f9a8e52433a", + "metadata": {}, + "source": [ + "### Lambda regression and plot of results of all molecules in one plot\n", + "\n", + "Produce plot with `matplotlib` for indiviual adaptions" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "00b9ab2e-8028-453d-adb7-554777e16f6e", + "metadata": {}, + "outputs": [], + "source": [ + "molecules = ['benzene','toluene','naphthalene','indene']\n", + "molecules_analysis_set = [molecules_analysis[i] for i in [0,1,4,5]]\n", + "fig, axes = plt.subplots(figsize=[5.5,5],\n", + " ncols = 2,\n", + " nrows = 2)\n", + "ax = axes.flat\n", + "for j,molecule in enumerate(molecules):\n", + "\n", + " results = molecules_analysis_set[j]\n", + "\n", + " x,y = results['delta_C'], results['delta_H']\n", + "\n", + " # Plot the scatter plot\n", + " ax[j].scatter(x,y,color = 'C{}'.format(j),ec = '0.5',s=50, zorder = 3,label = 'data')\n", + " ax[j].set_title(molecule,bbox=dict(facecolor=\"oldlace\",boxstyle=\"round\"))\n", + " ax[j].grid(True,zorder = 0)\n", + "\n", + " \n", + " # plot trendlines\n", + " polynomial = np.poly1d(results['coefficients'])\n", + " trendline_x = np.linspace(np.min(x), np.max(x), 50)\n", + " trendline_y = polynomial(trendline_x)\n", + " ax[j].plot(trendline_x, trendline_y,c= 'k', label=r'$\\Lambda = {:.0f}$'.format(results['coefficients'][0]))\n", + "\n", + " if j%2 == 0:\n", + " ax[j].set_ylabel(r'$\\delta^2$H')\n", + "\n", + " if j >= len(ax)-2:\n", + " ax[j].set_xlabel(r'$\\delta^{{13}}$C')\n", + "\n", + " ax[j].legend()\n", + "\n", + "fig.tight_layout()\n", + "plt.savefig(\"Amersfoort_isotope_Lambda.png\",dpi=300)\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/examples/ex02_Amersfoort/example_02_amersfoort_metabolites.ipynb b/docs/examples/ex02_Amersfoort/example_02_amersfoort_metabolites.ipynb new file mode 100644 index 0000000..9353b2a --- /dev/null +++ b/docs/examples/ex02_Amersfoort/example_02_amersfoort_metabolites.ipynb @@ -0,0 +1,474 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "aec1962d-a737-4453-a3b5-fae36f566c12", + "metadata": {}, + "source": [ + "# MiBiPreT example: Metabolite Data Analysis with Amersfoort data\n", + "\n", + "Diagnostic plots for data analysis on microbial biodegredation at the contaminant Amersfoort site. \n", + "\n", + "Author: Alraune Zech\n", + "\n", + "Data based on the PhD thesis of *Johan van Leeuwen*, 2021 'Biodegredation of mono- and polyaromatic hydrocarbons in a contaminated aquifer originating from a former Pintsch gas factory site' which is equivalent to the manuscript of van Leeuwen et al., 2022 'Anaerobic degradation of benzene and other aromatic hydrocarbons in a tar-derived plume: Nitrate versus iron reducing conditions', J. of Cont. Hydrol. The data was provided by Johan van Leeuwen.\n", + " \n", + "## Background: Amersfoort contaminant site\n", + "\n", + "Close to the train station in Amersfoort, the Netherlands, the subsurface is contaminated with organic hydrocarbons forming a NAPL. Contamination originates from decades of operating manufactured gas plant, which dumped tar by-products in waste lagoons. The tar is a DNAPL and has spread into the underlying shallow unconfined aquifer. Sample wells were installed to measure various characteristics of the subsurface. The raw data contains measurements on\n", + "* environmental conditions, such as pH, redox potential, concentrations of oxygen, nitrate, etc\n", + "* contaminant concentration such as BTEX, indene, indane, naphtalene and multiple other (typically cyclic) petroleum hydrocarbons\n", + "* metabolite concentration, i.e. byproducts of degredation processes of contaminant\n", + "* isotope measurments for specific contaminants and samples\n", + "* counts of genes (RNA/DNA) of mibrobiota that is know to perform biodegredation as well as functional enzymes know to be responsible for biodegredation" + ] + }, + { + "cell_type": "markdown", + "id": "31ae9c4a-5652-4d9e-9dbf-6049ddc397cc", + "metadata": {}, + "source": [ + "**Required packages**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5d7a3f49-dd14-4e73-94fb-5a44a30c9e25", + "metadata": {}, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c7b46e09-3c59-4edf-9012-20c49aadd76a", + "metadata": {}, + "outputs": [], + "source": [ + "import mibiscreen as mbs" + ] + }, + { + "cell_type": "markdown", + "id": "6e0c6fd7-8285-451c-8510-1b0b6cebace3", + "metadata": {}, + "source": [ + "## Data loading" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1d1c7d9f-ad38-435f-afae-4f76e9dd1117", + "metadata": {}, + "outputs": [], + "source": [ + "file_path = './amersfoort.xlsx'" + ] + }, + { + "cell_type": "markdown", + "id": "280d0eca-65bb-4d65-947d-e8baf737a8eb", + "metadata": {}, + "source": [ + "**Load and standardize data of metabolites**\n", + "\n", + "*Note*: Column names of metabolites is not checked. All columns provided (except settings) will be interpreted as individual metabolites." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d34ddbdc-9af8-4177-99b3-b30aae974924", + "metadata": {}, + "outputs": [], + "source": [ + "metabolites_raw,units = mbs.load_excel(file_path,\n", + " sheet_name = 'metabolites',\n", + " verbose = False)\n", + "\n", + "metabolites,units = mbs.standardize(metabolites_raw,\n", + " reduce = False,\n", + " verbose=False)\n", + "\n", + "# metabolites_columns = mbs.check_columns(metabolites_raw,verbose = False)\n", + "# metabolites_units_check = mbs.check_units(metabolites_raw,verbose = False)\n", + "# metabolites_pure = mbs.check_values(metabolites_raw,verbose = False)\n", + "\n", + "#display(metabolites)" + ] + }, + { + "cell_type": "markdown", + "id": "1270eb7c-507e-4537-a11d-8d59ec7bf71c", + "metadata": {}, + "source": [ + "## Metabolites Concentration Analysis\n", + "\n", + "### Calculating total concentration and counts of metabolites per sample" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0a9d7002-749d-4c9c-a567-6e180eca0c27", + "metadata": {}, + "outputs": [], + "source": [ + "metabolites_total = mbs.total_concentration(metabolites,\n", + " name_list = 'all',\n", + " include_as = False, \n", + " # verbose = True\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "7aa15e96-4df1-409b-b1f4-c8c18f179be7", + "metadata": {}, + "source": [ + "Note that calculated values are not included to data frame as for further analysis all column (except settings) will be used. If including the total concentration, the value of total count will be overestimated by 1." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0e73a40c-4d4c-41c1-9782-3d6ff40c6b9c", + "metadata": {}, + "outputs": [], + "source": [ + "metabolites_count = mbs.total_count(metabolites,\n", + " name_list = 'all', \n", + " include_as = False, \n", + " #verbose = True\n", + " )\n" + ] + }, + { + "cell_type": "markdown", + "id": "7f124881-20f5-49e1-a731-345273b6533a", + "metadata": {}, + "source": [ + "Previous two steps are equivalent to:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e5559913-27df-4eee-9bc4-1adccffc1427", + "metadata": {}, + "outputs": [], + "source": [ + "mbs.total_metabolites_concentration(metabolites,\n", + " include = True,\n", + " verbose = False)" + ] + }, + { + "cell_type": "markdown", + "id": "58208f9c-993f-4f17-b2ed-ba48ce18183d", + "metadata": {}, + "source": [ + "Now including results as own data column to data frame of *metabolites*:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "af99f4a3-4d23-4eda-9697-b156674fc885", + "metadata": {}, + "outputs": [], + "source": [ + "print(\"Names of last two columns\", metabolites.columns[-2:].values)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3dc09da1-7905-43ac-af5e-42eea40a8ac1", + "metadata": {}, + "outputs": [], + "source": [ + "mbs.total_metabolites_count(metabolites.iloc[:,:-1],\n", + " include = True,\n", + " verbose = False)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "84557ab2-0aed-465c-9a4c-49072c040e00", + "metadata": {}, + "outputs": [], + "source": [ + "print(\"Names of last two columns\", metabolites.columns[-2:].values)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eb22e955-b155-4d33-a8fd-dc5fa53d6705", + "metadata": {}, + "outputs": [], + "source": [ + "display(metabolites_total)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "29774fb3-ee31-441c-83b9-6170ea6b97b7", + "metadata": {}, + "outputs": [], + "source": [ + "mbs.total_metabolites_count(metabolites,\n", + " include = True,\n", + " verbose = True)\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "a46ca4d3-0046-4c20-9967-55fa6414ce1b", + "metadata": {}, + "source": [ + "### Plotting total concentration of metabolites" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9533ffa6-e228-44ab-8ce5-67b718d0c759", + "metadata": {}, + "outputs": [], + "source": [ + "mbs.contaminants_bar(metabolites,\n", + " list_contaminants = ['metabolites_concentration'],\n", + " list_labels = ['all metabolites'],\n", + " figsize = [18,5],\n", + " textsize = 14,\n", + " ylabel = r'Total metabolites concentration [$\\mu$g/l]',\n", + " loc='upper left',\n", + " title_text = 'Total concentration of metabolites per sample',\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "f69457d5-0f7c-4d0b-9785-2f6a8fbf6fab", + "metadata": {}, + "source": [ + "Producing the plot individually using `matplotlib` and `numpy` for individual adaptions:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f05df51a-b536-4d54-944d-ba34553195ce", + "metadata": {}, + "outputs": [], + "source": [ + "plt.figure(figsize = [18,5])\n", + "plt.bar(np.arange(len(metabolites_total.values)),metabolites_total.values,label='all')\n", + "plt.xlabel('Samples')\n", + "plt.ylabel(r'Total metabolites concentration [$\\mu$g/l]')\n", + "plt.title('Total concentration of metabolites per sample')" + ] + }, + { + "cell_type": "markdown", + "id": "8a4a478e-b807-4790-92c1-cd6ccba9b79a", + "metadata": {}, + "source": [ + "**Plot with sorting of values and sample names**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "12f5ec45-6e98-466a-964d-3e9a437ac004", + "metadata": {}, + "outputs": [], + "source": [ + "mbs.contaminants_bar(metabolites,\n", + " list_contaminants = ['metabolites_concentration'],\n", + " list_labels = ['all metabolites'],\n", + " sort = True,\n", + " name_sample = True,\n", + " figsize = [18,5],\n", + " textsize = 12,\n", + " ylabel = r'Total metabolites concentration [$\\mu$g/l]',\n", + " loc='upper left',\n", + " title_text = 'Total concentration of metabolites per sample',\n", + " xtick_autorotate = True,\n", + " # save_fig = 'metabolites_bar.png',\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "348602d1-aa81-442b-8d85-d20c6dafdc13", + "metadata": {}, + "source": [ + "Producing the plot individually using `matplotlib` and `numpy` for individual adaptions:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "faef3a5c-532e-4bad-83b6-6621cd2cffee", + "metadata": {}, + "outputs": [], + "source": [ + "fig = plt.figure(figsize = [18,5])\n", + "sort_args = np.argsort(metabolites['metabolites_concentration'].values)\n", + "plt.bar(metabolites.sample_nr.values[sort_args],metabolites['metabolites_concentration'].values[sort_args],label='all')\n", + "plt.xlabel('Samples')\n", + "plt.ylabel(r'Total metabolites concentration [$\\mu$g/l]')\n", + "plt.title('Total concentration of metabolites per sample')\n", + "fig.autofmt_xdate(bottom=0.2, rotation=30, ha='right', which='major')" + ] + }, + { + "cell_type": "markdown", + "id": "fb1559d3-ebc7-444f-8cf8-f49223aae890", + "metadata": {}, + "source": [ + "### Plotting total counts of metabolites" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "23543cb4-ece7-4eb5-9135-3491b57de149", + "metadata": {}, + "outputs": [], + "source": [ + "mbs.contaminants_bar(metabolites,\n", + " list_contaminants = ['metabolites_count'],\n", + " list_labels = ['total metabolites count'],\n", + " sort = True,\n", + " name_sample = True,\n", + " figsize = [18,5],\n", + " textsize = 12,\n", + " ylabel = r'Total metabolites count',\n", + " loc='upper left',\n", + " title_text = 'Total count of metabolites per sample',\n", + " xtick_autorotate = True,\n", + " # save_fig = 'metabolites_count_bar.png',\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "2093c961-99f3-4eaa-b5e4-b17f430cd0e1", + "metadata": {}, + "source": [ + "## Relating Metabolite activity to electron availability\n", + "\n", + "#### Load data of contaminants and geochemicals to identify electron availability and NA activity color" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5045254d-d748-4297-9276-d02d25695f55", + "metadata": {}, + "outputs": [], + "source": [ + "contaminants_raw,_ = mbs.load_excel(file_path,\n", + " sheet_name = 'contaminants',\n", + " verbose = False)\n", + "contaminants,units = mbs.standardize(contaminants_raw,verbose = False)\n", + "environment_raw,_ = mbs.load_excel(file_path,\n", + " sheet_name = 'environment',\n", + " verbose = False)\n", + "environment,units = mbs.standardize(environment_raw,verbose = False)" + ] + }, + { + "cell_type": "markdown", + "id": "99cb61ac-497d-460c-8fd4-82b53308cef6", + "metadata": {}, + "source": [ + "#### Enrich data by data analysis needed" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "db130890-930a-467a-9077-18fc9ffdbdc7", + "metadata": {}, + "outputs": [], + "source": [ + "mbs.total_contaminant_concentration(contaminants,include = True)\n", + "mbs.total_metabolites_count(metabolites,include = True)\n", + "data_NA = mbs.merge_data([environment,contaminants,metabolites])\n", + "mbs.sample_NA_traffic(data_NA,include = True)" + ] + }, + { + "cell_type": "markdown", + "id": "1ddf4a6d-ae7b-4427-bc5c-feb7c60bc492", + "metadata": {}, + "source": [ + "#### Activity plot linking contaminant concentration to metabolite occurence and NA screening" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "694a28fc-1826-4cb2-aa44-237cd0348c5e", + "metadata": {}, + "outputs": [], + "source": [ + "data_activity = mbs.activity_data_prep(data_NA)\n", + "data_activity['tot_cont'] = data_activity['tot_cont']*0.001" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5683c518-fb2c-426a-a337-7f2d8cfb03d9", + "metadata": {}, + "outputs": [], + "source": [ + "#fig, ax = mbs.activity_plot(data_activity)\n", + "fig, ax = mbs.activity_plot(data_activity,\n", + " figsize = [6,4],\n", + " textsize = 12,\n", + " xscale = 'log',\n", + " markersize = 60,\n", + " loc='center right',\n", + " xlabel = r\"Concentration contaminants [mg/L]\",\n", + " #save_fig = 'activity.png'\n", + " )" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/examples/ex02_Amersfoort/example_02_amersfoort_ordination.ipynb b/docs/examples/ex02_Amersfoort/example_02_amersfoort_ordination.ipynb new file mode 100644 index 0000000..5913fad --- /dev/null +++ b/docs/examples/ex02_Amersfoort/example_02_amersfoort_ordination.ipynb @@ -0,0 +1,322 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "4d35df26-33db-4d65-9d69-169861d27296", + "metadata": {}, + "source": [ + "# MiBiPreT example: Ordination with Amersfoort data\n", + "\n", + "Diagnostic plots for data analysis on microbial biodegredation at the contaminant Amersfoort site. Author: Alraune Zech\n", + "\n", + "Data based on the PhD thesis of *Johan van Leeuwen*, 2021 'Biodegredation of mono- and polyaromatic hydrocarbons in a contaminated aquifer originating from a former Pintsch gas factory site' which is equivalent to the manuscript of van Leeuwen et al., 2022 'Anaerobic degradation of benzene and other aromatic hydrocarbons in a tar-derived plume: Nitrate versus iron reducing conditions', J. of Cont. Hydrol. The data was provided by Johan van Leeuwen.\n", + " \n", + "## Background: Amersfoort contaminant site\n", + "\n", + "Close to the train station in Amersfoort, the Netherlands, the subsurface is contaminated with organic hydrocarbons forming a NAPL. Contamination originates from decades of operating manufactured gas plant, which dumped tar by-products in waste lagoons. The tar is a DNAPL and has spread into the underlying shallow unconfined aquifer. Sample wells were installed to measure various characteristics of the subsurface. The raw data contains measurements on\n", + "* environmental conditions, such as pH, redox potential, concentrations of oxygen, nitrate, etc\n", + "* contaminant concentration such as BTEX, indene, indane, naphtalene and multiple other (typically cyclic) petroleum hydrocarbons\n", + "* metabolite concentration, i.e. byproducts of degredation processes of contaminant\n", + "* isotope measurments for specific contaminants and samples\n", + "* counts of genes (RNA/DNA) of mibrobiota that is know to perform biodegredation as well as functional enzymes know to be responsible for biodegredation" + ] + }, + { + "cell_type": "markdown", + "id": "ae64ffdd-62de-49b6-8bd5-67463e40f336", + "metadata": {}, + "source": [ + "**Required packages**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "536c85e1-eaf1-4968-9c43-6acb605b4634", + "metadata": {}, + "outputs": [], + "source": [ + "import mibiscreen as mbs" + ] + }, + { + "cell_type": "markdown", + "id": "232d83bc-bc2e-4834-a12b-2223067e5fb7", + "metadata": {}, + "source": [ + "## Analysis\n", + "\n", + "### Data loading" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "80e749fa-c1e7-4903-9b8c-210b465bba0e", + "metadata": {}, + "outputs": [], + "source": [ + "file_path = './amersfoort.xlsx'" + ] + }, + { + "cell_type": "markdown", + "id": "1094e3e9-c822-4c4c-a625-7b59159d17e8", + "metadata": {}, + "source": [ + "Load and standardize data of environmental quantities/chemicals" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4186f2e4-e109-41ab-b17c-a7e9556def39", + "metadata": {}, + "outputs": [], + "source": [ + "environment_raw,units = mbs.load_excel(file_path,\n", + " sheet_name = 'environment',\n", + " verbose = False)\n", + "\n", + "environment,units = mbs.standardize(environment_raw,\n", + " reduce = True,\n", + " verbose=False)" + ] + }, + { + "cell_type": "markdown", + "id": "ab7f9683-e74d-44ab-9aa2-7ea63acbdbfa", + "metadata": {}, + "source": [ + "Load and standardize data of contaminants:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b4bc2d9-d4a1-4333-afdd-aa316b714d4d", + "metadata": {}, + "outputs": [], + "source": [ + "contaminants_raw,units = mbs.load_excel(file_path,\n", + " sheet_name = 'contaminants',\n", + " verbose = False)\n", + "\n", + "contaminants,units = mbs.standardize(contaminants_raw,\n", + " reduce = False,\n", + " verbose = False)\n", + "\n", + "mbs.total_contaminant_concentration(contaminants,\n", + " include = True,\n", + " verbose = False)" + ] + }, + { + "cell_type": "markdown", + "id": "253049a2-3a9e-45e7-8aa0-948bd7df1a58", + "metadata": {}, + "source": [ + "Merge both data frames into one for further analysis:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "418b2649-3650-4219-9d48-83182016c70f", + "metadata": {}, + "outputs": [], + "source": [ + "data = mbs.merge_data([environment,contaminants],clean = True)" + ] + }, + { + "cell_type": "markdown", + "id": "4e163ea6-bf1e-43c8-8a88-6ea5bd548408", + "metadata": {}, + "source": [ + "### Data pre-processing" + ] + }, + { + "cell_type": "markdown", + "id": "7b2b2da5-98b2-4a81-9484-a25739d457a9", + "metadata": {}, + "source": [ + "Specification of variables to chose for ordination. We make sure that variables selected for analysis are in standard names." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "30a78e3e-b5ed-4602-ba7c-661e0afaa15e", + "metadata": {}, + "outputs": [], + "source": [ + "variables_1 = mbs.standard_names(['total_contaminants'])\n", + "variables_2 = mbs.standard_names(['nitrate','pH','nitrite','sulfate','Redox','EC','DOC',\"Mn\",\"Fe\"])" + ] + }, + { + "cell_type": "markdown", + "id": "d8bddcb2-d36f-4eba-8377-6a731a833b75", + "metadata": {}, + "source": [ + "Extracting data of interest from data frame. All other quantities are removed, since only columns of interest should be passed to ordination analysis routines. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6c7df123-fc2a-4033-9cc5-6741e96e39af", + "metadata": {}, + "outputs": [], + "source": [ + "data_ordination = mbs.extract_data(data,\n", + " name_list = variables_1 + variables_2,\n", + " keep_setting_data = True)" + ] + }, + { + "cell_type": "markdown", + "id": "39cbda27-4568-4f90-b4f7-f770b2150f49", + "metadata": {}, + "source": [ + "Cleaning data, i.e. remove all sites where measurements are missing for any of the quantities" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7d45a5c9-13fe-4e18-82f9-2289d6a7e498", + "metadata": {}, + "outputs": [], + "source": [ + "data_filtered = mbs.filter_values(data_ordination, \n", + " replace_NaN = 'remove', \n", + " inplace = True,\n", + " verbose = True)\n", + "data_filtered" + ] + }, + { + "cell_type": "markdown", + "id": "72208484-a3b4-4460-8cf4-18f5abbb5462", + "metadata": {}, + "source": [ + "### Data transformation\n", + "\n", + "Concentrations of contaminants (`Sum GC`) is log-transformed (given that concentration vary over orders of magnitude) and then standardized.\n", + "Other data is only standardized." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "28570c35-ab3b-402a-965c-cd8699715747", + "metadata": {}, + "outputs": [], + "source": [ + "data_transformed = mbs.transform_values(data_ordination,\n", + " name_list = variables_1,\n", + " how = 'log_scale',\n", + " inplace = True,\n", + " )\n", + "\n", + "data_transformed = mbs.transform_values(data_ordination,\n", + " name_list = variables_1,\n", + " how = 'standardize',\n", + " inplace = True,\n", + " )\n", + "\n", + "data_transformed = mbs.transform_values(data_ordination,\n", + " name_list = variables_2,\n", + " how = 'standardize',\n", + " inplace = True,\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "e3e0125e-349c-430c-a5cf-c656f543b35f", + "metadata": {}, + "source": [ + "### Ordination analysis by PCA" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "861c62e3-ba4f-4434-bb2a-74070e08b25e", + "metadata": {}, + "outputs": [], + "source": [ + "ordination_output = mbs.pca(data_ordination,\n", + " independent_variables = variables_1+variables_2,\n", + " verbose = True)" + ] + }, + { + "cell_type": "markdown", + "id": "d3b7a990-991c-4451-a475-209b25eba09d", + "metadata": {}, + "source": [ + "### Ordination plot" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e5348b75-878c-4810-9253-60a42e03e4ca", + "metadata": {}, + "outputs": [], + "source": [ + "fig, ax = mbs.ordination_plot(ordination_output=ordination_output,\n", + " plot_scores = True, \n", + " plot_loadings = True,\n", + " rescale_loadings_scores = True, \n", + " title = \"Unconstrained Ordination PCA\", \n", + " # plot_scores = False, \n", + " # axis_ranges = [-0.6,0.8,-0.8,1.0],\n", + " # save_fig = 'ordination_amersfoort.png',\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "dd0a7427-172e-4e65-88ba-9bda8588fc23", + "metadata": {}, + "source": [ + "### Interpretation\n", + "\n", + "The figure shows the results of the PCA (principle component analysis) as multi-variate statistics tool for the geochemical parameters. The axes denote the percentage of variance explained by each principal component. Data was standardized, with `Sum GC` (being the total sum of contaminants) being logarithmically transformed as via $log(x+1)$.\n", + "\n", + "This biplot shows two different elements of information: the variable loadings show as arrows and the site scores shown as dots. The two plot axis represent the two main axis identified by the ordination methods. They are scales to the minimal value of $-1$ and the maximum value of $1$. \n", + "\n", + "The direction of the arrow indicates to which ordination axis it correlates. The length of the vector is equivalent to the extent of that correlation. Positive scores or loadings indicate positive correlation with the axis, where negative values indicate negative \n", + "correlation. For example, a variable with negative loadings for the first two ordination axes is anticorrelated with the two largest trends in the data. Arrows pointing in the same direction indicate that the variable are correlated. Arrows at an right angle to one another are uncorrelated. Arrows that point in opposite directions are anti-correlated. A vector very close to the origin shows little to no correlation with the axes. \n", + "\n", + "Proximity of the site scores in the plot indicate the similarity between the sample sites. " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/examples/ex02_Amersfoort/example_02_amersfoort_ordination_GQ.ipynb b/docs/examples/ex02_Amersfoort/example_02_amersfoort_ordination_GQ.ipynb new file mode 100644 index 0000000..910c70d --- /dev/null +++ b/docs/examples/ex02_Amersfoort/example_02_amersfoort_ordination_GQ.ipynb @@ -0,0 +1,594 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "4d35df26-33db-4d65-9d69-169861d27296", + "metadata": {}, + "source": [ + "# MiBiPreT example: Ordination with Amersfoort data\n", + "\n", + "Diagnostic plots for data analysis on microbial biodegredation at the contaminant Amersfoort site. Author: Alraune Zech\n", + "\n", + "Data based on the PhD thesis of *Johan van Leeuwen*, 2021 'Biodegredation of mono- and polyaromatic hydrocarbons in a contaminated aquifer originating from a former Pintsch gas factory site' which is equivalent to the manuscript of van Leeuwen et al., 2022 'Anaerobic degradation of benzene and other aromatic hydrocarbons in a tar-derived plume: Nitrate versus iron reducing conditions', J. of Cont. Hydrol. The data was provided by Johan van Leeuwen.\n", + " \n", + "## Background: Amersfoort contaminant site\n", + "\n", + "Close to the train station in Amersfoort, the Netherlands, the subsurface is contaminated with organic hydrocarbons forming a NAPL. Contamination originates from decades of operating manufactured gas plant, which dumped tar by-products in waste lagoons. The tar is a DNAPL and has spread into the underlying shallow unconfined aquifer. Sample wells were installed to measure various characteristics of the subsurface. The raw data contains measurements on\n", + "* environmental conditions, such as pH, redox potential, concentrations of oxygen, nitrate, etc\n", + "* contaminant concentration such as BTEX, indene, indane, naphtalene and multiple other (typically cyclic) petroleum hydrocarbons\n", + "* metabolite concentration, i.e. byproducts of degredation processes of contaminant\n", + "* isotope measurments for specific contaminants and samples\n", + "* counts of genes (RNA/DNA) of mibrobiota that is know to perform biodegredation as well as functional enzymes know to be responsible for biodegredation" + ] + }, + { + "cell_type": "markdown", + "id": "ae64ffdd-62de-49b6-8bd5-67463e40f336", + "metadata": {}, + "source": [ + "**Required packages**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "536c85e1-eaf1-4968-9c43-6acb605b4634", + "metadata": {}, + "outputs": [], + "source": [ + "import mibiscreen as mbs" + ] + }, + { + "cell_type": "markdown", + "id": "232d83bc-bc2e-4834-a12b-2223067e5fb7", + "metadata": {}, + "source": [ + "## Data loading" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "80e749fa-c1e7-4903-9b8c-210b465bba0e", + "metadata": {}, + "outputs": [], + "source": [ + "file_path = './amersfoort.xlsx'" + ] + }, + { + "cell_type": "markdown", + "id": "1094e3e9-c822-4c4c-a625-7b59159d17e8", + "metadata": {}, + "source": [ + "Load and standardize data of environmental quantities/chemicals" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4186f2e4-e109-41ab-b17c-a7e9556def39", + "metadata": {}, + "outputs": [], + "source": [ + "environment_raw,units = mbs.load_excel(file_path,\n", + " sheet_name = 'environment',\n", + " verbose = False)\n", + "\n", + "environment,units = mbs.standardize(environment_raw,\n", + " reduce = True,\n", + " verbose=False)" + ] + }, + { + "cell_type": "markdown", + "id": "ab7f9683-e74d-44ab-9aa2-7ea63acbdbfa", + "metadata": {}, + "source": [ + "Load and standardize data of contaminants:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b4bc2d9-d4a1-4333-afdd-aa316b714d4d", + "metadata": {}, + "outputs": [], + "source": [ + "contaminants_raw,units = mbs.load_excel(file_path,\n", + " sheet_name = 'contaminants',\n", + " verbose = False)\n", + "\n", + "contaminants,units = mbs.standardize(contaminants_raw,\n", + " reduce = False,\n", + " verbose = False)\n", + "\n", + "mbs.total_contaminant_concentration(contaminants,\n", + " include = True,\n", + " verbose = False)" + ] + }, + { + "cell_type": "markdown", + "id": "9bde3d18-8817-4462-84a4-8c975852a6d5", + "metadata": {}, + "source": [ + "Load and standardize data of DNA related data:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "34101d71-4fcb-446d-87d9-91a8f3aeca32", + "metadata": {}, + "outputs": [], + "source": [ + "###------------------------------------------------------------------------###\n", + "### Load and standardize data of contaminants\n", + "dna_raw,units = mbs.load_excel(file_path,\n", + " sheet_name = 'sequencing',\n", + " verbose = True)\n", + "\n", + "dna,units = mbs.standardize(dna_raw,\n", + " reduce = False,\n", + " verbose = True)" + ] + }, + { + "cell_type": "markdown", + "id": "253049a2-3a9e-45e7-8aa0-948bd7df1a58", + "metadata": {}, + "source": [ + "Merge both data frames into one for further analysis:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "418b2649-3650-4219-9d48-83182016c70f", + "metadata": {}, + "outputs": [], + "source": [ + "data = mbs.merge_data([environment,contaminants],clean = True)" + ] + }, + { + "cell_type": "markdown", + "id": "4e163ea6-bf1e-43c8-8a88-6ea5bd548408", + "metadata": {}, + "source": [ + "## Unconstrained Analysis (PCA)\n", + "### Data pre-processing" + ] + }, + { + "cell_type": "markdown", + "id": "7b2b2da5-98b2-4a81-9484-a25739d457a9", + "metadata": {}, + "source": [ + "Specification of variables to chose for ordination. We make sure that variables selected for analysis are in standard names." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "30a78e3e-b5ed-4602-ba7c-661e0afaa15e", + "metadata": {}, + "outputs": [], + "source": [ + "variables_1 = mbs.standard_names(['total_contaminants'])\n", + "variables_2 = mbs.standard_names(['nitrate','pH','nitrite','sulfate','Redox','EC','DOC',\"Mn2\",\"Fe2\"])" + ] + }, + { + "cell_type": "markdown", + "id": "d8bddcb2-d36f-4eba-8377-6a731a833b75", + "metadata": {}, + "source": [ + "Extracting data of interest from data frame. All other quantities are removed, since only columns of interest should be passed to ordination analysis routines. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6c7df123-fc2a-4033-9cc5-6741e96e39af", + "metadata": {}, + "outputs": [], + "source": [ + "data_ordination = mbs.extract_data(data,\n", + " name_list = variables_1 + variables_2,\n", + " keep_setting_data = True)" + ] + }, + { + "cell_type": "markdown", + "id": "39cbda27-4568-4f90-b4f7-f770b2150f49", + "metadata": {}, + "source": [ + "Cleaning data, i.e. remove all sites where measurements are missing for any of the quantities" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7d45a5c9-13fe-4e18-82f9-2289d6a7e498", + "metadata": {}, + "outputs": [], + "source": [ + "data_filtered = mbs.filter_values(data_ordination, \n", + " replace_NaN = 'remove', \n", + " inplace = True,\n", + " verbose = True)\n", + "data_filtered" + ] + }, + { + "cell_type": "markdown", + "id": "72208484-a3b4-4460-8cf4-18f5abbb5462", + "metadata": {}, + "source": [ + "### Data transformation\n", + "\n", + "Concentrations of contaminants (`Sum GC`) is log-transformed (given that concentration vary over orders of magnitude) and then standardized.\n", + "Other data is only standardized." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "28570c35-ab3b-402a-965c-cd8699715747", + "metadata": {}, + "outputs": [], + "source": [ + "data_transformed = mbs.transform_values(data_ordination,\n", + " name_list = variables_1,\n", + " how = 'log_scale',\n", + " inplace = True,\n", + " )\n", + "\n", + "data_transformed = mbs.transform_values(data_ordination,\n", + " name_list = variables_1,\n", + " how = 'standardize',\n", + " inplace = True,\n", + " )\n", + "\n", + "data_transformed = mbs.transform_values(data_ordination,\n", + " name_list = variables_2,\n", + " how = 'standardize',\n", + " inplace = True,\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "e3e0125e-349c-430c-a5cf-c656f543b35f", + "metadata": {}, + "source": [ + "### Ordination analysis by PCA" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "861c62e3-ba4f-4434-bb2a-74070e08b25e", + "metadata": {}, + "outputs": [], + "source": [ + "ordination_output = mbs.pca(data_ordination,\n", + " independent_variables = variables_1+variables_2,\n", + " verbose = True)" + ] + }, + { + "cell_type": "markdown", + "id": "d3b7a990-991c-4451-a475-209b25eba09d", + "metadata": {}, + "source": [ + "### Ordination plot" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e4808523-f6b7-4019-a575-d90ad4797ef6", + "metadata": {}, + "outputs": [], + "source": [ + "fig, ax = mbs.ordination_plot(ordination_output=ordination_output,\n", + " plot_scores = True, \n", + " plot_loadings = True,\n", + " rescale_loadings_scores = True,\n", + " figsize = [4.5,3],\n", + " title = \"Unconstrained Ordination PCA\", \n", + " axis_ranges = [-0.6,0.8,-0.6,0.7],\n", + " label_fontsize = 10,\n", + " loading_fontsize = 8,\n", + " #score_fontsize = 6,\n", + " #save_fig = 'ordination_amersfoort_pca.png',\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "dd0a7427-172e-4e65-88ba-9bda8588fc23", + "metadata": {}, + "source": [ + "### Interpretation\n", + "\n", + "The figure shows the results of the PCA (principle component analysis) as multi-variate statistics tool for the geochemical parameters. The axes denote the percentage of variance explained by each principal component. Data was standardized, with `Sum GC` (being the total sum of contaminants) being logarithmically transformed as via $log(x+1)$.\n", + "\n", + "This biplot shows two different elements of information: the variable loadings show as arrows and the site scores shown as dots. The two plot axis represent the two main axis identified by the ordination methods. They are scales to the minimal value of $-1$ and the maximum value of $1$. \n", + "\n", + "The direction of the arrow indicates to which ordination axis it correlates. The length of the vector is equivalent to the extent of that correlation. Positive scores or loadings indicate positive correlation with the axis, where negative values indicate negative \n", + "correlation. For example, a variable with negative loadings for the first two ordination axes is anticorrelated with the two largest trends in the data. Arrows pointing in the same direction indicate that the variable are correlated. Arrows at an right angle to one another are uncorrelated. Arrows that point in opposite directions are anti-correlated. A vector very close to the origin shows little to no correlation with the axes. \n", + "\n", + "Proximity of the site scores in the plot indicate the similarity between the sample sites. " + ] + }, + { + "cell_type": "markdown", + "id": "a0b64950-7749-42c0-8b6e-f04e3887a36d", + "metadata": {}, + "source": [ + "## Constrained Analysis (CCA & RDA)\n", + "### Data preprocessing\n", + "\n", + "Specify groups of quantities to perform analysis on:\n", + "* group of geochemical parameters\n", + "* group of contaminants\n", + "* sequencing data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ceb4d979-b418-4eb9-a4b0-ee5f2ba072d5", + "metadata": {}, + "outputs": [], + "source": [ + "geochemicals_group = ['nitrate','sulfate','redoxpot','iron2','manganese2']\n", + "#contaminant_group = ['benzene','toluene','ethylbenzene','pm_xylene','indene','naphthalene']\n", + "contaminant_group = ['benzene','toluene','indene','naphthalene']\n", + "variables_dna = ['Total bacteria 16SRrna', 'Benzene carboxylase', 'NirS', 'NarG', 'BssA SRB',\n", + " 'BssA nitraat', 'Peptococcus']" + ] + }, + { + "cell_type": "markdown", + "id": "4f0b5c46-3381-44c7-97ca-a024e40057a8", + "metadata": {}, + "source": [ + "Extract data of quantities of interest:\n", + "*geochemical\n", + "*contaminants" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "68cf38bb-c872-48bf-91a9-adc420ad2d73", + "metadata": {}, + "outputs": [], + "source": [ + "geochem_selected = environment[['sample_nr']+geochemicals_group]\n", + "cont_selected = contaminants[['sample_nr']+contaminant_group]\n", + "\n", + "contaminant_group_analysis = list(cont_selected.columns)\n", + "contaminant_group_analysis.remove('sample_nr')" + ] + }, + { + "cell_type": "markdown", + "id": "e186bf15-7a35-4ae3-98d4-2ba2831be596", + "metadata": {}, + "source": [ + "Concatenate all relevant data:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2ad63f9c-4eb9-4591-b0b1-d11781ad9b4b", + "metadata": {}, + "outputs": [], + "source": [ + "data_ordination = mbs.merge_data([geochem_selected,cont_selected,dna],clean = True)\n" + ] + }, + { + "cell_type": "markdown", + "id": "89c50d89-66de-4a13-b3c6-bb2c72b5390a", + "metadata": {}, + "source": [ + "### Data transformation for CCA" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a7992b3a-dc07-41de-af16-98e7854e7270", + "metadata": {}, + "outputs": [], + "source": [ + "data_cca = data_ordination.copy()\n", + "\n", + "mbs.filter_values(data_cca,\n", + " replace_NaN = 'remove',#'average', # #'zero'\n", + " inplace = True,\n", + " #verbose = True\n", + " )\n", + "\n", + "mbs.transform_values(data_cca,\n", + " name_list = variables_dna,\n", + " how = 'log_scale',\n", + " inplace = True,\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "4fb18d32-3da5-4cfe-bb26-345663084668", + "metadata": {}, + "source": [ + "### Ordination analysis by CCA" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c8a1b556-53ea-4ac5-80d8-a6b0f54717e6", + "metadata": {}, + "outputs": [], + "source": [ + "cca_output = mbs.cca(data_cca,\n", + " independent_variables = contaminant_group_analysis,\n", + " dependent_variables = variables_dna,\n", + " verbose = True)" + ] + }, + { + "cell_type": "markdown", + "id": "4bc6882c-9dcf-42e4-9e57-32aacd7dbe99", + "metadata": {}, + "source": [ + "### plot results CCA" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d1259e04-2f68-4787-a4d3-d37992787c5a", + "metadata": {}, + "outputs": [], + "source": [ + "fig, ax = mbs.ordination_plot(ordination_output=cca_output,\n", + " plot_scores = False,\n", + " plot_loadings = True,\n", + " rescale_loadings_scores = False,\n", + " label_fontsize = 10,\n", + " loading_fontsize = 8,\n", + " score_fontsize = 6,\n", + " title =\"Constrained Ordination CCA\",\n", + " save_fig = 'cca_dna.png',\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "0a8fa1b0-4d1c-442e-8a8a-80eb22389cb4", + "metadata": {}, + "source": [ + "### Data transformation for RDA" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d36f65b8-122f-464c-9b09-a114f8aa986e", + "metadata": {}, + "outputs": [], + "source": [ + "data_rda = data_ordination.copy()\n", + "\n", + "mbs.filter_values(data_rda,\n", + " replace_NaN = 'zero',\n", + " # replace_NaN = 'average',\n", + " # replace_NaN = 'remove',\n", + " inplace = True,\n", + " verbose = True)\n", + "\n", + "### if (part of) data is log-transformed (before standardization):\n", + "mbs.transform_values(data_rda,\n", + " name_list = variables_dna,\n", + " how = 'log_scale',\n", + " inplace = True,\n", + " )\n", + "\n", + "mbs.transform_values(data_rda,\n", + " how = 'standardize',\n", + " inplace = True,\n", + " )\n" + ] + }, + { + "cell_type": "markdown", + "id": "8599df9e-9828-4be8-83c1-b6ca1e1dcec4", + "metadata": {}, + "source": [ + "### Ordination analysis by RDA" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e16d1df7-bf9f-4c6a-9694-62f3bb30bd12", + "metadata": {}, + "outputs": [], + "source": [ + "rda_output = mbs.rda(data_rda,\n", + " independent_variables = contaminant_group_analysis,\n", + " # independent_variables = contaminant_group_analysis + geochemicals_group,\n", + " dependent_variables = variables_dna,\n", + " verbose = True)\n" + ] + }, + { + "cell_type": "markdown", + "id": "9da2699f-1323-4172-87b0-31f10d290198", + "metadata": {}, + "source": [ + "### plot results RDA" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9facfad6-3a7e-4c62-9b7e-3a0b9514def3", + "metadata": {}, + "outputs": [], + "source": [ + "fig, ax = mbs.ordination_plot(ordination_output=rda_output,\n", + " plot_scores = False,\n", + " plot_loadings = True,\n", + " rescale_loadings_scores = False,\n", + " title = \"Constrained Ordination RDA\",\n", + " figsize = [4.5,3],\n", + " label_fontsize = 10,\n", + " loading_fontsize = 8,\n", + " #score_fontsize = 6,\n", + " # axis_ranges = [-0.6,0.8,-0.8,1.0],\n", + " save_fig = 'ordination_amersfoort_rda.png',\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3e6bd870-57e6-4a2a-ba42-4b256e964f3e", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/mkdocs.yml b/mkdocs.yml index 7cba3dc..a85b2dc 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -17,6 +17,12 @@ nav: - Concentrations: methods/concentrations.md - Ordination: methods/ordination.md - Stable Isotope Analysis: methods/stable_isotopes.md + - Examples: + - Amersfoort Concentrations: examples/ex02_Amersfoort/example_02_amersfoort_concentrations.ipynb + - Amersfoort NA Screening: examples/ex02_Amersfoort/example_02_amersfoort_NAscreening.ipynb + - Amersfoort Metabolites: examples/ex02_Amersfoort/example_02_amersfoort_metabolites.ipynb + - Amersfoort Isotopes: examples/ex02_Amersfoort/example_02_amersfoort_isotopes_lambda.ipynb + - Amersfoort Ordination GQ: examples/ex02_Amersfoort/example_02_amersfoort_ordination_GQ.ipynb - Development: development/development.md - API Reference: - Data: reference/reference_data.md @@ -71,6 +77,10 @@ plugins: show_source: true options: show_submodules: true +- mkdocs-jupyter: + execute: true + include_source: true + custom_mathjax_url: "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS_CHTML-full,Safe" # Styled blocks: https://squidfunk.github.io/mkdocs-material/reference/admonitions/#supported-types markdown_extensions: @@ -104,4 +114,4 @@ extra: version: provider: mike default: latest - alias: true \ No newline at end of file + alias: true diff --git a/pyproject.toml b/pyproject.toml index 7c48f3a..066c5a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,6 +68,7 @@ doc = [ "mdx-include >=1.4.1", "mkdocs-markdownextradata-plugin >=0.2.5", "mike >=2.1.3", + "mkdocs-jupyter >=0.25.1", ] [project.urls]