Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def get(self, *args, **kwargs):
        name = self.get_argument('name', None)
        affiliation = self.get_argument('affiliation', None)

        if name is None and affiliation is None:
            # Retrieve the list of all the StudyPerson
            sp = [{
                'name': p.name,
                'affiliation': p.affiliation
            } for p in StudyPerson.iter()]
            self.write(json_encode(sp))
            self.finish()
        elif name is not None and affiliation is not None:
            try:
                p = StudyPerson.from_name_and_affiliation(name, affiliation)
            except QiitaDBLookupError:
                self.fail('Person not found', 404)
                return
            self.write({
                'address': p.address,
                'phone': p.phone,
                'email': p.email,
                'id': p.id
            })
            self.finish()
        else:
            arg_name = 'name' if name is None else 'affiliation'
            raise MissingArgumentError(arg_name)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
    def __init__(self, study=None, **kwargs):
        super(StudyEditorForm, self).__init__(**kwargs)

        # Get people from the study_person table to populate the PI and
        # lab_person fields
        choices = [(sp.id, u"%s, %s" % (sp.name, sp.affiliation))
                   for sp in StudyPerson.iter()]
        choices.insert(0, ('', ''))

        self.lab_person.choices = choices
        self.principal_investigator.choices = choices

        # If a study is provided, put its values in the form
        if study:
            study_info = study.info

            self.study_title.data = study.title
            self.study_alias.data = study_info['study_alias']
            dois = []
            pids = []
            for p, is_doi in study.publications:
                if is_doi:
                    dois.append(p)
                else:
                    pids.append(p)
            self.publication_doi.data = ",".join(dois)
            self.publication_pid.data = ",".join(pids)
            self.study_abstract.data = study_info['study_abstract']
            self.study_description.data = study_info['study_description']
            self.principal_investigator.data = study_info[
                'principal_investigator'].id
            self.lab_person.data = (study_info['lab_person'].id
                                    if study_info['lab_person'] else None)
            self.notes.data = study.notes
Ejemplo n.º 8
0
def _build_study_info(studytype, user=None):
    """builds list of namedtuples for study listings"""
    if studytype == "private":
        studylist = user.user_studies
    elif studytype == "shared":
        studylist = user.shared_studies
    elif studytype == "public":
        studylist = Study.get_by_status('public')
    else:
        raise IncompetentQiitaDeveloperError("Must use private, shared, "
                                             "or public!")

    StudyTuple = namedtuple(
        'StudyInfo', 'id title meta_complete '
        'num_samples_collected shared num_raw_data pi '
        'pmids owner status')

    infolist = []
    for s_id in studylist:
        study = Study(s_id)
        status = study.status
        # Just passing the email address as the name here, since
        # name is not a required field in qiita.qiita_user
        owner = study_person_linkifier((study.owner, study.owner))
        info = study.info
        PI = StudyPerson(info['principal_investigator_id'])
        PI = study_person_linkifier((PI.email, PI.name))
        pmids = ", ".join([pubmed_linkifier([pmid]) for pmid in study.pmids])
        shared = _get_shared_links_for_study(study)
        infolist.append(
            StudyTuple(study.id, study.title, info["metadata_complete"],
                       info["number_samples_collected"], shared,
                       len(study.raw_data()), PI, pmids, owner, status))
    return infolist
Ejemplo n.º 9
0
    def __init__(self, study=None, **kwargs):
        super(StudyEditorForm, self).__init__(**kwargs)

        # Get people from the study_person table to populate the PI and
        # lab_person fields
        choices = [(sp.id, u"%s, %s" %
                    (sp.name.decode('utf-8'), sp.affiliation.decode('utf-8')))
                   for sp in StudyPerson.iter()]
        choices.insert(0, ('', ''))

        self.lab_person.choices = choices
        self.principal_investigator.choices = choices

        # If a study is provided, put its values in the form
        if study:
            study_info = study.info

            self.study_title.data = study.title.decode('utf-8')
            self.study_alias.data = study_info['study_alias'].decode('utf-8')
            self.publication_doi.data = ",".join(
                [doi for doi, _ in study.publications]).decode('utf-8')
            self.study_abstract.data = study_info['study_abstract'].decode(
                'utf-8')
            self.study_description.data = study_info[
                'study_description'].decode('utf-8')
            self.principal_investigator.data = study_info[
                'principal_investigator_id']
            self.lab_person.data = study_info['lab_person_id']
