-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearchmarkcur.cpp
More file actions
180 lines (138 loc) · 4.43 KB
/
Copy pathsearchmarkcur.cpp
File metadata and controls
180 lines (138 loc) · 4.43 KB
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
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include "SuffixTree.h"
#include <fstream>
#include <time.h>
#include "stringify.h"
using namespace std;
class SeedVertex {
public:
SeedVertex(int position_in,int number_in) : position(position_in), number(number_in) {}
int position;
int number;
};
bool consistant_path(vector<vector<int> > &seed_positions,SeedVertex v1,SeedVertex v2,int spacing) {
int seed1_position = seed_positions[v1.position][v1.number];
int seed2_position = seed_positions[v2.position][v2.number];
int seed_distance = (v2.number - v1.number) * spacing;
if(((seed1_position + seed_distance) - seed2_position) < 8) return true;
return false;
}
bool location_finder(vector<vector<int> > seed_positions,size_t location,size_t score,int spacing) {
// this method finds consistant regions in seed_positions
vector<vector<SeedVertex> > paths;
for(size_t n=0;n<seed_positions[0].size();n++) {
vector<SeedVertex> s;
s.push_back(SeedVertex(0,n));
paths.push_back(s);
}
// build seed paths
int current_level = 1;
for(size_t current_level=1;current_level<seed_positions.size();current_level++) {
for(size_t n=0;n<seed_positions[current_level].size();n++) {
bool found=false;
for(size_t i=0;i<paths.size();i++) {
if(consistant_path(seed_positions,paths[i][paths[i].size()-1],SeedVertex(current_level,n),spacing)) {
paths[i].push_back(SeedVertex(n,i));
found=true;
break;
}
}
if(!found) {
vector<SeedVertex> v;
v.push_back(SeedVertex(current_level,n));
paths.push_back(v);
}
}
}
// find the longest path
int max_path_idx=0;
int max_path_len=0;
for(size_t n=0;n<paths.size();n++) {
if(paths[n].size() > max_path_len) { max_path_len = paths[n].size(); max_path_idx = n; }
}
return seed_positions[paths[max_path_idx][0].position][paths[max_path_idx][0].number];
}
vector<char> simulate_read(int read_length,int sub_rate,int ins_rate,int del_rate,SuffixTree &st,size_t &location) {
size_t seq_size = st.s.size();
// extract read_length location from read
size_t position = rand()%(seq_size-read_length);
location = position;
string ss = st.get_substr(position,position+read_length);
// cout << "Read: " << ss << endl;
vector<char> s;
for(size_t n=0;n<ss.size();n++) s.push_back(ss[n]);
// Apply substition errors
for(size_t n=0;n<s.size();n++) {
if(((rand()%1000)/10) < sub_rate) s[n] = stringify(rand()%10)[0];
}
return s;
}
int main(int argc,char ** argv) {
string s = argv[1];
ifstream infile(argv[1]);
SuffixTree st;
size_t seq_size=0;
for(;!infile.eof();) {
char c;
infile.get(c);
st.insert(c);
seq_size++;
}
st.finalise();
cout << "built suffix tree" << endl;
cout << "processing positions" << endl;
st.process_positions();
cout << "processed positions" << endl;
st.dump_stats();
time_t t1,t2;
time(&t1);
for(size_t n=0;n<200000;n++) {
// Simulate read
size_t location;
vector<char> read = simulate_read(100,0.1,0.1,0.1,st,location);
cout << location << endl;
// extract seed sequences
int seed_count=40;
int seed_size =9;
int seed_dist=read.size()/seed_count;
vector<vector<char> > seeds;
for(size_t i=0;i<seed_count;i++) {
vector<char> seed;
for(size_t j=((seed_dist)*i);j<(((seed_dist)*i)+10);j++) {
seed.push_back(read[j]);
}
seeds.push_back(seed);
}
bool debug=false;
// Align seed sequences
vector<vector<int> > seed_positions;
for(size_t i=0;i<seeds.size();i++) {
vector<int> occurs = st.all_occurs(seeds[i],8);
seed_positions.push_back(occurs);
if(debug) {
if(occurs.size() > 8) cout << "- "; else cout << occurs.size() << " ";
}
}
if(debug) cout<< endl;
if(debug) {
for(size_t i=0;i<seed_positions.size();i++) {
if(seed_positions[i].size() > 8) {cout << "-";} else {
for(size_t j=0;j<seed_positions[i].size();j++) {
cout << seed_positions[i][j] << " ";
}
}
cout << endl;
}
}
// Find consistant seeds
//size_t align_location;
//size_t align_location_score;
//location_finder(seed_positions,align_location,align_location_score,seed_dist);
//cout << location << " " << align_location << " " << align_location_score << endl;
}
time(&t2);
cout << "Time: " << t2-t1 << endl;
}