-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreshold.cpp
116 lines (102 loc) · 2.67 KB
/
threshold.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
/* Copyright (c) 2013 Y. William Yu. Released under CC0 1.0 Universal */
/* threshold.cpp
* Changes quality values above [quality score] in a file to [quality score]
*/
#if !defined(NDEBUG)
#define BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING
#define BOOST_MULTI_INDEX_ENABLE_SAFE_MODE
#endif
#define BOOST_MULT_INDEX_DISABLE_SERIALIZATION
//#define VERBOSE
#include "global.h"
#include <iterator>
#include <fstream>
int main( int argc, char *argv[])
{
if (argc < 3) {
std::cerr << "Smoothes all quality scores above a threshold." << std::endl;
std::cerr << "Usage: " << argv[0] << " [quality score] [input_file]" << std::endl;
std::cerr << "\tWill output a modified file named '[input_file].reduced' with all" << std::endl
<< "\tascii values above [quality score] in column 11 replaced with" << std::endl
<< "\t[quality score]." << std::endl;
exit(-1);
}
if (strlen(argv[1])>1) {
std::cerr << "[quality score] must be a single ascii character." << std::endl;
exit(-50);
}
std::FILE * inFile;
std::FILE * outFile;
char outfile_name[4096];
unsigned int name_length;
int col=1;
char quality_threshold;
quality_threshold = argv[1][0];
int c; // character input
for (int argwalker = 2; argwalker < argc; ++argwalker) {
name_length = strlen(argv[argwalker]);
if (name_length>4000) {
std::cerr << "Filepaths cannot be longer than 4000 characters." << std::endl;
exit(-2);
}
strcpy(outfile_name,argv[argwalker]);
outfile_name[name_length++]='.';
outfile_name[name_length++]='r';
outfile_name[name_length++]='e';
outfile_name[name_length++]='d';
outfile_name[name_length++]='u';
outfile_name[name_length++]='c';
outfile_name[name_length++]='e';
outfile_name[name_length++]='d';
outfile_name[name_length++]='\0';
std::cout << argv[argwalker] << " --> " << outfile_name << std::endl;
inFile=fopen(argv[argwalker],"r");
if (inFile==NULL) {
perror ("Error opening input file.");
exit(-3);
}
outFile=fopen(outfile_name,"w");
if (outFile==NULL) {
perror ("Error opening output file.");
exit(-4);
}
while ( (c=getc(inFile)) !=EOF)
{
if (col == 11) {
//printf(".");
switch (c) {
case '\t':
++col;
putc(c,outFile);
break;
case '\n':
col = 1;
putc(c,outFile);
break;
default:
if (c>quality_threshold) {
putc(quality_threshold,outFile);
}
else
putc(c,outFile);
break;
}
} else {
switch (c) {
case '\n':
col=0;
// Deliberate fall-through
case '\t':
++col;
// Deliberate fall-through
default:
break;
}
putc(c,outFile);
}
}
fclose(inFile);
fclose(outFile);
}
return 0;
};