File: config.h

package info (click to toggle)
kmc 2.3%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,412 kB
  • sloc: cpp: 17,316; perl: 178; makefile: 90; sh: 16
file content (550 lines) | stat: -rw-r--r-- 20,338 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
/*
  This file is a part of KMC software distributed under GNU GPL 3 licence.
  The homepage of the KMC project is http://sun.aei.polsl.pl/kmc
  
  Authors: Marek Kokot
  
  Version: 2.3.0
  Date   : 2015-08-21
*/

#ifndef _CONFIG_H
#define _CONFIG_H

#include "defs.h"
#include <string>
#include <vector>
#include <memory>
#include "kmc_header.h"
#include "percent_progress.h"
#include "queues.h"

struct CDescBase
{
	std::string file_src;
	uint32 cutoff_min = 0; //0 means it is not set yet
	uint32 cutoff_max = 0; //0 means it is not set yet
	CDescBase(const std::string& file_src) :
		file_src(file_src)
	{
	}
	CDescBase() = default;
};

//************************************************************************************************************
// CInputDesc - description of a single input KMC database.
//************************************************************************************************************
struct CInputDesc : public CDescBase
{	
	uint32 threads = 0; //for kmc2 input
	CInputDesc(const std::string& file_src) :
		CDescBase(file_src)
	{

	}	
	CInputDesc() = default;
};

//************************************************************************************************************
// COutputDesc - description of a output KMC database.
//************************************************************************************************************
struct COutputDesc : public CDescBase
{
	uint32 counter_max = 0; //0 means it is not set yet
	COutputDesc(const std::string& file_src) :
		CDescBase(file_src)		
	{

	}

	COutputDesc() = default;
};

struct CFilteringParams
{	
	enum class file_type { fasta, fastq };
	uint32 n_readers;
	uint32 n_filters;
	int fastq_buffer_size;
	int64 mem_part_pmm_fastq_reader;
	int64 mem_tot_pmm_fastq_reader;

	int64 mem_part_pmm_fastq_filter;
	int64 mem_tot_pmm_fastq_filter;

	uint32 kmer_len;
	uint32 gzip_buffer_size = 64 << 20;
	uint32 bzip2_buffer_size = 64 << 20;

	std::vector<std::string> input_srcs;
	bool use_float_value = false;
	uint32 n_min_kmers = 2;
	uint32 n_max_kmers = 1000000000;
	float f_min_kmers = 0.0f;
	float f_max_kmers = 1.0f;
	file_type input_file_type = file_type::fastq;
	file_type output_file_type = file_type::fastq;
	std::string output_src;
};

struct CDumpParams
{
	bool sorted_output = false;
};



struct CFilteringQueues
{
	CInputFilesQueue *input_files_queue;
	CPartQueue *input_part_queue, *filtered_part_queue;
	CMemoryPool *pmm_fastq_reader;
	CMemoryPool *pmm_fastq_filter;
};


//************************************************************************************************************
// CConfig - configuration of current application run. Singleton class.
//************************************************************************************************************
class CConfig
{
public:	
	enum class Mode { UNDEFINED, INTERSECTION, KMERS_SUBTRACT, COUNTERS_SUBTRACT, UNION, COMPLEX, SORT, REDUCE, COMPACT, HISTOGRAM, DUMP, COMPARE, FILTER }; 
	uint32 avaiable_threads;
	uint32 kmer_len = 0;
	Mode mode = Mode::UNDEFINED;
	bool verbose = false;	
	std::vector<CInputDesc> input_desc;
	std::vector<CKMC_header> headers;
	COutputDesc output_desc;	

	CFilteringParams filtering_params; //for filter operation only	
	CDumpParams dump_params; //for dump operation only

	CPercentProgress percent_progress;

	static CConfig& GetInstance()
	{
		static CConfig config;
		return config;
	}		
	CConfig(const CConfig&) = delete;
	CConfig& operator=(const CConfig&) = delete;

	bool Is2ArgOper()
	{
		return mode == Mode::UNION || mode == Mode::KMERS_SUBTRACT || mode == Mode::COUNTERS_SUBTRACT || mode == Mode::INTERSECTION || mode == Mode::COMPARE;
	}

	bool IsComplex()
	{
		return mode == Mode::COMPLEX;
	}
	
	bool Is1ArgOper()
	{
		return mode == Mode::SORT || mode == Mode::REDUCE || mode == Mode::COMPACT || mode == Mode::HISTOGRAM || mode == Mode::DUMP;		
	}

