Exemplo n.º 1
0
    def test_study_prep_get_req(self):
        obs = study_prep_get_req(1, '*****@*****.**')
        exp = {'status': 'success',
               'message': '',
               'info': {'18S': [{
                   'id': 1,
                   'status': 'private',
                   'name': 'PREP 1 NAME',
                   'start_artifact_id': 1,
                   'start_artifact': 'FASTQ',
                   'youngest_artifact': 'BIOM - BIOM'}]}}
        self.assertEqual(obs, exp)

        # Add a new prep template
        pt = npt.assert_warns(
            qdb.exceptions.QiitaDBWarning,
            qdb.metadata_template.prep_template.PrepTemplate.create,
            pd.DataFrame({'new_col': {'1.SKD6.640190': 1}}),
            qdb.study.Study(1), '16S')
        obs = study_prep_get_req(1, '*****@*****.**')
        exp = {'status': 'success',
               'message': '',
               'info': {
                   '18S': [{'id': 1,
                            'status': 'private',
                            'name': 'PREP 1 NAME',
                            'start_artifact_id': 1,
                            'start_artifact': 'FASTQ',
                            'youngest_artifact': 'BIOM - BIOM'}],
                   '16S': [{'id': pt.id,
                            'status': 'sandbox',
                            'name': 'PREP %d NAME' % pt.id,
                            'start_artifact_id': None,
                            'start_artifact': None,
                            'youngest_artifact': None}]}}
        self.assertEqual(obs, exp)

        obs = study_prep_get_req(1, '*****@*****.**')
        self.assertEqual(obs, exp)

        qdb.artifact.Artifact(1).visibility = 'public'
        obs = study_prep_get_req(1, '*****@*****.**')
        exp = {'status': 'success',
               'message': '',
               'info': {
                   '18S': [{'id': 1,
                            'status': 'public',
                            'name': 'PREP 1 NAME',
                            'start_artifact_id': 1,
                            'start_artifact': 'FASTQ',
                            'youngest_artifact': 'BIOM - BIOM'}]}}
        self.assertEqual(obs, exp)
Exemplo n.º 2
0
 def test_study_prep_get_req_no_access(self):
     obs = study_prep_get_req(1, '*****@*****.**')
     exp = {
         'status': 'error',
         'message': 'User does not have access to study'
     }
     self.assertEqual(obs, exp)
Exemplo n.º 3
0
    def test_study_prep_get_req_failed_EBI(self):
        temp_dir = mkdtemp()
        self._clean_up_files.append(temp_dir)
        user_email = '*****@*****.**'

        # creating a (A) new study, (B) sample info, (C) prep without EBI
        # values

        # (A)
        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": qdb.study.StudyPerson(2),
            "principal_investigator_id": qdb.study.StudyPerson(3),
            "lab_person_id": qdb.study.StudyPerson(1)
        }
        study = qdb.study.Study.create(qdb.user.User(user_email),
                                       "Test EBI study", info)

        # (B)
        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)
        npt.assert_warns(
            qdb.exceptions.QiitaDBWarning,
            qdb.metadata_template.sample_template.SampleTemplate.create,
            metadata, study)

        # (C)
        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 = qdb.metadata_template.prep_template.PrepTemplate.create(
            metadata, study, "16S", 'Metagenomics')

        # making sure that the EBI values are empty
        exp = {
            ('%d.Sample3' % study.id): None,
            ('%d.Sample2' % study.id): None,
            ('%d.Sample1' % study.id): None
        }
        self.assertEqual(pt.ebi_experiment_accessions, exp)

        # actual test
        obs = study_prep_get_req(study.id, user_email)
        exp = {
            'info': {
                '16S': [{
                    'status': 'sandbox',
                    'name': 'Prep information %d' % pt.id,
                    'start_artifact': None,
                    'youngest_artifact': None,
                    'ebi_experiment': False,
                    'id': pt.id,
                    'start_artifact_id': None
                }]
            },
            'message': '',
            'status': 'success'
        }
        self.assertEqual(obs, exp)

        qdb.metadata_template.prep_template.PrepTemplate.delete(pt.id)
