def color_gradient(nb_gradient): """ Compute and return the color gradient from red to green for a color mapping algorithm. @type nb_gradient: int @param nb_gradient: number of gradients @rtype : list @return : the list of (tlp.Color) """ colors = [] r = 255 g = 0 b = 0 gradient = 255 / (nb_gradient / 2) for i in range(nb_gradient / 2): colors.append(tlp.Color(r, g, b)) colors.append(tlp.Color(r, g, b)) r = r - gradient r = 0 colors.append(tlp.Color.Black) colors.append(tlp.Color.Black) for i in range(nb_gradient / 2): colors.append(tlp.Color(r, g, b)) colors.append(tlp.Color(r, g, b)) g = g + gradient return colors
def visu_node_edge(gr, size, color, viewBorderColor, viewBorderWidth): """ Input : The graph, the viewSize, the viewColor property, the viewBorderColor and the viewBorderWidth properties Function : Applies a style with the help of a dictionary "aspect" on the nodes and the edges regarding their properties Output : NONE """ interaction = gr["Interaction"] expression = gr["Expression"] aspect = { "node": { "up": [tlp.Color(0, 255, 0), tlp.Size(2, 2, 2)], "down": [tlp.Color(255, 0, 0), tlp.Size(2, 2, 2)], "stable": [tlp.Color(105, 105, 105), tlp.Size(1, 1, 1)], "intergenic": [tlp.Color(200, 200, 200), tlp.Size(1, 1, 1)], "nan": [tlp.Color(255, 255, 255), tlp.Size(1, 1, 1)] }, "edge": { "gain": [tlp.Color.Blue, 10], "loss": [tlp.Color.Yellow, 10], "stable": [tlp.Color.Gray, 0] } } for node in gr.getNodes(): color[node] = aspect["node"][expression[node]][0] size[node] = aspect["node"][expression[node]][1] for edge in gr.getEdges(): viewBorderColor[edge] = aspect["edge"][interaction[edge]][0] viewBorderWidth[edge] = aspect["edge"][interaction[edge]][1] color[edge] = aspect["edge"][interaction[edge]][0]
def getUserColor(self, param): try: c = self.dataSet[param] color = tlp.Color(c.getR(),c.getG(),c.getB(),c.getA()) return color except Exception: return tlp.Color(0,0,0,255);
def preprocessing(gr): """ Affect a pre-treatment to a graph (Size of nodes, color edges, add nodes name, etc...). @type gr: tlp.Graph @param gr: current graph """ # Load properties viewLabel = gr.getStringProperty("viewLabel") LabelPosition = gr.getIntegerProperty("viewLabelPosition") layout = gr.getLayoutProperty("viewLayout") viewSize = gr.getSizeProperty("viewSize") viewColor = gr.getColorProperty("viewColor") viewShape = gr.getIntegerProperty("viewShape") Locus = gr.getStringProperty("Locus") # Define colors green = tlp.Color(0, 255, 0) red = tlp.Color(255, 0, 0) size = (60.0, 60.0, 60.0) for n in graph.getNodes(): viewLabel[n] = Locus[n] viewSize[n] = size viewShape[n] = 14 #circle LabelPosition[n] = tlp.LabelPosition.Center for e in gr.getEdges(): properties = gr.getEdgePropertiesValues(e) if (properties["Positive"] == True): viewColor[e] = green else: viewColor[e] = red # Apply drawing algorithm paramalgo = tlp.getDefaultPluginParameters("FM^3 (OGDF)") paramalgo["Node size"] = 'viewSize' gr.applyLayoutAlgorithm("FM^3 (OGDF)", layout, paramalgo)
def main(graph): #graph.applyAlgorithm("Incremental") pos = graph.getLayoutProperty("viewLayout") previous_pos = tlp.LayoutProperty(graph) color = graph.getColorProperty("viewColor") size = graph.getSizeProperty("viewSize") it = 0 steps = 100 for g in graph.getSubGraphs(): print(g) sg_pos = g.getLocalLayoutProperty("viewLayout") is_new_node = g.getLocalBooleanProperty("isNewNode") is_new_edge = g.getLocalBooleanProperty("isNewEdge") sg_color = g.getLocalColorProperty("viewColor") for n in graph.getNodes(): if not n in g.getNodes(): color[n] = tlp.Color(0, 0, 0, 0) pos[n] = sg_pos[g.getOneNode()] else: color[n] = sg_color[n] pos[n] = sg_pos[n] for e in graph.getEdges(): if not e in g.getEdges(): color[e] = tlp.Color(0, 0, 0, 0) else: color[e] = sg_color[e] if it > 0: for n in is_new_node.getNodesEqualTo(True): pos[n] = sg_pos[n] color[n].setA(0) size[n] = tlp.Size(6) for e in is_new_edge.getEdgesEqualTo(True): color[e].setA(0) for i in range(1, steps + 1): t = 1.0 * i / steps # "/" operator <=> integer division in python 2.7, hence the float constant for n in g.getNodes(): if is_new_node[n]: alpha = lerp(0, 255, t) c = color[n] color[n] = tlp.Color(c.getR(), c.getG(), c.getB(), int(alpha)) else: pos[n] = lerp(previous_pos[n], sg_pos[n], t) for e in g.getEdges(): if is_new_edge[e]: alpha = lerp(0, 255, t) c = color[e] color[e] = tlp.Color(c.getR(), c.getG(), c.getB(), int(alpha)) updateVisualization(True) for n in is_new_node.getNodesEqualTo(True): size[n] = tlp.Size(1) updateVisualization(True) #pauseScript() #time.sleep(0.1) previous_pos.copy(sg_pos) it += 1
def preTraitementVisualisation(graph): """ Pré-traitement & première visualisation du graph """ # Partie 1 viewLabel = graph.getStringProperty("viewLabel") Locus = graph.getStringProperty("Locus") viewSize = graph.getSizeProperty("viewSize") viewFontSize = graph.getIntegerProperty("viewFontSize") viewColor = graph.getColorProperty("viewColor") viewTgtAnchorShape = graph.getIntegerProperty("viewTgtAnchorShape") viewTgtAnchorSize = graph.getSizeProperty("viewTgtAnchorSize") node_size = tlp.Size(100000, 30000, 1) for n in graph.getNodes(): #Ajoute des labels issu de Locus aux neouds du graph viewLabel[n] = Locus[n] viewFontSize[n] = 1 #Affection d'une taille non null à chaque sommet afin de pouvoir visualiser correctement les étiquettes viewSize[n] = node_size # Affectation des couleurs des arretes et la forme des extremités selon le type de régulation (positive ou negative) Negative = graph.getBooleanProperty("Negative") blue = tlp.Color(58, 95, 205) square = tlp.EdgeExtremityShape.Square Positive = graph.getBooleanProperty("Positive") green = tlp.Color(69, 139, 0) arrow = tlp.EdgeExtremityShape.Arrow for e in graph.getEdges(): if Negative[e] is True: #Regulation negatif viewColor[e] = blue viewTgtAnchorShape[e] = square elif Positive[e] is True: #regulation poistive viewColor[e] = green viewTgtAnchorShape[e] = arrow viewTgtAnchorSize[e] = node_size #Affectation des positions aux sommets du graphe par l'application un model de force "FM^3 (OGDF)" viewLayout = graph.getLayoutProperty("viewLayout") fm3pParams = tlp.getDefaultPluginParameters("FM^3 (OGDF)", graph) fm3pParams["Unit edge length"] = 400 graph.applyLayoutAlgorithm("FM^3 (OGDF)", viewLayout, fm3pParams)
def visGraph(G) : flow=G.getDoubleProperty("flow"); color=G.getColorProperty("viewColor"); color.setAllNodeValue(tlp.Color(0,0,0,0)); size=G.getSizeProperty("viewSize"); for u in G.getNodes() : if flow[u]>0 : color[u]=tlp.Color(255,0,0,255); u_s = (flow[u]-flow.getNodeMin())/(flow.getNodeMax()-flow.getNodeMin())*1.+0.05; size[u]=tlp.Size(u_s,u_s,1.); else : size[u]=tlp.Size(0.001,0.001,1.);
def pretraitement(graph, Locus, Negative, Positive, viewBorderColor, viewLabel, viewLayout, viewSize): size = 1000 for n in graph.getNodes(): viewSize[n] = tlp.Size(10000, 3000, 10) viewLabel[n] = Locus[n] for n in graph.getEdges(): if Negative[n] == True: if Positive[n] == True: viewBorderColor[n] = tlp.Color.Black else: viewBorderColor[n] = tlp.Color(0, 0, 225) elif Positive[n] == True: viewBorderColor[n] = tlp.Color(0, 200, 0)
def coloring_nodes(graph): """This is an example algorithm that colors nodes depending on their degree""" blue = tlp.Color(0, 0, 255) green = tlp.Color(0, 255, 0) viewColor = graph.getColorProperty("viewColor") viewMetric = graph.getDoubleProperty("viewMetric") success, about = graph.applyDoubleAlgorithm( 'Betweenness Centrality', tlp.getDefaultPluginParameters('Betweenness Centrality', graph)) if success: for n in graph.getNodes(): viewColor[n] = blue if viewMetric[n] > 10 else green else: print(about)
def initEdges(graph, negative, positive, color): red = tlp.Color(255,0,0) green = tlp.Color(0,255,0) darkBlue = tlp.Color(0,0,80) orange = tlp.Color(255,150,0) for e in graph.getEdges(): if (negative[e] == True and positive[e] == False): color.setEdgeValue(e, red) if (negative[e] == False and positive[e] == True): color.setEdgeValue(e, green) if (negative[e] == False and positive[e] == False): color.setEdgeValue(e, darkBlue) if (negative[e] == True and positive[e] == True): color.setEdgeValue(e, orange)
def importGraph(self): # get parameters self.base_url = self.dataSet["url"] self.min_score = self.dataSet["min score"] self.max_depth = self.dataSet["max depth"] self.logo_folder = self.dataSet["logo folder path"] # init properties for logos if self.logo_folder != '': color = self.graph.getColorProperty("viewColor") color.setAllNodeValue(tlp.Color(255, 255, 255, 255)) shape = self.graph.getIntegerProperty("viewShape") shape.setAllNodeValue(0) # crawl bands info bandNodes = {} # MA id to Band object, Tulip node self.crawlSimilarBands(bandNodes, self.base_url, 0) # add graph edges score = self.graph.getDoubleProperty("score") for band, n in bandNodes.values(): for id_sim, url_sim, score_sim in band.similar_bands: if id_sim in bandNodes.keys(): sim_b, sim_n = bandNodes[id_sim] e = self.graph.addEdge(n, sim_n) score[e] = score_sim return True
def run(self): p = parameters_value d = self.dataSet p[boolean_param_name] = d[boolean_param_name] p[int_param_name] = d[int_param_name] p[float_param_name] = d[float_param_name] p[string_param_name] = d[string_param_name] p[string_collection_param_name] = d[string_collection_param_name] p[color_param_name] = tlp.Color(d[color_param_name]) p[color_scale_param_name] = tlp.ColorScale(d[color_scale_param_name]) p[boolean_prop_param_name] = d[boolean_prop_param_name] p[color_prop_param_name] = d[color_prop_param_name] p[double_prop_param_name] = d[double_prop_param_name] p[int_prop_param_name] = d[int_prop_param_name] p[layout_prop_param_name] = d[layout_prop_param_name] p[size_prop_param_name] = d[size_prop_param_name] p[string_prop_param_name] = d[string_prop_param_name] p[boolean_vec_prop_param_name] = d[boolean_vec_prop_param_name] p[color_vec_prop_param_name] = d[color_vec_prop_param_name] p[double_vec_prop_param_name] = d[double_vec_prop_param_name] p[int_vec_prop_param_name] = d[int_vec_prop_param_name] p[coord_vec_prop_param_name] = d[coord_vec_prop_param_name] p[size_vec_prop_param_name] = d[size_vec_prop_param_name] p[string_vec_prop_param_name] = d[string_vec_prop_param_name] d[out_boolean_param_name] = out_boolean_param_value d[out_int_param_name] = out_int_param_value d[out_float_param_name] = out_float_param_value d[out_string_param_name] = out_string_param_value return True
def pretraitement(graph, Locus, Negative, Positive, viewBorderColor, viewLabel, viewLayout, viewSize): ''' Change la taille et la couleur des éléments du graphe afin qu'il soit plus lisible ''' size = 1000 for n in graph.getNodes(): viewSize[n] = tlp.Size(10000,3000,10) viewLabel[n] = Locus[n] for n in graph.getEdges(): if Negative[n] == True: if Positive[n] == True: viewBorderColor[n] = tlp.Color.Black else: viewBorderColor[n] = tlp.Color(0,0,225) elif Positive[n] == True: viewBorderColor[n] = tlp.Color(0,200,0)
def color_by_id(graph, id2color): root = graph.getRoot() view_color = root.getColorProperty(VIEW_COLOR) c_keys = { root[ID][n] for n in graph.getNodes() if root[TYPE][n] == TYPE_COMPARTMENT } i = len(c_keys) colors = get_n_colors(i, 0.7, 0.7) key2color = dict(zip(c_keys, colors)) for n in (n for n in graph.getNodes() if not graph.isMetaNode(n) and root[TYPE][n] == TYPE_REACTION): r, g, b = id2color[root[ID] [n]] if root[ID][n] in id2color else BLUE_RGB view_color[n] = tlp.Color(r, g, b) for m in graph.getInOutNodes(n): type_ = root[TYPE][m] if TYPE_SPECIES == type_: view_color[m] = GRAY if root[UBIQUITOUS][n] else view_color[n] for e in graph.getInOutEdges(n): view_color[e] = GRAY if root[UBIQUITOUS][root.target( e)] or root[UBIQUITOUS][root.source(e)] else view_color[n] for n in (n for n in graph.getNodes() if not graph.isMetaNode(n) and root[TYPE][n] == TYPE_SPECIES): if root[UBIQUITOUS][n]: r, g, b = GRAY_RGB elif root[ID][n] not in id2color: r, g, b = RED_RGB else: r, g, b = id2color[root[ID][n]] view_color[n] = tlp.Color(r, g, b) for n in (n for n in graph.getNodes() if graph.isMetaNode(n)): type_ = root[TYPE][n] if TYPE_COMPARTMENT == type_: r, g, b = key2color[root[ID][n]] view_color[n] = tlp.Color(r, g, b) else: view_color[n] = view_color[next( root[VIEW_META_GRAPH][n].getNodes())]
def color_by_compartment(graph, c_id2m_ids): root = graph.getRoot() view_color = root.getColorProperty(VIEW_COLOR) i = len(c_id2m_ids.keys()) + 1 colors = get_n_colors(i, 0.7, 0.8) ub_colors = get_n_colors(i, 0.2, 0.8) key2color = dict(zip(c_id2m_ids.keys(), colors[1:])) key2ub_color = dict(zip(c_id2m_ids.keys(), ub_colors[1:])) m_id2color = {} m_id2ub_color = {} for c_id, m_ids in c_id2m_ids.items(): for m_id in m_ids: m_id2color[m_id] = key2color[c_id] m_id2ub_color[m_id] = key2ub_color[c_id] for n in graph.getNodes(): view_color[n] = WHITE for n in (n for n in graph.getNodes() if not graph.isMetaNode(n) and root[TYPE][n] == TYPE_SPECIES): r, g, b = m_id2color[root[ID][n]] if root[ID][n] in m_id2color else ( 255, 255, 255) for r_n in graph.getInOutNodes(n): type_ = root[TYPE][r_n] if TYPE_REACTION == type_ and view_color[r_n] == WHITE: view_color[r_n] = tlp.Color(r, g, b) if root[UBIQUITOUS][n]: r, g, b = m_id2ub_color[ root[ID][n]] if root[ID][n] in m_id2ub_color else (255, 255, 255) view_color[n] = tlp.Color(r, g, b) for n in (n for n in graph.getNodes() if graph.isMetaNode(n)): type_ = root[TYPE][n] if TYPE_COMPARTMENT == type_: # view_color[n] = key2comp_color[root[NAME][n]] if root[NAME][n] in key2comp_color else TRANSPARENT_GRAY continue view_color[n] = view_color[next(root[VIEW_META_GRAPH][n].getNodes())]
def preprocessing(gr, viewColor): viewLabel = gr.getStringProperty("viewLabel") LabelPosition = gr.getIntegerProperty("viewLabelPosition") viewSize = gr.getIntegerProperty("size of nodes") green = tlp.Color(0, 255, 0) red = tlp.Color(255, 0, 0) size = 100 for n in graph.getNodes(): properties = gr.getNodePropertiesValues(n) locus_name = properties["locus"] viewLabel[n] = locus_name viewSize[n] = size LabelPosition[n] = tlp.LabelPosition.Center for e in gr.getEdges(): properties = gr.getEdgePropertiesValues(e) if (properties["Positive"] == True): viewColor[e] = green else: viewColor[e] = red
def colorLoci(self): self.colorLociByExpression('intergenic', tlp.Color(222, 212, 195, 80)) self.colorLociByExpression('up', tlp.Color(0, 255, 0)) self.colorLociByExpression('down', tlp.Color(255, 0, 0)) self.colorLociByExpression('stable', tlp.Color(0, 0, 0, 80)) self.colorLociByExpression('', tlp.Color(0, 0, 0, 80)) self.colorLociByExpression('nan', tlp.Color(255, 230, 255, 80))
def run(self): # retrieve parameter values metric = self.dataSet['metric'] aspectRatio = self.dataSet['aspect ratio'] treeMapType = self.dataSet['treemap type'] borderColor = self.dataSet['border color'] layout = self.dataSet['layout'] sizes = self.dataSet['sizes'] shapes = self.dataSet['shapes'] colors = self.dataSet['colors'] borderColors = self.dataSet['border colors'] borderWidths = self.dataSet['border widths'] # call the 'Squarified Tree Map' layout algorithm params = tlp.getDefaultPluginParameters('Squarified Tree Map', self.graph) params['Node Size'] = sizes params['Node Shape'] = shapes params['metric'] = metric params['Aspect Ratio'] = aspectRatio params['Treemap Type'] = treeMapType self.graph.applyLayoutAlgorithm('Squarified Tree Map', layout, params) # set edge colors and border colors to be fully transparent colors.setAllEdgeValue(tlp.Color(0, 0, 0, 0)) borderColors.setAllEdgeValue(tlp.Color(0, 0, 0, 0)) # set new border color for nodes borderColors.setAllNodeValue(borderColor) # ensure node borders are visible borderWidths.setAllNodeValue(1.0) # set the square shape to all leaf nodes for n in self.graph.getNodes(): if self.graph.outdeg(n) == 0: shapes[n] = tlp.NodeShape.Square return True
def color_by_pathway(graph, pw2r_ids): root = graph.getRoot() view_color = root.getColorProperty(VIEW_COLOR) i = len(pw2r_ids.keys()) + 1 colors = get_n_colors(i, 0.5, 0.8) key2color = dict(zip(pw2r_ids.keys(), colors[1:])) r_id2color = {} for pw, r_ids in pw2r_ids.items(): for r_id in r_ids: r_id2color[r_id] = key2color[pw] for n in graph.getNodes(): view_color[n] = WHITE for n in (n for n in graph.getNodes() if not graph.isMetaNode(n) and root[TYPE][n] == TYPE_REACTION): r, g, b = r_id2color[root[ID][n]] if root[ID][n] in r_id2color else ( 255, 255, 255) view_color[n] = tlp.Color(r, g, b) for m in graph.getInOutNodes(n): type_ = root[TYPE][m] if TYPE_SPECIES == type_ and view_color[m] == WHITE: if root[UBIQUITOUS][n]: r_, g_, b_ = 180, 180, 180 else: r_, g_, b_ = r, g, b view_color[m] = tlp.Color(r_, g_, b_) for n in (n for n in graph.getNodes() if graph.isMetaNode(n)): type_ = root[TYPE][n] if TYPE_COMPARTMENT == type_: # view_color[n] = key2comp_color[root[NAME][n]] if root[NAME][n] in key2comp_color else TRANSPARENT_GRAY continue view_color[n] = view_color[next(root[VIEW_META_GRAPH][n].getNodes())]
def Heatmap(heatmap, graph, TP, viewColor, viewSize, viewMCLMetric, viewMean, viewStd): """ Permet la création de la heatmap """ maxCluster = 0 count = 1.0 for n in graph.getNodes(): if viewMCLMetric[n] > maxCluster: maxCluster = int(viewMCLMetric[n]) for j in range(maxCluster): for n in graph.getNodes(): if viewMCLMetric[n] == j: for i in range(len(TP)): tpValue = (TP[i][n] - viewMean[n]) / viewStd[n] if (tpValue >= 0): heatmap.addNode({ "viewLayout": tlp.Coord(i, count / 20.0, 0), "viewColor": tlp.Color(0, int(255 / 2 * tpValue), 0), "viewSize": tlp.Size(1, 0.05, 1), "viewMCLMetric": j }) else: heatmap.addNode({ "viewLayout": tlp.Coord(i, count / 20.0, 0), "viewColor": tlp.Color(-int(255 / 2 * tpValue), 0, 0), "viewSize": tlp.Size(1, 0.05, 1), "viewMCLMetric": j }) count += 1
def run(self): parameters_value[boolean_param_name] = self.dataSet[boolean_param_name] parameters_value[int_param_name] = self.dataSet[int_param_name] parameters_value[float_param_name] = self.dataSet[float_param_name] parameters_value[string_param_name] = self.dataSet[string_param_name] parameters_value[string_collection_param_name] = self.dataSet[ string_collection_param_name] parameters_value[color_param_name] = tlp.Color( self.dataSet[color_param_name]) parameters_value[color_scale_param_name] = tlp.ColorScale( self.dataSet[color_scale_param_name]) parameters_value[boolean_prop_param_name] = self.dataSet[ boolean_prop_param_name] parameters_value[color_prop_param_name] = self.dataSet[ color_prop_param_name] parameters_value[double_prop_param_name] = self.dataSet[ double_prop_param_name] parameters_value[int_prop_param_name] = self.dataSet[ int_prop_param_name] parameters_value[layout_prop_param_name] = self.dataSet[ layout_prop_param_name] parameters_value[size_prop_param_name] = self.dataSet[ size_prop_param_name] parameters_value[string_prop_param_name] = self.dataSet[ string_prop_param_name] parameters_value[boolean_vec_prop_param_name] = self.dataSet[ boolean_vec_prop_param_name] parameters_value[color_vec_prop_param_name] = self.dataSet[ color_vec_prop_param_name] parameters_value[double_vec_prop_param_name] = self.dataSet[ double_vec_prop_param_name] parameters_value[int_vec_prop_param_name] = self.dataSet[ int_vec_prop_param_name] parameters_value[coord_vec_prop_param_name] = self.dataSet[ coord_vec_prop_param_name] parameters_value[size_vec_prop_param_name] = self.dataSet[ size_vec_prop_param_name] parameters_value[string_vec_prop_param_name] = self.dataSet[ string_vec_prop_param_name] self.dataSet[out_boolean_param_name] = out_boolean_param_value self.dataSet[out_int_param_name] = out_int_param_value self.dataSet[out_float_param_name] = out_float_param_value self.dataSet[out_string_param_name] = out_string_param_value return True
def echelle_couleur(): # On crée la liste des couleurs optimales # On se base sur le site suivant # https://colorbrewer2.org/#type=qualitative&scheme=Paired&n=12 colors = [] colors.append(tlp.Color(166, 206, 227)) colors.append(tlp.Color(251, 154, 153)) colors.append(tlp.Color(177, 89, 40)) colors.append(tlp.Color(51, 160, 44)) colors.append(tlp.Color(202, 178, 214)) colors.append(tlp.Color(253, 191, 111)) colors.append(tlp.Color(31, 120, 180)) colors.append(tlp.Color(255, 255, 153)) colors.append(tlp.Color(227, 26, 28)) colors.append(tlp.Color(178, 223, 138)) colors.append(tlp.Color(255, 127, 0)) colors.append(tlp.Color(106, 61, 154)) return (tlp.ColorScale(colors))
def draw(): """Draw all the methods of the list in subgraphs and color its nodes accordingly to their expression status. Assemble all the subgraphs in one parallel view """ # Check if all the methods are complete to draw them for method in Method.methodLines: if not method.is_complete(): return False # Copy the original graph in a subgraph to keep it intact source = self.graph.addSubGraph("Source") copy_graph(source, self.graph) # Create a sibling graph of source which will get all the duplicated subgraphs parallel_multi_graph = self.graph.addSubGraph( "Parallel Methods Analysis") for method in Method.methodLines: # Create a duplicated subgraph subgraph = parallel_multi_graph.addSubGraph( name=str(method)) copy_graph(subgraph, source) name_to_node = { } # Dictionary to associate a gene name to its node # Set all nodes and edges of the subgraph to a neutral color viewColor = subgraph.getColorProperty('viewColor') viewSize = subgraph.getSizeProperty("viewSize") viewColor.setAllEdgeValue(tlp.Color(128, 128, 128, 50)) for node in subgraph.getNodes(): viewColor[node] = tlp.Color(128, 128, 128, 50) name_to_node[subgraph.getNodePropertiesValues(node) ["name"]] = node # Get up regulated gene names described by the current method by a cypher query up_regulated = [ result["name"] for result in neo_graph.run( "MATCH " + method.cypher + "--(:Group {name:'up'})--(a) RETURN a.name as name" ) ] # Emphasize the up regulated nodes for name in up_regulated: if name in name_to_node: # If the current graph have this gene viewColor[name_to_node[name]] = tlp.Color( 0, 204, 0, 255) # Set the node green viewSize.setNodeValue(name_to_node[name], tlp.Size( 10, 10, 10)) # Make it bigger # Get down regulated gene names described by the current method by a cypher query down_regulated = [ result["name"] for result in neo_graph.run( "MATCH " + method.cypher + "--(:Group {name:'down'})--(a) RETURN a.name as name" ) ] # Emphasize the up regulated nodes for name in down_regulated: if name in name_to_node: # If the current graph have this gene viewColor[name_to_node[name]] = tlp.Color( 204, 0, 0, 255) # Set the node red viewSize.setNodeValue(name_to_node[name], tlp.Size( 10, 10, 10)) # Make it bigger # Align the different sub graphs on a grid layout subgraph_grid(parallel_multi_graph, self.dataSet["# Columns"]) # Set a view of the parallel multi graph and get its parameters node_link_view = tlpgui.createNodeLinkDiagramView( parallel_multi_graph) rendering_parameters = node_link_view.getRenderingParameters() background = node_link_view.state() scene = background['scene'] rendering_parameters.setEdgeColorInterpolate( True) # Set edge color interpolating from the node ones rendering_parameters.setLabelsDensity( -100) # Don't show any label scene = scene.replace( "<background>(255,255,255,255)</background>", # Set the background to black "<background>(0,0,0,255)</background>") # Apply the changed parameters background['scene'] = scene node_link_view.setState(background) node_link_view.setRenderingParameters(rendering_parameters) # Finish the plugin execution root.destroy()
def main(graph): trainingSentences = graph.getStringVectorProperty("trainingSentences") response = graph.getStringProperty("response") quickResponses = graph.getStringVectorProperty("quickResponses") viewColor = graph.getColorProperty("viewColor") viewLabel = graph.getStringProperty("viewLabel") viewLabelColor = graph.getColorProperty("viewLabelColor") entryPoints = graph.getBooleanProperty("isEntryPoint") leaves = graph.getBooleanProperty("isLeaf") letters = "abcdefghijklmnopqrstuvxyz" intents = [] labels = [] # mark the entry points and leaves for n in graph.getNodes(): if not graph.getInNodes(n).hasNext(): viewColor[n] = tlp.Color.BabyBlue entryPoints[n] = True elif not graph.getOutNodes(n).hasNext(): viewColor[n] = tlp.Color.Green leaves[n] = True else: viewColor[n] = tlp.Color(255, 95, 95) entryPoints[n] = False leaves[n] = False # convert the graph to a list of intents for n in graph.getNodes(): if entryPoints[n]: continue counter = 0 inDegree = graph.indeg(n) for e in graph.getInEdges(n): label = graph.getName() + "_" + viewLabel[n] if label in labels: label += ("_" + letters[counter]) labels.append(label) inputContext = "" if entryPoints[graph.source(e)] else ( "context_" + graph.getName() + "_" + viewLabel[graph.source(e)]) outputContext = "" if leaves[n] else ("context_" + graph.getName() + "_" + viewLabel[n]) intent = { "label": label[:100] if len(label) >= 100 else label, "response": response[n], "training_sentences": trainingSentences[e], "quick_responses": quickResponses[n], "entry_point": entryPoints[graph.source(e)], "leaf": leaves[n], "output": outputContext, "input": inputContext } intents.append(intent) counter += 1 # convert and write the intents list to json format with open(graph.getName() + ".json", 'w') as outfile: json.dump(intents, outfile) # send the intents to the bot print("Sending intent to DialogFlow...") subprocess.run("node create_intents.js " + graph.getName() + ".json", shell=True) print("Done!")
def random_color(): r = random.randint(0, 255) g = random.randint(0, 255) b = random.randint(0, 255) a = random.randint(0, 255) return tlp.Color(r, g, b, a)
def main(graph): ancestry = graph['ancestry'] annotations_count = graph['annotations_count'] code_id = graph['code_id'] creator_id = graph['creator_id'] degree = graph['degree'] description = graph['description'] forum = graph['forum'] name_cs = graph['name_cs'] name_en = graph['name_en'] name_pl = graph['name_pl'] name_sr = graph['name_sr'] numComms = graph['numComms'] parent_code = graph['parent_code'] post_id = graph['post_id'] user_id = graph['user_id'] user_name = graph['user_name'] viewBorderColor = graph['viewBorderColor'] viewBorderWidth = graph['viewBorderWidth'] viewColor = graph['viewColor'] viewFont = graph['viewFont'] viewFontAwesomeIcon = graph['viewFontAwesomeIcon'] viewFontSize = graph['viewFontSize'] viewIcon = graph['viewIcon'] viewLabel = graph['viewLabel'] viewLabelBorderColor = graph['viewLabelBorderColor'] viewLabelBorderWidth = graph['viewLabelBorderWidth'] viewLabelColor = graph['viewLabelColor'] viewLabelPosition = graph['viewLabelPosition'] viewLayout = graph['viewLayout'] viewMetric = graph['viewMetric'] viewRotation = graph['viewRotation'] viewSelection = graph['viewSelection'] viewShape = graph['viewShape'] viewSize = graph['viewSize'] viewSrcAnchorShape = graph['viewSrcAnchorShape'] viewSrcAnchorSize = graph['viewSrcAnchorSize'] viewTexture = graph['viewTexture'] viewTgtAnchorShape = graph['viewTgtAnchorShape'] viewTgtAnchorSize = graph['viewTgtAnchorSize'] # initialize the colors blue = tlp.Color(102,204,255, 255) red = tlp.Color(204,51, 0, 255) green = tlp.Color(51,255,204, 255) orange = tlp.Color(255, 153, 0, 255) steel = tlp.Color(160,160,160, 255) ## steel I keep for nodes that participate in more than one conversation colors = [blue, red, green, orange, steel] # need to add more colors def color_edges(): ''' (None) => None colors the edges according to the value of the forum property ''' fora = {} # map from value of forum to color i = 0 for e in graph.getEdges(): if forum[e] not in fora: fora[forum[e]] = colors[i] i += 1 graph.setEdgePropertiesValues(e, {'viewColor': fora[forum[e]]}) print(fora) return None def color_nodes(): ''' (None) => None color nodes according to the colors of the incident edges. * if all edges are of the same color, the node imherits that color * if there are at least two edges of different colors, the node is colored in steel ''' for n in graph.getNodes(): incidentEdgeColors = [] for e in graph.getInOutEdges(n): if viewColor[e] not in incidentEdgeColors: incidentEdgeColors.append(viewColor[e]) if len(incidentEdgeColors) == 1: viewColor[n] = incidentEdgeColors[0] else: viewColor[n] = steel success = color_nodes()
def colorInteractions(self): self.colorInteractionsByStatus('gain', tlp.Color(0, 255, 0)) self.colorInteractionsByStatus('stable', tlp.Color(0, 0, 0, 80)) self.colorInteractionsByStatus('loss', tlp.Color(255, 0, 0))
def tlp_color_to_hex(color): if (color == list(tlp.Color(166, 206, 227))): return ("#a6cee3") if (color == list(tlp.Color(251, 154, 153))): return ("#fb9a99") if (color == list(tlp.Color(177, 89, 40))): return ("#b15928") if (color == list(tlp.Color(51, 160, 44))): return ("#33a02c") if (color == list(tlp.Color(202, 178, 214))): return ("#cab2d6") if (color == list(tlp.Color(253, 191, 111))): return ("#fdbf6f") if (color == list(tlp.Color(31, 120, 180))): return ("#1f78b4") if (color == list(tlp.Color(255, 127, 0))): return ("#ff7f00") if (color == list(tlp.Color(255, 255, 153))): return ("#ffff99") if (color == list(tlp.Color(227, 26, 28))): return ("#e31a1c") if (color == list(tlp.Color(178, 223, 138))): return ("#b2df8a") if (color == list(tlp.Color(106, 61, 154))): return ("#6a3d9a") return
def make_metanode(sg): ''' (str) => Tulip subgraph the argument is the name of a subgraph. Returns another subgraph, where the nodes in sg are replaced by a single metanode. Edges incident to the nodes in the metanode are rewired to the metanode itself, and the relevant properties recomputed. ''' # create the graph tree, do the renaming as needed gname = graph.getName() ssg = graph.getSubGraph(sg) ssgname = ssg.getName() og = graph.addCloneSubGraph(gname + '_unchanged', True) csg = graph.addCloneSubGraph(gname + '_mn_' + ssgname) # create the "metanode" and populate its properties mn = csg.createMetaNode(ssg) name_en[mn] = ssg.getName() anns = 0 # to populate later when I iterate through nodes in ssn steel = tlp.Color(160, 160, 160, 255) viewColor[mn] = steel # default color # immediately erase incident edges for e in csg.getInOutEdges(mn): csg.delEdge(e) edgebox = { } # a dict of lists of edges incident to the original nodes. The latter are used as keys. colors = [] for n in ssg.getNodes(): anns += annotations_count[n] if viewColor[n] not in colors: colors.append(viewColor[n]) for e in og.getInOutEdges(n): the_source = og.source(e) the_target = og.target(e) if the_source not in ssg: incident = the_source else: if the_target not in ssg: incident = the_target else: continue if incident not in edgebox: edgebox[incident] = [e] else: edgebox[incident].append(e) annotations_count[mn] = anns if len(colors) == 1: viewColor[mn] = colors[0] for key in edgebox: print(name_en[key]) print('Edges in the box: ' + str(len(edgebox))) for n in edgebox: newedge = csg.addEdge(n, mn) # each of these nodes induce an edge viewColor[newedge] = steel # default color co_occ = 0 # the three edge properties I want to populate num_con = 0 conn = [] colors = [] for e in edgebox[n]: co_occ += cooccurrences[e] num_con += num_connectors[e] conn += connectors[e] if viewColor[e] not in colors: colors.append(viewColor[e]) if len(colors) == 1: viewColor[newedge] = colors[0] cooccurrences[newedge] = co_occ num_connectors[newedge] = num_con connectors[newedge] = conn # count the metanode's edges as a check mn_edges = 0 for mne in csg.getInOutEdges(mn): mn_edges += 1 print('edges incident to the metanode: ' + str(mn_edges)) return csg
def main(graph): viewFontAwesomeIcon = graph.getStringProperty("viewFontAwesomeIcon") category_id = graph.getIntegerProperty("category_id") numComms = graph.getIntegerProperty("numComms") user_name = graph.getStringProperty("user_name") viewBorderColor = graph.getColorProperty("viewBorderColor") viewBorderWidth = graph.getDoubleProperty("viewBorderWidth") viewColor = graph.getColorProperty("viewColor") viewFont = graph.getStringProperty("viewFont") viewFontSize = graph.getIntegerProperty("viewFontSize") viewIcon = graph.getStringProperty("viewIcon") viewLabel = graph.getStringProperty("viewLabel") viewLabelBorderColor = graph.getColorProperty("viewLabelBorderColor") viewLabelBorderWidth = graph.getDoubleProperty("viewLabelBorderWidth") viewLabelColor = graph.getColorProperty("viewLabelColor") viewLabelPosition = graph.getIntegerProperty("viewLabelPosition") viewLayout = graph.getLayoutProperty("viewLayout") viewMetric = graph.getDoubleProperty("viewMetric") viewRotation = graph.getDoubleProperty("viewRotation") viewSelection = graph.getBooleanProperty("viewSelection") viewShape = graph.getIntegerProperty("viewShape") viewSize = graph.getSizeProperty("viewSize") viewSrcAnchorShape = graph.getIntegerProperty("viewSrcAnchorShape") viewSrcAnchorSize = graph.getSizeProperty("viewSrcAnchorSize") viewTexture = graph.getStringProperty("viewTexture") viewTgtAnchorShape = graph.getIntegerProperty("viewTgtAnchorShape") viewTgtAnchorSize = graph.getSizeProperty("viewTgtAnchorSize") wordCount = graph.getDoubleProperty("wordCount") allCats = graph.getSubGraph('all Cats Stacked') catGraphs = [] for g in graph.getSubGraphs(): if g != allCats: catGraphs.append(g) blue = tlp.Color(102,204,255, 255) red = tlp.Color(204,51, 0, 255) green = tlp.Color(51,255,204, 255) orange = tlp.Color(255, 153, 0, 255) steel = tlp.Color(160,160,160, 255) ## steel I keep for nodes that participate in more than one conversation colors = [blue, red, green, orange, steel] # need to add more colors for i in range(len(catGraphs)): for e in catGraphs[i].getEdges(): viewColor[e] = colors[i] for n in graph.getNodes(): viewColor[n] = steel # reset the color of nodes in case I have to run the script multiple times nodesFound = [] # accumulator for the nodes already processed for i in range(len(catGraphs)): counter = 0 for n in catGraphs[i].getSubGraph('stacked').getNodes(): if n not in nodesFound: viewColor[n] = colors[i] counter +=1 nodesFound.append(n) else: viewColor[n] = steel # now count nodes by color: for color in colors: counter = 0 for n in graph.getNodes(): if viewColor[n] == color: counter +=1 print (str(color) + ': ' + str(counter))