Example #1
0
 def test_diff_abundance(self):
     # test using defulat values
     dd = diff_abundance(self.test1,
                         'group',
                         val1='1',
                         val2='2',
                         random_seed=2017)
     expected_ids = [0, 1, 2, 3, 4, 7, 10]
     self.assertEqual(len(dd.feature_metadata), 7)
     for cid in expected_ids:
         self.assertIn(self.test1.feature_metadata.index[cid],
                       dd.feature_metadata.index)
     # test using no group 2 using only group 1
     dd = diff_abundance(self.test1, 'group', val1='1')
     expected_ids = [0, 1, 2, 3, 4, 10]
     # we get 1 less since now we also include badsample sample (not in the mapping file, so gets na)
     self.assertEqual(len(dd.feature_metadata), 6)
     for cid in expected_ids:
         self.assertIn(self.test1.feature_metadata.index[cid],
                       dd.feature_metadata.index)
     # test using no val 2 using only group 2
     dd = diff_abundance(self.test1, 'group', val1='2')
     expected_ids = [0, 1, 2, 3, 4, 7, 10]
     self.assertEqual(len(dd.feature_metadata), 7)
     for cid in expected_ids:
         self.assertIn(self.test1.feature_metadata.index[cid],
                       dd.feature_metadata.index)
Example #2
0
 def test_diff_abundance_paired(self):
     # Do the paired test (we should get 4 features)
     dd = diff_abundance_paired(self.test_paired,
                                'subj',
                                field='group',
                                val1='1',
                                val2='2',
                                alpha=0.1,
                                random_seed=2020)
     self.assertEqual(len(dd.feature_metadata), 4)
     expected_ids = ['AG', 'AA', 'TA', 'TT']
     for cid in expected_ids:
         self.assertIn(cid, dd.feature_metadata._feature_id)
     # and the unpaired test (which is less sensitive for this dataset - we should get only 2)
     dd = diff_abundance(self.test_paired,
                         field='group',
                         val1='1',
                         val2='2',
                         alpha=0.1,
                         random_seed=2020)
     self.assertEqual(len(dd.feature_metadata), 2)
     expected_ids = ['AG', 'TT']
     for cid in expected_ids:
         self.assertIn(cid, dd.feature_metadata._feature_id)
     # test with binary transforming the pairs
     dd = diff_abundance_paired(self.test_paired,
                                'subj',
                                transform='pair_rank',
                                field='group',
                                val1='1',
                                val2='2',
                                alpha=0.1,
                                random_seed=2020)
     self.assertEqual(len(dd.feature_metadata), 4)
     expected_ids = ['AA', 'AG', 'TA', 'TT']
     for cid in expected_ids:
         self.assertIn(cid, dd.feature_metadata._feature_id)
     # test with more than 2 samples per group
     dd = diff_abundance_paired(self.test_paired,
                                'group3',
                                field='group2',
                                val1='1',
                                val2='2',
                                alpha=0.1,
                                random_seed=2020,
                                numperm=1000)
     self.assertEqual(len(dd.feature_metadata), 4)
     expected_ids = ['AA', 'AT', 'GG', 'TA']
     for cid in expected_ids:
         self.assertIn(cid, dd.feature_metadata._feature_id)
Example #3
0
 def test_diff_abundance_alpha0(self):
     # Test when we should get 0 features (setting FDR level to 0)
     dd = diff_abundance(self.test1, 'group', val1='1', val2='2', alpha=0)
     self.assertEqual(dd.shape, (self.test1.shape[0], 0))