Exemple #1
0
def test_update_group(name):
    graphspace = GraphSpace('*****@*****.**', 'user1')
    group = graphspace.get_group(group_name=name)
    group.set_description('A sample group for testing purpose')
    group1 = graphspace.update_group(group)
    assert type(group1) is Group
    assert group1.get_description() == group.get_description()
def test_post_graph(name=None):
    graphspace = GraphSpace('*****@*****.**', 'user1')
    graphspace.set_api_host('localhost:8000')
    graph1 = GSGraph()
    if name is not None:
        graph1.set_name(name)
    graph1.add_node('a', popup='sample node popup text', label='A')
    graph1.add_node_style('a',
                          shape='ellipse',
                          color='red',
                          width=90,
                          height=90)
    graph1.add_node('b', popup='sample node popup text', label='B')
    graph1.add_node_style('b',
                          shape='ellipse',
                          color='blue',
                          width=40,
                          height=40)

    graph1.add_edge('a', 'b', directed=True, popup='sample edge popup')
    graph1.add_edge_style('a', 'b', directed=True, edge_style='dotted')
    graph1.set_data(data={'description': 'my sample graph'})
    graph1.set_tags(['sample'])
    response = graphspace.post_graph(graph1)
    assert 'name' in response and response['name'] == graph1.get_name()
Exemple #3
0
def test_post_graph_layout(graph_id):
    graphspace = GraphSpace('*****@*****.**', 'user1')
    graphspace.set_api_host('localhost:8000')
    response = graphspace.post_graph_layout(graph_id=graph_id,
                                            layout_name='test layout')
    assert response is not None and response['is_shared'] == 0
    return response
Exemple #4
0
def test_post_group(name):
    graphspace = GraphSpace('*****@*****.**', 'user1')
    group = GSGroup(name, 'Sample group')
    group1 = graphspace.post_group(group)
    assert type(group1) is Group
    assert group1.get_name() == group.get_name()
    return group1
Exemple #5
0
def test_post_graph(name=None):
    graphspace = GraphSpace('*****@*****.**', 'user1')
    graph1 = GSGraph()
    if name is not None:
        graph1.set_name(name)
    graph1.add_node('a', popup='sample node popup text', label='A')
    graph1.add_node_style('a',
                          shape='ellipse',
                          color='red',
                          width=90,
                          height=90)
    graph1.add_node('b', popup='sample node popup text', label='B')
    graph1.add_node_style('b',
                          shape='ellipse',
                          color='blue',
                          width=40,
                          height=40)

    graph1.add_edge('a', 'b', directed=True, popup='sample edge popup')
    graph1.add_edge_style('a', 'b', directed=True, edge_style='dotted')
    graph1.set_data(data={'description': 'my sample graph'})
    graph1.set_tags(['sample'])
    graph = graphspace.post_graph(graph1)
    assert type(graph) is Graph
    assert graph.get_name() == graph1.get_name()
    return graph
Exemple #6
0
def main(graph_file, username, password):

    # read file as networkx graph
    nxG = nx.read_edgelist(graph_file)

    # convert networkx graph to GraphSpace object
    G = GSGraph()
    G.set_name('Docker Example %.4f' % (time.time()))
    for n in nxG.nodes():
        G.add_node(n, label=n, popup='Node %s' % (n))
        G.add_node_style(n,
                         color='#ACCE9A',
                         shape='rectangle',
                         width=30,
                         height=30)
    for u, v in nxG.edges():
        G.add_edge(u, v, popup='Edge %s-%s' % (u, v))
        G.add_edge_style(u, v, width=2, color='#281D6A')

    # post with unique timestamp
    gs = GraphSpace(username, password)
    try:
        graph = gs.update_graph(G)
    except:
        graph = gs.post_graph(G)
    print('posted graph')
    return
