Beispiel #1
0
    def test_create_nonqiita_portal(self):
        qiita_config.portal = "EMP"
        Study.create(User("*****@*****.**"), "NEW!", [1], self.info, Investigation(1))

        # make sure portal is associated
        obs = self.conn_handler.execute_fetchall("SELECT * from qiita.study_portal WHERE study_id = 2")
        self.assertEqual(obs, [[2, 2], [2, 1]])
Beispiel #2
0
    def test_build_study_info_empty_study(self):
        info = {
            'timeseries_type_id': 1,
            'lab_person_id': None,
            'principal_investigator_id': 3,
            'metadata_complete': False,
            'mixs_compliant': True,
            'study_description': 'desc',
            'study_alias': 'alias',
            'study_abstract': 'abstract'}
        Study.create(User('*****@*****.**'), "My study", efo=[1], info=info)
        obs = _build_study_info(User('*****@*****.**'), 'user')

        self.exp.append({
            'metadata_complete': False,
            'ebi_submission_status':
            'not submitted',
            'shared': [],
            'publication_pid': [],
            'pi': ('*****@*****.**', 'PIDude'),
            'status': 'sandbox',
            'proc_data_info': [],
            'publication_doi': [],
            'study_abstract': 'abstract',
            'study_id': 2,
            'ebi_study_accession': None,
            'study_title': 'My study',
            'number_samples_collected': 0})

        self.assertItemsEqual(obs, self.exp)

        # Now testing that admin also sees this study
        obs = _build_study_info(User('*****@*****.**'), 'user')
        self.assertEqual(obs, self.exp)
    def test_build_study_info_empty_study(self):
        info = {
            'timeseries_type_id': 1,
            'lab_person_id': None,
            'principal_investigator_id': 3,
            'metadata_complete': False,
            'mixs_compliant': True,
            'study_description': 'desc',
            'study_alias': 'alias',
            'study_abstract': 'abstract'
        }
        Study.create(User('*****@*****.**'), "My study", efo=[1], info=info)
        obs = _build_study_info(User('*****@*****.**'), 'user')

        self.exp.append({
            'metadata_complete': False,
            'ebi_submission_status': 'not submitted',
            'shared': [],
            'pmid': [],
            'pi': ('*****@*****.**', 'PIDude'),
            'status': 'private',
            'proc_data_info': [],
            'publication_doi': [],
            'study_abstract': 'abstract',
            'study_id': 2,
            'ebi_study_accession': None,
            'study_title': 'My study',
            'number_samples_collected': 0
        })
        self.assertItemsEqual(obs, self.exp)
    def test_build_study_info_new_study(self):
        info = {
            'timeseries_type_id': 1,
            'lab_person_id': None,
            'principal_investigator_id': 3,
            'metadata_complete': False,
            'mixs_compliant': True,
            'study_description': 'desc',
            'study_alias': 'alias',
            'study_abstract': 'abstract'
        }
        user = User('*****@*****.**')

        Study.create(user, 'test_study_1', efo=[1], info=info)
        obs = _build_study_info(user)
        self.exp.append({
            'study_id': 2,
            'status': 'sandbox',
            'study_abstract': 'abstract',
            'metadata_complete': False,
            'study_title': 'test_study_1',
            'num_raw_data': 0,
            'number_samples_collected': 0,
            'shared': '',
            'pmid': '',
            'publication_doi': '',
            'pi':
            '<a target="_blank" href="mailto:[email protected]">PIDude</a>',
            'proc_data_info': []
        })
        self.assertEqual(obs, self.exp)
Beispiel #5
0
    def test_get_accessible_filepath_ids(self):
        self._set_processed_data_private()

        # shared has access to all study files and analysis files

        obs = get_accessible_filepath_ids(User('*****@*****.**'))
        self.assertEqual(obs, set([1, 2, 5, 6, 7, 11, 12, 13, 14, 15, 16, 17,
                                   18, 19, 20]))

        # Now shared should not have access to the study files
        self._unshare_studies()
        obs = get_accessible_filepath_ids(User('*****@*****.**'))
        self.assertEqual(obs, set([12, 13, 14, 15]))

        # Now shared should not have access to any files
        self._unshare_analyses()
        obs = get_accessible_filepath_ids(User('*****@*****.**'))
        self.assertEqual(obs, set())

        # Now shared has access to public study files
        self._set_processed_data_public()
        obs = get_accessible_filepath_ids(User('*****@*****.**'))
        self.assertEqual(obs, set([1, 2, 5, 6, 7, 11, 16, 19, 20]))

        # Test that it doesn't break: if the SampleTemplate hasn't been added
        exp = set([1, 2, 5, 6, 7, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20])
        obs = get_accessible_filepath_ids(User('*****@*****.**'))
        self.assertEqual(obs, exp)

        info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "number_samples_collected": 4,
            "number_samples_promised": 4,
            "portal_type_id": 3,
            "study_alias": "TestStudy",
            "study_description": "Description of a test study",
            "study_abstract": "No abstract right now...",
            "emp_person_id": 1,
            "principal_investigator_id": 1,
            "lab_person_id": 1
        }
        Study.create(User('*****@*****.**'), "Test study", [1], info)
        obs = get_accessible_filepath_ids(User('*****@*****.**'))
        self.assertEqual(obs, exp)

        # test in case there is a prep template that failed
        self.conn_handler.execute(
            "INSERT INTO qiita.prep_template (data_type_id, raw_data_id) "
            "VALUES (2,1)")
        obs = get_accessible_filepath_ids(User('*****@*****.**'))
        self.assertEqual(obs, exp)

        # admin should have access to everything
        count = self.conn_handler.execute_fetchone("SELECT count(*) FROM "
                                                   "qiita.filepath")[0]
        exp = set(range(1, count + 1))
        obs = get_accessible_filepath_ids(User('*****@*****.**'))
        self.assertEqual(obs, exp)
Beispiel #6
0
    def test_build_study_info_new_study(self):
        ProcessedData(1).status = 'public'
        info = {
            'timeseries_type_id': 1,
            'portal_type_id': 1,
            'lab_person_id': None,
            'principal_investigator_id': 3,
            'metadata_complete': False,
            'mixs_compliant': True,
            'study_description': 'desc',
            'study_alias': 'alias',
            'study_abstract': 'abstract'}
        user = User('*****@*****.**')

        Study.create(user, 'test_study_1', efo=[1], info=info)
        obs = _build_study_info(user)
        self.exp.append({
            'status': 'sandbox',
            'checkbox': "<input type='checkbox' value='2' />",
            'abstract': 'abstract',
            'meta_complete': "<span class='glyphicon glyphicon-remove'>"
            "</span>",
            'title': '<a href=\'#\' data-toggle=\'modal\' data-target=\'#study'
            '-abstract-modal\' onclick=\'fillAbstract("studies-table"'
            ', 1)\'><span class=\'glyphicon glyphicon-file\' aria-hidden=\''
            'true\'></span></a> | <a href=\'/study/description/2\' id=\''
            'study1-title\'>test_study_1</a>',
            'num_raw_data': 0, 'id': 2, 'num_samples': '0',
            'shared': "<span id='shared_html_2'></span><br/><a class='btn "
            "btn-primary btn-xs' data-toggle='modal' data-target='#share-study"
            "-modal-view' onclick='modify_sharing(2);'>Modify</a>",
            'pmid': '', 'pi':
            '<a target="_blank" href="mailto:[email protected]">PIDude</a>'})
        self.assertEqual(obs, self.exp)
    def test_build_study_info_new_study(self):
        info = {
            'timeseries_type_id': 1,
            'lab_person_id': None,
            'principal_investigator_id': 3,
            'metadata_complete': False,
            'mixs_compliant': True,
            'study_description': 'desc',
            'study_alias': 'alias',
            'study_abstract': 'abstract'}
        user = User('*****@*****.**')

        Study.create(user, 'test_study_1', efo=[1], info=info)
        obs = _build_study_info(user)
        self.exp.append({
            'study_id': 2,
            'status': 'sandbox',
            'study_abstract': 'abstract',
            'metadata_complete': False,
            'study_title': 'test_study_1',
            'num_raw_data': 0,
            'number_samples_collected': 0,
            'shared': '',
            'pmid': '',
            'publication_doi': '',
            'pi':
                '<a target="_blank" href="mailto:[email protected]">PIDude</a>',
            'proc_data_info': []})
        self.assertEqual(obs, self.exp)
