Exemplo n.º 1
0
 def get(self, study_id):
     try:
         study = Study(int(study_id))
         term = self.get_argument('term', None)
         res = list(study.samples(term))
         self.write(json_encode(res))
     except LabmanUnknownIdError:
         self.set_status(404)
     self.finish()
Exemplo n.º 2
0
 def test_samples(self):
     s = Study(1)
     exp_samples = ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195',
                    '1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176',
                    '1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200',
                    '1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198',
                    '1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190',
                    '1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182',
                    '1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
                    '1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
                    '1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']
     self.assertEqual(s.samples(), exp_samples)
     exp_samples = ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195',
                    '1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176',
                    '1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200']
     self.assertEqual(s.samples(limit=9), exp_samples)
     exp_samples = ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195',
                    '1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176',
                    '1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200']
     self.assertEqual(s.samples('SKB'), exp_samples)
     exp_samples = ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195']
     self.assertEqual(s.samples('SKB', limit=3), exp_samples)
     exp_samples = ['1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
                    '1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
                    '1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']
     self.assertEqual(s.samples('1.SKM'), exp_samples)
     exp_samples = ['1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
                    '1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
                    '1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']
     self.assertEqual(s.samples('1.Skm'), exp_samples)  # case insensitive
     exp_samples = ['1.SKB1.640202', '1.SKD1.640179', '1.SKM1.640183']
     self.assertEqual(s.samples('1.64'), exp_samples)
Exemplo n.º 3
0
    def test_sample_composition_attributes(self):
        # Test a sample
        obs = SampleComposition(1)
        self.assertEqual(obs.sample_composition_type, 'experimental sample')
        self.assertEqual(obs.sample_id, '1.SKB1.640202')
        self.assertEqual(obs.content, '1.SKB1.640202')
        self.assertEqual(obs.upstream_process, SamplePlatingProcess(10))
        self.assertEqual(obs.container, Well(3073))
        self.assertEqual(obs.total_volume, 10)
        self.assertIsNone(obs.notes)
        obs.notes = 'New Notes'
        self.assertEqual(obs.notes, 'New Notes')
        obs.notes = None
        self.assertIsNone(obs.notes)
        self.assertEqual(obs.composition_id, 3081)
        self.assertEqual(obs.study, Study(1))

        # Test a control sample
        obs = SampleComposition(85)
        self.assertEqual(obs.sample_composition_type, 'blank')
        self.assertIsNone(obs.sample_id)
        self.assertEqual(obs.content, 'blank.21.H1')
        self.assertEqual(obs.upstream_process, SamplePlatingProcess(10))
        self.assertEqual(obs.container, Well(4333))
        self.assertEqual(obs.total_volume, 10)
        self.assertIsNone(obs.notes)
        self.assertEqual(obs.composition_id, 4341)
        self.assertIsNone(obs.study)
Exemplo n.º 4
0
 def test_attributes(self):
     s = Study(1)
     self.assertEqual(
         s.title, 'Identification of the Microbiomes '
         'for Cannabis Soils')
     self.assertEqual(s.creator, User('*****@*****.**'))
     self.assertEqual(s.num_samples, 27)
Exemplo n.º 5
0
 def test_gDNA_composition_attributes(self):
     obs = GDNAComposition(1)
     self.assertEqual(obs.sample_composition, SampleComposition(1))
     self.assertEqual(obs.upstream_process, GDNAExtractionProcess(1))
     self.assertEqual(obs.container, Well(3074))
     self.assertEqual(obs.total_volume, 10)
     self.assertIsNone(obs.notes)
     self.assertEqual(obs.composition_id, 3082)
     self.assertEqual(obs.study, Study(1))
Exemplo n.º 6
0
 def test_library_prep_16S_composition_attributes(self):
     obs = LibraryPrep16SComposition(1)
     self.assertEqual(obs.container, Well(3075))
     self.assertEqual(obs.total_volume, 10)
     self.assertIsNone(obs.notes)
     self.assertEqual(obs.gdna_composition, GDNAComposition(1))
     self.assertEqual(obs.primer_composition, PrimerComposition(1))
     self.assertEqual(obs.composition_id, 3083)
     self.assertEqual(obs.study, Study(1))
