Пример #1
0
def postToGS(alignededges, overlaps, leftcoords, graphid):
    """Post graph to graphspace
    """

    import graphspace_interface as interface

    maxleftcoord = max([leftcoords[c] for c in leftcoords])
    minleftcoord = min([leftcoords[c] for c in leftcoords])
    for c in leftcoords:
        leftcoords[c] = int(float(leftcoords[c]-minleftcoord)\
                / float(maxleftcoord-minleftcoord)*255)
    user = '******'
    password = '******'
    group = 'SVLocalAssembly'
    outfile = graphid + '.json'

    #Graph 1 (tmp): read edges in from a file.
    #Take the first two columns of the file as the edges.

    #Make a directed graph NetworkX object.
    #A directed graph will work even if we
    #want to show an undirected graph, since
    #each edge has a "directed" attribute that
    #determines whether the edge is drawn with an
    #arrow or not.
    graph = nx.DiGraph(alignededges, directed=False)

    for n in graph.nodes():
        label = '%s' % (n)
        interface.add_node_label(graph, n, label)
        interface.add_node_wrap(graph, n, 'wrap')
        interface.add_node_color(
            graph, n, rgb_to_hex((0, leftcoords[n], 255 - leftcoords[n])))
        interface.add_node_shape(graph, n, 'ellipse')
        interface.add_node_height(graph, n, None, label)
        interface.add_node_width(graph, n, None, label)

    trueedges = [[u, v] for u, v, t in overlaps]
    for t, h in graph.edges():
        interface.add_edge_directionality(graph, t, h, False)
        if [t, h] in trueedges or [h, t] in trueedges:
            # true edges are blue
            #print 'Blue'
            interface.add_edge_color(graph, t, h, '#6666FF')
        else:
            # false edges are black
            interface.add_edge_color(graph, t, h, '#000000')
        interface.add_edge_width(graph, t, h, 2)

    metadata = {'description': 'example1', 'title': graphid, 'tags': []}
    print(graph, graphid, outfile, user, password, metadata)
    interface.postGraph(graph, graphid, outfile=outfile, user=user,\
            password=password, metadata=metadata)
    if group != None:
        interface.shareGraph(graphid,
                             user=user,
                             password=password,
                             group=group)
    return
Пример #2
0
def postToGS(alignededges, overlaps, leftcoords, graphid):
    """Post graph to graphspace
    """

    import graphspace_interface as interface

    maxleftcoord = max([leftcoords[c] for c in leftcoords])
    minleftcoord = min([leftcoords[c] for c in leftcoords])
    for c in leftcoords:
        leftcoords[c] = int(float(leftcoords[c]-minleftcoord)\
                / float(maxleftcoord-minleftcoord)*255)
    user = '******'
    password = '******'
    group = 'SVLocalAssembly'
    outfile = graphid+'.json'

    #Graph 1 (tmp): read edges in from a file.
    #Take the first two columns of the file as the edges.

    #Make a directed graph NetworkX object.
    #A directed graph will work even if we
    #want to show an undirected graph, since
    #each edge has a "directed" attribute that
    #determines whether the edge is drawn with an
    #arrow or not.
    graph = nx.DiGraph(alignededges, directed=False)

    for n in graph.nodes():
        label = '%s' % (n)
        interface.add_node_label(graph, n, label)
        interface.add_node_wrap(graph, n, 'wrap')
        interface.add_node_color(graph, n, rgb_to_hex((0, leftcoords[n], 255-leftcoords[n])))
        interface.add_node_shape(graph, n, 'ellipse')
        interface.add_node_height(graph, n, None, label)
        interface.add_node_width(graph, n, None, label)

    trueedges = [[u, v] for u, v, t in overlaps]
    for t, h in graph.edges():
        interface.add_edge_directionality(graph, t, h, False)
        if [t, h] in trueedges or [h, t] in trueedges:
            # true edges are blue
            #print 'Blue'
            interface.add_edge_color(graph, t, h, '#6666FF')
        else:
            # false edges are black
            interface.add_edge_color(graph, t, h, '#000000')
        interface.add_edge_width(graph, t, h, 2)

    metadata = {'description': 'example1', 'title': graphid, 'tags': []}
    print(graph, graphid, outfile, user, password, metadata)
    interface.postGraph(graph, graphid, outfile=outfile, user=user,\
            password=password, metadata=metadata)
    if group != None:
        interface.shareGraph(graphid, user=user, password=password, group=group)
    return