Beispiel #8
0
    def setUp(self):
        fd, self.seqs_fp = mkstemp(suffix='_seqs.fastq')
        close(fd)
        fd, self.barcodes_fp = mkstemp(suffix='_barcodes.fastq')
        close(fd)
        self.filetype = 2
        self.filepaths = [(self.seqs_fp, 1), (self.barcodes_fp, 2)]
        self.studies = [Study(1)]
        _, self.db_test_raw_dir = get_mountpoint('raw_data')[0]

        with open(self.seqs_fp, "w") as f:
            f.write("\n")
        with open(self.barcodes_fp, "w") as f:
            f.write("\n")
        self._clean_up_files = []

        # Create a new study
        info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "number_samples_collected": 25,
            "number_samples_promised": 28,
            "portal_type_id": 3,
            "study_alias": "FCM",
            "study_description": "Microbiome of people who eat nothing but "
                                 "fried chicken",
            "study_abstract": "Exploring how a high fat diet changes the "
                              "gut microbiome",
            "emp_person_id": StudyPerson(2),
            "principal_investigator_id": StudyPerson(3),
            "lab_person_id": StudyPerson(1)
        }
        Study.create(User("*****@*****.**"), "Test study 2", [1], info)
    def test_build_study_info_new_study(self):
        info = {
            'timeseries_type_id': 1,
            'portal_type_id': 1,
            'lab_person_id': None,
            'principal_investigator_id': 3,
            'metadata_complete': False,
            'mixs_compliant': True,
            'study_description': 'desc',
            'study_alias': 'alias',
            'study_abstract': 'abstract'}
        user = User('*****@*****.**')

        Study.create(user, 'test_study_1', efo=[1], info=info)

        obs = _build_study_info('private', user)

        StudyTuple = namedtuple('StudyInfo', 'id title meta_complete '
                                'num_samples_collected shared num_raw_data pi '
                                'pmids owner status')
        exp = [
            StudyTuple(
                id=2,
                title='test_study_1',
                meta_complete=False, num_samples_collected=None,
                shared='',
                num_raw_data=0,
                pi='<a target="_blank" href="mailto:[email protected]">'
                   'PIDude</a>',
                pmids='',
                owner='<a target="_blank" href="mailto:[email protected]">'
                      '[email protected]</a>',
                status='sandbox')]
        self.assertEqual(obs, exp)
Beispiel #10
0
    def setUp(self):
        fd, self.seqs_fp = mkstemp(suffix='_seqs.fastq')
        close(fd)
        fd, self.barcodes_fp = mkstemp(suffix='_barcodes.fastq')
        close(fd)
        self.filetype = 2
        self.filepaths = [(self.seqs_fp, 1), (self.barcodes_fp, 2)]
        self.studies = [Study(1)]
        _, self.db_test_raw_dir = get_mountpoint('raw_data')[0]

        with open(self.seqs_fp, "w") as f:
            f.write("\n")
        with open(self.barcodes_fp, "w") as f:
            f.write("\n")
        self._clean_up_files = []

        # Create a new study
        info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "number_samples_collected": 25,
            "number_samples_promised": 28,
            "portal_type_id": 3,
            "study_alias": "FCM",
            "study_description": "Microbiome of people who eat nothing but "
                                 "fried chicken",
            "study_abstract": "Exploring how a high fat diet changes the "
                              "gut microbiome",
            "emp_person_id": StudyPerson(2),
            "principal_investigator_id": StudyPerson(3),
            "lab_person_id": StudyPerson(1)
        }
        Study.create(User("*****@*****.**"), "Test study 2", [1], info)
Beispiel #11
0
    def test_remove_portal(self):
        Portal.create("NEWPORTAL", "SOMEDESC")
        # Select some samples on a default analysis
        qiita_config.portal = "NEWPORTAL"
        a = Analysis(User("*****@*****.**").default_analysis)
        a.add_samples({1: ['1.SKB8.640193', '1.SKD5.640186']})

        Portal.delete("NEWPORTAL")
        obs = self.conn_handler.execute_fetchall(
            "SELECT * FROM qiita.portal_type")
        exp = [[1, 'QIITA', 'QIITA portal. Access to all data stored '
                'in database.'],
               [2, 'EMP', 'EMP portal']]
        self.assertItemsEqual(obs, exp)

        obs = self.conn_handler.execute_fetchall(
            "SELECT * FROM qiita.analysis_portal")
        exp = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 2], [8, 2],
               [9, 2], [10, 2]]
        self.assertItemsEqual(obs, exp)

        with self.assertRaises(QiitaDBLookupError):
            Portal.delete("NOEXISTPORTAL")
        with self.assertRaises(QiitaDBError):
            Portal.delete("QIITA")

        Portal.create("NEWPORTAL2", "SOMEDESC")
        # Add analysis to this new portal and make sure error raised
        qiita_config.portal = "NEWPORTAL2"
        Analysis.create(User("*****@*****.**"), "newportal analysis", "desc")
        qiita_config.portal = "QIITA"
        with self.assertRaises(QiitaDBError):
            Portal.delete("NEWPORTAL2")

        # Add study to this new portal and make sure error raised
        info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "number_samples_collected": 25,
            "number_samples_promised": 28,
            "study_alias": "FCM",
            "study_description": "Microbiome of people who eat nothing but "
                                 "fried chicken",
            "study_abstract": "Exploring how a high fat diet changes the "
                              "gut microbiome",
            "emp_person_id": StudyPerson(2),
            "principal_investigator_id": StudyPerson(3),
            "lab_person_id": StudyPerson(1)
        }
        Portal.create("NEWPORTAL3", "SOMEDESC")
        qiita_config.portal = "NEWPORTAL3"
        Study.create(User('*****@*****.**'), "Fried chicken microbiome",
                     [1], info)
        qiita_config.portal = "QIITA"
        with self.assertRaises(QiitaDBError):
            Portal.delete("NEWPORTAL3")
