GitHub PullRequestReviewCommentEvent at 2014-06-04 03:13:15
Repository: qiita
Actor: wasade
Payload: {"comment":{"url":"https://api.github.com/repos/biocore/qiita/pulls/comments/13369583","id":13369583,"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!\")","path":"qiita_db/study.py","position":191,"original_position":191,"commit_id":"17e8220b2ffbde3b1546dde559af16e82c3fe136","original_commit_id":"17e8220b2ffbde3b1546dde559af16e82c3fe136","user":{"login":"wasade","id":474290,"avatar_url":"https://avatars.githubusercontent.com/u/474290?","gravatar_id":"e45f3417df9a660f87d6e11f21d7f02a","url":"https://api.github.com/users/wasade","html_url":"https://github.com/wasade","followers_url":"https://api.github.com/users/wasade/followers","following_url":"https://api.github.com/users/wasade/following{/other_user}","gists_url":"https://api.github.com/users/wasade/gists{/gist_id}","starred_url":"https://api.github.com/users/wasade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wasade/subscriptions","organizations_url":"https://api.github.com/users/wasade/orgs","repos_url":"https://api.github.com/users/wasade/repos","events_url":"https://api.github.com/users/wasade/events{/privacy}","received_events_url":"https://api.github.com/users/wasade/received_events","type":"User","site_admin":false},"body":"I'm a bit confused by this, isn't the key check handled by `check_required`? Shouldn't it be the caller's responsibility to make sure that `info['study_experimental_factor']` is the correct type?","created_at":"2014-06-04T03:13:15Z","updated_at":"2014-06-04T03:13:15Z","html_url":"https://github.com/biocore/qiita/pull/70#discussion_r13369583","pull_request_url":"https://api.github.com/repos/biocore/qiita/pulls/70","_links":{"self":{"href":"https://api.github.com/repos/biocore/qiita/pulls/comments/13369583"},"html":{"href":"https://github.com/biocore/qiita/pull/70#discussion_r13369583"},"pull_request":{"href":"https://api.github.com/repos/biocore/qiita/pulls/70"}}}}