{"action":"created","comment":{"url":"https://api.github.com/repos/biocore/qiita/pulls/comments/27187583","id":27187583,"diff_hunk":"@@ -0,0 +1,96 @@\n+from collections import Counter, defaultdict\n+\n+from future.utils import viewvalues, viewitems\n+\n+from qiita_db.study import Study\n+from qiita_db.data import ProcessedData\n+\n+\n+def count_metadata(results, meta_cols):\n+    \"\"\"Counts the metadata found in a search, and returns these counts\n+    Parameters\n+    ----------\n+    results : dict of lists of list\n+        results in the format returned by the qiita_db search obj\n+    meta_cols : list\n+        metadata column names searched for, as returned by qiita_db search obj\n+    Returns\n+    -------\n+    fullcount : dict of dicts\n+        counts for each found metadata value over all studies, in the format\n+        {meta_col1: {value1: count, value2: count, ...}, ...}\n+    studycount : dict of dict of dicts\n+        counts for each found metadata value for each study, in the format\n+        {study_id: {meta_col1: {value1: count, value2: count, ...}, ...}, ...}\n+    \"\"\"\n+    def double_comprehension(results):\n+        for samples in viewvalues(results):\n+            for sample in samples:\n+                yield sample\n+\n+    fullcount = {}\n+    # rearrange all samples so that each metadata column found is its own list\n+    meta_vals = zip(*double_comprehension(results))\n+    for pos, cat in enumerate(meta_cols):\n+        # use Counter object to count all metadata values for a column\n+        # pos+1 so we skip the sample names list\n+        fullcount[cat] = Counter(meta_vals[pos + 1])\n+\n+    # Now get metadata counts for each study, removing sample ids as before\n+    studycount = {}\n+    for study_id in results:\n+        studycount[study_id] = {}\n+        # zip all samples for a given study so that each metadata column found\n+        # is its own list\n+        meta_vals = zip(*(sample for sample in results[study_id]))\n+        for pos, cat in enumerate(meta_cols):\n+            # use Counter object to count all metadata values for a column\n+            # pos+1 so we skip the sample names list\n+            studycount[study_id][cat] = Counter(meta_vals[pos + 1])","path":"qiita_ware/search.py","position":49,"original_position":49,"commit_id":"99ea8ee2c4a47bb6f01a5ad57853d3b7e99241da","original_commit_id":"99ea8ee2c4a47bb6f01a5ad57853d3b7e99241da","user":{"login":"squirrelo","id":3079066,"avatar_url":"https://avatars.githubusercontent.com/u/3079066?v=3","gravatar_id":"","url":"https://api.github.com/users/squirrelo","html_url":"https://github.com/squirrelo","followers_url":"https://api.github.com/users/squirrelo/followers","following_url":"https://api.github.com/users/squirrelo/following{/other_user}","gists_url":"https://api.github.com/users/squirrelo/gists{/gist_id}","starred_url":"https://api.github.com/users/squirrelo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/squirrelo/subscriptions","organizations_url":"https://api.github.com/users/squirrelo/orgs","repos_url":"https://api.github.com/users/squirrelo/repos","events_url":"https://api.github.com/users/squirrelo/events{/privacy}","received_events_url":"https://api.github.com/users/squirrelo/received_events","type":"User","site_admin":false},"body":"sounds right, done","created_at":"2015-03-26T04:18:11Z","updated_at":"2015-03-26T04:18:11Z","html_url":"https://github.com/biocore/qiita/pull/1014#discussion_r27187583","pull_request_url":"https://api.github.com/repos/biocore/qiita/pulls/1014","_links":{"self":{"href":"https://api.github.com/repos/biocore/qiita/pulls/comments/27187583"},"html":{"href":"https://github.com/biocore/qiita/pull/1014#discussion_r27187583"},"pull_request":{"href":"https://api.github.com/repos/biocore/qiita/pulls/1014"}}},"pull_request":{"url":"https://api.github.com/repos/biocore/qiita/pulls/1014","id":31957841,"html_url":"https://github.com/biocore/qiita/pull/1014","diff_url":"https://github.com/biocore/qiita/pull/1014.diff","patch_url":"https://github.com/biocore/qiita/pull/1014.patch","issue_url":"https://api.github.com/repos/biocore/qiita/issues/1014","number":1014,"state":"open","locked":false,"title":"Search stopgap","user":{"login":"squirrelo","id":3079066,"avatar_url":"https://avatars.githubusercontent.com/u/3079066?v=3","gravatar_id":"","url":"https://api.github.com/users/squirrelo","html_url":"https://github.com/squirrelo","followers_url":"https://api.github.com/users/squirrelo/followers","following_url":"https://api.github.com/users/squirrelo/following{/other_user}","gists_url":"https://api.github.com/users/squirrelo/gists{/gist_id}","starred_url":"https://api.github.com/users/squirrelo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/squirrelo/subscriptions","organizations_url":"https://api.github.com/users/squirrelo/orgs","repos_url":"https://api.github.com/users/squirrelo/repos","events_url":"https://api.github.com/users/squirrelo/events{/privacy}","received_events_url":"https://api.github.com/users/squirrelo/received_events","type":"User","site_admin":false},"body":"This takes the current search engine output and formats it into what we expect the refactored search to spit out. This is needed because the processed data samples available may be a subset of the total samples available, and this needs to be reflected by the found samples in the search engine. This is also a stopgap because the search engine needs refactoring but there are database and logic changes blocking that, so this will sit on top for now to give us the output required until we can refactor the search engine.","created_at":"2015-03-25T19:35:20Z","updated_at":"2015-03-26T04:18:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"db5276ae4c772ca15fbc2b7ebd30f4aba685bf9b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/biocore/qiita/pulls/1014/commits","review_comments_url":"https://api.github.com/repos/biocore/qiita/pulls/1014/comments","review_comment_url":"https://api.github.com/repos/biocore/qiita/pulls/comments{/number}","comments_url":"https://api.github.com/repos/biocore/qiita/issues/1014/comments","statuses_url":"https://api.github.com/repos/biocore/qiita/statuses/99ea8ee2c4a47bb6f01a5ad57853d3b7e99241da","head":{"label":"squirrelo:search-stopgap","ref":"search-stopgap","sha":"99ea8ee2c4a47bb6f01a5ad57853d3b7e99241da","user":{"login":"squirrelo","id":3079066,"avatar_url":"https://avatars.githubusercontent.com/u/3079066?v=3","gravatar_id":"","url":"https://api.github.com/users/squirrelo","html_url":"https://github.com/squirrelo","followers_url":"https://api.github.com/users/squirrelo/followers","following_url":"https://api.github.com/users/squirrelo/following{/other_user}","gists_url":"https://api.github.com/users/squirrelo/gists{/gist_id}","starred_url":"https://api.github.com/users/squirrelo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/squirrelo/subscriptions","organizations_url":"https://api.github.com/users/squirrelo/orgs","repos_url":"https://api.github.com/users/squirrelo/repos","events_url":"https://api.github.com/users/squirrelo/events{/privacy}","received_events_url":"https://api.github.com/users/squirrelo/received_events","type":"User","site_admin":false},"repo":{"id":21153084,"name":"qiita","full_name":"squirrelo/qiita","owner":{"login":"squirrelo","id":3079066,"avatar_url":"https://avatars.githubusercontent.com/u/3079066?v=3","gravatar_id":"","url":"https://api.github.com/users/squirrelo","html_url":"https://github.com/squirrelo","followers_url":"https://api.github.com/users/squirrelo/followers","following_url":"https://api.github.com/users/squirrelo/following{/other_user}","gists_url":"https://api.github.com/users/squirrelo/gists{/gist_id}","starred_url":"https://api.github.com/users/squirrelo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/squirrelo/subscriptions","organizations_url":"https://api.github.com/users/squirrelo/orgs","repos_url":"https://api.github.com/users/squirrelo/repos","events_url":"https://api.github.com/users/squirrelo/events{/privacy}","received_events_url":"https://api.github.com/users/squirrelo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/squirrelo/qiita","description":"Qiita - A QIIME databasing effort","fork":true,"url":"https://api.github.com/repos/squirrelo/qiita","forks_url":"https://api.github.com/repos/squirrelo/qiita/forks","keys_url":"https://api.github.com/repos/squirrelo/qiita/keys{/key_id}","collaborators_url":"https://api.github.com/repos/squirrelo/qiita/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/squirrelo/qiita/teams","hooks_url":"https://api.github.com/repos/squirrelo/qiita/hooks","issue_events_url":"https://api.github.com/repos/squirrelo/qiita/issues/events{/number}","events_url":"https://api.github.com/repos/squirrelo/qiita/events","assignees_url":"https://api.github.com/repos/squirrelo/qiita/assignees{/user}","branches_url":"https://api.github.com/repos/squirrelo/qiita/branches{/branch}","tags_url":"https://api.github.com/repos/squirrelo/qiita/tags","blobs_url":"https://api.github.com/repos/squirrelo/qiita/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/squirrelo/qiita/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/squirrelo/qiita/git/refs{/sha}","trees_url":"https://api.github.com/repos/squirrelo/qiita/git/trees{/sha}","statuses_url":"https://api.github.com/repos/squirrelo/qiita/statuses/{sha}","languages_url":"https://api.github.com/repos/squirrelo/qiita/languages","stargazers_url":"https://api.github.com/repos/squirrelo/qiita/stargazers","contributors_url":"https://api.github.com/repos/squirrelo/qiita/contributors","subscribers_url":"https://api.github.com/repos/squirrelo/qiita/subscribers","subscription_url":"https://api.github.com/repos/squirrelo/qiita/subscription","commits_url":"https://api.github.com/repos/squirrelo/qiita/commits{/sha}","git_commits_url":"https://api.github.com/repos/squirrelo/qiita/git/commits{/sha}","comments_url":"https://api.github.com/repos/squirrelo/qiita/comments{/number}","issue_comment_url":"https://api.github.com/repos/squirrelo/qiita/issues/comments{/number}","contents_url":"https://api.github.com/repos/squirrelo/qiita/contents/{+path}","compare_url":"https://api.github.com/repos/squirrelo/qiita/compare/{base}...{head}","merges_url":"https://api.github.com/repos/squirrelo/qiita/merges","archive_url":"https://api.github.com/repos/squirrelo/qiita/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/squirrelo/qiita/downloads","issues_url":"https://api.github.com/repos/squirrelo/qiita/issues{/number}","pulls_url":"https://api.github.com/repos/squirrelo/qiita/pulls{/number}","milestones_url":"https://api.github.com/repos/squirrelo/qiita/milestones{/number}","notifications_url":"https://api.github.com/repos/squirrelo/qiita/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/squirrelo/qiita/labels{/name}","releases_url":"https://api.github.com/repos/squirrelo/qiita/releases{/id}","created_at":"2014-06-24T05:18:58Z","updated_at":"2015-03-25T16:14:07Z","pushed_at":"2015-03-26T04:11:49Z","git_url":"git://github.com/squirrelo/qiita.git","ssh_url":"git@github.com:squirrelo/qiita.git","clone_url":"https://github.com/squirrelo/qiita.git","svn_url":"https://github.com/squirrelo/qiita","homepage":"","size":17634,"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":"biocore:master","ref":"master","sha":"7a398ed0434314ca35a2c7b9b464b6283b8de880","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":13131245,"name":"qiita","full_name":"biocore/qiita","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/qiita","description":"Qiita - A QIIME databasing effort","fork":false,"url":"https://api.github.com/repos/biocore/qiita","forks_url":"https://api.github.com/repos/biocore/qiita/forks","keys_url":"https://api.github.com/repos/biocore/qiita/keys{/key_id}","collaborators_url":"https://api.github.com/repos/biocore/qiita/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/biocore/qiita/teams","hooks_url":"https://api.github.com/repos/biocore/qiita/hooks","issue_events_url":"https://api.github.com/repos/biocore/qiita/issues/events{/number}","events_url":"https://api.github.com/repos/biocore/qiita/events","assignees_url":"https://api.github.com/repos/biocore/qiita/assignees{/user}","branches_url":"https://api.github.com/repos/biocore/qiita/branches{/branch}","tags_url":"https://api.github.com/repos/biocore/qiita/tags","blobs_url":"https://api.github.com/repos/biocore/qiita/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/biocore/qiita/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/biocore/qiita/git/refs{/sha}","trees_url":"https://api.github.com/repos/biocore/qiita/git/trees{/sha}","statuses_url":"https://api.github.com/repos/biocore/qiita/statuses/{sha}","languages_url":"https://api.github.com/repos/biocore/qiita/languages","stargazers_url":"https://api.github.com/repos/biocore/qiita/stargazers","contributors_url":"https://api.github.com/repos/biocore/qiita/contributors","subscribers_url":"https://api.github.com/repos/biocore/qiita/subscribers","subscription_url":"https://api.github.com/repos/biocore/qiita/subscription","commits_url":"https://api.github.com/repos/biocore/qiita/commits{/sha}","git_commits_url":"https://api.github.com/repos/biocore/qiita/git/commits{/sha}","comments_url":"https://api.github.com/repos/biocore/qiita/comments{/number}","issue_comment_url":"https://api.github.com/repos/biocore/qiita/issues/comments{/number}","contents_url":"https://api.github.com/repos/biocore/qiita/contents/{+path}","compare_url":"https://api.github.com/repos/biocore/qiita/compare/{base}...{head}","merges_url":"https://api.github.com/repos/biocore/qiita/merges","archive_url":"https://api.github.com/repos/biocore/qiita/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/biocore/qiita/downloads","issues_url":"https://api.github.com/repos/biocore/qiita/issues{/number}","pulls_url":"https://api.github.com/repos/biocore/qiita/pulls{/number}","milestones_url":"https://api.github.com/repos/biocore/qiita/milestones{/number}","notifications_url":"https://api.github.com/repos/biocore/qiita/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/biocore/qiita/labels{/name}","releases_url":"https://api.github.com/repos/biocore/qiita/releases{/id}","created_at":"2013-09-26T18:50:43Z","updated_at":"2015-03-22T20:41:21Z","pushed_at":"2015-03-26T04:11:49Z","git_url":"git://github.com/biocore/qiita.git","ssh_url":"git@github.com:biocore/qiita.git","clone_url":"https://github.com/biocore/qiita.git","svn_url":"https://github.com/biocore/qiita","homepage":"","size":126562,"stargazers_count":14,"watchers_count":14,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"open_issues_count":197,"forks":17,"open_issues":197,"watchers":14,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/biocore/qiita/pulls/1014"},"html":{"href":"https://github.com/biocore/qiita/pull/1014"},"issue":{"href":"https://api.github.com/repos/biocore/qiita/issues/1014"},"comments":{"href":"https://api.github.com/repos/biocore/qiita/issues/1014/comments"},"review_comments":{"href":"https://api.github.com/repos/biocore/qiita/pulls/1014/comments"},"review_comment":{"href":"https://api.github.com/repos/biocore/qiita/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/biocore/qiita/pulls/1014/commits"},"statuses":{"href":"https://api.github.com/repos/biocore/qiita/statuses/99ea8ee2c4a47bb6f01a5ad57853d3b7e99241da"}}}}