Beispiel #12
0
    def test_get_accessible_filepath_ids(self):
        self._set_studies_private()

        # shared has access to all study files and analysis files

        obs = get_accessible_filepath_ids(User('*****@*****.**'))
        self.assertEqual(obs,
                         set([1, 2, 5, 6, 7, 11, 12, 13, 14, 15, 16, 17, 18]))

        # Now shared should not have access to the study files
        self._unshare_studies()
        obs = get_accessible_filepath_ids(User('*****@*****.**'))
        self.assertEqual(obs, set([12, 13, 14, 15]))

        # Now shared should not have access to any files
        self._unshare_analyses()
        obs = get_accessible_filepath_ids(User('*****@*****.**'))
        self.assertEqual(obs, set())

        # Test that it doesn't break: if the SampleTemplate hasn't been added
        exp = set([1, 2, 5, 6, 7, 11, 12, 13, 14, 15, 16, 17, 18])
        obs = get_accessible_filepath_ids(User('*****@*****.**'))
        self.assertEqual(obs, exp)

        info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "number_samples_collected": 4,
            "number_samples_promised": 4,
            "portal_type_id": 3,
            "study_alias": "TestStudy",
            "study_description": "Description of a test study",
            "study_abstract": "No abstract right now...",
            "emp_person_id": 1,
            "principal_investigator_id": 1,
            "lab_person_id": 1
        }
        Study.create(User('*****@*****.**'), "Test study", [1], info)
        obs = get_accessible_filepath_ids(User('*****@*****.**'))
        self.assertEqual(obs, exp)

        # test in case there is a prep template that failed
        self.conn_handler.execute(
            "INSERT INTO qiita.prep_template (data_type_id, raw_data_id) "
            "VALUES (2,1)")
        obs = get_accessible_filepath_ids(User('*****@*****.**'))
        self.assertEqual(obs, exp)

        # admin should have access to everything
        count = self.conn_handler.execute_fetchone("SELECT count(*) FROM "
                                                   "qiita.filepath")[0]
        exp = set(range(1, count + 1))
        obs = get_accessible_filepath_ids(User('*****@*****.**'))
        self.assertEqual(obs, exp)
Beispiel #13
0
    def test_get_no_samples(self):
        # /api/v1/study/%d/samples/info -> {'number-of-samples':<int>,
        #   'categories': [<str>]}
        info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "number_samples_collected": 25,
            "number_samples_promised": 28,
            "study_alias": "FCM",
            "study_description": "DESC",
            "study_abstract": "ABS",
            "principal_investigator_id": StudyPerson(3),
            'first_contact': datetime(2015, 5, 19, 16, 10),
            'most_recent_contact': datetime(2015, 5, 19, 16, 11),
        }

        new_study = Study.create(User('*****@*****.**'),
                                 "Some New Study for test", info)

        exp = {'message': 'Study does not have sample information'}
        response = self.get('/api/v1/study/%d/samples/categories=foo' %
                            new_study.id,
                            headers=self.headers)
        self.assertEqual(response.code, 404)
        obs = json_decode(response.body)
        self.assertEqual(obs, exp)
Beispiel #14
0
    def test_create_sample_template(self):
        # Test error
        job = self._create_job('create_sample_template', {
            'fp': self.fp, 'study_id': 1, 'is_mapping_file': False,
            'data_type': None})
        private_task(job.id)
        self.assertEqual(job.status, 'error')
        self.assertIn("The 'SampleTemplate' object with attributes (id: 1) "
                      "already exists.", job.log.msg)

        # Test success with a warning
        info = {"timeseries_type_id": '1',
                "metadata_complete": 'true',
                "mixs_compliant": 'true',
                "study_alias": "TDST",
                "study_description": "Test create sample template",
                "study_abstract": "Test create sample template",
                "principal_investigator_id": StudyPerson(1)}
        study = Study.create(User('*****@*****.**'),
                             "Create Sample Template test", info)
        job = self._create_job('create_sample_template',
                               {'fp': self.fp, 'study_id': study.id,
                                'is_mapping_file': False, 'data_type': None})
        private_task(job.id)
        self.assertEqual(job.status, 'success')
        obs = r_client.get("sample_template_%d" % study.id)
        self.assertIsNotNone(obs)
        obs = loads(obs)
        self.assertCountEqual(obs, ['job_id', 'alert_type', 'alert_msg'])
        self.assertEqual(obs['job_id'], job.id)
        self.assertEqual(obs['alert_type'], 'warning')
        self.assertIn(
            'Some functionality will be disabled due to missing columns:',
            obs['alert_msg'])
Beispiel #15
0
    def test_get_no_samples(self):
        # /api/v1/study/%d/samples/info -> {'number-of-samples':<int>,
                                        #   'categories': [<str>]}
        info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "number_samples_collected": 25,
            "number_samples_promised": 28,
            "study_alias": "FCM",
            "study_description": "DESC",
            "study_abstract": "ABS",
            "principal_investigator_id": StudyPerson(3),
            'first_contact': datetime(2015, 5, 19, 16, 10),
            'most_recent_contact': datetime(2015, 5, 19, 16, 11),
        }

        new_study = Study.create(User('*****@*****.**'),
                                 "Some New Study for test", info)

        exp = {'message': 'Study does not have sample information'}
        response = self.get('/api/v1/study/%d/samples/categories=foo' %
                            new_study.id, headers=self.headers)
        self.assertEqual(response.code, 404)
        obs = json_decode(response.body)
        self.assertEqual(obs, exp)
Beispiel #16
0
    def test_patch_no_sample_template(self):
        info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "number_samples_collected": 25,
            "number_samples_promised": 28,
            "study_alias": "FCM",
            "study_description": "DESC",
            "study_abstract": "ABS",
            "principal_investigator_id": StudyPerson(3),
            'first_contact': datetime(2015, 5, 19, 16, 10),
            'most_recent_contact': datetime(2015, 5, 19, 16, 11),
        }

        new_study = Study.create(User('*****@*****.**'),
                                 "Some New Study for test jr", info)

        body = {
            'sampleid1': {
                'category_a': 'value_a'
            },
            'sampleid2': {
                'category_b': 'value_b'
            }
        }

        exp = {'message': 'No sample information found'}
        response = self.patch('/api/v1/study/%d/samples' % new_study.id,
                              headers=self.headers,
                              data=body,
                              asjson=True)
        self.assertEqual(response.code, 404)
        obs = json_decode(response.body)
        self.assertEqual(obs, exp)
Beispiel #17
0
 def test_set_info_disallowed_keys(self):
     """Tests for fail if sending non-info keys in info dict"""
     new = Study.create(
         User("*****@*****.**"), "NOT Identification of the " "Microbiomes for Cannabis Soils", [1], self.info
     )
     with self.assertRaises(QiitaDBColumnError):
         new.info = {"email": "*****@*****.**"}
Beispiel #18
0
 def test_set_efo_empty(self):
     """Set efo with list efo_id"""
     new = Study.create(
         User("*****@*****.**"), "NOT Identification of the " "Microbiomes for Cannabis Soils", [1], self.info
     )
     with self.assertRaises(IncompetentQiitaDeveloperError):
         new.efo = []
Beispiel #19
0
 def test_set_efo(self):
     """Set efo with list efo_id"""
     new = Study.create(
         User("*****@*****.**"), "NOT Identification of the " "Microbiomes for Cannabis Soils", [1], self.info
     )
     new.efo = [3, 4]
     self.assertEqual(new.efo, [3, 4])
Beispiel #20
0
 def test_create_study_with_investigation(self):
     """Insert a study into the database with an investigation"""
     obs = Study.create(User("*****@*****.**"), "Fried chicken microbiome", [1], self.info, Investigation(1))
     self.assertEqual(obs.id, 2)
     # check the investigation was assigned
     obs = self.conn_handler.execute_fetchall("SELECT * from qiita.investigation_study WHERE study_id = 2")
     self.assertEqual(obs, [[1, 2]])
