Biorithm  1.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions
MyGraph Class Reference

A class that stores an undirected graph. More...

#include <graph.h>

Inheritance diagram for MyGraph:
ActiveNetwork MyGainGraph NetworkLego

List of all members.

Classes

class  EdgeObjectIterator
class  MyNodeIterator
class  NodeObjectIterator

Public Types

typedef map< MyNodeId, MyNodeMyNodeList
typedef MyNodeList::const_iterator MyConstNodePtr
typedef MyNodeList::iterator MyNodePtr
typedef list< MyEdgeMyEdgeList
typedef MyEdgeList::iterator MyEdgePtr
typedef MyEdgeList::const_iterator MyConstEdgePtr
typedef
MyGraph::NodeObjectIterator
< const MyNode, MyConstNodePtr > 
MyConstNodeIterator
typedef
MyGraph::EdgeObjectIterator
< MyEdge, MyEdgePtr > 
MyEdgeIterator
typedef
MyGraph::EdgeObjectIterator
< const MyEdge, MyConstEdgePtr > 
MyConstEdgeIterator
typedef MyNode Node
typedef MyEdge Edge
typedef MyNodeIterator NodeIterator
typedef MyEdgeIterator EdgeIterator
typedef Node::EdgeIterator IncidentEdgeIterator
typedef Node::ConstEdgeIterator ConstIncidentEdgeIterator

Public Member Functions

 MyGraph (string infile, string type, MyNT minEdgeWeight=0)
 MyGraph (const MyGraph &copy)
void setName (string name)
string getName () const
virtual MyGraph::MyNodeIterator nodes ()
 Return an iterator over the nodes in the graph.
virtual
MyGraph::MyConstNodeIterator 
nodes () const
 Return a const iterator over the nodes in the graph.
virtual MyGraph::MyEdgeIterator edges ()
 Return an iterator over the edges in the graph.
virtual
MyGraph::MyConstEdgeIterator 
edges () const
 Return a const iterator over the edges in the graph.
virtual MyNode::MyEdgeIterator incidentEdges (MyNodeId nodeId)
virtual MyNode::MyEdgeIterator incidentEdges (MyNode &node)
void computeBinaryVector (const map< string, unsigned int > &edgeToColumn, vector< unsigned int > &binaryVector) const
void computeEdgeTypeCounts (map< string, unsigned int > &counts) const
unsigned int computeCommonNeighbours (MyNode &node1, MyNode &node2, set< MyNodeId > &common)
MyNT computeSegregation (MyNodeIdList &nodes)
 From Arjun Krishnan's paper gene-function prediction in Arabidopsis. Given a set of nodes, compute the fraction of edges between those nodes out of all edges incident on the nodes.
void printEdgeTypeCounts (ostream &ostr) const
virtual void construct (const map< string, map< string, MyNT > > &allEdgeWeights)
virtual void read (string fileName, string type="", MyNT minEdgeWeight=0, ostream &logStream=cout)
 Read a graph from a tab-delimited file.
virtual void read2 (string fileName, string type="", MyNT minEdgeWeight=0, ostream &logstream=cout)
 Read a graph from a tab-delimited file.
virtual void readNodeTypes (string file)
 Read the type of each node from a file.
virtual void print (ostream &fstr=cout, string name="")
 Print the details of the graph to fstr.
virtual void printNodes (ostream &fstr=cout, string name="")
 Print information about the graph's nodes to fstr.
virtual void printEdges (ostream &fstr=cout, string name="") const
 Print information about the graph's edges to fstr.
virtual void printEdgesItemset (ostream &fstr, vector< string > types)
virtual void readEdgeWeights (string weightsFile)
virtual void transformEdgeWeightsString (string transform)
 Transforms edge weights using various methods.
template<typename _Transform >
void transformEdgeWeights (_Transform function)
virtual void clear ()
virtual void add (MyGraph &other)
virtual void addInduced (MyGraph &other)
void copyEdgeWeights (MyGraph &other)
virtual void subtract (MyGraph &other)
int getId () const
MyGraphoperator= (const MyGraph &rhs)
bool operator< (const MyGraph &rhs) const
 a comparator that can be used by the STL set constructor/insert functions to make sure that two different MyGraph objects go in the same container.
void getEdgeSet (set< string > &edgeSet) const
void getNodeSet (set< MyNodeId > &nodeSet) const
void getNodeVec (vector< MyNodeId > &nodeVec) const
 Return the identifiers of the nodes in the graph as a vector of MyNodeId.
unsigned int numNodes () const
 Return the number of nodes in the graph.
unsigned int numHiddenNodes () const
 Return the number of hidden nodes in the graph.
unsigned int numEdges () const
 Return the number of edges in the graph.
unsigned int numHiddenEdges () const
 Return the number of hidden edges in the graph.
bool isConnected ()
 Return true if and only if the graph is connected.
MyNT computeDensity () const
 Return the density of a graph, defined as half its average degree, i.e., the number of edges divided by the number of nodes.
MyNT computeWeightedDensity ()
 Return the weighted density of a graph.
MyNT computeStouffersZScore () const
 Return the zscore of the graph.
MyNT computeStouffersZScoreSlowly () const
 The method computes the Stouffer's z-score of the graph but by explicitly looping over all the nodes and edges of the graph.
MyNT getAverageNodeWeight ()
 Return the average weight of a node in the graph.
MyNT getTotalNodeWeight () const
 Return the sum of the weights of the nodes in the graph.
MyNT getTotalSquaredNodeDegrees () const
 Return the sum of the degrees of the nodes in the graph.
MyNT getTotalAbsoluteNodeWeight () const
 Return the sum of the absolute values of the weights of the nodes in the graph.
MyNT getTotalEdgeWeight () const
 Return the sum of the weights of the edges in the graph.
