Exemple #1
0
    def test_resolve_ambiguities(self):
        import redbiom._requests
        import redbiom
        config = redbiom.get_config()
        get = redbiom._requests.make_get(config)

        redbiom.admin.create_context('test', 'foo')
        redbiom.admin.load_sample_metadata(metadata)
        redbiom.admin.ScriptManager.load_scripts(read_only=False)
        redbiom.admin.load_sample_data(table, 'test', tag=None)

        # all samples as ambiguous
        samples = {'10317.000047188', '10317.000046868', '10317.000051129',
                   '10317.000012975', '10317.000033804', '10317.000001405',
                   '10317.000022252', '10317.000001378', '10317.000005080',
                   '10317.000003302'}
        exp_stable = {"%s.UNTAGGED" % k: k for k in samples}
        exp_unobserved = []
        exp_ambiguous = {k: ["UNTAGGED_%s" % k] for k in samples}
        exp_ri = {'UNTAGGED_%s' % k: '%s.UNTAGGED' % k for k in samples}
        obs_stable, obs_unobserved, obs_ambiguous, obs_ri = \
            resolve_ambiguities('test', samples, get)

        self.assertEqual(obs_stable, exp_stable)
        self.assertEqual(obs_unobserved, exp_unobserved)
        self.assertEqual(obs_ambiguous, exp_ambiguous)
        self.assertEqual(obs_ri, exp_ri)
Exemple #2
0
    def test_resolve_ambiguities_ambigbug(self):
        import redbiom._requests
        import redbiom
        config = redbiom.get_config()
        get = redbiom._requests.make_get(config)

        redbiom.admin.create_context('test', 'foo')
        redbiom.admin.load_sample_metadata(metadata)
        redbiom.admin.ScriptManager.load_scripts(read_only=False)
        redbiom.admin.load_sample_data(table, 'test', tag='fromtest')
        redbiom.admin.load_sample_metadata(metadata_with_alt)
        redbiom.admin.load_sample_data(table_with_alt, 'test',
                                       tag='fromalt')

        samples = {'fromtest_10317.000005080', 'fromalt_10317.000005080'}
        exp_stable = {'10317.000005080.fromtest': 'fromtest_10317.000005080',
                      '10317.000005080.fromalt': 'fromalt_10317.000005080'}
        exp_unobserved = []
        exp_ambiguous = {'10317.000005080': ['fromtest_10317.000005080',
                                             'fromalt_10317.000005080']}
        exp_ri = {'fromtest_10317.000005080': '10317.000005080.fromtest',
                  'fromalt_10317.000005080': '10317.000005080.fromalt'}

        obs_stable, obs_unobserved, obs_ambiguous, obs_ri = \
            resolve_ambiguities('test', samples, get)

        self.assertEqual(obs_stable, exp_stable)
        self.assertEqual(obs_unobserved, exp_unobserved)
        self.assertEqual({k: set(v) for k, v in obs_ambiguous.items()},
                         {k: set(v) for k, v in exp_ambiguous.items()})
        self.assertEqual(obs_ri, exp_ri)
Exemple #3
0
    def test_resolve_ambiguities_mixed(self):
        import redbiom._requests
        import redbiom
        config = redbiom.get_config()
        get = redbiom._requests.make_get(config)

        redbiom.admin.create_context('test', 'foo')
        redbiom.admin.load_sample_metadata(metadata)
        redbiom.admin.ScriptManager.load_scripts(read_only=False)
        redbiom.admin.load_sample_data(table, 'test', tag=None)

        samples = {
            '10317.000047188', '10317.000046868', '10317.000051129',
            '10317.000012975', '10317.000033804', '10317.000001405',
            '10317.000022252', '10317.000001378', 'foo', 'UNTAGGED_bar',
            'UNTAGGED_10317.000003302'
        }
        exp_stable = {
            "%s.UNTAGGED" % k: k
            for k in samples if 'foo' not in k and 'bar' not in k
        }
        exp_stable.pop('UNTAGGED_10317.000003302.UNTAGGED')
        exp_stable['10317.000003302.UNTAGGED'] = 'UNTAGGED_10317.000003302'
        exp_unobserved = ['foo', 'UNTAGGED_bar']
        exp_ambiguous = {
            '10317.000047188': ['UNTAGGED_10317.000047188'],
            '10317.000046868': ['UNTAGGED_10317.000046868'],
            '10317.000051129': ['UNTAGGED_10317.000051129'],
            '10317.000012975': ['UNTAGGED_10317.000012975'],
            '10317.000033804': ['UNTAGGED_10317.000033804'],
            '10317.000001405': ['UNTAGGED_10317.000001405'],
            '10317.000022252': ['UNTAGGED_10317.000022252'],
            '10317.000001378': ['UNTAGGED_10317.000001378'],
            '10317.000003302': ['UNTAGGED_10317.000003302']
        }
        exp_ri = {
            'UNTAGGED_10317.000047188': '10317.000047188.UNTAGGED',
            'UNTAGGED_10317.000046868': '10317.000046868.UNTAGGED',
            'UNTAGGED_10317.000051129': '10317.000051129.UNTAGGED',
            'UNTAGGED_10317.000012975': '10317.000012975.UNTAGGED',
            'UNTAGGED_10317.000033804': '10317.000033804.UNTAGGED',
            'UNTAGGED_10317.000001405': '10317.000001405.UNTAGGED',
            'UNTAGGED_10317.000022252': '10317.000022252.UNTAGGED',
            'UNTAGGED_10317.000001378': '10317.000001378.UNTAGGED',
            'UNTAGGED_10317.000003302': '10317.000003302.UNTAGGED'
        }

        obs_stable, obs_unobserved, obs_ambiguous, obs_ri = \
            resolve_ambiguities('test', samples, get)

        self.assertEqual(obs_stable, exp_stable)
        self.assertEqual(obs_unobserved, exp_unobserved)
        self.assertEqual(obs_ambiguous, exp_ambiguous)
        self.assertEqual(obs_ri, exp_ri)