Exemple #7
0
def test_update_graph(name):
    graphspace = GraphSpace('*****@*****.**', 'user1')

    graph1 = GSGraph()
    if name is not None:
        graph1.set_name(name)
    graph1.add_node('a', popup='sample node popup text', label='A updated')
    graph1.add_node_style('a',
                          shape='ellipse',
                          color='green',
                          width=90,
                          height=90)
    graph1.add_node('b', popup='sample node popup text', label='B updated')
    graph1.add_node_style('b',
                          shape='ellipse',
                          color='yellow',
                          width=40,
                          height=40)
    graph1.set_is_public()
    graph1.set_data(data={'description': 'my sample graph'})

    graph = graphspace.update_graph(graph1)
    assert type(graph) is Graph
    assert graph.get_name() == graph1.get_name() and graph.is_public == 1
    assert len(graph.graph_json['elements']['edges']) == 0
    assert len(graph.graph_json['elements']['nodes']) == 2
def test_update_graph(name):
    graphspace = GraphSpace('*****@*****.**', 'user1')
    graphspace.set_api_host('localhost:8000')

    graph1 = GSGraph()
    if name is not None:
        graph1.set_name(name)
    graph1.add_node('a', popup='sample node popup text', label='A updated')
    graph1.add_node_style('a',
                          shape='ellipse',
                          color='green',
                          width=90,
                          height=90)
    graph1.add_node('b', popup='sample node popup text', label='B updated')
    graph1.add_node_style('b',
                          shape='ellipse',
                          color='yellow',
                          width=40,
                          height=40)

    graph1.set_data(data={'description': 'my sample graph'})
    response = graphspace.update_graph(name, graph=graph1, is_public=1)
    assert 'name' in response and response['name'] == graph1.get_name()
    assert response['is_public'] == 1
    assert len(response['graph_json']['elements']['edges']) == 0
    assert len(response['graph_json']['elements']['nodes']) == 2
Exemple #9
0
def post_graph(edge_list, T):
    graphspace = GraphSpace("*****@*****.**",
                            "solTB")  #Starting GraphSpace session
    G = GSGraph()
    G.set_name('Sol_MST_EGFR_Graph')
    G.set_tags(['HW 4'])

    seennodes = set(
    )  #keeps track of nodes which have been added since nodes can only be added once
    for e in edge_list:
        nodeA = e[0]
        nodeB = e[1]
        if nodeA not in seennodes:
            G.add_node(nodeA, label=nodeA)  #adds first node
            seennodes.add(nodeA)
        if nodeB not in seennodes:
            G.add_node(nodeB, label=nodeB)  #adds second node
            seennodes.add(nodeB)

        G.add_edge(nodeA, nodeB)  #adds edge
        edge_tup = (nodeA, nodeB)
        if edge_tup in T:
            G.add_edge_style(nodeA, nodeB, color='blue')

    graphspace.post_graph(G)
    print("Graph Posted")
Exemple #10
0
def test_update_graph_layout(graph_id, layout_id):
    graphspace = GraphSpace('*****@*****.**', 'user1')
    graphspace.set_api_host('localhost:8000')
    response = graphspace.update_graph_layout(
        graph_id=graph_id,
        layout_id=layout_id,
        layout_name='updated test layout',
        is_shared=1)
    assert response is not None and response['is_shared'] == 1 and response[
        'name'] == 'updated test layout'
Exemple #11
0
def post_graph(G: GSGraph,
               username: str,
               password: str,
               directed=False) -> None:
    gs = GraphSpace(username, password)
    try:
        graph = gs.update_graph(G)
    except:
        graph = gs.post_graph(G)
    print('posted graph')
    return
Exemple #12
0
def test_update_graph_layout(graph_id, layout_id):
    graphspace = GraphSpace('*****@*****.**', 'user1')
    layout = graphspace.get_graph_layout(graph_id=graph_id,
                                         layout_id=layout_id)
    layout.set_node_position('z', 74, 37)
    layout.set_is_shared()
    layout1 = graphspace.update_graph_layout(layout)
    assert type(layout1) is Layout
    assert layout1.get_name() == layout.get_name()
    assert 'z' in layout1.positions_json
    assert layout1.is_shared == 1
