예제 #1
0
 def test_validate_input_values(self):
     # should not raise error
     _validate_input_columns(md, "ind", "Group", "Time", None)
     _validate_input_columns(md, "ind", None, None, None)
     _validate_input_values(md, "Value", "ind", "Group", "Time", None, None)
     with self.assertRaisesRegex(ValueError, "state_1 and state_2"):
         _validate_input_values(md, "Value", "ind", "Group", "Time", 1, 1)
     with self.assertRaisesRegex(ValueError, "not present"):
         _validate_input_values(md, "Value", "ind", "Group", "Time", 1, 3)
     with self.assertRaisesRegex(ValueError, "not a column"):
         _validate_input_values(md, "Value", "ind", "Group", "Days", 1, 2)
     with self.assertRaisesRegex(ValueError, "not a column"):
         _validate_input_columns(md, "ind", ["Group", "More stuff"], "Time",
                                 "Value")
     with self.assertRaisesRegex(ValueError, "unique values"):
         _validate_input_columns(md, "ind", "Time", "Time", "Value")
     with self.assertRaisesRegex(ValueError, "state_column must contain"):
         _validate_input_columns(
             md[md['Time'] == 1], "ind", "Group", "Time", "Value")
     dropped = md.drop(['9', '10', '11'])
     with self.assertRaisesRegex(ValueError, "not represented"):
         _validate_input_values(
             dropped, "Value", "ind", "Group", "Time", 1, 2)
     with self.assertRaisesRegex(ValueError, "state_1 and state_2"):
         pairwise_differences(
             output_dir=self.temp_dir.name, table=None,
             metadata=self.md_ecam_fp, group_column='delivery',
             state_column='month', state_1=0, state_2=0,
             individual_id_column='studyid', metric='observed_otus',
             replicate_handling='drop')
     with self.assertRaisesRegex(ValueError, "Detected replicate samples"):
         _get_group_pairs(
             md_dup, 'a', individual_id_column='ind', group_column='Group',
             state_column='Time', state_values=[1, 2],
             replicate_handling='error')
예제 #2
0
 def test_get_group_pairs(self):
     res = _get_group_pairs(md,
                            'a',
                            individual_id_column='ind',
                            group_column='Group',
                            state_column='Time',
                            state_values=[1, 2],
                            replicate_handling='drop')
     self.assertEqual(res, [('0', '3'), ('1', '4'), ('2', '5')])
     res = _get_group_pairs(md_dup,
                            'a',
                            individual_id_column='ind',
                            group_column='Group',
                            state_column='Time',
                            state_values=[1, 2],
                            replicate_handling='drop')
     self.assertEqual(res, [('0', '3')])
     res = _get_group_pairs(md_dup,
                            'a',
                            individual_id_column='ind',
                            group_column='Group',
                            state_column='Time',
                            state_values=[1, 2],
                            replicate_handling='random')
     self.assertEqual(res[0], ('0', '3'))
     self.assertIn(res[1], [('1', '4'), ('2', '4')])
예제 #3
0
 def test_get_group_pairs(self):
     res, err = _get_group_pairs(md,
                                 'a',
                                 individual_id_column='ind',
                                 group_column='Group',
                                 state_column='Time',
                                 state_values=[1, 2],
                                 replicate_handling='drop')
     self.assertEqual(res, [('0', '3'), ('1', '4'), ('2', '5')])
     # test operation without group_column
     res, err = _get_group_pairs(md,
                                 'a',
                                 individual_id_column='ind',
                                 group_column=None,
                                 state_column='Time',
                                 state_values=[1, 2],
                                 replicate_handling='drop')
     self.assertEqual(res, [('0', '3'), ('1', '4'), ('2', '5'), ('6', '9'),
                            ('7', '10'), ('8', '11')])
     res, err = _get_group_pairs(md_dup,
                                 'a',
                                 individual_id_column='ind',
                                 group_column='Group',
                                 state_column='Time',
                                 state_values=[1, 2],
                                 replicate_handling='drop')
     self.assertEqual(res, [('0', '3')])
     res, err = _get_group_pairs(md_dup,
                                 'a',
                                 individual_id_column='ind',
                                 group_column='Group',
                                 state_column='Time',
                                 state_values=[1, 2],
                                 replicate_handling='random')
     self.assertEqual(res[0], ('0', '3'))
     self.assertIn(res[1], [('1', '4'), ('2', '4')])