-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
165 lines (157 loc) · 5.94 KB
/
main.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
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
#include <omp.h>
#include <string>
#include <cstdlib>
#include <cstdint>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <assert.h>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unordered_map>
#include "config.hpp"
#include "lprint.hpp"
#include "ping_pong.hpp"
#include "aggregator.hpp"
#include "chromosomes.hpp"
#include "snp_corrector.hpp"
#include "converter.hpp"
#ifdef LOCAL_BUILD
#include "finder.hpp"
#include "shifter.hpp"
#include "scanner.hpp"
#include "extractor.hpp"
#include "kmer_finder.hpp"
#include "haplotype_shifter.hpp"
#endif
using namespace std ;
// ============================================================================= \\
// ============================================================================= \\
// ============================================================================= \\
// ============================================================================= \\
void create_workdir() {
auto c = Configuration::getInstance() ;
struct stat info ;
lprint({c->workdir}, 0);
if (stat(c->workdir.c_str(), &info) != 0) {
lprint({"Working directory does not exist. creating.."}, 0);
int check = mkdir(c->workdir.c_str(), 0777) ;
if (check != 0) {
lprint({"Failed to create output directory, aborting.."}, 2);
exit(check) ;
}
}
}
void print_help() {
cerr << "Usage: " << endl;
cerr << "\tTo index sample:" << endl ;
cerr << "\t\tPingPong index [--binary] [--append /path/to/binary/index] --fastq /path/to/fastq/file [--threads threads] --index /path/to/output/index/file" << endl ;
cerr << "\t\tOptional arguments: " << endl ;
cerr << "\t\t\t-b, --binary output index in binary format" << endl ;
cerr << "\t\t\t-a, --append append to existing index (must be stored in binary). DON'T pass this option for building an index you want to use directly." << endl ;
// cerr << "\t\t\t-t, --threads number of threads (default is 1)" << endl ;
cerr << "\tTo search for specific strings:" << endl ;
cerr << "\t\tPingPong search [--index /path/to/index] [--fastq /path/to/fastq] [--threads threads] --workdir /output/directory" << endl ;
cerr << "\t\tOptional arguments: " << endl ;
cerr << "\t\t\t--workdir create output files in this directory (default:.)" << endl;
cerr << "\t\t\t--overlap -1/0 run the exact algorithm (-1) or the relaxed one (0) (default:0)" << endl;
cerr << "\t\t\t-t, --threads number of threads (default:4)" << endl;
// cerr << "\t\t\t--aggregate aggregate ouputs directly." << endl ;
// cerr << "\t\t\t--cutoff sets cutoff for minimum string abundance (tau)" << endl ;
cerr << "\tTo convert SFS to fastq (print to stdout):" << endl ;
cerr << "\t\tPingPong convert [--workdir /output/directory] --batches n" << endl ;
cerr << "\t\tOptional arguments: " << endl ;
cerr << "\t\t\t--workdir create output files in this directory (default:.)" << endl;
// cerr << "\tTo aggregate specfic strings:" << endl ;
// cerr << "\t\tPingPong aggregate --workdir /path/to/string/batches --threads <threads> --cutoff <minimum abundance for strings> --batches <number of output batches>" << endl ;
}
int main(int argc, char** argv) {
cerr << "Ping-pong, comparative genome analysis using sample-specific string detection in accurate long reads." << endl ;
auto c = Configuration::getInstance() ;
if (argc == 1) {
print_help() ;
exit(0) ;
}
#ifdef LOCAL_BUILD
if (strcmp(argv[1], "find") == 0) {
c->parse(argc - 1, argv + 1) ;
create_workdir() ;
auto finder = new Finder() ;
finder->run() ;
exit(0) ;
}
if (strcmp(argv[1], "kmer") == 0) {
c->parse(argc - 1, argv + 1) ;
create_workdir() ;
auto finder = new KmerFinder() ;
finder->run() ;
exit(0) ;
}
if (strcmp(argv[1], "extract") == 0) {
c->parse(argc - 1, argv + 1) ;
create_workdir() ;
auto extractor = new Extractor() ;
extractor->run() ;
exit(0) ;
}
if (strcmp(argv[1], "haplotype-shifter") == 0) {
c->parse(argc - 1, argv + 1) ;
auto shifter = new HaplotypeShifter() ;
shifter->load_tracks() ;
exit(0) ;
}
if (strcmp(argv[1], "shift-bed") == 0) {
c->parse(argc - 1, argv + 1) ;
auto shifter = new HaplotypeShifter() ;
shifter->shift_bed_file() ;
exit(0) ;
}
#endif
if (strcmp(argv[1], "index") == 0) {
c->parse(argc - 1, argv + 1) ;
create_workdir() ;
auto pingpong = new PingPong() ;
pingpong->index() ;
}
else if (strcmp(argv[1], "query") == 0) {
c->parse(argc - 2, argv + 2) ;
auto pingpong = new PingPong() ;
bool b = pingpong->query(string(argv[2])) ;
cerr << (b ? "SFS" : "Not SFS") << endl ;
}
else if (strcmp(argv[1], "search") == 0) {
c->parse(argc - 1, argv + 1) ;
create_workdir() ;
auto pingpong = new PingPong() ;
pingpong->search() ;
if (c->aggregate) {
auto aggregator = new Aggregator() ;
c->aggregate_batches = pingpong->num_output_batches ;
aggregator->run() ;
}
}
else if (strcmp(argv[1], "correct") == 0) {
c->parse(argc - 1, argv + 1) ;
create_workdir() ;
auto snp_corrector = new SnpCorrector() ;
snp_corrector->run() ;
}
else if (strcmp(argv[1], "aggregate") == 0) {
c->parse(argc - 1, argv + 1) ;
create_workdir() ;
auto aggregator = new Aggregator() ;
aggregator->run() ;
}
else if (strcmp(argv[1], "convert") == 0) {
c->parse(argc - 1, argv + 1) ;
// create_workdir() ;
auto converter = new Converter() ;
converter->run() ;
} else {
print_help() ;
}
}