Beispiel #21
0
    def _create_study(self, study_title):
        """Creates a new study

        Parameters
        ----------
        study_title: str
            The title of the new study

        Returns
        -------
        qiita_db.study.Study
            The newly created study
        """
        info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "number_samples_collected": 25,
            "number_samples_promised": 28,
            "study_alias": "ALIAS",
            "study_description": "DESC",
            "study_abstract": "ABS",
            "principal_investigator_id": StudyPerson(3),
            "lab_person_id": StudyPerson(1)
        }
        return Study.create(User('*****@*****.**'), study_title, info)
Beispiel #22
0
 def test_set_efo(self):
     """Set efo with list efo_id"""
     new = Study.create(
         User('*****@*****.**'), 'NOT Identification of the '
         'Microbiomes for Cannabis Soils', [1], self.info)
     new.efo = [3, 4]
     self.assertEqual(new.efo, [3, 4])
Beispiel #23
0
 def test_add_raw_data_private(self):
     new = Study.create(
         User('*****@*****.**'), 'NOT Identification of the '
         'Microbiomes for Cannabis Soils', [1], self.info)
     new.status = 'private'
     with self.assertRaises(QiitaDBStatusError):
         new.add_raw_data([RawData(2)])
Beispiel #24
0
 def test_set_info_disallowed_keys(self):
     """Tests for fail if sending non-info keys in info dict"""
     new = Study.create(
         User('*****@*****.**'), 'NOT Identification of the '
         'Microbiomes for Cannabis Soils', [1], self.info)
     with self.assertRaises(QiitaDBColumnError):
         new.info = {"email": "*****@*****.**"}
Beispiel #25
0
    def test_status_error(self):
        # Let's create a new study, so we can check that the error is raised
        # because the new study does not have access to the raw data
        info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "number_samples_collected": 25,
            "number_samples_promised": 28,
            "portal_type_id": 3,
            "study_alias": "FCM",
            "study_description": "Microbiome of people who eat nothing but "
                                 "fried chicken",
            "study_abstract": "Exploring how a high fat diet changes the "
                              "gut microbiome",
            "emp_person_id": StudyPerson(2),
            "principal_investigator_id": StudyPerson(3),
            "lab_person_id": StudyPerson(1)
        }
        s = Study.create(User('*****@*****.**'), "Fried chicken microbiome",
                         [1], info)
        rd = RawData(1)

        with self.assertRaises(QiitaDBStatusError):
            rd.status(s)
Beispiel #26
0
    def test_patch_no_sample_template(self):
        info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "study_alias": "FCM",
            "study_description": "DESC",
            "study_abstract": "ABS",
            "principal_investigator_id": StudyPerson(3),
            'first_contact': datetime(2015, 5, 19, 16, 10),
            'most_recent_contact': datetime(2015, 5, 19, 16, 11),
        }

        new_study = Study.create(User('*****@*****.**'),
                                 "Some New Study for test jr", info)

        body = {'sampleid1': {'category_a': 'value_a'},
                'sampleid2': {'category_b': 'value_b'}}

        exp = {'message': 'No sample information found'}
        response = self.patch('/api/v1/study/%d/samples' % new_study.id,
                              headers=self.headers, data=body, asjson=True)
        self.assertEqual(response.code, 404)
        obs = json_decode(response.body)
        self.assertEqual(obs, exp)
Beispiel #27
0
    def setUp(self):
        # Create a directory with the test split libraries output
        self.test_slo = mkdtemp(prefix='test_slo_')
        path_builder = partial(join, self.test_slo)
        fna_fp = path_builder('seqs.fna')
        fastq_fp = path_builder('seqs.fastq')
        log_fp = path_builder('split_library_log.txt')
        demux_fp = path_builder('seqs.demux')

        with open(fna_fp, 'w') as f:
            f.write(FASTA_SEQS)

        with open(fastq_fp, 'w') as f:
            f.write(FASTQ_SEQS)

        with open(log_fp, 'w') as f:
            f.write("Test log\n")

        generate_demux_file(self.test_slo)

        self._filepaths_to_remove = [fna_fp, fastq_fp, demux_fp, log_fp]
        self._dirpaths_to_remove = [self.test_slo]

        # Generate a directory with test split libraries output missing files
        self.missing_slo = mkdtemp(prefix='test_missing_')
        path_builder = partial(join, self.test_slo)
        fna_fp = path_builder('seqs.fna')
        fastq_fp = path_builder('seqs.fastq')

        with open(fna_fp, 'w') as f:
            f.write(FASTA_SEQS)

        with open(fastq_fp, 'w') as f:
            f.write(FASTQ_SEQS)

        self._filepaths_to_remove.append(fna_fp)
        self._filepaths_to_remove.append(fastq_fp)
        self._dirpaths_to_remove.append(self.missing_slo)

        # Create a study with no preprocessed data
        info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "number_samples_collected": 25,
            "number_samples_promised": 28,
            "study_alias": "FCM",
            "study_description": "Microbiome of people who eat nothing but "
                                 "fried chicken",
            "study_abstract": "Exploring how a high fat diet changes the "
                              "gut microbiome",
            "emp_person_id": StudyPerson(2),
            "principal_investigator_id": StudyPerson(3),
            "lab_person_id": StudyPerson(1)
        }
        self.no_ppd_study = Study.create(
            User('*****@*****.**'), "Test study", [1], info)

        # Get the directory where the preprocessed data is usually copied.
        _, self.db_ppd_dir = get_mountpoint('preprocessed_data')[0]
Beispiel #28
0
    def _create_study(self, study_title):
        """Creates a new study

        Parameters
        ----------
        study_title: str
            The title of the new study

        Returns
        -------
        qiita_db.study.Study
            The newly created study
        """
        info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "number_samples_collected": 25,
            "number_samples_promised": 28,
            "study_alias": "ALIAS",
            "study_description": "DESC",
            "study_abstract": "ABS",
            "principal_investigator_id": StudyPerson(3),
            "lab_person_id": StudyPerson(1)
        }
        return Study.create(User('*****@*****.**'), study_title, info)
Beispiel #29
0
    def test_create_study_min_data(self):
        """Insert a study into the database"""
        obs = Study.create(User('*****@*****.**'), "Fried chicken microbiome",
                           [1], self.info)
        self.assertEqual(obs.id, 2)
        exp = {'mixs_compliant': True, 'metadata_complete': True,
               'reprocess': False, 'study_status_id': 1,
               'number_samples_promised': 28, 'emp_person_id': 2,
               'funding': None, 'vamps_id': None,
               'first_contact': date.today().isoformat(),
               'principal_investigator_id': 3,
               'timeseries_type_id': 1,
               'study_abstract': 'Exploring how a high fat diet changes the '
                                 'gut microbiome',
               'email': '*****@*****.**', 'spatial_series': None,
               'study_description': 'Microbiome of people who eat nothing but'
                                    ' fried chicken',
               'portal_type_id': 3, 'study_alias': 'FCM', 'study_id': 2,
               'most_recent_contact': None, 'lab_person_id': 1,
               'study_title': 'Fried chicken microbiome',
               'number_samples_collected': 25}

        obsins = self.conn_handler.execute_fetchall(
            "SELECT * FROM qiita.study WHERE study_id = 2")
        self.assertEqual(len(obsins), 1)
        obsins = dict(obsins[0])
        self.assertEqual(obsins, exp)

        # make sure EFO went in to table correctly
        efo = self.conn_handler.execute_fetchall(
            "SELECT efo_id FROM qiita.study_experimental_factor "
            "WHERE study_id = 2")
        self.assertEqual(efo, [[1]])
