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 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
|
// ==========================================================================
// 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: David Weese <david.weese@fu-berlin.de>
// Author: Manuel Holtgrewe <manuel.holtgrewe@fu-berlin.de>
// ==========================================================================
// Concept definitions for alphabets.
// ==========================================================================
// SEQAN_NO_GENERATED_FORWARDS
#ifndef SEQAN_INCLUDE_SEQAN_BASIC_ALPHABET_CONCEPT_H_
#define SEQAN_INCLUDE_SEQAN_BASIC_ALPHABET_CONCEPT_H_
namespace seqan {
// ============================================================================
// Concepts for generic alphabets
// ============================================================================
/*!
* @concept AlphabetConcept
* @extends AssignableConcept
* @extends DefaultConstructibleConcept
* @extends CopyConstructibleConcept
* @headerfile <seqan/basic.h>
* @brief Natural container value.
*
* @signature concept AlphabetConcept;
*
* @section Examples
*
* Valid expressions (<tt>v</tt> is of type <tt>T</tt>):
*
* @code{.cpp}
* unsigned bpv = BitsPerValue<T>::VALUE;
* @endcode
*/
/*!
* @mfn AlphabetConcept#BitsPerValue
* @headerfile <seqan/basic.h>
* @brief Number of bits needed to store a value.
*
* @signature BitsPerValue<T>::VALUE
*
* @tparam T A class.
*
* @return VALUE The number of bits needed to store a value.
*/
// Forwards for Metafunctions and Functions.
template <typename T> struct BitsPerValue;
// minimal requirements for the alphabet of a String class
SEQAN_CONCEPT_REFINE(AlphabetConcept, (TValue), (Assignable)(DefaultConstructible)(CopyConstructible))
{
typedef typename BitsPerValue<TValue>::Type TBitsPerValue;
TValue val, val2;
SEQAN_CONCEPT_USAGE(AlphabetConcept)
{
SEQAN_STATIC_ASSERT_MSG(BitsPerValue<TValue>::VALUE != 0, "Alphabet types must implement the BitsPerValue metafunction with non-zero value.");
// assign must be available as an equivalent to '='
assign(val, val2);
// swap(val, val2);
TBitsPerValue b = BitsPerValue<TValue>::VALUE;
ignoreUnusedVariableWarning(b);
}
};
// ============================================================================
// Concepts For Alphabets From The Mathematics Domain.
// ============================================================================
/*!
* @concept OrderedAlphabetConcept
* @extends AlphabetConcept
* @extends ComparableConcept
* @headerfile <seqan/basic.h>
*
* @brief Totally strict ordered alphabet.
*
* @signature concept OrderedAlphabetConcept;
*/
/*!
* @fn OrderedAlphabetConcept::operator<
* @brief Less-than operator.
*
* @signature bool OrderedAlphabetConcept::operator<(other);
*
* @param[in] other Object of the same type to compare to this.
*
* @return bool True in case of this object being smaller than <tt>other</tt>
*/
/*!
* @mfn OrderedAlphabetConcept#MaxValue
* @headerfile <seqan/basic.h>
* @brief Supremum for a given type.
*
* @signature MaxValue<T>::VALUE
*
* @tparam T An ordered type.
*
* @return VALUE The largest value that <tt>T</tt> can represent.
*
* @see OrderedAlphabetConcept#maxValue
*/
/*!
* @mfn OrderedAlphabetConcept#MinValue
* @headerfile <seqan/basic.h>
* @brief Infimum for a given type.
*
* @signature MinValue<T>::VALUE
*
* @tparam T An ordered type.
*
* @return VALUE The smallest value that <tt>T</tt> can represent.
*
* @see OrderedAlphabetConcept#minValue
*/
/*!
* @fn OrderedAlphabetConcept#supremumValueImpl
* @brief Implements maxValue.
*
* @signature T supremumValueImpl(valuePointerTag);
*
* @param[in] valuePointerTag A pointer that is used as a tag to specify the value type. The pointer needs not to point
* to a valid object, so it is possible to use a null pointer here.
*
* @return T A value <tt>inf</tt> that holds: <tt>inf >= i</tt> for all values <tt>i</tt>.
*
* This function implements OrderedAlphabetConcept#maxValue. It is recommended to use OrderedAlphabetConcept#maxValue
* rather than <tt>supremumValueImpl</tt>.
*
* @section Status
*
* @deprecated Will be removed in favour of MaxValue.
*
* @see OrderedAlphabetConcept#maxValue
*/
/*!
* @fn OrderedAlphabetConcept#maxValue
* @brief Supremum for a given type.
*
* @signature T maxValue<T>();
*
* @tparam T The type to get the max value of.
*
* @return T A value <tt>inf</tt> that holds: <tt>inf >= i</tt> for all values <tt>i</tt> of type <tt>T</tt>.
*
* The function is implemented in supremumValueImpl. Do not specialize <tt>maxValue</tt>, specialize supremumValueImpl
* instead!
*
* @section Status
*
* @deprecated Will be removed in favour of MaxValue.
*
* @see OrderedAlphabetConcept#supremumValueImpl
* @see OrderedAlphabetConcept#minValue
* @see OrderedAlphabetConcept#MaxValue
*/
/*!
* @fn OrderedAlphabetConcept#infimumValueImpl
* @brief Implements minValue.
*
* @signature T infimumValueImpl(valuePointerTag);
*
* @param[in] valuePointerTag A pointer that is used as a tag to specify the value type. The pointer needs not to point
* to a valid object, so it is possible to use a null pointer here.
*
* @return T A value <tt>inf</tt> that holds: <tt>inf <= i</tt> for all values <tt>i</tt>.
*
* This function implements minValue. It is recommended to use minValue rather than <tt>infimumValueImpl</tt>.
*
* @section Status
*
* @deprecated Will be removed in favour of MinValue.
*
* @see OrderedAlphabetConcept#minValue
*/
/*!
* @fn OrderedAlphabetConcept#minValue
* @brief Infimum for a given type.
*
* @signature T minValue<T>();
*
* @tparam T An ordered type.
*
* @return T A value <tt>inf</tt> that holds: <tt>inf <= i</tt> for all values <tt>i</tt> of type <tt>T</tt>.
*
* The function is implemented in infimumValueImpl. Do not specialize <tt>minValue</tt>, specialize infimumValueImpl
* instead!
*
* @section Status
*
* @deprecated Will be removed in favour of MinValue.
*
* @see OrderedAlphabetConcept#infimumValueImpl
* @see OrderedAlphabetConcept#maxValue
* @see OrderedAlphabetConcept#MinValue
*/
// Forwards for Metafunctions and Functions.
template <typename T> struct MinValue;
template <typename T> struct MaxValue;
template <typename T> T minValue();
template <typename T> T minValue(T);
template <typename T> T maxValue();
template <typename T> T maxValue(T);
SEQAN_CONCEPT_REFINE(OrderedAlphabetConcept, (TValue), (AlphabetConcept)(Comparable))
{
TValue val;
SEQAN_CONCEPT_USAGE(OrderedAlphabetConcept)
{
// type consistency checks
// sameType(minValue(val), val); // minValue() is deprecated
// sameType(minValue<TValue>(), val); // minValue() is deprecated
sameType(MinValue<TValue>::VALUE, val);
// sameType(maxValue(val), val); // maxValue() is deprecated
// sameType(maxValue<TValue>(), val); // maxValue() is deprecated
sameType(MaxValue<TValue>::VALUE, val);
// TODO(holtgrew): This does not work in C++98, we need C++11 with constexpr.
// TODO(holtgrew): Do these tests for each alphabet in runtime tests.
// sanity checks
// SEQAN_STATIC_ASSERT_MSG(MinValue<TValue>::VALUE <= MaxValue<TValue>::VALUE, "Minimal alphabet value must be less or equal to the maximal value.");
// TODO(holtgrew): This does not work in C++98, we need C++11 with constexpr, cannot cast non-integral and non-enumeration types at compile time in C++98.
// 0 must be an element of the alphabet, as we want to be able
// to initialize a TValue variable to omit uninitialized warnings.
// SEQAN_STATIC_ASSERT_MSG(MinValue<TValue>::VALUE <= static_cast<TValue>(0), "0 must be convertible to a valid alphabet value.");
// SEQAN_STATIC_ASSERT_MSG(static_cast<TValue>(0) <= MaxValue<TValue>::VALUE, "0 must be convertible to a valid alphabet value.");
}
};
/*!
* @concept FiniteOrderedAlphabetConcept
* @headerfile <seqan/basic.h>
* @extends OrderedAlphabetConcept
* @brief An type that is of finite domain and totally ordered and thus has a minimum and maximum value.
*/
/*!
* @mfn FiniteOrderedAlphabetConcept#ValueSize
* @brief Number of different values a value type object can have.
*
* @signature ValueSize<T>::Type;
* @signature ValueSize<T>::VALUE;
*
* @tparam T A type to query for its value size.
*
* @return VALUE The number of different values a value of type T can have. The type is <tt>Type</tt>.
* @return Type The type of the result <tt>VALUE</tt>.
*
* This function is only defined for integral types like <tt>unsigned</tt>, <tt>int</tt>, or Dna. For floating point
* numbers and the 64 bit types <tt>int64_t</tt> and <tt>uint64_t</tt>, it returns 0 since there is no standard
* compliant way to return the number of values for these types.
*
* Note that you cannot get pointers or references to <tt>ValueSize<T>::VALUE</tt> in your program. You can use
* @link FiniteOrderedAlphabetConcept#valueSize @endlink in your programs without problems, though. When you get
* problems in your tests, use the "unary plus" workaround from the examples section.
*
* @section Examples
*
* The temporary assignment workaround.
*
* @code{.cpp}
* SEQAN_ASSERT_EQ(ValueSize<bool>::VALUE, 2u); // Linker error.
* SEQAN_ASSERT_EQ(+ValueSize<bool>::VALUE, 2u); // OK
* SEQAN_ASSERT_EQ(valueSize<bool>(), 2u); // OK
* @endcode
*/
/*!
* @fn FiniteOrderedAlphabetConcept#ordValue
* @headerfile <seqan/sequence.h>
* @brief Maps an alphabet 1-to-1 to the interval [0..ValueSize).
*
* @signature T ordValue(value);
*
* @param[in] value Arbitrary character value. Types: SimpleType
*
* @return T An unsigned value (result of Size<tt><typeof(value)></tt> between 0 and ValueSize of the type of value.
*
* This function first converts value to its unsigned value type and after that to an <tt>unsigned int</tt>. You can't
* use <tt>(unsigned int)c</tt> for a character <tt>c</tt> as on some systems <tt>char</tt> is signed and a <tt>-1</tt>
* would be mapped to <tt>0xffffffff</tt> instead of <tt>0x000000ff</tt>.
*/
/*!
* @fn FiniteOrderedAlphabetConcept#valueSize
* @brief Returns size of an alphabet.
*
* @signature T1 valueSize<T2>();
*
* @tparam T2 Type to query for value size.
*
* @return T1 Number of values in type <tt>T2</tt>.
*
* @see FiniteOrderedAlphabetConcept#ValueSize
*/
// Forwards for Metafunctions and Functions.
template <typename T> struct ValueSize;
template <typename T> typename ValueSize<T>::Type valueSize();
// Forwards for Metafunctions and Functions.
template <typename TValue> inline typename ValueSize<TValue>::Type ordValue(TValue const & c);
SEQAN_CONCEPT_REFINE(FiniteOrderedAlphabetConcept, (TValue), (OrderedAlphabetConcept))
{
typedef typename ValueSize<TValue>::Type TSize;
TValue val;
TSize size;
SEQAN_CONCEPT_ASSERT((UnsignedIntegerConcept<TSize>));
SEQAN_CONCEPT_USAGE(FiniteOrderedAlphabetConcept)
{
// a finite alphabet must be countable
sameType(ordValue(val), size);
sameType(valueSize<TValue>(), size);
sameType(ValueSize<TValue>::VALUE, size);
// alphabet must be non-empty
SEQAN_STATIC_ASSERT_MSG(static_cast<TSize>(0) < ValueSize<TValue>::VALUE, "Alphabet size be greater than zero.");
// convert integer to alphabet value
val = 0;
val = size;
TValue val2(0);
TValue val3(size);
ignoreUnusedVariableWarning(val2);
ignoreUnusedVariableWarning(val3);
}
};
// ============================================================================
// Concepts For Alphabets From The Bioinformatics Domain.
// ============================================================================
/*!
* @concept AlphabetWithGapsConcept
* @extends AlphabetConcept
* @headerfile <seqan/basic.h>
*
* @brief An alphabet that includes a specific gap character.
*/
/*!
* @fn AlphabetWithGapsConcept#gapValueImpl
* @brief Implements gapValue.
*
* @signature T gapValueImpl(valuePointerTag);
*
* @param[in] valuePointerTag A pointer that is used as a tag to specify the value type. The pointer needs not to
* point to a valid object, so it is possible to use a null pointer here.
*
* @return T A gap character.
*
* This function implements gapValue. It is recommended to use gapValue rather than <tt>gapValueImpl</tt>.
*
* @see AlphabetWithGapsConcept#gapValue
*/
/*!
* @fn AlphabetWithGapsConcept#gapValue
* @brief Return the "gap" value from an alphabet.
*
* @signature T gapValue<T>();
*
* @tparam T The alphabet type to query the gap value from.
*
* @return T The gap character.
*
* The function is implemented in gapValueImpl. Do not specialize <tt>gapValue</tt>, specialize link gapValueImpl
* instead!
*
* @see AlphabetWithGapsConcept#gapValueImpl
*/
// Forwards for Metafunctions and Functions.
template <typename T> T gapValue();
template <typename T> T gapValueImpl(T *);
SEQAN_CONCEPT_REFINE(AlphabetWithGapsConcept, (TValue), (AlphabetConcept))
{
TValue val;
SEQAN_CONCEPT_USAGE(AlphabetWithGapsConcept)
{
// Test the availability and return type of gapValue() and gapValueImpl().
sameType(gapValue<TValue>(), val);
sameType(gapValueImpl<TValue>(static_cast<TValue *>(0)), val);
}
};
/*!
* @concept AlphabetWithUnknownValueConcept
* @extends AlphabetConcept
* @headerfile <seqan/basic.h>
*
* @brief An alphabet which includes a specific "unknown" character.
*/
/*!
* @fn AlphabetWithUnknownValueConcept#unknownValue
*
* @brief Return the "unknown" value from an alphabet.
*
* @signature T unknownValue<T>();
*
* @tparam T The alphabet type to query the unknown value from.
*
* @return TReturn The "unknown" value.
*
* @see AlphabetWithUnknownValueConcept#unknownValueImpl
*/
/*!
* @fn AlphabetWithUnknownValueConcept#unknownValueImpl
* @brief Implements unknownValue.
*
* @signature T gapValueImpl(valuePointerTag)
*
* @param[in] valuePointerTag A pointer that is used as a tag to specify the value type. The pointer needs not to
* point to a valid object, so it is possible to use a null pointer here.
*
* @return TReturn A "unknown" character.
*
* This function implements unknownValue. It is recommended to use gapValue rather than <tt>gapValueImpl</tt>.
*
* @see AlphabetWithUnknownValueConcept#unknownValue
*/
// Forwards for Metafunctions and Functions.
template <typename T> T unknownValue();
template <typename T> T unknownValueImpl(T *);
SEQAN_CONCEPT_REFINE(AlphabetWithUnknownValueConcept, (TValue), (AlphabetConcept))
{
TValue val;
SEQAN_CONCEPT_USAGE(AlphabetWithUnknownValueConcept)
{
// Test the availability and return type of unknownValue() and unknownValueImpl().
sameType(unknownValue<TValue>(), val);
sameType(unknownValueImpl<TValue>(static_cast<TValue *>(0)), val);
}
};
/*!
* @concept AlphabetWithQualitiesConcept
* @extends AlphabetConcept
* @headerfile <seqan/basic.h>
*
* @brief An alphabet where qualities can be attached to the characters.
*/
/*!
* @mfn AlphabetWithQualitiesConcept#HasQualities
* @headerfile <seqan/basic.h>
* @brief Return whether the given type stores qualities besides the alphabet.
*
* @signature HasQualities<TAlphabet>::VALUE;
* @signature HasQualities<TAlphabet>::Type;
*
* @tparam TAlphabet The alphabe to query.
*
* @return VALUE <tt>true</tt> or <tt>false</tt>
* @return Type <tt>True</tt> or <tt>False</tt>
*/
/*!
* @mfn AlphabetWithQualitiesConcept#QualityValueSize
* @brief Return the number of quality values in characters from alphabet with qualities.
*
* @signature QualityValueSize<TAlphabet>::VALUE;
*
* @tparam TAlphabet The alphabet to query for its value size.
*
* @return VALUE The cardinality of the set of qualities.
*/
/*!
* @fn AlphabetWithQualitiesConcept#getQualityValue
* @brief Returns the quality of a character from an alphabet with integrated quality, e.g. the quality associated with
* a specified element from a sequence.
* @signature int getQualityValue(c);
*
* @param[in] c Character to retrieve the quality from.
*
* @return int Quality value of <tt>c</tt>. The quality value is an <tt>int</tt> value between 0 and 62 (inclusive).
*
* @section Examples
*
* @code{.cpp}
* String<Dna5Q> seq = "TATA";
* // Assign quality value to first 'T' in sequence seq
* assignQualityValue(seq[0], 35);
* // Print quality value of first 'T', and default quality value of first 'A'
* std::cout << getQualityValue(seq[0]) << std::endl; // Defined as 35
* std::cout << getQualityValue(seq[1]) << std::endl; // Default value 60
* @endcode
*
* @see AlphabetWithQualitiesConcept#assignQualityValue
* @see convertQuality
*/
/*!
* @fn AlphabetWithQualitiesConcept#assignQualityValue
* @brief Assigns quality to a character from an alphabet with integrated quality, e.g. to a specified element from a
* sequence.
*
* @signature void assignQualityValue(c, q);
*
* @param[out] c Target character to assign quality to.
* @param[in] q Quality to assign to the character. The quality value is an integral value between 0 and 62
* (inclusive).
*
* If <tt>q</tt> is a <tt>char</tt> then <tt>'!'</tt> is subtracted from <tt>q</tt>. This is useful for ASCII encoded
* PHRED scores.
*
* @see AlphabetWithQualitiesConcept#getQualityValue
* @see convertQuality
* @see assignQualities
*/
// TODO(holtgrew): What about different quality types? Guess scaling? Look at how other packages do this.
SEQAN_CONCEPT_REFINE(AlphabetWithQualitiesConcept, (TValue), (AlphabetConcept))
{
TValue val;
SEQAN_CONCEPT_USAGE(AlphabetWithQualitiesConcept)
{
// TODO(holtgrew): Write me!
}
};
} // namespace seqan
#endif // #ifndef SEQAN_INCLUDE_SEQAN_BASIC_ALPHABET_CONCEPT_H_
|