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 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037
|
// ==========================================================================
// SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2013, 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>
// Author: David Weese <david.weese@fu-berlin.de>
// ==========================================================================
#ifndef SEQAN_SEQUENCE_STRING_SET_BASE_H_
#define SEQAN_SEQUENCE_STRING_SET_BASE_H_
namespace seqan {
// ============================================================================
// Forwards
// ============================================================================
// ============================================================================
// Tags, Classes, Enums
// ============================================================================
template <typename TSpec = Default>
struct Owner {};
/*!
* @class StringSet
* @implements SequenceConcept
* @implements TextConcept
* @implements SegmentableConcept
* @headerfile <seqan/sequence.h>
* @brief A container class for a set of strings.
*
* @signature template <typename TString, typename TSpec>
* class StringSet;
*
* @tparam TString The type of the string to store in the string set.
* @tparam TSpec A tag for selecting the specialization of the string set. Default: <tt>Owner<Generous></tt>.
*
* String sets are containers for strings. They have two advantages over a string of strings:
*
* First, they allow to express the common intent in Bioinformatics to have a list of strings, e.g. for the
* chromosomes of a genome. This facilitates writing generic data structures and algorithms to operate on single
* strings and genomes which is captured by the @link TextConcept @endlink.
*
* Second, the @link DependentStringSet @endlink specialization allows to create subsets of string sets without
* storing copies of strings and identifying strings by a common id.
*
* @section Examples
*
* @include demos/sequence/stringset.cpp
*
* The output is as follows:
*
* @include demos/sequence/stringset.cpp.stdout
*/
/**
.Class.StringSet:
..cat:Sequences
..summary:A container class for a set of strings.
..signature:StringSet<TString, TSpec>
..param.TString:The string type.
...type:Class.String
..param.TSpec:The specializing type for the StringSet.
...metafunction:Metafunction.Spec
...default:$Owner<Generous>$.
..example.file:demos/sequence/stringset.cpp
..example.text:The output is as follows:
..example.output:
Number of elements: 1
Number of elements: 3
Element 0: Hello World!
Element 1: To be or not to be!
Element 2: A man, a plan, a canal - Panama!
Number of elements: 0
..include:sequence.h
*/
template <typename TString, typename TSpec = Owner<> >
class StringSet;
// ============================================================================
// Metafunctions
// ============================================================================
// --------------------------------------------------------------------------
// Metafunction Concatenator
// --------------------------------------------------------------------------
/*!
* @mfn StringSet#Concatenator
* @brief Return the type of the concatenated sequence of all sequences in a StringSet.
*
* @signature Concatenator<TStringSet>::Type
*
* @tparam TStringSet The type of the string set.
*
* @return Type The resulting concatenator type.
*/
/**
.Metafunction.Concatenator:
..class:Class.StringSet
..summary:Returns the type of the concatenation sequence of all sequences in a @Class.StringSet@.
..cat:Sequences
..signature:Concatenator<TStringSet>::Type
..param.TStringSet:The @Class.StringSet@ type.
...type:Class.StringSet
..returns:The type of a container that can be iterated like the concatenation string of all sequences in a @Class.StringSet@.
..include:seqan/sequence.h
*/
// TODO(holtgrew): Why is this specialized for all types?
template <typename TObject>
struct Concatenator
{
typedef TObject Type;
};
template <typename TObject>
struct Concatenator<TObject const>
{
typedef typename Concatenator<TObject>::Type const Type;
};
template <typename TString, typename TSpec >
struct Concatenator<StringSet<TString, TSpec> >
{
typedef ConcatenatorManyToOne<StringSet<TString, TSpec> > Type;
};
// --------------------------------------------------------------------------
// Metafunction StringSetLimits
// --------------------------------------------------------------------------
// TODO(holtgrew): Document these metafunctions.
// TODO(holtgrew): Default specializations necessary?
template <typename TString>
struct StringSetLimits
{
typedef Nothing Type;
};
template <typename TString>
struct StringSetLimits<TString const>
{
typedef typename StringSetLimits<TString>::Type const Type;
};
template <typename TString, typename TSpec>
struct StringSetLimits<StringSet<TString, TSpec> >
{
typedef typename Size<TString>::Type TSize_;
typedef String<TSize_> Type;
};
// --------------------------------------------------------------------------
// Metafunction StringSetPosition
// --------------------------------------------------------------------------
/*!
* @mfn StringSet#StringSetPosition
* @brief Returns position type in string set.
*
* @signature StringSetPosition<T>::Type
*
* @tparam T
*
* @return Type
*
* TODO(holtgrew): Complete documentation, part of TextConcept?
*/
// TODO(holtgrew): Default specializations necessary?
template <typename TString>
struct StringSetPosition
{
typedef typename Size<TString>::Type Type;
};
template <typename TString, typename TSpec>
struct StringSetPosition<StringSet<TString, TSpec> >
{
typedef typename Size<TString>::Type TSize_;
typedef Pair<TSize_> Type;
};
// --------------------------------------------------------------------------
// Metafunction LengthSum
// --------------------------------------------------------------------------
/*!
* @mfn StringSet#LengthSum
* @brief Length sum type type in string set.
*
* @signature LengthSum<T>::Type
*
* @tparam T
*
* @return Type
*
* TODO(holtgrew): Complete documentation, part of TextConcept?
*/
template <typename TString>
struct LengthSum
{
typedef typename Size<TString>::Type Type;
};
template <typename TString, typename TSpec>
struct LengthSum<StringSet<TString, TSpec> >
{
typedef StringSet<TString, TSpec> TStringSet;
typedef typename StringSetLimits<TStringSet>::Type TLimits;
typedef typename Value<TLimits>::Type Type;
};
template <typename T>
struct LengthSum<T const> :
public LengthSum<T> {};
// --------------------------------------------------------------------------
// Metafunction GetSequenceNo
// --------------------------------------------------------------------------
/*!
* @mfn StringSet#GetSequenceByNo
* @brief Type for getting sequence by number.
*
* @signature GetSequenceByNo<T>::Type
*
* @tparam T
*
* @return Type
*
* TODO(holtgrew): Complete documentation, part of TextConcept?
*/
// TODO(holtgrew): Default specializations necessary?
template <typename TString>
struct GetSequenceByNo
{
typedef TString & Type;
};
template <typename TString, typename TSpec>
struct GetSequenceByNo<StringSet<TString, TSpec> >
{
typedef typename Reference< StringSet<TString, TSpec> >::Type Type;
};
template <typename TString, typename TSpec>
struct GetSequenceByNo<StringSet<TString, TSpec> const>
{
typedef typename Reference< StringSet<TString, TSpec> const>::Type Type;
};
// --------------------------------------------------------------------------
// Metafunction Value
// --------------------------------------------------------------------------
template < typename TString, typename TSpec >
struct Value< StringSet< TString, TSpec > >
{
typedef TString Type;
};
template < typename TString, typename TSpec >
struct Value< StringSet< TString, TSpec > const>
{
typedef TString const Type;
};
// --------------------------------------------------------------------------
// Metafunction Iterator
// --------------------------------------------------------------------------
template < typename TString, typename TSpec, typename TIteratorSpec>
struct Iterator< StringSet< TString, TSpec >, TIteratorSpec>
{
typedef Iter< StringSet< TString, TSpec >, PositionIterator> Type;
};
template < typename TString, typename TSpec, typename TIteratorSpec >
struct Iterator< StringSet< TString, TSpec> const, TIteratorSpec>
{
typedef Iter< StringSet< TString, TSpec > const, PositionIterator> Type;
};
// --------------------------------------------------------------------------
// Metafunction Size
// --------------------------------------------------------------------------
template <typename TString, typename TSpec>
struct Size< StringSet< TString, TSpec > >
: Size<typename StringSetLimits< StringSet<TString, TSpec> >::Type > {};
// Default Size<T const> redirects to non-const.
// --------------------------------------------------------------------------
// Metafunction Prefix
// --------------------------------------------------------------------------
// TODO(holtgrew): Do Prefix, Suffix, Infix make sense if defined in this way for all StringSet classes?
// TODO(holtgrew): However, if this works nicely then it shows that implementing segments as Strings would not be advantageous since they now work for arbitrary sequential-access containers.
template <typename TString, typename TSpec>
struct Prefix< StringSet< TString, TSpec > >
: Prefix<TString > {};
template <typename TString, typename TSpec>
struct Prefix<StringSet< TString, TSpec > const>
: Prefix<TString const > {};
// --------------------------------------------------------------------------
// Metafunction Suffix
// --------------------------------------------------------------------------
template <typename TString, typename TSpec>
struct Suffix<StringSet< TString, TSpec> >
: Suffix<TString> {};
template <typename TString, typename TSpec>
struct Suffix<StringSet< TString, TSpec> const>
: Suffix<TString const> {};
// --------------------------------------------------------------------------
// Metafunction Infix
// --------------------------------------------------------------------------
template <typename TString, typename TSpec>
struct Infix<StringSet< TString, TSpec> >
: Infix<TString> {};
template <typename TString, typename TSpec>
struct Infix<StringSet< TString, TSpec > const>
: Infix< TString const > {};
// --------------------------------------------------------------------------
// Metafunction AllowsFastRandomAccess
// --------------------------------------------------------------------------
template <typename TString, typename TSpec>
struct AllowsFastRandomAccess<StringSet<TString, TSpec> >
: AllowsFastRandomAccess<TString> {};
// Default AllowsFastRandomAccess<T const> redirects to non-const.
// --------------------------------------------------------------------------
// Metafunction DefaultOverflowImplicit
// --------------------------------------------------------------------------
template < typename TString, typename TSpec >
struct DefaultOverflowImplicit<StringSet< TString, TSpec> >
{
typedef Generous Type;
};
template < typename TString, typename TSpec >
struct DefaultOverflowImplicit<StringSet< TString, TSpec> const>
{
typedef Generous Type;
};
// ============================================================================
// Functions
// ============================================================================
// --------------------------------------------------------------------------
// Function stringSetLimits()
// --------------------------------------------------------------------------
/**
.Function.stringSetLimits:
..cat:Sequences
..class:Class.String
..class:Class.StringSet
..summary:Retrieves a string of delimiter positions of a @Class.StringSet@ which is needed for local<->global position conversions.
..signature:stringSetLimits(me)
..param.me:A string or string set.
...type:Class.String
...type:Class.StringSet
..returns:A reference to a string.
...remarks:If $me$ is a @Class.StringSet@ then the returned string is of size $length(me)+1$ and contains the ascending (virtual) delimiter positions of the concatenation of all strings in the string set.
...remarks:If $me$ is a @Class.String@, @Tag.Nothing@ is returned.
..include:seqan/sequence.h
*/
// TODO(holtgrew): Default implementation necessary?!
template <typename TStringSet>
inline typename StringSetLimits<TStringSet>::Type
stringSetLimits(TStringSet &)
{
return typename StringSetLimits<TStringSet>::Type();
}
template <typename TString, typename TSpec>
inline typename StringSetLimits< StringSet<TString, TSpec> >::Type &
stringSetLimits(StringSet<TString, TSpec> & stringSet)
{
if (!_validStringSetLimits(stringSet))
_refreshStringSetLimits(stringSet);
return stringSet.limits;
}
template <typename TString, typename TSpec>
inline typename StringSetLimits< StringSet<TString, TSpec> const>::Type &
stringSetLimits(StringSet<TString, TSpec> const & stringSet)
{
if (!_validStringSetLimits(stringSet))
_refreshStringSetLimits(const_cast< StringSet<TString, TSpec>& >(stringSet));
return stringSet.limits;
}
// --------------------------------------------------------------------------
// Function getSeqNo()
// --------------------------------------------------------------------------
/**
.Function.getSeqNo:
..cat:Sequences
..summary:Returns the sequence number of a position.
..signature:getSeqNo(pos[, limits])
..param.pos:A position.
...type:Class.Pair
..param.limits:The limits string returned by @Function.stringSetLimits@.
..returns:A single integer value that identifies the string within the stringset $pos$ points at.
...remarks:If $limits$ is omitted or @Tag.Nothing@ $getSeqNo$ returns 0.
...remarks:If $pos$ is a local position (of class @Class.Pair@) then $i1$ is returned.
...remarks:If $pos$ is a global position (integer type and $limits$ is a @Class.String@) then $pos$ is converted to a local position and $i1$ is returned.
..include:seqan/sequence.h
*/
// TODO(holtgrew): Auto-sequences should go away!
template <typename TPosition>
SEQAN_HOST_DEVICE inline TPosition
getSeqNo(TPosition const &, Nothing const &)
{
return 0;
}
// TODO(holtgrew): Auto-sequences should go away!
template <typename TPosition>
SEQAN_HOST_DEVICE inline TPosition
getSeqNo(TPosition const &)
{
return 0;
}
// n sequences (position type is Pair)
template <typename T1, typename T2, typename TPack, typename TLimitsString>
SEQAN_HOST_DEVICE inline T1 getSeqNo(Pair<T1, T2, TPack> const & pos, TLimitsString const &)
{
return getValueI1(pos);
}
// n sequences (position type is Pair)
template <typename T1, typename T2, typename TPack>
SEQAN_HOST_DEVICE inline T1 getSeqNo(Pair<T1, T2, TPack> const & pos)
{
return getValueI1(pos);
}
// n sequences (position type is an integral type)
template <typename TPos, typename TLimitsString>
inline TPos getSeqNo(TPos const & pos, TLimitsString const & limits)
{
typedef typename Iterator<TLimitsString const, Standard>::Type TIter;
typedef typename Value<TLimitsString>::Type TSize;
TIter _begin = begin(limits, Standard());
TIter _upper = ::std::upper_bound(_begin, end(limits, Standard()), (TSize)pos) - 1;
return difference(_begin, _upper);
}
// --------------------------------------------------------------------------
// Function getSeqOffset()
// --------------------------------------------------------------------------
/**
.Function.getSeqOffset:
..cat:Sequences
..summary:Returns the local sequence offset of a position.
..signature:getSeqOffset(pos[, limits])
..param.pos:A position.
...type:Class.Pair
..param.limits:The limits string returned by @Function.stringSetLimits@.
..returns:A single integer value that identifies the position within the string $pos$ points at.
...remarks:If $limits$ is omitted or @Tag.Nothing@ $getSeqNo$ returns $pos$.
...remarks:If $pos$ is a local position (of class @Class.Pair@) then $i2$ is returned.
...remarks:If $pos$ is a global position (integer type and $limits$ is a @Class.String@) then $pos$ is converted to a local position and $i2$ is returned.
..include:seqan/sequence.h
*/
// TODO(holtgrew): Auto-sequences should go away!
template <typename TPosition>
SEQAN_HOST_DEVICE inline TPosition
getSeqOffset(TPosition const & pos, Nothing const &)
{
return pos;
}
// TODO(holtgrew): Auto-sequences should go away!
template <typename TPosition>
SEQAN_HOST_DEVICE inline TPosition
getSeqOffset(TPosition const & pos)
{
return pos;
}
// n sequences (position type is Pair)
template <typename T1, typename T2, typename TPack, typename TLimitsString>
SEQAN_HOST_DEVICE inline T2 getSeqOffset(Pair<T1, T2, TPack> const & pos, TLimitsString const &) {
return getValueI2(pos);
}
// n sequences (position type is Pair)
template <typename T1, typename T2, typename TPack>
SEQAN_HOST_DEVICE inline T2 getSeqOffset(Pair<T1, T2, TPack> const & pos) {
return getValueI2(pos);
}
// n sequences (position type is an integral type)
template <typename TPos, typename TLimitsString>
inline TPos getSeqOffset(TPos const & pos, TLimitsString const & limits) {
typedef typename Iterator<TLimitsString const, Standard>::Type TIter;
typedef typename Value<TLimitsString>::Type TSize;
TIter _begin = begin(limits, Standard());
TIter _upper = ::std::upper_bound(_begin, end(limits, Standard()), (TSize)pos) - 1;
return pos - *_upper;
}
// --------------------------------------------------------------------------
// Function setSeqOffset()
// --------------------------------------------------------------------------
// TODO(esiragusa): Implement a spec for global positions.
template <typename TPosition, typename TSeqOffset>
inline void
setSeqOffset(TPosition & pos, TSeqOffset seqOffset)
{
pos = seqOffset;
}
template <typename T1, typename T2, typename TPack, typename TSeqOffset>
inline void
setSeqOffset(Pair<T1, T2, TPack> & pos, TSeqOffset seqOffset)
{
setValueI2(pos, seqOffset);
}
// --------------------------------------------------------------------------
// Function posGlobalize()
// --------------------------------------------------------------------------
/**
.Function.posGlobalize:
..cat:Sequences
..summary:Converts a local/global to a global position.
..signature:posGlobalize(pos, limits)
..param.pos:A local or global position (pair or integer value).
...type:Class.Pair
..param.limits:The limits string returned by @Function.stringSetLimits@.
..returns:The corresponding global position of $pos$.
...remarks:If $pos$ is an integral type $pos$ is returned.
...remarks:If not, $limits[getSeqNo(pos, limits)] + getSeqOffset(pos, limits)$ is returned.
..include:seqan/sequence.h
*/
// any_position and no limits_string -> any_position
template <typename TPosition>
inline TPosition posGlobalize(TPosition const & pos, Nothing const &)
{
return pos;
}
// local_position (0,x) and no limits_string -> global_position x
template <typename T1, typename T2, typename TPack>
inline T2 posGlobalize(Pair<T1, T2, TPack> const & pos, Nothing const &)
{
return getSeqOffset(pos);
}
// any_position and no limits_string -> any_position
template <typename TLimitsString, typename TPosition>
inline TPosition posGlobalize(TPosition const & pos, TLimitsString const &)
{
return pos;
}
// local_position and limits_string -> global_position
template <typename TLimitsString, typename T1, typename T2, typename TPack>
inline typename Value<TLimitsString>::Type
posGlobalize(Pair<T1, T2, TPack> const & pos, TLimitsString const & limits)
{
return limits[getSeqNo(pos, limits)] + getSeqOffset(pos, limits);
}
// --------------------------------------------------------------------------
// Function posLocalToX()
// --------------------------------------------------------------------------
/**
.Function.posLocalToX:
..cat:Sequences
..summary:Converts a local to a local/global position.
..signature:posLocalToX(dst, localPos, limits)
..param.dst:Destination value. A local or global position (pair or integer value).
...type:Class.Pair
..param.localPos:A local position (pair).
...type:Class.Pair
..param.limits:The limits string returned by @Function.stringSetLimits@.
..include:seqan/sequence.h
*/
template <typename TDest, typename TLimitsString, typename T1, typename T2, typename TPack>
inline void
posLocalToX(TDest & dst, Pair<T1, T2, TPack> const & localPos, TLimitsString const & limits)
{
dst = posGlobalize(localPos, limits);
}
template <typename TD1, typename TD2, typename TDPack, typename TLimitsString, typename T1, typename T2, typename TPack>
inline void
posLocalToX(Pair<TD1, TD2, TDPack> & dst, Pair<T1, T2, TPack> const & localPos, TLimitsString const &)
{
dst = localPos;
}
// --------------------------------------------------------------------------
// Function posLocalize()
// --------------------------------------------------------------------------
/**
.Function.posLocalize:
..cat:Sequences
..summary:Converts a local/global to a local position.
..signature:posLocalize(result, pos, limits)
..param.pos:A local or global position (pair or integer value).
...type:Class.Pair
..param.limits:The limits string returned by @Function.stringSetLimits@.
..param.result:Reference to the resulting corresponding local position of $pos$.
...remarks:If $pos$ is an integral type and $limits$ is omitted or @Tag.Nothing@, $pos$ is returned.
...remarks:If $pos$ is a local position (of class @Class.Pair@) then $pos$ is returned.
...remarks:If $pos$ is a global position (integer type and $limits$ is a @Class.String@) then $pos$ is converted to a local position.
..include:seqan/sequence.h
*/
// any_position and no limits_string -> any_position
template <typename TResult, typename TPosition>
inline void posLocalize(TResult & result, TPosition const & pos, Nothing const &) {
result = pos;
}
template <typename T1, typename T2, typename TPack, typename TPosition>
inline void posLocalize(Pair<T1, T2, TPack> & result, TPosition const & pos, Nothing const &) {
result.i1 = 0;
result.i2 = pos;
}
// global_position and limits_string -> local_position
template <typename TResult, typename TSize, typename TSpec, typename TPosition>
inline void posLocalize(TResult & result, TPosition const & pos, String<TSize, TSpec> const & limits) {
typedef typename Iterator<String<TSize, TSpec> const, Standard>::Type TIter;
TIter _begin = begin(limits, Standard());
TIter _upper = ::std::upper_bound(_begin, end(limits, Standard()), (TSize)pos) - 1;
result.i1 = difference(_begin, _upper);
result.i2 = pos - *_upper;
}
// local_position -> local_position
template <typename TResult, typename TSize, typename TSpec, typename T1, typename T2, typename TPack>
inline void posLocalize(TResult & result, Pair<T1, T2, TPack> const & pos, String<TSize, TSpec> const &/*limits*/) {
result = pos;
}
// --------------------------------------------------------------------------
// Function prefix()
// --------------------------------------------------------------------------
///.Function.prefix.param.host.type:Class.StringSet
///.Function.prefix.class:Class.StringSet
template < typename TString, typename TSpec, typename TPosition >
inline typename Prefix<TString>::Type
prefix(StringSet< TString, TSpec > & me, TPosition const & pos)
{
typedef StringSet<TString, TSpec> TStringSet;
typedef typename Size<TStringSet>::Type TSetSize;
typedef typename Size<TString>::Type TStringSize;
typedef Pair<TSetSize, TStringSize, Pack> TPair;
TPair lPos;
posLocalize(lPos, pos, stringSetLimits(me));
return prefix(me[getSeqNo(lPos)], getSeqOffset(lPos));
}
template < typename TString, typename TSpec, typename TPosition >
inline typename Prefix<TString const>::Type
prefix(StringSet< TString, TSpec > const & me, TPosition const & pos)
{
typedef StringSet<TString, TSpec> TStringSet;
typedef typename Size<TStringSet>::Type TSetSize;
typedef typename Size<TString>::Type TStringSize;
typedef Pair<TSetSize, TStringSize, Pack> TPair;
TPair lPos;
posLocalize(lPos, pos, stringSetLimits(me));
return prefix(me[getSeqNo(lPos)], getSeqOffset(lPos));
}
// --------------------------------------------------------------------------
// Function suffix()
// --------------------------------------------------------------------------
///.Function.suffix.param.host.type:Class.StringSet
///.Function.suffix.class:Class.StringSet
template < typename TString, typename TSpec, typename TPosition >
inline typename Suffix<TString>::Type
suffix(StringSet< TString, TSpec > & me, TPosition const & pos)
{
typedef StringSet<TString, TSpec> TStringSet;
typedef typename Size<TStringSet>::Type TSetSize;
typedef typename Size<TString>::Type TStringSize;
typedef Pair<TSetSize, TStringSize, Pack> TPair;
TPair lPos;
posLocalize(lPos, pos, stringSetLimits(me));
return suffix(me[getSeqNo(lPos)], getSeqOffset(lPos));
}
template < typename TString, typename TSpec, typename TPosition >
inline typename Suffix<TString const>::Type
suffix(StringSet< TString, TSpec > const & me, TPosition const & pos)
{
typedef StringSet<TString, TSpec> TStringSet;
typedef typename Size<TStringSet>::Type TSetSize;
typedef typename Size<TString>::Type TStringSize;
typedef Pair<TSetSize, TStringSize, Pack> TPair;
TPair lPos;
posLocalize(lPos, pos, stringSetLimits(me));
return suffix(me[getSeqNo(lPos)], getSeqOffset(lPos));
}
// --------------------------------------------------------------------------
// Function infixWithLength()
// --------------------------------------------------------------------------
///.Function.infixWithLength.param.host.type:Class.StringSet
///.Function.infixWithLength.class:Class.StringSet
template < typename TString, typename TSpec, typename TPosition, typename TSize >
inline typename Infix<TString>::Type
infixWithLength(StringSet< TString, TSpec > & me, TPosition const & pos, TSize length)
{
typedef StringSet<TString, TSpec> TStringSet;
typedef typename Size<TStringSet>::Type TSetSize;
typedef typename Size<TString>::Type TStringSize;
typedef Pair<TSetSize, TStringSize, Pack> TPair;
TPair lPos;
posLocalize(lPos, pos, stringSetLimits(me));
return infixWithLength(me[getSeqNo(lPos)], getSeqOffset(lPos), length);
}
template < typename TString, typename TSpec, typename TPosition, typename TSize >
inline typename Infix<TString const>::Type
infixWithLength(StringSet< TString, TSpec > const & me, TPosition const & pos, TSize length)
{
typedef StringSet<TString, TSpec> TStringSet;
typedef typename Size<TStringSet>::Type TSetSize;
typedef typename Size<TString>::Type TStringSize;
typedef Pair<TSetSize, TStringSize, Pack> TPair;
TPair lPos;
posLocalize(lPos, pos, stringSetLimits(me));
return infixWithLength(me[getSeqNo(lPos)], getSeqOffset(lPos), length);
}
// --------------------------------------------------------------------------
// Function infix()
// --------------------------------------------------------------------------
///.Function.infix.param.host.type:Class.StringSet
///.Function.infix.class:Class.StringSet
template < typename TString, typename TSpec, typename TPosBegin, typename TPosEnd >
inline typename Infix<TString>::Type
infix(StringSet< TString, TSpec > & me, TPosBegin const & posBegin, TPosEnd const & posEnd)
{
typedef StringSet<TString, TSpec> TStringSet;
typedef typename Size<TStringSet>::Type TSetSize;
typedef typename Size<TString>::Type TStringSize;
typedef Pair<TSetSize, TStringSize, Pack> TPair;
TPair localPosBegin, localPosEnd;
posLocalize(localPosBegin, posBegin, stringSetLimits(me));
posLocalize(localPosEnd, posEnd, stringSetLimits(me));
return infix(me[getSeqNo(localPosBegin)], getSeqOffset(localPosBegin), getSeqOffset(localPosEnd));
}
template < typename TString, typename TSpec, typename TPosBegin, typename TPosEnd >
inline typename Infix<TString const>::Type
infix(StringSet< TString, TSpec > const & me, TPosBegin const & posBegin, TPosEnd const & posEnd)
{
typedef StringSet<TString, TSpec> TStringSet;
typedef typename Size<TStringSet>::Type TSetSize;
typedef typename Size<TString>::Type TStringSize;
typedef Pair<TSetSize, TStringSize, Pack> TPair;
TPair localPosBegin, localPosEnd;
posLocalize(localPosBegin, posBegin, stringSetLimits(me));
posLocalize(localPosEnd, posEnd, stringSetLimits(me));
return infix(me[getSeqNo(localPosBegin)], getSeqOffset(localPosBegin), getSeqOffset(localPosEnd));
}
// --------------------------------------------------------------------------
// Function posAtFirstLocal()
// --------------------------------------------------------------------------
template <typename TPos, typename TLimitsString>
inline bool posAtFirstLocal(TPos const & pos, TLimitsString const & limits) {
return getSeqOffset(pos, limits) == 0;
}
template <typename TPos>
inline bool posAtFirstLocal(TPos const & pos) {
return getSeqOffset(pos) == 0;
}
// --------------------------------------------------------------------------
// Function posAtEnd()
// --------------------------------------------------------------------------
template <typename T1, typename T2, typename TPack, typename TSequence, typename TSpec>
inline bool posAtEnd(Pair<T1, T2, TPack> const & pos, StringSet<TSequence, TSpec> const & stringSet) {
return pos.i2 == sequenceLength(pos.i1, stringSet);
}
template <typename TPos, typename TSequence, typename TSpec>
inline bool posAtEnd(TPos pos, StringSet<TSequence, TSpec> const & stringSet) {
return getSeqOffset(pos, stringSetLimits(stringSet)) == 0;
}
template <typename TPos, typename TSequence>
inline bool posAtEnd(TPos pos, TSequence const & seq) {
return pos == length(seq);
}
// --------------------------------------------------------------------------
// Function posPrev()
// --------------------------------------------------------------------------
/*!
* @fn posPrev
* @headerfile <seqan/sequence.h>
* @brief Returns a position where the local offset is decreased by one.
*
* @signature TPos posPrev(pos);
*
* @param[in] pos A position type, an integer with <tt>seqOfs</tt> or a pair <tt>(seqNo, seqOfs)</tt>.
*
* @return TPos The predecessor. TPos is the type of <tt>pos</tt>.
*
* @see posNext
* @see posInc
* @see posAdd
*/
/**
.Function.posPrev
..cat:Sequences
..summary:Returns a position where the local offset is decreased by one.
..signature:posPrev(pos)
..param.pos:A position type. Could either be an integer $seqOfs$ or a pair $(seqNo, seqOfs)$.
..returns:Returns a value of the same type as $pos$ where $seqOfs$ is decreased by one.
..see:Function.posNext
..see:Function.posInc
..see:Function.posAdd
..include:seqan/sequence.h
*/
template <typename TPos>
inline TPos posPrev(TPos pos) {
return pos - 1;
}
template <typename T1, typename T2, typename TPack>
inline Pair<T1, T2, TPack> posPrev(Pair<T1, T2, TPack> const & pos) {
return Pair<T1, T2, TPack>(getValueI1(pos), getValueI2(pos) - 1);
}
// --------------------------------------------------------------------------
// Function posInc()
// --------------------------------------------------------------------------
/*!
* @fn posInc
* @headerfile <seqan/sequence.h>
* @brief Increments the local offset of a position type.
*
* @signature void posInc(pos);
*
* @param[in,out] pos A position type, an integer with <tt>seqOfs</tt> or a pair <tt>(seqNo, seqOfs)</tt>. In both
* cases, <tt>seqOfs</tt> will be incremented by one.
*
* @see posNext
* @see posPrev
* @see posAdd
*/
/**
.Function.posInc
..cat:Sequences
..summary:Increments the local offset of a position type.
..signature:posInc(pos)
..param.pos:A position type. Could either be an integer $seqOfs$ or a pair $(seqNo, seqOfs)$. In both cases $seqOfs$ will be incremented by one.
..see:Function.posNext
..see:Function.posAdd
..include:seqan/sequence.h
*/
template <typename TPos>
inline void posInc(TPos &pos) {
++pos;
}
template <typename TPos, typename TDelta>
inline void posInc(TPos &pos, TDelta delta) {
pos += delta;
}
template <typename T1, typename T2, typename TPack>
inline void posInc(Pair<T1, T2, TPack> & pos) {
++pos.i2;
}
template <typename T1, typename T2, typename TPack, typename TDelta>
inline void posInc(Pair<T1, T2, TPack> & pos, TDelta delta) {
pos.i2 += delta;
}
// --------------------------------------------------------------------------
// Function posNext()
// --------------------------------------------------------------------------
/*!
* @fn posNext
* @headerfile <seqan/sequence.h>
* @brief Returns a position where the local offset is increased by one.
*
* @signature TPos posNext(pos);
*
* @param[in] pos A position type, an integer with <tt>seqOfs</tt> or a pair <tt>(seqNo, seqOfs)</tt>.
*
* @return TPos Returns a value of the same type as <tt>pos</tt> where <tt>seqOfs</tt> is increased by one.
*
* @see posInc
* @see posPrev
* @see posAdd
*/
/**
.Function.posNext
..cat:Sequences
..summary:Returns a position where the local offset is increased by one.
..signature:posNext(pos)
..param.pos:A position type. Could either be an integer $seqOfs$ or a pair $(seqNo, seqOfs)$.
..returns:Returns a value of the same type as $pos$ where $seqOfs$ is increased by one.
..see:Function.posPrev
..see:Function.posInc
..see:Function.posAdd
..include:seqan/sequence.h
*/
template <typename TPos>
inline TPos posNext(TPos pos) {
return pos + 1;
}
template <typename T1, typename T2, typename TPack>
inline Pair<T1, T2, TPack>
posNext(Pair<T1, T2, TPack> const & pos) {
return Pair<T1, T2, TPack>(getValueI1(pos), getValueI2(pos) + 1);
}
// --------------------------------------------------------------------------
// Function posAdd()
// --------------------------------------------------------------------------
/*!
* @fn posAdd
* @brief Returns a position where the local offset is increased by a value <tt>delta</tt>.
*
* @signature TPos posAdd(pos, delta);
*
* @param[in] pos A position type, an integer with <tt>seqOfs</tt> or a pair <tt>(seqNo, seqOfs)</tt>.
* @param[in] delta Increase the local offset of <tt>pos</tt> by this value.
*
* @return TPos Returns a value of the same type as <tt>pos</tt> where <tt>seqOfs</tt> is increased by <tt>delta</tt>.
*
* @see posInc
* @see posPrev
* @see posNext
*/
/**
.Function.posAdd
..cat:Sequences
..summary:Returns a position where the local offset is increased by a value $delta$.
..signature:posAdd(pos, delta)
..param.pos:A position type. Could either be an integer $seqOfs$ or a pair $(seqNo, seqOfs)$.
..param.delta:Increase the local offset of $pos$ by this value.
..returns:Returns a value of the same type as $pos$ where $seqOfs$ is increased by $delta$.
..see:Function.posAddAndCheck
..see:Function.posInc
..see:Function.posNext
..include:seqan/sequence.h
*/
template <typename TPos, typename TDelta>
SEQAN_HOST_DEVICE inline TPos posAdd(TPos pos, TDelta delta) {
return pos + delta;
}
template <typename T1, typename T2, typename TPack, typename TDelta>
SEQAN_HOST_DEVICE inline Pair<T1, T2, TPack>
posAdd(Pair<T1, T2, TPack> const & pos, TDelta delta) {
return Pair<T1, T2, TPack>(getValueI1(pos), getValueI2(pos) + delta);
}
// --------------------------------------------------------------------------
// Function posAddAndCheck()
// --------------------------------------------------------------------------
/*!
* @fn posAddAndCheck
* @headerfile <seqan/sequence.h>
* @brief Increases the local offset of a position by a value <tt>delta</tt> and check for overflow.
*
* @signature bool posAddAndCheck(pos, delta, text);
*
* @param[in,out] pos A position type, an integer with <tt>seqOfs</tt> or a pair <tt>(seqNo, seqOfs)</tt>.
* @param[in] delta Increase the local offset of <tt>pos</tt> by this value.
* @param[in] text The @link TextConcept text @endlink to use for checking.
*
* @see posAdd
* @see posInc
*/
/**
.Function.posAddAndCheck
..cat:Sequences
..summary:Increases the local offset of a position by a value $delta$ and check for overflow.
..signature:posAddAndCheck(pos, delta, text)
..param.pos:A position type. Could either be an integer $seqOfs$ or a pair $(seqNo, seqOfs)$.
..param.delta:Increase the local offset of $pos$ by this value.
..param.text:Single sequence or @Class.StringSet@.
..returns:Returns a $bool$ which is $true$ if the position is still valid, i.e.
if it doesn't exceed the end of the referred sequence in the text.
..see:Function.posAdd
..see:Function.posInc
..include:seqan/sequence.h
*/
template <typename TPos, typename TDelta, typename TSequence>
inline bool posAddAndCheck(TPos & pos, TDelta delta, TSequence const & sequence) {
return (pos += delta) < length(sequence);
}
template <typename TPos, typename TDelta, typename TSequence, typename TSpec>
inline bool posAddAndCheck(TPos & pos, TDelta delta, StringSet<TSequence, TSpec> const & stringSet)
{
typedef StringSet<TSequence, TSpec> TStringSet;
typedef typename StringSetLimits<TStringSet const>::Type TLimits;
typedef typename Iterator<TLimits, Standard>::Type TIter;
typedef typename Value<TLimits>::Type TSize;
TLimits & limits = stringSetLimits(stringSet);
TIter _end = end(limits, Standard());
TIter _endMark = ::std::upper_bound(begin(limits, Standard()), _end, (TSize)pos);
pos += delta;
if (_endMark < _end)
return pos < *_endMark;
else
return false;
}
template <typename T1, typename T2, typename TPack, typename TDelta, typename TSequence, typename TSpec>
inline bool
posAddAndCheck(Pair<T1, T2, TPack> & pos, TDelta delta, StringSet<TSequence, TSpec> const & stringSet) {
return (pos.i2 += delta) < length(stringSet[pos.i1]);
}
// --------------------------------------------------------------------------
// Function posSub()
// --------------------------------------------------------------------------
/*!
* @fn posSub
* @headerfile <seqan/sequence.h>
* @brief Returns a position where the local offset is decreased by a value <tt>delta</tt>.
*
* @signature TPos posSub(pos, delta);
*
* @param[in] pos A position type, an integer with <tt>seqOfs</tt> or a pair <tt>(seqNo, seqOfs)</tt>.
* @param[in] delta Decrease the local offset of <tt>pos</tt> by this value.
*
* @return TPos Returns a value of the same type as <tt>pos</tt> where <tt>seqOfs</tt> is decreased by <tt>delta</tt>.
*
* @see posAdd
* @see posInc
* @see posNext
*/
/**
.Function.posSub
..cat:Sequences
..summary:Returns a position where the local offset is decreased by a value $delta$.
..signature:posSub(pos, delta)
..param.pos:A position type. Could either be an integer $seqOfs$ or a pair $(seqNo, seqOfs)$.
..param.delta:Decrease the local offset of $pos$ by this value.
..returns:Returns a value of the same type as $pos$ where $seqOfs$ is decreased by $delta$.
..see:Function.posAdd
..see:Function.posInc
..see:Function.posNext
..include:seqan/sequence.h
*/
template <typename TA, typename TB>
inline TA posSub(TA a, TB b) {
return a - b;
}
template <
typename TA1, typename TA2, typename TAPack,
typename TB1, typename TB2, typename TBPack
>
inline TA2
posSub(Pair<TA1, TA2, TAPack> const & a, Pair<TB1, TB2, TBPack> const & b) {
return getValueI2(a) - getValueI2(b);
}
// --------------------------------------------------------------------------
// Function posLess()
// --------------------------------------------------------------------------
template <typename TPos>
inline bool posLess(TPos const & a, TPos const & b) {
return a < b;
}
template <typename T1, typename T2, typename TPack>
inline bool posLess(Pair<T1, T2, TPack> const & a, Pair<T1, T2, TPack> const & b) {
return
(getValueI1(a) < getValueI1(b)) ||
((getValueI1(a) == getValueI1(b)) && (getValueI2(a) < getValueI2(b)));
}
// --------------------------------------------------------------------------
// Function posCompare()
// --------------------------------------------------------------------------
template <typename TPos>
inline int posCompare(TPos const & a, TPos const & b) {
if (a < b) return -1;
if (a > b) return 1;
return 0;
}
template <typename T1, typename T2, typename TPack>
inline int posCompare(Pair<T1, T2, TPack> const & a, Pair<T1, T2, TPack> const & b) {
if (getValueI1(a) < getValueI1(b)) return -1;
if (getValueI1(a) > getValueI1(b)) return 1;
return posCompare(getValueI2(a), getValueI2(b));
}
// --------------------------------------------------------------------------
// Function suffixLength()
// --------------------------------------------------------------------------
template <typename TPos, typename TString>
inline typename Size<TString>::Type
suffixLength(TPos pos, TString const & string) {
return length(string) - pos;
}
template <typename TPos, typename TString, typename TSpec>
inline typename Size<TString>::Type
suffixLength(TPos pos, StringSet<TString, TSpec> const & stringSet) {
return length(stringSet[getSeqNo(pos, stringSetLimits(stringSet))]) - getSeqOffset(pos, stringSetLimits(stringSet));
}
// --------------------------------------------------------------------------
// Function countSequences()
// --------------------------------------------------------------------------
template <typename TString>
inline unsigned
countSequences(TString const &) {
return 1;
}
template <typename TString, typename TSpec>
inline typename Size<StringSet<TString, TSpec> >::Type
countSequences(StringSet<TString, TSpec> const & stringSet) {
return length(stringSet);
}
// --------------------------------------------------------------------------
// Function getSequenceByNo()
// --------------------------------------------------------------------------
template <typename TSeqNo, typename TString>
SEQAN_HOST_DEVICE inline typename GetSequenceByNo<TString>::Type
getSequenceByNo(TSeqNo /*seqNo*/, TString & string)
{
return string;
}
template <typename TSeqNo, typename TString, typename TSpec>
SEQAN_HOST_DEVICE inline typename GetSequenceByNo< StringSet<TString, TSpec> >::Type
getSequenceByNo(TSeqNo seqNo, StringSet<TString, TSpec> & stringSet)
{
return stringSet[seqNo];
}
template <typename TSeqNo, typename TString, typename TSpec>
SEQAN_HOST_DEVICE inline typename GetSequenceByNo< StringSet<TString, TSpec> const>::Type
getSequenceByNo(TSeqNo seqNo, StringSet<TString, TSpec> const & stringSet)
{
return stringSet[seqNo];
}
// --------------------------------------------------------------------------
// Function sequenceLength()
// --------------------------------------------------------------------------
template <typename TSeqNo, typename TText>
SEQAN_HOST_DEVICE inline typename Size< typename GetSequenceByNo<TText const>::Type>::Type
sequenceLength(TSeqNo seqNo, TText const & text)
{
return length(getSequenceByNo(seqNo, text));
}
// --------------------------------------------------------------------------
// Function _validStringSetLimits
// --------------------------------------------------------------------------
// TODO(holtgrew): Anti auto-stringset
template < typename T >
inline bool _validStringSetLimits(T const &) {
return true;
}
template < typename TString, typename TSpec >
inline bool _validStringSetLimits(StringSet< TString, TSpec > const & me) {
return me.limitsValid;
}
// --------------------------------------------------------------------------
// Function _refreshStringSetLimits
// --------------------------------------------------------------------------
template < typename T >
inline void _refreshStringSetLimits(T &) {}
template < typename TString, typename TSpec >
void _refreshStringSetLimits(StringSet< TString, TSpec > & me)
{
typedef StringSet< TString, TSpec > TStringSet;
typedef typename StringSetLimits<TStringSet>::Type TLimits;
typename Value<TLimits>::Type sum = 0;
typename Size<TStringSet>::Type len = length(me);
typename Size<TStringSet>::Type i = 0;
// SEQAN_ASSERT_EQ(length(me.limits), len + 1);
resize(me.limits, len + 1, Generous());
for(; i < len; ++i)
{
me.limits[i] = sum;
sum += length(me[i]);
SEQAN_ASSERT_LEQ(me.limits[i], sum);
}
me.limits[i] = sum;
me.limitsValid = true;
}
// --------------------------------------------------------------------------
// Function _findIthNonZeroValue()
// --------------------------------------------------------------------------
// find the i-th non-zero value of a string me
template < typename TValue, typename TSpec, typename TPos >
inline typename Size< String<TValue, TSpec> >::Type
_findIthNonZeroValue(String<TValue, TSpec> const & me, TPos i)
{
typename Iterator< String<TValue, TSpec> const, Standard >::Type it = begin(me, Standard());
typename Iterator< String<TValue, TSpec> const, Standard >::Type itEnd = end(me, Standard());
for(; it != itEnd; ++it)
if (*it)
{
if (i)
--i;
else
return position(it, me);
}
return length(me);
}
// --------------------------------------------------------------------------
// Function _countNonZeroValues()
// --------------------------------------------------------------------------
// count non-zero values before position i
template < typename TValue, typename TSpec, typename TPos >
inline typename Size< String<TValue, TSpec> >::Type
_countNonZeroValues(String<TValue, TSpec> const & me, TPos i)
{
typename Iterator< String<TValue, TSpec> const, Standard >::Type it = begin(me, Standard());
typename Iterator< String<TValue, TSpec> const, Standard >::Type itEnd = begin(me, Standard()) + i;
typename Size< String<TValue, TSpec> >::Type counter = 0;
for(; it != itEnd; ++it)
if (*it) ++counter;
return counter;
}
// --------------------------------------------------------------------------
// Function lengthSum()
// --------------------------------------------------------------------------
/*!
* @fn StringSet#lengthSum
* @brief Returns total length of all strings in the string set.
*
* @signature TSize lengthSum(s);
*
* @param s The string set to get length sum of.
*
* @return TSize The sum of the lengths of all strings in the string set.
*/
template <typename TString>
inline typename LengthSum<TString>::Type
lengthSum(TString const & me)
{
return length(me);
}
template <typename TString, typename TSpec>
inline typename LengthSum<StringSet<TString, TSpec> >::Type
lengthSum(StringSet<TString, TSpec> & me)
{
if (!_validStringSetLimits(me))
_refreshStringSetLimits(me);
return back(stringSetLimits(me));
}
template < typename TString, typename TSpec >
inline typename LengthSum<StringSet<TString, TSpec> >::Type
lengthSum(StringSet<TString, TSpec> const & me)
{
if (!_validStringSetLimits(me))
_refreshStringSetLimits(me);
return back(stringSetLimits(me));
}
// --------------------------------------------------------------------------
// Function length()
// --------------------------------------------------------------------------
///.Function.appendValue.param.target.type:Class.StringSet
///.Function.appendValue.class:Class.StringSet
///.Function.clear.param.object.type:Class.StringSet
///.Function.clear.class:Class.StringSet
///.Function.resize.param.object.type:Class.StringSet
///.Function.resize.class:Class.StringSet
///.Function.length.param.object.type:Class.StringSet
///.Function.length.class:Class.StringSet
template <typename TString, typename TSpec >
inline typename Size<StringSet<TString, TSpec > >::Type
length(StringSet<TString, TSpec > const & me)
{
return length(me.strings);
}
// --------------------------------------------------------------------------
// Function resize()
// --------------------------------------------------------------------------
// TODO(rmaerker): This belongs to string_set_base.h. Move it!
template <typename TString, typename TSpec, typename TSize, typename TExpand >
inline typename Size<StringSet<TString, TSpec > >::Type
resize(StringSet<TString, TSpec > & me, TSize new_size, Tag<TExpand> tag)
{
resize(me.limits, new_size + 1, tag);
me.limitsValid = (new_size == 0);
// the following would not work as changing the size of
// a single string cannot be recognized by the stringset
//
// if (_validStringSetLimits(me))
// resize(me.limits, new_size + 1, back(me.limits), tag);
return resize(me.strings, new_size, tag);
}
// --------------------------------------------------------------------------
// Function reserve()
// --------------------------------------------------------------------------
/*!
* @fn StringSet#reserve
* @brief Reserve memory for string set.
*
* @signature TSize reserver(s, newCapacity, tag);
*
* @param s The string set to reserve memory for.
* @param newCapacity The target capacity.
* @param tag A tag to select the reservation strategy.
*/
template <typename TString, typename TSpec, typename TSize, typename TExpand>
inline typename Size<StringSet<TString, TSpec > >::Type
reserve(StringSet<TString, TSpec > & me,
TSize const & new_capacity,
Tag<TExpand> tag)
{
reserve(me.limits, new_capacity + 1, tag);
return reserve(me.strings, new_capacity, tag);
}
// --------------------------------------------------------------------------
// Function iter()
// --------------------------------------------------------------------------
///.Function.iter.param.object.type:Class.StringSet
template <typename TString, typename TSpec, typename TPos, typename TTag>
inline typename Iterator<StringSet<TString, TSpec >, Tag<TTag> const>::Type
iter(StringSet<TString, TSpec > & me,
TPos pos,
Tag<TTag> const &)
{
typedef StringSet<TString, TSpec > TStringSet;
typedef typename Iterator<TStringSet, Tag<TTag> const>::Type TIterator;
typedef typename Position<TStringSet>::Type TPosition;
return TIterator(me, (TPosition) pos);
}
template <typename TString, typename TSpec, typename TPos, typename TTag>
inline typename Iterator<StringSet<TString, TSpec > const, Tag<TTag> const>::Type
iter(StringSet<TString, TSpec > const & me,
TPos pos,
Tag<TTag> const &)
{
typedef StringSet<TString, TSpec > const TStringSet;
typedef typename Iterator<TStringSet, Tag<TTag> const>::Type TIterator;
typedef typename Position<TStringSet>::Type TPosition;
return TIterator(me, (TPosition) pos);
}
// --------------------------------------------------------------------------
// Function begin()
// --------------------------------------------------------------------------
///.Function.begin.param.object.type:Class.StringSet
///.Function.begin.class:Class.StringSet
template <typename TString, typename TSpec, typename TTag>
inline typename Iterator<StringSet<TString, TSpec >, Tag<TTag> const>::Type
begin(StringSet<TString, TSpec > & me,
Tag<TTag> const & tag)
{
return iter(me, 0, tag);
}
template <typename TString, typename TSpec, typename TTag>
inline typename Iterator<StringSet<TString, TSpec > const, Tag<TTag> const>::Type
begin(StringSet<TString, TSpec > const & me,
Tag<TTag> const & tag)
{
return iter(me, 0, tag);
}
// --------------------------------------------------------------------------
// Function end()
// --------------------------------------------------------------------------
///.Function.end.param.object.type:Class.StringSet
///.Function.end.class:Class.StringSet
template <typename TString, typename TSpec, typename TTag>
inline typename Iterator<StringSet<TString, TSpec >, Tag<TTag> const>::Type
end(StringSet<TString, TSpec > & me,
Tag<TTag> const & tag)
{
return iter(me, length(me), tag);
}
template <typename TString, typename TSpec, typename TTag>
inline typename Iterator<StringSet<TString, TSpec > const, Tag<TTag> const>::Type
end(StringSet<TString, TSpec > const & me,
Tag<TTag> const & tag)
{
return iter(me, length(me), tag);
}
// --------------------------------------------------------------------------
// Function value()
// --------------------------------------------------------------------------
///.Function.value.param.object.type:Class.StringSet
///.Function.value.class:Class.StringSet
// --------------------------------------------------------------------------
// Function getValueById()
// --------------------------------------------------------------------------
/*!
* @mfn StringSet#Id
* @brief Return the id type for the string set.
*
* @signature Id<TStringSet>::Type
*
* @tparam TStringSet The string set type to query for its id type.
*
* @return Type The resulting ID type.
*/
/*!
* @fn StringSet#getValueById
* @brief Get the value from a string set by its id.
*
* @signature TString getValueById(s, id);
*
* @param s The string set to get string from.
* @param id The id of the string to get.
*
* @return TString Reference to the string with the given id.
*/
/**
.Function.getValueById:
..cat:Sequences
..class:Class.StringSet
..summary:Retrieves a string from the StringSet given an id.
..signature:getValueById(me, id)
..param.me:A StringSet.
...type:Class.StringSet
..param.id:An id.
...type:Metafunction.Id
..returns:A reference to a string.
..see:Function.assignValueById
..see:Function.valueById
..include:seqan/sequence.h
*/
// TODO(holtgrew): Why is there no generic implementation for StringSets??
// --------------------------------------------------------------------------
// Function valueById()
// --------------------------------------------------------------------------
/*!
* @fn StringSet#valueById
* @brief Get the value from a string set by its id.
*
* @signature TString valueById(s, id);
*
* @param s The string set to get string from.
* @param id The id of the string to get.
*
* @return TString Reference to the string with the given id.
*/
/**
.Function.valueById:
..cat:Sequences
..class:Class.StringSet
..summary:Retrieves a string from the StringSet given an id.
..signature:valueById(me, id)
..param.me:A StringSet.
...type:Class.StringSet
..param.id:An id.
...type:Metafunction.Id
..returns:A reference to a string.
..see:Function.assignValueById
..see:Function.getValueById
..include:seqan/sequence.h
*/
template<typename TString, typename TSpec, typename TId>
inline typename Reference<StringSet<TString, TSpec> >::Type
valueById(StringSet<TString, TSpec> & me,
TId const id)
{
SEQAN_CHECKPOINT;
return getValueById(me, id);
}
// --------------------------------------------------------------------------
// Function assignValueById()
// --------------------------------------------------------------------------
/*!
* @fn StringSet#assignValueById
* @brief Set the member of a string set by its id.
*
* @signature TId getValueById(set, s[, id]);
*
* @param set The string to assign value in.
* @param s The string set to assign.
* @param id The id of the string to set. If omitted, <tt>s</tt> will be appended to <tt>set</tt>.
*
* @return TId The id of the new string in the string set.
*/
/**
.Function.assignValueById:
..cat:Sequences
..class:Class.StringSet
..summary:Adds a new string to the StringSet and returns an id.
..signature:assignValueById(dest, str, [id])
..signature:assignValueById(dest, source, id)
..param.dest:A StringSet.
...type:Class.StringSet
..param.source:A StringSet.
...type:Class.StringSet
..param.str:A new string.
...type:Metafunction.Value
..param.id:An associated id.
...type:Metafunction.Id
..returns:A new id
...type:Metafunction.Id
..see:Function.getValueById
..see:Function.valueById
..include:seqan/sequence.h
*/
template<typename TString, typename TSpec, typename TString2>
inline typename Id<StringSet<TString, TSpec> >::Type
assignValueById(StringSet<TString, TSpec>& me,
TString2& obj)
{
SEQAN_CHECKPOINT;
appendValue(me, obj);
SEQAN_ASSERT_EQ(length(me.limits), length(me) + 1);
return length(me.strings) - 1;
}
template<typename TString, typename TSpec1, typename TSpec2, typename TId>
inline typename Id<StringSet<TString, TSpec1> >::Type
assignValueById(StringSet<TString, TSpec1>& dest,
StringSet<TString, TSpec2>& source,
TId id)
{
SEQAN_CHECKPOINT;
return assignValueById(dest, getValueById(source, id), id);
}
// --------------------------------------------------------------------------
// Function removeValueById()
// --------------------------------------------------------------------------
/*!
* @fn StringSet#removeValueById
* @brief Remove a value from a string set by its id.
*
* @signature void removeValueById(set, id);
*
* @param set The string to remove value in.
* @param id The id of the string to remove.
*/
/**
.Function.removeValueById:
..cat:Sequences
..class:Class.StringSet
..summary:Removes a string from the StringSet given an id.
..signature:removeValueById(me, id)
..param.me:A StringSet.
...type:Class.StringSet
..param.id:An id.
...type:Metafunction.Id
..returns:void
..see:Function.assignValueById
..include:seqan/sequence.h
*/
// TODO(holtgrew): Why is there no generic implementation for StringSets??
// --------------------------------------------------------------------------
// Function positionToId()
// --------------------------------------------------------------------------
/*!
* @fn StringSet#positionToId
* @brief Convert a position/index in the string set to a string id.
*
* @signature Id positionToId(set, pos);
*
* @param set The string to convert positions for.
* @param pos The position to convert.
*
* @return TId The resulting id.
*/
/**
.Function.positionToId:
..cat:Sequences
..class:Class.StringSet
..summary:Retrieves the id of a string in the StringSet given a position.
..signature:positionToId(string_set, pos)
..param.string_set:A StringSet.
...type:Class.StringSet
..param.pos:A position that is transfored into an id.
..returns:An id that corresponds to $pos$ within $string_set$
..see:Function.assignValueById
..see:Function.valueById
..include:seqan/sequence.h
*/
// TODO(holtgrew): Why is there no generic implementation for StringSets??
// --------------------------------------------------------------------------
// Function concat()
// --------------------------------------------------------------------------
/*!
* @fn StringSet#concat
* @brief Returns the concatenation sequence of all sequences in a string set.
*
* @signature TConcat concat(set);
*
* @param set The string set to get the concatenation sequence for.
*
* @return TConcat The concatenation sequence.
*/
/**
.Function.concat:
..summary:Returns the concatenation sequence of all sequences in a @Class.StringSet@.
..cat:Sequences
..class:Class.StringSet
..signature:concat(stringSet)
..param.stringSet:A @Class.StringSet@ object.
...type:Class.StringSet
..returns:A container that can be iterated like the concatenation string of all sequences in a @Class.StringSet@.
..remarks:If $stringSet$ is a @Spec.ConcatDirect@ StringSet a reference to $stringSet.concat$ is returned.
For all other StringSets a @Class.ConcatenatorManyToOne@ object is returned.
...type:Metafunction.Concatenator
..include:seqan/sequence.h
*/
// TODO(holtgrew): Why default concat() for any class?
template <typename TString>
SEQAN_HOST_DEVICE inline typename Concatenator<TString>::Type &
concat(TString & string)
{
return string;
}
// TODO(holtgrew): Why default concat() for any class?
template <typename TString>
SEQAN_HOST_DEVICE inline typename Concatenator<TString const>::Type &
concat(TString const & string)
{
return string;
}
template <typename TString, typename TSpec>
inline typename Concatenator<StringSet<TString, TSpec> >::Type &
concat(StringSet<TString, TSpec> & me)
{
me.concat.set = &me;
return me.concat;
}
template <typename TString, typename TSpec>
inline typename Concatenator<StringSet<TString, TSpec> const>::Type &
concat(StringSet<TString, TSpec> const & constMe)
{
StringSet<TString, TSpec> &me = const_cast<StringSet<TString, TSpec> &>(constMe);
me.concat.set = &me;
return me.concat;
}
// --------------------------------------------------------------------------
// Function strSplit()
// --------------------------------------------------------------------------
/*!
* @fn StringSet#strSplit
* @brief Append a list of the words in the string, using sep as the delimiter string @link StringSet @endlink.
*
* @signature void strSplit(result, sequence[, sep[, allowEmptyStrings[, maxSplit]]]);
*
* @param result The resulting string set.
* @param sequence The sequence to split.
* @param sep The splitter to use (default <tt>' '</tt>).
* @param allowEmptyString Whether or not to allow empty strings (<tt>bool</tt>, defaults to <tt>true</tt> iff
* <tt>sep</tt> is given).
* @param maxSplit The maximal number of split operations to do if given.
*
* @return TConcat The concatenation sequence.
*/
/**
.Function.stringSplit:
..summary:Append a list of the words in the string, using sep as the delimiter string @Class.StringSet@.
..cat:Sequences
..class:Class.StringSet
..signature:strSplit(stringSet, sequence)
..signature:strSplit(stringSet, sequence, sep)
..signature:strSplit(stringSet, sequence, sep, allowEmptyStrings)
..signature:strSplit(stringSet, sequence, sep, allowEmptyStrings, maxSplit)
..param.stringSet:The @Class.StringSet@ object the words are appended to.
...type:Class.StringSet
..param.sequence:A sequence of words.
..param.sep:Word separator (default: ' ').
..param.allowEmptyStrings:Boolean to specify whether empty words should be considered (default: true, iff sep is given).
..param.maxSplit:If maxsplit is given, at most maxsplit splits are done.
..include:seqan/sequence.h
*/
template <typename TString, typename TSpec, typename TSequence, typename TSeparator, typename TSize>
inline void
strSplit(StringSet<TString, TSpec> & result, TSequence const &sequence, TSeparator sep, bool allowEmptyStrings, TSize maxSplit)
{
typedef typename Iterator<TSequence const, Standard>::Type TIter;
TIter itBeg = begin(sequence, Standard());
TIter itEnd = end(sequence, Standard());
TIter itFrom = itBeg;
if (maxSplit == 0)
{
appendValue(result, sequence);
return;
}
for (TIter it = itBeg; it != itEnd; ++it)
if (*it == sep)
{
if (allowEmptyStrings || itFrom != it)
{
appendValue(result, infix(sequence, itFrom - itBeg, it - itBeg));
if (--maxSplit == 0)
{
if (!allowEmptyStrings)
{
while (it != itEnd && *it == sep)
++it;
}
else
++it;
if (it != itEnd)
appendValue(result, infix(sequence, it - itBeg, itEnd - itBeg));
return;
}
}
itFrom = it + 1;
}
if (allowEmptyStrings || itFrom != itEnd)
appendValue(result, infix(sequence, itFrom - itBeg, itEnd - itBeg));
}
template <typename TString, typename TSpec, typename TSequence, typename TSeparator>
inline void
strSplit(StringSet<TString, TSpec> & result, TSequence const &sequence, TSeparator sep, bool allowEmptyStrings)
{
strSplit(result, sequence, sep, allowEmptyStrings, maxValue<typename Size<TSequence>::Type>());
}
template <typename TString, typename TSpec, typename TSequence, typename TSeparator>
inline void
strSplit(StringSet<TString, TSpec> & result, TSequence const &sequence, TSeparator sep)
{
strSplit(result, sequence, sep, true);
}
template <typename TString, typename TSpec, typename TSequence>
inline void
strSplit(StringSet<TString, TSpec> & result, TSequence const &sequence)
{
strSplit(result, sequence, ' ', false);
}
// --------------------------------------------------------------------------
// Function idToPosition()
// --------------------------------------------------------------------------
/*!
* @fn StringSet#idToPosition
* @brief Convert a string id to a position/index in the string set.
*
* @signature TPos idToPosition(set, id);
*
* @param set The string to convert positions for.
* @param id The id to convert.
*
* @return The resulting position.
*/
/**
.Function.idToPosition:
..cat:Sequences
..class:Class.StringSet
..summary:Retrieves the position of a string in the StringSet given an id.
..signature:idToPosition(me, id)
..param.me:A StringSet.
...type:Class.StringSet
..param.id:An id.
...type:Metafunction.Id
..returns:A reference to a string.
..see:Function.assignValueById
..see:Function.valueById
..include:seqan/sequence.h
*/
// TODO(holtgrew): Why is there no generic implementation for StringSets??
// TODO(holtgrew): Should the following code be thrown away?
//template <typename TString, typename TSpec, typename TDestSpec, typename TIds, typename TLength>
//inline void
//subset(StringSet<TString, Owner<TSpec> >& source,
// StringSet<TString, TDestSpec>& dest,
// TIds ids,
// TLength len)
//{
//SEQAN_CHECKPOINT
//}
//template <typename TString, typename TIds, typename TLength>
//inline void
//subset(StringSet<TString, Dependent<Generous> >& source,
// StringSet<TString, Dependent<Generous> >& dest,
// TIds ids,
// TLength len)
//{
//SEQAN_CHECKPOINT
// typedef StringSet<TString, Dependent<Generous> > TStringSet;
// typedef typename Id<TStringSet>::Type TId;
// typedef typename Size<TStringSet>::Type TSize;
// clear(dest);
// resize(dest.limits, len + 1);
// dest.limitsValid = (len == 0);
// resize(dest.strings, length(source.strings), (TString*) 0);
// for(TSize i = 0; i < len; ++i)
// dest.strings[ids[i]] = source.strings[ids[i]];
//}
//template <typename TString, typename TIds, typename TLength>
//inline void
//subset(StringSet<TString, Dependent<Tight> >& source,
// StringSet<TString, Dependent<Tight> >& dest,
// TIds ids,
// TLength len)
//{
//SEQAN_CHECKPOINT
// typedef StringSet<TString, Dependent<Tight> > TStringSet;
// typedef typename Id<TStringSet>::Type TId;
// typedef typename Size<TStringSet>::Type TSize;
// clear(dest);
// resize(dest.limits, len + 1);
// dest.limitsValid = (len == 0);
// TLength upperBound = length(source.ids);
// for(TSize i=0;i<len;++i) {
// TId id = ids[i];
// if ((upperBound > id) &&
// (source.ids[id] == id)) {
// appendValue(dest.strings, source.strings[id]);
// appendValue(dest.ids, id);
// } else {
// typedef String<TId> TIdString;
// typedef typename Iterator<TIdString, Rooted>::Type TIter;
// TIter it = begin(source.ids);
// for(;!atEnd(it);goNext(it)) {
// if (*it == id) {
// appendValue(dest.strings, source.strings[position(it)]);
// appendValue(dest.ids, id);
// }
// }
// }
// }
//}
//template <typename TString, typename TSpec, typename TIds>
//inline void
//subset(StringSet<TString, TSpec>& source,
// StringSet<TString, TSpec>& dest,
// TIds ids)
//{
//SEQAN_CHECKPOINT
// subset(source, dest, ids, length(ids));
//}
} // namespace seqan
#endif // #ifndef SEQAN_SEQUENCE_STRING_SET_BASE_H_
|