Exemplo n.º 7
0
 def test_list_studies(self):
     obs = Study.list_studies()
     exp = [{'study_id': 1,
             'study_title': 'Identification of the Microbiomes for '
                            'Cannabis Soils',
             'study_alias': 'Cannabis Soils',
             'owner': '*****@*****.**',
             'num_samples': 27}]
     self.assertEqual(obs, exp)
Exemplo n.º 8
0
 def test_normalized_gDNA_composition_attributes(self):
     obs = NormalizedGDNAComposition(1)
     self.assertEqual(obs.container, Well(3077))
     self.assertEqual(obs.total_volume, 3500)
     self.assertIsNone(obs.notes)
     self.assertEqual(obs.gdna_composition, GDNAComposition(2))
     self.assertEqual(obs.dna_volume, 415)
     self.assertEqual(obs.water_volume, 3085)
     self.assertEqual(obs.composition_id, 3085)
     self.assertEqual(obs.study, Study(1))
Exemplo n.º 9
0
 def get(self):
     # Get all arguments that DataTables send us
     res = {
         "data": [[
             s['study_id'], s['study_title'], s['study_alias'], s['owner'],
             s['num_samples']
         ] for s in Study.list_studies()]
     }
     self.write(res)
     self.finish()
Exemplo n.º 10
0
 def test_library_prep_shotgun_composition_attributes(self):
     obs = LibraryPrepShotgunComposition(1)
     self.assertEqual(obs.container, Well(3078))
     self._baseAssertEqual(obs.total_volume, 4000)
     self.assertIsNone(obs.notes)
     self.assertEqual(obs.normalized_gdna_composition,
                      NormalizedGDNAComposition(1))
     self.assertEqual(obs.i5_composition, PrimerComposition(769))
     self.assertEqual(obs.i7_composition, PrimerComposition(770))
     self.assertEqual(obs.composition_id, 3086)
     self.assertEqual(obs.study, Study(1))
Exemplo n.º 11
0
 def get(self, study_id):
     try:
         study = Study(int(study_id))
         self.write({
             'study_id': study.id,
             'study_title': study.title,
             'total_samples': study.num_samples
         })
     except LabmanUnknownIdError:
         self.set_status(404)
     self.finish()
Exemplo n.º 12
0
    def get(self, study_id):
        try:
            study = Study(int(study_id))
        except LabmanUnknownIdError:
            raise HTTPError(404, reason="Study %s doesn't exist" % study_id)

        study_numbers = study.sample_numbers_summary
        self.render('study.html',
                    study_id=study.id,
                    study_title=study.title,
                    study_numbers=study_numbers)
Exemplo n.º 13
0
    def test_samples_with_specimen_id(self):
        s = Study(1)

        # HACK: the Study object in labman can't modify specimen_id_column
        # hence we do this directly in SQL, if a test fails the transaction
        # will rollback, otherwise we reset the column to NULL.
        sql = """UPDATE qiita.study
                 SET specimen_id_column = %s
                 WHERE study_id = 1"""
        with sql_connection.TRN as TRN:
            TRN.add(sql, ['anonymized_name'])

            exp_samples = [
                'SKB1', 'SKB2', 'SKB3', 'SKB4', 'SKB5', 'SKB6', 'SKB7', 'SKB8',
                'SKB9', 'SKD1', 'SKD2', 'SKD3', 'SKD4', 'SKD5', 'SKD6', 'SKD7',
                'SKD8', 'SKD9', 'SKM1', 'SKM2', 'SKM3', 'SKM4', 'SKM5', 'SKM6',
                'SKM7', 'SKM8', 'SKM9'
            ]
            self.assertEqual(s.samples(), exp_samples)
            exp_samples = [
                'SKB1', 'SKB2', 'SKB3', 'SKB4', 'SKB5', 'SKB6', 'SKB7', 'SKB8',
                'SKB9'
            ]
            self.assertEqual(s.samples(limit=9), exp_samples)
            exp_samples = [
                'SKB1', 'SKB2', 'SKB3', 'SKB4', 'SKB5', 'SKB6', 'SKB7', 'SKB8',
                'SKB9'
            ]
            self.assertEqual(s.samples('SKB'), exp_samples)
            exp_samples = ['SKB1', 'SKB2', 'SKB3']
            self.assertEqual(s.samples('SKB', limit=3), exp_samples)
            exp_samples = [
                'SKM1', 'SKM2', 'SKM3', 'SKM4', 'SKM5', 'SKM6', 'SKM7', 'SKM8',
                'SKM9'
            ]
            self.assertEqual(s.samples('SKM'), exp_samples)
            exp_samples = [
                'SKM1', 'SKM2', 'SKM3', 'SKM4', 'SKM5', 'SKM6', 'SKM7', 'SKM8',
                'SKM9'
            ]
            # case insensitive
            self.assertEqual(s.samples('Skm'), exp_samples)
            self.assertEqual(s.samples('64'), [])

            TRN.add(sql, [None])
