[go: up one dir, main page]

File: align_cols_base.h

package info (click to toggle)
seqan 1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 21,368 kB
  • ctags: 17,376
  • sloc: cpp: 81,339; ansic: 58,225; makefile: 96; sh: 14
file content (429 lines) | stat: -rw-r--r-- 11,757 bytes parent folder | download
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
 /*==========================================================================
                SeqAn - The Library for Sequence Analysis
                          http://www.seqan.de 
 ============================================================================
  Copyright (C) 2007

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 3 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.

 ============================================================================
  $Id: align_cols_base.h 1769 2008-03-12 08:51:24Z doering@PCPOOL.MI.FU-BERLIN.DE $
 ==========================================================================*/

#ifndef SEQAN_HEADER_ALIGN_COLS_BASE_H
#define SEQAN_HEADER_ALIGN_COLS_BASE_H

namespace SEQAN_NAMESPACE_MAIN
{
//////////////////////////////////////////////////////////////////////////////
// Align Cols
//////////////////////////////////////////////////////////////////////////////
//implements Cols sequence for align implementations

/**
.Class.AlignCols:
..cat:Alignments
..summary:Pseudo columns container for row-based alignment classes.
..signature:AlignCols<TAlign>
..param.TAlign:Alignment type.
...metafunction:Metafunction.Host
..remarks:This class emulates a container of columns on alignment classes
  that store the alignment in a container of rows.
  Note that accessing a row-based alignment column-wise can be significantly
  slower than accessing the alignment row-wise.
..see:Class.Align
*/

template <typename TAlign>
struct AlignCols
{
//____________________________________________________________________________
	mutable TAlign * data_align;

	AlignCols():
		data_align(0)
	{
SEQAN_CHECKPOINT
	}

	AlignCols(AlignCols const & other):
		data_align(other.data_align)
	{
SEQAN_CHECKPOINT
	}

	AlignCols(TAlign & ali):
		data_align(& ali)
	{
SEQAN_CHECKPOINT
	}

	~AlignCols() 
	{
SEQAN_CHECKPOINT
	}

	AlignCols const & operator = (AlignCols const & other)
	{
SEQAN_CHECKPOINT
		data_align = other.data_align;
		return *this;
	}
//____________________________________________________________________________

	template <typename TPosition>
	inline typename Value<AlignCols>::Type
	operator [](TPosition _pos)
	{
SEQAN_CHECKPOINT
		return value(*this, _pos);
	}

	template <typename TPosition>
	inline typename Value<AlignCols const>::Type
	operator [](TPosition _pos) const
	{
SEQAN_CHECKPOINT
		return value(*this, _pos);
	}
//____________________________________________________________________________
};


//////////////////////////////////////////////////////////////////////////////

///.Metafunction.Cols.param.T.type:Class.Align

template <typename TSource, typename TSpec>
struct Cols<Align<TSource, TSpec> >
{
	typedef AlignCols<Align<TSource, TSpec> > Type;
};
template <typename TSource, typename TSpec>
struct Cols<Align<TSource, TSpec> const>
{
	typedef AlignCols<Align<TSource, TSpec> const> Type;
};

//////////////////////////////////////////////////////////////////////////////
// Metafunctions for AlignCols
//////////////////////////////////////////////////////////////////////////////

///.Metafunction.Host.param.T.type:Class.AlignCols

template <typename TAlign>
struct Host<AlignCols<TAlign> >
{
	typedef TAlign Type;
};
template <typename TAlign>
struct Host<AlignCols<TAlign> const>
{
	typedef TAlign Type;
};

//////////////////////////////////////////////////////////////////////////////
/**
.Spec.AlignColIterator:
..cat:Iterators
..summary:Iterator for @Class.AlignCols@ pseudo container.
..signature:Iter< TAlign, AlignColIterator<TSpec> >
..param.TSpec:Specialization tag.
..general:Class.Iter
..see:Class.AlignCols
*/


template <typename TSpec>
struct AlignColIterator;

///.Metafunction.Iterator.param.T.type:Class.AlignCols

template <typename TAlign, typename TIteratorSpec>
struct Iterator<AlignCols<TAlign>, TIteratorSpec>
{
	typedef Iter< TAlign, AlignColIterator<void> > Type;
};
template <typename TAlign, typename TIteratorSpec>
struct Iterator<AlignCols<TAlign> const, TIteratorSpec>
{
	typedef Iter< TAlign, AlignColIterator<void> > Type;
};

//////////////////////////////////////////////////////////////////////////////
// Iterator is also used as Value

///.Metafunction.Value.param.T.type:Class.AlignCols

template <typename TAlign>
struct Value<AlignCols<TAlign> >:
	Iterator<AlignCols<TAlign>, Standard >
{
};
template <typename TAlign>
struct Value<AlignCols<TAlign> const>:
	Iterator<AlignCols<TAlign> const, Standard>
{
};

//////////////////////////////////////////////////////////////////////////////

///.Metafunction.Size.param.T.type:Class.AlignCols

template <typename TAlign>
struct Size<AlignCols<TAlign> >:
	Size<typename Row<TAlign>::Type>
{
};
template <typename TAlign>
struct Size<AlignCols<TAlign> const>:
	Size<typename Row<TAlign const>::Type>
{
};

//////////////////////////////////////////////////////////////////////////////

///.Metafunction.Position.param.T.type:Class.AlignCols

template <typename TAlign>
struct Position<AlignCols<TAlign> >:
	Position<typename Row<TAlign>::Type>
{
};
template <typename TAlign>
struct Position<AlignCols<TAlign> const>:
	Position<typename Row<TAlign const>::Type>
{
};

//////////////////////////////////////////////////////////////////////////////
// Functions
//////////////////////////////////////////////////////////////////////////////

///.Function.host.param.object.type:Class.AlignCols

template <typename TAlign>
inline typename Host<AlignCols<TAlign> >::Type &
host(AlignCols<TAlign> & me)
{
SEQAN_CHECKPOINT
	SEQAN_ASSERT(me.data_align)
	return *me.data_align; 
}
template <typename TAlign>
inline typename Host<AlignCols<TAlign> const>::Type &
host(AlignCols<TAlign> const & me)
{
SEQAN_CHECKPOINT
	SEQAN_ASSERT(me.data_align)
	return *me.data_align; 
}

//////////////////////////////////////////////////////////////////////////////

///.Function.iter.param.object.type:Class.AlignCols

template <typename TAlign, typename TPosition, typename TTag>
inline typename Iterator<AlignCols<TAlign>, Tag<TTag> const>::Type
iter(AlignCols<TAlign> & me,
	 TPosition pos_,
	 Tag<TTag> const)
{
SEQAN_CHECKPOINT
	return typename Iterator<AlignCols<TAlign>, Tag<TTag> const >::Type(host(me), pos_); 
}
template <typename TAlign, typename TPosition, typename TTag>
inline typename Iterator<AlignCols<TAlign> const, Tag<TTag> const>::Type
iter(AlignCols<TAlign> const & me,
	 TPosition pos_,
	 Tag<TTag> const)
{
SEQAN_CHECKPOINT
	return typename Iterator<AlignCols<TAlign> const, Tag<TTag> const>::Type(host(me), pos_); 
}

//////////////////////////////////////////////////////////////////////////////

///.Function.value.param.container.type:Class.AlignCols

template <typename TAlign, typename TPosition>
inline typename Value< AlignCols<TAlign> >::Type
value(AlignCols<TAlign> & me,
	  TPosition _pos)
{
SEQAN_CHECKPOINT
	return iter(me, _pos);
}
template <typename TAlign, typename TPosition>
inline typename Value< AlignCols<TAlign> const>::Type
value(AlignCols<TAlign> const & me,
	  TPosition _pos)
{
SEQAN_CHECKPOINT
	return iter(me, _pos);
}

//////////////////////////////////////////////////////////////////////////////

///.Function.beginPosition.param.object.type:Class.AlignCols

template <typename TAlignCols>
inline typename Position<TAlignCols>::Type
beginPosition_AlignCols(TAlignCols const & me)
{
SEQAN_CHECKPOINT
	typedef typename Host<TAlignCols>::Type TAlign;
	typename Position<typename Rows<TAlign>::Type>::Type _i = length(rows(host(me)));

	if (!_i)
	{
		return 0;
	}

	--_i;
	typename Position<TAlignCols>::Type _pos = beginPosition(row(host(me), _i));

	while (_i > 0)
	{
		--_i;
		typename Position<TAlignCols>::Type _pos2 = beginPosition(row(host(me), _i));
		if (_pos2 < _pos)
		{
			_pos = _pos2;
		}
	}
	return _pos;
}

template <typename TAlign>
inline typename Position<AlignCols<TAlign> >::Type
beginPosition(AlignCols<TAlign> const & me)
{
SEQAN_CHECKPOINT
	return beginPosition_AlignCols(me);
}
template <typename TAlign>
inline typename Position<AlignCols<TAlign> >::Type
beginPosition(AlignCols<TAlign> & me)
{
SEQAN_CHECKPOINT
	return beginPosition_AlignCols(me);
}

//////////////////////////////////////////////////////////////////////////////

///.Function.begin.param.object.type:Class.AlignCols

template <typename TAlign, typename TTag>
inline typename Iterator<AlignCols<TAlign>, Tag<TTag> const>::Type
begin(AlignCols<TAlign> & me,
	  Tag<TTag> const tag_)
{
SEQAN_CHECKPOINT
	return iter(me, beginPosition(me), tag_); 
}
template <typename TAlign, typename TTag>
inline typename Iterator<AlignCols<TAlign> const, Tag<TTag> const>::Type
begin(AlignCols<TAlign> const & me,
	  Tag<TTag> const tag_)
{
SEQAN_CHECKPOINT
	return iter(me, beginPosition(me), tag_); 
}

//////////////////////////////////////////////////////////////////////////////

///.Function.endPosition.param.object.type:Class.AlignCols

template <typename TAlignCols>
inline typename Position<TAlignCols>::Type
endPosition_AlignCols(TAlignCols const & me)
{
SEQAN_CHECKPOINT
	typedef typename Host<TAlignCols>::Type TAlign;

	typename Position<typename Rows<TAlign>::Type>::Type _i = length(rows(host(me)));
	typename Position<TAlignCols>::Type _pos = 0;

	while (_i > 0)
	{
		--_i;
		typename Position<TAlignCols>::Type _pos2 = endPosition(row(host(me), _i));
		if (_pos2 > _pos)
		{
			_pos = _pos2;
		}
	}
	return _pos;
}

template <typename TAlign>
inline typename Position<AlignCols<TAlign> >::Type
endPosition(AlignCols<TAlign> & me)
{
SEQAN_CHECKPOINT
	return endPosition_AlignCols(me);
}
template <typename TAlign>
inline typename Position<AlignCols<TAlign> const>::Type
endPosition(AlignCols<TAlign> const & me)
{
SEQAN_CHECKPOINT
	return endPosition_AlignCols(me);
}

//////////////////////////////////////////////////////////////////////////////

///.Function.end.param.object.type:Class.AlignCols

template <typename TAlign, typename TTag>
inline typename Iterator<AlignCols<TAlign>, Tag<TTag> const>::Type
end(AlignCols<TAlign> & me,
	 Tag<TTag> const tag_)
{
SEQAN_CHECKPOINT
	return iter(me, endPosition(me), tag_); 
}
template <typename TAlign, typename TTag>
inline typename Iterator<AlignCols<TAlign> const, Tag<TTag> const>::Type
end(AlignCols<TAlign> const & me,
	 Tag<TTag> const tag_)
{
SEQAN_CHECKPOINT
	return iter(me, endPosition(me), tag_); 
}

//////////////////////////////////////////////////////////////////////////////

template <typename TAlign>
inline typename Size<AlignCols<TAlign> >::Type
length(AlignCols<TAlign> const & me)
{
SEQAN_CHECKPOINT
	return endPosition(me) - beginPosition(me);
}

//////////////////////////////////////////////////////////////////////////////

template <typename TAlign>
inline bool
operator ==(AlignCols<TAlign> const & left, 
			AlignCols<TAlign> const & right)
{
SEQAN_CHECKPOINT
	return left.data_align == right.data_align; 
}

//////////////////////////////////////////////////////////////////////////////

}// namespace SEQAN_NAMESPACE_MAIN

#endif //#ifndef SEQAN_HEADER_...