Ejemplo n.º 10
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 = []
Ejemplo n.º 11
0
    def __init__(self, study=None, **kwargs):
        super(StudyEditorForm, self).__init__(**kwargs)

        # Get people from the study_person table to populate the PI and
        # lab_person fields
        choices = [(sp.id, u"%s, %s"
                    % (sp.name.decode('utf-8'),
                       sp.affiliation.decode('utf-8')))
                   for sp in StudyPerson.iter()]
        choices.insert(0, ('', ''))

        self.lab_person.choices = choices
        self.principal_investigator.choices = choices

        # If a study is provided, put its values in the form
        if study:
            study_info = study.info

            self.study_title.data = study.title.decode('utf-8')
            self.study_alias.data = study_info['study_alias'].decode('utf-8')
            self.publication_doi.data = ",".join(
                [doi for doi, _ in study.publications]).decode('utf-8')
            self.study_abstract.data = study_info[
                'study_abstract'].decode('utf-8')
            self.study_description.data = study_info[
                'study_description'].decode('utf-8')
            self.principal_investigator.data = study_info[
                'principal_investigator'].id
            self.lab_person.data = (study_info['lab_person'].id
                                    if study_info['lab_person'] else None)
Ejemplo n.º 12
0
 def test_create_studyperson(self):
     new = StudyPerson.create('SomeDude', '*****@*****.**', 'affil',
                              '111 fake street', '111-121-1313')
     self.assertEqual(new.id, 4)
     obs = self.conn_handler.execute_fetchall(
         "SELECT * FROM qiita.study_person WHERE study_person_id = 4")
     self.assertEqual(obs, [[4, 'SomeDude', '*****@*****.**', 'affil',
                      '111 fake street', '111-121-1313']])
Ejemplo n.º 13
0
    def post(self, *args, **kwargs):
        name = self.get_argument('name')
        affiliation = self.get_argument('affiliation')
        email = self.get_argument('email')

        phone = self.get_argument('phone', None)
        address = self.get_argument('address', None)

        if StudyPerson.exists(name, affiliation):
            self.fail('Person already exists', 409)
            return

        p = StudyPerson.create(name=name, affiliation=affiliation, email=email,
                               phone=phone, address=address)

        self.set_status(201)
        self.write({'id': p.id})
        self.finish()
Ejemplo n.º 14
0
 def test_create_studyperson(self):
     new = StudyPerson.create('SomeDude', '*****@*****.**', 'affil',
                              '111 fake street', '111-121-1313')
     self.assertEqual(new.id, 4)
     obs = self.conn_handler.execute_fetchall(
         "SELECT * FROM qiita.study_person WHERE study_person_id = 4")
     self.assertEqual(obs, [[
         4, 'SomeDude', '*****@*****.**', 'affil', '111 fake street',
         '111-121-1313'
     ]])
Ejemplo n.º 15
0
    def test_post_new_person(self):
        body = {'name': 'Boaty McBoatFace', 'affiliation': 'UCSD',
                'email': '*****@*****.**', 'phone': '720-876-5309'}

        response = self.post('/api/v1/person', data=body, headers=self.headers)
        self.assertEqual(response.code, 201)
        obs = json_decode(response.body)
        exp = StudyPerson.from_name_and_affiliation(body['name'],
                                                    body['affiliation']).id
        self.assertEqual(exp, obs['id'])