Beispiel #30
0
    def test_delete_study_empty_study(self):
        info = {
            "timeseries_type_id": '1',
            "metadata_complete": 'true',
            "mixs_compliant": 'true',
            "number_samples_collected": 25,
            "number_samples_promised": 28,
            "study_alias": "FCM",
            "study_description": "Microbiome of people who eat nothing but "
            "fried chicken",
            "study_abstract": "Exploring how a high fat diet changes the "
            "gut microbiome",
            "emp_person_id": StudyPerson(2),
            "principal_investigator_id": StudyPerson(3),
            "lab_person_id": StudyPerson(1)
        }
        new_study = Study.create(User('*****@*****.**'),
                                 "Fried Chicken Microbiome %s" % time(), info)
        job = self._create_job('delete_study', {'study': new_study.id})
        private_task(job.id)
        self.assertEqual(job.status, 'success')

        # making sure the study doesn't exist
        with self.assertRaises(QiitaDBUnknownIDError):
            Study(new_study.id)
Beispiel #31
0
 def test_set_efo_empty(self):
     """Set efo with list efo_id"""
     new = Study.create(
         User('*****@*****.**'), 'NOT Identification of the '
         'Microbiomes for Cannabis Soils', [1], self.info)
     with self.assertRaises(IncompetentQiitaDeveloperError):
         new.efo = []
Beispiel #32
0
    def test_get_by_status(self):
        obs = Study.get_by_status('sandbox')
        self.assertEqual(obs, set())

        Study.create(User('*****@*****.**'), 'NOT Identification of the '
                     'Microbiomes for Cannabis Soils', [1], self.info)
        obs = Study.get_by_status('private')
        self.assertEqual(obs, {1})

        obs = Study.get_by_status('sandbox')
        self.assertEqual(obs, {2})

        obs = Study.get_by_status('public')
        self.assertEqual(obs, set())

        obs = Study.get_by_status('awaiting_approval')
        self.assertEqual(obs, set())
Beispiel #33
0
 def test_add_raw_data(self):
     self._make_sandbox()
     new = Study.create(User('*****@*****.**'), 'NOT Identification of the '
                        'Microbiomes for Cannabis Soils', [1], self.info)
     new.add_raw_data([RawData(1), RawData(2)])
     obs = self.conn_handler.execute_fetchall(
         "SELECT * FROM qiita.study_raw_data WHERE study_id=%s",
         (new.id,))
     self.assertEqual(obs, [[new.id, 1], [new.id, 2]])
Beispiel #34
0
 def test_create_study_with_investigation(self):
     """Insert a study into the database with an investigation"""
     obs = Study.create(User('*****@*****.**'), "Fried chicken microbiome",
                        [1], self.info, Investigation(1))
     self.assertEqual(obs.id, 2)
     # check the investigation was assigned
     obs = self.conn_handler.execute_fetchall(
         "SELECT * from qiita.investigation_study WHERE study_id = 2")
     self.assertEqual(obs, [[1, 2]])
Beispiel #35
0
    def test_ebi_study_accession_setter(self):
        new = Study.create(User('*****@*****.**'), 'Test', [1], self.info)
        self.assertEqual(new.ebi_study_accession, None)
        new.ebi_study_accession = 'EBI654321-BB'
        self.assertEqual(new.ebi_study_accession, 'EBI654321-BB')

        # Raises an error if the study already has an EBI study accession
        with self.assertRaises(QiitaDBError):
            self.study.ebi_study_accession = 'EBI654321-BB'
Beispiel #36
0
 def test_add_raw_data(self):
     self._make_sandbox()
     new = Study.create(
         User('*****@*****.**'), 'NOT Identification of the '
         'Microbiomes for Cannabis Soils', [1], self.info)
     new.add_raw_data([RawData(1), RawData(2)])
     obs = self.conn_handler.execute_fetchall(
         "SELECT * FROM qiita.study_raw_data WHERE study_id=%s", (new.id, ))
     self.assertEqual(obs, [[new.id, 1], [new.id, 2]])
Beispiel #37
0
    def test_get_by_status(self):
        obs = Study.get_by_status("sandbox")
        self.assertEqual(obs, set())

        Study.create(
            User("*****@*****.**"), "NOT Identification of the " "Microbiomes for Cannabis Soils", [1], self.info
        )
        obs = Study.get_by_status("private")
        self.assertEqual(obs, {1})

        obs = Study.get_by_status("sandbox")
        self.assertEqual(obs, {2})

        obs = Study.get_by_status("public")
        self.assertEqual(obs, set())

        obs = Study.get_by_status("awaiting_approval")
        self.assertEqual(obs, set())
Beispiel #38
0
    def test_delete(self):
        title = "Fried chicken microbiome"
        study = Study.create(User('*****@*****.**'), title, [1], self.info)
        study.delete(study.id)
        self.assertFalse(study.exists(title))

        with self.assertRaises(QiitaDBError):
            Study.delete(1)

        with self.assertRaises(QiitaDBUnknownIDError):
            Study.delete(41)
Beispiel #39
0
    def test_environmental_packages_setter(self):
        new = Study.create(User('*****@*****.**'), 'NOT Identification of the '
                           'Microbiomes for Cannabis Soils', [1], self.info)
        obs = new.environmental_packages
        exp = []
        self.assertEqual(obs, exp)

        new_values = ['air', 'human-oral']
        new.environmental_packages = new_values
        obs = new.environmental_packages
        self.assertEqual(sorted(obs), sorted(new_values))
Beispiel #40
0
    def test_environmental_packages_setter(self):
        new = Study.create(
            User("*****@*****.**"), "NOT Identification of the " "Microbiomes for Cannabis Soils", [1], self.info
        )
        obs = new.environmental_packages
        exp = []
        self.assertEqual(obs, exp)

        new_values = ["air", "human-oral"]
        new.environmental_packages = new_values
        obs = new.environmental_packages
        self.assertEqual(sorted(obs), sorted(new_values))
Beispiel #41
0
    def test_environmental_packages_setter(self):
        new = Study.create(
            User('*****@*****.**'), 'NOT Identification of the '
            'Microbiomes for Cannabis Soils', [1], self.info)
        obs = new.environmental_packages
        exp = []
        self.assertEqual(obs, exp)

        new_values = ['air', 'human-oral']
        new.environmental_packages = new_values
        obs = new.environmental_packages
        self.assertEqual(sorted(obs), sorted(new_values))
Beispiel #42
0
    def test_ebi_submission_status_setter(self):
        new = Study.create(User('*****@*****.**'), 'Test', [1], self.info)
        self.assertEqual(new.ebi_submission_status, "not submitted")
        new.ebi_submission_status = 'submitting'
        self.assertEqual(new.ebi_submission_status, 'submitting')
        new.ebi_submission_status = 'failed: something horrible happened'
        self.assertEqual(new.ebi_submission_status,
                         'failed: something horrible happened')
        new.ebi_submission_status = 'submitted'
        self.assertEqual(new.ebi_submission_status, 'submitted')

        with self.assertRaises(ValueError):
            new.ebi_submission_status = "unknown"
