def draw_small_multiples(nb_col, TPs, SM, lay): """ Create a graph containing a number of thumbnails per line. @type nb_col: Int @param nb_col: Number of thumbnails by line @type TPs: List @param TPs: Time points name @type SM: Tulip graph @param SM: Small Multiples subgraph @type lay: tlp.LayoutProperty @param lay: Coord of nodes @note : disable (better v2) """ bb_tp = tlp.computeBoundingBox(SM) x = 0 y = 0 count = 0 for gr in TPs: x = x + bb_tp.width() + 2000 tp = SM.getSubGraph(gr) if count >= nb_col: x = bb_tp.width() + 2000 y = y - bb_tp.height() - 2000 count = 0 for n in tp.getNodes(): lay[n] = lay[n] + tlp.Vec3f(x, y, 0) for e in tp.getEdges(): Ltmp = [] for el in lay[e]: h = el + tlp.Vec3f(x, y, 0) Ltmp.append(h) lay[e] = Ltmp count += 1
def createNodes(self, rows, fieldnames, createParams): """ Create a new node for each patient in the provided data file and add an edge to every different node (gene). @param rows: a list containing each row of the samples data file (without first row) @param fieldnames: a list containing the name of columns for each row in rows; fieldnames=['gene_name', 'gene_id', 'Patient1', 'Patient2', ..., 'PatientN'] @param createParams: parameters used for the creation of new nodes and edges; createParams.keys=["nodesColor", "edgesColor"] """ ns = self.graph.nodes() dmdict = dm.Maker(self.graph) rlen = len(rows) createParams['coords'] = tlp.Vec3f(0,0,0) addedNodes = dict() for i, row in enumerate(rows): rid = row[fieldnames[1]] # fieldnames[1] should be 'gene_id' node = dmdict.find(rid) if node == False: continue; for num in xrange(2, len(fieldnames)): patient = fieldnames[num] if row[patient] == '': continue if not patient in addedNodes: addedNodes[patient] = self.create_node(node, patient, createParams) createParams['coords'] -= tlp.Vec3f(10,0,0) edge = self.graph.addEdge(addedNodes[patient], node, {self.EDGE_TYPE_COL:row[patient], "viewColor":createParams['edgesColor']}) self.pluginProgress.progress(i, rlen) if self.pluginProgress.state() == tlp.TLP_CANCEL: self.graph.delNodes(addedNodes.values(), True) return 0;
def draw_small_multiples_v2(nb_col, TPs, SM, lay): """ Create a graph containing a number of thumbnails per line. Optimized algorithm to save around 5 seconds. @type nb_col: Int @param nb_col: Number of thumbnails by line @type TPs: List @param TPs: Time points name @type SM: Tulip graph @param SM: Small Multiples subgraph @type lay: tlp.LayoutProperty @param lay: Coord of nodes """ bb_tp = tlp.computeBoundingBox(SM) x = 0 y = 0 count = 0 for gr in TPs: x = x + bb_tp.width() + 2000 tp = SM.getSubGraph(gr) if count >= nb_col: x = bb_tp.width() + 2000 y = y - bb_tp.height() - 2000 count = 0 count = count + 1 lay.translate(tlp.Vec3f(x, y, 0), tp)
def run(self): # compute a spanning tree of the input graph spanningTree = tlp.TreeTest.computeTree(self.graph) # get edges to use an input for the H3 layout implementation from buzzfeed # and reverse their orientation as it does not use the same direction as in Tulip graphs edges = [self.graph.ends(e)[::-1] for e in spanningTree.getEdges()] # compute the layout tree = Tree(edges) # copy result to Tulip layout property self.result.setAllEdgeValue([]) for n in self.graph.getNodes(): self.result[n] = tlp.Coord(tree.nodes[n].coord.x, tree.nodes[n].coord.y, tree.nodes[n].coord.z) # apply some scaling factor to the layout to get a correct rendering # in Tulip scaling = 1000 if self.dataSet: scaling = self.dataSet["layout scaling"] self.result.scale(tlp.Vec3f(scaling)) # cleanup computed spanning tree tlp.TreeTest.cleanComputedTree(self.graph, spanningTree) return True
def create_node(self, node, nodeName, userParams): nColor = userParams['nodesColor'] eColor = userParams['edgesColor'] params = dict.fromkeys(["viewLabel", "name", "sharedName"], nodeName) params["viewColor"] = nColor params["viewSize"] = tlp.Vec3f(1,1,1) params["viewLayout"] = userParams['coords'] params["isPatient"] = True new_node = self.graph.addNode(params) return new_node
def draw_small_multiples(nb_col, TPs, SM, lay): """ """ bb_tp = tlp.computeBoundingBox(SM) x = 0 y = 0 count = 0 for gr in TPs: x = x + bb_tp.width() + 2000 tp = SM.getSubGraph(gr) if count >= nb_col: x = bb_tp.width() + 2000 y = y - bb_tp.height() - 2000 count = 0 for n in tp.getNodes(): lay[n] = lay[n] + tlp.Vec3f(x, y, 0) for e in tp.getEdges(): Ltmp = [] for el in lay[e]: h = el + tlp.Vec3f(x, y, 0) Ltmp.append(h) lay[e] = Ltmp count += 1
def draw_small_multiples_v2(nb_col, TPs, SM, lay): #TODO dire qu'on a gagné du temps par rapport à l'autre v1 bb_tp = tlp.computeBoundingBox(SM) x = 0 y = 0 count = 0 for gr in TPs: x = x + bb_tp.width() + 2000 tp = SM.getSubGraph(gr) #lay = tp.getLayoutProperty("viewlayout") if count >= nb_col: x = bb_tp.width() + 2000 y = y - bb_tp.height() - 2000 count = 0 count = count + 1 lay.translate(tlp.Vec3f(x, y, 0), tp)
def positionSmallMultiples(g, smallG, columnNumber): layout = g.getLayoutProperty("viewLayout") graphBoundingBox = tlp.computeBoundingBox(g) gHeight = graphBoundingBox.height() gWidth = graphBoundingBox.width() n = 1 y = 0 line = 0 for smallImg in smallG.getSubGraphs(): if n == columnNumber + 1: line += 1 y = -gHeight * line * 1.5 n = 1 x = gWidth * n * 1.5 newCenter = tlp.Vec3f(x, y, 0) layout.center(newCenter, smallImg) n += 1
def subgraph_grid(multiple_graph, nbcolumn): """ Align all the subgraph of a graph, in a grid. Author: Pierre Jacquet Modfied by Eliot Ragueneau Args: multiple_graph (tlp.Graph): A parent graph nbcolumn (int): number of column in the grid """ # get one subgraph's bounding box bounding_box = tlp.computeBoundingBox(multiple_graph.getNthSubGraph(1)) size_x = 1.5 * abs(bounding_box[1][0] - bounding_box[0][0]) size_y = 1.5 * abs(bounding_box[1][1] - bounding_box[0][1]) # Multiplied by 1.5 to have an separation between graphs number_of_visited_subgraph = 0 offset_x = 0 offset_y = 0 layout = multiple_graph.getLayoutProperty("viewLayout") for sub_graph in multiple_graph.getSubGraphs(): number_of_visited_subgraph += 1 for node in sub_graph.getNodes(): layout[node] += tlp.Vec3f(offset_x, -offset_y, 0) # Move the node by offsets values for edge in sub_graph.getEdges(): control_points = layout[edge] new_control_points = [] for vector in control_points: new_control_points.append( tuple(map(sum, zip(vector, (offset_x, -offset_y, 0))))) layout[edge] = new_control_points # Calculate the new offset value offset_x = number_of_visited_subgraph % nbcolumn * size_x offset_y = (number_of_visited_subgraph // nbcolumn) * size_y
def setLociSize(self): self.viewSize.setAllNodeValue(tlp.Vec3f(1e4, 1e4, 0.5))