MyNT getTotalAbsoluteEdgeWeight () const
 Return the sum of the absolute values of weights of the edges in the graph.
MyNT computeCompleteness () const
 Compute the "completeness" of a graph.
MyNT computeExpansionNodeBased (MyGraph &superGraph)
int degree (MyNodeId nid) const
 Return the degree of the node whose id is nid.
MyNT weightedDegree (MyNodeId nid) const
 Return the weighted degree of the node whose id is nid.
void degrees (map< unsigned int, unsigned int > &distribution) const
void power (unsigned int distance)
bool isNode (const MyNode &node) const
 Return true if node is a node in the invocant graph, false otherwise.
bool isNode (MyNodeId id) const
bool isVisibleNode (MyNodeId id) const
bool isHiddenNode (MyNodeId id) const
void addNodes (set< MyNodeId > ids)
 Add all the nodeIds in ids to the invocant graph.
MyNodeaddNode (MyNodeId id)
MyNodeaddNode (const MyNode &node)
void nodeFunctions (MyNodeId id, vector< string > &fns) const
bool addNodeFunction (MyNodeId id, string function)
bool deleteNode (MyNodeId id, set< MyNodeId > *neighbours=NULL)
void deleteNodeSet (const set< MyNodeId > ids)
MyEdgegetEdge (MyNodeId node1, MyNodeId node2) const
bool getEdge (MyNodeId node1, MyNodeId node2, MyEdgePtr &ptr)
bool isValidEdge (const MyEdgePtr &eptr) const
bool isEdge (MyNodeId node1, MyNodeId node2) const
bool isEdge (const MyNode &node1, const MyNode &node2) const
 Check if an edge connecting node1 and node2 is in the invocant.
MyEdgePtr addEdge (const MyEdge &edge)
MyEdgePtr addEdge (MyNodeId nodeId1, MyNodeId nodeId2, MyNT weight=1, set< string > *types=NULL, bool keepGraphSimple=true)
bool deleteEdge (MyNodeId node1, MyNodeId node2)
 Delete the edge between node1 and node2 in the graph.
bool isEdgeValid (MyEdgePtr eptr)
 Return true if eptr is a valid iterator.
void setEdgeWeight (MyNodeId node1, MyNodeId node2, MyNT weight)
void setEdgeWeight (MyEdge *edge, MyNT weight)
bool _checkNodeTotalEdgeWeight ()
void computeEdgeTypeOverlaps () const
 Edges in a graph have different types. For each pair of types, compute and print how many edges they have in common.
void computeEdgeTypeSubgraphs (ostream &logStream, map< string, MyGraph > &edgeTypeSubgraphs, bool useShared=1)
 For each edge type, compute subgraphs of the invocant induced by edges with that type.
void components (vector< MyGraph > *comps=NULL)
 Compute the connected components and return them in order.
MyNT computeClosestNode (const MyNode &rootNode, MyNodeIdSet &nodeSet, MyNodeId &closest)
 Find the nodes in nodeSet that is closest to rootNode.
void computeHistogramNodeWeights (MyHistogram &hist, bool cumulative=false, bool reverse=false)
void computeHistogramEdgeWeights (MyHistogram &hist, bool cumulative=false, bool reverse=false)
void computeMinimumSpanningTreePrim (MyGraph &mst)
void computeMaximumSpanningTreePrim (MyGraph &mst)
template<typename Compare >
void computeMSTPrim (MyGraph &mst)
unsigned int computeNumCommonEdges (const MyGraph &other) const
 Compute the number of common edges between the invocant and other.
MyNT computeNumCommonEdgesWeighted (const MyGraph &other) const
 Compute the number of common nodes between the invocant and other, taking the weighted degrees of the nodes into account.
unsigned int computeNumCommonNodes (const MyGraph &other) const
 Compute the number of common nodes between the invocant and other.
MyNT computeNumCommonNodesWeighted (const MyGraph &other) const
 Compute the number of common nodes between the invocant and other, taking the weighted degrees of the nodes into account.
void computeShortestPathDAG (const MyNode &node, map< MyNodeId, MyNT > &distance, map< MyNodeId, unsigned int > &count)
 Compute the shortest path DAG rooted at node.
void computeShortestPathDAG (const MyNodeId nodeid, map< MyNodeId, MyNT > &distance, map< MyNodeId, unsigned int > &count)
 Compute the shortest path DAG rooted at the node with ID nodeid.
void computeShortestPathDAG (const MyNode &node, map< MyNodeId, MyNT > &distance, map< MyNodeId, unsigned int > &count, stack< MyNodeId > &descendents, map< MyNodeId, vector< MyNodeId > > &predecessors)
void computeShortestPathDAG (const MyNode &node, map< MyNodeId, MyNT > &distance, map< MyNodeId, unsigned int > &count, stack< MyNodeId > &descendents, map< MyNodeId, vector< MyNodeId > > &predecessors, map< MyNodeId, vector< MyNodeId > > &successors)
void printAllPairsShortestPathDistances (ostream &ostr)
 Print the shortest paths and the number of such paths between all pairs of nodes to an output file.
void printAllPairsShortestPathDistances (string outfile)
 Print the shortest paths and the number of such paths between all pairs of nodes to an output file.
MyNT computeSimilarityEdges (const MyGraph &other, bool jacquard=true, bool asymmetric=false) const
MyNT computeSimilarityEdgesWeighted (const MyGraph &other, bool jacquard=true, bool asymmetric=false) const
 This method is similar to MyGraph::computeSimilarityEdges(), except that it used the weighted version of edge similarity between two graphs (see MyGraph::computeNumCommonEdgesWeighted()).
