{"action":"created","comment":{"url":"https://api.github.com/repos/biocore/qiita/pulls/comments/24457507","id":24457507,"diff_hunk":"@@ -308,6 +329,65 @@ def create(cls, filetype, studies, filepaths=None):\n \n         return rd\n \n+    @classmethod\n+    def delete(cls, raw_data_id, study_id):\n+        \"\"\"Removes the raw data with id raw_data_id\n+\n+        Parameters\n+        ----------\n+        raw_data_id : int\n+            The raw data id\n+        study_id : int\n+            The study id\n+\n+        Raises\n+        ------\n+        ValueError\n+            If the raw data id doesn't exist\n+            If the raw data is not linked to that study_id\n+            If the raw data has prep templates associated\n+        \"\"\"\n+        conn_handler = SQLConnectionHandler()\n+\n+        # check if the raw data exist\n+        if not cls.exists(raw_data_id):\n+            raise ValueError(\"Raw data: %s doesn't exist.\" % str(raw_data_id))\n+\n+        study_raw_data_exists = conn_handler.execute_fetchone(\n+            \"SELECT EXISTS(SELECT * FROM qiita.study_raw_data WHERE \"\n+            \"study_id = {0} AND raw_data_id = {1})\".format(study_id,\n+                                                           raw_data_id))[0]\n+        if not study_raw_data_exists:\n+            raise ValueError(\n+                \"Raw data %s is not linked to study %s\" % (raw_data_id,\n+                                                           study_id))\n+\n+        # check if there are any prep templates\n+        prep_template_count = conn_handler.execute_fetchone(\n+            \"SELECT COUNT(*) FROM qiita.prep_template WHERE \"\n+            \"raw_data_id = {0}\".format(raw_data_id))[0]\n+\n+        if (prep_template_count > 0):\n+            raise ValueError(\"Raw data: %s, has %d prep templates associated \"","path":"qiita_db/data.py","position":71,"original_position":71,"commit_id":"1a035d5a71581000406148baa1e841bc289db2f4","original_commit_id":"1a035d5a71581000406148baa1e841bc289db2f4","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":"ok","created_at":"2015-02-10T22:29:39Z","updated_at":"2015-02-10T22:29:39Z","html_url":"https://github.com/biocore/qiita/pull/842#discussion_r24457507","pull_request_url":"https://api.github.com/repos/biocore/qiita/pulls/842","_links":{"self":{"href":"https://api.github.com/repos/biocore/qiita/pulls/comments/24457507"},"html":{"href":"https://github.com/biocore/qiita/pull/842#discussion_r24457507"},"pull_request":{"href":"https://api.github.com/repos/biocore/qiita/pulls/842"}}},"pull_request":{"url":"https://api.github.com/repos/biocore/qiita/pulls/842","id":29033334,"html_url":"https://github.com/biocore/qiita/pull/842","diff_url":"https://github.com/biocore/qiita/pull/842.diff","patch_url":"https://github.com/biocore/qiita/pull/842.patch","issue_url":"https://api.github.com/repos/biocore/qiita/issues/842","number":842,"state":"open","locked":false,"title":"deletes raw data","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":"Add the possibility of removing raw data. Raw data can only be removed if there are not prep templates added, this functionality will be in another PR. There are 2 delete levels: if there is more studies link to the raw data, only the study_raw_data connection is removed, and if the raw data is the last one, it will remove all connections.\r\n\r\nThis also adds the exists method at the BaseData level. ","created_at":"2015-02-10T18:48:05Z","updated_at":"2015-02-10T22:29:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"21c6a67abf4493949e16dccd6ff9f411b5e0a653","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/biocore/qiita/pulls/842/commits","review_comments_url":"https://api.github.com/repos/biocore/qiita/pulls/842/comments","review_comment_url":"https://api.github.com/repos/biocore/qiita/pulls/comments/{number}","comments_url":"https://api.github.com/repos/biocore/qiita/issues/842/comments","statuses_url":"https://api.github.com/repos/biocore/qiita/statuses/1a035d5a71581000406148baa1e841bc289db2f4","head":{"label":"antgonza:delete-raw-data","ref":"delete-raw-data","sha":"1a035d5a71581000406148baa1e841bc289db2f4","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},"repo":{"id":16964638,"name":"qiita","full_name":"antgonza/qiita","owner":{"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},"private":false,"html_url":"https://github.com/antgonza/qiita","description":"Qiita - A QIIME databasing effort","fork":true,"url":"https://api.github.com/repos/antgonza/qiita","forks_url":"https://api.github.com/repos/antgonza/qiita/forks","keys_url":"https://api.github.com/repos/antgonza/qiita/keys{/key_id}","collaborators_url":"https://api.github.com/repos/antgonza/qiita/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/antgonza/qiita/teams","hooks_url":"https://api.github.com/repos/antgonza/qiita/hooks","issue_events_url":"https://api.github.com/repos/antgonza/qiita/issues/events{/number}","events_url":"https://api.github.com/repos/antgonza/qiita/events","assignees_url":"https://api.github.com/repos/antgonza/qiita/assignees{/user}","branches_url":"https://api.github.com/repos/antgonza/qiita/branches{/branch}","tags_url":"https://api.github.com/repos/antgonza/qiita/tags","blobs_url":"https://api.github.com/repos/antgonza/qiita/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/antgonza/qiita/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/antgonza/qiita/git/refs{/sha}","trees_url":"https://api.github.com/repos/antgonza/qiita/git/trees{/sha}","statuses_url":"https://api.github.com/repos/antgonza/qiita/statuses/{sha}","languages_url":"https://api.github.com/repos/antgonza/qiita/languages","stargazers_url":"https://api.github.com/repos/antgonza/qiita/stargazers","contributors_url":"https://api.github.com/repos/antgonza/qiita/contributors","subscribers_url":"https://api.github.com/repos/antgonza/qiita/subscribers","subscription_url":"https://api.github.com/repos/antgonza/qiita/subscription","commits_url":"https://api.github.com/repos/antgonza/qiita/commits{/sha}","git_commits_url":"https://api.github.com/repos/antgonza/qiita/git/commits{/sha}","comments_url":"https://api.github.com/repos/antgonza/qiita/comments{/number}","issue_comment_url":"https://api.github.com/repos/antgonza/qiita/issues/comments/{number}","contents_url":"https://api.github.com/repos/antgonza/qiita/contents/{+path}","compare_url":"https://api.github.com/repos/antgonza/qiita/compare/{base}...{head}","merges_url":"https://api.github.com/repos/antgonza/qiita/merges","archive_url":"https://api.github.com/repos/antgonza/qiita/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/antgonza/qiita/downloads","issues_url":"https://api.github.com/repos/antgonza/qiita/issues{/number}","pulls_url":"https://api.github.com/repos/antgonza/qiita/pulls{/number}","milestones_url":"https://api.github.com/repos/antgonza/qiita/milestones{/number}","notifications_url":"https://api.github.com/repos/antgonza/qiita/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/antgonza/qiita/labels{/name}","releases_url":"https://api.github.com/repos/antgonza/qiita/releases{/id}","created_at":"2014-02-18T21:38:48Z","updated_at":"2015-02-10T11:51:28Z","pushed_at":"2015-02-10T18:45:30Z","git_url":"git://github.com/antgonza/qiita.git","ssh_url":"git@github.com:antgonza/qiita.git","clone_url":"https://github.com/antgonza/qiita.git","svn_url":"https://github.com/antgonza/qiita","homepage":"","size":115175,"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":"8a791a30972f111331a09a2466148fde66f13b98","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-02-10T22:05:07Z","pushed_at":"2015-02-10T22:05:06Z","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":117505,"stargazers_count":13,"watchers_count":13,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":182,"forks":13,"open_issues":182,"watchers":13,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/biocore/qiita/pulls/842"},"html":{"href":"https://github.com/biocore/qiita/pull/842"},"issue":{"href":"https://api.github.com/repos/biocore/qiita/issues/842"},"comments":{"href":"https://api.github.com/repos/biocore/qiita/issues/842/comments"},"review_comments":{"href":"https://api.github.com/repos/biocore/qiita/pulls/842/comments"},"review_comment":{"href":"https://api.github.com/repos/biocore/qiita/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/biocore/qiita/pulls/842/commits"},"statuses":{"href":"https://api.github.com/repos/biocore/qiita/statuses/1a035d5a71581000406148baa1e841bc289db2f4"}}}}