Beispiel #43
0
    def test_create_study_all_data(self):
        """Insert a study into the database with every info field"""
        self.info.update({
            'vamps_id': 'MBE_1111111',
            'funding': 'FundAgency',
            'spatial_series': True,
            'metadata_complete': False,
            'reprocess': True,
            'first_contact': "10/24/2014 12:47PM",
            'study_id': 3827
        })
        obs = Study.create(User('*****@*****.**'), "Fried chicken microbiome",
                           [1], self.info)
        self.assertEqual(obs.id, 3827)
        exp = {
            'mixs_compliant': True,
            'metadata_complete': False,
            'reprocess': True,
            'study_status_id': 4,
            'number_samples_promised': 28,
            'emp_person_id': 2,
            'funding': 'FundAgency',
            'vamps_id': 'MBE_1111111',
            'first_contact': datetime(2014, 10, 24, 12, 47),
            'principal_investigator_id': 3,
            'timeseries_type_id': 1,
            'study_abstract': 'Exploring how a high fat diet changes the '
            'gut microbiome',
            'email': '*****@*****.**',
            'spatial_series': True,
            'study_description': 'Microbiome of people who eat nothing '
            'but fried chicken',
            'portal_type_id': 3,
            'study_alias': 'FCM',
            'study_id': 3827,
            'most_recent_contact': None,
            'lab_person_id': 1,
            'study_title': 'Fried chicken microbiome',
            'number_samples_collected': 25
        }
        obsins = self.conn_handler.execute_fetchall(
            "SELECT * FROM qiita.study WHERE study_id = 3827")
        self.assertEqual(len(obsins), 1)
        obsins = dict(obsins[0])
        self.assertEqual(obsins, exp)

        # make sure EFO went in to table correctly
        obsefo = self.conn_handler.execute_fetchall(
            "SELECT efo_id FROM qiita.study_experimental_factor "
            "WHERE study_id = 3827")
        self.assertEqual(obsefo, [[1]])
Beispiel #44
0
    def test_create_study_min_data(self):
        """Insert a study into the database"""
        before = datetime.now()
        obs = Study.create(User('*****@*****.**'), "Fried chicken microbiome",
                           [1], self.info)
        after = datetime.now()
        self.assertEqual(obs.id, 2)
        exp = {
            'mixs_compliant': True,
            'metadata_complete': True,
            'reprocess': False,
            'study_status_id': 4,
            'number_samples_promised': 28,
            'emp_person_id': 2,
            'funding': None,
            'vamps_id': None,
            'principal_investigator_id': 3,
            'timeseries_type_id': 1,
            'study_abstract': 'Exploring how a high fat diet changes the '
            'gut microbiome',
            'email': '*****@*****.**',
            'spatial_series': None,
            'study_description': 'Microbiome of people who eat nothing but'
            ' fried chicken',
            'portal_type_id': 3,
            'study_alias': 'FCM',
            'study_id': 2,
            'most_recent_contact': None,
            'lab_person_id': 1,
            'study_title': 'Fried chicken microbiome',
            'number_samples_collected': 25
        }

        obsins = self.conn_handler.execute_fetchall(
            "SELECT * FROM qiita.study WHERE study_id = 2")
        self.assertEqual(len(obsins), 1)
        obsins = dict(obsins[0])

        # Check the timestamp separately, since it is set by the database
        # to the microsecond, and we can't predict it a priori
        ins_timestamp = obsins.pop('first_contact')
        self.assertTrue(before < ins_timestamp < after)

        self.assertEqual(obsins, exp)

        # make sure EFO went in to table correctly
        efo = self.conn_handler.execute_fetchall(
            "SELECT efo_id FROM qiita.study_experimental_factor "
            "WHERE study_id = 2")
        self.assertEqual(efo, [[1]])
Beispiel #45
0
    def test_delete(self):
        title = "Fried chicken microbiome"
        # the study is assigned to investigation 1
        study = Study.create(User("*****@*****.**"), title, [1], self.info, Investigation(1))
        # sharing with other user
        study.share(User("*****@*****.**"))
        study.delete(study.id)
        self.assertFalse(study.exists(title))

        with self.assertRaises(QiitaDBError):
            Study.delete(1)

        with self.assertRaises(QiitaDBUnknownIDError):
            Study.delete(41)
Beispiel #46
0
    def test_build_study_info_new_study(self):
        info = {
            'timeseries_type_id': 1,
            'portal_type_id': 1,
            'lab_person_id': None,
            'principal_investigator_id': 3,
            'metadata_complete': False,
            'mixs_compliant': True,
            'study_description': 'desc',
            'study_alias': 'alias',
            'study_abstract': 'abstract'
        }
        user = User('*****@*****.**')

        Study.create(user, 'test_study_1', efo=[1], info=info)

        obs = _build_study_info('private', user)

        StudyTuple = namedtuple(
            'StudyInfo', 'id title meta_complete '
            'num_samples_collected shared num_raw_data pi '
            'pmids owner status')
        exp = [
            StudyTuple(id=2,
                       title='test_study_1',
                       meta_complete=False,
                       num_samples_collected=None,
                       shared='',
                       num_raw_data=0,
                       pi='<a target="_blank" href="mailto:[email protected]">'
                       'PIDude</a>',
                       pmids='',
                       owner='<a target="_blank" href="mailto:[email protected]">'
                       '[email protected]</a>',
                       status='sandbox')
        ]
        self.assertEqual(obs, exp)
Beispiel #47
0
 def setUp(self):
     info = {
         "timeseries_type_id": 1,
         "metadata_complete": True,
         "mixs_compliant": True,
         "study_alias": "FCM",
         "study_description": "Microbiome of people who eat nothing but "
         "fried chicken",
         "study_abstract": "Exploring how a high fat diet changes the "
         "gut microbiome",
         "principal_investigator_id": StudyPerson(3),
         "lab_person_id": StudyPerson(1)
     }
     self.new_study = Study.create(User('*****@*****.**'),
                                   "Fried Chicken Microbiome", info)
     self._clean_up_files = []
 def setUp(self):
     info = {
         "timeseries_type_id": 1,
         "metadata_complete": True,
         "mixs_compliant": True,
         "study_alias": "FCM",
         "study_description": "Microbiome of people who eat nothing but "
                              "fried chicken",
         "study_abstract": "Exploring how a high fat diet changes the "
                           "gut microbiome",
         "principal_investigator_id": StudyPerson(3),
         "lab_person_id": StudyPerson(1)
     }
     self.new_study = Study.create(
         User('*****@*****.**'), "Fried Chicken Microbiome", info)
     self._clean_up_files = []
