{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true, "slideshow": { "slide_type": "slide" } }, "source": [ "# Animated ordinations\n", "\n", "In some cases it is useful to look at longitudinal data animated in an ordination. If your dataset includes longitudinal data (time, position, pH, etc), you can draw an animated trace using the `Animations` tab. For more information look at [this tutorial](http://emperor.microbio.me/uno/build/html/tutorials/animations.html)." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "deletable": true, "editable": true, "slideshow": { "slide_type": "slide" } }, "outputs": [], "source": [ "import pandas as pd, numpy as np\n", "from emperor import Emperor, nbinstall\n", "from skbio import OrdinationResults\n", "\n", "nbinstall()\n", "\n", "def load_mf(fn, index='#SampleID'):\n", " _df = pd.read_csv(fn, sep='\\t', dtype=str, keep_default_na=False, na_values=[])\n", " _df.set_index(index, inplace=True)\n", " return _df" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "We are going to load data from [Caporaso et al. 2011](https://www.ncbi.nlm.nih.gov/pubmed/21624126). This is a subset of the full dataset, if you wish to look at the full data you can find it in study [550](https://qiita.ucsd.edu/study/description/550) in [Qiita](https://qiita.ucsd.edu) (remember you need to be logged in to access the study)." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "deletable": true, "editable": true, "slideshow": { "slide_type": "slide" } }, "outputs": [], "source": [ "mf = load_mf('moving-pictures/sample-metadata.tsv')\n", "res = OrdinationResults.read('moving-pictures/ordination.txt')" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "Recall that in this study two subjects are sampled longitudinally over four different sites (gut, left palm, right palm and tongue). In order to look at an individual trace per body site and per subject, we need to combine the `Subject` and the `BodySite` columns." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "mf['animated_trace'] = mf.Subject + ' ' + mf.BodySite" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "If you want to share your notebook via GitHub use `remote=True` and make sure you share your notebook using nbviewer." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "viz = Emperor(res, mf, remote=False)\n", "viz.custom_axes.append('DaysSinceExperimentStart')" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "In the `Gradient` dropdown, select the `DaysSinceExperimentStart` category. This category determines the order to connect the samples in a trace. And in the `Trajectory` dropdown, select the `animated_trace` category. This category indicates which samples will constitute each trace. Lastly, to look at the animated traces, go to the `Animations` tab and click the play button.\n", "\n", "As you can see in the animation, each body site for each subject is animated individually over time." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "viz" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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", "version": "3.5.1" }, "widgets": { "state": {}, "version": "1.1.2" } }, "nbformat": 4, "nbformat_minor": 0 }