Ejemplo n.º 16
0
def _build_single_study_info(study, info, study_proc, proc_samples):
    """Clean up and add to the study info for HTML purposes

    Parameters
    ----------
    study : Study object
        The study to build information for
    info : dict
        Information from Study.get_info
    study_proc : dict of dict of lists
        Dictionary keyed on study_id that lists all processed data associated
        with that study. This list of processed data ids is keyed by data type
    proc_samples : dict of lists
        Dictionary keyed on proc_data_id that lists all samples associated with
        that processed data.

    Returns
    -------
    dict
        info-information + extra information for the study,
        slightly HTML formatted
    """
    PI = StudyPerson(info['principal_investigator_id'])
    status = study.status
    if info['publication_doi'] is not None:
        pmids = get_pubmed_ids_from_dois(info['publication_doi']).values()
        info['pmid'] = ", ".join([pubmed_linkifier([p]) for p in pmids])
        info['publication_doi'] = ", ".join(
            [doi_linkifier([p]) for p in info['publication_doi']])

    else:
        info['publication_doi'] = ""
        info['pmid'] = ""
    if info["number_samples_collected"] is None:
        info["number_samples_collected"] = 0
    info["shared"] = _get_shared_links_for_study(study)
    # raw data is any artifact that is not Demultiplexed or BIOM

    info["num_raw_data"] = len([
        a for a in study.artifacts()
        if a.artifact_type not in ['Demultiplexed', 'BIOM']
    ])
    info["status"] = status
    info["study_id"] = study.id
    info["pi"] = study_person_linkifier((PI.email, PI.name))
    del info["principal_investigator_id"]
    del info["email"]
    # Build the proc data info list for the child row in datatable
    info["proc_data_info"] = []
    for data_type, proc_datas in viewitems(study_proc[study.id]):
        info["proc_data_info"].extend([
            _build_single_proc_data_info(pd_id, data_type, proc_samples[pd_id])
            for pd_id in proc_datas
        ])
    return info
Ejemplo n.º 17
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)
Ejemplo n.º 18
0
    def post(self, *args, **kwargs):
        name = self.get_argument('name')
        affiliation = self.get_argument('affiliation')
        email = self.get_argument('email')

        phone = self.get_argument('phone', None)
        address = self.get_argument('address', None)

        if StudyPerson.exists(name, affiliation):
            self.fail('Person already exists', 409)
            return

        p = StudyPerson.create(name=name,
                               affiliation=affiliation,
                               email=email,
                               phone=phone,
                               address=address)

        self.set_status(201)
        self.write({'id': p.id})
        self.finish()
Ejemplo n.º 19
0
    def get(self, *args, **kwargs):
        name = self.get_argument('name', None)
        affiliation = self.get_argument('affiliation', None)

        if name is None and affiliation is None:
            # Retrieve the list of all the StudyPerson
            sp = [{'name': p.name, 'affiliation': p.affiliation}
                  for p in StudyPerson.iter()]
            self.write(json_encode(sp))
            self.finish()
        elif name is not None and affiliation is not None:
            try:
                p = StudyPerson.from_name_and_affiliation(name, affiliation)
            except QiitaDBLookupError:
                self.fail('Person not found', 404)
                return
            self.write({'address': p.address, 'phone': p.phone,
                        'email': p.email, 'id': p.id})
            self.finish()
        else:
            arg_name = 'name' if name is None else 'affiliation'
            raise MissingArgumentError(arg_name)
Ejemplo n.º 20
0
 def test_iter(self):
     """Make sure that each and every StudyPerson is retrieved"""
     expected = [
         ('LabDude', '*****@*****.**', 'knight lab', '123 lab street',
          '121-222-3333'),
         ('empDude', '*****@*****.**', 'broad', None, '444-222-3333'),
         ('PIDude', '*****@*****.**', 'Wash U', '123 PI street', None)]
     for i, person in enumerate(StudyPerson.iter()):
         self.assertEqual(person.id, i+1)
         self.assertEqual(person.name, expected[i][0])
         self.assertEqual(person.email, expected[i][1])
         self.assertEqual(person.affiliation, expected[i][2])
         self.assertEqual(person.address, expected[i][3])
         self.assertEqual(person.phone, expected[i][4])
Ejemplo n.º 21
0
    def test_post_new_person(self):
        body = {
            'name': 'Boaty McBoatFace',
            'affiliation': 'UCSD',
            'email': '*****@*****.**',
            'phone': '720-876-5309'
        }

        response = self.post('/api/v1/person', data=body, headers=self.headers)
        self.assertEqual(response.code, 201)
        obs = json_decode(response.body)
        exp = StudyPerson.from_name_and_affiliation(body['name'],
                                                    body['affiliation']).id
        self.assertEqual(exp, obs['id'])
Ejemplo n.º 22
0
 def test_iter(self):
     """Make sure that each and every StudyPerson is retrieved"""
     expected = [
         ("LabDude", "*****@*****.**", "knight lab", "123 lab street", "121-222-3333"),
         ("empDude", "*****@*****.**", "broad", None, "444-222-3333"),
         ("PIDude", "*****@*****.**", "Wash U", "123 PI street", None),
     ]
     for i, person in enumerate(StudyPerson.iter()):
         self.assertTrue(person.id == i + 1)
         self.assertTrue(person.name == expected[i][0])
         self.assertTrue(person.email == expected[i][1])
         self.assertTrue(person.affiliation == expected[i][2])
         self.assertTrue(person.address == expected[i][3])
         self.assertTrue(person.phone == expected[i][4])