Beispiel #49
0
    def test_create_sample_template(self):
        # Test error
        job = self._create_job(
            'create_sample_template', {
                'fp': self.fp,
                'study_id': 1,
                'is_mapping_file': False,
                'data_type': None
            })
        private_task(job.id)
        self.assertEqual(job.status, 'error')
        self.assertIn(
            "The 'SampleTemplate' object with attributes (id: 1) "
            "already exists.", job.log.msg)

        # Test success with a warning
        info = {
            "timeseries_type_id": '1',
            "metadata_complete": 'true',
            "mixs_compliant": 'true',
            "study_alias": "TDST",
            "study_description": "Test create sample template",
            "study_abstract": "Test create sample template",
            "principal_investigator_id": StudyPerson(1)
        }
        study = Study.create(User('*****@*****.**'),
                             "Create Sample Template test", info)
        job = self._create_job(
            'create_sample_template', {
                'fp': self.fp,
                'study_id': study.id,
                'is_mapping_file': False,
                'data_type': None
            })
        private_task(job.id)
        self.assertEqual(job.status, 'success')
        obs = r_client.get("sample_template_%d" % study.id)
        self.assertIsNotNone(obs)
        obs = loads(obs)
        self.assertCountEqual(obs, ['job_id', 'alert_type', 'alert_msg'])
        self.assertEqual(obs['job_id'], job.id)
        self.assertEqual(obs['alert_type'], 'warning')
        self.assertIn(
            'Some functionality will be disabled due to missing columns:',
            obs['alert_msg'])
        # making sure that the error name is not in the messages
        self.assertNotIn('QiitaDBWarning', obs['alert_msg'])
Beispiel #50
0
    def test_delete_sample_template(self):
        # Error case
        job = self._create_job('delete_sample_template', {'study': 1})
        private_task(job.id)
        self.assertEqual(job.status, 'error')
        self.assertIn(
            "Sample template cannot be erased because there are "
            "prep templates associated", job.log.msg)

        # Success case
        info = {
            "timeseries_type_id": '1',
            "metadata_complete": 'true',
            "mixs_compliant": 'true',
            "number_samples_collected": 25,
            "number_samples_promised": 28,
            "study_alias": "TDST",
            "study_description": "Test delete sample template",
            "study_abstract": "Test delete sample template",
            "principal_investigator_id": StudyPerson(1)
        }
        study = Study.create(User('*****@*****.**'),
                             "Delete Sample Template test", info)
        metadata = pd.DataFrame.from_dict(
            {
                'Sample1': {
                    'physical_specimen_location': 'location1',
                    'physical_specimen_remaining': 'true',
                    'dna_extracted': 'true',
                    'sample_type': 'type1',
                    'collection_timestamp': '2014-05-29 12:24:15',
                    'host_subject_id': 'NotIdentified',
                    'Description': 'Test Sample 1',
                    'latitude': '42.42',
                    'longitude': '41.41',
                    'taxon_id': '9606',
                    'scientific_name': 'h**o sapiens'
                }
            },
            orient='index',
            dtype=str)
        SampleTemplate.create(metadata, study)

        job = self._create_job('delete_sample_template', {'study': study.id})
        private_task(job.id)
        self.assertEqual(job.status, 'success')
        self.assertFalse(SampleTemplate.exists(study.id))
Beispiel #51
0
    def test_create_study_all_data(self):
        """Insert a study into the database with every info field"""
        self.info.update(
            {
                "vamps_id": "MBE_1111111",
                "funding": "FundAgency",
                "spatial_series": True,
                "metadata_complete": False,
                "reprocess": True,
                "first_contact": "10/24/2014 12:47PM",
                "study_id": 3827,
            }
        )
        obs = Study.create(User("*****@*****.**"), "Fried chicken microbiome", [1], self.info)
        self.assertEqual(obs.id, 3827)
        exp = {
            "mixs_compliant": True,
            "metadata_complete": False,
            "reprocess": True,
            "number_samples_promised": 28,
            "emp_person_id": 2,
            "funding": "FundAgency",
            "vamps_id": "MBE_1111111",
            "first_contact": datetime(2014, 10, 24, 12, 47),
            "principal_investigator_id": 3,
            "timeseries_type_id": 1,
            "study_abstract": "Exploring how a high fat diet changes the " "gut microbiome",
            "email": "*****@*****.**",
            "spatial_series": True,
            "study_description": "Microbiome of people who eat nothing " "but fried chicken",
            "study_alias": "FCM",
            "study_id": 3827,
            "most_recent_contact": None,
            "lab_person_id": 1,
            "study_title": "Fried chicken microbiome",
            "number_samples_collected": 25,
        }
        obsins = self.conn_handler.execute_fetchall("SELECT * FROM qiita.study WHERE study_id = 3827")
        self.assertEqual(len(obsins), 1)
        obsins = dict(obsins[0])
        self.assertEqual(obsins, exp)

        # make sure EFO went in to table correctly
        obsefo = self.conn_handler.execute_fetchall(
            "SELECT efo_id FROM qiita.study_experimental_factor " "WHERE study_id = 3827"
        )
        self.assertEqual(obsefo, [[1]])
Beispiel #52
0
    def setUp(self):
        # Create a sample template file
        self.st_contents = SAMPLE_TEMPLATE

        # create a new study to attach the sample template
        info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "number_samples_collected": 4,
            "number_samples_promised": 4,
            "portal_type_id": 3,
            "study_alias": "TestStudy",
            "study_description": "Description of a test study",
            "study_abstract": "No abstract right now...",
            "emp_person_id": StudyPerson(2),
            "principal_investigator_id": StudyPerson(3),
            "lab_person_id": StudyPerson(1)
        }
        self.study = Study.create(User('*****@*****.**'),
                                  "Test study", [1], info)
Beispiel #53
0
    def test_get_no_access(self):
        # Create a new study belonging to the 'shared' user, so 'test' doesn't
        # have access
        info = {
            'timeseries_type_id': 1,
            'lab_person_id': None,
            'principal_investigator_id': 3,
            'metadata_complete': False,
            'mixs_compliant': True,
            'study_description': 'desc',
            'study_alias': 'alias',
            'study_abstract': 'abstract'
        }
        u = User('*****@*****.**')
        s = Study.create(u, 'test_study', efo=[1], info=info)
        self.assertEqual(s.shared_with, [])

        args = {'selected': '*****@*****.**', 'id': s.id}
        response = self.get('/study/sharing/', args)
        self.assertEqual(response.code, 403)
        self.assertEqual(s.shared_with, [])
Beispiel #54
0
 def test_set_info(self):
     """Set info in a study"""
     newinfo = {
         "timeseries_type_id": 2,
         "metadata_complete": False,
         "number_samples_collected": 28,
         "lab_person_id": StudyPerson(2),
         "vamps_id": 'MBE_111222',
         "first_contact": "June 11, 2014"
     }
     new = Study.create(
         User('*****@*****.**'), 'NOT Identification of the '
         'Microbiomes for Cannabis Soils', [1], self.info)
     self.infoexp.update(newinfo)
     new.info = newinfo
     # add missing table cols
     self.infoexp["funding"] = None
     self.infoexp["spatial_series"] = None
     self.infoexp["most_recent_contact"] = None
     self.infoexp["reprocess"] = False
     self.infoexp["lab_person_id"] = 2
     self.assertEqual(new.info, self.infoexp)
Beispiel #55
0
    def test_get_study_no_samples(self):
        info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "study_alias": "FCM",
            "study_description": "DESC",
            "study_abstract": "ABS",
            "principal_investigator_id": StudyPerson(3),
            'first_contact': datetime(2015, 5, 19, 16, 10),
            'most_recent_contact': datetime(2015, 5, 19, 16, 11),
        }

        new_study = Study.create(User('*****@*****.**'),
                                 "Some New Study for test", info)

        exp = []
        response = self.get('/api/v1/study/%d/samples' % new_study.id,
                            headers=self.headers)
        self.assertEqual(response.code, 200)
        obs = json_decode(response.body)
        self.assertEqual(obs, exp)
