{"action":"created","comment":{"url":"https://api.github.com/repos/biocore/labadmin/pulls/comments/80382798","id":80382798,"diff_hunk":"@@ -2415,6 +2415,144 @@ def set_deposited_ebi(self):\n                  WHERE barcode IN %s\"\"\"\n         self._con.execute(sql, [barcodes])\n \n+    def create_study(self, study_id, title=None, alias=None, notes=None):\n+        \"\"\"Creates a study\n+\n+        Parameters\n+        ----------\n+        study_id : int\n+            Positive if it is a Qiita study ID, negative if others\n+        title : str\n+        alias : str\n+        notes : str\n+\n+        Returns\n+        -------\n+        bool\n+            True if successful\n+\n+        Raises\n+        ------\n+        ValueError\n+            If there is error creating the study\n+        \"\"\"\n+        with self._con.cursor() as cur:\n+            cur.execute('BEGIN')\n+            sql = \"\"\"SELECT study_id, title FROM pm.study WHERE study_id = %s\n+                     OR title = %s\"\"\"\n+            sql_args = [study_id, title or None]\n+            qry = self._con.execute_fetchone(sql, sql_args)\n+            if qry is not None:\n+                raise ValueError('Study ID or title conflicts with exisiting '\n+                                 'study %s: %s.' % (qry[0], qry[1]))\n+            sql = \"\"\"INSERT INTO pm.study (study_id, title, alias, notes)\n+                     VALUES (%s, %s, %s, %s) RETURNING study_id\"\"\"\n+            sql_args = [study_id, title or None, alias or None, notes or None]\n+            if self._con.execute_fetchone(sql, sql_args) is None:\n+                raise ValueError('Creation of study %s failed.' % study_id)\n+            cur.execute('COMMIT')\n+        return True\n+\n+    def edit_study(self, study_id, title=None, alias=None, notes=None):\n+        \"\"\"Edits properties of an existing study\n+\n+        Parameters\n+        ----------\n+        study_id : int\n+        title : str\n+        alias : str\n+        notes : str\n+\n+        Returns\n+        -------\n+        bool\n+            True if successful\n+\n+        Raises\n+        ------\n+        ValueError\n+            If there is error editing the study's properties\n+        \"\"\"\n+        with self._con.cursor() as cur:\n+            cur.execute('BEGIN')\n+            sql = \"\"\"SELECT * FROM pm.study WHERE study_id = %s LIMIT 1\"\"\"\n+            sql_args = [study_id]\n+            if self._con.execute_fetchone(sql, sql_args) is None:\n+                raise ValueError('Study ID %s does not exist.' % study_id)\n+            if title:\n+                sql = \"\"\"SELECT study_id FROM pm.study WHERE study_id <> %s\n+                         AND title = %s LIMIT 1\"\"\"\n+                sql_args = [study_id, title]\n+                qry = self._con.execute_fetchone(sql, sql_args)\n+                if qry is not None:\n+                    raise ValueError('Study title \"%s\" conflicts with another '\n+                                     'study: %s.' % (title, qry[0]))\n+            sql = \"\"\"UPDATE pm.study SET title = %s, alias = %s, notes = %s\n+                     WHERE study_id = %s RETURNING study_id\"\"\"\n+            sql_args = [title or None, alias or None, notes or None, study_id]\n+            if self._con.execute_fetchone(sql, sql_args) is None:\n+                raise ValueError('Editing study %s failed.' % study_id)\n+            cur.execute('COMMIT')\n+        return True\n+\n+    def read_study(self, study_id):\n+        \"\"\"Read properties of an existing study\n+\n+        Parameters\n+        ----------\n+        study_id : int\n+\n+        Returns\n+        -------\n+        dict\n+            {title : str, alias : str, notes : str}\n+\n+        Raises\n+        ------\n+        ValueError\n+            If there is error reading the study's properties\n+        \"\"\"\n+        with self._con.cursor() as cur:\n+            cur.execute('BEGIN')\n+            sql = \"\"\"SELECT title, alias, notes FROM pm.study\n+                     WHERE study_id = %s LIMIT 1\"\"\"\n+            sql_args = [study_id]\n+            qry = self._con.execute_fetchone(sql, sql_args)\n+            if qry is None:\n+                raise ValueError('Study ID %s does not exist.' % study_id)\n+            cur.execute('COMMIT')\n+        return {'title': qry[0], 'alias': qry[1], 'notes': qry[2]}\n+\n+    def delete_study(self, study_id):\n+        \"\"\"Deletes an existing study\n+\n+        Parameters\n+        ----------\n+        study_id : int\n+\n+        Returns\n+        -------\n+        bool\n+            True if successful\n+\n+        Raises\n+        ------\n+        ValueError\n+            If there is error deleting the study\n+        \"\"\"\n+        with self._con.cursor() as cur:\n+            cur.execute('BEGIN')","path":"knimin/lib/data_access.py","position":148,"original_position":148,"commit_id":"772a9ab148e9deb539257e2eb43019db1232ca43","original_commit_id":"772a9ab148e9deb539257e2eb43019db1232ca43","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":"Also take advantage of the exists method. ","created_at":"2016-09-25T14:03:35Z","updated_at":"2016-09-25T14:03:35Z","html_url":"https://github.com/biocore/labadmin/pull/99#discussion_r80382798","pull_request_url":"https://api.github.com/repos/biocore/labadmin/pulls/99","_links":{"self":{"href":"https://api.github.com/repos/biocore/labadmin/pulls/comments/80382798"},"html":{"href":"https://github.com/biocore/labadmin/pull/99#discussion_r80382798"},"pull_request":{"href":"https://api.github.com/repos/biocore/labadmin/pulls/99"}}},"pull_request":{"url":"https://api.github.com/repos/biocore/labadmin/pulls/99","id":85517952,"html_url":"https://github.com/biocore/labadmin/pull/99","diff_url":"https://github.com/biocore/labadmin/pull/99.diff","patch_url":"https://github.com/biocore/labadmin/pull/99.patch","issue_url":"https://api.github.com/repos/biocore/labadmin/issues/99","number":99,"state":"open","locked":false,"title":"Plate mapper kiwi checkpoint","user":{"login":"qiyunzhu","id":4396343,"avatar_url":"https://avatars.githubusercontent.com/u/4396343?v=3","gravatar_id":"","url":"https://api.github.com/users/qiyunzhu","html_url":"https://github.com/qiyunzhu","followers_url":"https://api.github.com/users/qiyunzhu/followers","following_url":"https://api.github.com/users/qiyunzhu/following{/other_user}","gists_url":"https://api.github.com/users/qiyunzhu/gists{/gist_id}","starred_url":"https://api.github.com/users/qiyunzhu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qiyunzhu/subscriptions","organizations_url":"https://api.github.com/users/qiyunzhu/orgs","repos_url":"https://api.github.com/users/qiyunzhu/repos","events_url":"https://api.github.com/users/qiyunzhu/events{/privacy}","received_events_url":"https://api.github.com/users/qiyunzhu/received_events","type":"User","site_admin":false},"body":"Dear Jose and Daniel,\r\n\r\nThank you for your patience. My first pull request of the plate mapper from the labadmin end is online for your review.\r\n\r\nBased on the previous discussion between Jose and me, I only kept a small amount of edits with highest priority, while removed all other functions such as GUI and data migration. Therefore only two files were modified: data_access.py and test_data_access.py.\r\n\r\nThe major functionality I added are the database read/write operations of plate attributes and plate-to-sample map. They were achieved in four functions: get_plate_info, set_plate_info, get_plate_map, and set_plate_map.\r\n\r\nIn addition there is a fifth function: get_plate_type. In my previous email I explained an idea of uniformizing field option retrieval operations. In this version I still kept the conventional way of getting plate types. But we can think of using the new idea later.\r\n\r\nI wrote unit tests for all those five functions. It wasn't easy, as it involves database read/write operations. I had to combine the tests for the four plate functions into one single test function, since a plate has to be created prior to the creation of the plate map. Meanwhile, I also added three additional functions: _add_new_samples, _delete_new_samples, and _delete_new_plate, to serve as setup and teardown functionalities for the test of the four functions.\r\n\r\nThank you for reviewing my code! Looking forward to hearing your valuable feedbacks!\r\n\r\nBest,\r\nQiyun","created_at":"2016-09-16T04:38:39Z","updated_at":"2016-09-25T14:05:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2c9f70cdbd3e93a8730704175286460c6a399978","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/biocore/labadmin/pulls/99/commits","review_comments_url":"https://api.github.com/repos/biocore/labadmin/pulls/99/comments","review_comment_url":"https://api.github.com/repos/biocore/labadmin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/biocore/labadmin/issues/99/comments","statuses_url":"https://api.github.com/repos/biocore/labadmin/statuses/772a9ab148e9deb539257e2eb43019db1232ca43","head":{"label":"qiyunzhu:plate-mapper-kiwi-checkpoint","ref":"plate-mapper-kiwi-checkpoint","sha":"772a9ab148e9deb539257e2eb43019db1232ca43","user":{"login":"qiyunzhu","id":4396343,"avatar_url":"https://avatars.githubusercontent.com/u/4396343?v=3","gravatar_id":"","url":"https://api.github.com/users/qiyunzhu","html_url":"https://github.com/qiyunzhu","followers_url":"https://api.github.com/users/qiyunzhu/followers","following_url":"https://api.github.com/users/qiyunzhu/following{/other_user}","gists_url":"https://api.github.com/users/qiyunzhu/gists{/gist_id}","starred_url":"https://api.github.com/users/qiyunzhu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qiyunzhu/subscriptions","organizations_url":"https://api.github.com/users/qiyunzhu/orgs","repos_url":"https://api.github.com/users/qiyunzhu/repos","events_url":"https://api.github.com/users/qiyunzhu/events{/privacy}","received_events_url":"https://api.github.com/users/qiyunzhu/received_events","type":"User","site_admin":false},"repo":{"id":65934612,"name":"labadmin","full_name":"qiyunzhu/labadmin","owner":{"login":"qiyunzhu","id":4396343,"avatar_url":"https://avatars.githubusercontent.com/u/4396343?v=3","gravatar_id":"","url":"https://api.github.com/users/qiyunzhu","html_url":"https://github.com/qiyunzhu","followers_url":"https://api.github.com/users/qiyunzhu/followers","following_url":"https://api.github.com/users/qiyunzhu/following{/other_user}","gists_url":"https://api.github.com/users/qiyunzhu/gists{/gist_id}","starred_url":"https://api.github.com/users/qiyunzhu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qiyunzhu/subscriptions","organizations_url":"https://api.github.com/users/qiyunzhu/orgs","repos_url":"https://api.github.com/users/qiyunzhu/repos","events_url":"https://api.github.com/users/qiyunzhu/events{/privacy}","received_events_url":"https://api.github.com/users/qiyunzhu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/qiyunzhu/labadmin","description":"Administration website for the Knight Lab","fork":true,"url":"https://api.github.com/repos/qiyunzhu/labadmin","forks_url":"https://api.github.com/repos/qiyunzhu/labadmin/forks","keys_url":"https://api.github.com/repos/qiyunzhu/labadmin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/qiyunzhu/labadmin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/qiyunzhu/labadmin/teams","hooks_url":"https://api.github.com/repos/qiyunzhu/labadmin/hooks","issue_events_url":"https://api.github.com/repos/qiyunzhu/labadmin/issues/events{/number}","events_url":"https://api.github.com/repos/qiyunzhu/labadmin/events","assignees_url":"https://api.github.com/repos/qiyunzhu/labadmin/assignees{/user}","branches_url":"https://api.github.com/repos/qiyunzhu/labadmin/branches{/branch}","tags_url":"https://api.github.com/repos/qiyunzhu/labadmin/tags","blobs_url":"https://api.github.com/repos/qiyunzhu/labadmin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/qiyunzhu/labadmin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/qiyunzhu/labadmin/git/refs{/sha}","trees_url":"https://api.github.com/repos/qiyunzhu/labadmin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/qiyunzhu/labadmin/statuses/{sha}","languages_url":"https://api.github.com/repos/qiyunzhu/labadmin/languages","stargazers_url":"https://api.github.com/repos/qiyunzhu/labadmin/stargazers","contributors_url":"https://api.github.com/repos/qiyunzhu/labadmin/contributors","subscribers_url":"https://api.github.com/repos/qiyunzhu/labadmin/subscribers","subscription_url":"https://api.github.com/repos/qiyunzhu/labadmin/subscription","commits_url":"https://api.github.com/repos/qiyunzhu/labadmin/commits{/sha}","git_commits_url":"https://api.github.com/repos/qiyunzhu/labadmin/git/commits{/sha}","comments_url":"https://api.github.com/repos/qiyunzhu/labadmin/comments{/number}","issue_comment_url":"https://api.github.com/repos/qiyunzhu/labadmin/issues/comments{/number}","contents_url":"https://api.github.com/repos/qiyunzhu/labadmin/contents/{+path}","compare_url":"https://api.github.com/repos/qiyunzhu/labadmin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/qiyunzhu/labadmin/merges","archive_url":"https://api.github.com/repos/qiyunzhu/labadmin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/qiyunzhu/labadmin/downloads","issues_url":"https://api.github.com/repos/qiyunzhu/labadmin/issues{/number}","pulls_url":"https://api.github.com/repos/qiyunzhu/labadmin/pulls{/number}","milestones_url":"https://api.github.com/repos/qiyunzhu/labadmin/milestones{/number}","notifications_url":"https://api.github.com/repos/qiyunzhu/labadmin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/qiyunzhu/labadmin/labels{/name}","releases_url":"https://api.github.com/repos/qiyunzhu/labadmin/releases{/id}","deployments_url":"https://api.github.com/repos/qiyunzhu/labadmin/deployments","created_at":"2016-08-17T19:06:36Z","updated_at":"2016-08-17T19:06:37Z","pushed_at":"2016-09-24T18:23:51Z","git_url":"git://github.com/qiyunzhu/labadmin.git","ssh_url":"git@github.com:qiyunzhu/labadmin.git","clone_url":"https://github.com/qiyunzhu/labadmin.git","svn_url":"https://github.com/qiyunzhu/labadmin","homepage":"","size":3784,"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:plate-mapper-kiwi","ref":"plate-mapper-kiwi","sha":"717cd5d044f4b5fe1a6a22a79e3f4ee3faef4ed0","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":43971581,"name":"labadmin","full_name":"biocore/labadmin","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/labadmin","description":"Administration website for the Knight Lab","fork":false,"url":"https://api.github.com/repos/biocore/labadmin","forks_url":"https://api.github.com/repos/biocore/labadmin/forks","keys_url":"https://api.github.com/repos/biocore/labadmin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/biocore/labadmin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/biocore/labadmin/teams","hooks_url":"https://api.github.com/repos/biocore/labadmin/hooks","issue_events_url":"https://api.github.com/repos/biocore/labadmin/issues/events{/number}","events_url":"https://api.github.com/repos/biocore/labadmin/events","assignees_url":"https://api.github.com/repos/biocore/labadmin/assignees{/user}","branches_url":"https://api.github.com/repos/biocore/labadmin/branches{/branch}","tags_url":"https://api.github.com/repos/biocore/labadmin/tags","blobs_url":"https://api.github.com/repos/biocore/labadmin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/biocore/labadmin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/biocore/labadmin/git/refs{/sha}","trees_url":"https://api.github.com/repos/biocore/labadmin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/biocore/labadmin/statuses/{sha}","languages_url":"https://api.github.com/repos/biocore/labadmin/languages","stargazers_url":"https://api.github.com/repos/biocore/labadmin/stargazers","contributors_url":"https://api.github.com/repos/biocore/labadmin/contributors","subscribers_url":"https://api.github.com/repos/biocore/labadmin/subscribers","subscription_url":"https://api.github.com/repos/biocore/labadmin/subscription","commits_url":"https://api.github.com/repos/biocore/labadmin/commits{/sha}","git_commits_url":"https://api.github.com/repos/biocore/labadmin/git/commits{/sha}","comments_url":"https://api.github.com/repos/biocore/labadmin/comments{/number}","issue_comment_url":"https://api.github.com/repos/biocore/labadmin/issues/comments{/number}","contents_url":"https://api.github.com/repos/biocore/labadmin/contents/{+path}","compare_url":"https://api.github.com/repos/biocore/labadmin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/biocore/labadmin/merges","archive_url":"https://api.github.com/repos/biocore/labadmin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/biocore/labadmin/downloads","issues_url":"https://api.github.com/repos/biocore/labadmin/issues{/number}","pulls_url":"https://api.github.com/repos/biocore/labadmin/pulls{/number}","milestones_url":"https://api.github.com/repos/biocore/labadmin/milestones{/number}","notifications_url":"https://api.github.com/repos/biocore/labadmin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/biocore/labadmin/labels{/name}","releases_url":"https://api.github.com/repos/biocore/labadmin/releases{/id}","deployments_url":"https://api.github.com/repos/biocore/labadmin/deployments","created_at":"2015-10-09T17:57:39Z","updated_at":"2016-08-24T19:21:17Z","pushed_at":"2016-09-24T18:23:51Z","git_url":"git://github.com/biocore/labadmin.git","ssh_url":"git@github.com:biocore/labadmin.git","clone_url":"https://github.com/biocore/labadmin.git","svn_url":"https://github.com/biocore/labadmin","homepage":"","size":3857,"stargazers_count":2,"watchers_count":2,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":17,"forks":11,"open_issues":17,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/biocore/labadmin/pulls/99"},"html":{"href":"https://github.com/biocore/labadmin/pull/99"},"issue":{"href":"https://api.github.com/repos/biocore/labadmin/issues/99"},"comments":{"href":"https://api.github.com/repos/biocore/labadmin/issues/99/comments"},"review_comments":{"href":"https://api.github.com/repos/biocore/labadmin/pulls/99/comments"},"review_comment":{"href":"https://api.github.com/repos/biocore/labadmin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/biocore/labadmin/pulls/99/commits"},"statuses":{"href":"https://api.github.com/repos/biocore/labadmin/statuses/772a9ab148e9deb539257e2eb43019db1232ca43"}}}}
{"actor":{"display_login":"antgonza"}}