MyNT computeMostSimilarGraphEdges (const vector< MyGraph > &others, unsigned int &bestIndex) const
MyNT computeSimilarityNodes (const MyGraph &other, bool jacquard=true, bool asymmetric=false) const
MyNT computeSimilarityNodesWeighted (const MyGraph &other, bool jacquard=true, bool asymmetric=false) const
 This method is similar to MyGraph::computeSimilarityNodes(), except that it used the weighted version of node similarity between two graphs (see MyGraph::computeNumCommonNodesWeighted()).
MyNT computeMostSimilarGraphNodes (const vector< MyGraph > &others, unsigned int &bestIndex) const
void computeNodeBetweenessCentrality (ostream *fstr, map< MyNodeId, MyNT > *bets)
void computeEdgeBetweenessCentrality (ostream *fstr, map< MyEdge, MyNT > *bets)
void computeEdgeFSWeights ()
void computeEdgeCDWeights ()
void randomise (MyGraph &random, map< MyNodeId, bool > *vertexcover=NULL)
void randomiseVectorOfEdges (MyGraph &random, unsigned int numIterations)
void randomiseErdosRenyiSubgraph (MyGraph &random, const vector< MyNodeId > &subgraphNodes, MyNT prob=0.5)
 randomise a subgraph of a given graph to create a new graph using Erdos-Renyi (ER) model from a subset of the original graph's nodes (to randomize) and a probability (p)
void randomiseErdosRenyiSubgraph (MyGraph &random, const set< MyNodeId > &subgraphNodes, MyNT prob=0.5)
 randomise a subgraph of a given graph to create a new graph using Erdos-Renyi (ER) model from a subset of the original graph's nodes (to randomize) and a probability (p). It's same as the previous one except it accepts set of MyNodeIds instead of vectors
void randomiseErdosRenyiSubgraph (const set< MyNodeId > &subgraphNodes, MyNT prob)
 this version is to be used when we want to randomize a portion of *this graph instance
unsigned int deleteDisconnectedNodes ()
void createSubgraph (const vector< MyNodeId > &deletedNodes, MyGraph &subgraph) const
 Create a subgraph by deleting the nodes in deletedNodes.
void deleteSubgraphNodes (MyGraph &subgraph)
 Deleting the nodes in the given subgraph.
void deleteSubgraphEdges (MyGraph &subgraph)
 Deleting the edges induced by the nodes in the given subgraph.
void computeInducedSubgraph (const set< MyNodeId > &subgraphNodes, MyGraph &subgraph) const
 Compute the subgraph of the invocant induced by the nodes in subgraphNodes.
bool isInduced (const MyGraph &subgraph)
void core (unsigned int k, MyGraph &subgraph, bool hide, ostream *fstr=NULL) const
void find_cores (vector< MyGraph > &cores) const
void computeDensestSubgraphApprox (MyGraph &subgraph, bool optimiseStouffersZscore=false, ostream *fstr=NULL) const
void computeDenseSubgraphs (ostream &logStream, vector< MyGraph > &denseSubgraphs, bool computeDenseSubgraphsTillTheBitterEnd=false, bool splitDenseSubgraphsIntoComponents=false, bool suppressDetails=false)
void computeMostPerturbedSubgraph (MyGraph &subgraph, unsigned int numIterationsFactor, ostream &logStream, bool runOnCopy=true)
void findCliques (vector< MyGraph > &cliques, ostream &ostr) const
virtual void sparsify (string method)
 Modify edge weights in the molecular interaction network so that it has no dense components.
const MyNode_getNode (MyNodeId id) const
MyNode_getNode (MyNodeId id)
void assignEdgeWeightsFromEdgeTypeWeights (const map< string, MyNT > &edgeTypeWeights)
MyGraph computeIntersection (const vector< MyGraph > &others)
 Compute the intersection of the invocant with all the graphs in others.
void readEdgeTypeGroups (string fileName)
void translateTypes (const set< string > &types, set< string > &workingTypes, bool useShared=1)
void computeSeparator (const set< MyNodeId > &nodes, set< MyNodeId > &separator)
MyNT computeSeparatorRatio (MyGraph subgraph)
void _createDegreeLists (unsigned int &minDegree, vector< list< MyNodeId > > &degreeLists, map< MyNodeId, list< MyNodeId >::iterator > &nodePositions) const
void _decrementDegrees (vector< list< MyNodeId > > &degreeLists, map< MyNodeId, list< MyNodeId >::iterator > &nodePositions, const set< MyNodeId > &neighbours) const

Static Public Member Functions

static void createErdosRenyiNPGraph (MyGraph &graph, unsigned long numNodes, MyNT prob=0.5)
 , factory method to create an ER graph G(n,p) it creates an Erdos-Renyi (ER) Graph from a given number of nodes (n) and a given probability (p)

Protected Member Functions

void _copyNodes (const MyGraph &copy)
void _copyEdges (const MyGraph &copy)
bool _check () const
bool _checkDegree () const
MyNodeId _getNodeId (MyNodePtr &nptr)
MyNodeId _getNodeId (MyConstNodePtr &nptr) const
MyNode_getNode (MyNodePtr &nptr)
const MyNode_getNode (MyConstNodePtr &nptr) const
void _core (unsigned int k, bool hide, ostream *fstr)
void _find_cores (vector< MyGraph > &cores)
bool _tryAddingNode (MyNodeId nid, const set< MyNodeId > &currentClique)
void _findCliques (vector< MyGraph > &cliques, ostream &ostr)
void _computeDensestSubgraphApprox (MyGraph &subgraph, bool hide=false, ostream *fstr=NULL)
void _computeDensestWeightedSubgraphApprox (MyGraph &subgraph, bool optimiseStouffersZscore=false, bool hide=false, ostream *fstr=NULL)

Detailed Description

A class that stores an undirected graph.


Member Function Documentation

void MyGraph::add ( MyGraph other) [virtual]

Add the nodes and edges of other to the invocant.