Exemplo n.º 4
0
    def test_study_prep_get_req(self):
        obs = study_prep_get_req(1, '*****@*****.**')
        exp = {
            'status': 'success',
            'message': '',
            'info': {
                '18S': [{
                    'id': 1,
                    'status': 'private',
                    'name': 'Prep information 1',
                    'start_artifact_id': 1,
                    'start_artifact': 'FASTQ',
                    'youngest_artifact': 'BIOM - BIOM',
                    'ebi_experiment': 27
                }, {
                    'id': 2,
                    'status': 'private',
                    'name': 'Prep information 2',
                    'start_artifact': 'BIOM',
                    'youngest_artifact': 'BIOM - BIOM',
                    'ebi_experiment': 27,
                    'start_artifact_id': 7
                }]
            }
        }
        self.assertEqual(obs, exp)

        # Add a new prep template
        pt = npt.assert_warns(
            qdb.exceptions.QiitaDBWarning,
            qdb.metadata_template.prep_template.PrepTemplate.create,
            pd.DataFrame({'new_col': {
                '1.SKD6.640190': 1
            }}), qdb.study.Study(1), '16S')
        obs = study_prep_get_req(1, '*****@*****.**')
        exp = {
            'status': 'success',
            'message': '',
            'info': {
                '18S': [{
                    'id': 1,
                    'status': 'private',
                    'name': 'Prep information 1',
                    'start_artifact_id': 1,
                    'start_artifact': 'FASTQ',
                    'youngest_artifact': 'BIOM - BIOM',
                    'ebi_experiment': 27
                }, {
                    'id': 2,
                    'status': 'private',
                    'name': 'Prep information 2',
                    'start_artifact_id': 7,
                    'start_artifact': 'BIOM',
                    'youngest_artifact': 'BIOM - BIOM',
                    'ebi_experiment': 27
                }],
                '16S': [{
                    'id': pt.id,
                    'status': 'sandbox',
                    'name': 'Prep information %d' % pt.id,
                    'start_artifact_id': None,
                    'start_artifact': None,
                    'youngest_artifact': None,
                    'ebi_experiment': 0
                }]
            }
        }
        self.assertEqual(obs, exp)

        obs = study_prep_get_req(1, '*****@*****.**')
        self.assertEqual(obs, exp)

        qdb.artifact.Artifact(1).visibility = 'public'
        obs = study_prep_get_req(1, '*****@*****.**')
        exp = {
            'status': 'success',
            'message': '',
            'info': {
                '18S': [{
                    'id': 1,
                    'status': 'public',
                    'name': 'Prep information 1',
                    'start_artifact_id': 1,
                    'start_artifact': 'FASTQ',
                    'youngest_artifact': 'BIOM - BIOM',
                    'ebi_experiment': 27
                }]
            }
        }
        self.assertEqual(obs, exp)
        # Reset visibility of the artifacts
        for i in range(4, 0, -1):
            qdb.artifact.Artifact(i).visibility = "private"

        qdb.metadata_template.prep_template.PrepTemplate.delete(pt.id)
Exemplo n.º 5
0
    def test_study_prep_get_req(self):
        obs = study_prep_get_req(1, '*****@*****.**')
        exp = {
            'status': 'success',
            'message': '',
            'info': {
                '18S': [{
                    'id': 1,
                    'status': 'private',
                    'name': 'PREP 1 NAME',
                    'start_artifact_id': 1,
                    'start_artifact': 'FASTQ',
                    'youngest_artifact': 'BIOM - BIOM'
                }]
            }
        }
        self.assertEqual(obs, exp)

        # Add a new prep template
        pt = npt.assert_warns(
            qdb.exceptions.QiitaDBWarning,
            qdb.metadata_template.prep_template.PrepTemplate.create,
            pd.DataFrame({'new_col': {
                '1.SKD6.640190': 1
            }}), qdb.study.Study(1), '16S')
        obs = study_prep_get_req(1, '*****@*****.**')
        exp = {
            'status': 'success',
            'message': '',
            'info': {
                '18S': [{
                    'id': 1,
                    'status': 'private',
                    'name': 'PREP 1 NAME',
                    'start_artifact_id': 1,
                    'start_artifact': 'FASTQ',
                    'youngest_artifact': 'BIOM - BIOM'
                }],
                '16S': [{
                    'id': pt.id,
                    'status': 'sandbox',
                    'name': 'PREP %d NAME' % pt.id,
                    'start_artifact_id': None,
                    'start_artifact': None,
                    'youngest_artifact': None
                }]
            }
        }
        self.assertEqual(obs, exp)

        obs = study_prep_get_req(1, '*****@*****.**')
        self.assertEqual(obs, exp)

        qdb.artifact.Artifact(1).visibility = 'public'
        obs = study_prep_get_req(1, '*****@*****.**')
        exp = {
            'status': 'success',
            'message': '',
            'info': {
                '18S': [{
                    'id': 1,
                    'status': 'public',
                    'name': 'PREP 1 NAME',
                    'start_artifact_id': 1,
                    'start_artifact': 'FASTQ',
                    'youngest_artifact': 'BIOM - BIOM'
                }]
            }
        }
        self.assertEqual(obs, exp)
