Added method: as_selections() to CategoryDataset
This commit is contained in:
parent
026dc639e3
commit
b000792faa
|
@ -211,14 +211,28 @@ class CategoryDataset(Dataset):
|
||||||
self._type = 'c'
|
self._type = 'c'
|
||||||
|
|
||||||
def as_dict_lists(self):
|
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={}
|
data={}
|
||||||
for name,ind in self._map[self.get_dim_name(0)].items():
|
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._dictlists = data
|
||||||
self.has_dictlists=True
|
self.has_dictlists = True
|
||||||
return data
|
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):
|
class GraphDataset(Dataset):
|
||||||
"""The graph dataset class.
|
"""The graph dataset class.
|
||||||
|
@ -278,8 +292,8 @@ class ReverseDict(dict):
|
||||||
All values and keys must be hashable, and unique.
|
All values and keys must be hashable, and unique.
|
||||||
|
|
||||||
d = ReverseDict((['a',1],['b',2]))
|
d = ReverseDict((['a',1],['b',2]))
|
||||||
print d['a']
|
print d['a'] --> 1
|
||||||
print d.reverse[1]
|
print d.reverse[1] --> 'a'
|
||||||
"""
|
"""
|
||||||
def __init__(self, *args, **kw):
|
def __init__(self, *args, **kw):
|
||||||
dict.__init__(self, *args, **kw)
|
dict.__init__(self, *args, **kw)
|
||||||
|
|
Reference in New Issue