def setUp(self): self.dir = tempfile.mkdtemp() + '/' self.db = self.dir + 'TEMPDB' self.metadata = self.dir + 'TEMPmetadata' self.fasta = self.dir + 'TEMP' file_header = 'Fasta,Class,Dataset\n' file_contents = 'TEMP,A,Train\n' with open(self.metadata, 'w') as f: f.write('%s%s' % (file_header, file_contents)) with open(self.fasta, 'w') as f: out = '>label1\nAAAA\n>label2\nCCCC\n>label3\nATAT\n>label4\nACGT' f.write(out) metadata_kwargs = { 'metadata': self.metadata, 'prefix': self.dir, 'validate': False } kmer_kwargs = {'k': 4, 'limit': 0} args = { 'metadata_kwargs': metadata_kwargs, 'kmer_kwargs': kmer_kwargs, 'database': self.db, 'recount': True, 'validate': False, 'complete_count': False } self.data = get_kmer(**args) self.correct_features = np.array(['AAAA', 'ACGT', 'ATAT', 'CCCC'])
def test_y_test_complete(self): self.args['complete_count'] = True self.args['database'] = self.db_complete self.args['kmer_kwargs'] = {'k': 2} data, features, files, le = get_kmer(**self.args) val = False if np.array_equal(le.inverse_transform(data[3]), self.correct_y_test): val = True self.assertTrue(val)
def test_y_train(self): data, features, files, le = get_kmer(**self.args) count1 = 0 count2 = 0 for elem in self.correct_y_train: count2 += 1 if elem in le.inverse_transform(data[1]): count1 += 1 for elem in le.inverse_transform(data[1]): count2 += 1 if elem in self.correct_y_train: count1 += 1 self.assertEqual(count1, count2)
def test_x_train(self): data, features, files, le = get_kmer(**self.args) count1 = 0 count2 = 0 for elem in self.correct_x_train: count2 += 1 if elem in data[0]: count1 += 1 for elem in data[0]: count2 += 1 if elem in self.correct_x_train: count1 += 1 self.assertEqual(count1, count2)
def test_x_train_complete(self): self.args['complete_count'] = True self.args['database'] = self.db_complete self.args['kmer_kwargs'] = {'k': 2} data, features, files, le = get_kmer(**self.args) count1 = 0 count2 = 0 for elem in self.correct_x_train: count2 += 1 if elem in data[0]: count1 += 1 for elem in data[0]: count2 += 1 if elem in self.correct_x_train: count1 += 1 self.assertEqual(count1, count2)
def test_y_test(self): data, features, files, le = get_kmer(**self.args) val = False if np.array_equal(le.inverse_transform(data[3]), self.correct_y_test): val = True self.assertTrue(val)
def test_x_test(self): data, features, files, le = get_kmer(**self.args) val = False if np.array_equal(data[2], self.correct_x_test): val = True self.assertTrue(val)