Exemplo n.º 14
0
    def test_translate_ids_with_sample_id(self):
        # Tests sample_id_to_specimen_id and specimen_id_to_sample_id when
        # there is no specimen identifier set for the study
        s = Study(1)

        obs = s.sample_id_to_specimen_id('1.SKM4.640180')
        self.assertEqual(obs, '1.SKM4.640180')

        # doesn't even need to be a valid sample id
        obs = s.sample_id_to_specimen_id('SKM3')
        self.assertEqual(obs, 'SKM3')

        with self.assertRaisesRegex(ValueError, 'Could not find "SKM4"'):
            s.specimen_id_to_sample_id('SKM4')

        with self.assertRaisesRegex(ValueError, 'Could not find "SSSS"'):
            s.specimen_id_to_sample_id('SSSS')
Exemplo n.º 15
0
    def test_translate_ids_with_specimen_id(self):
        s = Study(1)
        # HACK: the Study object in labman can't modify specimen_id_column
        # hence we do this directly in SQL, if a test fails the transaction
        # will rollback, otherwise we reset the column to NULL.
        sql = """UPDATE qiita.study
                 SET specimen_id_column = %s
                 WHERE study_id = 1"""
        with sql_connection.TRN as TRN:
            TRN.add(sql, ['anonymized_name'])

            obs = s.sample_id_to_specimen_id('1.SKM4.640180')
            self.assertEqual(obs, 'SKM4')

            obs = s.specimen_id_to_sample_id('SKM4')
            self.assertEqual(obs, '1.SKM4.640180')

            # should be an exact match
            with self.assertRaisesRegex(ValueError,
                                        'Could not find \"1\.skm4\.640180\"'):
                s.sample_id_to_specimen_id('1.skm4.640180')
            with self.assertRaisesRegex(ValueError, 'Could not find \"skm4\"'):
                s.specimen_id_to_sample_id('skm4')

            # raise an error in the rare case that the specimen_id_column was
            # set to something that's not unique (this could only accidentally
            # happen)
            TRN.add(sql, ['taxon_id'])
            with self.assertRaisesRegex(
                    RuntimeError, 'There are several '
                    'matches found for "1118232"; there is'
                    ' a problem with the specimen id '
                    'column'):
                s.specimen_id_to_sample_id('1118232')

            TRN.add(sql, [None])
Exemplo n.º 16
0
 def test_attributes(self):
     s = Study(1)
     self.assertEqual(s.title, 'Identification of the Microbiomes '
                               'for Cannabis Soils')
     self.assertEqual(s.creator, User('*****@*****.**'))
     self.assertEqual(s.num_samples, 27)
     exp = {'num_samples': 27,
            'number_samples_plated': 6,
            'number_samples_extracted': 6,
            'number_samples_amplicon_libraries': 6,
            'number_samples_amplicon_pools': 6,
            'number_samples_amplicon_sequencing_pools': 6,
            'number_samples_amplicon_sequencing_runs': 6,
            'number_samples_compressed': 6,
            'number_samples_normalized': 6,
            'number_samples_shotgun_libraries': 6,
            'number_samples_shotgun_pool': 6,
            'number_samples_shotgun_sequencing_runs': 6}
     self.assertEqual(s.sample_numbers_summary, exp)
