Created
July 31, 2015 21:27
-
-
Save wasade/f94d869fd4ea406a5089 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
| { | |
| "metadata": { | |
| "name": "", | |
| "signature": "sha256:a35ba5cf62583326081251bbb8c13dc76d747fa7fc2c8bee3616faae26381d95" | |
| }, | |
| "nbformat": 3, | |
| "nbformat_minor": 0, | |
| "worksheets": [ | |
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "!pwd" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "stream": "stdout", | |
| "text": [ | |
| "/Users/mcdonadt/rs/qiime/qiime_test_data/parallel_beta_diversity\r\n" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 1 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "# using cogent as that's what backs fast unifrac but same issue exists if done with skbio\n", | |
| "base_tree = 'rep_set.tre'\n", | |
| "changed_tree = 'rep_set_int_changed.tre'\n", | |
| "from cogent.parse.tree import DndParser" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 9 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "unchanged = DndParser(open(base_tree))\n", | |
| "altered_internal_labels = DndParser(open(base_tree))" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 4 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "# change the internal labels on the tree\n", | |
| "for idx, node in enumerate(altered_internal_labels.nontips()):\n", | |
| " node.Name = idx\n", | |
| "\n", | |
| "with open(changed_tree, 'w') as fp:\n", | |
| " fp.write(altered_internal_labels.getNewick(with_distances=True))" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 28 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "# verify tip names are unchanged\n", | |
| "[n.Name for n in unchanged.tips()] == [n.Name for n in altered_internal_labels.tips()]" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "metadata": {}, | |
| "output_type": "pyout", | |
| "prompt_number": 29, | |
| "text": [ | |
| "True" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 29 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "# verify branch lengths in the tree haven't changed\n", | |
| "[n.Length for n in unchanged.traverse()] == [n.Length for n in altered_internal_labels.traverse()]" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "metadata": {}, | |
| "output_type": "pyout", | |
| "prompt_number": 30, | |
| "text": [ | |
| "True" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 30 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "# verify the topologies are the same\n", | |
| "print unchanged.compareBySubsets(altered_internal_labels)" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "stream": "stdout", | |
| "text": [ | |
| "0.0\n" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 8 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "!beta_diversity.py -i otu_table.biom -o unchanged_test -t $base_tree -m unweighted_unifrac,weighted_unifrac -r PC.636,PC.481,PC.354,PC.635,PC.593,PC.356,PC.355,PC.607,PC.634" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "stream": "stdout", | |
| "text": [ | |
| "/Users/mcdonadt/.virtualenvs/python27/lib/python2.7/site-packages/numpy/core/fromnumeric.py:2507: VisibleDeprecationWarning: `rank` is deprecated; use the `ndim` attribute or function instead. To find the rank of a matrix see `numpy.linalg.matrix_rank`.\r\n", | |
| " VisibleDeprecationWarning)\r\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "stream", | |
| "stream": "stdout", | |
| "text": [ | |
| "/Users/mcdonadt/.virtualenvs/python27/lib/python2.7/site-packages/pytz/__init__.py:29: UserWarning: Module argparse was already imported from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.pyc, but /Users/mcdonadt/.virtualenvs/python27/lib/python2.7/site-packages is being added to sys.path\r\n", | |
| " from pkg_resources import resource_stream\r\n" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 18 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "!beta_diversity.py -i otu_table.biom -o changed_test -t $changed_tree -m unweighted_unifrac,weighted_unifrac -r PC.636,PC.481,PC.354,PC.635,PC.593,PC.356,PC.355,PC.607,PC.634" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "stream": "stdout", | |
| "text": [ | |
| "/Users/mcdonadt/.virtualenvs/python27/lib/python2.7/site-packages/numpy/core/fromnumeric.py:2507: VisibleDeprecationWarning: `rank` is deprecated; use the `ndim` attribute or function instead. To find the rank of a matrix see `numpy.linalg.matrix_rank`.\r\n", | |
| " VisibleDeprecationWarning)\r\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "stream", | |
| "stream": "stdout", | |
| "text": [ | |
| "/Users/mcdonadt/.virtualenvs/python27/lib/python2.7/site-packages/pytz/__init__.py:29: UserWarning: Module argparse was already imported from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.pyc, but /Users/mcdonadt/.virtualenvs/python27/lib/python2.7/site-packages is being added to sys.path\r\n", | |
| " from pkg_resources import resource_stream\r\n" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 19 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "from skbio import DistanceMatrix, read" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "stream": "stderr", | |
| "text": [ | |
| "/Users/mcdonadt/.virtualenvs/python27/lib/python2.7/site-packages/pytz/__init__.py:29: UserWarning: Module argparse was already imported from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.pyc, but /Users/mcdonadt/.virtualenvs/python27/lib/python2.7/site-packages is being added to sys.path\n", | |
| " from pkg_resources import resource_stream\n" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 20 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "# load the distance matrics\n", | |
| "unchanged_uw_dm = read('unchanged_test/unweighted_unifrac_otu_table.txt', into=DistanceMatrix)\n", | |
| "changed_uw_dm = read('changed_test/unweighted_unifrac_otu_table.txt', into=DistanceMatrix)" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 23 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "# check if they're the same\n", | |
| "unchanged_uw_dm == changed_uw_dm" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "metadata": {}, | |
| "output_type": "pyout", | |
| "prompt_number": 24, | |
| "text": [ | |
| "False" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 24 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "# verify the IDs are in the same order\n", | |
| "unchanged_uw_dm.ids == changed_uw_dm.ids" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "metadata": {}, | |
| "output_type": "pyout", | |
| "prompt_number": 25, | |
| "text": [ | |
| "True" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 25 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "# show an example of the changed data\n", | |
| "print unchanged_uw_dm.data[0, :]\n", | |
| "print changed_uw_dm.data[0, :]" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "stream": "stdout", | |
| "text": [ | |
| "[ 0. 0.60645837 0.6563796 0.5760386 0.65509986 0.62061374\n", | |
| " 0.57519786 0.65976109 0.56825433]\n", | |
| "[ 0. 0.61048819 0.69541332 0.62852528 0.64096947 0.68815016\n", | |
| " 0.64415814 0.61814587 0.49493281]\n" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 31 | |
| } | |
| ], | |
| "metadata": {} | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment