-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.cpp
More file actions
299 lines (272 loc) · 7.99 KB
/
Copy pathutil.cpp
File metadata and controls
299 lines (272 loc) · 7.99 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
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#include "util.h"
char ntoc ( Nucleotide base )
{
char ret ='N';
switch ( base )
{
case BASE_A:
ret = 'A';
break;
case BASE_$:
ret = '$';
break;
case BASE_C:
ret = 'C';
break;
case BASE_G:
ret = 'G';
break;
case BASE_T:
ret = 'T';
break;
case BASE_N:
ret = 'N';
break;
case BASE_Z:
ret = 'Z';
break;
default:
std::cerr << "ERROR: Can't convert Nucleotide int( "
<< base << " ) to char. Aborting." << std::endl;
std::exit( -1 );
}
return ret;
}
Nucleotide cton ( char c )
{
Nucleotide ret = ALPHABET_SIZE;
switch ( c )
{
case '$':
ret = BASE_$;
break;
case 'A':
ret = BASE_A;
break;
case 'C':
ret = BASE_C;
break;
case 'G':
ret = BASE_G;
break;
case 'T':
ret = BASE_T;
break;
case 'N':
ret = BASE_N;
break;
case 'Z':
ret = BASE_Z;
break;
default:
#ifndef DEBUG
std::cerr << "ERROR: Received char '" << c << "' "
<< " int( " << int(c) << " ). Which base is it?"
<< std::endl;
#endif
break;
}
return ret;
}
void checkIfIrreducible( SGraph& s, Precedencies& p, GSAEntry* prefixI, GSAEntry* suffixI, EdgeLength& len )
{
// Check if the edge beetween suffixI->numSeq and prefixI->numSeq is the best
// found until now with length len
if( s.find( suffixI->numSeq ) == s.end( ) )
{
// Add
SGEdge* e = new SGEdge( );
e->first_read = suffixI->numSeq;
e->second_read = prefixI->numSeq;
e->len = len;
s.insert( std::pair< unsigned int, SGEdge* >( e->first_read, e ) );
if( p.find( prefixI->numSeq ) != p.end( ) )
p.find( prefixI->numSeq )->second.push_back( suffixI->numSeq );
else
{
vector< unsigned int > v;
v.push_back( suffixI->numSeq );
p.insert( std::pair< unsigned int, vector< unsigned int > >( prefixI->numSeq,
v ) );
}
}
else
{
SGEdge* e1 = (* (s.find( suffixI->numSeq ))).second;
if( e1->len > len )
{
e1->len = len;
e1->first_read = suffixI->numSeq;
e1->second_read = prefixI->numSeq;
if( p.find( prefixI->numSeq ) != p.end( ) )
p.find( prefixI->numSeq )->second.push_back( suffixI->numSeq );
else
{
vector< unsigned int > v;
v.push_back( suffixI->numSeq );
p.insert( std::pair< unsigned int, vector< unsigned int > >( prefixI->numSeq,
v ) );
}
}
}
}
ofstream& operator<<( ofstream& out, const EdgeInterval& edgeint )
{
// First we store the _extendI interval
BWTPosition begin = edgeint._extendI.get_begin( );
out.write( (char *) &begin, sizeof( BWTPosition ) );
BWTPosition end = edgeint._extendI.get_end( );
out.write( (char *) &end, sizeof( BWTPosition ) );
// Then we write the length of _suffixI (that should be the same as _len)
unsigned int num_of_suffix = edgeint._suffixI.size( );
out.write( (char *) &num_of_suffix, sizeof( unsigned int ) );
// Then, for each interval in _suffixI and for each length in _len we store
// the interval and the related length.
for( unsigned int i( 0 ); i < edgeint._suffixI.size( ); ++i )
{
begin = edgeint._suffixI[ i ]->get_begin( );
end = edgeint._suffixI[ i ]->get_end( );
EdgeLength length = edgeint._len[ i ];
if( begin != end )
{
out.write( (char *) &begin, sizeof( BWTPosition ) );
out.write( (char *) &end, sizeof( BWTPosition ) );
out.write( (char *) &length, sizeof( EdgeLength ) );
}
}
out.flush( );
return out;
}
ifstream& operator>>( ifstream& in, EdgeInterval* edgeint )
{
// First we read the _extendI interval
BWTPosition extend_b =0;
in.read( (char *) &extend_b, sizeof( BWTPosition ) );
BWTPosition extend_e =0;
in.read( (char *) &extend_e, sizeof( BWTPosition ) );
// Then we read the number of intervals in _suffixI (an unsigned long)
unsigned int length =0;
in.read( (char *) &length, sizeof( unsigned int ) );
// We read the first _suffixI (we are sure that at least ONE interval is in
// _suffixI)
BWTPosition suffix_b =0;
in.read( (char *) &suffix_b, sizeof( BWTPosition ) );
BWTPosition suffix_e =0;
in.read( (char *) &suffix_e, sizeof( BWTPosition ) );
EdgeLength suffix_len =0;
in.read( (char *) &suffix_len, sizeof( EdgeLength ) );
if( extend_b != extend_e )
{
// Then we create the edgeinterval
edgeint = new EdgeInterval( extend_b, extend_e, suffix_b, suffix_e, suffix_len );
// Finally, we read all the remaining intervals in _suffixI (if needed)
for( unsigned long i( 1 ); i < length; ++i )
{
in.read( (char *) &suffix_b, sizeof( BWTPosition ) );
in.read( (char *) &suffix_e, sizeof( BWTPosition ) );
in.read( (char *) &suffix_len, sizeof( EdgeLength ) );
if( suffix_e > suffix_b )
{
QInterval temp( suffix_b, suffix_e );
edgeint->add_suffix_interval( &temp, suffix_len );
}
}
}
else
{
edgeint = NULL;
}
return in;
}
ifstream& operator>>( ifstream& in, EdgeInterval** edgeint )
{
// First we read the _extendI interval
BWTPosition extend_b =0;
in.read( (char *) &extend_b, sizeof( BWTPosition ) );
BWTPosition extend_e =0;
in.read( (char *) &extend_e, sizeof( BWTPosition ) );
// Then we read the number of intervals in _suffixI (an unsigned long)
unsigned int length =0;
in.read( (char *) &length, sizeof( unsigned int ) );
// We read the first _suffixI (we are sure that at least ONE interval is in
// _suffixI)
BWTPosition suffix_b =0;
in.read( (char *) &suffix_b, sizeof( BWTPosition ) );
BWTPosition suffix_e =0;
in.read( (char *) &suffix_e, sizeof( BWTPosition ) );
EdgeLength suffix_len =0;
in.read( (char *) &suffix_len, sizeof( EdgeLength ) );
if( extend_b != extend_e )
{
// Then we create the edgeinterval
(*edgeint) = new EdgeInterval( extend_b, extend_e, suffix_b, suffix_e, suffix_len );
// Finally, we read all the remaining intervals in _suffixI (if needed)
for( unsigned long i( 1 ); i < length; ++i )
{
in.read( (char *) &suffix_b, sizeof( BWTPosition ) );
in.read( (char *) &suffix_e, sizeof( BWTPosition ) );
in.read( (char *) &suffix_len, sizeof( EdgeLength ) );
if( suffix_e > suffix_b )
{
QInterval temp( suffix_b, suffix_e );
(*edgeint)->add_suffix_interval( &temp, suffix_len );
}
}
}
else
{
edgeint = NULL;
}
return in;
}
ofstream& operator<<( ofstream& out, const JoinedQInterval& jint )
{
// First we store the _int interval
BWTPosition begin = jint._int.get_begin( );
BWTPosition end = jint._int.get_end( );
out.write( (char *) &begin, sizeof( BWTPosition ) );
out.write( (char *) &end, sizeof( BWTPosition ) );
// Then we write the _revint interval
begin = jint._revint.get_begin( );
end = jint._revint.get_end( );
out.write( (char *) &begin, sizeof( BWTPosition ) );
out.write( (char *) &end, sizeof( BWTPosition ) );
out.flush( );
return out;
}
ifstream& operator>>( ifstream& in, JoinedQInterval** jint )
{
// Read the 4 positions ( _int.begin, _int.end, _revint.begin, _revint.end )
BWTPosition ibegin=0, iend=0, rbegin=0, rend=0;
in.read( (char *) &ibegin, sizeof( BWTPosition ) );
in.read( (char *) &iend, sizeof( BWTPosition ) );
in.read( (char *) &rbegin, sizeof( BWTPosition ) );
in.read( (char *) &rend, sizeof( BWTPosition ) );
if( ibegin != iend )
{
*jint = new JoinedQInterval( ibegin, iend, rbegin, rend );
}
else
*jint = NULL;
return in;
}
ofstream& operator<<( ofstream& out, const QInterval& i )
{
BWTPosition begin = i.get_begin( );
BWTPosition end = i.get_end( );
out.write( (char *) &begin, sizeof( BWTPosition ) );
out.write( (char *) &end, sizeof( BWTPosition ) );
out.flush( );
return out;
}
ifstream& operator>>( ifstream& in, QInterval** i )
{
BWTPosition begin=0, end=0;
in.read( (char *) &begin, sizeof( BWTPosition ) );
in.read( (char *) &end, sizeof( BWTPosition ) );
if( begin != end )
*i = new QInterval( begin, end );
else
*i = NULL;
return in;
}