Exemplo n.º 17
0
    def test_properties(self):
        # Plate 21 - Defined in the test DB
        tester = Plate(21)
        self.assertEqual(tester.external_id, 'Test plate 1')
        self.assertEqual(tester.plate_configuration, PlateConfiguration(1))
        self.assertFalse(tester.discarded)
        tester.discarded = True
        self.assertTrue(tester.discarded)
        self.assertIsNone(tester.notes)
        obs_layout = tester.layout
        self.assertEqual(len(obs_layout), 8)
        for row in obs_layout:
            self.assertEqual(len(row), 12)
        self.assertEqual(tester.studies, {Study(1)})
        self.assertListEqual(tester.quantification_processes, [])
        self.assertEqual(tester.process, SamplePlatingProcess(10))

        # Test changing the name of the plate
        tester.external_id = 'Some new name'
        self.assertEqual(tester.external_id, 'Some new name')
        tester.external_id = 'Test plate 1'
        self.assertEqual(tester.external_id, 'Test plate 1')

        self.assertEqual(len(Plate(23).quantification_processes), 1)
        self.assertEqual(
            Plate(23).quantification_processes[0], QuantificationProcess(1))
        self.assertEqual(Plate(22).process, GDNAExtractionProcess(1))

        exp = {
            '1.SKB1.640202': [[Well(3073), '1.SKB1.640202.21.A1'],
                              [Well(3121), '1.SKB1.640202.21.A2'],
                              [Well(3169), '1.SKB1.640202.21.A3'],
                              [Well(3217), '1.SKB1.640202.21.A4'],
                              [Well(3265), '1.SKB1.640202.21.A5'],
                              [Well(3313), '1.SKB1.640202.21.A6'],
                              [Well(3361), '1.SKB1.640202.21.A7'],
                              [Well(3409), '1.SKB1.640202.21.A8'],
                              [Well(3457), '1.SKB1.640202.21.A9'],
                              [Well(3505), '1.SKB1.640202.21.A10'],
                              [Well(3553), '1.SKB1.640202.21.A11'],
                              [Well(3601), '1.SKB1.640202.21.A12']],
            '1.SKB2.640194': [[Well(3079), '1.SKB2.640194.21.B1'],
                              [Well(3127), '1.SKB2.640194.21.B2'],
                              [Well(3175), '1.SKB2.640194.21.B3'],
                              [Well(3223), '1.SKB2.640194.21.B4'],
                              [Well(3271), '1.SKB2.640194.21.B5'],
                              [Well(3319), '1.SKB2.640194.21.B6'],
                              [Well(3367), '1.SKB2.640194.21.B7'],
                              [Well(3415), '1.SKB2.640194.21.B8'],
                              [Well(3463), '1.SKB2.640194.21.B9'],
                              [Well(3511), '1.SKB2.640194.21.B10'],
                              [Well(3559), '1.SKB2.640194.21.B11'],
                              [Well(3607), '1.SKB2.640194.21.B12']],
            '1.SKB3.640195': [[Well(3085), '1.SKB3.640195.21.C1'],
                              [Well(3133), '1.SKB3.640195.21.C2'],
                              [Well(3181), '1.SKB3.640195.21.C3'],
                              [Well(3229), '1.SKB3.640195.21.C4'],
                              [Well(3277), '1.SKB3.640195.21.C5'],
                              [Well(3325), '1.SKB3.640195.21.C6'],
                              [Well(3373), '1.SKB3.640195.21.C7'],
                              [Well(3421), '1.SKB3.640195.21.C8'],
                              [Well(3469), '1.SKB3.640195.21.C9'],
                              [Well(3517), '1.SKB3.640195.21.C10'],
                              [Well(3565), '1.SKB3.640195.21.C11'],
                              [Well(3613), '1.SKB3.640195.21.C12']],
            '1.SKB4.640189': [[Well(3091), '1.SKB4.640189.21.D1'],
                              [Well(3139), '1.SKB4.640189.21.D2'],
                              [Well(3187), '1.SKB4.640189.21.D3'],
                              [Well(3235), '1.SKB4.640189.21.D4'],
                              [Well(3283), '1.SKB4.640189.21.D5'],
                              [Well(3331), '1.SKB4.640189.21.D6'],
                              [Well(3379), '1.SKB4.640189.21.D7'],
                              [Well(3427), '1.SKB4.640189.21.D8'],
                              [Well(3475), '1.SKB4.640189.21.D9'],
                              [Well(3523), '1.SKB4.640189.21.D10'],
                              [Well(3571), '1.SKB4.640189.21.D11'],
                              [Well(3619), '1.SKB4.640189.21.D12']],
            '1.SKB5.640181': [[Well(3097), '1.SKB5.640181.21.E1'],
                              [Well(3145), '1.SKB5.640181.21.E2'],
                              [Well(3193), '1.SKB5.640181.21.E3'],
                              [Well(3241), '1.SKB5.640181.21.E4'],
                              [Well(3289), '1.SKB5.640181.21.E5'],
                              [Well(3337), '1.SKB5.640181.21.E6'],
                              [Well(3385), '1.SKB5.640181.21.E7'],
                              [Well(3433), '1.SKB5.640181.21.E8'],
                              [Well(3481), '1.SKB5.640181.21.E9'],
                              [Well(3529), '1.SKB5.640181.21.E10'],
                              [Well(3577), '1.SKB5.640181.21.E11'],
                              [Well(3625), '1.SKB5.640181.21.E12']],
            '1.SKB6.640176': [[Well(3103), '1.SKB6.640176.21.F1'],
                              [Well(3151), '1.SKB6.640176.21.F2'],
                              [Well(3199), '1.SKB6.640176.21.F3'],
                              [Well(3247), '1.SKB6.640176.21.F4'],
                              [Well(3295), '1.SKB6.640176.21.F5'],
                              [Well(3343), '1.SKB6.640176.21.F6'],
                              [Well(3391), '1.SKB6.640176.21.F7'],
                              [Well(3439), '1.SKB6.640176.21.F8'],
                              [Well(3487), '1.SKB6.640176.21.F9'],
                              [Well(3535), '1.SKB6.640176.21.F10'],
                              [Well(3583), '1.SKB6.640176.21.F11'],
                              [Well(3631), '1.SKB6.640176.21.F12']]
        }
        self.assertEqual(tester.duplicates, exp)
        self.assertEqual(tester.unknown_samples, [])
        exp = tester.get_well(1, 1)
        exp.composition.update('Unknown')
        self.assertEqual(tester.unknown_samples, [exp])
        exp.composition.update('1.SKB1.640202')

        # test that the quantification_processes attribute correctly
        # orders multiple processes in order from oldest to newest
        tester2 = Plate(26)
        self.assertEqual(len(tester2.quantification_processes), 2)
        self.assertEqual(
            tester2.quantification_processes[0].date,
            datetime.strptime("2017-10-25 19:10:25-0700",
                              '%Y-%m-%d %H:%M:%S%z'))
        self.assertEqual(
            tester2.quantification_processes[1].date,
            datetime.strptime("2017-10-26 03:10:25-0700",
                              '%Y-%m-%d %H:%M:%S%z'))
