예제 #1
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('SKB'), 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.SKB1.640202', '1.SKD1.640179', '1.SKM1.640183']
     self.assertEqual(s.samples('1.64'), exp_samples)
예제 #2
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()
예제 #3
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])