-
Notifications
You must be signed in to change notification settings - Fork 4
/
pipeline.cpp
104 lines (84 loc) · 3.01 KB
/
pipeline.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
/*
Pheniqs : PHilology ENcoder wIth Quality Statistics
Copyright (C) 2018 Lior Galanti
NYU Center for Genetics and System Biology
Author: Lior Galanti <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pipeline.h"
Pipeline::Pipeline(const int argc, const char** argv) try :
interface(argc, argv) {
PhredScale::get_instance();
} catch(Error& error) {
error.push("Pipeline");
throw;
};
Pipeline::~Pipeline() {
for(auto& job : job_queue) {
delete job;
}
};
void Pipeline::print_version(ostream& o) const {
interface.print_version(o);
/* This is mostly for when building a static pheniqs binary
The --version will report the library versions that were built in. */
#ifdef PHENIQS_ZLIB_VERSION
o << "zlib " << PHENIQS_ZLIB_VERSION << endl;
#endif
#ifdef PHENIQS_BZIP2_VERSION
o << "bzlib " << PHENIQS_BZIP2_VERSION << endl;
#endif
#ifdef PHENIQS_XZ_VERSION
o << "xzlib " << PHENIQS_XZ_VERSION << endl;
#endif
#ifdef PHENIQS_LIBDEFLATE_VERSION
o << "libdeflate " << PHENIQS_LIBDEFLATE_VERSION << endl;
#endif
#ifdef PHENIQS_RAPIDJSON_VERSION
o << "rapidjson " << PHENIQS_RAPIDJSON_VERSION << endl;
#endif
#ifdef PHENIQS_HTSLIB_VERSION
o << "htslib " << PHENIQS_HTSLIB_VERSION << endl;
#endif
};
Job* Pipeline::pop_from_queue() {
if(!job_queue.empty()) {
Job* job(job_queue.front());
job_queue.pop_front();
return job;
} else { return NULL;}
};
void Pipeline::push_to_queue(Document& operation) {
if(operation.IsObject()) {
Job* job(NULL);
string implementation(decode_value_by_key< string >("implementation", operation));
if(implementation == "transcode") { job = new Transcode(operation); }
else { job = new Job(operation); }
job->assemble();
job_queue.emplace_back(job);
} else { throw ConfigurationError("Job operation element is not a dictionary"); }
};
void Pipeline::execute() {
if(interface.help_triggered()) {
interface.print_help(cout);
} else if(interface.version_triggered()) {
print_version(cout);
} else {
Document operation(interface.operation());
push_to_queue(operation);
Job* job(NULL);
while((job = pop_from_queue()) != NULL) {
job->run();
delete job;
}
}
};