Exemplo n.º 18
0
    def test_properties(self):
        # Plate 21 - Defined in the test DB
        tester = Plate(21)
        self.assertEqual(tester.external_id, 'Test plate 1')
        self.assertEqual(tester.plate_configuration, PlateConfiguration(1))
        self.assertFalse(tester.discarded)
        tester.discarded = True
        self.assertTrue(tester.discarded)
        self.assertIsNone(tester.notes)
        obs_layout = tester.layout
        self.assertEqual(len(obs_layout), 8)
        for row in obs_layout:
            self.assertEqual(len(row), 12)
        self.assertEqual(tester.studies, {Study(1)})
        self.assertIsNone(tester.quantification_process)
        self.assertEqual(tester.process, SamplePlatingProcess(10))

        # Test changing the name of the plate
        tester.external_id = 'Some new name'
        self.assertEqual(tester.external_id, 'Some new name')
        tester.external_id = 'Test plate 1'
        self.assertEqual(tester.external_id, 'Test plate 1')

        self.assertEqual(
            Plate(23).quantification_process, QuantificationProcess(1))
        self.assertEqual(Plate(22).process, GDNAExtractionProcess(1))

        exp = {
            '1.SKB1.640202': [[Well(3073), '1.SKB1.640202.21.A1'],
                              [Well(3253), '1.SKB1.640202.21.B1'],
                              [Well(3433), '1.SKB1.640202.21.C1'],
                              [Well(3613), '1.SKB1.640202.21.D1'],
                              [Well(3793), '1.SKB1.640202.21.E1'],
                              [Well(3973), '1.SKB1.640202.21.F1']],
            '1.SKB2.640194': [[Well(3088), '1.SKB2.640194.21.A2'],
                              [Well(3268), '1.SKB2.640194.21.B2'],
                              [Well(3448), '1.SKB2.640194.21.C2'],
                              [Well(3628), '1.SKB2.640194.21.D2'],
                              [Well(3808), '1.SKB2.640194.21.E2'],
                              [Well(3988), '1.SKB2.640194.21.F2']],
            '1.SKB3.640195': [[Well(3103), '1.SKB3.640195.21.A3'],
                              [Well(3283), '1.SKB3.640195.21.B3'],
                              [Well(3463), '1.SKB3.640195.21.C3'],
                              [Well(3643), '1.SKB3.640195.21.D3'],
                              [Well(3823), '1.SKB3.640195.21.E3'],
                              [Well(4003), '1.SKB3.640195.21.F3']],
            '1.SKB4.640189': [[Well(3118), '1.SKB4.640189.21.A4'],
                              [Well(3298), '1.SKB4.640189.21.B4'],
                              [Well(3478), '1.SKB4.640189.21.C4'],
                              [Well(3658), '1.SKB4.640189.21.D4'],
                              [Well(3838), '1.SKB4.640189.21.E4'],
                              [Well(4018), '1.SKB4.640189.21.F4']],
            '1.SKB5.640181': [[Well(3133), '1.SKB5.640181.21.A5'],
                              [Well(3313), '1.SKB5.640181.21.B5'],
                              [Well(3493), '1.SKB5.640181.21.C5'],
                              [Well(3673), '1.SKB5.640181.21.D5'],
                              [Well(3853), '1.SKB5.640181.21.E5'],
                              [Well(4033), '1.SKB5.640181.21.F5']],
            '1.SKB6.640176': [[Well(3148), '1.SKB6.640176.21.A6'],
                              [Well(3328), '1.SKB6.640176.21.B6'],
                              [Well(3508), '1.SKB6.640176.21.C6'],
                              [Well(3688), '1.SKB6.640176.21.D6'],
                              [Well(3868), '1.SKB6.640176.21.E6'],
                              [Well(4048), '1.SKB6.640176.21.F6']],
            '1.SKB7.640196': [[Well(3163), '1.SKB7.640196.21.A7'],
                              [Well(3343), '1.SKB7.640196.21.B7'],
                              [Well(3523), '1.SKB7.640196.21.C7'],
                              [Well(3703), '1.SKB7.640196.21.D7'],
                              [Well(3883), '1.SKB7.640196.21.E7'],
                              [Well(4063), '1.SKB7.640196.21.F7']],
            '1.SKB8.640193': [[Well(3178), '1.SKB8.640193.21.A8'],
                              [Well(3358), '1.SKB8.640193.21.B8'],
                              [Well(3538), '1.SKB8.640193.21.C8'],
                              [Well(3718), '1.SKB8.640193.21.D8'],
                              [Well(3898), '1.SKB8.640193.21.E8'],
                              [Well(4078), '1.SKB8.640193.21.F8']],
            '1.SKB9.640200': [[Well(3193), '1.SKB9.640200.21.A9'],
                              [Well(3373), '1.SKB9.640200.21.B9'],
                              [Well(3553), '1.SKB9.640200.21.C9'],
                              [Well(3733), '1.SKB9.640200.21.D9'],
                              [Well(3913), '1.SKB9.640200.21.E9'],
                              [Well(4093), '1.SKB9.640200.21.F9']],
            '1.SKD1.640179': [[Well(3208), '1.SKD1.640179.21.A10'],
                              [Well(3388), '1.SKD1.640179.21.B10'],
                              [Well(3568), '1.SKD1.640179.21.C10'],
                              [Well(3748), '1.SKD1.640179.21.D10'],
                              [Well(3928), '1.SKD1.640179.21.E10'],
                              [Well(4108), '1.SKD1.640179.21.F10']],
            '1.SKD2.640178': [[Well(3223), '1.SKD2.640178.21.A11'],
                              [Well(3403), '1.SKD2.640178.21.B11'],
                              [Well(3583), '1.SKD2.640178.21.C11'],
                              [Well(3763), '1.SKD2.640178.21.D11'],
                              [Well(3943), '1.SKD2.640178.21.E11'],
                              [Well(4123), '1.SKD2.640178.21.F11']],
            '1.SKD3.640198': [[Well(3238), '1.SKD3.640198.21.A12'],
                              [Well(3418), '1.SKD3.640198.21.B12'],
                              [Well(3598), '1.SKD3.640198.21.C12'],
                              [Well(3778), '1.SKD3.640198.21.D12'],
                              [Well(3958), '1.SKD3.640198.21.E12'],
                              [Well(4138), '1.SKD3.640198.21.F12']]
        }
        self.assertEqual(tester.duplicates, exp)
        self.assertEqual(tester.unknown_samples, [])
        exp = tester.get_well(1, 1)
        exp.composition.update('Unknown')
        self.assertEqual(tester.unknown_samples, [exp])
        exp.composition.update('1.SKB1.640202')