Parameters:
othera constant reference to MyGraph, the graph to be added.
MyGraph::MyEdgePtr MyGraph::addEdge ( MyNodeId  nodeId1,
MyNodeId  nodeId2,
MyNT  weight = 1,
set< string > *  types = NULL,
bool  keepGraphSimple = true 
)
Note:
If edge already exists, returns iterator to that edge.
If the edge is a self-loop, return _edgeList.end().
void MyGraph::addInduced ( MyGraph other) [virtual]

The method computes the subgraph of other induced by the nodes of the invocant. Then the method adds this subgraph to the invocant.

Parameters:
othera constant reference to MyGraph, the graph to be added.
Note:
This method is different from MyGraph::add(), which simply adds all nodes and edges of other to the invocant.
void MyGraph::computeBinaryVector ( const map< string, unsigned int > &  edgeToColumn,
vector< unsigned int > &  binaryVector 
) const

Given a univeral set of edges, compute a binary vector representing the edges in the invocant.

Parameters:
[in]edgeToColumna map from strings representing edges to indices into the other argument. The keys of this map represent a universal set of edges.
[out]binaryVectora vector in which indices that have the value 1 will correspond precisely to edges that are in the invocant.
Warning:
The calling function must ensure that the sizes of binaryVector and edgeToColumn to are equal and that all indices in binaryVector are initialised to 0.
MyNT MyGraph::computeClosestNode ( const MyNode rootNode,
MyNodeIdSet &  nodeSet,
MyNodeId &  closest 
)

Find the nodes in nodeSet that is closest to rootNode.

Parameters:
[in]rootNodea const reference to an instance of MyNode.
[in]nodeSeta reference to an instance of MyNodeIdSet that contains the set of target nodes.
[out]closestthe id of any node in nodeSet that is closest to rootNode.
Returns:
the distance between rootNode and the closest nodes in nodeSet.

The method computes the shortest path DAG rooted at rootNode. It uses the distance in the shortest path DAG to find the nodes in nodeSet closest to rootNode.

unsigned int MyGraph::computeCommonNeighbours ( MyNode node1,
MyNode node2,
set< MyNodeId > &  common 
)

Compute the set of nodes adjacent to both node1 and node2.

Parameters:
[in]node1an instance of MyNode.
[in]node2an instance of MyNode.
[out]commona set that will contain the common neighbours.
Returns:
The number of common neighbours.
MyNT MyGraph::computeCompleteness ( ) const [inline]

Compute the "completeness" of a graph.

This method measures how close to a clique the graph is, the ratio of the number of edges in the graph and the maximum possible edges in it.

Note:
the pro of this method is it always returns a number between 0 and 1 the con is - it doesn't consider the size of the graph, so a triangle and a line both will get the same value: 1
void MyGraph::computeDenseSubgraphs ( ostream &  logStream,
vector< MyGraph > &  denseSubgraphs,
bool  computeDenseSubgraphsTillTheBitterEnd = false,
bool  splitDenseSubgraphsIntoComponents = false,
bool  suppressDetails = false 
)

Decompose the graph into dense subgraphs.

The method defines the density of a graph to be the total edge weight divided by the number of nodes. It computes a 2-approximation to the most dense subgraph by using the greedy algorithm described by Charikar. The method iteratively deletes edges in the computed dense subgraph until the remaining graph has density less than the invocant.

Parameters:
[out]logStreaman output stream to print information to.
[out]denseSubgraphsa vector that will contain the computed dense subgraphs.
[in]computeDensestSubgraphApproxif true, decompose the entire graph into dense subgraphs, i.e., do not stop when the remaining graph has density less than the invocant.
[in]splitDenseSubgraphsIntoComponents.If true, split each dense subgraph found into connected components.
Note:
The method operates on a copy of the invocant, so as not to destroy the invocant.
void MyGraph::computeEdgeBetweenessCentrality ( ostream *  fstr,
map< MyEdge, MyNT > *  bets 
)

For each edge in the network, compute the Czekanowski-Dice distance between the neighborhoods of the nodes on that edge and set this value to be the edge weight.

For each edge in the network, compute the functional similarity weight (FS-Weight) as described in Chua et al. and update the edge's weight to that value: http://bioinformatics.oxfordjournals.org/content/22/13/1623.abstract

void MyGraph::computeEdgeTypeCounts ( map< string, unsigned int > &  counts) const

Count over all the edges, the number of times each edge type appears.

Parameters:
[out]countsa map keyed by the edge type. The value is the number of edges with that type in the graph.
Note:
The running time of this method is O(n + m).

Compute the node-based expansion of the graph.

Parameters:
[in]superGraphthe graph that the invocant is a subgraph of.

The method computes the total weight of the edges connecting the nodes in the invocant to nodes in superGraph but not in the invocant divided by the number of nodes in the invocant.

The running time of the method is proportional to the total degree in superGraph of the nodes in the invocant.

void MyGraph::computeHistogramEdgeWeights ( MyHistogram hist,
bool  cumulative = false,
bool  reverse = false 
)

Compute a histogram of edge weights.

Parameters:
[out]histogram,:instance of MyHistogram to store the histogram in.
[in]cumulative,:a Boolean variable; if true, return a cumulative histogram.
[in]reverse,:a Boolean variable; if true and if cumulative is true, accumulate the histogram in reverse. If only reverse is true, the parameter has no effect.
void MyGraph::computeHistogramNodeWeights ( MyHistogram hist,
bool  cumulative = false,
bool  reverse = false 
)

Compute a histogram of node weights.

The method uses MyGraph::getWeightedDegree() to compute the weight of a node.

Parameters:
[out]histogram,:instance of MyHistogram to store the histogram in.
[in]cumulative,:a Boolean variable; if true, return a cumulative histogram.
[in]reverse,:a Boolean variable; if true and if cumulative is true, accumulate the histogram in reverse. If only reverse is true, the parameter has no effect.
void MyGraph::computeInducedSubgraph ( const set< MyNodeId > &  subgraphNodes,
MyGraph subgraph 
) const

