def test_ids_from(self): 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) sample_ids = table.ids()[:] sample_ids = np.array(["UNTAGGED_%s" % i for i in sample_ids]) ids = table.ids(axis='observation').copy() random.shuffle(ids) for i in range(1, 5): fetch = ids[:i] assoc_ids = [] for id_ in fetch: assoc_data = table.data(id_, axis='observation') assoc_ids.append(sample_ids[assoc_data > 0]) exp_exact = reduce(set.intersection, map(set, assoc_ids)) exp_union = reduce(set.union, map(set, assoc_ids)) obs_exact = ids_from(iter(fetch), True, 'feature', ['test']) obs_union = ids_from(iter(fetch), False, 'feature', ['test']) self.assertEqual(obs_exact, exp_exact) self.assertEqual(obs_union, exp_union)
def test_ids_from_multicontext(self): redbiom.admin.create_context('test', 'foo') redbiom.admin.create_context('test2', 'foo') redbiom.admin.ScriptManager.load_scripts(read_only=False) redbiom.admin.load_sample_metadata(metadata) redbiom.admin.load_sample_data(table, 'test', tag=None) redbiom.admin.load_sample_data(table, 'test2', tag=None) d = table.data(table.ids()[0], dense=True) ids = table.ids(axis='observation')[d.nonzero()] exp = set([ 'UNTAGGED_' + table.ids()[0], ]) obs = ids_from(iter(ids), True, 'feature', ['test', 'test2']) self.assertEqual(obs, exp) redbiom.admin.create_context('testalt', 'foo') redbiom.admin.load_sample_metadata(metadata_with_alt) redbiom.admin.load_sample_data(table_with_alt, 'testalt', tag=None) exp = {'UNTAGGED_10317.000051129alt', 'UNTAGGED_10317.000051129'} d = table.data('10317.000051129', dense=True) ids = table.ids(axis='observation')[d.nonzero()] obs = ids_from(iter(ids), True, 'feature', ['test', 'test2', 'testalt']) self.assertEqual(obs, exp)
def test_ids_from_filter(self): 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) id_ = [ table.ids(axis='observation')[0], ] obs = ids_from(id_, False, 'feature', [ 'test', ], min_count=3) self.assertEqual(len(obs), 3) obs = ids_from(id_, False, 'feature', [ 'test', ]) self.assertEqual(len(obs), 4)
def test_ids_from_samples(self): 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) obs_ids = table.ids(axis='observation') exp = set(obs_ids[table.data(table.ids()[0]) > 0]) exp.update(set(obs_ids[table.data(table.ids()[1]) > 0])) to_fetch = ['UNTAGGED_%s' % i for i in table.ids()[:2]] obs = ids_from(to_fetch, False, 'sample', ['test']) self.assertEqual(obs, exp)