Added existing_identifiers function to Dataset.
Added colouring drag'n'drop to DAGPlot in gobrowser module.
This commit is contained in:
parent
a45743c31e
commit
dc7f7dbde2
|
@ -194,6 +194,12 @@ class Dataset:
|
||||||
for key in idents if self._map[dim].has_key(key)]
|
for key in idents if self._map[dim].has_key(key)]
|
||||||
return asarray(index)
|
return asarray(index)
|
||||||
|
|
||||||
|
def existing_identifiers(self, dim, idents):
|
||||||
|
if not isinstance(idents, list) and not isinstance(idents, set):
|
||||||
|
raise ValueError("idents needs to be a list/set got: %s" %type(idents))
|
||||||
|
|
||||||
|
return [key for key in idents if self._map[dim].has_key(key)]
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
""" Returns deepcopy of dataset.
|
""" Returns deepcopy of dataset.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -477,7 +477,6 @@ class PlotDagFunction(workflow.Function):
|
||||||
|
|
||||||
def run(self, selection):
|
def run(self, selection):
|
||||||
g = self.get_network(list(selection['go-terms']))
|
g = self.get_network(list(selection['go-terms']))
|
||||||
# print g.edges()
|
|
||||||
ds = dataset.GraphDataset(networkx.adj_matrix(g),
|
ds = dataset.GraphDataset(networkx.adj_matrix(g),
|
||||||
[('go-terms', g.nodes()), ('_go-terms', g.nodes())],
|
[('go-terms', g.nodes()), ('_go-terms', g.nodes())],
|
||||||
name="DAG")
|
name="DAG")
|
||||||
|
@ -674,3 +673,47 @@ class DagPlot(plots.Plot):
|
||||||
self.selected_nodes.set_linewidth(linewidth)
|
self.selected_nodes.set_linewidth(linewidth)
|
||||||
self.canvas.draw()
|
self.canvas.draw()
|
||||||
|
|
||||||
|
def is_mappable_with(self, obj):
|
||||||
|
"""Returns True if dataset/selection is mappable with this plot.
|
||||||
|
"""
|
||||||
|
if isinstance(obj, fluents.dataset.Dataset):
|
||||||
|
if self.current_dim in obj.get_dim_name():
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _update_color_from_dataset(self, ds):
|
||||||
|
"""Updates the facecolors from a dataset.
|
||||||
|
"""
|
||||||
|
|
||||||
|
array = ds.asarray()
|
||||||
|
|
||||||
|
#only support for 2d-arrays:
|
||||||
|
try:
|
||||||
|
m, n = array.shape
|
||||||
|
except:
|
||||||
|
raise ValueError, "No support for more than 2 dimensions."
|
||||||
|
# is dataset a vector or matrix?
|
||||||
|
if not n==1:
|
||||||
|
# we have a category dataset
|
||||||
|
if isinstance(ds, fluents.dataset.CategoryDataset):
|
||||||
|
vec = dot(array, diag(arange(n))).sum(1)
|
||||||
|
else:
|
||||||
|
vec = array.sum(1)
|
||||||
|
else:
|
||||||
|
vec = array.ravel()
|
||||||
|
|
||||||
|
indices = ds.get_indices(self.current_dim, self.nodes)
|
||||||
|
nodes = ds.existing_identifiers(self.current_dim, self.nodes)
|
||||||
|
v = vec.take(indices, 0)
|
||||||
|
d = dict(zip(nodes, list(v)))
|
||||||
|
|
||||||
|
map_vec = zeros(len(self.nodes))
|
||||||
|
for i, n in enumerate(self.nodes):
|
||||||
|
map_vec[i] = d.get(n, -1)
|
||||||
|
|
||||||
|
# update facecolors
|
||||||
|
self.node_collection.set_array(map_vec)
|
||||||
|
self.node_collection.set_clim(map_vec.min(), map_vec.max())
|
||||||
|
self.node_collection.update_scalarmappable() #sets facecolors from array
|
||||||
|
self.canvas.draw()
|
||||||
|
|
||||||
|
|
Reference in New Issue