Compute the subgraph of the invocant induced by the nodes in subgraphNodes.

Parameters:
[in]subgraphNodesa set of node identifiers that induce the desired subgraph.
[out]subgraphthe induced subgraph.
Note:
If subgraphNodes contains nodes not in the invocant, the induced subgraph will not contain these nodes.
MyGraph MyGraph::computeIntersection ( const vector< MyGraph > &  others)

Compute the intersection of the invocant with all the graphs in others.

Parameters:
[in]othersa vector of instances of MyGraph
Returns:
A graph in which each edge is present in the invocant and every graph in others.

Run Prim's algorithm for computing the maximum spanning tree.

Parameters:
[out]mstan instance of MyGraph that will contain the maximum spanning tree.

Run Prim's algorithm for computing the minimum spanning tree.

Parameters:
[out]mstan instance of MyGraph that will contain the minimum spanning tree.
void MyGraph::computeMostPerturbedSubgraph ( MyGraph subgraph,
unsigned int  numIterationsFactor,
ostream &  logStream,
bool  runOnCopy = true 
)

Compute the most perturbed subgraph of the invocant, based on the Liptak-Stouffer score.

Parameters:
[out]subgraphthe MyGraph instance in which to store the result.
[in]numIterationsFactora multiplicative factor controlling the number of iterations. The number of interations of simulated annealing invoked by this method is this argument times the number of edges in *this.
[out]logStreaman output stream to print information to.
[in]dontCopyif this Boolean is false, run the method on a copy of the invocant, else on the invocant itself. This parameter is not meant for use by an external caller, since its main use is the default value of true: the method makes a copy of the invocant, and invokes the method on the copy with runOnCopy set to false.
MyNT MyGraph::computeMostSimilarGraphEdges ( const vector< MyGraph > &  others,
unsigned int &  bestIndex 
) const

Compute the graph in other most similar to the invocant based on common edges.

Parameters:
[in]othersa vector of MyGraphs.
[out]bestIndexthe index of the most similar graph.
Returns:
the value of the similarity.
MyNT MyGraph::computeMostSimilarGraphNodes ( const vector< MyGraph > &  others,
unsigned int &  bestIndex 
) const

Compute the graph in other most similar to the invocant based on common nodes.

Parameters:
[in]othersa vector of MyGraphs.
[out]bestIndexthe index of the most similar graph.
Returns:
the value of the similarity.
MyNT MyGraph::computeNumCommonEdgesWeighted ( const MyGraph other) const

Compute the number of common nodes between the invocant and other, taking the weighted degrees of the nodes into account.

This method computes the following sum: the sum over each edge (u, v) common to both graphs of the product of (u, v)'s weighted degree in the invocant and (u, v)'s weighted degree in other.

MyNT MyGraph::computeNumCommonNodesWeighted ( const MyGraph other) const

Compute the number of common nodes between the invocant and other, taking the weighted degrees of the nodes into account.

This method computes the following sum: the sum over each node v common to both graphs of the product of v's weighted degree in the invocant and v's weighted degree in other.

MyNT MyGraph::computeSegregation ( MyNodeIdList &  nodes) [inline]

From Arjun Krishnan's paper gene-function prediction in Arabidopsis. Given a set of nodes, compute the fraction of edges between those nodes out of all edges incident on the nodes.

Compute the segregation score of the input nodes.

Parameters:
[in]nodes,aninstance of MyNodeIdList
Returns:
The segregation score, a real number between 0 and 1.
void MyGraph::computeSeparator ( const set< MyNodeId > &  nodes,
set< MyNodeId > &  separator 
)

Compute the number of nodes that separate a given set of nodes from the rest of the graph.

Parameters:
[in]nodesthe nodes whose separator we want to compute
[out]separaterthe set of nodes that separate the given nodes from the rest of the network

Given an induced subgraph of the invocant, compute the ratio of the number of edges in the subgraph by the number of edges in the invocant that are incident to the nodes in the subgraph.

void MyGraph::computeShortestPathDAG ( const MyNode node,
map< MyNodeId, MyNT > &  distance,
map< MyNodeId, unsigned int > &  count 
)

Compute the shortest path DAG rooted at node.

Parameters:
[in]nodea reference to an instance of MyNode that is the root of the shortest path DAG to be computed.
[out]distancea map keyed by node IDs. The value stored with each node ID is the distance from the root to that node.
[out]counta map keyed by node IDs. The value stored with each node ID is the the number of shortest paths from the root to that node.
void MyGraph::computeShortestPathDAG ( const MyNodeId  nodeid,
map< MyNodeId, MyNT > &  distance,
map< MyNodeId, unsigned int > &  count 
)

Compute the shortest path DAG rooted at the node with ID nodeid.

This method simply passes on the work to the version of MyGraph::computeShortestPathDAG() that accepts as a reference to an instance of MyNode as the first argument.

MyNT MyGraph::computeSimilarityEdges ( const MyGraph other,
bool  jacquard = true,
bool  asymmetric = false 
) const

Compute the similarity between two graphs based on common edges.

