-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.cc
99 lines (75 loc) · 2.41 KB
/
main.cc
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
#include <iostream>
#include <stdint.h>
#include <map>
#include <vector>
#include <string>
#include <sys/stat.h>
#include <boost/program_options.hpp>
#include <api/BamReader.h>
#include "src/io_data/local_bamtools/bamtools_pileup_engine.h"
#include "src/io_data/local_bamtools/bamtools_fasta.h"
#include "boost_input_utils.h"
#include "variant_visitor.h"
using namespace std;
using namespace BamTools;
int main(int argc, char** argv){
boost::program_options::variables_map vm;
BoostUtils::ParseCommandLineInput(argc, argv, vm);
streambuf * buf;
ofstream of;
string out_name = vm["out"].as<string>();
if(out_name == "") {
buf = cout.rdbuf();
}
else {
of.open(out_name);
buf = of.rdbuf();
}
ostream result_stream(buf);
BamReader experiment;
RefVector references;
SamHeader header;
LocalBamToolsUtils::Fasta reference_genome; // BamTools::Fasta
BoostUtils::ExtractInputVariables(vm, experiment, references, header, reference_genome);
ModelParams params = BoostUtils::CreateModelParams(vm);
SampleMap samples = BoostUtils::ParseSamples(vm, header);
LocalBamToolsUtils::PileupEngine pileup;
BamAlignment ali;
VariantVisitor *v = new VariantVisitor(
references,
reference_genome,
&result_stream,
samples,
vm["sample-name"].as< vector<string> >(),
params,
ali,
vm["qual"].as<int>(),
vm["mapping-qual"].as<int>(),
vm["prob"].as<double>()
);
pileup.AddVisitor(v);
if (vm.count("intervals")){
BedFile bed (vm["intervals"].as<string>());
BedInterval region;
while(bed.get_interval(region) == 0){
// new pileup object for each interval
LocalBamToolsUtils::PileupEngine pileup;
v->SetRegion(region);
pileup.AddVisitor(v);
int ref_id = experiment.GetReferenceID(region.chr);
experiment.SetRegion(ref_id, region.start, ref_id, region.end);
while( experiment.GetNextAlignment(ali) ){
pileup.AddAlignment(ali);
}
pileup.Flush();
}
}
else{
while( experiment.GetNextAlignment(ali)){
pileup.AddAlignment(ali);
}
}
pileup.Flush();
delete v;
return 0;
}