-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutations_T_json.cu
216 lines (168 loc) · 6.95 KB
/
mutations_T_json.cu
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
#include "mutations_T_json.cuh"
mutations_T_json::mutations_T_json(string parameter_Master_Location)
{
cout << "Intializing conversion to JSON format\n";
parameter_load Parameters = parameter_load();
functions_library function = functions_library();
//exit(-1);
vector<string> parameters_List = {
"\"Convert file location\"",
"\"Output folders\""};
vector<string> found_Parameters = Parameters.get_parameters(parameter_Master_Location, parameters_List);
site_model_Location = Parameters.get_STRING(found_Parameters[0]);
output_Folder = Parameters.get_STRING(found_Parameters[1]);
function.config_Folder(output_Folder, "Output");
}
void mutations_T_json::recombinations_Convert()
{
cout << "\nReading recombination file: " << site_model_Location << endl;
functions_library functions = functions_library();
string file_Name = filesystem::path(site_model_Location).filename().stem().string();
string output_File_Location = output_Folder + "/" + file_Name + ".json";
cout << "Writing recombination JSON file to: " << output_File_Location << endl;
fstream site_model_File;
site_model_File.open(site_model_Location, ios::in);
if (site_model_File.is_open())
{
string line;
getline(site_model_File, line);
vector<string> line_Data;
char delim = '\t';
functions.split(line_Data, line, delim);
if (line_Data.size() == 1)
{
delim = ',';
functions.split(line_Data, line, delim);
}
if (line_Data.size() == 5)
{
fstream json_File;
json_File.open(output_File_Location, ios::out);
json_File << " \"Recombination\":{\n\n";
vector<string> write_Lines;
cout << "Configuring lines\n";
while (getline(site_model_File, line))
{
functions.split(line_Data, line, delim);
string write_Line = " \"Hotspot " + line_Data[0] + "\":{\n\n" + " \"Region\":\"" + line_Data[1] + "_" + line_Data[2] + "\",\n\n";
write_Line = write_Line + " \"Reference probability of recombination\":\"" + line_Data[3] + "\",\n";
write_Line = write_Line + " \"Reference selectivity\":\"" + line_Data[4] + "\"\n";
write_Line = write_Line + " },\n\n";
write_Lines.push_back(write_Line);
}
cout << "Writing lines\n";
json_File << " \"Number of hotspots\":" << write_Lines.size() << ",\n\n";
for (int line = 0; line < write_Lines.size(); line++)
{
json_File << write_Lines[line];
}
json_File << " },\n";
json_File.close();
}
else
{
cout << "ERROR: RECOMBINATION FILE DOES NOT HAVE THE CORRECT NUMBER OF COLUMNS\n\n";
exit(-1);
}
site_model_File.close();
}
}
void mutations_T_json::mutations_Convert()
{
cout << "\nReading site model file: " << site_model_Location << endl;
functions_library functions = functions_library();
string file_Name = filesystem::path(site_model_Location).filename().stem().string();
string output_File_Location = output_Folder + "/" + file_Name + ".json";
cout << "Writing site model JSON file to: " << output_File_Location << endl;
// exit(-1);
fstream site_model_File;
site_model_File.open(site_model_Location, ios::in);
if (site_model_File.is_open())
{
string line;
getline(site_model_File, line);
vector<string> line_Data;
char delim = '\t';
functions.split(line_Data, line, delim);
if (line_Data.size() == 1)
{
delim = ',';
functions.split(line_Data, line, delim);
}
if (line_Data.size() == 24)
{
vector<string> base_mutations;
cout << "\nCollecting base change headers\n\n";
for (int col = 8; col < line_Data.size(); col++)
{
base_mutations.push_back(line_Data[col]);
}
fstream json_File;
json_File.open(output_File_Location, ios::out);
json_File << " \"Mutations\":{\n\n";
vector<string> write_Lines;
cout << "Configuring lines\n";
while (getline(site_model_File, line))
{
functions.split(line_Data, line, delim);
string write_Line = " \"Hotspot " + line_Data[0] + "\":{\n\n" + " \"Region\":\"" + line_Data[1] + "_" + line_Data[2] + "\",\n\n";
write_Line = write_Line + " \"Clock model\":\"" + line_Data[3] + "\",\n";
if (functions.to_Upper_Case(line_Data[3]) == "POISSON")
{
write_Line = write_Line + " \"Clock model Poisson mean\":\"" + line_Data[4] + "\",\n";
}
else if (functions.to_Upper_Case(line_Data[3]) == "NEGATIVE_BINOMIAL")
{
write_Line = write_Line + " \"Clock model Negative Binomial sucesses\":\"" + line_Data[5] + "\",\n";
write_Line = write_Line + " \"Clock model Negative Binomial probability\":\"" + line_Data[6] + "\",\n";
}
else
{
write_Line = write_Line + " \"Clock model Fixed probability\":\"" + line_Data[7] + "\",\n";
}
write_Line = write_Line + "\n";
int base_pair = 0;
for (int col = 8; col < line_Data.size(); col++)
{
write_Line = write_Line + " \"" + base_mutations[base_pair] + "\":\"" + line_Data[col];
if (col != line_Data.size() - 1)
{
write_Line = write_Line + "\",\n";
}
else
{
write_Line = write_Line + "\"\n";
}
base_pair++;
}
write_Line = write_Line + " },\n\n";
write_Lines.push_back(write_Line);
}
cout << "Writing lines\n";
json_File << " \"Number of hotspots\":" << write_Lines.size() << ",\n\n";
for (int line = 0; line < write_Lines.size(); line++)
{
json_File << write_Lines[line];
}
json_File << " },\n";
json_File.close();
}
else
{
cout << "ERROR: BASE SITE MODEL FILE DOES NOT HAVE THE CORRECT NUMBER OF COLUMNS\n\n";
exit(-1);
}
site_model_File.close();
}
}
void mutations_T_json::ingress(string convert_Type)
{
if (convert_Type == "mutations")
{
mutations_Convert();
}
else
{
recombinations_Convert();
}
}