Пример #3
0
def main(argv):
    """
    Makes graphs with all possible attributes.
    Nodes are labeled by the test number.
    """

    if len(argv) != 3 and len(argv) != 4:
        print 'USAGE: interface_examples.py <USERNAME> <PASSWORD> <OPTIONAL-GROUPNAME>\n'
        sys.exit()

    user = argv[1]
    password = argv[2]

    if len(argv) == 3:
        group = None
    else:
        group = argv[3]
    print 'USER=%s' % (user)
    print 'PASSWORD=%s' % (password)
    print 'GROUP=%s' % (group)

    ## build list of NetworkX graphs.
    graphs = {}
    graphs['NodeShapes'] = testNodeShapes()
    graphs['LabelPlacement'] = testLabelPlacement()
    graphs['BorderStyles'] = testBorderStyles()
    graphs['EdgeStyles'] = testEdgeStyles()
    graphs['FilteringByK'] = testKFiltering()
    graphs['Popups'] = testPopups()

    edgefile = 'test.json'
    for graphid in graphs:
        G = graphs[graphid]

        #print G,graphid,outfile,user,password,metadata
        interface.postGraph(G,
                            graphid,
                            outfile=edgefile,
                            user=user,
                            password=password,
                            logfile='tmp.log',
                            metadata={'tags': ['AttributeGallery']})
        if group != None:
            interface.shareGraph(graphid,
                                 user=user,
                                 password=password,
                                 group=group)
    interface.makeGraphsWithTagPublic(user, password, 'AttributeGallery')

    ## delete edgefile.
    #os.system('rm -f %s' % (edgefile))

    print 'DONE. Check log file tmp.log for errors.\n'
    return
def runExample2(user,password,group,graphid,outfile):
    #############
    ## Graph 2 (tmp2): randomly generate nodes and edges.

    G = nx.DiGraph(directed=True)
    # add 10 nodes
    nodeids = ['node\n%d' % (i) for i in range(10)]
    for n in nodeids:
        interface.add_node(G,n,label=n,bubble='yellow',color='yellow')
    for i in range(20): # randomly add 20 edges
        interface.add_edge(G,random.choice(nodeids),random.choice(nodeids),width=random.choice([1,2,3,4,5]),directed=True)

    interface.validate_json(G)
    interface.postGraph(G,graphid,outfile=outfile,user=user,password=password,logfile='tmp.log')
    if group != None:
        interface.shareGraph(graphid,user=user,password=password,group=group)
    return
Пример #5
0
def main(argv):
    """
    Makes graphs with all possible attributes.
    Nodes are labeled by the test number.
    """

    if len(argv) != 3 and len(argv) != 4:
        print 'USAGE: interface_examples.py <USERNAME> <PASSWORD> <OPTIONAL-GROUPNAME>\n'
        sys.exit()

    user = argv[1]
    password = argv[2]

    if len(argv)==3:
        group = None
    else:   
        group=argv[3]
    print 'USER=%s' % (user)
    print 'PASSWORD=%s' % (password)
    print 'GROUP=%s' % (group)

    ## build list of NetworkX graphs.
    graphs = {}
    graphs['NodeShapes'] = testNodeShapes()
    graphs['LabelPlacement'] = testLabelPlacement()
    graphs['BorderStyles'] = testBorderStyles()
    graphs['EdgeStyles'] = testEdgeStyles()
    graphs['FilteringByK'] = testKFiltering()
    graphs['Popups'] = testPopups()

    edgefile = 'test.json'
    for graphid in graphs:
        G = graphs[graphid]

        #print G,graphid,outfile,user,password,metadata
        interface.postGraph(G,graphid,outfile=edgefile,user=user,password=password,logfile='tmp.log',metadata={'tags':['AttributeGallery']})
        if group != None:
            interface.shareGraph(graphid,user=user,password=password,group=group)
    interface.makeGraphsWithTagPublic(user,password,'AttributeGallery')

    ## delete edgefile.
    #os.system('rm -f %s' % (edgefile))

    print 'DONE. Check log file tmp.log for errors.\n'
    return