Ejemplo n.º 23
0
 def test_iter(self):
     """Make sure that each and every StudyPerson is retrieved"""
     expected = [
         ('LabDude', '*****@*****.**', 'knight lab', '123 lab street',
          '121-222-3333'),
         ('empDude', '*****@*****.**', 'broad', None, '444-222-3333'),
         ('PIDude', '*****@*****.**', 'Wash U', '123 PI street', None)
     ]
     for i, person in enumerate(StudyPerson.iter()):
         self.assertTrue(person.id == i + 1)
         self.assertTrue(person.name == expected[i][0])
         self.assertTrue(person.email == expected[i][1])
         self.assertTrue(person.affiliation == expected[i][2])
         self.assertTrue(person.address == expected[i][3])
         self.assertTrue(person.phone == expected[i][4])
Ejemplo n.º 24
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'])
Ejemplo n.º 25
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))
Ejemplo n.º 26
0
    def get(self):
        creation_form = CreateStudyForm()

        # Get people from the study_person table to populate the PI and
        # lab_person fields
        choices = [('', '')]
        for study_person in StudyPerson.iter():
            person = "{}, {}".format(study_person.name,
                                     study_person.affiliation)
            choices.append((study_person.id, person))

        creation_form.lab_person.choices = choices
        creation_form.principal_investigator.choices = choices

        # TODO: set the choices attributes on the investigation_type field
        # TODO: set the choices attributes on the environmental_package field
        self.render('create_study.html', user=self.current_user,
                    creation_form=creation_form)
Ejemplo n.º 27
0
    def render(self, study):
        study_info = study.info
        abstract = study_info['study_abstract']
        description = study_info['study_description']
        pmids = ", ".join([pubmed_linkifier([pmid]) for pmid in study.pmids])
        princ_inv = StudyPerson(study_info['principal_investigator_id'])
        pi_link = study_person_linkifier((princ_inv.email, princ_inv.name))
        number_samples_promised = study_info['number_samples_promised']
        number_samples_collected = study_info['number_samples_collected']
        metadata_complete = study_info['metadata_complete']

        # Retrieve the files from the uploads folder, so the user can choose
        # the sample template of the study
        files = [f for _, f in get_files_from_uploads_folders(str(study.id))]

        # If the sample template exists, retrieve all its filepaths
        if SampleTemplate.exists(study.id):
            sample_templates = SampleTemplate(study.id).get_filepaths()
        else:
            # If the sample template does not exist, just pass an empty list
            sample_templates = []

        # Check if the request came from a local source
        is_local_request = self._is_local()

        # The user can choose the sample template only if the study is
        # sandboxed or the current user is an admin
        show_select_sample = (
            study.status == 'sandbox' or self.current_user.level == 'admin')

        return self.render_string(
            "study_description_templates/study_information_tab.html",
            abstract=abstract,
            description=description,
            pmids=pmids,
            principal_investigator=pi_link,
            number_samples_promised=number_samples_promised,
            number_samples_collected=number_samples_collected,
            metadata_complete=metadata_complete,
            show_select_sample=show_select_sample,
            files=files,
            study_id=study.id,
            sample_templates=sample_templates,
            is_local_request=is_local_request)
Ejemplo n.º 28
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)
Ejemplo n.º 29
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)
Ejemplo n.º 30
0
    def test_post(self):
        person_count_before = get_count('qiita.study_person')
        study_count_before = get_count('qiita.study')

        post_data = {
            'new_people_names': ['Adam', 'Ethan'],
            'new_people_emails': ['*****@*****.**', '*****@*****.**'],
            'new_people_affiliations': ['CU Boulder', 'NYU'],
            'new_people_addresses': ['Some St., Boulder, CO 80305', ''],
            'new_people_phones': ['', ''],
            'study_title': 'dummy title',
            'study_alias': 'dummy alias',
            'pubmed_id': 'dummy pmid',
            'environmental_packages': ['air'],
            'timeseries': '1',
            'study_abstract': "dummy abstract",
            'study_description': 'dummy description',
            'principal_investigator': '-2',
            'notes': '',
            'lab_person': '1'
        }

        self.post('/study/create/', post_data)

        # Check that the new person was created
        expected_id = person_count_before + 1
        self.assertTrue(check_count('qiita.study_person', expected_id))

        new_person = StudyPerson(expected_id)
        self.assertTrue(new_person.name == 'Ethan')
        self.assertTrue(new_person.email == '*****@*****.**')
        self.assertTrue(new_person.affiliation == 'NYU')
        self.assertTrue(new_person.address is None)
        self.assertTrue(new_person.phone is None)

        # Check the study was created
        expected_id = study_count_before + 1
        self.assertTrue(check_count('qiita.study', expected_id))