	std::string GetOperationName()
	{
		switch (mode)
		{
		case CConfig::Mode::UNDEFINED:
			return "";			
		case CConfig::Mode::INTERSECTION:
			return "intersect";			
		case CConfig::Mode::KMERS_SUBTRACT:
			return "kmers_subtract";
		case CConfig::Mode::COUNTERS_SUBTRACT:
			return "counters_subtract";
		case CConfig::Mode::UNION:
			return "union";			
		case CConfig::Mode::COMPLEX:
			return "complex";			
		case CConfig::Mode::SORT:
			return "sort";
		case CConfig::Mode::REDUCE:
			return "reduce";
		case CConfig::Mode::COMPACT:
			return "compact";
		case CConfig::Mode::HISTOGRAM:
			return "histogram";
		case CConfig::Mode::DUMP:
			return "dump";
		case CConfig::Mode::COMPARE:
			return "compare";
		case CConfig::Mode::FILTER:
			return "filter";
		default:
			return "";
		}
	}


private:
	CConfig() = default;
};



class CUsageDisplayer
{
protected:
	std::string name;		
	bool is2ArgOper = false;
	bool is1ArgOper = false;
	CUsageDisplayer(const std::string& name) :name(name){}
	void Display2ArgGeneral() const
	{
		std::cout << "The '" << name << "' is two arguments' operation. General syntax:\n";
		std::cout << " kmc_tools " << name << " <input1 [input1_params]> <input2 [input2_params]> <output [output_params]>\n";
		std::cout << " input1, input2 - paths to databases generated by KMC \n";
		std::cout << " output		  - path  to output database\n";
		std::cout << " For each input there are additional parameters:\n";
		std::cout << "  -ci<value> - exclude k-mers occurring less than <value> times \n";
		std::cout << "  -cx<value> - exclude k-mers occurring more of than <value> times\n";
		std::cout << " For output there are additional parameters:\n";
		std::cout << "  -ci<value> - exclude k-mers occurring less than <value> times \n";
		std::cout << "  -cx<value> - exclude k-mers occurring more of than <value> times\n";
		std::cout << "  -cs<value> - maximal value of a counter\n";
	}

	void Display1ArgGeneral(bool output_params) const
	{
		std::cout << " The '" << name << "' is one argument operation. General syntax:\n";
		std::cout << " kmc_tools " << name << " <input> [input_params] <output> "<< (output_params ? "[output_params]" : "") << "\n";
		std::cout << " input - path to database generated by KMC \n";
		std::cout << " For input there are additional parameters:\n";
		std::cout << "  -ci<value> - exclude k-mers occurring less than <value> times \n";
		std::cout << "  -cx<value> - exclude k-mers occurring more of than <value> times\n";
	}
public:
	virtual void Display() const = 0;
	virtual ~CUsageDisplayer() {}
};

class CGeneralUsageDisplayer : public CUsageDisplayer
{
public:
	CGeneralUsageDisplayer() :CUsageDisplayer("")
	{}
	void Display() const override
	{
		std::cout << "kmc_tools ver. " << KMC_VER << " (" << KMC_DATE << ")\n";
		std::cout << "Usage:\n kmc_tools [global parameters] <operation> [operation parameters]\n";		
		std::cout << "Available operations:\n";
		std::cout << " k-mers sets' operations for 2 KMC's databases:\n";
		std::cout << "  intersect           - intersection of 2 k-mers' sets\n";
		std::cout << "  kmers_subtract      - subtraction of 2 k-mers' sets\n";
		std::cout << "  counters_subtract   - counters' subtraction of 2 k-mers' sets\n";
		std::cout << "  union               - union of 2 k-mers' sets\n\n";
		std::cout << " operations for single kmc database:\n";
		std::cout << "  sort                - sorts k-mers from database generated by KMC2.x\n";
		std::cout << "  reduce              - exclude too rare and too frequent k-mers\n";
		std::cout << "  compact             - remove counters (store only k-mers)\n";
		std::cout << "  histogram           - histogram of k-mers occurrences\n";
		std::cout << "  dump                - dump k-mers and counters to text file\n";		
		std::cout << " more complex operations:\n";
		std::cout << "  complex             - complex operations with a number of input databases\n";
		std::cout << " other operations:\n";
		std::cout << "  filter              - filter out reads with too small number of k-mers\n";
		std::cout << " global parameters:\n";
		std::cout << "  -t<value>           - total number of threads (default: no. of CPU cores)\n";
		std::cout << "  -v                  - enable verbose mode (shows some information) (default: false)\n";
		std::cout << "  -hp                 - hide percentage progress (default: false)\n";
		std::cout << "Example:\n";
		std::cout << "kmc_tools union db1 -ci3 db2 -ci5 -cx300 db1_union_db2 -ci10\n";
		std::cout << "For detailed help of concrete operation type operation name without parameters:\n";
		std::cout << "kmc_tools union\n";
	}
};

