Biorithm
1.1
|
A class that stores an undirected graph. More...
#include <graph.h>
Classes | |
class | EdgeObjectIterator |
class | MyNodeIterator |
class | NodeObjectIterator |
Public Types | |
typedef map< MyNodeId, MyNode > | MyNodeList |
typedef MyNodeList::const_iterator | MyConstNodePtr |
typedef MyNodeList::iterator | MyNodePtr |
typedef list< MyEdge > | MyEdgeList |
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 ©) | |
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 |
MyGraph & | operator= (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. | |
MyNode * | addNode (MyNodeId id) |
MyNode * | addNode (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) |
MyEdge * | getEdge (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 > > °reeLists, map< MyNodeId, list< MyNodeId >::iterator > &nodePositions) const |
void | _decrementDegrees (vector< list< MyNodeId > > °reeLists, 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 ©) |
void | _copyEdges (const MyGraph ©) |
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 > ¤tClique) |
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) |
A class that stores an undirected graph.
void MyGraph::add | ( | MyGraph & | other | ) | [virtual] |
Add the nodes and edges of other to the invocant.
other | a 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 |
||
) |
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.
other | a constant reference to MyGraph, the graph to be added. |
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.
[in] | edgeToColumn | a map from strings representing edges to indices into the other argument. The keys of this map represent a universal set of edges. |
[out] | binaryVector | a vector in which indices that have the value 1 will correspond precisely to edges that are in the invocant. |
MyNT MyGraph::computeClosestNode | ( | const MyNode & | rootNode, |
MyNodeIdSet & | nodeSet, | ||
MyNodeId & | closest | ||
) |
Find the nodes in nodeSet that is closest to rootNode.
[in] | rootNode | a const reference to an instance of MyNode. |
[in] | nodeSet | a reference to an instance of MyNodeIdSet that contains the set of target nodes. |
[out] | closest | the id of any node in nodeSet that is closest to rootNode. |
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 | ||
) |
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.
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.
[out] | logStream | an output stream to print information to. |
[out] | denseSubgraphs | a vector that will contain the computed dense subgraphs. |
[in] | computeDensestSubgraphApprox | if 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. |
void MyGraph::computeEdgeBetweenessCentrality | ( | ostream * | fstr, |
map< MyEdge, MyNT > * | bets | ||
) |
void MyGraph::computeEdgeCDWeights | ( | ) |
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.
void MyGraph::computeEdgeFSWeights | ( | ) |
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.
[out] | counts | a map keyed by the edge type. The value is the number of edges with that type in the graph. |
MyNT MyGraph::computeExpansionNodeBased | ( | MyGraph & | superGraph | ) |
Compute the node-based expansion of the graph.
[in] | superGraph | the 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.
[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.
[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.
[in] | subgraphNodes | a set of node identifiers that induce the desired subgraph. |
[out] | subgraph | the induced subgraph. |
MyGraph MyGraph::computeIntersection | ( | const vector< MyGraph > & | others | ) |
Compute the intersection of the invocant with all the graphs in others.
[in] | others | a vector of instances of MyGraph |
void MyGraph::computeMaximumSpanningTreePrim | ( | MyGraph & | mst | ) |
Run Prim's algorithm for computing the maximum spanning tree.
[out] | mst | an instance of MyGraph that will contain the maximum spanning tree. |
void MyGraph::computeMinimumSpanningTreePrim | ( | MyGraph & | mst | ) |
Run Prim's algorithm for computing the minimum spanning tree.
[out] | mst | an 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.
[out] | subgraph | the MyGraph instance in which to store the result. |
[in] | numIterationsFactor | a 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] | logStream | an output stream to print information to. |
[in] | dontCopy | if 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.
[in] | others | a vector of MyGraphs. |
[out] | bestIndex | the index of the most similar graph. |
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.
[in] | others | a vector of MyGraphs. |
[out] | bestIndex | the index of the most similar graph. |
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.
[in] | nodes,an | instance of MyNodeIdList |
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.
[in] | nodes | the nodes whose separator we want to compute |
[out] | separater | the set of nodes that separate the given nodes from the rest of the network |
MyNT MyGraph::computeSeparatorRatio | ( | MyGraph | subgraph | ) |
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.
[in] | node | a reference to an instance of MyNode that is the root of the shortest path DAG to be computed. |
[out] | distance | a map keyed by node IDs. The value stored with each node ID is the distance from the root to that node. |
[out] | count | a 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.
[in] | other | an instance of MyGraph to compare the |
[in] | jacquard | a 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] | asymmetric | a 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.
[in] | other | an instance of MyGraph to compare the |
[in] | jacquard | a 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] | asymmetric | a 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.
MyNT MyGraph::computeStouffersZScore | ( | ) | const |
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.
MyNT MyGraph::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 MyGraph::computeWeightedDensity | ( | ) |
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.
[in] | allEdgeWeights | a 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.
[out] | other | an instance of MyGraph whose edges do not have weights. |
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)
[out] | graph | an 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,number | of nodes in "graph" |
[in] | prob,probability | 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 |
void MyGraph::createSubgraph | ( | const vector< MyNodeId > & | deletedNodes, |
MyGraph & | subgraph | ||
) | const |
Create a subgraph by deleting the nodes in deletedNodes.
[in] | deletedNodes | nodes to be deleted. |
[out] | subgraph | the resulting subgraph |
cerr<<"here"<<endl;
void MyGraph::degrees | ( | map< unsigned int, unsigned int > & | distribution | ) | const |
Compute the degree distribution of all the nodes.
[out] | distribution | a map storing the node degrees and their counts. |
unsigned int MyGraph::deleteDisconnectedNodes | ( | ) |
Delete all nodes of degree 0 or weighted degree 0.
bool MyGraph::deleteEdge | ( | MyNodeId | node1, |
MyNodeId | node2 | ||
) |
Delete the edge between node1 and node2 in the graph.
bool MyGraph::deleteNode | ( | MyNodeId | id, |
set< MyNodeId > * | neighbours = NULL |
||
) |
Delete the given node and all its incident edges.
[in] | ids | the set of nodes to delete. |
[out] | neighbours | optionally 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.
[in] | ids | the set of nodes to delete. |
void MyGraph::deleteSubgraphEdges | ( | MyGraph & | subgraph | ) |
Deleting the edges induced by the nodes in the given subgraph.
[in] | subgraph | edges 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.
[in] | subgraph | nodes in this graph are to be deleted. |
MyEdge* MyGraph::getEdge | ( | MyNodeId | node1, |
MyNodeId | node2 | ||
) | const [inline] |
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.
[out] | edgeSet | the 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.
[out] | nodeSet | the 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.
[out] | nodeVec | the vector containing the node identifiers. |
bool MyGraph::isConnected | ( | ) |
Return true if and only if the graph is connected.
bool MyGraph::isEdge | ( | MyNodeId | node1, |
MyNodeId | node2 | ||
) | const [inline] |
bool MyGraph::isEdge | ( | const MyNode & | node1, |
const MyNode & | node2 | ||
) | const [inline] |
Check if an edge connecting node1 and node2 is in the invocant.
bool MyGraph::isEdgeValid | ( | MyEdgePtr | eptr | ) | [inline] |
Return true if eptr is a valid iterator.
eptr | an instance of MyEdgePtr. |
bool MyGraph::isHiddenNode | ( | MyNodeId | id | ) | const [inline] |
Return true if the given node is hidden in the invocant graph.
bool MyGraph::isInduced | ( | const MyGraph & | subgraph | ) |
Check if the given subgraph is an induced subgraph within the caller.
[in] | subgraph | the subgraph to be tested |
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.
[in] | eptr | an instance of MyEdgeptr. |
bool MyGraph::isVisibleNode | ( | MyNodeId | id | ) | const [inline] |
Return true if the given node is visible in the invocant graph.
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.
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.
fstr | the output stream to which output is written; default is standard out. | |
[in] | name | an optional identifier for the graph. If left empty, the value from getName() is used. |
void MyGraph::printAllPairsShortestPathDistances | ( | ostream & | ostr | ) |
Print the shortest paths and the number of such paths between all pairs of nodes to an output file.
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).
fstr | the output stream to which output is written; default is standard out. | |
[in] | name | an 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.
[out] | ostr | an output stream to print the results to. |
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).
fstr | the output stream to which output is written; default is standard out. | |
[in] | name | an 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)
[out] | random | an instance of MyGraph that will hold the returned Graph (randomized version of caller graph) |
[in] | subgraphNodes | subset 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] | prob | probability 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 |
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
[out] | random | an instance of MyGraph that will hold the returned Graph (randomized version of caller graph) |
[in] | subgraphNodes | subset 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] | prob | probability 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 |
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
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.
[in] | random | an instance of MyGraph in which to store the newly-created random graph. |
[in] | numIterations | the 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.
[in] | infile | the file containing the input graph. |
[in] | type | the type of file being read. This parameter is antiquated; behavior only changes if "sif" is explicitly provided. |
[in] | minimumEdgeWeight | edges with weight smaller than minEdgeWeight are ignored. |
[out] | logStream | out 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.
[in] | infile | the file containing the input graph. |
[in] | type | the type of file being read. This parameter is antiquated; behavior only changes if "sif" is explicitly provided. |
[in] | minimumEdgeWeight | edges with weight smaller than minEdgeWeight are ignored. |
void MyGraph::readNodeTypes | ( | string | file | ) | [virtual] |
Read the type of each node from a file.
[in] | file | the 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. |
void MyGraph::sparsify | ( | string | method | ) | [virtual] |
Modify edge weights in the molecular interaction network so that it has no dense components.
[in] | method | can 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.
other | a constant reference to MyGraph, the graph to be subtracted. |
The method also removes any nodes that have degree zero after the edge removal.
void MyGraph::transformEdgeWeights | ( | _Transform | function | ) |
Transform the edge weights based on a function.
[in] | function | a 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.
[in] | transform | name 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.