Ejemplo n.º 31
0
    def _get_study_person_id(self, index, new_people_info):
        """Returns the id of the study person, creating if needed

        If index < 0, means that we need to create a new study person, and its
        information is stored in new_people_info[index]

        Parameters
        ----------
        index : int
            The index of the study person
        new_people_info : list of tuples
            The information of the new study persons added through the
            interface

        Returns
        -------
        int
            the study person id
        """
        # If the ID is less than 0, then this is a new person
        if index < 0:
            return StudyPerson.create(*new_people_info[index]).id

        return index
Ejemplo n.º 32
0
    def __init__(self, study=None, **kwargs):
        super(StudyEditorForm, self).__init__(**kwargs)

        # Get people from the study_person table to populate the PI and
        # lab_person fields
        choices = [(sp.id, "%s, %s" % (sp.name, sp.affiliation))
                   for sp in StudyPerson.iter()]
        choices.insert(0, ('', ''))

        self.lab_person.choices = choices
        self.principal_investigator.choices = choices

        # If a study is provided, put its values in the form
        if study:
            study_info = study.info

            self.study_title.data = study.title
            self.study_alias.data = study_info['study_alias']
            self.pubmed_id.data = ",".join(study.pmids)
            self.study_abstract.data = study_info['study_abstract']
            self.study_description.data = study_info['study_description']
            self.principal_investigator.data = study_info[
                'principal_investigator_id']
            self.lab_person.data = study_info['lab_person_id']
Ejemplo n.º 33
0
    def _get_study_person_id(self, index, new_people_info):
        """Returns the id of the study person, creating if needed

        If index < 0, means that we need to create a new study person, and its
        information is stored in new_people_info[index]

        Parameters
        ----------
        index : int
            The index of the study person
        new_people_info : list of tuples
            The information of the new study persons added through the
            interface

        Returns
        -------
        int
            the study person id
        """
        # If the ID is less than 0, then this is a new person
        if index < 0:
            return StudyPerson.create(*new_people_info[index]).id

        return index
Ejemplo n.º 34
0
 def test_retrieve_phone_null(self):
     person = StudyPerson(3)
     self.assertEqual(person.phone, None)
Ejemplo n.º 35
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
Ejemplo n.º 36
0
 def test_create_studyperson(self):
     new = StudyPerson.create("SomeDude", "*****@*****.**", "affil", "111 fake street", "111-121-1313")
     self.assertEqual(new.id, 4)
     obs = self.conn_handler.execute_fetchall("SELECT * FROM qiita.study_person WHERE study_person_id = 4")
     self.assertEqual(obs, [[4, "SomeDude", "*****@*****.**", "affil", "111 fake street", "111-121-1313"]])
Ejemplo n.º 37
0
 def setUp(self):
     StudyPerson.create('SomeDude', '*****@*****.**', 'some',
                        '111 fake street', '111-121-1313')
     User.create('*****@*****.**', 'password')
     self.config1 = CONFIG_1
     self.config2 = CONFIG_2