class CUnionUsageDisplayer : public CUsageDisplayer
{
	public:
		CUnionUsageDisplayer() :CUsageDisplayer("union")
		{}
		void Display() const override
		{
			Display2ArgGeneral();
			std::cout << "The output database will contains each k-mer present in both input sets. For the same k-mers in first and second input the counter in output is equal to sum from inputs.";
			std::cout << "Example:\n";
			std::cout << "kmc - k28 file1.fastq kmers1 tmp\n";
			std::cout << "kmc - k28 file2.fastq kmers2 tmp\n";
			std::cout << "kmc_tools union kmers1 -ci3 -cx70000 kmers2 kmers1_kmers2_union -cs65536\n";
		}
};

class CIntersectUsageDisplayer : public CUsageDisplayer
{
public:
	CIntersectUsageDisplayer() :CUsageDisplayer("intersect")
	{}
	void Display() const override
	{
		Display2ArgGeneral();
		std::cout << "The output database will contains only k-mers that are present in both input sets. The counter value in output database is equal to lower counter value in input.";
		std::cout << "Example:\n";
		std::cout << "kmc - k28 file1.fastq kmers1 tmp\n";
		std::cout << "kmc - k28 file2.fastq kmers2 tmp\n";
		std::cout << "kmc_tools intersect kmers1 -ci10 -cx200 kmers2 -ci4 -cx100 kmers1_kmers2_intersect -ci20 -cx150\n";
	}
};


class CCountersSubtractUsageDisplayer : public CUsageDisplayer
{
public:
	CCountersSubtractUsageDisplayer() :CUsageDisplayer("counters_subtract")
	{}
	void Display() const override
	{
		Display2ArgGeneral();
		std::cout << "The output database will contains only k-mers that are present in first input set and have counters higher than appropriate k - mers in second set. For each k - mer the counter is equal to difference between counter in first set and counter in second set.";
		std::cout << "Example:\n";
		std::cout << "kmc -k28 file1.fastq kmers1 tmp\n";
		std::cout << "kmc -k28 file2.fastq kmers2 tmp\n";
		std::cout << "kmc_tools counters_subtract kmers1 kmers2 kmers1_kmers2_counters_subtract\n";
	}
};

class CKmersSubtractUsageDisplayer : public CUsageDisplayer
{
public:
	CKmersSubtractUsageDisplayer() :CUsageDisplayer("kmers_subtract")
	{}
	void Display() const override
	{
		Display2ArgGeneral();
		std::cout << "The output database will contains only k-mers that are present in first input set but absent in the second one. The counter value is equal to value from first input set.";
		std::cout << "Example:\n";
		std::cout << "kmc - k28 file1.fastq kmers1 tmp\n";
		std::cout << "kmc - k28 file2.fastq kmers2 tmp\n";
		std::cout << "kmc_tools kmers_subtract kmers1 kmers2 kmers1_kmers2_subtract - cs200\n";
	}
};

