-
Notifications
You must be signed in to change notification settings - Fork 23
/
assembly-stats.cpp
116 lines (99 loc) · 2.65 KB
/
assembly-stats.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
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include "fasta.h"
#include "fastq.h"
#include "filetype.h"
#include "stats.h"
using namespace std;
struct CmdLineOps
{
unsigned long minLength;
int infileStartIndex;
short outFormat;
};
void parseOptions(int argc, char** argv, CmdLineOps& ops);
int main(int argc, char* argv[])
{
CmdLineOps ops;
parseOptions(argc, argv, ops);
bool first = true;
for (int i = ops.infileStartIndex; i < argc; i++)
{
Stats s(argv[i], ops.minLength);
if (ops.outFormat == FORMAT_HUMAN)
{
if (first)
{
first = false;
}
else
{
cout << string(79, '-') << endl;
}
}
cout << s.toString(ops.outFormat);
if (ops.outFormat == FORMAT_TAB)
{
ops.outFormat = FORMAT_TAB_NO_HEAD;
}
}
return 0;
}
void parseOptions(int argc, char** argv, CmdLineOps& ops)
{
string usage;
ops.minLength = 1;
ops.infileStartIndex = 1;
ops.outFormat = FORMAT_HUMAN;
usage = "usage: stats [options] <list of fasta/q files>\n\n\
Reports sequence length statistics from fasta and/or fastq files\n\n\
options:\n\
-l <int>\n\tMinimum length cutoff for each sequence.\n\
\tSequences shorter than the cutoff will be ignored [1]\n\
-s\n\tPrint 'grep friendly' output\n\
-t\n\tPrint tab-delimited output\n\
-u\n\tPrint tab-delimited output with no header line\n\
-v\n\tPrint version and exit\n\
";
if (argc < 2)
{
cerr << usage;
exit(1);
}
while (argv[ops.infileStartIndex][0] == '-')
{
if (strcmp(argv[ops.infileStartIndex], "-s") == 0)
{
ops.outFormat = FORMAT_GREPPY;
ops.infileStartIndex++;
}
else if (strcmp(argv[ops.infileStartIndex], "-t") == 0)
{
ops.outFormat = FORMAT_TAB;
ops.infileStartIndex++;
}
else if (strcmp(argv[ops.infileStartIndex], "-u") == 0)
{
ops.outFormat = FORMAT_TAB_NO_HEAD;
ops.infileStartIndex++;
}
else if (strcmp(argv[ops.infileStartIndex], "-l") == 0)
{
ops.minLength = atoi(argv[ops.infileStartIndex + 1]);
ops.infileStartIndex += 2;
}
else if (strcmp(argv[ops.infileStartIndex], "-v") == 0)
{
cout << "Version: 1.0.1" << endl;
exit(0);
}
else
{
cerr << "error parsing options, somewhere around this: " << argv[ops.infileStartIndex] << endl;
exit(1);
}
}
}