Ejemplo n.º 38
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 public, we use the short version of the form
            if the_study.status == 'public':
                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
        new_people_info = 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])
        if index < 0:
            # If the ID is less than 0, then this is a new person
            PI = StudyPerson.create(
                new_people_info[index][0],
                new_people_info[index][1],
                new_people_info[index][2],
                new_people_info[index][3] or None,
                new_people_info[index][4] or None).id
        else:
            PI = index

        if form_data.data['lab_person'][0]:
            index = int(form_data.data['lab_person'][0])
            if index < 0:
                # If the ID is less than 0, then this is a new person
                lab_person = StudyPerson.create(
                    new_people_info[index][0],
                    new_people_info[index][1],
                    new_people_info[index][2],
                    new_people_info[index][3] or None,
                    new_people_info[index][4] or None).id
            else:
                lab_person = index
        else:
            lab_person = None

        # TODO: Get the portal type from... somewhere
        # TODO: MIXS compliant?  Always true, right?
        info = {
            'portal_type_id': 1,
            '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(User(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
        if ('environmental_packages' in form_data.data and
                form_data.data['environmental_packages']):
            the_study.environmental_packages = form_data.data[
                'environmental_packages']

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

        self.render('index.html', message=msg, level='success',
                    user=self.current_user)
Ejemplo n.º 39
0
 def test_create_studyperson_already_exists(self):
     obs = StudyPerson.create('LabDude', '*****@*****.**', 'knight lab')
     self.assertEqual(obs.name, 'LabDude')
     self.assertEqual(obs.email, '*****@*****.**')
Ejemplo n.º 40
0
 def test_exists(self):
     self.assertTrue(StudyPerson.exists('LabDude', 'knight lab'))
     self.assertFalse(StudyPerson.exists('AnotherDude', 'knight lab'))
     self.assertFalse(StudyPerson.exists('LabDude', 'Another lab'))
Ejemplo n.º 41
0
 def test_create_studyperson_already_exists(self):
     obs = StudyPerson.create('LabDude', '*****@*****.**', 'knight lab')
     self.assertEqual(obs.name, 'LabDude')
     self.assertEqual(obs.email, '*****@*****.**')
Ejemplo n.º 42
0
 def test_create_studyperson_already_exists(self):
     obs = StudyPerson.create("LabDude", "*****@*****.**", "knight lab")
     self.assertEqual(obs.name, "LabDude")
     self.assertEqual(obs.email, "*****@*****.**")
Ejemplo n.º 43
0
    def render(self, study):
        study_info = study.info
        id = study.id
        abstract = study_info['study_abstract']
        description = study_info['study_description']
        publications = []
        for doi, pmid in study.publications:
            if doi is not None:
                publications.append(doi_linkifier([doi]))
            if pmid is not None:
                publications.append(pubmed_linkifier([pmid]))
        publications = ", ".join(publications)
        princ_inv = StudyPerson(study_info['principal_investigator_id'])
        pi_link = study_person_linkifier((princ_inv.email, princ_inv.name))
        number_samples_promised = study_info['number_samples_promised']
        number_samples_collected = study_info['number_samples_collected']
        metadata_complete = study_info['metadata_complete']

        data_types = sorted(viewitems(get_data_types()), key=itemgetter(1))

        # Retrieve the files from the uploads folder, so the user can choose
        # the sample template of the study. Filter them to only include the
        # ones that ends with 'txt' or 'tsv'.
        files = [
            f for _, f in get_files_from_uploads_folders(str(study.id))
            if f.endswith(('txt', 'tsv'))
        ]

        # If the sample template exists, retrieve all its filepaths
        if SampleTemplate.exists(study.id):
            sample_templates = SampleTemplate(study.id).get_filepaths()
        else:
            # If the sample template does not exist, just pass an empty list
            sample_templates = []

        # Check if the request came from a local source
        is_local_request = is_localhost(self.request.headers['host'])

        # The user can choose the sample template only if the study is
        # sandboxed or the current user is an admin
        show_select_sample = (study.status == 'sandbox'
                              or self.current_user.level == 'admin')

        # EBI information
        ebi_status = study.ebi_submission_status
        ebi_accession = study.ebi_study_accession
        if ebi_accession:
            ebi_accession = (EBI_LINKIFIER.format(ebi_accession))

        return self.render_string(
            "study_description_templates/study_information_tab.html",
            abstract=abstract,
            description=description,
            id=id,
            publications=publications,
            principal_investigator=pi_link,
            number_samples_promised=number_samples_promised,
            number_samples_collected=number_samples_collected,
            metadata_complete=metadata_complete,
            show_select_sample=show_select_sample,
            files=files,
            study_id=study.id,
            sample_templates=sample_templates,
            is_local_request=is_local_request,
            data_types=data_types,
            ebi_status=ebi_status,
            ebi_accession=ebi_accession)
Ejemplo n.º 44
0
 def test_retrieve_address_null(self):
     person = StudyPerson(2)
     self.assertEqual(person.address, None)