class CComplexUsageDisplayer : public CUsageDisplayer
{
public:
	CComplexUsageDisplayer() :CUsageDisplayer("complex")
	{}
	void Display() const override
	{
		std::cout << "Complex operation allows one to define operations for more than 2 input k-mers sets. Command-line syntax:\n";
		std::cout << "kmc_tools complex <operations_definition_file>\n";
		std::cout << " operations_definition_file - path to file which define input sets and operations. It is text file with following syntax:\n";
		std::cout << " __________________________________________________________________ \n";
		std::cout << "|INPUT:                                                            |\n";
		std::cout << "|<input1>=<input1_db_path> [params]                                |\n";
		std::cout << "|<input2>=<input2_db_path> [params]                                |\n";
		std::cout << "|...                                                               |\n";
		std::cout << "|<inputN>=<inputN_db_path> [params]                                |\n";
		std::cout << "|OUTPUT:                                                           |\n";
		std::cout << "|<out_db_path>=<ref_input><oper><ref_input>[<oper><ref_input>[...] |\n";
		std::cout << "|[OUTPUT_PARAMS:                                                 __|\n";
		std::cout << "|<output_params>]                                               |  /\n";
		std::cout << "|                                                               | / \n";
		std::cout << "|_______________________________________________________________|/  \n";
		std::cout << "input1, input2, ..., inputN - names of inputs used to define equasion\n";
		std::cout << "input1_db_path, input2_db_path, ..., inputN_db_path - paths to k-mers sets\n";
		std::cout << "For each input there are additional parameters which can be set:\n";
		std::cout << "  -ci<value> - exclude k-mers occurring less than <value> times \n";
		std::cout << "  -cx<value> - exclude k-mers occurring more of than <value> times\n";
		std::cout << "out_db_path - path to output database\n";
		std::cout << "ref_input - one of input1, input2, ..., inputN\n";
		std::cout << "oper - one of {*,-,~,+}, which refers to {intersect, kmers_subtract, counters_subtract, union}\n";
		std::cout << "operator * has the highest priority. Other operators has equals priorities. Order of operations can be changed with parentheses\n";
		std::cout << "output_params are:\n";
		std::cout << "  -ci<value> - exclude k-mers occurring less than <value> times \n";
		std::cout << "  -cx<value> - exclude k-mers occurring more of than <value> times\n";
		std::cout << "  -cs<value> - maximal value of a counter\n";

		std::cout << "Example:\n";
		std::cout << " __________________________________________________________________ \n";
		std::cout << "|INPUT:                                                            |\n";
		std::cout << "|set1 = kmc_o1 -ci5                                                |\n";
		std::cout << "|set2 = kmc_o2                                                     |\n";
		std::cout << "|set3 = kmc_o3 -ci10 -cx100                                      __|\n";		
		std::cout << "|OUTPUT:                                                        |  /\n";
		std::cout << "|result = (set3+set1)*set2                                      | / \n";
		std::cout << "|_______________________________________________________________|/  \n";
		
	}
};

class CSortUsageDisplayer : public CUsageDisplayer
{
public:
	CSortUsageDisplayer() :CUsageDisplayer("sort")
	{}
	void Display() const override
	{
		Display1ArgGeneral(true);
		std::cout << " For output there are additional parameters:\n";
		std::cout << "  -cs<value> - maximal value of a counter\n";
		std::cout << "Converts database produced by KMC2.x to KMC1.x database format (which contains k-mers in sorted order)\n";
		std::cout << "Example:\n";
		std::cout << "kmc_tools sort wy_kmc2 -ci3 -cx1000 wy_kmc1 -cs255\n";
	}
};

class CReduceUsageDisplayer : public CUsageDisplayer
{
public:
	CReduceUsageDisplayer() :CUsageDisplayer("reduce")
	{}
	void Display() const override
	{
		Display1ArgGeneral(true);
		std::cout << " For output there are additional parameters:\n";
		std::cout << "  -cs<value> - maximal value of a counter\n";
		std::cout << "Exclude too rare and too frequent k-mers\n";
		std::cout << "Example:\n";
		std::cout << "kmc_tools reduce wy_kmc2 -ci3 -cx1000 wy_kmc1 -cs255\n";
	}
};


class CCompactUsageDisplayer : public CUsageDisplayer
{
public:
	CCompactUsageDisplayer() :CUsageDisplayer("compact")
	{}
	void Display() const override
	{
		Display1ArgGeneral(false);		
		std::cout << "Remove counters of k-mers\n";
		std::cout << "Example:\n";
		std::cout << "kmc_tools compact wy_kmc2 -ci3 -cx1000 wy_kmc1\n";
	}
};

class CHistogramUsageDisplayer : public CUsageDisplayer
{
public:
	CHistogramUsageDisplayer() :CUsageDisplayer("histogram")
	{}
	void Display() const override
	{
		Display1ArgGeneral(false);
		std::cout << "Produce histogram of k-mers occurrences\n";
		std::cout << "Example:\n";
		std::cout << "kmc_tools histogram wy_kmc2 -ci3 -cx1000 histo.txt\n";
	}
};


