diff --git a/system/dataset.py b/system/dataset.py index 7fbfa68..2c4bc49 100644 --- a/system/dataset.py +++ b/system/dataset.py @@ -211,14 +211,28 @@ class CategoryDataset(Dataset): self._type = 'c' def as_dict_lists(self): - """Returns data as dict of indices along first dim""" + """Returns data as dict of indices along first dim. + + ex: data['gene_id'] = ['map0030','map0010', ...] + """ data={} for name,ind in self._map[self.get_dim_name(0)].items(): - data[name] = list(nonzero(self._array[ind,:])) + data[name] = self.get_identifiers(self.get_dim_name(1),list(nonzero(self._array[ind,:]))) self._dictlists = data - self.has_dictlists=True - return data + self.has_dictlists = True + return data + def as_selections(self): + """Returns data as a list of Selection objects. + """ + ret_list = [] + for cat_name,ind in self._map[self.get_dim_name(1)].items(): + ids = self.get_identifiers(self.get_dim_name(0),nonzero(self._array[:,ind])) + selection = Selection(cat_name) + selection.select(cat_name,ids) + ret_list.append(selection) + return ret_list + class GraphDataset(Dataset): """The graph dataset class. @@ -278,8 +292,8 @@ class ReverseDict(dict): All values and keys must be hashable, and unique. d = ReverseDict((['a',1],['b',2])) - print d['a'] - print d.reverse[1] + print d['a'] --> 1 + print d.reverse[1] --> 'a' """ def __init__(self, *args, **kw): dict.__init__(self, *args, **kw)