Exemple #13
0
def test_update_graph_layout2(graph_id, name):
    graphspace = GraphSpace('*****@*****.**', 'user1')
    L = GSLayout()
    L.set_node_position('b', y=38.5, x=67.3)
    L.set_node_position('a', y=102, x=238.1)
    L.add_node_style('a', shape='octagon', color='green', width=60, height=60)
    L.add_edge_style('a', 'b', directed=True, edge_style='solid')
    L.set_name(name)
    L.set_is_shared()
    layout = graphspace.update_graph_layout(graph_id=graph_id, layout=L)
    assert type(layout) is Layout
    assert layout.get_name() == L.get_name()
    assert layout.is_shared == 1
Exemple #14
0
def post_graph(nodes, edges, nonterminal_ST_nodes, terminals, steiner_tree,
               BFS_rank, title):  ##Collaborative
    ## connect to GraphSpace
    USERNAME = '******'
    PASSWORD = '******'
    if USERNAME == 'FILL IN':
        sys.exit(
            'ERROR: add your username and password in the post_graph() function.  Exiting.'
        )
    graphspace = GraphSpace(USERNAME, PASSWORD)

    # create Graph instance, set title and tags.
    G = GSGraph()
    m = 2
    G.set_name(title)
    G.set_tags(['Hw5'])
    for n in nodes:
        if n in nonterminal_ST_nodes:
            color = rgb_to_hex(0, 1, 0)
        if n in BFS_rank:
            color = rgb_to_hex(1 * BFS_rank[n], 0, 0)
        if n in nonterminal_ST_nodes and n in BFS_rank:
            color = rgb_to_hex(1 * BFS_rank[n], 1, 0)

        popup = None
        if n in terminals:
            color = '#0C7999'
            popup = 'terminal node'
        G.add_node(n, label=n, popup=popup)
        G.add_node_style(n, color=color, shape='ellipse', height=30, width=30)
    for e in edges:
        G.add_edge(e[0], e[1])
        G.add_edge_style(e[0], e[1], edge_style='dotted', color='#B1B1B1')
    for e in steiner_tree:
        G.add_edge_style(e[0], e[1], color='#000000', width=2)
        G.add_edge_style(e[1], e[0], color='#000000', width=2)
    G.set_data(
        data={
            'Regulators': 'Blue',
            'top 100 Dijkstra Rank': 'Red',
            'nonterminal_ST_nodes+': 'green',
            'Spanning Tree Edge': 'Black',
            'ST Node and Dijkstra ranked': 'Yellow (R+G)'
        })
    try:
        graph = graphspace.update_graph(G)
        print('updated graph with title', title)
    except:
        graph = graphspace.post_graph(G)
    print('posted graph with title', title)
    return
Exemple #15
0
def GraphMaker(V, E, nk, ek):
    graphspace = GraphSpace("*****@*****.**",
                            "solTB")  #Starting GraphSpace session
    G = GSGraph()
    G.set_name('Sol_BA_Graph')
    G.set_tags(['Lab 3'])
    for node in V:
        nkval = nk[node]
        G.add_node(node, label=node, k=nkval)
    for edge in E:
        ekval = ek[edge]
        G.add_edge(edge[0], edge[1], k=ekval)
    graphspace.update_graph(G)
    print("Graph Posted")
Exemple #16
0
def test_update_graph2(name):
    graphspace = GraphSpace('*****@*****.**', 'user1')
    # Retrieving graph
    graph = graphspace.get_graph(graph_name=name)
    # Modifying the retrieved graph
    graph.set_name(name)
    graph.add_node('z', popup='sample node popup text', label='Z')
    graph.set_is_public()
    # Updating graph
    graph1 = graphspace.update_graph(graph)
    assert type(graph1) is Graph
    assert graph1.get_name() == graph.get_name()
    assert 'z' in graph1.node
    assert graph1.is_public == 1
