{"action":"created","comment":{"url":"https://api.github.com/repos/biocore/scikit-bio/pulls/comments/37227351","id":37227351,"diff_hunk":"@@ -0,0 +1,203 @@\n+# ----------------------------------------------------------------------------\n+# Copyright (c) 2013--, scikit-bio development team.\n+#\n+# Distributed under the terms of the Modified BSD License.\n+#\n+# The full license is in the file COPYING.txt, distributed with this software.\n+# ----------------------------------------------------------------------------\n+\n+from __future__ import absolute_import, division, print_function\n+\n+from skbio.util._decorator import experimental\n+from skbio.diversity._base import (_validate_counts_vectors,\n+                                   _validate_otu_ids_and_tree)\n+\n+\n+def _observed_otu_counts(counts, otu_ids):\n+    return {o: c for o, c in zip(otu_ids, counts) if c >= 1}\n+\n+\n+def _validate(u_counts, v_counts, otu_ids, tree):\n+    _validate_counts_vectors(u_counts=u_counts, v_counts=v_counts,\n+                             suppress_cast=True)\n+    _validate_otu_ids_and_tree(counts=u_counts, otu_ids=otu_ids, tree=tree)\n+\n+\n+@experimental(as_of=\"0.4.0-dev\")\n+def unweighted_unifrac(u_counts, v_counts, otu_ids, tree,\n+                       suppress_validation=False, **kwargs):\n+    \"\"\" Compute unweighted UniFrac\n+\n+    Parameters\n+    ----------\n+    u_counts, v_counts: list, np.array\n+        Vectors of counts of OTUs for two samples. Must be equal length.\n+    otu_ids: list, np.array\n+        Vector of OTU ids corresponding to tip names in ``tree``. Must be the\n+        same length as ``u_counts`` and ``v_counts``.\n+    tree: skbio.TreeNode\n+        Tree relating the OTUs in otu_ids. The set of tip names in the tree can\n+        be a superset of ``otu_ids``, but not a subset.\n+    suppress_validation: bool, optional\n+        If `True`, validation of the input won't be performed. This step can\n+        be slow, so if validation is run elsewhere it can be disabled here.\n+        However, invalid input data can lead to invalid results, so this step\n+        should not be bypassed all together.","path":"skbio/diversity/beta/_unifrac.py","position":45,"original_position":45,"commit_id":"9fc93861889214abdcd5b962a6a230b58275d52c","original_commit_id":"9fc93861889214abdcd5b962a6a230b58275d52c","user":{"login":"gregcaporaso","id":192372,"avatar_url":"https://avatars.githubusercontent.com/u/192372?v=3","gravatar_id":"","url":"https://api.github.com/users/gregcaporaso","html_url":"https://github.com/gregcaporaso","followers_url":"https://api.github.com/users/gregcaporaso/followers","following_url":"https://api.github.com/users/gregcaporaso/following{/other_user}","gists_url":"https://api.github.com/users/gregcaporaso/gists{/gist_id}","starred_url":"https://api.github.com/users/gregcaporaso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gregcaporaso/subscriptions","organizations_url":"https://api.github.com/users/gregcaporaso/orgs","repos_url":"https://api.github.com/users/gregcaporaso/repos","events_url":"https://api.github.com/users/gregcaporaso/events{/privacy}","received_events_url":"https://api.github.com/users/gregcaporaso/received_events","type":"User","site_admin":false},"body":"From @jairideout: Add ``kwargs``, and note that it's for internal use only. ","created_at":"2015-08-17T19:35:20Z","updated_at":"2015-08-17T19:35:20Z","html_url":"https://github.com/biocore/scikit-bio/pull/1027#discussion_r37227351","pull_request_url":"https://api.github.com/repos/biocore/scikit-bio/pulls/1027","_links":{"self":{"href":"https://api.github.com/repos/biocore/scikit-bio/pulls/comments/37227351"},"html":{"href":"https://github.com/biocore/scikit-bio/pull/1027#discussion_r37227351"},"pull_request":{"href":"https://api.github.com/repos/biocore/scikit-bio/pulls/1027"}}},"pull_request":{"url":"https://api.github.com/repos/biocore/scikit-bio/pulls/1027","id":41707296,"html_url":"https://github.com/biocore/scikit-bio/pull/1027","diff_url":"https://github.com/biocore/scikit-bio/pull/1027.diff","patch_url":"https://github.com/biocore/scikit-bio/pull/1027.patch","issue_url":"https://api.github.com/repos/biocore/scikit-bio/issues/1027","number":1027,"state":"open","locked":false,"title":"adds phylogenetic diversity metrics","user":{"login":"gregcaporaso","id":192372,"avatar_url":"https://avatars.githubusercontent.com/u/192372?v=3","gravatar_id":"","url":"https://api.github.com/users/gregcaporaso","html_url":"https://github.com/gregcaporaso","followers_url":"https://api.github.com/users/gregcaporaso/followers","following_url":"https://api.github.com/users/gregcaporaso/following{/other_user}","gists_url":"https://api.github.com/users/gregcaporaso/gists{/gist_id}","starred_url":"https://api.github.com/users/gregcaporaso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gregcaporaso/subscriptions","organizations_url":"https://api.github.com/users/gregcaporaso/orgs","repos_url":"https://api.github.com/users/gregcaporaso/repos","events_url":"https://api.github.com/users/gregcaporaso/events{/privacy}","received_events_url":"https://api.github.com/users/gregcaporaso/received_events","type":"User","site_admin":false},"body":"Adds PD, unweighted unifrac, and weighted unifrac (with and without normalization). \r\n\r\nTo do before merge:\r\n- [x] interface work (how will this be imported/used)\r\n - [x] add stability decorators\r\n - ~~should ``normalized=True`` be the default for ``weighted_unifrac``?~~ let's not for now, for consistency with QIIME\r\n - [x] modify ``pw_distances`` to take ``metric`` as the first argument and not have a default \r\n - [x] update ``pw_distances`` to take skbio's distance functions as strings and this should be the preferred/documented way of passing them (similar to SciPy's ``pdist``)\r\n - [x] for PD, ``u`` becomes ``counts`` to match our other alpha diversity metrics\r\n - [x] for *unifrac, ``u`` and ``v`` become ``u_counts`` and ``v_counts``, to match the alpha diversity metrics and SciPy\r\n - [x] ``phylogenetic_diversity`` renamed to ``faith_pd`` and move to ``_base.py``; make it accessible from ``skbio.diversity.alpha``\r\n - [x] ``*unifrac`` should be accessible from ``skbio.diversity.beta``, and ``skbio/diversity/beta/_stats.py`` should be renamed ``skbio/diversity/beta/_unifrac.py``\r\n - [x] allow **kwargs (some optimized methods may need to pass in other data, such as a cache) \r\n\r\n- [ ] testing\r\n - [x] expand unit tests to include direct computation of distance metrics with ``pw_distances``, including referencing the metric both by passing the function and the name (as a string)\r\n - [x] tree with no branch lengths\r\n - [x] tree with duplicated tip names\r\n - [x] tree with one node\r\n - [x] non-trivial case where tips in tree are superset of ``otu_ids``\r\n - [x] add test with input vector of ``length == 0``\r\n - [x] add test of vector with negative counts (see ``skbio.diversity.alpha._validate``)\r\n - [x] add direct tests of the new validate methods\r\n - [x] raises error on unrooted tree\r\n - [ ] add boundary test cases for ``faith_pd``\r\n\r\n- [ ] documentation\r\n - [x] add numpy-doc (with [cite](http://aem.asm.org/content/73/5/1576.long))\r\n - [ ] add formulas for metrics (including normalization of weighted unifrac)\r\n - [x] update ``skbio.diversity.beta`` doctests to use a phylogenetic metric\r\n - [x] update ``skbio.diversity.alpha`` doctests to use ``faith_pd``\r\n - [x] describe branch length normalization (more detail will be added when I add the formulas)\r\n - [ ] *OTU* versus *observation* in docs?\r\n\r\n- [x] misc\r\n - [x] inline ``_to_pdist_metric``\r\n - [x] add tree/otu ids ``_validate`` function\r\n - [x] add ``_validate`` for beta diversity metrics, similar (or the same as ``skbio.diversity.alpha._validate``)\r\n\r\n\r\n- [ ] squash commits\r\n- [ ] add ChangeLog note\r\n\r\n- [ ] future\r\n - [ ] port original web docs\r\n - [ ] explore alternative weighting schemes\r\n - [ ] generalization to DAGs\r\n - [ ] sparse vectors as input\r\n\r\n\r\n\r\n\r\n\r\n\r\nAddresses #46, #820.\r\n","created_at":"2015-08-05T17:59:14Z","updated_at":"2015-08-17T19:35:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4707a633728a6ae4cb4001bd83f93b22272330cc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/biocore/scikit-bio/pulls/1027/commits","review_comments_url":"https://api.github.com/repos/biocore/scikit-bio/pulls/1027/comments","review_comment_url":"https://api.github.com/repos/biocore/scikit-bio/pulls/comments{/number}","comments_url":"https://api.github.com/repos/biocore/scikit-bio/issues/1027/comments","statuses_url":"https://api.github.com/repos/biocore/scikit-bio/statuses/9fc93861889214abdcd5b962a6a230b58275d52c","head":{"label":"gregcaporaso:issue-46","ref":"issue-46","sha":"9fc93861889214abdcd5b962a6a230b58275d52c","user":{"login":"gregcaporaso","id":192372,"avatar_url":"https://avatars.githubusercontent.com/u/192372?v=3","gravatar_id":"","url":"https://api.github.com/users/gregcaporaso","html_url":"https://github.com/gregcaporaso","followers_url":"https://api.github.com/users/gregcaporaso/followers","following_url":"https://api.github.com/users/gregcaporaso/following{/other_user}","gists_url":"https://api.github.com/users/gregcaporaso/gists{/gist_id}","starred_url":"https://api.github.com/users/gregcaporaso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gregcaporaso/subscriptions","organizations_url":"https://api.github.com/users/gregcaporaso/orgs","repos_url":"https://api.github.com/users/gregcaporaso/repos","events_url":"https://api.github.com/users/gregcaporaso/events{/privacy}","received_events_url":"https://api.github.com/users/gregcaporaso/received_events","type":"User","site_admin":false},"repo":{"id":22703109,"name":"scikit-bio","full_name":"gregcaporaso/scikit-bio","owner":{"login":"gregcaporaso","id":192372,"avatar_url":"https://avatars.githubusercontent.com/u/192372?v=3","gravatar_id":"","url":"https://api.github.com/users/gregcaporaso","html_url":"https://github.com/gregcaporaso","followers_url":"https://api.github.com/users/gregcaporaso/followers","following_url":"https://api.github.com/users/gregcaporaso/following{/other_user}","gists_url":"https://api.github.com/users/gregcaporaso/gists{/gist_id}","starred_url":"https://api.github.com/users/gregcaporaso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gregcaporaso/subscriptions","organizations_url":"https://api.github.com/users/gregcaporaso/orgs","repos_url":"https://api.github.com/users/gregcaporaso/repos","events_url":"https://api.github.com/users/gregcaporaso/events{/privacy}","received_events_url":"https://api.github.com/users/gregcaporaso/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gregcaporaso/scikit-bio","description":"Core objects, functions and statistics for working with biological data in Python.","fork":true,"url":"https://api.github.com/repos/gregcaporaso/scikit-bio","forks_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/forks","keys_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/teams","hooks_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/hooks","issue_events_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/issues/events{/number}","events_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/events","assignees_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/assignees{/user}","branches_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/branches{/branch}","tags_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/tags","blobs_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/git/refs{/sha}","trees_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/statuses/{sha}","languages_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/languages","stargazers_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/stargazers","contributors_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/contributors","subscribers_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/subscribers","subscription_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/subscription","commits_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/commits{/sha}","git_commits_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/git/commits{/sha}","comments_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/comments{/number}","issue_comment_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/issues/comments{/number}","contents_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/contents/{+path}","compare_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/merges","archive_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/downloads","issues_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/issues{/number}","pulls_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/pulls{/number}","milestones_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/milestones{/number}","notifications_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/labels{/name}","releases_url":"https://api.github.com/repos/gregcaporaso/scikit-bio/releases{/id}","created_at":"2014-08-07T00:44:01Z","updated_at":"2015-05-04T21:38:20Z","pushed_at":"2015-08-17T17:41:55Z","git_url":"git://github.com/gregcaporaso/scikit-bio.git","ssh_url":"git@github.com:gregcaporaso/scikit-bio.git","clone_url":"https://github.com/gregcaporaso/scikit-bio.git","svn_url":"https://github.com/gregcaporaso/scikit-bio","homepage":"http://scikit-bio.org","size":33119,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"biocore:master","ref":"master","sha":"a4782c404cba853558177a9dd48b30c49a4551fb","user":{"login":"biocore","id":6241857,"avatar_url":"https://avatars.githubusercontent.com/u/6241857?v=3","gravatar_id":"","url":"https://api.github.com/users/biocore","html_url":"https://github.com/biocore","followers_url":"https://api.github.com/users/biocore/followers","following_url":"https://api.github.com/users/biocore/following{/other_user}","gists_url":"https://api.github.com/users/biocore/gists{/gist_id}","starred_url":"https://api.github.com/users/biocore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biocore/subscriptions","organizations_url":"https://api.github.com/users/biocore/orgs","repos_url":"https://api.github.com/users/biocore/repos","events_url":"https://api.github.com/users/biocore/events{/privacy}","received_events_url":"https://api.github.com/users/biocore/received_events","type":"Organization","site_admin":false},"repo":{"id":15168264,"name":"scikit-bio","full_name":"biocore/scikit-bio","owner":{"login":"biocore","id":6241857,"avatar_url":"https://avatars.githubusercontent.com/u/6241857?v=3","gravatar_id":"","url":"https://api.github.com/users/biocore","html_url":"https://github.com/biocore","followers_url":"https://api.github.com/users/biocore/followers","following_url":"https://api.github.com/users/biocore/following{/other_user}","gists_url":"https://api.github.com/users/biocore/gists{/gist_id}","starred_url":"https://api.github.com/users/biocore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biocore/subscriptions","organizations_url":"https://api.github.com/users/biocore/orgs","repos_url":"https://api.github.com/users/biocore/repos","events_url":"https://api.github.com/users/biocore/events{/privacy}","received_events_url":"https://api.github.com/users/biocore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/biocore/scikit-bio","description":"scikit-bio is an open-source, BSD-licensed, Python package providing data structures, algorithms, and educational resources for bioinformatics.","fork":false,"url":"https://api.github.com/repos/biocore/scikit-bio","forks_url":"https://api.github.com/repos/biocore/scikit-bio/forks","keys_url":"https://api.github.com/repos/biocore/scikit-bio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/biocore/scikit-bio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/biocore/scikit-bio/teams","hooks_url":"https://api.github.com/repos/biocore/scikit-bio/hooks","issue_events_url":"https://api.github.com/repos/biocore/scikit-bio/issues/events{/number}","events_url":"https://api.github.com/repos/biocore/scikit-bio/events","assignees_url":"https://api.github.com/repos/biocore/scikit-bio/assignees{/user}","branches_url":"https://api.github.com/repos/biocore/scikit-bio/branches{/branch}","tags_url":"https://api.github.com/repos/biocore/scikit-bio/tags","blobs_url":"https://api.github.com/repos/biocore/scikit-bio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/biocore/scikit-bio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/biocore/scikit-bio/git/refs{/sha}","trees_url":"https://api.github.com/repos/biocore/scikit-bio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/biocore/scikit-bio/statuses/{sha}","languages_url":"https://api.github.com/repos/biocore/scikit-bio/languages","stargazers_url":"https://api.github.com/repos/biocore/scikit-bio/stargazers","contributors_url":"https://api.github.com/repos/biocore/scikit-bio/contributors","subscribers_url":"https://api.github.com/repos/biocore/scikit-bio/subscribers","subscription_url":"https://api.github.com/repos/biocore/scikit-bio/subscription","commits_url":"https://api.github.com/repos/biocore/scikit-bio/commits{/sha}","git_commits_url":"https://api.github.com/repos/biocore/scikit-bio/git/commits{/sha}","comments_url":"https://api.github.com/repos/biocore/scikit-bio/comments{/number}","issue_comment_url":"https://api.github.com/repos/biocore/scikit-bio/issues/comments{/number}","contents_url":"https://api.github.com/repos/biocore/scikit-bio/contents/{+path}","compare_url":"https://api.github.com/repos/biocore/scikit-bio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/biocore/scikit-bio/merges","archive_url":"https://api.github.com/repos/biocore/scikit-bio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/biocore/scikit-bio/downloads","issues_url":"https://api.github.com/repos/biocore/scikit-bio/issues{/number}","pulls_url":"https://api.github.com/repos/biocore/scikit-bio/pulls{/number}","milestones_url":"https://api.github.com/repos/biocore/scikit-bio/milestones{/number}","notifications_url":"https://api.github.com/repos/biocore/scikit-bio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/biocore/scikit-bio/labels{/name}","releases_url":"https://api.github.com/repos/biocore/scikit-bio/releases{/id}","created_at":"2013-12-13T16:24:41Z","updated_at":"2015-08-13T13:47:16Z","pushed_at":"2015-08-17T19:33:45Z","git_url":"git://github.com/biocore/scikit-bio.git","ssh_url":"git@github.com:biocore/scikit-bio.git","clone_url":"https://github.com/biocore/scikit-bio.git","svn_url":"https://github.com/biocore/scikit-bio","homepage":"http://scikit-bio.org","size":41625,"stargazers_count":149,"watchers_count":149,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":83,"mirror_url":null,"open_issues_count":130,"forks":83,"open_issues":130,"watchers":149,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/biocore/scikit-bio/pulls/1027"},"html":{"href":"https://github.com/biocore/scikit-bio/pull/1027"},"issue":{"href":"https://api.github.com/repos/biocore/scikit-bio/issues/1027"},"comments":{"href":"https://api.github.com/repos/biocore/scikit-bio/issues/1027/comments"},"review_comments":{"href":"https://api.github.com/repos/biocore/scikit-bio/pulls/1027/comments"},"review_comment":{"href":"https://api.github.com/repos/biocore/scikit-bio/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/biocore/scikit-bio/pulls/1027/commits"},"statuses":{"href":"https://api.github.com/repos/biocore/scikit-bio/statuses/9fc93861889214abdcd5b962a6a230b58275d52c"}}}}