-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvcfCTools.cpp
119 lines (102 loc) · 4 KB
/
vcfCTools.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
// ******************************************************
// vcfCTools (c) 2011 Alistair Ward
// Marth Lab, Department of Biology, Boston College
// All rights reserved.
// ------------------------------------------------------
// Last modified: 18 February 2011
// ------------------------------------------------------
// Toolkit for vcf file manipulation
// ******************************************************
// includes
#include "tool_annotate.h"
//#include "tool_distributions.h"
#include "tool_filter.h"
#include "tool_intersect.h"
#include "tool_merge.h"
#include "tool_stats.h"
#include "tool_validate.h"
#include "vcfCTools_version.h"
#include <cstdio>
#include <iostream>
#include <string>
using namespace vcfCTools;
using namespace std;
// vcfCTools tool list
static const string ANNOTATE = "annotate";
//static const string DISTRIBUTIONS = "distributions";
static const string FILTER = "filter";
static const string INTERSECT = "intersect";
static const string MERGE = "merge";
static const string STATS = "stats";
static const string VALIDATE = "validate";
// help and version
static const string HELP = "help";
static const string LONG_HELP = "--help";
static const string SHORT_HELP = "-h";
static const string VERSION = "version";
static const string LONG_VERSION = "--version";
static const string SHORT_VERSION = "-v";
// determine if string is a help constant
static bool IsHelp(char* str) {
return (str == HELP || str == LONG_HELP || str == SHORT_HELP);
}
// determine if string is a version constant
static bool IsVersion(char* str) {
return (str == VERSION || str == LONG_VERSION || str == SHORT_VERSION);
}
// Determine the tool.
AbstractTool* CreateTool(const string& arg) {
if (arg == ANNOTATE ) return new annotateTool;
//if (arg == DISTRIBUTIONS ) return new distributionsTool;
if (arg == FILTER ) return new filterTool;
if (arg == INTERSECT ) return new intersectTool;
if (arg == MERGE ) return new mergeTool;
if (arg == STATS ) return new statsTool;
if (arg == VALIDATE ) return new validateTool;
return 0;
}
// Print help information.
int Help(int argc, char* argv[]) {
// Check if the requested help is for a specific tool.
if (argc > 2) {
AbstractTool* tool = CreateTool(argv[2]);
if (tool) return tool->Help();
}
// General help information.
cout << endl;
cout << "Usage: vcfCTools [tool] [options]" << endl << endl;
cout << "Available tools:" << endl;
cout << " annotate:\n\tAnnotate a vcf file with dbsnp or hapmap membership." << endl;
cout << " distributions:\n\tGenerate distributions from the vcf data." << endl;
cout << " filter:\n\tFilter the vcf file on specified criteria and populate the filter field." << endl;
cout << " intersect:\n\tCalculate the intersection of two vcf files (or a vcf and a bed file)." << endl;
cout << " merge:\n\tMerge a list of vcf files." << endl;
cout << " stats:\n\tGenerate statistics on a vcf file." << endl;
cout << " validate:\n\tValidate a vcf file." << endl;
cout << endl;
cout << "vcfCTools help tool for help on a specific tool." << endl << endl;
return 0;
}
// Print out version information.
int Version(void) {
cout << endl;
cout << "vcfCTools - vcf file manipulation tools." << endl;
cout << "Version " << VCFCTOOLS_VERSION_MAJOR << "." << VCFCTOOLS_VERSION_MINOR << " - " << VCFCTOOLS_DATE << endl;
cout << "Alistair Ward, Marth Lab, Department of Biology, Boston College." << endl;
cout << endl;
return 0;
}
// vcfCTools tool select.
int main(int argc, char* argv[]) {
// If no tool is selected, show the help.
if (argc == 1) return Help(argc, argv);
//vcfCTools help
if (IsHelp(argv[1])) return Help(argc, argv);
//vcfCTools version.
if (IsVersion(argv[1])) return Version();
// If a tool is specified, determine and run the tool. If the tool
// does not exist, show the help.
AbstractTool* tool = CreateTool(argv[1]);
if (tool ) return tool->Run(argc, argv);
else return Help(argc, argv);
}