{"action":"created","comment":{"url":"https://api.github.com/repos/biocore/qiita/pulls/comments/49739199","id":49739199,"diff_hunk":"@@ -6,52 +6,358 @@\n # The full license is in the file LICENSE, distributed with this software.\n # -----------------------------------------------------------------------------\n from __future__ import division\n+import warnings\n \n-from qiita_pet.handlers.api_proxy.util import check_access\n+from os import remove\n+from natsort import natsorted\n+\n+from qiita_core.util import execute_as_transaction\n+from qiita_pet.handlers.api_proxy.util import check_access, check_fp\n+from qiita_db.metadata_template.util import load_template_to_dataframe\n+from qiita_db.util import convert_to_id\n from qiita_db.study import Study\n+from qiita_db.ontology import Ontology\n+from qiita_db.metadata_template.prep_template import PrepTemplate\n \n \n-def prep_template_get_req(study_id, user_id):\n-    \"\"\"Gives a summary of each prep template attached to the study\n+@execute_as_transaction\n+def _process_investigation_type(inv_type, user_def_type, new_type):\n+    \"\"\"Return the investigation_type and add it to the ontology if needed\n \n     Parameters\n     ----------\n-    study_id : int\n-        Study id to get prep template info for\n+    inv_type : str\n+        The investigation type\n+    user_def_type : str\n+        The user-defined investigation type\n+    new_type : str\n+        The new user-defined investigation_type\n+\n+    Returns\n+    -------\n+    str\n+        The investigation type chosen by the user\n+    \"\"\"\n+    if inv_type == '':\n+        inv_type = None\n+    elif inv_type == 'Other' and user_def_type == 'New Type':\n+        # This is a nre user defined investigation type so store it\n+        inv_type = new_type\n+        ontology = Ontology(convert_to_id('ENA', 'ontology'))\n+        ontology.add_user_defined_term(inv_type)\n+    elif inv_type == 'Other' and user_def_type != 'New Type':\n+        inv_type = user_def_type\n+    return inv_type\n+\n+\n+def prep_template_get_req(prep_id, user_id):\n+    \"\"\"Gets the json of the full prep template\n+\n+    Parameters\n+    ----------\n+    prep_id : int\n+        PrepTemplate id to get info for\n+    user_id : str\n+        User requesting the sample template info\n+\n+    Returns\n+    -------\n+    dict of dictionaries\n+        Dictionary object where the keys are the metadata samples\n+        and the values are a dictionary of column and value.\n+        Format {sample: {column: value, ...}, ...}\n+    \"\"\"\n+    prep = PrepTemplate(int(prep_id))\n+    access_error = check_access(prep.study_id, user_id)\n+    if access_error:\n+        return access_error\n+    df = prep.to_dataframe()\n+    return {'status': 'success',\n+            'message': '',\n+            'template': df.to_dict(orient='index')}\n+\n+\n+def prep_template_summary_get_req(prep_id, user_id):\n+    \"\"\"Get the summarized prep template data for each metadata column\n+\n+    Parameters\n+    ----------\n+    prep_id : int\n+        PrepTemplate id to get info for\n     user_id : str\n-        User id requesting the prep templates\n+        User requesting the sample template info\n \n     Returns\n     -------\n-    dict\n-        Prep template information in the form\n-        {'status': status,\n-         'message': msg,\n-         'info': dict of list of dict}\n-        status can be success, warning, or error depending on result\n-        message has the warnings or errors\n-        info contains prep template information seperated by data type, in the\n-        form {data_type: [{prep 1 info dict}, ....], ...}\n+    dict of objects\n+        Dictionary object where the keys are the metadata categories\n+        and the values are list of tuples. Each tuple is an observed value in\n+        the category and the number of times its seen.\n+        Format {status: status,\n+                message: message,\n+                num_samples: value,\n+                category: [(val1, count1), (val2, count2), ...], ...}\n+    \"\"\"\n+    prep = PrepTemplate(int(prep_id))\n+    access_error = check_access(prep.study_id, user_id)\n+    if access_error:\n+        return access_error\n+    df = prep.to_dataframe()\n+    out = {'num_samples': df.shape[0],\n+           'summary': {}}\n+\n+    # drop the prep_id column if it exists\n+    if 'study_id' in df.columns:","path":"qiita_pet/handlers/api_proxy/prep_template.py","position":120,"original_position":120,"commit_id":"27ef422836ed1c3f870381085b43b40b4a324d6f","original_commit_id":"27ef422836ed1c3f870381085b43b40b4a324d6f","user":{"login":"antgonza","id":2014559,"avatar_url":"https://avatars.githubusercontent.com/u/2014559?v=3","gravatar_id":"","url":"https://api.github.com/users/antgonza","html_url":"https://github.com/antgonza","followers_url":"https://api.github.com/users/antgonza/followers","following_url":"https://api.github.com/users/antgonza/following{/other_user}","gists_url":"https://api.github.com/users/antgonza/gists{/gist_id}","starred_url":"https://api.github.com/users/antgonza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antgonza/subscriptions","organizations_url":"https://api.github.com/users/antgonza/orgs","repos_url":"https://api.github.com/users/antgonza/repos","events_url":"https://api.github.com/users/antgonza/events{/privacy}","received_events_url":"https://api.github.com/users/antgonza/received_events","type":"User","site_admin":false},"body":"This is not tested. ","created_at":"2016-01-14T15:26:28Z","updated_at":"2016-01-14T15:26:28Z","html_url":"https://github.com/biocore/qiita/pull/1583#discussion_r49739199","pull_request_url":"https://api.github.com/repos/biocore/qiita/pulls/1583","_links":{"self":{"href":"https://api.github.com/repos/biocore/qiita/pulls/comments/49739199"},"html":{"href":"https://github.com/biocore/qiita/pull/1583#discussion_r49739199"},"pull_request":{"href":"https://api.github.com/repos/biocore/qiita/pulls/1583"}}},"pull_request":{"url":"https://api.github.com/repos/biocore/qiita/pulls/1583","id":54214423,"html_url":"https://github.com/biocore/qiita/pull/1583","diff_url":"https://github.com/biocore/qiita/pull/1583.diff","patch_url":"https://github.com/biocore/qiita/pull/1583.patch","issue_url":"https://api.github.com/repos/biocore/qiita/issues/1583","number":1583,"state":"open","locked":false,"title":"Study prep","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":"Requires #1582 \r\n\r\nAdds the prep template information and graphs to the study page.\r\n\r\nStill needs the `Artifact(id).to_html()` #1576  and `PrepTemplate(id).last_artifact` #1573 to be completed.","created_at":"2015-12-21T01:56:26Z","updated_at":"2016-01-14T15:26:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4d80412eaeb161598b7bebdf4589c6486a8178c4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/biocore/qiita/pulls/1583/commits","review_comments_url":"https://api.github.com/repos/biocore/qiita/pulls/1583/comments","review_comment_url":"https://api.github.com/repos/biocore/qiita/pulls/comments{/number}","comments_url":"https://api.github.com/repos/biocore/qiita/issues/1583/comments","statuses_url":"https://api.github.com/repos/biocore/qiita/statuses/27ef422836ed1c3f870381085b43b40b4a324d6f","head":{"label":"squirrelo:study-prep","ref":"study-prep","sha":"27ef422836ed1c3f870381085b43b40b4a324d6f","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-05-06T16:22:32Z","pushed_at":"2016-01-13T23:41:14Z","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":22199,"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":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"biocore:artifact-study-pages","ref":"artifact-study-pages","sha":"e4694aa1e106dd614f3d3855e72fc37688adeeec","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":"2016-01-13T22:31:01Z","pushed_at":"2016-01-13T23:41:15Z","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":"http://qiita.microbio.me","size":129061,"stargazers_count":25,"watchers_count":25,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":25,"mirror_url":null,"open_issues_count":327,"forks":25,"open_issues":327,"watchers":25,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/biocore/qiita/pulls/1583"},"html":{"href":"https://github.com/biocore/qiita/pull/1583"},"issue":{"href":"https://api.github.com/repos/biocore/qiita/issues/1583"},"comments":{"href":"https://api.github.com/repos/biocore/qiita/issues/1583/comments"},"review_comments":{"href":"https://api.github.com/repos/biocore/qiita/pulls/1583/comments"},"review_comment":{"href":"https://api.github.com/repos/biocore/qiita/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/biocore/qiita/pulls/1583/commits"},"statuses":{"href":"https://api.github.com/repos/biocore/qiita/statuses/27ef422836ed1c3f870381085b43b40b4a324d6f"}}}}