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 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
|
// ==========================================================================
// SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2026, 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>
// ==========================================================================
// Definition of the class Pattern and supporting functions and
// metafunctions.
// ==========================================================================
#ifndef SEQAN_HEADER_FIND_PATTERN_BASE_H
#define SEQAN_HEADER_FIND_PATTERN_BASE_H
//////////////////////////////////////////////////////////////////////////////
namespace seqan2 {
//////////////////////////////////////////////////////////////////////////////
/*!
* @class Pattern
* @headerfile <seqan/find.h>
* @brief Holds the needle and preprocessing data (depends on algorithm).
*
* @signature template <typename TNeedle[, typename TSpec]>
* class Pattern;
*
* @tparam TNeedle The needle type. Types: @link TextConcept @endlink.
* @tparam TSpec A tag that specifies the online algorithm to use for the search. Defaults to the result of
* @link DefaultPattern @endlink.
*
* If <tt>Needle</tt> is a StringSet then <tt>position(pattern)</tt> returns a @link Pair @endlink with the index of the currently
* matching needle and the position in the needle.
*/
template < typename TNeedle, typename TSpec = typename DefaultPattern<TNeedle>::Type >
class Pattern;
//default implementation
template < typename TNeedle >
class Pattern<TNeedle, void>
{
public:
typedef typename Position<TNeedle>::Type TNeedlePosition;
Holder<TNeedle> data_host;
TNeedlePosition data_begin_position;
TNeedlePosition data_end_position;
Pattern() : data_host(), data_begin_position(), data_end_position()
{}
template <typename TNeedle_>
Pattern(TNeedle_ & ndl) : data_host(ndl), data_begin_position(), data_end_position()
{}
template <typename TNeedle_>
Pattern(TNeedle_ const & ndl) : data_host(ndl), data_begin_position(), data_end_position()
{}
};
//////////////////////////////////////////////////////////////////////////////
/*!
* @mfn Pattern#Container
* @brief Returns the needle type of the pattern.
*
* @signature Container<TPattern>::Type;
*
* @tparam TPattern The pattern to query for its needle type.
*
* @return Type The needle type.
*/
template <typename TNeedle, typename TSpec>
struct Container< Pattern<TNeedle, TSpec> > {
typedef TNeedle Type;
};
template <typename TNeedle, typename TSpec>
struct Container< Pattern<TNeedle, TSpec> const > {
typedef TNeedle const Type;
};
/*!
* @mfn Pattern#Host
* @brief Returns the host type of the pattern.
*
* @signature Host<TPattern>::Type;
*
* @tparam TPattern The pattern to query for its host type.
*
* @return Type The host type.
*/
template <typename TNeedle, typename TSpec>
struct Host< Pattern<TNeedle, TSpec> > {
typedef TNeedle Type;
};
template <typename TNeedle, typename TSpec>
struct Host< Pattern<TNeedle, TSpec> const > {
typedef TNeedle const Type;
};
/*!
* @mfn Pattern#Value
* @brief Returns the value type of the underlying pattern.
*
* @signature Value<TPattern>::Type;
*
* @tparam TPattern The Pattern to query.
*
* @return Type The value type.
*/
template <typename TPattern, typename TSpec>
struct Value< Pattern<TPattern, TSpec> > {
typedef typename Value<TPattern>::Type Type;
};
/*!
* @mfn Pattern#Position
* @brief Returns the position type of the underlying pattern.
*
* @signature Position<TPattern>::Type;
*
* @tparam TPattern The Pattern to query.
*
* @return Type The position type.
*/
template <typename TPattern, typename TSpec>
struct Position< Pattern<TPattern, TSpec> > {
typedef typename Position<TPattern>::Type Type;
};
/*!
* @mfn Pattern#Difference
* @brief Returns the difference type of the underlying pattern.
*
* @signature Difference<TPattern>::Type;
*
* @tparam TPattern The Pattern to query.
*
* @return Type The difference type.
*/
template <typename TPattern, typename TSpec>
struct Difference< Pattern<TPattern, TSpec> > {
typedef typename Difference<TPattern>::Type Type;
};
/*!
* @mfn Pattern#Size
* @brief Returns the size type of the underlying pattern.
*
* @signature Size<TPattern>::Type;
*
* @tparam TPattern The Pattern to query.
*
* @return Type The size type.
*/
template <typename TPattern, typename TSpec>
struct Size< Pattern<TPattern, TSpec> > {
typedef typename Size<TPattern>::Type Type;
};
//////////////////////////////////////////////////////////////////////////////
/*!
* @mfn Pattern#ScoringScheme
* @brief Returns the scoring scheme type of an approximate search algorithm.
*
* @signature ScoringScheme<TPattern>::Type;
*
* @tparam TPattern The Pattern to query for its scoring scheme type. Default: EditDistanceScore.
*/
template <typename TNeedle>
struct ScoringScheme
{
typedef EditDistanceScore Type;
};
template <typename TNeedle>
struct ScoringScheme<TNeedle const>:
ScoringScheme<TNeedle>
{
};
//////////////////////////////////////////////////////////////////////////////
template <typename TNeedle, typename TSpec>
inline void
_reinitPattern(Pattern<TNeedle, TSpec> &)
{
// no-op.
}
//////////////////////////////////////////////////////////////////////////////
template <typename TNeedle, typename TSpec>
inline Holder<TNeedle> &
_dataHost(Pattern<TNeedle, TSpec> & me)
{
return me.data_host;
}
template <typename TNeedle, typename TSpec>
inline Holder<TNeedle> const &
_dataHost(Pattern<TNeedle, TSpec> const & me)
{
return me.data_host;
}
//host access: see basic_host.h
template <typename TNeedle, typename TSpec, typename TNeedle2>
inline void
setHost(Pattern<TNeedle, TSpec> & me,
TNeedle2 && ndl)
{
SEQAN_ASSERT(!empty(ndl));
setValue(_dataHost(me), std::forward<TNeedle2>(ndl));
_reinitPattern(me);
}
//////////////////////////////////////////////////////////////////////////////
template <typename TNeedle, typename TSpec>
inline typename Position<Pattern<TNeedle, TSpec> >::Type &
beginPosition(Pattern<TNeedle, TSpec> & me)
{
return me.data_begin_position;
}
template <typename TNeedle, typename TSpec>
inline typename Position<Pattern<TNeedle, TSpec> const >::Type &
beginPosition(Pattern<TNeedle, TSpec> const & me)
{
return me.data_begin_position;
}
template <typename TNeedle, typename TSpec, typename TPosition>
inline void
setBeginPosition(Pattern<TNeedle, TSpec> & me,
TPosition _pos)
{
me.data_begin_position = _pos;
}
//////////////////////////////////////////////////////////////////////////////
template <typename TNeedle, typename TSpec>
inline typename Position<Pattern<TNeedle, TSpec> >::Type &
endPosition(Pattern<TNeedle, TSpec> & me)
{
return me.data_end_position;
}
template <typename TNeedle, typename TSpec>
inline typename Position<Pattern<TNeedle, TSpec> const >::Type &
endPosition(Pattern<TNeedle, TSpec> const & me)
{
return me.data_end_position;
}
template <typename TNeedle, typename TSpec, typename TPosition>
inline void
setEndPosition(Pattern<TNeedle, TSpec> & me,
TPosition _pos)
{
me.data_end_position = _pos;
}
//////////////////////////////////////////////////////////////////////////////
template <typename TNeedle, typename TSpec>
inline typename Infix<TNeedle>::Type
segment(Pattern<TNeedle, TSpec> & me)
{
typedef typename Infix<TNeedle>::Type TInfix;
return TInfix(host(me), me.data_begin_position, me.data_end_position);
}
template <typename TNeedle, typename TSpec>
inline typename Infix<TNeedle>::Type
segment(Pattern<TNeedle, TSpec> const & me)
{
typedef typename Infix<TNeedle>::Type TInfix;
return TInfix(host(me), me.data_begin_position, me.data_end_position);
}
//////////////////////////////////////////////////////////////////////////////
/*!
* @fn Pattern#host
* @brief Query a Pattern for its host.
*
* @signature THost host(pattern);
*
* @param[in] pattern The Pattern to query for its host.
*
* @return THost Reference to the host.
*/
template <typename TNeedle, typename TSpec>
inline typename Host<Pattern<TNeedle, TSpec> >::Type &
host(Pattern<TNeedle, TSpec> & me)
{
return value(me.data_host);
}
template <typename TNeedle, typename TSpec>
inline typename Host<Pattern<TNeedle, TSpec> const>::Type &
host(Pattern<TNeedle, TSpec> const & me)
{
return value(me.data_host);
}
//////////////////////////////////////////////////////////////////////////////
/*!
* @fn Pattern#needle
* @brief Returns the needle of a @link Pattern @endlink object (not implemented for some online-algorithms).
*
* @signature TNeedle needle(pattern);
*
* @param[in] pattern The Pattern to query for its needle.
*
* @return TNeedle Reference of the needle object.
*
* TNeedle is the result of the Needle metafunction of TPattern. This is an alias to the function @link Pattern#host @endlink.
*/
template < typename TObject >
inline typename Needle<TObject>::Type &
needle(TObject &obj)
{
return obj;
}
template < typename TObject >
inline typename Needle<TObject const>::Type &
needle(TObject const &obj)
{
return obj;
}
/*!
* @fn Pattern#position
* @brief Return the position of the last match in the pattern.
*
* @signature TPosition position(pattern);
*
* @param[in] pattern The Pattern to query for its position.
*
* @return TPosition The position of the last match in the pattern.
*/
template < typename TNeedle, typename TSpec >
inline typename Needle< Pattern<TNeedle, TSpec> >::Type &
needle(Pattern<TNeedle, TSpec> & obj)
{
return host(obj);
}
template < typename TNeedle, typename TSpec >
inline typename Needle< Pattern<TNeedle, TSpec> const>::Type &
needle(Pattern<TNeedle, TSpec> const & obj)
{
return host(obj);
}
/*!
* @fn Pattern#setNeedle
* @brief Sets the needle of a Pattern object and optionall induces preprocessing.
*
* @signature void setNeedle(pattern, needle);
*
* @param[in,out] pattern The pattern to set the needle for.
* @param[in] needle The needle to set.
*/
template < typename TNeedle, typename TSpec >
inline void
setNeedle(Pattern<TNeedle, TSpec> &obj, TNeedle const &ndl) {
setHost(obj, ndl);
}
//____________________________________________________________________________
/*!
* @fn Pattern#scoringScheme
* @brief The scoring scheme used for finding or aligning.
*
* @signature TScoringScheme scoringScheme(pattern);
*
* @param[in] pattern The Pattern to query for its scoring scheme.
*
* @return TScoringScheme The scoring scheme of the pattern.
*/
template <typename TNeedle, typename TSpec>
inline typename ScoringScheme<Pattern<TNeedle, TSpec> >::Type
scoringScheme(Pattern<TNeedle, TSpec> &)
{
return typename ScoringScheme<Pattern<TNeedle, TSpec> >::Type();
}
template <typename TNeedle, typename TSpec>
inline typename ScoringScheme<Pattern<TNeedle, TSpec> const>::Type
scoringScheme(Pattern<TNeedle, TSpec> const &)
{
return typename ScoringScheme<Pattern<TNeedle, TSpec> const>::Type();
}
//____________________________________________________________________________
/*!
* @fn Pattern#setScoringScheme
* @brief Sets the scoring scheme used for finding or aligning.
*
* @signature void setScoringScheme(pattern, score);
*
* @param[in,out] pattern The pattern to set the scoring scheme for.
* @param[in] score The scoring scheme to set.
*/
template <typename TNeedle, typename TSpec, typename TScore2>
inline void
setScoringScheme(Pattern<TNeedle, TSpec> & /*me*/,
TScore2 & /*score*/)
{
//dummy implementation for compatibility reasons
}
//////////////////////////////////////////////////////////////////////////////
} // namespace seqan2
#endif //#ifndef SEQAN_HEADER_...
|