-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
243 lines (199 loc) · 7.45 KB
/
main.cpp
File metadata and controls
243 lines (199 loc) · 7.45 KB
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
//
// Created by Walfred (Wangfei) MA at the University of Southern California,
// Mark Chaisson Lab on 2/13/23.
//
// Licensed under the MIT License.
// If you use this code, please cite our work.
//
#include <iostream>
#include <string>
#include <unordered_set>
#include <chrono>
#include <filesystem>
#include "Processor.hpp"
#include "config.hpp"
extern bool optioncorr;
bool optioncorr = 0;
extern bool ifbg;
bool ifbg = 0;
void printHelp()
{
std::cout << "Usage: CTyper [options]\n\n"
<< "Options:\n"
<< " -i, --input <file> Input NGS file, allows CRAM(indexed), BAM(indexed), SAM, FASTQ and FASTA formats\n"
<< " -I, --Inputs <file> File with a list of input files\n"
<< " -m, --matrix <file> Path to the matrix database, need to come with its index file \n"
<< " -o, --output <file> Output file\n"
<< " -O, --Outputs <file> File with a list of output files\n"
<< " -n, --nthreads <number> Number of threads to use (default: 1) \n"
<< " -N, --Nsubthreads <number> Number of sub-threads (default: 1) \n"
<< " -d, --depth <value> Predetermined depth value, not compatible with -b options\n"
<< " -D, --Depth <file> File with a list of predetermined depth values, not compatible with -b options\n"
<< " -b, --background <file> Background k-mer file, used to determine NGS coverage, not compatible with -d/-D options \n"
<< " -c, --corr <0/1> Set correction for biased k-mer option for NGS data (default: 0)\n"
<< " -T, --reference <file> Specify reference for reading.\n"
<< " -h, --help Show this help message\n"
<< std::endl;
}
int main(int argc, const char * argv[])
{
std::vector<std::string> inputfiles;
std::vector<std::string> outputfiles;
std::vector<float> depths;
std::unordered_set<std::string> genes;
std::vector<char *> regions;
std::string kmatrixfile="";
std::string backgroundfile="";
const char* Argument;
int nthreads = 1;
int Nsubthreads = 1;
int window = 30;
std::string reference="";
if (argc == 1 or strcmp(argv[1], "-h")==0 or strcmp(argv[1], "--help")==0)
{
printHelp();
return 0;
}
std::cerr <<"About to process arguments."<< endl;
for (int i = 1; i < argc ; i++)
{
if (argv[i][0] == '-')
{
Argument = argv[i];
}
else if (strcmp(Argument, "-i")==0 or strcmp(Argument, "--input")==0)
{
inputfiles.push_back(argv[i]);
}
else if (strcmp(Argument, "-I")==0 or strcmp(Argument, "--Inputs")==0)
{
std::ifstream pathfile(argv[i]);
if(!pathfile)
{
std::cout<<"Error opening input file"<<std::endl;
return -1;
}
std::string line;
while (std::getline(pathfile, line))
{
inputfiles.push_back(line);
}
}
else if (strcmp(Argument, "-m")==0 or strcmp(Argument, "--matrix")==0)
{
kmatrixfile = string(argv[i]);
}
else if (strcmp(Argument, "-o")==0 or strcmp(Argument, "--output")==0)
{
outputfiles.push_back(argv[i]);
}
else if (strcmp(Argument, "-T")==0 or strcmp(Argument, "--reference")==0) {
reference=argv[i];
}
else if (strcmp(Argument, "-O")==0 or strcmp(Argument, "--Outputs")==0)
{
std::ifstream pathfile(argv[i]);
if(!pathfile)
{
std::cout<<"Error opening output file"<<std::endl;
return -1;
}
std::string line;
while (std::getline(pathfile, line))
{
outputfiles.push_back(line);
}
std::cerr << "Done reading " << outputfiles.size() << " output files." << endl;
for (auto of: outputfiles) {
std::cerr << of << endl;
}
}
else if (strcmp(Argument, "-bed") ==0 )
{
regions.push_back( (char*) malloc( (strlen(argv[i])+1)*sizeof(char) ) );
strcpy(regions[0], argv[i]);
}
else if (strcmp(Argument, "-BED") ==0 )
{
std::ifstream pathfile(argv[i]);
if(!pathfile)
{
std::cout<<"Error opening bed file"<<std::endl;
return -1;
}
std::string line;
while (std::getline(pathfile, line))
{
regions.push_back((char*) malloc((line.length()+1)*sizeof(char))) ;
strcpy(regions[regions.size()-1], line.c_str());
}
}
else if (strcmp(Argument, "-g")==0 or strcmp(Argument, "--gene")==0)
{
genes.insert(argv[i]);
}
else if (strcmp(Argument, "-G")==0 or strcmp(Argument, "--Genes")==0)
{
std::ifstream pathfile(argv[i]);
if(!pathfile)
{
std::cout<<"Error opening output file"<<std::endl;
return -1;
}
std::string line;
while (std::getline(pathfile, line))
{
genes.insert(line);
}
}
else if (strcmp(Argument, "-n")==0 or strcmp(Argument, "--nthreads")==0)
{
nthreads=(int)atoi(argv[i]);
}
else if (strcmp(Argument, "-N")==0 or strcmp(Argument, "--Nsubthreads")==0)
{
Nsubthreads=(int)atoi(argv[i]);
}
else if (strcmp(Argument, "-d")==0 or strcmp(Argument, "--depth")==0)
{
depths.push_back(atof(argv[i]));
ifbg = 0;
}
else if (strcmp(Argument, "-D")==0 or strcmp(Argument, "--Depth")==0)
{
std::ifstream pathfile(argv[i]);
if(!pathfile)
{
std::cout<<"Error opening output file"<<std::endl;
return -1;
}
std::string line;
while (std::getline(pathfile, line))
{
depths.push_back(atof(line.c_str()));
}
}
else if (strcmp(Argument, "-b")==0 or strcmp(Argument, "--background")==0)
{
backgroundfile = string(argv[i]);
ifbg = 1;
}
else if (strcmp(Argument, "-w")==0 or strcmp(Argument, "--window")==0)
{
window = (int)atoi(argv[i]);
}
else if (strcmp(Argument, "-c")==0 or strcmp(Argument, "--corr")==0)
{
optioncorr = (int)atoi(argv[i]);
}
}
std::cerr << "Done processing command line" << endl;
//if (!inputfiles.size()) return 1;
auto begin = std::chrono::high_resolution_clock::now();
Processor *processor = new Processor(inputfiles, outputfiles, depths, kmatrixfile, backgroundfile,genes, regions, window, nthreads, Nsubthreads, reference);
processor->Run();
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cout<<"finished running at time: "<<elapsed.count()* 1e-9 <<endl;
return 0;
}