Commit 814f1db3 by Rayan Chikhi

### getting snippets to compile with new Graph API

parent 92595cce
 ... ... @@ -17,7 +17,7 @@ int main (int argc, char* argv[]) Graph graph = Graph::create (new BankStrings ("AATGC", NULL), "-kmer-size 4 -abundance-min 1 -verbose 0"); // We get an iterator for all nodes of the graph. Graph::Iterator it = graph.iterator (); Graph::Iterator it = graph.iterator (); // We check that we have only two possible nodes assert (it.size() == 2); ... ... @@ -38,7 +38,7 @@ int main (int argc, char* argv[]) { // We get the neighbors of this specific current // Note that we get here the full edge information Graph::Vector neighbors = graph.successors (current); Graph::Vector neighbors = graph.successorsEdge (current); // We check that we got only one successor assert (neighbors.size() == 1); ... ...
 ... ... @@ -17,7 +17,7 @@ int main (int argc, char* argv[]) Graph graph = Graph::create (new BankStrings ("AATGC", NULL), "-kmer-size 4 -abundance-min 1 -verbose 0"); // We get an iterator for all nodes of the graph. Graph::Iterator it = graph.iterator (); Graph::Iterator it = graph.iterator (); // We check that we have only two possible nodes assert (it.size() == 2); ... ... @@ -37,7 +37,7 @@ int main (int argc, char* argv[]) // It could have been retrieved by an previous call to Graph::neighbors method // Now, we want to get the successor of the current node, only by giving the transition nucleotide. Node neighbor = graph.successor (current, NUCL_C); Node neighbor = graph.successor (current, NUCL_C); // WARNING ! This Graph::successor method doesn't check whether the neighbor actually belongs to the graph. // It is supposed here that the client knows perfectly that its transition nucleotide is valid. ... ... @@ -52,17 +52,17 @@ int main (int argc, char* argv[]) bool exists; Node potentialNeighbor; potentialNeighbor = graph.successor (current, NUCL_A, exists); potentialNeighbor = graph.successor (current, NUCL_A, exists); assert (exists == false); potentialNeighbor = graph.successor (current, NUCL_C, exists); potentialNeighbor = graph.successor (current, NUCL_C, exists); assert (exists == true); assert (graph.toString (potentialNeighbor) == "ATGC"); potentialNeighbor = graph.successor (current, NUCL_G, exists); potentialNeighbor = graph.successor (current, NUCL_G, exists); assert (exists == false); potentialNeighbor = graph.successor (current, NUCL_T, exists); potentialNeighbor = graph.successor (current, NUCL_T, exists); assert (exists == false); } } ... ...
 ... ... @@ -17,7 +17,7 @@ int main (int argc, char* argv[]) Graph graph = Graph::create (new BankStrings ("AATGC", NULL), "-kmer-size 5 -abundance-min 1 -verbose 0"); // We get an iterator for all nodes of the graph. Graph::Iterator it = graph.iterator (); Graph::Iterator it = graph.iterator (); // We check that we have only one possible node assert (it.size() == 1); ... ...
 ... ... @@ -23,7 +23,7 @@ int main (int argc, char* argv[]) // We create a Node iterator that iterates all the simple nodes from the first node // Remember that a simple node has indegree==1 and outdegree==1 Graph::Iterator path = graph.simplePath (node, DIR_OUTCOMING); Graph::Iterator path = graph.simplePath (node, DIR_OUTCOMING); // We iterate the simple path. for (path.first(); !path.isDone(); path.next()) ... ...
 ... ... @@ -23,7 +23,7 @@ int main (int argc, char* argv[]) // We create a Edge iterator that iterates all the simple edges from the first node // Recall that a simple node has indegree==1 and outdegree==1 Graph::Iterator path = graph.simplePath (node, DIR_OUTCOMING); Graph::Iterator path = graph.simplePathEdge (node, DIR_OUTCOMING); // We iterate the simple path. for (path.first(); !path.isDone(); path.next()) ... ...
 ... ... @@ -34,7 +34,7 @@ int main (int argc, char* argv[]) Node node = graph.buildNode (sequences[0]); // We retrieve the branching neighbors for the node. Graph::Vector branchingNeighbors = graph.successors (node); Graph::Vector branchingNeighbors = graph.successorsBranching (node); std::cout << "We found " << branchingNeighbors.size() << " branching neighbors from node " << graph.toString(node) << std::endl; ... ...
 ... ... @@ -34,7 +34,7 @@ int main (int argc, char* argv[]) Node node = graph.buildNode (sequences[0]); // We retrieve the branching neighbors for the node. Graph::Vector branchingNeighbors = graph.successors (node); Graph::Vector branchingNeighbors = graph.successorsBranchingEdge (node); std::cout << "We found " << branchingNeighbors.size() << " branching neighbors from node " << graph.toString(node) << std::endl; ... ...
 ... ... @@ -36,7 +36,7 @@ int main (int argc, char* argv[]) // We get an iterator for branching nodes of the graph. // We use a progress iterator to get some progress feedback ProgressGraphIterator itBranching (graph.iterator(), "statistics"); ProgressGraphIterator itBranching (graph.iteratorBranching(), "statistics"); // We define some kind of unique identifier for a couple (indegree,outdegree) typedef pair InOut_t; ... ... @@ -53,8 +53,8 @@ int main (int argc, char* argv[]) map & localTopology = topology(); // We get branching nodes neighbors for the current branching node. Graph::Vector successors = graph.successors (node); Graph::Vector predecessors = graph.predecessors (node); Graph::Vector successors = graph.successorsBranchingEdge ((Node&)node); /* node casting is necessary due to incomplete Graph.hpp api for successorsBranchingEdge */ Graph::Vector predecessors = graph.predecessorsBranchingEdge ((Node&)node); // We increase the occurrences number for the current couple (in/out) neighbors localTopology [make_pair(predecessors.size(), successors.size())] ++; ... ...
 ... ... @@ -16,29 +16,29 @@ using namespace std; // We define a class that marks nodes in a graph and call tell whether a given node is marked or not. // We use a map for the implementation (could be not optimal). template class GraphMarker class GraphMarker { public: GraphMarker (const Graph& graph) : graph(graph) { // We insert all the nodes into our map. auto iter = [&] (const T& item) { this->markMap[item] = false; }; graph.iterator().iterate (iter); auto iter = [&] (const BranchingNode& item) { this->markMap[item] = false; }; graph.iteratorBranching().iterate (iter); } void mark (const T& item) { markMap [item] = true; } void mark (const BranchingNode& item) { markMap [item] = true; } void mark (const set& items) void mark (const set& items) { for (typename set::const_iterator it=items.begin(); it != items.end(); ++it) { mark (*it); } for (typename set::const_iterator it=items.begin(); it != items.end(); ++it) { mark (*it); } } bool isMarked (const T& item) const { return markMap.find(item)->second; } bool isMarked (const BranchingNode& item) const { return markMap.find(item)->second; } private: const Graph& graph; map markMap; map markMap; }; /********************************************************************************/ ... ... @@ -46,7 +46,7 @@ private: // We define a class that performs a breadth first search in a graph from a starting node. // We need a marker to globally mark the visited nodes from one call to another. // The nodes visit is handled by a std::queue object. template class BFS class BFS { public: ... ... @@ -54,7 +54,7 @@ public: // Process the BFS started from the provided node. As a result, we get the nodes number in the // found connected component. const set& run (const T& node) const set& run (const BranchingNode& node) { // ALGORITHM (recursion on n) // We define as C(n) the set of nodes of the connected component to be computed. ... ... @@ -70,7 +70,7 @@ public: // card(F(n)) = 0 // We set the initial state for F(0) set frontline; set frontline; frontline.insert (node); // We set the initial state for C(0) ... ... @@ -81,13 +81,13 @@ public: while (!frontline.empty()) { // We get the neighbors for the current front line, ie. we get N(F(n)) set neighbors = graph.neighbors (frontline.begin(), frontline.end()); set neighbors = graph.neighbors (frontline.begin(), frontline.end()); // this is a very special overload of neighbors() from Graph.hpp // We reset the current front line => we reuse it for computing F(n+1) frontline.clear(); // We compute the recursion for F(n+1) and C(n+1) for (typename set::iterator it = neighbors.begin(); it != neighbors.end(); it++) for (typename set::iterator it = neighbors.begin(); it != neighbors.end(); it++) { if (connectedComponent.find (*it) == connectedComponent.end()) { ... ... @@ -105,11 +105,11 @@ public: } // We provide an accessor to the nodes of the found connected component const set& get() const { return connectedComponent; } const set& get() const { return connectedComponent; } private: const Graph& graph; set connectedComponent; set connectedComponent; }; /********************************************************************************/ ... ... @@ -134,10 +134,10 @@ int main (int argc, char* argv[]) Graph graph = Graph::load (options->getStr(STR_URI_GRAPH)); // We create a graph marker. GraphMarker marker (graph); GraphMarker marker (graph); // We create an object for Breadth First Search for the de Bruijn graph. BFS bfs (graph); BFS bfs (graph); // We want to compute the distribution of connected components of the branching nodes. // - key is a connected component class (for a given number of branching nodes for this component) ... ... @@ -145,7 +145,7 @@ int main (int argc, char* argv[]) map distrib; // We get an iterator for branching nodes of the graph. We use a progress iterator to get some progress feedback ProgressGraphIterator itBranching (graph.iterator(), "statistics"); ProgressGraphIterator itBranching (graph.iteratorBranching(), "statistics"); // We want to know the number of connected components size_t nbConnectedComponents = 0; ... ...
 ... ... @@ -20,26 +20,26 @@ using namespace std; // We define a class that marks nodes in a graph and call tell whether a given node is marked or not. // We use a map for the implementation (could be not optimal). template class GraphMarker class GraphMarker { public: GraphMarker (const Graph& graph) : graph(graph) { // We insert all the nodes into our map. auto iter = [&] (const T& item) { this->markMap[item] = false; }; graph.iterator().iterate (iter); auto iter = [&] (const BranchingNode& item) { this->markMap[item] = false; }; graph.iteratorBranching().iterate (iter); } void mark (const T& item) { markMap [item] = true; } void mark (const BranchingNode& item) { markMap [item] = true; } void mark (const set& items) { for (typename set::const_iterator it=items.begin(); it != items.end(); ++it) { mark (*it); } } void mark (const set& items) { for (typename set::const_iterator it=items.begin(); it != items.end(); ++it) { mark (*it); } } bool isMarked (const T& item) const { return markMap.find(item)->second; } bool isMarked (const BranchingNode& item) const { return markMap.find(item)->second; } private: const Graph& graph; map markMap; map markMap; }; /********************************************************************************/ ... ... @@ -47,7 +47,7 @@ private: // We define a class that performs a breadth first search in a graph from a starting node. // We need a marker to globally mark the visited nodes from one call to another. // The nodes visit is handled by a std::queue object. template class BFS class BFS { public: ... ... @@ -55,7 +55,7 @@ public: // Process the BFS started from the provided node. As a result, we get the nodes number in the // found connected component. const set& run (const T& node) const set& run (const BranchingNode& node) { // ALGORITHM (recursion on n) // We define as C(n) the set of nodes of the connected component to be computed. ... ... @@ -71,7 +71,7 @@ public: // card(F(n)) = 0 // We set the initial state for F(0) set frontline; set frontline; frontline.insert (node); // We set the initial state for C(0) ... ... @@ -82,13 +82,13 @@ public: while (!frontline.empty()) { // We get the neighbors for the current front line, ie. we get N(F(n)) set neighbors = graph.neighbors (frontline.begin(), frontline.end()); set neighbors = graph.neighbors (frontline.begin(), frontline.end()); // We reset the current front line => we reuse it for computing F(n+1) frontline.clear(); // We compute the recursion for F(n+1) and C(n+1) for (typename set::iterator it = neighbors.begin(); it != neighbors.end(); it++) for (typename set::iterator it = neighbors.begin(); it != neighbors.end(); it++) { if (connectedComponent.find (*it) == connectedComponent.end()) { ... ... @@ -106,11 +106,11 @@ public: } // We provide an accessor to the nodes of the found connected component const set& get() const { return connectedComponent; } const set& get() const { return connectedComponent; } private: const Graph& graph; set connectedComponent; set connectedComponent; }; /********************************************************************************/ ... ... @@ -135,10 +135,10 @@ int main (int argc, char* argv[]) Graph graph = Graph::load (options->getStr(STR_URI_GRAPH)); // We create a graph marker. GraphMarker marker (graph); GraphMarker marker (graph); // We create an object for Breadth First Search for the de Bruijn graph. BFS bfs (graph); BFS bfs (graph); // We want to compute the distribution of connected components of the branching nodes. // - key is a connected component class (for a given number of branching nodes for this component) ... ... @@ -146,7 +146,7 @@ int main (int argc, char* argv[]) map distrib; // We get an iterator for all nodes of the graph. We use a progress iterator to get some progress feedback ProgressGraphIterator itBranching (graph.iterator(), "statistics"); ProgressGraphIterator itBranching (graph.iteratorBranching(), "statistics"); // We want time duration of the iteration TimeInfo ti; ... ...
 ... ... @@ -27,10 +27,10 @@ int main (int argc, char* argv[]) Graph graph = Graph::load (options->getStr(STR_URI_GRAPH)); // We iterate the branching nodes Dispatcher().iterate (graph.iterator (), [&] (const BranchingNode& node) Dispatcher().iterate (graph.iteratorBranching (), [&] (const BranchingNode& node) { // We iterate the successors of the current node graph.successors(node).iterate ([&] (const BranchingEdge& edge) graph.successorsBranchingEdge((Node&)node).iterate ([&] (const BranchingEdge& edge) { if (edge.from == edge.to) { cout << "CYCLE: " << graph.toString (edge) << endl; } }); ... ...
 ... ... @@ -83,7 +83,8 @@ public: model.iterate (seq.getData(), [&] (const Kmer<>::ModelCanonical::Kmer& kmer, size_t rank) { // We count the branching nodes. if (graph.isBranching (Node::Value(kmer.value()))) { nbBranching++; } Node node = Node::Value(kmer.value()); if (graph.isBranching (node)) { nbBranching++; } }); // We increase the (local) distribution for this number of branching nodes per sequence ... ...
 ... ... @@ -28,32 +28,46 @@ public: _parser->push_front (new OptionOneParam (STR_NODE_TYPE, "node type (0: all, 1:branching)", false, "1" )); } template void process (const char* name) void processNode(Graph &graph, ofstream &output) { string outputFile = getInput()->get(STR_URI_OUTPUT) ? getInput()->getStr(STR_URI_OUTPUT) : (System::file().getBaseName(getInput()->getStr(STR_URI_GRAPH)) + ".dot"); map mapping; u_int64_t count = 0; Graph::Iterator itMap = graph.iterator (); for (itMap.first(); !itMap.isDone(); itMap.next()) { mapping[itMap.item()] = count++; } ofstream output (outputFile.c_str()); ProgressGraphIterator it = graph.iterator (); for (it.first(); !it.isDone(); it.next()) { Node current = it.item(); output << "digraph " << name << "{\n"; Graph::Vector neighbors = graph.neighbors(current.kmer); // We load the graph Graph graph = Graph::load (getInput()->getStr(STR_URI_GRAPH)); for (size_t i=0; i " << mapping[neighbors[i].kmer] << " ;\n"; } } output << "}\n"; output.close(); } void processBranchingNode(Graph &graph, ofstream & output) { map mapping; u_int64_t count = 0; Graph::Iterator itMap = graph.iterator (); Graph::Iterator itMap = graph.iteratorBranching(); for (itMap.first(); !itMap.isDone(); itMap.next()) { mapping[itMap.item()] = count++; } ProgressGraphIterator it = graph.iterator (); ProgressGraphIterator it = graph.iteratorBranching (); for (it.first(); !it.isDone(); it.next()) { NodeType current = it.item(); BranchingNode current = it.item(); Graph::Vector neighbors = graph.neighbors (current.kmer); Graph::Vector neighbors = graph.neighborsBranching (current.kmer); for (size_t i=0; iget(STR_URI_OUTPUT) ? getInput()->getStr(STR_URI_OUTPUT) : (System::file().getBaseName(getInput()->getStr(STR_URI_GRAPH)) + ".dot"); ofstream output (outputFile.c_str()); // We load the graph Graph graph = Graph::load (getInput()->getStr(STR_URI_GRAPH)); switch (getInput()->getInt(STR_NODE_TYPE)) { case 0: process ("all"); break; case 1: process ("branching"); break; case 0: output << "digraph " << "all" << "{\n"; processNode(graph, output); break; case 1: output << "digraph " << "branching" << "{\n"; processBranchingNode(graph, output); break; default: break; } } ... ...
 ... ... @@ -21,7 +21,7 @@ int main (int argc, char* argv[]) Graph graph = Graph::load (argv[1]); // We get an iterator for all nodes of the graph. Graph::Iterator it = graph.iterator (); Graph::Iterator it = graph.iterator (); // We loop each node. Note the structure of the for loop. for (it.first(); !it.isDone(); it.next()) ... ...
 ... ... @@ -25,7 +25,7 @@ int main (int argc, char* argv[]) Graph graph = Graph::load (argv[1]); // We get an iterator for all nodes of the graph. Graph::Iterator it = graph.iterator (); Graph::Iterator it = graph.iterator (); // We choose how many cores we want to use. // By convention, a 0 value will use all available cores. ... ...
 ... ... @@ -21,7 +21,7 @@ int main (int argc, char* argv[]) Graph graph = Graph::load (argv[1]); // We get an iterator for branching nodes of the graph. Graph::Iterator it = graph.iterator (); Graph::Iterator it = graph.iteratorBranching (); // We loop each node. Note the structure of the for loop. for (it.first(); !it.isDone(); it.next()) ... ...
 ... ... @@ -17,7 +17,7 @@ int main (int argc, char* argv[]) Graph graph = Graph::create (new BankStrings ("AATGC", NULL), "-kmer-size 4 -abundance-min 1 -verbose 0"); // We get an iterator for all nodes of the graph. Graph::Iterator it = graph.iterator (); Graph::Iterator it = graph.iterator(); // We check that we have only two possible nodes assert (it.size() == 2); ... ... @@ -37,7 +37,7 @@ int main (int argc, char* argv[]) if (s=="AATG") { // We get the neighbors of this specific current Graph::Vector neighbors = graph.successors (current); Graph::Vector neighbors = graph.successors(current); // We check that we got only one successor assert (neighbors.size() == 1); ... ...
 ... ... @@ -38,7 +38,7 @@ int main (int argc, char* argv[]) Path pathLeft; // We get one branching node in the graph Graph::Iterator itBranching = graph.iterator (); Graph::Iterator itBranching = graph.iteratorBranching (); for (itBranching.first(); !itBranching.isDone(); itBranching.next()) { BranchingNode current = itBranching.item(); ... ... @@ -49,7 +49,8 @@ int main (int argc, char* argv[]) //if (terminator.is_marked_branching (itBranching.item())) { continue; } int lenRight = traversal->traverse (current, DIR_OUTCOMING, pathRight); int lenLeft = traversal->traverse (graph.reverse(current), DIR_OUTCOMING, pathLeft); Node rev = graph.reverse(current); int lenLeft = traversal->traverse (rev, DIR_OUTCOMING, pathLeft); cout << "lenLeft=" << lenLeft << " lenRight=" << lenRight << endl; } ... ...
 ... ... @@ -47,7 +47,7 @@ int main (int argc, char* argv[]) size_t kmerSize = atol (storage->root().getProperty("kmer_size").c_str()); // We get a minimizer model Model model (kmerSize, 8, typename Kmer<>::ComparatorMinimizerFrequency(), repart.getMinimizerFrequencies()); Model model (kmerSize, 8, typename Kmer<>::ComparatorMinimizerFrequencyOrLex(), repart.getMinimizerFrequencies()); // We create the output file string outputUri = options->get(STR_URI_OUTPUT) ? ... ...
 ... ... @@ -20,7 +20,7 @@ public: Graph graph = Graph::create (getParser()->getProperties()); // We get an iterator for all nodes of the graph. We use a progress iterator to get some progress feedback ProgressGraphIterator it (graph.iterator(), "MiniDiscoSNP: finding bubbles "); ProgressGraphIterator it (graph.iteratorBranching(), "MiniDiscoSNP: finding bubbles "); int nbsnps = 1 ; int ksize = graph.getKmerSize(); ... ... @@ -40,7 +40,7 @@ public: if ((indegree ==1 && outdegree==2) || (indegree ==2 && outdegree==1) ) { //get neighbor branching edges Graph::Vector branchingNeighbors = graph.successors (current); Graph::Vector branchingNeighbors = graph.successorsBranchingEdge (current); //clean bubble if(branchingNeighbors.size()==2 && branchingNeighbors[0].distance == ksize && branchingNeighbors[1].distance == ksize) ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!