Exemple #17
0
def main():

	# creates a discionary of FB identifiers and common names
	common_names_dict = read_common_names('inputs/nodes-flybase.txt')

	# reads in output files
	steiner_terminal_nodes,steiner_non_terminal_nodes = read_tree_nodes(TREE_NODE_FILE)
	
	shortest_paths,sp_dict = read_new_shortest_paths(SHORTEST_PATHS_FILE)
	
	dijkstra,dij_dict = read_dijkstra_rank(PATHS_RANK_FILE)

	# converts node sets for each single output into common names
	steiner_nt_common = FB_to_common(steiner_non_terminal_nodes,common_names_dict)
	new_shortest_common = FB_to_common(shortest_paths, common_names_dict)
	dijkstra_common = FB_to_common(dijkstra, common_names_dict)

	make_venn(steiner_nt_common,dijkstra_common,new_shortest_common,'Nodes in Steiner Tree\napproximation','Nodes on paths to\nmany positives','Nodes on paths from Sqh to positives','outputs/venn.png')

	## connect to GraphSpace
	graphspace = GraphSpace('*****@*****.**', 'platypus')
	post_graphspace_graphs(common_names_dict,sp_dict,dij_dict,graphspace)

	print_to_screen(steiner_nt_common,new_shortest_common,dijkstra_common)

	return
Exemple #18
0
def main():
	# connect to GraphSpace
	graphspace = GraphSpace('YOUR_EMAIL','YOUR_PASSWORD')
	nodes,edges,terminals,adj_list = lab_utils.get_graph()

    ## This line visualizes the graph, colors the terminals, and doesn't color any edges.
	lab_utils.viz_graph(graphspace,nodes,edges,terminals,[],'Original Graph')
Exemple #19
0
def main():

	## connect to GraphSpace
	graphspace = GraphSpace('*****@*****.**', 'platypus')

	post_test_graph(graphspace)
	post_dolphin_graph(graphspace)
Exemple #20
0
def main():
	# connect to GraphSpace
	graphspace = GraphSpace('YOUR_EMAIL','YOUR_PASSWORD')

    # uncomment when you need it
	#run_example(graphspace)
	#run_yellowstone(graphspace)
	#run_badgers(graphspace)

	return
Exemple #21
0
def test_post_graph_layout(graph_id, name=None):
    graphspace = GraphSpace('*****@*****.**', 'user1')
    layout1 = GSLayout()
    if name is not None:
        layout1.set_name(name)
    layout1.set_node_position('a', 45, 55)
    layout1.set_node_position('b', 36, 98)
    layout1.add_node_style('a',
                           shape='ellipse',
                           color='green',
                           width=90,
                           height=90)
    layout1.add_node_style('b',
                           shape='ellipse',
                           color='yellow',
                           width=40,
                           height=40)
    layout = graphspace.post_graph_layout(graph_id=graph_id, layout=layout1)
    assert type(layout) is Layout
    assert layout.get_name() == layout1.get_name()
    return layout
Exemple #22
0
def test_delete_graph_layout(graph_id, layout_id):
    graphspace = GraphSpace('*****@*****.**', 'user1')
    graphspace.set_api_host('localhost:8000')
    graphspace.delete_graph_layout(graph_id=graph_id, layout_id=layout_id)
    assert graphspace.get_graph_layout(graph_id=graph_id,
                                       layout_id=layout_id) is None


