Debian Codegraph @

tools/kissnp2/src/Kissnp2.cpp

raw
1 /*****************************************************************************
2 * discoSnp++: discovering polymorphism from raw unassembled NGS reads
3 * A tool from the GATB (Genome Assembly Tool Box)
4 * Copyright (C) 2014 INRIA
5 * Authors: P.Peterlongo, E.Drezen
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *****************************************************************************/
20
21 #include <Kissnp2.hpp>
22 #include <Bubble.hpp>
23
24 using namespace std;
25
26 /********************************************************************************
27 *
28 * A QUICK OVERVIEW OF THE CLASS...
29 *
30 * This class implements the detection of SNP in a provided de Bruijn graph.
31 *
32 * It is implemented as a subclass of Tool, so we get all the facilities of the
33 * Tool class. We can therefore see two main parts here:
34 *
35 * 1) constructor: we define all the command line parameters available
36 *
37 * 2) 'execute' method: this is the main method of the class where the main loop
38 * (ie. iteration over nodes of the graph) is done.
39 *
40 ********************************************************************************/
41
42 /*********************************************************************
43 ** METHOD :
44 ** PURPOSE :
45 ** INPUT :
46 ** OUTPUT :
47 ** RETURN :
48 ** REMARKS :
49 *********************************************************************/
50 Kissnp2::Kissnp2 () : Tool ("Kissnp2")
51 {
52 /** We add options known by kissnp2. */
53 getParser()->push_front (new OptionNoParam (STR_DISCOSNP_LOW_COMPLEXITY, "conserve low complexity SNPs", false));
54 getParser()->push_front (new OptionOneParam (STR_MAX_AMBIGOUS_INDELS, "Maximal size of ambiguity of INDELs. INDELS whose ambiguity is higher than this value are not output", false, "20"));
55 getParser()->push_front (new OptionOneParam (STR_DISCOSNP_AUTHORISED_BRANCHING, "branching mode\n"
56 "\t\t0: forbid SNPs for which any of the two paths is branching (high precision, low recall)\n"
57 "\t\t1: forbid SNPs for which the two paths are branching (e.g. the two paths can be created either with a 'A' or a 'C' at the same position (default value)\n"
58 "\t\t2: No limitation on branching (low precision, high recall)", false, "1"));
59 getParser()->push_front (new OptionOneParam (STR_MAX_SYMMETRICAL_CROSSROADS,"In b2 mode only: maximal number of symmetrical croasroads traversed while trying to close a bubble. Default: no limit", false, "-1"));
60
61 getParser()->push_front (new OptionNoParam (STR_DISCOSNP_TRAVERSAL_UNITIG, "extend found and stop at first polymorphism (strict extension=unitigs) SNPs. Uncompatible with -T", false));
62 getParser()->push_front (new OptionNoParam (STR_DISCOSNP_TRAVERSAL_CONTIG, "extend found and stop at large polymorphism (extension=contigs) SNPs. Uncompatible with -t", false));
63 getParser()->push_front (new OptionOneParam (STR_URI_OUTPUT, "output name", true));
64 getParser()->push_front (new OptionOneParam (STR_KISSNP2_COVERAGE_FILE_NAME, "File (.h5) generated by kissnp2, containing the coverage threshold per read set", false, "_removemeplease"));
65
66 getParser()->push_front (new OptionOneParam (STR_URI_INPUT, "input file (likely a hdf5 file)", true));
67 getParser()->push_front (new OptionNoParam (STR_KISSNP2_DONT_OUTPUT_FIRST_COV, "Don't output the first coverage threshold. Use this option when the reference file is used for finding the variants", false));
68
69
70 getParser()->push_front (new OptionOneParam (STR_MAX_INDEL_SIZE, "maximal size of a predicted indel", false, "0"));
71 getParser()->push_front (new OptionOneParam (STR_MAX_POLYMORPHISM, "maximal number of polymorphism per bubble", false, "1"));
72
73
74 getParser()->push_back (new OptionOneParam (BubbleFinder::STR_BFS_MAX_DEPTH, "maximum depth for BFS", false, "200"));
75 getParser()->push_back (new OptionOneParam (BubbleFinder::STR_BFS_MAX_BREADTH, "maximum breadth for BFS", false, "20"));
76
77 getParser()->push_front (new OptionNoParam (STR_RADSEQ, "keep truncated bubbles, that have no successors on the 2 paths at the same position", false));
78 getParser()->push_back (new OptionOneParam (STR_MAX_TRUNCATED_PATH_LENGTH_DIFFERENCE, "Longest accepted difference length between two paths of a truncated bubble", false, "0"));
79
80 }
81
82 /*********************************************************************
83 ** METHOD :
84 ** PURPOSE :
85 ** INPUT :
86 ** OUTPUT :
87 ** RETURN :
88 ** REMARKS :
89 *********************************************************************/
90
91
92 /*
93 * // We load a Storage product "foo" in HDF5 format
94 // It must have been created with the storage1 snippet
95 Storage* storage = StorageFactory(STORAGE_HDF5).load ("foo");
96 LOCAL (storage);
97 // Shortcut: we get the root of this Storage object
98 Group& root = storage->root();
99 // We get a collection of native integer from the storage.
100 Collection<NativeInt64>& myIntegers = root.getCollection<NativeInt64> ("myIntegers");
101 // We create an iterator for our collection.
102 Iterator<NativeInt64>* iter = myIntegers.iterator();
103 LOCAL (iter);
104 // Now we can iterate the collection through this iterator.
105 for (iter->first(); !iter->isDone(); iter->next()) { cout << iter->item() << endl; }
106 */
107 void Kissnp2::execute ()
108 {
109 Dispatcher::Status status;
110 u_int64_t nbNodes = 0;
111
112
113 /** We load the graph from the provided uri. */
114
115 string input_graph = "-in "+getInput()->getStr(STR_URI_INPUT)+" -no-mphf";
116
117 Graph graph = Graph::create(input_graph.c_str());
118 // DEBUG
119 // cout<<"INFOS: "<<graph.getInfo()<<endl;
120 // // We get an iterator for all nodes of the graph.
121 // GraphIterator<Node> ite = graph.iterator ();
122 // // We loop each node. Note the structure of the for loop.
123 // for (ite.first(); !ite.isDone(); ite.next())
124 // {
125 // // The currently iterated node is available with it.item()
126 // // We dump an ascii representation of the current node.
127 // std::cout << graph.toString (ite.item()) << std::endl;
128 // }
129
130 istringstream iss(graph.getInfo().getStr("thresholds"));
131
132 /** We store in a _removemeplease.txt file the used coverages */
133 // We create a Storage product "_removemeplease.h5" in HDF5 format
134 Storage* storage = StorageFactory(STORAGE_HDF5).create (getInput()->getStr(STR_KISSNP2_COVERAGE_FILE_NAME), true, false);
135
136 LOCAL (storage);
137 Group& root = storage->root();
138 Collection<NativeInt64>& myIntegers = root.getCollection<NativeInt64> ("cutoffs");
139
140 int n;
141 if (getInput()->get (STR_KISSNP2_DONT_OUTPUT_FIRST_COV) != 0)
142 iss >> n; //Don't output the first coverage value
143
144 while (iss >> n)
145 myIntegers.insert (n);
146
147 myIntegers.flush();
148
149
150
151
152
153
154 /** We want to get some statistics about the execution. */
155 BubbleFinder::Stats stats;
156
157 /** We create an instance of BubbleFinder, used as a functor by the dispatcher.
158 * This instance will be cloned N times, one per thread created by the dispatcher.
159 */
160 BubbleFinder bubbleFinder (getInput(), graph, stats);
161
162 /** THIS IS THE MAIN ITERATION LOOP... We launch the iteration over all the branching nodes of the graph.
163 * Each iterated node is sent in one of N threads where it is provided to the operator() method
164 * of one of the N BubbleFinder instance. */
165
166 /** We get an iterator over the branching nodes of the graph. */
167 ProgressGraphIterator<BranchingNode,ProgressTimer> it (graph.iteratorBranching(), "nodes");
168
169 /** We get the number of nodes. */
170 nbNodes = it.size();
171
172 /** We loop the nodes. */
173 status = getDispatcher()->iterate (it, bubbleFinder);
174
175
176
177
178
179 /** We aggregate information for user. */
180 getInfo()->add (1, bubbleFinder.getConfig());
181 getInfo()->add (1, "nodes", "");
182 getInfo()->add (2, "nb", "%lu", nbNodes);
183 getInfo()->add (1, "SNP bubbles", "");
184 getInfo()->add (2, "nb", "%lu", stats.nb_bubbles_snp);
185 getInfo()->add (3, "nb truncated (among all)", "%lu", stats.nb_bubbles_snp_truncated);
186 getInfo()->add (3, "nb_high", "%lu", stats.nb_bubbles_snp_high);
187 getInfo()->add (3, "nb_low", "%lu", stats.nb_bubbles_snp_low);
188 getInfo()->add (2, "extensions", "");
189 getInfo()->add (3, "none", "%d", stats.nb_where_to_extend_snp[0]);
190 getInfo()->add (3, "left", "%d", stats.nb_where_to_extend_snp[1]);
191 getInfo()->add (3, "right", "%d", stats.nb_where_to_extend_snp[2]);
192 getInfo()->add (3, "left|right", "%d", stats.nb_where_to_extend_snp[3]);
193 getInfo()->add (1, "Indel bubbles", "");
194 getInfo()->add (2, "nb", "%lu", stats.nb_bubbles_del);
195 getInfo()->add (2, "nb_high", "%lu", stats.nb_bubbles_del_high);
196 getInfo()->add (2, "nb_low", "%lu", stats.nb_bubbles_del_low);
197 getInfo()->add (2, "extensions", "");
198 getInfo()->add (3, "none", "%d", stats.nb_where_to_extend_del[0]);
199 getInfo()->add (3, "left", "%d", stats.nb_where_to_extend_del[1]);
200 getInfo()->add (3, "right", "%d", stats.nb_where_to_extend_del[2]);
201 getInfo()->add (3, "left|right", "%d", stats.nb_where_to_extend_del[3]);
202 getInfo()->add (1, "time", "");
203 getInfo()->add (2, "find", "%d", status.time);
204 }
205