Exemplo n.º 19
0
 def test_specimen_id_column(self):
     s = Study(1)
     self.assertIsNone(s.specimen_id_column)
Exemplo n.º 20
0
    def test_properties(self):
        # Plate 21 - Defined in the test DB
        tester = Plate(21)
        self.assertEqual(tester.external_id, 'Test plate 1')
        self.assertEqual(tester.plate_configuration, PlateConfiguration(1))
        self.assertFalse(tester.discarded)
        self.assertIsNone(tester.notes)
        obs_layout = tester.layout
        self.assertEqual(len(obs_layout), 8)
        for row in obs_layout:
            self.assertEqual(len(row), 12)
        self.assertEqual(tester.studies, {Study(1)})
        self.assertIsNone(tester.quantification_process)
        self.assertEqual(tester.process, SamplePlatingProcess(10))

        # Test changing the name of the plate
        tester.external_id = 'Some new name'
        self.assertEqual(tester.external_id, 'Some new name')
        tester.external_id = 'Test plate 1'
        self.assertEqual(tester.external_id, 'Test plate 1')

        self.assertEqual(
            Plate(23).quantification_process, QuantificationProcess(1))
        self.assertEqual(Plate(22).process, GDNAExtractionProcess(1))

        exp = {
            '1.SKB1.640202': [
                Well(3073),
                Well(3253),
                Well(3433),
                Well(3613),
                Well(3793),
                Well(3973)
            ],
            '1.SKB2.640194': [
                Well(3088),
                Well(3268),
                Well(3448),
                Well(3628),
                Well(3808),
                Well(3988)
            ],
            '1.SKB3.640195': [
                Well(3103),
                Well(3283),
                Well(3463),
                Well(3643),
                Well(3823),
                Well(4003)
            ],
            '1.SKB4.640189': [
                Well(3118),
                Well(3298),
                Well(3478),
                Well(3658),
                Well(3838),
                Well(4018)
            ],
            '1.SKB5.640181': [
                Well(3133),
                Well(3313),
                Well(3493),
                Well(3673),
                Well(3853),
                Well(4033)
            ],
            '1.SKB6.640176': [
                Well(3148),
                Well(3328),
                Well(3508),
                Well(3688),
                Well(3868),
                Well(4048)
            ],
            '1.SKB7.640196': [
                Well(3163),
                Well(3343),
                Well(3523),
                Well(3703),
                Well(3883),
                Well(4063)
            ],
            '1.SKB8.640193': [
                Well(3178),
                Well(3358),
                Well(3538),
                Well(3718),
                Well(3898),
                Well(4078)
            ],
            '1.SKB9.640200': [
                Well(3193),
                Well(3373),
                Well(3553),
                Well(3733),
                Well(3913),
                Well(4093)
            ],
            '1.SKD1.640179': [
                Well(3208),
                Well(3388),
                Well(3568),
                Well(3748),
                Well(3928),
                Well(4108)
            ],
            '1.SKD2.640178': [
                Well(3223),
                Well(3403),
                Well(3583),
                Well(3763),
                Well(3943),
                Well(4123)
            ],
            '1.SKD3.640198': [
                Well(3238),
                Well(3418),
                Well(3598),
                Well(3778),
                Well(3958),
                Well(4138)
            ]
        }
        self.assertEqual(tester.duplicates, exp)