# test_get_graph_by_id()
# test_graphspace_python()
def Convert(opts):
    nodes = set()
    uni2name = FileToDictionary(opts.unitproID)
    DSnodes = ConvertToNodes(opts.downstream)
    USnodes = ConvertToNodes(opts.upstream)
    OtherPath = ConvertToNodes(opts.OtherPathway)
    with open(opts.FileInput) as t:
        g = [line.split('\t') for line in t.readlines().copy()]
        for x in g:
            for y in [0, 2]:  ##Only care about columns 1 and 3.
                x[y] = x[y].strip('\n')
                if x[y] not in nodes:
                    nodes.add(x[y])
                    G.add_node(x[y], label=uni2name.get(x[y], x[y]))
                    print('Current Node=', uni2name.get(x[y]))
                    NodeShape, NodeColor = get_node_style(
                        x[y], USnodes, DSnodes, OtherPath)
                    G.add_node_style(x[y],
                                     shape=NodeShape,
                                     color=NodeColor,
                                     width=90,
                                     height=90)

            G.add_edge(x[0], x[2], directed=True)
            G.add_edge_style(x[0], x[2], directed=True, edge_style='dotted')

        G.set_name(opts.GraphName)

        G.set_data(
            data={
                'Graph Key':
                'Yellow Triangle = Upstream Input; Yellow Ellipse = Downstream Input; Red Rectangle = TieDie Result Path'
            })

        G.set_data(data={'Description': opts.GraphDescription})

        G.set_tags(['No Tags'])
        graphspace = GraphSpace(opts.GraphspaceLogin, opts.GraphspacePassword)
        graphspace.post_graph(G)
Exemple #24
0
def test_update_graph2(name):
    graphspace = GraphSpace('*****@*****.**', 'user1')
    graphspace.set_api_host('localhost:8000')
    # Retrieving graph
    graph = graphspace.get_graph(name)
    # Creating updated graph object
    G = GSGraph()
    G.set_graph_json(graph.get('graph_json'))
    G.set_style_json(graph.get('style_json'))
    G.set_name(graph.get('name'))
    G.set_tags(graph.get('name'))
    # Updating graph
    response = graphspace.update_graph(name, graph=G, is_public=1)
    assert 'name' in response and response['name'] == G.get_name()
    assert response['is_public'] == 1
Exemple #25
0
def main():
    # connect to GraphSpace
    graphspace = GraphSpace('YOUR_EMAIL', 'YOUR_PASSWORD')
    nodes, edges, weights, costs, adj_list = lab_utils.get_graph(
        'example_edges.txt')
    #nodes,edges,weights,costs,adj_list = lab_utils.get_graph('mouse_visual_cortex_edges.txt')

    ## visualize the graph before community detection
    lab_utils.viz_graph(graphspace, nodes, edges, weights, 'Example Graph',
                        None)
    #lab_utils.viz_graph(graphspace,nodes,edges,weights,'Mouse Graph',None)

    ## copy the edges to pass to the community detection function
    copy_edges = [e for e in edges]

    ## get communities
    communities = get_communities(nodes, copy_edges, costs, adj_list)

    ## visualize the graph after community detection
    #lab_utils.viz_graph(graphspace,nodes,edges,weights,'Example Graph k=3',communities[2])
    #lab_utils.viz_graph(graphspace,nodes,edges,weights,'Mouse Graph k=2',communities[1])
    return
Exemple #26
0
def post(G, username, password, group=None):
    '''
  Post a graph to graphspace.  If this graph is new, share it with
  the group.
  Inputs: Graph (GSGraph Object)
  Outputs: the graph ID (int)
  '''
    print('Posting graph...')

    # connect to GraphSpace with the username and password.
    gs = GraphSpace(username, password)
    try:
        # try updating the graph. If the graph does not exist,
        # this will throw an error.
        graph = gs.update_graph(G)
    except:
        # catch the error and try posting a new graph.
        graph = gs.post_graph(G)
        if group:
            # share this graph with the group.
            gs.share_graph(graph_id=graph.id, group_name=group)
    return graph.id
Exemple #27
0
To start, go to the main() function at the bottom.
In the "read_fly_interactome" function, add filepaths/filenames for the .txt files with graph nodes/edges and node labels, respectively,
if different from those already entered (these may be found in the "inputs" Google Drive folder).
You may change the source/target nodes (s and t, respectively) if desired, but this script is meant to use sqh/fog as the source and target.
You may adjust K to be any number of paths you want to choose from at each iteration, but 5 is a good starting point.
Nothing else need be changed in order to run the program as you normally would.

