-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenomic_clean.hpp
177 lines (132 loc) · 4.21 KB
/
genomic_clean.hpp
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
#ifndef genomic_clean_h
#define genomic_clean_h
#include <stdexcept>
#include <boost/program_options.hpp>
namespace po = boost::program_options;
#include "typedefs.h"
#include "global.hpp"
#include "SampleSets.hpp"
#include "genomic_common.hpp"
class Clean : public Command {
public:
Clean()
: Command("clean file based on filtering criteria") {
// Delcare options
opts.add_options()
("help", "print help message")
("input,i", po::value<string>(), "sample set file")
("output,o", po::value<string>(), "output file")
("format,f", po::value<string>(), "input file format [default: determined from file extension]")
("inverse,v", po::value<bool>(), "select instead of filter overlapping segments")
("merge,m", po::value<bool>(), "merge filtered segments with upstream/downstream segments?")
("count", po::value<position>(), "threshold for number of markers in segment")
("length", po::value<position>(), "threshold for segment length")
("balanced", po::value<bool>(), "remove balanced segments?")
("state_diff", po::value<rvalue>(), "threshold for difference from reference state")
("ref_state", po::value<rvalue>(), "reference state")
;
popts.add("input", 1).add("output", 1);
}
template <bool> struct segmented {};
template <typename SampleSetType>
void clean(segmented<false>) {
throw logic_error("Cleaning functions for raw CN files have yet been implemented.");
}
template <typename SampleSetType>
void clean(segmented<true>) {
SampleSetType set;
set.read(inputFileName);
set.set(CNACriteria(refState, stateDiff));
if (count > 0) set.filter(spurious_segment_filter<typename SampleSetType::Value>(count), inverse, merge);
if (length > 0) set.filter(small_segment_filter<typename SampleSetType::Value>(length), inverse, merge);
if (balanced) set.filter(balanced_segment_filter<typename SampleSetType::Value>(refState, stateDiff), inverse, false);
set.write(outputFileName);
}
void run() {
if (vm.count("help")) {
cout << "usage: " << progname << " clean [options] <sample set file> <output file>" << endl;
cout << opts << endl;
return;
}
getOptions();
switch (inputType) {
case data::segmented:
clean< SegmentedSampleSet<rvalue> >(segmented<true>());
break;
case data::segmented_ascn:
clean< SegmentedSampleSet<alleles_cn> >(segmented<true>());
break;
case data::raw:
clean< RawSampleSet<rvalue> >(segmented<false>());
break;
case data::raw_ascn:
clean< RawSampleSet<alleles_cn> >(segmented<false>());
break;
}
}
private:
string inputFileName, outputFileName;
data::Type inputType;
float diceThreshold;
bool inverse, merge, balanced;
position count, length;
float stateDiff, refState;
void getOptions() {
if (vm.count("input")) {
inputFileName = vm["input"].as<string>();
} else {
throw invalid_argument("Input file not specified.");
}
if (vm.count("format")) {
inputType = mapping::extension[ vm["format"].as<string>() ];
} else {
inputType = mapping::extension[ name::fileext(inputFileName) ];
}
if (inputType == data::invalid) {
throw invalid_argument("Invalid input format type.");
}
if (vm.count("output")) {
outputFileName = vm["output"].as<string>();
} else {
outputFileName = name::filestem(inputFileName) + ".filtered." + name::fileext(inputFileName);
}
if (vm.count("inverse")) {
inverse = vm["inverse"].as<bool>();
} else {
inverse = false;
}
if (vm.count("merge")) {
merge = vm["merge"].as<bool>();
} else {
merge = false;
}
if (vm.count("count")) {
count = vm["count"].as<position>();
} else {
count = 0;
}
if (vm.count("length")) {
length = vm["length"].as<position>();
} else {
length = 0;
}
//TODO automatically determine stateDiff and refState
// current settings are suitable for LRR data
if (vm.count("balanced")) {
balanced = vm["balanced"].as<bool>();
} else {
balanced = false;
}
if (vm.count("state_diff")) {
stateDiff = vm["state_diff"].as<float>();
} else {
stateDiff = 0.2;
}
if (vm.count("ref_state")) {
refState = vm["ref_state"].as<float>();
} else {
refState = 0;
}
}
};
#endif