Parameters:
[in]otheran instance of MyGraph to compare the
[in]jacquarda Boolean. If this variable is true, which is the default, the method computes the set similarity measure (aka Jacquard's coefficient) between the sets of edges in the two graphs. If the variable is false, the method computes the number of edges common to the two graphs.
[in]asymmetrica Boolean. If this argument is true, the method returns the fraction of edges in the invocant that are common to both graphs. Otherwise (the default), the method the fraction of edges in union of the two graphs that are in both graphs.

The running time of the method is proportional to the number of edges in the smaller graph multipled by the time taken to check if an edge exists in the larger graph.

MyNT MyGraph::computeSimilarityNodes ( const MyGraph other,
bool  jacquard = true,
bool  asymmetric = false 
) const

Compute the similarity between two graphs based on common nodes.

Parameters:
[in]otheran instance of MyGraph to compare the
[in]jacquarda Boolean. If this variable is true, which is the default, the method computes the set similarity measure (aka Jacquard's coefficient) between the sets of edges in the two graphs. If the variable is false, the method computes the number of edges common to the two graphs.
[in]asymmetrica boolean. If this argument is true, the method returns the fraction of nodes in the invocant that are common to both graphs. Otherwise (the default), the method the fraction of nodes in union of the two graphs that are in both graphs.

The method computes the set similarity measure (aka Jacquard's coefficient) between the sets of nodes in the two graphs.

The running time of the method is proportional to the number of nodes in the smaller graph multipled by the time taken to check if a node exists in the larger graph.

Return the zscore of the graph.

Assuming that the weight of a node is its zscore, the Stouffer's z-score of a graph is the ratio of two quantities:

(i) the sum over all the nodes of the degree of the node multiplied by the z-score of the node.

(ii) the square root of the sum of the squares of the degrees of the nodes.

Note:
The method assumes that z-scores of the nodes are actually transferred to the edges, so that each edge has a weight equal to the sum of the z-scores of the nodes incident on it.

The method computes the Stouffer's z-score of the graph but by explicitly looping over all the nodes and edges of the graph.

Note:
The main purpose of this method is to perform a sanity check. Node and edge modifications in instances of MyGraph manage quantities such as total edge weight efficiently, but they may get out of synch with the correct values because of unknown bugs.
Warning:
The running time of this method is linear in the number of nodes and edges in the graph.

Return the weighted density of a graph.

Weighted density is defined as half its average weighted degree, i.e., the total weight of the edges divided by the number of nodes.

Return the weighted density of a graph, defined as half its average weighted degree, i.e., the total weight of the edges divided by the number of nodes.

void MyGraph::construct ( const map< string, map< string, MyNT > > &  allEdgeWeights) [virtual]

Construct the graph from a pairs of nodes and edge weights.

Parameters:
[in]allEdgeWeightsa map from node identifiers to a map from node identifiers to weights. Each edge should appear once in this map. If an edge appears twice, the weight corresponding to the second appearance is used in the graph.
void MyGraph::copyEdgeWeights ( MyGraph other)

For each edge in other, get its weight from *this.

Parameters:
[out]otheran instance of MyGraph whose edges do not have weights.
Warning:
The method does not change the weight of an edge in other that does not exist in the invocant.
void MyGraph::createErdosRenyiNPGraph ( MyGraph graph,
unsigned long  numNodes,
MyNT  prob = 0.5 
) [static]

, factory method to create an ER graph G(n,p) it creates an Erdos-Renyi (ER) Graph from a given number of nodes (n) and a given probability (p)

Parameters:
[out]graphan instance of MyGraph that will hold the returned ER Graph it should be either an empty graph or a graph having only nodes (to preserve node labels) but no edges
[in]numNodes,numberof nodes in "graph"
[in]prob,probabilityof adding 2 disconnected nodes via an edge when prob = 0.5 (by default), it creates a random-graph over all possible ( 2^(n-choose-2) ) graphs having n vertices
Note:
it clears the edges of "graph" initially, if there is any already
it doesn't resuse randomiseErdosRenyiSubgraph as that would be more time consuming due to extra cost for set_intersection
void MyGraph::createSubgraph ( const vector< MyNodeId > &  deletedNodes,
MyGraph subgraph 
) const

Create a subgraph by deleting the nodes in deletedNodes.

Parameters:
[in]deletedNodesnodes to be deleted.
[out]subgraphthe resulting subgraph

cerr<<"here"<<endl;

void MyGraph::degrees ( map< unsigned int, unsigned int > &  distribution) const

Compute the degree distribution of all the nodes.

Parameters:
[out]distributiona map storing the node degrees and their counts.

Delete all nodes of degree 0 or weighted degree 0.

Returns:
The number of nodes deleted.
bool MyGraph::deleteEdge ( MyNodeId  node1,
MyNodeId  node2 
)

Delete the edge between node1 and node2 in the graph.

Warning:
This method assumes that node1 and node2 are nodes in the graph and that (node1, node2) is an edge in the graph. The behaviour of this method is undefined if these conditions are not true.
bool MyGraph::deleteNode ( MyNodeId  id,
set< MyNodeId > *  neighbours = NULL 
)

Delete the given node and all its incident edges.

Parameters:
[in]idsthe set of nodes to delete.
[out]neighboursoptionally return a list of nodes previously adjacent to the deleted node.
void MyGraph::deleteNodeSet ( const set< MyNodeId >  ids)

Delete all nodes in the given set of node identifiers and their incident edges.

Note:
This method ignores identifiers that are not in invocant.
Parameters:
[in]idsthe set of nodes to delete.
void MyGraph::deleteSubgraphEdges ( MyGraph subgraph)

Deleting the edges induced by the nodes in the given subgraph.

Parameters:
[in]subgraphedges induced by the nodes in this subgraph are to be deleted from the caller.
void MyGraph::deleteSubgraphNodes ( MyGraph subgraph)

Deleting the nodes in the given subgraph.

Parameters:
[in]subgraphnodes in this graph are to be deleted.
MyEdge* MyGraph::getEdge ( MyNodeId  node1,
MyNodeId  node2 
) const [inline]
Warning:
If you invoke this method for a pair of nodes that do not define an edge, the behaviour of the method is not defined. Therefore, it is safest to first invoke MyGraph::isEdge() to check if the edge exists.
void MyGraph::getEdgeSet ( set< string > &  edgeSet) const [inline]

Return the edges in the graph as a set of pairs of node IDs. The method converts each edge into a string by concatenating the incident nodes into a pair where the lexicographically smaller node id is the first element in the pair.

Parameters:
[out]edgeSetthe set containing the edge strings.
void MyGraph::getNodeSet ( set< MyNodeId > &  nodeSet) const [inline]

Return the identifiers of the nodes in the graph as a set of MyNodeId.

Parameters:
[out]nodeSetthe set containing the node identifiers.
void MyGraph::getNodeVec ( vector< MyNodeId > &  nodeVec) const [inline]

Return the identifiers of the nodes in the graph as a vector of MyNodeId.

Parameters:
[out]nodeVecthe vector containing the node identifiers.

Return true if and only if the graph is connected.

Warning:
This operation is expensive! It computes the connected components of the graph, so it runs in time linear in the number of nodes and edges of the graph, in the worst case.
bool MyGraph::isEdge ( MyNodeId  node1,
MyNodeId  node2 
) const [inline]
Note:
this function is typically used to check if an edge in some other graph exists in this graph.
bool MyGraph::isEdge ( const MyNode node1,
const MyNode node2 
) const [inline]

Check if an edge connecting node1 and node2 is in the invocant.

Warning:
DO NOT USE THIS METHOD FOR CHECKING if an edge between node1 and node2 exists in a graph DIFFERENT from the one that node1 and node2 belong to. For that purpose, use the overloaded method that takes node identifiers as arguments.
bool MyGraph::isEdgeValid ( MyEdgePtr  eptr) [inline]

Return true if eptr is a valid iterator.

Parameters:
eptran instance of MyEdgePtr.
Warning:
This method only checks if eptr equals the end of the list of edges in the graph. Use it immediately after a call to MyGraph::addEdge().
bool MyGraph::isHiddenNode ( MyNodeId  id) const [inline]

Return true if the given node is hidden in the invocant graph.

Note:
A node is hidden if it exists and is marked as hidden.
bool MyGraph::isInduced ( const MyGraph subgraph)

Check if the given subgraph is an induced subgraph within the caller.

Parameters:
[in]subgraphthe subgraph to be tested
Returns:
true if subgraph is an induced subgraph, false otherwise
bool MyGraph::isNode ( MyNodeId  id) const [inline]

Return true if the invocant graph has a node with the given identifier, false otherwise.

bool MyGraph::isValidEdge ( const MyEdgePtr &  eptr) const [inline]

Returns true if eptr points to a valid edge.

Parameters:
[in]eptran instance of MyEdgeptr.
Note:
Currently, this method just checks if eptr equals the end of the edge list or not.
bool MyGraph::isVisibleNode ( MyNodeId  id) const [inline]

Return true if the given node is visible in the invocant graph.

Note:
A node is visible if it exists and is not hidden.
bool MyGraph::operator< ( const MyGraph rhs) const

a comparator that can be used by the STL set constructor/insert functions to make sure that two different MyGraph objects go in the same container.

Note:
see http://stackoverflow.com/questions/1114856/stdset-with-user-defined-type-how-to-ensure-no-duplicates for this issue

if none of the afore-mentioned checks could find any dissimilarity between the 2 graphs then they must be the same graph to speed-up processing in later call on (rhs < lhs), we set same graphIDs to both graphs

void MyGraph::print ( ostream &  fstr = cout,
string  name = "" 
) [virtual]

Print the details of the graph to fstr.

Prints the number of nodes, number of edges, density, completeness, the list of nodes and the list of edges in the graph.

Parameters:
fstrthe output stream to which output is written; default is standard out.
[in]namean optional identifier for the graph. If left empty, the value from getName() is used.

Print the shortest paths and the number of such paths between all pairs of nodes to an output file.

Note:
The class does not support a method to compute and store this information because of the intensive memory requirements of such a method for a large graph.
Warning:
The output file is likely to be huge.
void MyGraph::printEdges ( ostream &  fstr = cout,
string  name = "" 
) const [virtual]

Print information about the graph's edges to fstr.

For each node, print the IDs of the nodes incident on the edge, the weight of the edge, the type of the edge, and the name of the graph (or the parameter name it is provided).

Parameters:
fstrthe output stream to which output is written; default is standard out.
[in]namean optional identifier for the graph. If left empty, the value from getName() is used.
void MyGraph::printEdgeTypeCounts ( ostream &  ostr) const

Print a count over all the edges, the number of times each edge type appears.

Parameters:
[out]ostran output stream to print the results to.
Note:
The method calls MyGraph::countTypes().
void MyGraph::printNodes ( ostream &  fstr = cout,
string  name = "" 
) [virtual]

Print information about the graph's nodes to fstr.

For each node, print the node's ID, its weighted degree, and the name of the graph (or the parameter name it is provided).

Parameters:
fstrthe output stream to which output is written; default is standard out.
[in]namean optional identifier for the graph. If left empty, the value from getName() is used.
void MyGraph::randomise ( MyGraph random,
map< MyNodeId, bool > *  vertexcover = NULL 
)
void MyGraph::randomiseErdosRenyiSubgraph ( MyGraph random,
const vector< MyNodeId > &  subgraphNodes,
MyNT  prob = 0.5 
)

randomise a subgraph of a given graph to create a new graph using Erdos-Renyi (ER) model from a subset of the original graph's nodes (to randomize) and a probability (p)

Parameters:
[out]randoman instance of MyGraph that will hold the returned Graph (randomized version of caller graph)
[in]subgraphNodessubset of nodes in the caller graph: these set of nodes will be used to create a copy of caller graph which is the same as the caller graph, except the subgraph induced by the nodes in 'subgraphNodes' is randomized using ER model.
[in]probprobability of adding 2 disconnected nodes via an edge when prob = 0.5 (by default), it creates a random-graph over all possible ( 2^(n-choose-2) ) graphs having n vertices
Note:
it clears the edges of the "random" initially, consider only nodes in caller graph when subgraphNodes contains some outliers.

HACKHACKHACK since in for loop edges are not always deleted, I am deleting them beforehand

BUGBUGBUG why this doesn't delete existing edges (for which I had to call random.deleteSubgraphEdges(subgraph) before loop)?

void MyGraph::randomiseErdosRenyiSubgraph ( MyGraph random,
const set< MyNodeId > &  subgraphNodes,
MyNT  prob = 0.5 
)

randomise a subgraph of a given graph to create a new graph using Erdos-Renyi (ER) model from a subset of the original graph's nodes (to randomize) and a probability (p). It's same as the previous one except it accepts set of MyNodeIds instead of vectors

Parameters:
[out]randoman instance of MyGraph that will hold the returned Graph (randomized version of caller graph)
[in]subgraphNodessubset of nodes in the caller graph: these set of nodes will be used to create a copy of caller graph which is the same as the caller graph, except the subgraph induced by the nodes in 'subgraphNodes' is randomized using ER model.
[in]probprobability of adding 2 disconnected nodes via an edge when prob = 0.5 (by default), it creates a random-graph over all possible ( 2^(n-choose-2) ) graphs having n vertices
Note:
it clears the edges of the "random" initially, consider only nodes in caller graph when subgraphNodes contains some outliers.

HACKHACKHACK since in for loop edges are not always deleted, I am deleting them beforehand

BUGBUGBUG why this doesn't delete existing edges (for which I had to call random.deleteSubgraphEdges(subgraph) before loop)?

void MyGraph::randomiseErdosRenyiSubgraph ( const set< MyNodeId > &  subgraphNodes,
MyNT  prob 
)

this version is to be used when we want to randomize a portion of *this graph instance

Note:
this doesn't check whether the provided subgraphNodes exists in the graph so it's caller's responsibilty to make this sure, also call seed() function before calling this

HACKHACKHACK since in for loop edges are not always deleted, I am deleting them beforehand

BUGBUGBUG why this doesn't delete existing edges (for which I had to call random.deleteSubgraphEdges(subgraph) before loop)?

void MyGraph::randomiseVectorOfEdges ( MyGraph random,
unsigned int  numIterations 
)

Create a random graph with the same degree distribution of the invoking graph.

Parameters:
[in]randoman instance of MyGraph in which to store the newly-created random graph.
[in]numIterationsthe number of iterations to run the random edge-swapping algorithm. This means that numIterations times the number of edges in the invoking graph will be the actual number of swapping iterations.
void MyGraph::read ( string  fileName,
string  type = "",
MyNT  minEdgeWeight = 0,
ostream &  logStream = cout 
) [virtual]

Read a graph from a tab-delimited file.

This method expects a four column file format: node1, node2, edge type, edge weight.

Parameters:
[in]infilethe file containing the input graph.
[in]typethe type of file being read. This parameter is antiquated; behavior only changes if "sif" is explicitly provided.
[in]minimumEdgeWeightedges with weight smaller than minEdgeWeight are ignored.
[out]logStreamout output stream to which diagnostic information is printed.
void MyGraph::read2 ( string  fileName,
string  type = "",
MyNT  minEdgeWeight = 0,
ostream &  logstream = cout 
) [virtual]

Read a graph from a tab-delimited file.

This method expects a 2-4 column file format: node1, node2, edge weight, edge type. Lines beginning with '#' are ignored as comments Lines with fewer than two columns are ignored. The edge weight and edge type are optional columns.

Note:
This method differs from MyGraph::read because it expects edge weight before edge type.
Parameters:
[in]infilethe file containing the input graph.
[in]typethe type of file being read. This parameter is antiquated; behavior only changes if "sif" is explicitly provided.
[in]minimumEdgeWeightedges with weight smaller than minEdgeWeight are ignored.
void MyGraph::readNodeTypes ( string  file) [virtual]

Read the type of each node from a file.

Parameters:
[in]filethe file containing the node types. Each line of the file contains two columns. The first column contains the identifier of the node and the second column contain the type of the node. The mapping from nodes to types is many to many.
Warning:
The method silently ignores nodes that do not belong to the graph, so you should invoke the method after adding all nodes to the graph using a method such as MyGraph::read().
void MyGraph::sparsify ( string  method) [virtual]

Modify edge weights in the molecular interaction network so that it has no dense components.

Parameters:
[in]methodcan have two values two values: "edges" and "nodes".

The method finds edge-disjoint dense subgraphs in the graph and sets the weight of each edge to be the reciprocal of the total edge weight (the "edges" option) or the reciprocal of the density (the "nodes" option) of the dense subgraph the edge belongs to.

void MyGraph::subtract ( MyGraph other) [virtual]

Remove the edges (not the nodes) of other from the invocant.

Parameters:
othera constant reference to MyGraph, the graph to be subtracted.

The method also removes any nodes that have degree zero after the edge removal.

template<typename _Transform >
void MyGraph::transformEdgeWeights ( _Transform  function)

Transform the edge weights based on a function.

Parameters:
[in]functiona unary_function that takes a single argument of type MyNT and returns a value of type MyNT.
void MyGraph::transformEdgeWeightsString ( string  transform) [virtual]

Transforms edge weights using various methods.

Parameters:
[in]transformname of the transformation method to apply

The methods available are: "-log" -> new_weight = -ln(old_weight) "exp-" -> new_weight = e^(-old_weight) "one-" -> new_weight = 1 - old_weight "lapnorm" -> transforms weights so that the graph laplacian is normalized. this is done by dividing the original weight of each edge by the square-root of the product of the original weighted-degrees of the nodes it connects.


The documentation for this class was generated from the following files:
 All Classes Functions Variables Typedefs Friends