{"action":"created","comment":{"url":"https://api.github.com/repos/biocore/qiita/pulls/comments/41317447","id":41317447,"diff_hunk":"@@ -1325,3 +1326,78 @@ def check_restrictions(self, restrictions):\n                 for col in restriction.columns}\n \n         return cols.difference(self.categories())\n+\n+    def _get_accession_numbers(self, column):\n+        \"\"\"Return the accession numbers stored under the given column\n+\n+        Parameters\n+        ----------\n+        column : str\n+            The column name where the accession number is stored\n+\n+        Returns\n+        -------\n+        dict of {str: str}\n+            The accession numbers keyed by sample id\n+        \"\"\"\n+        with TRN:\n+            sql = \"\"\"SELECT sample_id, {0}\n+                     FROM qiita.{1}\n+                     WHERE {2}=%s\"\"\".format(column, self._table,\n+                                            self._id_column)\n+            TRN.add(sql, [self.id])\n+            result = {sample_id: accession\n+                      for sample_id, accession in TRN.execute_fetchindex()}\n+        return result\n+\n+    def _update_accession_numbers(self, column, values):\n+        \"\"\"Update the accession numbers stored under the given column\n+\n+        Parameters\n+        ----------\n+        column : str\n+            The column name where the accession number is stored\n+        values : dict of {str: str}\n+            The accession numbers keyed by sample id\n+\n+        Raises\n+        ------\n+        QiitaDBError\n+            If values tries to change the accession number of a sample that\n+            already has an assigned accession number\n+        \"\"\"\n+        with TRN:\n+            sql = \"\"\"SELECT sample_id, {0}\n+                     FROM qiita.{1}\n+                     WHERE {2}=%s\n+                        AND {0} IS NOT NULL\"\"\".format(column, self._table,\n+                                                      self._id_column)\n+            TRN.add(sql, [self.id])\n+            db_vals = {sample_id: accession\n+                       for sample_id, accession in TRN.execute_fetchindex()}\n+            common_samples = set(db_vals) & set(values)\n+            diff = [sample for sample in common_samples\n+                    if db_vals[sample] != values[sample]]\n+            if diff:\n+                raise QiitaDBError(\n+                    \"The following samples already have an accession number: \"\n+                    \"%s\" % ', '.join(diff))\n+\n+            # Remove the common samples form the values dictionary\n+            values = deepcopy(values)\n+            for sample in common_samples:\n+                del values[sample]\n+\n+            if values:\n+                sql_vals = ', '.join(\n+                    [\"('%s', '%s')\" % (k, v) for k, v in viewitems(values)])","path":"qiita_db/metadata_template/base_metadata_template.py","position":76,"original_position":76,"commit_id":"0116e5562f619ef93db6fab1a3cee40933664d5b","original_commit_id":"0116e5562f619ef93db6fab1a3cee40933664d5b","user":{"login":"josenavas","id":2501478,"avatar_url":"https://avatars.githubusercontent.com/u/2501478?v=3","gravatar_id":"","url":"https://api.github.com/users/josenavas","html_url":"https://github.com/josenavas","followers_url":"https://api.github.com/users/josenavas/followers","following_url":"https://api.github.com/users/josenavas/following{/other_user}","gists_url":"https://api.github.com/users/josenavas/gists{/gist_id}","starred_url":"https://api.github.com/users/josenavas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josenavas/subscriptions","organizations_url":"https://api.github.com/users/josenavas/orgs","repos_url":"https://api.github.com/users/josenavas/repos","events_url":"https://api.github.com/users/josenavas/events{/privacy}","received_events_url":"https://api.github.com/users/josenavas/received_events","type":"User","site_admin":false},"body":"excellent point! changed!\r\n","created_at":"2015-10-06T20:28:51Z","updated_at":"2015-10-06T20:28:51Z","html_url":"https://github.com/biocore/qiita/pull/1481#discussion_r41317447","pull_request_url":"https://api.github.com/repos/biocore/qiita/pulls/1481","_links":{"self":{"href":"https://api.github.com/repos/biocore/qiita/pulls/comments/41317447"},"html":{"href":"https://github.com/biocore/qiita/pull/1481#discussion_r41317447"},"pull_request":{"href":"https://api.github.com/repos/biocore/qiita/pulls/1481"}}},"pull_request":{"url":"https://api.github.com/repos/biocore/qiita/pulls/1481","id":45820626,"html_url":"https://github.com/biocore/qiita/pull/1481","diff_url":"https://github.com/biocore/qiita/pull/1481.diff","patch_url":"https://github.com/biocore/qiita/pull/1481.patch","issue_url":"https://api.github.com/repos/biocore/qiita/issues/1481","number":1481,"state":"open","locked":false,"title":"WIP: DB changes for EBI","user":{"login":"josenavas","id":2501478,"avatar_url":"https://avatars.githubusercontent.com/u/2501478?v=3","gravatar_id":"","url":"https://api.github.com/users/josenavas","html_url":"https://github.com/josenavas","followers_url":"https://api.github.com/users/josenavas/followers","following_url":"https://api.github.com/users/josenavas/following{/other_user}","gists_url":"https://api.github.com/users/josenavas/gists{/gist_id}","starred_url":"https://api.github.com/users/josenavas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josenavas/subscriptions","organizations_url":"https://api.github.com/users/josenavas/orgs","repos_url":"https://api.github.com/users/josenavas/repos","events_url":"https://api.github.com/users/josenavas/events{/privacy}","received_events_url":"https://api.github.com/users/josenavas/received_events","type":"User","site_admin":false},"body":"This PR modifies the DB to store all the information that EBI returns when we are doing a submission.\r\nStoring all this information (in the correct place) will help us to do a better usage of the EBI structure (which actually fits pretty nicely with our structure) as well as being able to do EBI updates in the future.\r\n\r\nTests are currently failing, and I'm fixing them right now.","created_at":"2015-09-23T19:27:10Z","updated_at":"2015-10-06T20:28:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e0132d413fd3d87ce87f27f137609e7020304c0d","assignee":null,"milestone":{"url":"https://api.github.com/repos/biocore/qiita/milestones/10","html_url":"https://github.com/biocore/qiita/milestones/Alpha%200.3","labels_url":"https://api.github.com/repos/biocore/qiita/milestones/10/labels","id":1093698,"number":10,"title":"Alpha 0.3","description":"","creator":{"login":"josenavas","id":2501478,"avatar_url":"https://avatars.githubusercontent.com/u/2501478?v=3","gravatar_id":"","url":"https://api.github.com/users/josenavas","html_url":"https://github.com/josenavas","followers_url":"https://api.github.com/users/josenavas/followers","following_url":"https://api.github.com/users/josenavas/following{/other_user}","gists_url":"https://api.github.com/users/josenavas/gists{/gist_id}","starred_url":"https://api.github.com/users/josenavas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josenavas/subscriptions","organizations_url":"https://api.github.com/users/josenavas/orgs","repos_url":"https://api.github.com/users/josenavas/repos","events_url":"https://api.github.com/users/josenavas/events{/privacy}","received_events_url":"https://api.github.com/users/josenavas/received_events","type":"User","site_admin":false},"open_issues":130,"closed_issues":10,"state":"open","created_at":"2015-05-02T23:05:42Z","updated_at":"2015-10-05T22:34:30Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/biocore/qiita/pulls/1481/commits","review_comments_url":"https://api.github.com/repos/biocore/qiita/pulls/1481/comments","review_comment_url":"https://api.github.com/repos/biocore/qiita/pulls/comments{/number}","comments_url":"https://api.github.com/repos/biocore/qiita/issues/1481/comments","statuses_url":"https://api.github.com/repos/biocore/qiita/statuses/0116e5562f619ef93db6fab1a3cee40933664d5b","head":{"label":"josenavas:db-changes-ebi","ref":"db-changes-ebi","sha":"0116e5562f619ef93db6fab1a3cee40933664d5b","user":{"login":"josenavas","id":2501478,"avatar_url":"https://avatars.githubusercontent.com/u/2501478?v=3","gravatar_id":"","url":"https://api.github.com/users/josenavas","html_url":"https://github.com/josenavas","followers_url":"https://api.github.com/users/josenavas/followers","following_url":"https://api.github.com/users/josenavas/following{/other_user}","gists_url":"https://api.github.com/users/josenavas/gists{/gist_id}","starred_url":"https://api.github.com/users/josenavas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josenavas/subscriptions","organizations_url":"https://api.github.com/users/josenavas/orgs","repos_url":"https://api.github.com/users/josenavas/repos","events_url":"https://api.github.com/users/josenavas/events{/privacy}","received_events_url":"https://api.github.com/users/josenavas/received_events","type":"User","site_admin":false},"repo":{"id":13527677,"name":"QiiTa","full_name":"josenavas/QiiTa","owner":{"login":"josenavas","id":2501478,"avatar_url":"https://avatars.githubusercontent.com/u/2501478?v=3","gravatar_id":"","url":"https://api.github.com/users/josenavas","html_url":"https://github.com/josenavas","followers_url":"https://api.github.com/users/josenavas/followers","following_url":"https://api.github.com/users/josenavas/following{/other_user}","gists_url":"https://api.github.com/users/josenavas/gists{/gist_id}","starred_url":"https://api.github.com/users/josenavas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josenavas/subscriptions","organizations_url":"https://api.github.com/users/josenavas/orgs","repos_url":"https://api.github.com/users/josenavas/repos","events_url":"https://api.github.com/users/josenavas/events{/privacy}","received_events_url":"https://api.github.com/users/josenavas/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/josenavas/QiiTa","description":"QiiTa databasing effort","fork":true,"url":"https://api.github.com/repos/josenavas/QiiTa","forks_url":"https://api.github.com/repos/josenavas/QiiTa/forks","keys_url":"https://api.github.com/repos/josenavas/QiiTa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/josenavas/QiiTa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/josenavas/QiiTa/teams","hooks_url":"https://api.github.com/repos/josenavas/QiiTa/hooks","issue_events_url":"https://api.github.com/repos/josenavas/QiiTa/issues/events{/number}","events_url":"https://api.github.com/repos/josenavas/QiiTa/events","assignees_url":"https://api.github.com/repos/josenavas/QiiTa/assignees{/user}","branches_url":"https://api.github.com/repos/josenavas/QiiTa/branches{/branch}","tags_url":"https://api.github.com/repos/josenavas/QiiTa/tags","blobs_url":"https://api.github.com/repos/josenavas/QiiTa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/josenavas/QiiTa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/josenavas/QiiTa/git/refs{/sha}","trees_url":"https://api.github.com/repos/josenavas/QiiTa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/josenavas/QiiTa/statuses/{sha}","languages_url":"https://api.github.com/repos/josenavas/QiiTa/languages","stargazers_url":"https://api.github.com/repos/josenavas/QiiTa/stargazers","contributors_url":"https://api.github.com/repos/josenavas/QiiTa/contributors","subscribers_url":"https://api.github.com/repos/josenavas/QiiTa/subscribers","subscription_url":"https://api.github.com/repos/josenavas/QiiTa/subscription","commits_url":"https://api.github.com/repos/josenavas/QiiTa/commits{/sha}","git_commits_url":"https://api.github.com/repos/josenavas/QiiTa/git/commits{/sha}","comments_url":"https://api.github.com/repos/josenavas/QiiTa/comments{/number}","issue_comment_url":"https://api.github.com/repos/josenavas/QiiTa/issues/comments{/number}","contents_url":"https://api.github.com/repos/josenavas/QiiTa/contents/{+path}","compare_url":"https://api.github.com/repos/josenavas/QiiTa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/josenavas/QiiTa/merges","archive_url":"https://api.github.com/repos/josenavas/QiiTa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/josenavas/QiiTa/downloads","issues_url":"https://api.github.com/repos/josenavas/QiiTa/issues{/number}","pulls_url":"https://api.github.com/repos/josenavas/QiiTa/pulls{/number}","milestones_url":"https://api.github.com/repos/josenavas/QiiTa/milestones{/number}","notifications_url":"https://api.github.com/repos/josenavas/QiiTa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/josenavas/QiiTa/labels{/name}","releases_url":"https://api.github.com/repos/josenavas/QiiTa/releases{/id}","created_at":"2013-10-12T19:29:32Z","updated_at":"2015-05-05T22:50:05Z","pushed_at":"2015-10-05T17:12:50Z","git_url":"git://github.com/josenavas/QiiTa.git","ssh_url":"git@github.com:josenavas/QiiTa.git","clone_url":"https://github.com/josenavas/QiiTa.git","svn_url":"https://github.com/josenavas/QiiTa","homepage":null,"size":129331,"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:ebi-improvements","ref":"ebi-improvements","sha":"3ff52c5e4d95f97c99e6cf9b20efef7f5e0b6d44","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-09-20T19:09:27Z","pushed_at":"2015-10-06T19:39:53Z","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":132756,"stargazers_count":24,"watchers_count":24,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":24,"mirror_url":null,"open_issues_count":318,"forks":24,"open_issues":318,"watchers":24,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/biocore/qiita/pulls/1481"},"html":{"href":"https://github.com/biocore/qiita/pull/1481"},"issue":{"href":"https://api.github.com/repos/biocore/qiita/issues/1481"},"comments":{"href":"https://api.github.com/repos/biocore/qiita/issues/1481/comments"},"review_comments":{"href":"https://api.github.com/repos/biocore/qiita/pulls/1481/comments"},"review_comment":{"href":"https://api.github.com/repos/biocore/qiita/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/biocore/qiita/pulls/1481/commits"},"statuses":{"href":"https://api.github.com/repos/biocore/qiita/statuses/0116e5562f619ef93db6fab1a3cee40933664d5b"}}}}