Exemplo n.º 21
0
def sample_plating_process_handler_patch_request(
        user, process_id, req_op, req_path, req_value, req_from):
    """Performs the patch operation on the sample plating process

    Parameters
    ----------
    user: labman.db.user.User
        User performing the request
    process_id: int
        The SamplePlatingProcess to apply the patch operation
    req_op: string
        JSON PATCH op parameter
    req_path: string
        JSON PATCH path parameter
    req_value: string
        JSON PATCH value parameter
    req_from: string
        JSON PATCH from parameter

    Returns
    -------
    dict
        The results of the patch operation

    Raises
    ------
    HTTPError
        400: If req_op is not a supported operation
        400: If req_path is incorrect
    """
    if req_op == 'replace':
        req_path = [v for v in req_path.split('/') if v]
        if len(req_path) != 5:
            raise HTTPError(400, 'Incorrect path parameter')
        attribute = req_path[0]

        if attribute == 'well':
            row = req_path[1]
            col = req_path[2]
            study_id = int(req_path[3])
            well_attribute = req_path[4]

            # The default values of the variables sample_id and
            # blank_or_unknown are set before the try, and these are the values
            # that are used if either (a) study_id is not 0 OR (b) the try
            # fails with a ValueError (see comment in try below). If the try
            # fails with anything other than a ValueError then the entire
            # function bails, so it doesn't matter what these variables are set
            # to. If and only if the try succeeds are these variables set to
            # the values within the try.
            sample_id = req_value
            blank_or_unknown = True

            # It actually IS possible to plate a plate without specifying
            # separate study id(s); can plate just all blanks, or can provide
            # the fully qualified sample id(s)--i.e., <studyid>.<sampleid>.
            if study_id != 0:
                try:
                    # Note that the try fails iff the
                    # Study(study_id).specimen_id_to_sample_id() call fails,
                    # as the blank_or_unknown = False can't really fail ...
                    # this assures that we can't realistically end up in an
                    # inconsistent situation where sample_id has been set
                    # during the try but blank_or_unknown has not.
                    #
                    # Thus, the ordering of these two statements within the try
                    # is really important: do not change it unless you
                    # understand all of the above!
                    the_study = Study(study_id)
                    sample_id = the_study.specimen_id_to_sample_id(
                        req_value)
                    blank_or_unknown = False
                except ValueError:
                    pass
                # end try/except
            # end if

            if well_attribute == 'sample':
                if req_value is None or not req_value.strip():
                    raise HTTPError(
                        400, 'A new value for the well should be provided')

                plates = Plate.search(samples=[sample_id])
                process = SamplePlatingProcess(process_id)
                plates = set(plates) - {process.plate}
                prev_plates = [{'plate_id': p.id, 'plate_name': p.external_id}
                               for p in plates]
                content, sample_ok = process.update_well(row, col, sample_id)

                if blank_or_unknown:
                    req_value = content

                return {'sample_id': req_value, 'previous_plates': prev_plates,
                        'sample_ok': sample_ok}
            elif well_attribute == 'notes':
                if req_value is not None:
                    # If the user provides an empty string, just store None
                    # in the database
                    req_value = (req_value.strip()
                                 if req_value.strip() else None)
                SamplePlatingProcess(process_id).comment_well(
                    row, col, req_value)
                return {'comment': req_value}
            else:
                raise HTTPError(
                    404, 'Well attribute %s not found' % well_attribute)
        else:
            raise HTTPError(404, 'Attribute %s not found' % attribute)

    else:
        raise HTTPError(400, 'Operation %s not supported. Current supported '
                             'operations: replace' % req_op)
Exemplo n.º 22
0
 def test_init(self):
     with self.assertRaises(LabmanUnknownIdError):
         Study(1000000)