BIO331 Utils Documentation

graphspace_utils

This module contains functions to access, post, and delete graphs in GraphSpace. Users can also make graphs public and share them with groups.

graphspace_utils.deleteGraph(graphid, user, password)[source]

Removes a graph (denoted by graphid and user) from GraphSpace.

Parameters:
  • graphid – ID of GraphSpace graph
  • user – graph owner’s username
  • password – graph owner’s password
graphspace_utils.execute(cmd, logout=None)[source]

Executes the command, using subprocess.Popen. We need to capture the output, so we cannot simply us os.system().

Parameters:
  • cmd – string – command to execute
  • logout – File object – File of log output or None.
Return out:

string – output of command

graphspace_utils.makeGraphPrivate(graphid, user, password)[source]

Makes a graph privately viewable (makes it no longer public).

Parameters:
  • graphid – ID of GraphSpace graph
  • user – graph owner’s username
  • password – graph owner’s password
graphspace_utils.makeGraphPublic(graphid, user, password)[source]

Makes a graph publicly viewable.

Parameters:
  • graphid – ID of GraphSpace graph
  • user – graph owner’s username
  • password – graph owner’s password
graphspace_utils.makeGraphsWithTagPrivate(user, password, tag)[source]

Makes all graphs with a tag privately viewable (make them no longer public).

Parameters:
  • user – graph owner’s username
  • password – graph owner’s password
  • tag – graph tag.
graphspace_utils.makeGraphsWithTagPublic(user, password, tag)[source]

Makes all graphs with a tag publicly viewable.

Parameters:
  • user – graph owner’s username
  • password – graph owner’s password
  • tag – graph tag.
graphspace_utils.postGraph(graphid, jsonfile, user, password, logfile=None)[source]

Posts a graph in ‘jsonfile’ with id ‘graphid’ to the account of the user ‘user’ to GraphSpace.

Parameters:
  • graphid – string – ID of GraphSpace graph
  • jsonfile – string – JSON file to post.
  • user – string – graph owner’s username
  • password – string – graph owner’s password
  • logfile – filename for command outputs. Optional.
graphspace_utils.shareGraph(graphid, user, password, group, group_owner)[source]

Shares an existing graph with a group.

Parameters:
  • graphid – ID of GraphSpace graph
  • user – graph owner’s username
  • password – graph owner’s password
  • group – group to share graph with.
  • group_user – owner of group.
graphspace_utils.unShareGraph(graphid, user, password, group, group_owner)[source]

Un-Shares a graph with a group. Graph is not deleted, but others in the group may no longer view it.

Parameters:
  • graphid – ID of GraphSpace graph
  • user – graph owner’s username
  • password – graph owner’s password
  • group – group to share graph with.
  • group_user – owner of group.

json_utils

This module contains functions to create JSON data structures from node and edge information.

json_utils.make_json_data(nodes, edges, node_attributes=None, edge_attributes=None, title='', description='', tags=[], labels=True)[source]

Creates a dictionary that contains the following entries:

{
        "graph": {
                "nodes": [],
                "edges": []
        },
        "metadata": {
                "title": "",
                "description": "",
                "tags": []
        }
}

See http://ec2-52-41-252-78.us-west-2.compute.amazonaws.com/help/programmers for more information about the JSON structure.

Parameters:
  • nodes – list or set of nodes
  • edges – list or set of edges
  • node_attributes

    dictionary of node attributes. Optional. The key is a node name and the value is a dictionary of “attribute”/”value” pairs.Dictionary has the form:

    {"node_name" : {"attribute1":"val1","attribute2":"val2",...}}
    
  • edge_attributes

    dictionary of edge attributes. Optional. The key is the source node and the value is a dictionary where the key is the target node and the value is a dictionary of “attribute”/”value” pairs. Dictionary has the form:

    {"source" : {"target" : {"attribute1":"val1","attribute2":"val2",...}}}
    
  • title – string – title of graph. Optional.
  • description – string – description of graph. Optional.
  • tags – list – list of tag names. Optional.
  • labels – boolean – If True, write node IDs as the text on the node. Default is True. Set labels=False to not write the names on the nodes.
Returns:

dictionary formatted for JSON.

json_utils.test()[source]

Test function to make sure that the module is successfully imported.

json_utils.write_json(data, jsonfile)[source]

Writes the data object as a JSON file.

Parameters:
  • data – dictionary from make_json_data() function.
  • jsonfile – string – name of JSON file.