Beispiel #56
0
 def test_retrieve_processed_data_none(self):
     new = Study.create(
         User('*****@*****.**'), 'NOT Identification of the '
         'Microbiomes for Cannabis Soils', [1], self.info)
     self.assertEqual(new.processed_data(), [])
Beispiel #57
0
    def generate_new_study_with_preprocessed_data(self):
        """Creates a new study up to the processed data for testing"""
        info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "number_samples_collected": 3,
            "number_samples_promised": 3,
            "study_alias": "Test EBI",
            "study_description": "Study for testing EBI",
            "study_abstract": "Study for testing EBI",
            "emp_person_id": StudyPerson(2),
            "principal_investigator_id": StudyPerson(3),
            "lab_person_id": StudyPerson(1)
        }
        study = Study.create(User('*****@*****.**'), "Test EBI study", info)
        metadata_dict = {
            'Sample1': {
                'collection_timestamp': datetime(2015, 6, 1, 7, 0, 0),
                'physical_specimen_location': 'location1',
                'taxon_id': 9606,
                'scientific_name': 'h**o sapiens',
                'Description': 'Test Sample 1'
            },
            'Sample2': {
                'collection_timestamp': datetime(2015, 6, 2, 7, 0, 0),
                'physical_specimen_location': 'location1',
                'taxon_id': 9606,
                'scientific_name': 'h**o sapiens',
                'Description': 'Test Sample 2'
            },
            'Sample3': {
                'collection_timestamp': datetime(2015, 6, 3, 7, 0, 0),
                'physical_specimen_location': 'location1',
                'taxon_id': 9606,
                'scientific_name': 'h**o sapiens',
                'Description': 'Test Sample 3'
            }
        }
        metadata = pd.DataFrame.from_dict(metadata_dict,
                                          orient='index',
                                          dtype=str)
        SampleTemplate.create(metadata, study)
        metadata_dict = {
            'Sample1': {
                'primer': 'GTGCCAGCMGCCGCGGTAA',
                'barcode': 'CGTAGAGCTCTC',
                'center_name': 'KnightLab',
                'platform': 'ILLUMINA',
                'instrument_model': 'Illumina MiSeq',
                'library_construction_protocol': 'Protocol ABC',
                'experiment_design_description': "Random value 1"
            },
            'Sample2': {
                'primer': 'GTGCCAGCMGCCGCGGTAA',
                'barcode': 'CGTAGAGCTCTA',
                'center_name': 'KnightLab',
                'platform': 'ILLUMINA',
                'instrument_model': 'Illumina MiSeq',
                'library_construction_protocol': 'Protocol ABC',
                'experiment_design_description': "Random value 2"
            },
            'Sample3': {
                'primer': 'GTGCCAGCMGCCGCGGTAA',
                'barcode': 'CGTAGAGCTCTT',
                'center_name': 'KnightLab',
                'platform': 'ILLUMINA',
                'instrument_model': 'Illumina MiSeq',
                'library_construction_protocol': 'Protocol ABC',
                'experiment_design_description': "Random value 3"
            },
        }
        metadata = pd.DataFrame.from_dict(metadata_dict,
                                          orient='index',
                                          dtype=str)
        pt = PrepTemplate.create(metadata, study, "16S", 'Metagenomics')
        fna_fp = join(self.temp_dir, 'seqs.fna')
        demux_fp = join(self.temp_dir, 'demux.seqs')
        with open(fna_fp, 'w') as f:
            f.write(FASTA_EXAMPLE_2.format(study.id))
        with File(demux_fp, 'w') as f:
            to_hdf5(fna_fp, f)

        ppd = Artifact.create([(demux_fp, 6)],
                              "Demultiplexed",
                              prep_template=pt)

        return ppd
Beispiel #58
0
 def test_environmental_packages_setter_valueerror(self):
     new = Study.create(
         User('*****@*****.**'), 'NOT Identification of the '
         'Microbiomes for Cannabis Soils', [1], self.info)
     with self.assertRaises(ValueError):
         new.environmental_packages = ['air', 'not a package']
Beispiel #59
0
 def test_retrieve_investigation_empty(self):
     new = Study.create(
         User('*****@*****.**'), 'NOT Identification of the '
         'Microbiomes for Cannabis Soils', [1], self.info)
     self.assertEqual(new.investigation, None)
Beispiel #60
0
    def post(self, study=None):
        the_study = None
        form_factory = StudyEditorExtendedForm
        if study:
            # Check study and user access
            the_study = self._check_study_exists_and_user_access(study)
            # If the study is not sandbox, we use the short version
            if the_study.status != 'sandbox':
                form_factory = StudyEditorForm

        # Get the form data from the request arguments
        form_data = form_factory()
        form_data.process(data=self.request.arguments)

        # Get information about new people that need to be added to the DB
        # Phones and addresses are optional, so make sure that we have None
        # values instead of empty strings
        new_people_info = [(name, email, affiliation, phone or None, address
                            or None)
                           for name, email, affiliation, phone, address in zip(
                               self.get_arguments('new_people_names'),
                               self.get_arguments('new_people_emails'),
                               self.get_arguments('new_people_affiliations'),
                               self.get_arguments('new_people_phones'),
                               self.get_arguments('new_people_addresses'))]

        # New people will be indexed with negative numbers, so we reverse
        # the list here
        new_people_info.reverse()

        index = int(form_data.data['principal_investigator'][0])
        PI = self._get_study_person_id(index, new_people_info)

        if form_data.data['lab_person'][0]:
            index = int(form_data.data['lab_person'][0])
            lab_person = self._get_study_person_id(index, new_people_info)
        else:
            lab_person = None

        # TODO: MIXS compliant?  Always true, right?
        info = {
            'lab_person_id': lab_person,
            'principal_investigator_id': PI,
            'metadata_complete': False,
            'mixs_compliant': True,
            'study_description': form_data.data['study_description'][0],
            'study_alias': form_data.data['study_alias'][0],
            'study_abstract': form_data.data['study_abstract'][0]
        }

        if 'timeseries' in form_data.data and form_data.data['timeseries']:
            info['timeseries_type_id'] = form_data.data['timeseries'][0]

        study_title = form_data.data['study_title'][0]

        if the_study:
            # We are under editing, so just update the values
            the_study.title = study_title
            the_study.info = info

            msg = ('Study <a href="/study/description/%d">%s</a> '
                   'successfully updated' %
                   (the_study.id, form_data.data['study_title'][0]))
        else:
            # create the study
            # TODO: Fix this EFO once ontology stuff from emily is added
            the_study = Study.create(self.current_user,
                                     study_title,
                                     efo=[1],
                                     info=info)

            msg = ('Study <a href="/study/description/%d">%s</a> '
                   'successfully created' %
                   (the_study.id, form_data.data['study_title'][0]))

        # Add the environmental packages, this attribute can only be edited
        # if the study is not public, otherwise this cannot be changed
        if isinstance(form_data, StudyEditorExtendedForm):
            the_study.environmental_packages = form_data.data[
                'environmental_packages']

        dois = form_data.data['publication_doi']
        if dois and dois[0]:
            # The user can provide a comma-seprated list
            dois = dois[0].split(',')
            # Make sure that we strip the spaces from the pubmed ids
            the_study.publications = [(doi.strip(), None) for doi in dois]

        self.render('index.html', message=msg, level='success')