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
// ==========================================================================
// Copyright (c) 2006-2018, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Knut Reinert or the FU Berlin nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: Andreas Gogol-Doering <andreas.doering@mdc-berlin.de>
// ==========================================================================
// AlignCols is a wrapper around Align that allows the virtual access to the
// rows of an alignment.
// ==========================================================================
#ifndef SEQAN_INCLUDE_SEQAN_ALIGN_ALIGN_COLS_H_
#define SEQAN_INCLUDE_SEQAN_ALIGN_ALIGN_COLS_H_
namespace seqan {
// ============================================================================
// Forwards
// ============================================================================
// ============================================================================
// Tags, Classes, Enums
// ============================================================================
// ----------------------------------------------------------------------------
// Class AlignCols
// ----------------------------------------------------------------------------
/*!
* @class AlignCols
* @implements EqualityComparableConcept
* @implements RandomAccessContainerConcept
* @headerfile <seqan/align.h>
* @brief Pseudo columns container for row-based Align class.
*
* @signature template <typename TAlign>
* class AlignCols<TAlign>;
*
* @tparam TAlign The Align type.
*/
template <typename TAlign>
struct AlignCols
{
// TODO(holtgrew): Do we need this mutable?
mutable TAlign * data_align;
AlignCols() :
data_align(0)
{}
AlignCols(TAlign & align) : data_align(&align)
{}
template <typename TPosition>
inline typename Value<AlignCols>::Type
operator[](TPosition _pos)
{
return value(*this, _pos);
}
template <typename TPosition>
inline typename Value<AlignCols const>::Type
operator[](TPosition _pos) const
{
return value(*this, _pos);
}
};
// ----------------------------------------------------------------------------
// Specialization AlignCols
// ----------------------------------------------------------------------------
template <typename TSpec>
struct AlignColIterator;
// ============================================================================
// Metafunctions
// ============================================================================
// ----------------------------------------------------------------------------
// Metafunction Host
// ----------------------------------------------------------------------------
// TODO(holtgrew): Add HostedTypeConcept and make AlignCols object implement the concept.
template <typename TAlign>
struct Host<AlignCols<TAlign> >
{
typedef TAlign Type;
};
template <typename TAlign>
struct Host<AlignCols<TAlign> const>
{
typedef TAlign Type;
};
// ----------------------------------------------------------------------------
// Metafunction AlignColIterator
// ----------------------------------------------------------------------------
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;
};
// ----------------------------------------------------------------------------
// Metafunction Value
// ----------------------------------------------------------------------------
// Iterator is also used as Value
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
// ----------------------------------------------------------------------------
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
// ----------------------------------------------------------------------------
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()
// ----------------------------------------------------------------------------
template <typename TAlign>
inline typename Host<AlignCols<TAlign> >::Type &
host(AlignCols<TAlign> & me)
{
SEQAN_ASSERT(me.data_align != 0);
return *me.data_align;
}
template <typename TAlign>
inline typename Host<AlignCols<TAlign> const>::Type &
host(AlignCols<TAlign> const & me)
{
SEQAN_ASSERT(me.data_align != 0);
return *me.data_align;
}
// ----------------------------------------------------------------------------
// Function iter()
// ----------------------------------------------------------------------------
/*!
* @fn AlignCols#iter
* @headerfile <seqan/align.h>
* @brief Iterator to the item at the given position in the alignment columns.
*
* @signature TIterator iter(cols, pos[, tag]);
*
* @param[in] cols The AlignCols object to get the iterator for.
* @param[in] pos The position to get the iterator for.
* @param[in] tag The tag to pick the type of the iterator.
*
* @return TIterator The resulting iterator. If <tt>TTag</tt> is the type of <tt>tag</tt> and <tt>TAlignCols</tt> the
* type of <tt>cols</tt> then TIterator is of the type <tt>Iterator<TAlignCols,
* TTag>::Type</tt>.
*
* @section Remarks
*
* If <tt>pos</tt> is out of range then the iterator is invalid.
*/
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)
{
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)
{
return typename Iterator<AlignCols<TAlign> const, Tag<TTag> const>::Type(host(me), pos_);
}
// ----------------------------------------------------------------------------
// Function value()
// ----------------------------------------------------------------------------
/*!
* @fn AlignCols#value
* @headerfile <seqan/align.h>
* @brief Returns AlignCols value at a position.
*
* @signature TColumn value(alignCols, pos);
*
* @return TColumn The column, as determined by Value metafunction.
*/
template <typename TAlign, typename TPosition>
inline typename Value<AlignCols<TAlign> >::Type
value(AlignCols<TAlign> & me,
TPosition _pos)
{
return iter(me, _pos);
}
template <typename TAlign, typename TPosition>
inline typename Value<AlignCols<TAlign> const>::Type
value(AlignCols<TAlign> const & me,
TPosition _pos)
{
return iter(me, _pos);
}
// ----------------------------------------------------------------------------
// Function beginPosition()
// ----------------------------------------------------------------------------
template <typename TAlignCols>
inline typename Position<TAlignCols>::Type
_beginPositionAlignCols(TAlignCols const & me)
{
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)
{
return _beginPositionAlignCols(me);
}
template <typename TAlign>
inline typename Position<AlignCols<TAlign> >::Type
beginPosition(AlignCols<TAlign> & me)
{
return _beginPositionAlignCols(me);
}
// ----------------------------------------------------------------------------
// Function begin()
// ----------------------------------------------------------------------------
template <typename TAlign, typename TTag>
inline typename Iterator<AlignCols<TAlign>, Tag<TTag> const>::Type
begin(AlignCols<TAlign> & me,
Tag<TTag> const tag_)
{
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_)
{
return iter(me, beginPosition(me), tag_);
}
// ----------------------------------------------------------------------------
// Function endPosition()
// ----------------------------------------------------------------------------
template <typename TAlignCols>
inline typename Position<TAlignCols>::Type
_endPositionAlignCols(TAlignCols const & me)
{
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)
{
return _endPositionAlignCols(me);
}
template <typename TAlign>
inline typename Position<AlignCols<TAlign> const>::Type
endPosition(AlignCols<TAlign> const & me)
{
return _endPositionAlignCols(me);
}
// ----------------------------------------------------------------------------
// Function end()
// ----------------------------------------------------------------------------
template <typename TAlign, typename TTag>
inline typename Iterator<AlignCols<TAlign>, Tag<TTag> const>::Type
end(AlignCols<TAlign> & me,
Tag<TTag> const tag_)
{
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_)
{
return iter(me, endPosition(me), tag_);
}
// ----------------------------------------------------------------------------
// Function length()
// ----------------------------------------------------------------------------
template <typename TAlign>
inline typename Size<AlignCols<TAlign> >::Type
length(AlignCols<TAlign> const & me)
{
return endPosition(me) - beginPosition(me);
}
// ----------------------------------------------------------------------------
// Function operator==()
// ----------------------------------------------------------------------------
template <typename TAlign>
inline bool
operator==(AlignCols<TAlign> const & left,
AlignCols<TAlign> const & right)
{
return left.data_align == right.data_align;
}
} // namespace seqan
#endif // #ifndef SEQAN_INCLUDE_SEQAN_ALIGN_ALIGN_COLS_H_
|