class CDumpUsageDisplayer : public CUsageDisplayer
{
public:
	CDumpUsageDisplayer() :CUsageDisplayer("dump")
	{}
	void Display() const override
	{
		std::cout << " The '" << name << "' is one argument operation. General syntax:\n";
		std::cout << " kmc_tools " << name << " [dump_params] <input> [input_params] <output>\n";
		std::cout << " dump_params:\n";
		std::cout << "  -s - sorted output\n";
		std::cout << " input - path to database generated by KMC \n";
		std::cout << " For input there are additional parameters:\n";
		std::cout << "  -ci<value> - exclude k-mers occurring less than <value> times \n";
		std::cout << "  -cx<value> - exclude k-mers occurring more of than <value> times\n";


		std::cout << "Produce text dump of kmc database\n";
		std::cout << "Example:\n";
		std::cout << "kmc_tools dump wy_kmc2 -ci3 -cx1000 dump.txt\n";
	}
};

class CFilterUsageDisplayer : public CUsageDisplayer
{
public:
	CFilterUsageDisplayer() : CUsageDisplayer("filter")
	{}
	void Display() const override
	{
		std::cout << " The '" << name << "' is two arguments' operation. General syntax:\n";
		std::cout << " kmc_tools " << name << " <kmc_input_db> [kmc_input_db_params] <input_read_set> [input_read_set_params] <output_read_set> [output_read_set_params]\n";
		std::cout << " kmc_input_db     - path to database generated by KMC \n";
		std::cout << " input_read_set   - path to input set of reads \n";
		std::cout << " output_read_set  - path to set output of reads \n";
		std::cout << " For k-mers' database there are additional parameters:\n";
		std::cout << "  -ci<value> - exclude k-mers occurring less than <value> times \n";
		std::cout << "  -cx<value> - exclude k-mers occurring more of than <value> times\n";
		std::cout << " For input set of reads there are additional parameters:\n";
		std::cout << " -ci<value> - remove reads containing less k-mers than value. It can be integer or floating number in range [0.0;1.0]\n";
		std::cout << " -ci<value> - remove reads containing more k-mers than value. It can be integer or floating number in range [0.0;1.0]\n";
		std::cout << " -f<a/q>    - input in FASTA format (-fa), FASTQ format (-fq); default: FASTQ\n";
		std::cout << " For output set of reads there are additional parameters:\n";
		std::cout << " -f<a/q>    - output in FASTA format (-fa), FASTQ format (-fq); default: same as input\n";
		std::cout << "Example:\n";
		std::cout << "kmc_tools filter kmc_db -ci3 input.fastq -ci0.5 -cx1.0 filtered.fastq\n";
		std::cout << "kmc_tools filter kmc_db input.fastq -ci10 -cx100 filtered.fastq\n";
	}
};

class CUsageDisplayerFactory
{
	std::unique_ptr<CUsageDisplayer> desc;
public:
	CUsageDisplayerFactory(CConfig::Mode mode)
	{
		switch (mode)
		{
		case CConfig::Mode::UNDEFINED:
			desc = std::make_unique<CGeneralUsageDisplayer>();
			break;
		case CConfig::Mode::INTERSECTION:
			desc = std::make_unique<CIntersectUsageDisplayer>();
			break;
		case CConfig::Mode::KMERS_SUBTRACT:
			desc = std::make_unique<CKmersSubtractUsageDisplayer>();
			break;
		case CConfig::Mode::COUNTERS_SUBTRACT:
			desc = std::make_unique<CCountersSubtractUsageDisplayer>();
			break;
		case CConfig::Mode::UNION:
			desc = std::make_unique<CUnionUsageDisplayer>();
			break;
		case CConfig::Mode::COMPLEX:
			desc = std::make_unique<CComplexUsageDisplayer>();
			break;
		case CConfig::Mode::SORT:
			desc = std::make_unique<CSortUsageDisplayer>();
			break;
		case CConfig::Mode::REDUCE:
			desc = std::make_unique<CReduceUsageDisplayer>();
			break;
		case CConfig::Mode::COMPACT:
			desc = std::make_unique<CCompactUsageDisplayer>();
			break;
		case CConfig::Mode::HISTOGRAM:
			desc = std::make_unique<CHistogramUsageDisplayer>();
			break;
		case CConfig::Mode::DUMP:
			desc = std::make_unique<CDumpUsageDisplayer>();
			break;
		case CConfig::Mode::COMPARE:
			desc = std::make_unique<CGeneralUsageDisplayer>();
			break;
		case CConfig::Mode::FILTER:
			desc = std::make_unique<CFilterUsageDisplayer>();
			break;
		default:
			desc = std::make_unique<CGeneralUsageDisplayer>();
			break;
		}
	}
	const CUsageDisplayer& GetUsageDisplayer()
	{
		return *desc;
	}
};

#endif


// ***** EOF