def test_cache(self): np.random.seed(0) aligner, query, exp_fp = self.blast pred = FeatureAnnt([self.db], mkdtemp(dir=self.tmp_dir), cache=self.cache) obs = pred(query, aligner=aligner) exp = pred.parse_tabular(exp_fp) self.assertEquals(exp['sseqid'].values, obs['sseqid'].values)
def test_cache_empty_db(self): np.random.seed(0) for test in self.tests: aligner, query, exp_fp = test.aligner, test.input, test.exp pred = FeatureAnnt([], mkdtemp(dir=self.tmp_dir), cache=self.cache) obs = pred(query, aligner=aligner) exp = pred._filter_best(pred.parse_tabular(exp_fp)) self.assertEqual(exp['sseqid'].values, obs['sseqid'].values)
def test_blast(self): for test in self.tests: pred = FeatureAnnt([self.db], mkdtemp(dir=self.tmp_dir)) obs = pred(test.input, aligner=test.aligner, outfmt='tab') exp = pred._filter_best( pred.parse_tabular('%s.diamond' % test.exp)) self.assertTrue(exp.equals(obs)) obs = pred(test.input, aligner=test.aligner, outfmt='sam') exp = pred._filter_id_cov(pred.parse_sam('%s.sam' % test.exp)) self.assertTrue(exp.equals(obs))
def test_parse_sam_best(self): for test in self.blast: df = FeatureAnnt.parse_sam(test[2], column='bitscore') df = df.reindex_axis(sorted(df.columns), axis=1) exp = df.reindex_axis(sorted(self.exp.columns), axis=1) pdt.assert_frame_equal(df, exp)
def test_blast_wrong_input(self): pred = FeatureAnnt([self.db], self.tmp_dir) for i in self.neg_fp: for aligner in ['blastp', 'blastx']: with self.assertRaisesRegex( ApplicationError, r'(Error reading file)|(Invalid input file format)'): pred(i, aligner=aligner)
def test_cache_initialize(self): np.random.seed(0) for test in self.tests: aligner, query = test.aligner, test.input pred = FeatureAnnt([self.db], mkdtemp(dir=self.tmp_dir), cache=DiamondCache()) pred(query, aligner=aligner) self.assertTrue(len(pred.cache.seqs) > 0)
def test_blast(self): for test in self.tests: pred = FeatureAnnt([self.db], mkdtemp(dir=self.tmp_dir)) obs = pred(test.input, aligner=test.aligner, outfmt='tab') exp = pred._filter_best(pred.parse_tabular('%s.diamond' % test.exp)) self.assertTrue(exp.equals(obs)) obs = pred(test.input, aligner=test.aligner, outfmt='sam') exp = pred._filter_id_cov(pred.parse_sam('%s.sam' % test.exp)) self.assertTrue(exp.equals(obs))
def test_filter_id_cov(self): for test in self.filter_tests2: df = FeatureAnnt.parse_sam(test.input) df_filter = FeatureAnnt._filter_id_cov(df, pident=30, cov=92) df_filter.to_csv(test.obs, sep='\t') self.assertTrue(cmp(test.exp, test.obs, shallow=False))
def test_filter_best(self): for test in self.filter_tests: df = FeatureAnnt.parse_tabular(test.input) df_filter = FeatureAnnt._filter_best(df) df_filter.to_csv(test.obs, sep='\t') self.assertTrue(cmp(test.exp, test.obs, shallow=False))
def test_parse_sam(self): for test in self.sam_tests: df = FeatureAnnt.parse_sam(test.input) df.to_csv(test.obs, sep='\t', index=False) self.assertTrue(cmp(test.exp, test.obs, shallow=False))
def test_blast(self): for aligner, query, exp_fp in self.blast: pred = FeatureAnnt([self.db], mkdtemp(dir=self.tmp_dir)) obs = pred(query, aligner=aligner) exp = pred.parse_tabular(exp_fp) self.assertTrue(exp.equals(obs))
def test_blast(self): for test in self.tests: pred = FeatureAnnt([self.db], mkdtemp(dir=self.tmp_dir)) obs = pred(test.input, aligner=test.aligner) exp = pred._filter_best(pred.parse_tabular(test.exp)) self.assertTrue(exp.equals(obs))