Created
March 23, 2016 21:21
-
-
Save ElDeveloper/40ee4bdf9a342e252127 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "import pandas as pd\n", | |
| "import numpy as np\n", | |
| "\n", | |
| "from emperor.qiime_backports.parse import parse_mapping_file\n", | |
| "from skbio.stats.ordination import OrdinationResults\n", | |
| "from skbio.io.util import open_file\n", | |
| "from emperor import Emperor\n", | |
| "\n", | |
| "def load_mf(fn):\n", | |
| " with open_file(fn, 'U') as f:\n", | |
| " mapping_data, header, _ = parse_mapping_file(f)\n", | |
| " _mapping_file = pd.DataFrame(mapping_data, columns=header)\n", | |
| " _mapping_file.set_index('SampleID', inplace=True)\n", | |
| " return _mapping_file" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "from skbio import DistanceMatrix\n", | |
| "from skbio.stats.ordination import PCoA\n", | |
| "\n", | |
| "mf = load_mf('/Users/yoshikivazquezbaeza/Desktop/emperor_pg/Fasting_Map.txt')\n", | |
| "\n", | |
| "dm = DistanceMatrix.from_file('/Users/yoshikivazquezbaeza/Desktop/emperor_pg/unweighted_unifrac_dm.txt')\n", | |
| "res = PCoA(dm).scores()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "res.proportion_explained" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "np.random.randn(3, 3)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "eigvals = np.array([0.47941212, 0.29201496, 0.24744925,\n", | |
| " 0.20149607, 0.18007613, 0.14780677,\n", | |
| " 0.13579593, 0.1122597, 0.])\n", | |
| "n = eigvals.shape[0]\n", | |
| "site = np.random.rand(n, n)\n", | |
| "site_ids = ('PC.636', 'PC.635', 'PC.356', 'PC.481', 'PC.354', 'PC.593',\n", | |
| " 'PC.355', 'PC.607', 'PC.634')\n", | |
| "p_explained = np.array([0.26688705, 0.1625637, 0.13775413, 0.11217216,\n", | |
| " 0.10024775, 0.08228351, 0.07559712, 0.06249458,\n", | |
| " 0.])\n", | |
| "OrdinationResults(eigvals, site=site, site_ids=site_ids, proportion_explained=p_explained)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "Emperor(mf, _19)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 2", | |
| "language": "python", | |
| "name": "python2" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 2 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython2", | |
| "version": "2.7.9" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 0 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment