GitHub PullRequestReviewCommentEvent at 2014-06-03 18:06:52
Repository: qiita
Actor: josenavas
Payload: {"comment":{"url":"https://api.github.com/repos/biocore/qiita/pulls/comments/13349499","id":13349499,"diff_hunk":"@@ -19,42 +72,138 @@\n # The full license is in the file LICENSE, distributed with this software.\n # -----------------------------------------------------------------------------\n \n-from .base import QiitaStatusObject\n-from .exceptions import QiitaDBNotImplementedError\n+from datetime import date\n+\n+from .base import QiitaStatusObject, QiitaObject\n+from .data import RawData, PreprocessedData, ProcessedData\n+from .user import User\n+from .investigation import Investigation\n+from .util import check_required, check_table_cols\n+from .metadata_template import SampleTemplate\n+from .sql_connection import SQLConnectionHandler\n+from qiita_core.exceptions import QiitaStudyError\n+\n+\n+REQUIRED_KEYS = {\"timeseries_type_id\", \"lab_person_id\", \"mixs_compliant\",\n+                 \"metadata_complete\", \"number_samples_collected\",\n+                 \"number_samples_promised\", \"portal_type_id\",\n+                 \"principal_investigator_id\", \"study_title\", \"study_alias\",\n+                 \"study_description\", \"study_abstract\"}\n \n \n class Study(QiitaStatusObject):\n-    \"\"\"\n-    Study object to access to the Qiita Study information\n+    r\"\"\"Study object to access to the Qiita Study information\n \n     Attributes\n     ----------\n-    name\n-    sample_ids\n-    info\n+    name: str\n+        name of the study\n+    info: dict\n+        Major information about the study, keyed by db column name\n+    status: int\n+        Status of the study\n+    sample_ids: list of str\n+        All sample_ids associated with the study\n+    shared_with: list of User objects\n+        Emails of users the study is shared with\n+    pmids: list of str\n+        PMIDs assiciated with the study\n+    investigations: list of Investigation objects\n+        All investigations study is part of\n+    metadata: Metadata object\n+        Metadata object tied to this study\n+    raw_data: list of RawData objects\n+        All raw data attached to the study\n+    preprocessed_data: list of PreprocessedData objects\n+        All preprocessed data attached to the study\n+    processed_data: list of ProcessedData objects\n+        All processed data attached to the study\n \n     Methods\n     -------\n-    add_samples(samples)\n-        Adds the samples listed in `samples` to the study\n+    share_with(User_obj)\n+        Shares the study with given user\n \n-    remove_samples(samples)\n-        Removes the samples listed in `samples` from the study\n+    add_pmid(self, pmid):\n+        Adds PMID to study\n     \"\"\"\n+    _table = \"study\"\n \n-    @staticmethod\n-    def create(owner):\n+    @classmethod\n+    def create(cls, owner, info, investigation=None):\n         \"\"\"Creates a new study on the database\n \n         Parameters\n         ----------\n-        owner : str\n+        owner : User object\n             the user id of the study' owner\n+        info: dict\n+            the information attached to the study.\n+        investigation_id: Investigation object\n+            if the study is part of an investigation, the id to associate with\n+\n+        Raises\n+        ------\n+        QiitaDBExecutionError\n+            All required keys not passed or non-db columns in info dictionary\n+\n+        Notes\n+        -----\n+        All keys in info, except the efo, must be equal to columns in the\n+        forge.study table in the database. EFO information is stored as a list\n+        under the key 'study_experimental_factor', the name of the table it is\n+        stored in.\n         \"\"\"\n-        raise QiitaDBNotImplementedError()\n+        # make sure not passing a study id in the info dict\n+        if \"study_id\" in info:\n+            raise QiitaStudyError(\"Can't pass study_id in info dict!\")\n+\n+        # make sure required keys are in the info dict\n+        check_required(info, REQUIRED_KEYS)\n+\n+        # Save study_experimental_factor data for insertion\n+        efo = None\n+        if \"study_experimental_factor\" in info:\n+            efo = info[\"study_experimental_factor\"]\n+            if isinstance(efo, int):\n+                efo = [efo]\n+            info.pop(\"study_experimental_factor\")\n+        else:\n+            raise QiitaStudyError(\"EFO information is required!\")\n+\n+        conn_handler = SQLConnectionHandler()\n+        # make sure dictionary only has keys for available columns in db\n+        check_table_cols(conn_handler, info, \"study\")","path":"qiita_db/study.py","position":195,"original_position":195,"commit_id":"17e8220b2ffbde3b1546dde559af16e82c3fe136","original_commit_id":"17e8220b2ffbde3b1546dde559af16e82c3fe136","user":{"login":"josenavas","id":2501478,"avatar_url":"https://avatars.githubusercontent.com/u/2501478?","gravatar_id":"a99e7718dc3c82563a0236d3adec1b36","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":"Oooops!! Nevermind....","created_at":"2014-06-03T18:06:52Z","updated_at":"2014-06-03T18:06:52Z","html_url":"https://github.com/biocore/qiita/pull/70#discussion_r13349499","pull_request_url":"https://api.github.com/repos/biocore/qiita/pulls/70","_links":{"self":{"href":"https://api.github.com/repos/biocore/qiita/pulls/comments/13349499"},"html":{"href":"https://github.com/biocore/qiita/pull/70#discussion_r13349499"},"pull_request":{"href":"https://api.github.com/repos/biocore/qiita/pulls/70"}}}}