{"action":"created","comment":{"url":"https://api.github.com/repos/qiime2/q2-diversity/pulls/comments/69355253","id":69355253,"diff_hunk":"@@ -5,3 +5,110 @@\n #\n # The full license is in the file LICENSE, distributed with this software.\n # ----------------------------------------------------------------------------\n+\n+import os\n+\n+import biom\n+import scipy\n+import skbio\n+import qiime\n+import pandas as pd\n+import seaborn as sns\n+import skbio.diversity\n+from statsmodels.sandbox.stats.multicomp import multipletests\n+\n+\n+# We should consider moving these functions to scikit-bio. They're part of\n+# the private API here for now.\n+def phylogenetic_metrics():\n+    return {'faith_pd'}\n+\n+\n+def non_phylogenetic_metrics():\n+    return {'ace', 'chao1', 'chao1_ci', 'berger_parker_d', 'brillouin_d',\n+            'dominance', 'doubles', 'enspie', 'esty_ci', 'fisher_alpha',\n+            'goods_coverage', 'heip_e', 'kempton_taylor_q', 'margalef',\n+            'mcintosh_d', 'mcintosh_e', 'menhinick', 'michaelis_menten_fit',\n+            'observed_otus', 'osd', 'pielou_e', 'robbins', 'shannon',\n+            'simpson', 'simpson_e', 'singles', 'strong', 'gini_index',\n+            'lladser_pe', 'lladser_ci'}\n+\n+\n+def alpha_phylogenetic(metric: str, feature_table: biom.Table,\n+                       phylogeny: skbio.TreeNode=None) -> pd.Series:\n+    if metric not in phylogenetic_metrics():\n+        raise ValueError(\"Unknown phylogenetic metric: %s\" % metric)\n+\n+    counts = feature_table.matrix_data.toarray().astype(int).T\n+    sample_ids = feature_table.ids(axis='sample')\n+    feature_ids = feature_table.ids(axis='observation')\n+\n+    return skbio.diversity.alpha_diversity(\n+              metric=metric,\n+              counts=counts,\n+              ids=sample_ids,\n+              otu_ids=feature_ids,\n+              tree=phylogeny)\n+\n+\n+def alpha(metric: str, feature_table: biom.Table) -> pd.Series:\n+    if metric not in non_phylogenetic_metrics():\n+        raise ValueError(\"Unknown metric: %s\" % metric)\n+\n+    counts = feature_table.matrix_data.toarray().astype(int).T\n+    sample_ids = feature_table.ids(axis='sample')\n+\n+    return skbio.diversity.alpha_diversity(\n+              metric=metric,\n+              counts=counts,\n+              ids=sample_ids)\n+\n+\n+def alpha_comparisons(output_dir: str, alpha_diversities: pd.Series,\n+                      metadata: qiime.MetadataCategory) -> None:\n+    alpha_diversities.name = 'Alpha diversity'\n+    metadata = metadata.to_series()\n+    data = pd.concat([alpha_diversities, metadata], axis=1)\n+    names = []\n+    groups = []\n+    for name, group in data.groupby(metadata.name):\n+        names.append(name)\n+        groups.append(list(group['Alpha diversity']))\n+    ax = sns.boxplot(data=groups)\n+    ax.set_xticklabels(names)\n+    ax.get_figure().savefig(os.path.join(output_dir, 'boxplots.png'))\n+    ax.get_figure().savefig(os.path.join(output_dir, 'boxplots.pdf'))\n+\n+    # perform Kruskal-Wallis H-test\n+    H, p = scipy.stats.mstats.kruskalwallis(*groups)\n+\n+    # perform Mann-Whitney U-test and correct for multiple comparisons\n+    u_results = []\n+    for i in range(len(names)):\n+        for j in range(i):\n+            U, p = scipy.stats.mannwhitneyu(groups[i], groups[j])","path":"q2_diversity/_alpha.py","position":85,"original_position":85,"commit_id":"829f657e1f1428540f7f8d4dee46b69d3c966ea1","original_commit_id":"829f657e1f1428540f7f8d4dee46b69d3c966ea1","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":"Good to know... I can change this to also call Kruskal-Wallis, which is the same as Mann-Whitney U when there are two groups. ","created_at":"2016-07-01T21:00:28Z","updated_at":"2016-07-01T21:00:28Z","html_url":"https://github.com/qiime2/q2-diversity/pull/22#discussion_r69355253","pull_request_url":"https://api.github.com/repos/qiime2/q2-diversity/pulls/22","_links":{"self":{"href":"https://api.github.com/repos/qiime2/q2-diversity/pulls/comments/69355253"},"html":{"href":"https://github.com/qiime2/q2-diversity/pull/22#discussion_r69355253"},"pull_request":{"href":"https://api.github.com/repos/qiime2/q2-diversity/pulls/22"}}},"pull_request":{"url":"https://api.github.com/repos/qiime2/q2-diversity/pulls/22","id":75731737,"html_url":"https://github.com/qiime2/q2-diversity/pull/22","diff_url":"https://github.com/qiime2/q2-diversity/pull/22.diff","patch_url":"https://github.com/qiime2/q2-diversity/pull/22.patch","issue_url":"https://api.github.com/repos/qiime2/q2-diversity/issues/22","number":22,"state":"open","locked":false,"title":"new methods and visualization","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":"* splits beta diversity into phylogenetic and non-phylogenetic methods\r\n* adds phylogenetic and non-phylogenetic alpha diversity computation methods\r\n* adds pcoa method\r\n* adds alpha diversity visualization (boxplots and non-parametric stats)\r\n* improvements to README.md\r\n\r\nThis one is ready for review @ebolyen and @jairideout. ","created_at":"2016-06-29T22:20:13Z","updated_at":"2016-07-01T21:00:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0b419ac34a7fc00683d78bd0de0f5d5c0fa09fe6","assignee":{"login":"jairideout","id":1847232,"avatar_url":"https://avatars.githubusercontent.com/u/1847232?v=3","gravatar_id":"","url":"https://api.github.com/users/jairideout","html_url":"https://github.com/jairideout","followers_url":"https://api.github.com/users/jairideout/followers","following_url":"https://api.github.com/users/jairideout/following{/other_user}","gists_url":"https://api.github.com/users/jairideout/gists{/gist_id}","starred_url":"https://api.github.com/users/jairideout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jairideout/subscriptions","organizations_url":"https://api.github.com/users/jairideout/orgs","repos_url":"https://api.github.com/users/jairideout/repos","events_url":"https://api.github.com/users/jairideout/events{/privacy}","received_events_url":"https://api.github.com/users/jairideout/received_events","type":"User","site_admin":false},"assignees":[{"login":"jairideout","id":1847232,"avatar_url":"https://avatars.githubusercontent.com/u/1847232?v=3","gravatar_id":"","url":"https://api.github.com/users/jairideout","html_url":"https://github.com/jairideout","followers_url":"https://api.github.com/users/jairideout/followers","following_url":"https://api.github.com/users/jairideout/following{/other_user}","gists_url":"https://api.github.com/users/jairideout/gists{/gist_id}","starred_url":"https://api.github.com/users/jairideout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jairideout/subscriptions","organizations_url":"https://api.github.com/users/jairideout/orgs","repos_url":"https://api.github.com/users/jairideout/repos","events_url":"https://api.github.com/users/jairideout/events{/privacy}","received_events_url":"https://api.github.com/users/jairideout/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/qiime2/q2-diversity/pulls/22/commits","review_comments_url":"https://api.github.com/repos/qiime2/q2-diversity/pulls/22/comments","review_comment_url":"https://api.github.com/repos/qiime2/q2-diversity/pulls/comments{/number}","comments_url":"https://api.github.com/repos/qiime2/q2-diversity/issues/22/comments","statuses_url":"https://api.github.com/repos/qiime2/q2-diversity/statuses/829f657e1f1428540f7f8d4dee46b69d3c966ea1","head":{"label":"gregcaporaso:issue-2","ref":"issue-2","sha":"829f657e1f1428540f7f8d4dee46b69d3c966ea1","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":53688961,"name":"diversity","full_name":"gregcaporaso/diversity","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/diversity","description":"","fork":true,"url":"https://api.github.com/repos/gregcaporaso/diversity","forks_url":"https://api.github.com/repos/gregcaporaso/diversity/forks","keys_url":"https://api.github.com/repos/gregcaporaso/diversity/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gregcaporaso/diversity/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gregcaporaso/diversity/teams","hooks_url":"https://api.github.com/repos/gregcaporaso/diversity/hooks","issue_events_url":"https://api.github.com/repos/gregcaporaso/diversity/issues/events{/number}","events_url":"https://api.github.com/repos/gregcaporaso/diversity/events","assignees_url":"https://api.github.com/repos/gregcaporaso/diversity/assignees{/user}","branches_url":"https://api.github.com/repos/gregcaporaso/diversity/branches{/branch}","tags_url":"https://api.github.com/repos/gregcaporaso/diversity/tags","blobs_url":"https://api.github.com/repos/gregcaporaso/diversity/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gregcaporaso/diversity/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gregcaporaso/diversity/git/refs{/sha}","trees_url":"https://api.github.com/repos/gregcaporaso/diversity/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gregcaporaso/diversity/statuses/{sha}","languages_url":"https://api.github.com/repos/gregcaporaso/diversity/languages","stargazers_url":"https://api.github.com/repos/gregcaporaso/diversity/stargazers","contributors_url":"https://api.github.com/repos/gregcaporaso/diversity/contributors","subscribers_url":"https://api.github.com/repos/gregcaporaso/diversity/subscribers","subscription_url":"https://api.github.com/repos/gregcaporaso/diversity/subscription","commits_url":"https://api.github.com/repos/gregcaporaso/diversity/commits{/sha}","git_commits_url":"https://api.github.com/repos/gregcaporaso/diversity/git/commits{/sha}","comments_url":"https://api.github.com/repos/gregcaporaso/diversity/comments{/number}","issue_comment_url":"https://api.github.com/repos/gregcaporaso/diversity/issues/comments{/number}","contents_url":"https://api.github.com/repos/gregcaporaso/diversity/contents/{+path}","compare_url":"https://api.github.com/repos/gregcaporaso/diversity/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gregcaporaso/diversity/merges","archive_url":"https://api.github.com/repos/gregcaporaso/diversity/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gregcaporaso/diversity/downloads","issues_url":"https://api.github.com/repos/gregcaporaso/diversity/issues{/number}","pulls_url":"https://api.github.com/repos/gregcaporaso/diversity/pulls{/number}","milestones_url":"https://api.github.com/repos/gregcaporaso/diversity/milestones{/number}","notifications_url":"https://api.github.com/repos/gregcaporaso/diversity/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gregcaporaso/diversity/labels{/name}","releases_url":"https://api.github.com/repos/gregcaporaso/diversity/releases{/id}","deployments_url":"https://api.github.com/repos/gregcaporaso/diversity/deployments","created_at":"2016-03-11T18:41:26Z","updated_at":"2016-03-11T18:41:27Z","pushed_at":"2016-07-01T18:49:23Z","git_url":"git://github.com/gregcaporaso/diversity.git","ssh_url":"git@github.com:gregcaporaso/diversity.git","clone_url":"https://github.com/gregcaporaso/diversity.git","svn_url":"https://github.com/gregcaporaso/diversity","homepage":null,"size":21,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"qiime2:master","ref":"master","sha":"93aef6d463730276eb9defbb1c1e619fabc15db5","user":{"login":"qiime2","id":18176583,"avatar_url":"https://avatars.githubusercontent.com/u/18176583?v=3","gravatar_id":"","url":"https://api.github.com/users/qiime2","html_url":"https://github.com/qiime2","followers_url":"https://api.github.com/users/qiime2/followers","following_url":"https://api.github.com/users/qiime2/following{/other_user}","gists_url":"https://api.github.com/users/qiime2/gists{/gist_id}","starred_url":"https://api.github.com/users/qiime2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qiime2/subscriptions","organizations_url":"https://api.github.com/users/qiime2/orgs","repos_url":"https://api.github.com/users/qiime2/repos","events_url":"https://api.github.com/users/qiime2/events{/privacy}","received_events_url":"https://api.github.com/users/qiime2/received_events","type":"Organization","site_admin":false},"repo":{"id":53173670,"name":"q2-diversity","full_name":"qiime2/q2-diversity","owner":{"login":"qiime2","id":18176583,"avatar_url":"https://avatars.githubusercontent.com/u/18176583?v=3","gravatar_id":"","url":"https://api.github.com/users/qiime2","html_url":"https://github.com/qiime2","followers_url":"https://api.github.com/users/qiime2/followers","following_url":"https://api.github.com/users/qiime2/following{/other_user}","gists_url":"https://api.github.com/users/qiime2/gists{/gist_id}","starred_url":"https://api.github.com/users/qiime2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qiime2/subscriptions","organizations_url":"https://api.github.com/users/qiime2/orgs","repos_url":"https://api.github.com/users/qiime2/repos","events_url":"https://api.github.com/users/qiime2/events{/privacy}","received_events_url":"https://api.github.com/users/qiime2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/qiime2/q2-diversity","description":"","fork":false,"url":"https://api.github.com/repos/qiime2/q2-diversity","forks_url":"https://api.github.com/repos/qiime2/q2-diversity/forks","keys_url":"https://api.github.com/repos/qiime2/q2-diversity/keys{/key_id}","collaborators_url":"https://api.github.com/repos/qiime2/q2-diversity/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/qiime2/q2-diversity/teams","hooks_url":"https://api.github.com/repos/qiime2/q2-diversity/hooks","issue_events_url":"https://api.github.com/repos/qiime2/q2-diversity/issues/events{/number}","events_url":"https://api.github.com/repos/qiime2/q2-diversity/events","assignees_url":"https://api.github.com/repos/qiime2/q2-diversity/assignees{/user}","branches_url":"https://api.github.com/repos/qiime2/q2-diversity/branches{/branch}","tags_url":"https://api.github.com/repos/qiime2/q2-diversity/tags","blobs_url":"https://api.github.com/repos/qiime2/q2-diversity/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/qiime2/q2-diversity/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/qiime2/q2-diversity/git/refs{/sha}","trees_url":"https://api.github.com/repos/qiime2/q2-diversity/git/trees{/sha}","statuses_url":"https://api.github.com/repos/qiime2/q2-diversity/statuses/{sha}","languages_url":"https://api.github.com/repos/qiime2/q2-diversity/languages","stargazers_url":"https://api.github.com/repos/qiime2/q2-diversity/stargazers","contributors_url":"https://api.github.com/repos/qiime2/q2-diversity/contributors","subscribers_url":"https://api.github.com/repos/qiime2/q2-diversity/subscribers","subscription_url":"https://api.github.com/repos/qiime2/q2-diversity/subscription","commits_url":"https://api.github.com/repos/qiime2/q2-diversity/commits{/sha}","git_commits_url":"https://api.github.com/repos/qiime2/q2-diversity/git/commits{/sha}","comments_url":"https://api.github.com/repos/qiime2/q2-diversity/comments{/number}","issue_comment_url":"https://api.github.com/repos/qiime2/q2-diversity/issues/comments{/number}","contents_url":"https://api.github.com/repos/qiime2/q2-diversity/contents/{+path}","compare_url":"https://api.github.com/repos/qiime2/q2-diversity/compare/{base}...{head}","merges_url":"https://api.github.com/repos/qiime2/q2-diversity/merges","archive_url":"https://api.github.com/repos/qiime2/q2-diversity/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/qiime2/q2-diversity/downloads","issues_url":"https://api.github.com/repos/qiime2/q2-diversity/issues{/number}","pulls_url":"https://api.github.com/repos/qiime2/q2-diversity/pulls{/number}","milestones_url":"https://api.github.com/repos/qiime2/q2-diversity/milestones{/number}","notifications_url":"https://api.github.com/repos/qiime2/q2-diversity/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/qiime2/q2-diversity/labels{/name}","releases_url":"https://api.github.com/repos/qiime2/q2-diversity/releases{/id}","deployments_url":"https://api.github.com/repos/qiime2/q2-diversity/deployments","created_at":"2016-03-05T00:10:32Z","updated_at":"2016-06-26T20:35:20Z","pushed_at":"2016-07-01T18:49:23Z","git_url":"git://github.com/qiime2/q2-diversity.git","ssh_url":"git@github.com:qiime2/q2-diversity.git","clone_url":"https://github.com/qiime2/q2-diversity.git","svn_url":"https://github.com/qiime2/q2-diversity","homepage":null,"size":15,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":9,"forks":3,"open_issues":9,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/qiime2/q2-diversity/pulls/22"},"html":{"href":"https://github.com/qiime2/q2-diversity/pull/22"},"issue":{"href":"https://api.github.com/repos/qiime2/q2-diversity/issues/22"},"comments":{"href":"https://api.github.com/repos/qiime2/q2-diversity/issues/22/comments"},"review_comments":{"href":"https://api.github.com/repos/qiime2/q2-diversity/pulls/22/comments"},"review_comment":{"href":"https://api.github.com/repos/qiime2/q2-diversity/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/qiime2/q2-diversity/pulls/22/commits"},"statuses":{"href":"https://api.github.com/repos/qiime2/q2-diversity/statuses/829f657e1f1428540f7f8d4dee46b69d3c966ea1"}}}}
{"actor":{"display_login":"gregcaporaso"}}