def runExample1(edgefile,user,password,group,graphid,outfile):
    #Graph 1 (tmp): read edges in from a file.
    #Take the first two columns of the file as the edges.
    edges = []
    with open(edgefile) as fin:
        for line in fin:
            if line[0] == '#': # skip comments
                continue
            row = line.strip().split()
            edges.append((row[0],row[1]))

    #Make a directed graph NetworkX object.
    #A directed graph will work even if we 
    #want to show an undirected graph, since
    #each edge has a "directed" attribute that
    #determines whether the edge is drawn with an
    #arrow or not.
    G = nx.DiGraph(edges,directed=True)

    for n in G.nodes():
        label= 'node\n%s' % (n)
        interface.add_node_label(G,n,label)
        interface.add_node_wrap(G,n,'wrap')
        interface.add_node_color(G,n,'#ACFA58')
        interface.add_node_shape(G,n,'rectangle')
        interface.add_node_height(G,n,None,label)
        interface.add_node_width(G,n,None,label)

    for t,h in G.edges():
        interface.add_edge_directionality(G,t,h,True)
        interface.add_edge_color(G,t,h,'#000000')
        interface.add_edge_width(G,t,h,2)

    metadata = {'description':'example1','title':'Example 1 Graph','tags':[]}
    print G,graphid,outfile,user,password,metadata
    interface.postGraph(G,graphid,outfile=outfile,user=user,password=password,metadata=metadata)
    if group != None:
        interface.shareGraph(graphid,user=user,password=password,group=group)
    return
Пример #7
0
    interface.add_node_color(G,n,'#ACFA58')
    interface.add_node_shape(G,n,'rectangle')
    interface.add_node_height(G,n,None,label)
    interface.add_node_width(G,n,None,label)

for t,h in G.edges():
    interface.add_edge_directionality(G,t,h,True)
    interface.add_edge_color(G,t,h,'#000000')
    interface.add_edge_width(G,t,h,2)

#Divit's Note: We should have a JSON validator at this step
#Divit: We should.  I want to talk to Murali about possibly enhancing the validator.

interface.postGraph(G,graphid,outfile=outfile,user=user,password=password)
if group != None:
    interface.shareGraph(graphid,user=user,password=password,group=group)

#############
## Graph 2 (tmp2): randomly generate nodes and edges.
graphid = 'gs-interface-example2'
outfile = 'gs-interface-example2.json'

G = nx.DiGraph(directed=True)
# add 10 nodes
nodeids = ['node\n%d' % (i) for i in range(10)]
for n in nodeids:
    interface.add_node(G,n,label=n,bubble="#880",color='yellow')
for i in range(20): # randomly add 20 edges
    interface.add_edge(G,random.choice(nodeids),random.choice(nodeids),width=random.choice([1,2,3,4,5]),directed=True)

interface.validate_json(G)
Пример #8
0
    interface.add_node_color(G, n, '#ACFA58')
    interface.add_node_shape(G, n, 'rectangle')
    interface.add_node_height(G, n, None, label)
    interface.add_node_width(G, n, None, label)

for t, h in G.edges():
    interface.add_edge_directionality(G, t, h, True)
    interface.add_edge_color(G, t, h, '#000000')
    interface.add_edge_width(G, t, h, 2)

#Divit's Note: We should have a JSON validator at this step
#Divit: We should.  I want to talk to Murali about possibly enhancing the validator.

interface.postGraph(G, graphid, outfile=outfile, user=user, password=password)
if group != None:
    interface.shareGraph(graphid, user=user, password=password, group=group)

#############
## Graph 2 (tmp2): randomly generate nodes and edges.
graphid = 'gs-interface-example2'
outfile = 'gs-interface-example2.json'

G = nx.DiGraph(directed=True)
# add 10 nodes
nodeids = ['node\n%d' % (i) for i in range(10)]
for n in nodeids:
    interface.add_node(G, n, label=n, bubble="#880", color='yellow')
for i in range(20):  # randomly add 20 edges
    interface.add_edge(G,
                       random.choice(nodeids),
                       random.choice(nodeids),