Exemplo n.º 6
0
 def test_study_prep_get_req_no_access(self):
     obs = study_prep_get_req(1, '*****@*****.**')
     exp = {'status': 'error',
            'message': 'User does not have access to study'}
     self.assertEqual(obs, exp)
Exemplo n.º 7
0
    def test_study_prep_get_req_failed_EBI(self):
        temp_dir = mkdtemp()
        self._clean_up_files.append(temp_dir)
        user_email = '*****@*****.**'

        # creating a (A) new study, (B) sample info, (C) prep without EBI
        # values

        # (A)
        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": qdb.study.StudyPerson(2),
            "principal_investigator_id": qdb.study.StudyPerson(3),
            "lab_person_id": qdb.study.StudyPerson(1)
        }
        study = qdb.study.Study.create(
            qdb.user.User(user_email), "Test EBI study", info)

        # (B)
        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)
        npt.assert_warns(
            qdb.exceptions.QiitaDBWarning,
            qdb.metadata_template.sample_template.SampleTemplate.create,
            metadata, study)

        # (C)
        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 = qdb.metadata_template.prep_template.PrepTemplate.create(
            metadata, study, "16S", 'Metagenomics')

        # making sure that the EBI values are empty
        exp = {('%d.Sample3' % study.id): None,
               ('%d.Sample2' % study.id): None,
               ('%d.Sample1' % study.id): None}
        self.assertEqual(pt.ebi_experiment_accessions, exp)

        # actual test
        obs = study_prep_get_req(study.id, user_email)
        exp = {
            'info': {
                '16S': [
                    {'status': 'sandbox',
                     'name': 'Prep information %d' % pt.id,
                     'start_artifact': None, 'youngest_artifact': None,
                     'ebi_experiment': False, 'id': pt.id,
                     'start_artifact_id': None}]
            },
            'message': '',
            'status': 'success'}
        self.assertEqual(obs, exp)

        qdb.metadata_template.prep_template.PrepTemplate.delete(pt.id)
Exemplo n.º 8
0
    def test_study_prep_get_req(self):
        obs = study_prep_get_req(1, '*****@*****.**')
        exp = {'status': 'success',
               'message': '',
               'info': {
                   '18S': [{
                       'id': 1,
                       'status': 'private',
                       'name': 'Prep information 1',
                       'start_artifact_id': 1,
                       'start_artifact': 'FASTQ',
                       'youngest_artifact': 'BIOM - BIOM',
                       'ebi_experiment': 27}, {
                       'id': 2,
                       'status': 'private',
                       'name': 'Prep information 2',
                       'start_artifact': 'BIOM',
                       'youngest_artifact': 'BIOM - BIOM',
                       'ebi_experiment': 27,
                       'start_artifact_id': 7}]}}
        self.assertEqual(obs, exp)

        # Add a new prep template
        pt = npt.assert_warns(
            qdb.exceptions.QiitaDBWarning,
            qdb.metadata_template.prep_template.PrepTemplate.create,
            pd.DataFrame({'new_col': {'1.SKD6.640190': 1}}),
            qdb.study.Study(1), '16S')
        obs = study_prep_get_req(1, '*****@*****.**')
        exp = {'status': 'success',
               'message': '',
               'info': {
                   '18S': [{'id': 1,
                            'status': 'private',
                            'name': 'Prep information 1',
                            'start_artifact_id': 1,
                            'start_artifact': 'FASTQ',
                            'youngest_artifact': 'BIOM - BIOM',
                            'ebi_experiment': 27},
                           {'id': 2,
                            'status': 'private',
                            'name': 'Prep information 2',
                            'start_artifact_id': 7,
                            'start_artifact': 'BIOM',
                            'youngest_artifact': 'BIOM - BIOM',
                            'ebi_experiment': 27}],
                   '16S': [{'id': pt.id,
                            'status': 'sandbox',
                            'name': 'Prep information %d' % pt.id,
                            'start_artifact_id': None,
                            'start_artifact': None,
                            'youngest_artifact': None,
                            'ebi_experiment': 0}]}}
        self.assertEqual(obs, exp)

        obs = study_prep_get_req(1, '*****@*****.**')
        self.assertEqual(obs, exp)

        qdb.artifact.Artifact(1).visibility = 'public'
        obs = study_prep_get_req(1, '*****@*****.**')
        exp = {'status': 'success',
               'message': '',
               'info': {
                   '18S': [{'id': 1,
                            'status': 'public',
                            'name': 'Prep information 1',
                            'start_artifact_id': 1,
                            'start_artifact': 'FASTQ',
                            'youngest_artifact': 'BIOM - BIOM',
                            'ebi_experiment': 27}]}}
        self.assertEqual(obs, exp)
        # Reset visibility of the artifacts
        for i in range(4, 0, -1):
            qdb.artifact.Artifact(i).visibility = "private"

        qdb.metadata_template.prep_template.PrepTemplate.delete(pt.id)
