-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
137 lines (112 loc) · 4.72 KB
/
main.cpp
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
//Written by Annika Jochheim <annika.jochheim@mpinat.mpg.de>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <sstream>
#include "src/util.h"
#include "src/Options.h"
#include "src/Command.h"
#include "src/Info.h"
#ifdef GIT_SHA1
#define str2(s) #s
#define str(s) str2(s)
const char *version = str(GIT_SHA1);
#undef str
#undef str2
#else
const char *version = "UNKNOWN";
#endif
const char *tool_name = "CoCo";
const char *tool_introduction = "CoCo is an open-source software suite for "\
"different COnsensus COrrection applications "\
"using spaced k-mer count profiles of short reads or contigs";
const char *main_author = "Annika Jochheim (annika.jochheim@mpinat.mpg.de)";
extern int correction(int argc, const char **argv, const struct Command *tool);
extern int consensus(int argc, const char **argv, const struct Command *tool);
extern int filter(int argc, const char **argv, const struct Command *tool);
extern int abundanceEstimator(int argc, const char **argv, const struct Command *tool);
extern int profile(int argc, const char **argv, const struct Command *tool);
extern int counts2flat(int argc, const char **argv, const struct Command *tool);
Options &opt = Options::getInstance();
std::vector<struct Command> commands =
{
/*** basic tools ***/
{"correction", correction, &opt.correctionWorkflow, "correct sequencing errors",
"identify reads with sequencing errors and correct them",
"Annika Jochheim <annika.jochheim@mpinat.mpg.de>",
" -1 <fasta|q> -2 <fasta|q> | --reads <fasta|q> [--counts <count.h5>] [options]",
CORRECTOR
},
/*{"consensus", consensus, &opt.consensusWorkflow, "generate consensus reads ",
"flip SNPs to the major allele to generate the consensus nucleotide sequence",
"Annika Jochheim <annika.jochheim@mpinat.mpg.de>",
"--reads <fastaFile> [--counts <count.h5>] [--outprefix <string>] [options]",
CONSENSUS
}*/
{"filter", filter, &opt.filterWorkflow, "filter chimeric reads",
"identify reads containing spurious nucleotide order",
"Annika Jochheim <annika.jochheim@mpinat.mpg.de>",
" -1 <fasta|q> -2 <fasta|q> | --reads <fasta|q> [--counts <count.h5>] [options]",
FILTER
},
{"abundance", abundanceEstimator, &opt.abundanceEstimatorWorkflow, "estimate abundance values",
"Give for every read an estimated value for the abundance",
"Annika Jochheim <annika.jochheim@mpinat.mpg.de>",
" -1 <fasta|q> -2 <fasta|q> | --reads <fasta|q> [--counts <count.h5>] [options]",
ABUNDANCE_ESTIMATOR
},
/*** developer tools ***/
{"profile", profile, &opt.profileWorkflow, "print spaced k-mer count profiles (devtool)",
"dev tool to write for every sequence the spaced k-mer count profile in a tab separated plain text file",
"Annika Jochheim <annika.jochheim@mpinat.mpg.de>",
" -1 <fasta|q> -2 <fasta|q> | --reads <fasta|q> [--counts <count.h5>] [options]",
PROFILE
},
{"counts2flat", counts2flat, &opt.counts2flatWorkflow, "print spaced k-mer lookup table (devtool)",
"transform continous kmers to spaced kmers and print spaced k-mers and counts as stored in lookuptable",
"Annika Jochheim <annika.jochheim@mpinat.mpg.de>",
" --counts <count.h5>] [--outprefix <string>] [options]",
COUNTS2FLAT
}
};
struct Command *getCommand(const char *name) {
for (size_t idx = 0; idx < commands.size(); idx++) {
struct Command *command = &commands[idx];
if (!strcmp(name, command->cmd))
return command;
}
return NULL;
}
void printUsage(const int mode = SIMPLE) {
std::stringstream usage;
usage << tool_introduction << "\n\n";
usage << tool_name << " Version: " << version << "\n";
usage << "© " << main_author << "\n\n";
usage << "available commands:\n";
for (size_t j = 0; j < commands.size(); j++) {
struct Command &t = commands[j];
usage << " " + std::string(t.cmd) << "\t"<< t.descriptShort << "\n";
}
//TODO: add extra category for dev tools
std::cerr << usage.str() << "\n";
}
int main(int argc, const char *argv[]) {
if (argc < 2) {
printUsage(SIMPLE);
return (EXIT_FAILURE);
}
if ((argv[1][0] == '-' && argv[1][1] == 'h') ||
strcmp(argv[1], "--help") == 0) {
printUsage(EXTENDED);
return (EXIT_SUCCESS);
}
struct Command *command = getCommand(argv[1]);
if (command == NULL) {
Info(Info::ERROR) << "Invalid Command: " << argv[1] << "\n";
printUsage(SIMPLE);
return (EXIT_FAILURE);
}
Info(Info::INFO) <<"\n" << tool_name << " Version: " << version << "\n";
Info(Info::INFO) << "Execute " << tool_name << " command: " << command->cmd << "\n\n";
EXIT(command->callerFunction(argc - 2, argv + 2, command));
}