OUTPUT: text file with list of candidates in order of rank
"""

from copy import deepcopy
from math import log
from graphspace_python.api.client import GraphSpace
from graphspace_python.graphs.classes.gsgraph import GSGraph

graphspace = GraphSpace('*****@*****.**','mygraphspacepw')

# From HW6, written by me, with modifications for this particular use case
# Returns a dictionary of dictionaries of nodes and their neighbors/edge weights
# Also returns a dictionary of labeled nodes
def read_fly_interactome(graph_file,label_file):
	G = {}	# G = {u:{v:w,v2:w2,...},...}
	L = {}	# L = {u:Positive,v:Negative,...}
	with open(graph_file, 'rt') as file:						# Get node/edge info for graph
		next(file)	# Skip header line
		for line in file:
			line_list = line.strip().split()
			node1 = line_list[0]
			node2 = line_list[1]
			weight = float(line_list[2])
			cost = -log(weight,10)
Exemple #28
0
import urllib
import json
from graphspace_python.graphs.classes.gsgraph import GSGraph
from graphspace_python.api.client import GraphSpace

# Initialize client with your username and password
graphspace = GraphSpace('*****@*****.**', 'user1')

# Fetch the graph data
data_url = 'https://cdn.rawgit.com/maxkfranz/934042c1ecc464a8de85/raw'
response = urllib.urlopen(data_url)
graph_data = json.loads(response.read())

# Load the style json file
with open('style.json') as style_json_file:
    style_json = json.load(style_json_file)

# Initialize graph
G = GSGraph()
# Set name, tags and visibility status
G.set_name('Tokyo Railways')
G.set_tags(['tokyo-railways', 'graphspace', 'demo'])
G.set_is_public()
# Define and set data
data = {
    'description':
    'Graphical representation of railway network of Tokyo.<br>View functional demo of this graph at:\
 <a href=\"http://js.cytoscape.org/demos/tokyo-railways/\">http://js.cytoscape.org/demos/tokyo-railways/</a>',
    'directed': False
}
G.set_data(data)
Exemple #29
0
'''
This program runs a random walk simulation on the subnetwork of candidates using either each node as a starting node
OR using known positives as starting nodes (potentially better ways to do this).
Author: Sol Taylor-Brill
Last Edit: 12/10/19
'''

import math
import random
from graphspace_python.api.client import GraphSpace
from graphspace_python.graphs.classes.gsgraph import GSGraph
graphspace = GraphSpace("*****@*****.**",
                        "solTB")  #Starting GraphSpace session


def main():
    ## READ INTERACTOME AND KNOWN POSITIVE FILES ##
    positive_f = 'labeled_nodes.txt'  #known-positives
    interactome_f = 'interactome-flybase-collapsed-weighted.txt'  #whole interactome

    Pos_Name_set = PositiveReader(positive_f)  #set of known positives
    nodeset, edgeset, simpedgeset = InteractomeReader(
        interactome_f)  #set of ALL nodes, ALL edges + weights, ALL edges

    ## CANDIDATE FILES ##
    Maddy_f = "Maddy_candidates_10.txt"  #unweighted, 10
    CN_f = "Common_Neighbor_Candidates.txt"  #weighted, 100
    WN_f = "Weighted_Neighbor_Candidates.txt"  #weighted, 100
    Co_F = "Clustering_Candidates.txt"  #weighted, 100

    All_Candidates_List = (Maddy_f, CN_f, WN_f, Co_F
Exemple #30
0
def test_delete_graph(name):
    graphspace = GraphSpace('*****@*****.**', 'user1')
    graphspace.delete_graph(graph_name=name)
    assert graphspace.get_graph(graph_name=name) is None