Exemplo n.º 9
0
    def test_study_prep_get_req(self):
        obs = study_prep_get_req(1, '*****@*****.**')
        obs_info = obs['info']['18S']
        temp_info = defaultdict(list)
        temp_info['18S'] = [{
            'id':
            1,
            'status':
            'private',
            'name':
            'Prep information 1',
            'start_artifact_id':
            1,
            'start_artifact':
            'FASTQ',
            'youngest_artifact':
            'BIOM - BIOM',
            'youngest_artifact_name':
            'BIOM',
            'youngest_artifact_type':
            'BIOM',
            'num_artifact_children':
            2,
            'total_samples':
            27,
            'ebi_experiment':
            27,
            'modification_timestamp':
            obs_info[0]['modification_timestamp'],
            'creation_timestamp':
            obs_info[0]['creation_timestamp']
        }, {
            'id':
            2,
            'status':
            'private',
            'name':
            'Prep information 2',
            'start_artifact':
            'BIOM',
            'youngest_artifact':
            'BIOM - BIOM',
            'youngest_artifact_name':
            'BIOM',
            'youngest_artifact_type':
            'BIOM',
            'total_samples':
            27,
            'num_artifact_children':
            0,
            'ebi_experiment':
            27,
            'start_artifact_id':
            7,
            'modification_timestamp':
            obs_info[1]['modification_timestamp'],
            'creation_timestamp':
            obs_info[1]['creation_timestamp']
        }]
        exp = {'status': 'success', 'message': '', 'info': temp_info}
        self.assertEqual(obs, exp)

        # Add a new prep template
        pt = npt.assert_warns(
            qdb.exceptions.QiitaDBWarning,
            qdb.metadata_template.prep_template.PrepTemplate.create,
            pd.DataFrame({'new_col': {
                '1.SKD6.640190': 1
            }}), qdb.study.Study(1), '16S')
        obs = study_prep_get_req(1, '*****@*****.**')
        temp_info['16S'] = [{
            'id': pt.id,
            'status': 'sandbox',
            'name': 'Prep information %d' % pt.id,
            'creation_timestamp': pt.creation_timestamp,
            'modification_timestamp': pt.modification_timestamp,
            'total_samples': 1,
            'start_artifact_id': None,
            'start_artifact': None,
            'youngest_artifact': None,
            'num_artifact_children': 0,
            'youngest_artifact_name': None,
            'youngest_artifact_type': None,
            'ebi_experiment': 0
        }]
        exp = {'status': 'success', 'message': '', 'info': temp_info}
        self.assertEqual(obs, exp)

        obs = study_prep_get_req(1, '*****@*****.**')
        self.assertEqual(obs, exp)

        qdb.artifact.Artifact(1).visibility = 'public'
        obs = study_prep_get_req(1, '*****@*****.**')
        temp_info = defaultdict(list)
        temp_info['18S'] = [{
            'id':
            1,
            'status':
            'public',
            'name':
            'Prep information 1',
            'start_artifact_id':
            1,
            'start_artifact':
            'FASTQ',
            'youngest_artifact':
            'BIOM - BIOM',
            'youngest_artifact_name':
            'BIOM',
            'youngest_artifact_type':
            'BIOM',
            'num_artifact_children':
            2,
            'total_samples':
            27,
            'ebi_experiment':
            27,
            'modification_timestamp':
            obs_info[0]['modification_timestamp'],
            'creation_timestamp':
            obs_info[0]['creation_timestamp']
        }]
        temp_info['16S'] = []
        exp = {'status': 'success', 'message': '', 'info': temp_info}
        self.assertEqual(obs, exp)
        # Reset visibility of the artifacts
        for i in range(4, 0, -1):
            qdb.artifact.Artifact(i).visibility = "private"

        qdb.metadata_template.prep_template.PrepTemplate.delete(pt.id)