/usr/include/Bpp/PopGen/SequenceStatistics.h is in libbpp-popgen-dev 2.2.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | //
// File SequenceStatistics.h
// Authors: Eric Bazin
// Sylvain Gaillard
// Khalid Belkhir
// Benoit Nabholz
// Created on: Wed Aug 04 2004
//
/*
Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
This software is a computer program whose purpose is to provide classes
for population genetics analysis.
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
*/
// Secured inclusion of header's file
#ifndef _SEQUENCESTATISTICS_H_
#define _SEQUENCESTATISTICS_H_
// From the bpp-seq library
#include <Bpp/Seq/SymbolListTools.h>
#include <Bpp/Seq/Alphabet/CodonAlphabet.h>
#include <Bpp/Seq/GeneticCode/GeneticCode.h>
#include <Bpp/Seq/Container/SiteContainerIterator.h>
#include <Bpp/Seq/Container/SiteContainer.h>
#include <Bpp/Seq/Container/SiteContainerTools.h>
#include "PolymorphismSequenceContainer.h"
// From the STL
#include <string>
#include <map>
#include <vector>
namespace bpp
{
/**
* @brief Static class providing methods to compute statistics on sequences data.
*
* @author Sylvain Gaillard
*/
class SequenceStatistics
{
public:
/**
* @brief Compute the number of polymorphic site in an alignment
*
* The number of polymorphic site is also known as the number of
* segregating site @f$S@f$.
*
* Gaps are consider as mutations so if you want number of
* polymorphic site without gap, set the gapflag parameter to true.
*
* @param psc a PolymorphismSequenceContainer
* @param gapflag a boolean set by default to true if you don't want to
* take gap into account
* @param ignoreUnknown a boolean set by default to true to ignore
* unknown states
*/
static unsigned int numberOfPolymorphicSites(
const PolymorphismSequenceContainer& psc,
bool gapflag = true,
bool ignoreUnknown = true);
/**
* @brief Compute the number of parsimony informative sites in an alignment
*
* @param psc a PolymorphicSequenceContainer
* @param gapflag a boolean set by default to true if you don't want to
* take gap into account
*/
static unsigned int numberOfParsimonyInformativeSites(
const PolymorphismSequenceContainer& psc,
bool gapflag = true);
/**
* @brief Count the number of singleton nucleotides in an alignment.
*
* @param psc a PolymorphismSequenceContainer
* @param gapflag a boolean set by default to true if you don't want to
* take gap into account
* @author Sylvain Gaillard
*/
static unsigned int numberOfSingletons(
const PolymorphismSequenceContainer& psc,
bool gapflag = true);
/**
* @brief Count the total number of mutations in an alignment.
*
* This count is assumed to be under an infinite site model.
*
* @param psc a PolymorphismSequenceContainer
* @param gapflag a boolean set by default to true if you don't want to
* take gap into account
* @author Sylvain Gaillard
*/
static unsigned int totalNumberOfMutations(
const PolymorphismSequenceContainer& psc,
bool gapflag = true);
/**
* @brief Count the total number of mutations in external branchs.
*
* This is counted as the number of distinct singleton nucleotide
* in the ingroup that are not shared with the outgroup.
* A site is ignored if it contains more than one variant in the outgroup.
* A site is ignored if it contains unresolved variants or gaps.
*
* @param ing a PolymorphismSequenceContainer the ingroup alignement
* @param outg a PolymorphismSequenceContainer the outgroup alignement
* @throw Exception if ing and outg are not of the same size (site number)
* @author Khalid Belkhir
*/
static unsigned int totalNumberOfMutationsOnExternalBranches(
const PolymorphismSequenceContainer& ing,
const PolymorphismSequenceContainer& outg)
throw (Exception);
/**
* @brief Compute the number of triplet in an alignment
*
* @param psc a PolymorphismSequenceContainer
* @param gapflag a boolean set by default to true if you don't want to take gap into account
* @author Sylvain Glémin
*/
static unsigned int numberOfTriplets(
const PolymorphismSequenceContainer& psc,
bool gapflag = true);
/**
* @brief Compute the sum of per site heterozygosity in an alignment
*
* @param psc a PolymorphismSequenceContainer
* @param gapflag a boolean set by default to true if you don't want to take gap into account
*/
static double heterozygosity(
const PolymorphismSequenceContainer& psc,
bool gapflag = true);
/**
* @brief Compute the sum of per site squared heterozygosity in an alignment
*
* @param psc a PolymorphismSequenceContainer
* @param gapflag a boolean set by default to true if you don't want
* to take gap into account
*/
static double squaredHeterozygosity(
const PolymorphismSequenceContainer& psc,
bool gapflag = true);
/**
* @brief Compute the mean GC content in an alignment
*
* @param psc a PolymorphismSequenceContainer
*/
static double gcContent(
const PolymorphismSequenceContainer& psc);
/**
* @brief Return the number of GC alleles and the total number of alleles at polymorphic sites only
*
* G vs C and A vs T polymorphism are not taken into account
*
* @warning SG 15/03/2010: The code of this method is not clear. See
* implementation for more details.
*
* @param psc a PolymorphismSequenceContainer
* @param gapflag a boolean set by default to true if you don't want
* to take gap into account
* @return A std::vector of size 2 containing the number of GC alleles
* and the total number of alleles.
*/
static std::vector<unsigned int> gcPolymorphism(
const PolymorphismSequenceContainer& psc,
bool gapflag = true);
/**
* @brief Compute diversity estimator Theta of Watterson (1975, Theor Popul Biol, 7 pp256-276)
*
* @f[
* \hat{\theta}_S=\frac{S}{a_1}
* @f]
* where @f$S@f$ is the number of polymorphic sites and @f$a_1@f$ is
* describe in SequenceStatistics::getUsefulValues_().
*
* @param psc a PolymorphismSequenceContainer
* @param gapflag flag set by default to true if you don't want to
* take gap into account
* @param ignoreUnknown a boolean set by default to true to ignore
* unknown states
* @author Sylvain Gaillard
*/
static double watterson75(
const PolymorphismSequenceContainer& psc,
bool gapflag = true,
bool ignoreUnknown = true);
/**
* @brief Compute diversity estimator Theta of Tajima (1983, Genetics, 105 pp437-460)
*
* @f[
* \hat{\theta}_\pi = \sum_{i=1}^{S} \left(1-\sum_{j=1}^{4} \frac{k_{j,i}\times\left(k_{j,i}-1\right)}
* {n_i\times\left(n_i-1\right)}\right) \qquad \textrm{with }k_{j,i}>0
* @f]
* where @f$k_{j,i}@f$ is the count of the j<sup>th</sup> state at the
* i<sup>th</sup> site,
* @f$n_i@f$ the number of nucleotides and @f$S@f$ the number of
* polymorphic sites.
*
* @param psc a PolymorphismSequenceContainer
* @param gapflag flag set by default to true if you don't want to
* take gap into account
* @author Sylvain Gaillard
*/
static double tajima83(
const PolymorphismSequenceContainer& psc,
bool gapflag = true);
/**
* @brief Compute diversity estimator Theta H (eq. 3) of Fay and Wu (2000, Genetics, 155: 1405-1413)
*
* @param psc a PolymorphismSequenceContainer
* @param ancestralSites a Sequence containing the ancestral states
* (reconstructed independently) to fold the mutation in the psc SequenceContainer.
@author Benoit Nabholz
*/
static double fayWu2000(
const PolymorphismSequenceContainer& psc,
const Sequence& ancestralSites);
/**
* @brief Return the number of haplotype in the sample.
* Depaulis and Veuille (1998, Mol Biol Evol, 12 pp1788-1790)
*
* @param psc a PolymorphismSequenceContainer
* @param gapflag flag set by default to true if you don't want to
* take gap into account
* @author Éric Bazin
* @todo
* - remove unneeded Sequence Container recopy
* - work on Sequence rather than string
*/
static unsigned int dvk(
const PolymorphismSequenceContainer& psc,
bool gapflag = true);
/**
* @brief Return the haplotype diversity of a sample.
* Depaulis and Veuille (1998, Mol Biol Evol, 12 pp1788-1790)
*
* @param psc a PolymorphismSequenceContainer
* @param gapflag flag set by default to true if you don't want to
* take gaps into account
* @author Éric Bazin
* @todo
* - remove unneeded Sequence Container recopy
* - work on Sequence rather on string
*/
static double dvh(
const PolymorphismSequenceContainer& psc,
bool gapflag = true);
/**
* @brief Return the number of transitions.
*
* @param psc a PolymorphismSequenceContainer
* @author Éric Bazin
*/
static unsigned int numberOfTransitions(
const PolymorphismSequenceContainer& psc);
/**
* @brief Return the number of transversions.
*
* @param psc a PolymorphismSequenceContainer
* @author Éric Bazin
*/
static unsigned int numberOfTransversions(
const PolymorphismSequenceContainer& psc);
/**
* @brief Return the ratio of transitions/transversions.
*
* @param psc a PolymorphismSequenceContainer
* @author Éric Bazin
*/
static double ratioOfTransitionsTransversions(
const PolymorphismSequenceContainer& psc )
throw (Exception);
/**
* @brief Compute the number of codon sites with stop codon
*
* @param psc a PolymorphismSequenceContainer
* @param gCode the genetic code to use
* @param gapflag a boolean set by default to true if you don't want to
* take gaps into account
* @author Sylvain Glémin
*/
static unsigned int numberOfSitesWithStopCodon(
const PolymorphismSequenceContainer& psc,
const GeneticCode& gCode,
bool gapflag = true);
/**
* @brief Compute the number of polymorphic codon with only one mutated site
*
* @param psc a PolymorphismSequenceContainer
* @param stopflag a boolean set by default to true if you don't want
* to take stop codon neither undefined sites into account
* @param gapflag a boolean set by default to true if you don't want
* to take gaps into account
* @author Sylvain Glémin
* @bug Sylvain Gaillard 17/03/2010: stopflag don't work as expected
* because CompleteSiteIterator don't skip stop codon.
*/
static unsigned int numberOfMonoSitePolymorphicCodons(
const PolymorphismSequenceContainer& psc,
bool stopflag = true,
bool gapflag = true);
/**
* @brief Compute the number of synonymous polymorphic codon sites
*
* Gaps and unresolved sites are automatically excluded
*
* @param psc a PolymorphismSequenceContainer
* @param gc a GeneticCode
* @author Sylvain Glémin
* @author Éric Bazin
*/
static unsigned int numberOfSynonymousPolymorphicCodons(
const PolymorphismSequenceContainer& psc,
const GeneticCode& gc);
/**
* @brief Compute the Watterson(1975,Theor Popul Biol, 7 pp256-276) estimator for synonymous positions
*
* Gaps and unresolved sites are automatically excluded
*
* In case of complex codon, the path that gives the minimum number of
* non-synonymous changes* is chosen. The argument minchange=true is sent
* to numberOfSynonymousDifferences used in this method.
* Otherwise, a non-integer number could be return.
*
* @param psc a PolymorphismSequenceContainer
* @param gc a GeneticCode
* @author Sylvain Glémin
*/
static double watterson75Synonymous(
const PolymorphismSequenceContainer& psc,
const GeneticCode& gc);
/**
* @brief Compute the Watterson(1975, Theor Popul Biol, 7 pp256-276) estimator for non synonymous positions
*
* Gaps and unresolved sites are automatically excluded
*
* In case of complex codon, the path that gives the minimum number of
* non-synonymous changes is chosen. The argument minchange=true is sent
* to numberOfSynonymousDifferences used in this method.
* Otherwise, a non-integer number could be return.
*
* @param psc a PolymorphismSequenceContainer
* @param gc a GeneticCode
* @author Sylvain Glémin
*/
static double watterson75NonSynonymous(
const PolymorphismSequenceContainer& psc,
const GeneticCode& gc);
/**
* @brief Compute the synonymous nucleotide diversity, pi
*
* Gaps and unresolved sites are automatically excluded
* If minchange = false (default option) the different paths are equally
* weighted.
* If minchange = true the path with the minimum number of non-synonymous
* change is chosen.
*
* @param psc a PolymorphismSequenceContainer
* @param gc a GeneticCode
* @param minchange a boolean set to false
* @author Sylvain Glémin
* @author Éric Bazin
*/
static double piSynonymous(
const PolymorphismSequenceContainer& psc,
const GeneticCode& gc,
bool minchange = false);
/**
* @brief Compute the non-synonymous nucleotide diversity, pi
*
* Gaps and unresolved sites are automatically excluded
* If minchange = false (default option) the different paths are equally
* weighted.
* If minchange = true the path with the minimum number of non-synonymous
* change is chosen.
*
* @param psc a PolymorphismSequenceContainer
* @param gc a GeneticCode
* @param minchange a boolean set by default to false
* @author Sylvain Glémin
* @author Éric Bazin
*/
static double piNonSynonymous(
const PolymorphismSequenceContainer& psc,
const GeneticCode& gc,
bool minchange = false);
/**
* @brief compute the mean number of synonymous site in an alignment
*
* A site is x% synonymous if x% of possible mutations are synonymous.
* The transition/transversion can be taken into account (use the
* variable ratio).
* Gaps and unresolved sites are automatically excluded.
*
* @param psc a PolymorphismSequenceContainer
* @param gc a GeneticCode
* @param ratio a double
* @author Sylvain Glémin
* @author Éric Bazin
*/
static double meanNumberOfSynonymousSites(
const PolymorphismSequenceContainer& psc,
const GeneticCode& gc,
double ratio = 1.);
/**
* @brief compute the mean number of non-synonymous site in an alignment
*
* A site is x% synonymous if x% of possible mutations are synonymous
* The transition/transversion can be taken into account (use the
* variable ratio).
* Gaps are automatically excluded
*
* @param psc a PolymorphismSequenceContainer
* @param gc a GeneticCode
* @param ratio a double
* @author Éric Bazin
*/
static double meanNumberOfNonSynonymousSites(
const PolymorphismSequenceContainer& psc,
const GeneticCode& gc,
double ratio = 1.);
/**
* @brief compute the number of synonymous subsitutions in an alignment
*
* Gaps and unresolved sites are automatically excluded
*
* In case of complex codon, the path that gives the minimum number of
* non-synonymous changes is chosen. The argument minchange=true is sent
* to numberOfSynonymousDifferences used in this method.
* Otherwise, a non-integer number could be return.
*
* @param psc a PolymorphismSequenceContainer
* @param gc a GeneticCode
* @param freqmin a double, to exclude snp in frequency strictly lower
* than freqmin
*/
static unsigned int numberOfSynonymousSubstitutions(
const PolymorphismSequenceContainer& psc,
const GeneticCode& gc,
double freqmin = 0.);
/**
* @brief compute the number of non synonymous subsitutions in an alignment
*
* Gaps and unresolved sites are automatically excluded
*
* In case of complex codon, the path that gives the minimum number of
* non-synonymous changes is chosen. The argument minchange=true is sent
* to numberOfSynonymousDifferences used in this method.
* Otherwise, a non-integer number could be return.
*
* @param psc a PolymorphismSequenceContainer
* @param gc a GeneticCode
* @param freqmin a double, to exclude snp in frequency strictly lower
* than freqmin
*/
static unsigned int numberOfNonSynonymousSubstitutions(
const PolymorphismSequenceContainer& psc,
const GeneticCode& gc,
double freqmin = 0.);
/**
* @brief compute the number of fixed differences between two alignements
*
* Gaps and unresolved sites are automatically excluded
*
* In case of complex codon, the path that gives the minimum number of
* non-synonymous changes is chosen. The argument minchange=true is sent
* to numberOfSynonymousDifferences used in this method.
* Otherwise, a non-integer number could be return.
* @param pscin a PolymorphismSequenceContainer
* @param pscout a PolymorphismSequenceContainer
* @param psccons a PolymorphismSequenceContainer
* @param gc a GeneticCode
* @author Sylvain Glémin
* @bug Sylvain Gaillard 17.03.2010: should throw something if pscin,
* pscout and psccons have different length (site number).
*/
static std::vector<unsigned int> fixedDifferences(
const PolymorphismSequenceContainer& pscin,
const PolymorphismSequenceContainer& pscout,
PolymorphismSequenceContainer& psccons,
const GeneticCode& gc);
/**
* @brief return a vector containing Pa, Ps, Da, Ds
*
* Gaps and unresolved sites are automatically excluded
* @param ingroup a PolymorphismSequenceContainer
* @param outgroup a PolymorphismSequenceContainer
* @param gc a GeneticCode
* @param freqmin a double, to exclude snp in frequency strictly lower
* than freqmin
* @author Sylvain Glémin
*/
static std::vector<unsigned int> mkTable(
const PolymorphismSequenceContainer& ingroup,
const PolymorphismSequenceContainer& outgroup,
const GeneticCode& gc,
double freqmin = 0.);
/**
* @brief return the neutrality index NI = (Pa/Ps)/(Da/Ds) (Rand & Kann 1996, Mol. Biol. Evol. 13 pp735-748)
*
* Return -1 if Ps or Da are zero
* Gaps and unresolved sites are automatically excluded
*
* @param ingroup a PolymorphismSequenceContainer
* @param outgroup a PolymorphismSequenceContainer
* @param gc a GeneticCode
* @param freqmin a double, to exclude snp in frequency strictly lower
* than freqmin
* @author Sylvain Glémin
*/
static double neutralityIndex(
const PolymorphismSequenceContainer& ingroup,
const PolymorphismSequenceContainer& outgroup,
const GeneticCode& gc,
double freqmin = 0.);
/**
* @brief Return the Tajima's D test (Tajima 1989, Genetics 123 pp 585-595).
*
* Calculation using the number of polymorphic (segregating) sites.
* @f[
* D=\frac{\hat{\theta}_\pi-\hat{\theta}_S}{\sqrt{\textrm{V}\left(\hat{\theta}_\pi-\hat{\theta}_S\right)}}
* =\frac{\hat{\theta}_\pi-\hat{\theta}_S}{\sqrt{e_1S+e_2S(S-1)}}
* @f]
*
* @param psc a PolymorphismSequenceContainer
* @param gapflag flag set by default to true if you don't want to
* take gap into account
* @throw ZeroDivisionException if S == 0
* @author Sylvain Gaillard
*/
static double tajimaDss(
const PolymorphismSequenceContainer& psc,
bool gapflag = true)
throw (ZeroDivisionException);
/**
* @brief Return the Tajima's D test (Tajima 1989, Genetics 123 pp 585-595).
*
* Calculation using the total number of mutation.
* @f[
* D=\frac{\hat{\theta}_\pi-\frac{\eta}{a_1}}{\sqrt{e_1\eta+e_2\eta(\eta-1)}}
* @f]
* @param psc a PolymorphismSequenceContainer
* @param gapflag flag set by default to true if you don't want to
* take gap into account
* @throw ZeroDivisionException if eta == 0
* @author Sylvain Gaillard
*/
static double tajimaDtnm(
const PolymorphismSequenceContainer& psc,
bool gapflag = true)
throw (ZeroDivisionException);
/**
* @brief Return the Fu and Li D test (Fu & Li 1993, Genetics, 133 pp693-709).
*
* @param ingroup a PolymorphismSequenceContainer
* @param outgroup a PolymorphismSequenceContainer
* @param original true: use the Fu & Li methode, false: use mutations in
* external branch.
* @throw ZeroDivisionException if eta == 0
* @author Sylvain Gaillard
* @author Khalid Belkhir
*
* If one set original=false then the number of mutations will be used.
* If the outgroup contains more than one sequence the sites with more
* than one variant will not be considered for external branch mutations!
*/
static double fuLiD(
const PolymorphismSequenceContainer& ingroup,
const PolymorphismSequenceContainer& outgroup,
bool original = true)
throw (ZeroDivisionException);
/**
* @brief Return the Fu and Li D<sup>*</sup> test (Fu & Li 1993, Genetics, 133 pp693-709).
*
* @param group a PolymorphismSequenceContainer
* @author Sylvain Gaillard
*/
static double fuLiDStar(
const PolymorphismSequenceContainer& group)
throw (ZeroDivisionException);
/**
* @brief Return the Fu and Li F test (Fu & Li 1993, Genetics, 133 pp693-709).
*
* @param ingroup a PolymorphismSequenceContainer
* @param outgroup a PolymorphismSequenceContainer
* @param original true: use the Fu & Li methode, false: use mutations in
* external branch.
* @author Sylvain Gaillard
* @author Khalid Belkhir
*
* If one set original=false then the number of mutations will be used.
* If the outgroup contains more than one sequence the sites with more
* than one variant will not be considered for external branch mutations!
*/
static double fuLiF(
const PolymorphismSequenceContainer& ingroup,
const PolymorphismSequenceContainer& outgroup,
bool original = true)
throw (ZeroDivisionException);
/**
* @brief Return the Fu and Li F<sup>*</sup> test (Fu & Li 1993, Genetics, 133 pp693-709).
*
* @param group a PolymorphismSequenceContainer
* @author Sylvain Gaillard
*/
static double fuLiFStar(
const PolymorphismSequenceContainer& group)
throw (ZeroDivisionException);
/**
* Fst of Hudson, Slatkin and Maddison
*
* Taken from eq. 3 of Hudson, Slatkin and Maddison 1992 Genetics 132:153
*
* @f[
* F_{st} = 1 - \frac{H_w}{H_b}
* @f]
* where @f$H_w@f$ is mean number of differences between different
* sequences sampled from the same subpopulation, and @f$H_b@f$ is the
* mean number of differences between sequences sampled from the two
* different subpopulations sampled.
*
* @param psc a PolymorphismSequenceContainer will at least two populations
* @param id1 is the id of the population 1
* @param id2 is the id of the population 2
* @author Benoit Nabholz
*/
double fstHudson92(
const PolymorphismSequenceContainer& psc,
size_t id1,
size_t id2);
/**
* @brief generate a special PolymorphismSequenceContainer for linkage disequilbrium analysis
*
* Create a PolymorphismSequenceContainer with only polymorphic site :
* The value 1 is assigned to the most frequent allele, and 0 to the
* least frequent.
* This psc is needed to compute Linkage Disequilibrium
* Statistics.
* Should be used before excluding gaps, but sites with gaps are not
* counted as polymorphic sites.
* Singleton can be excluded.
* Polymorphic site with the lowest frequency < threshold can be excluded.
* Only polymorphic sites with 2 alleles are kept.
*
* @param psc a PolymorphismSequenceContainer
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @author Sylvain Glémin
* @bug Sylvain Gaillard 17/03/2010: Needs cleaning and lack of tests
* of usability. This methode assume that psc as a DNA alphabet but don't
* check for conformity.
* @todo
* - To be moved to PolymorphismSequenceContainerTools.
*/
static PolymorphismSequenceContainer* generateLdContainer(
const PolymorphismSequenceContainer& psc,
bool keepsingleton = true,
double freqmin = 0.);
/**
* @brief give the vector of the pairwise distances between site positions corresponding to a LD SequencePolymorphismContainer
*
* Assume that all sequences have the same length
*
* @param psc a PolymorphismSequenceContainer
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites is lower than 2
* @author Sylvain Glémin
*/
static Vdouble pairwiseDistances1(
const PolymorphismSequenceContainer& psc,
bool keepsingleton = true,
double freqmin = 0.)
throw (DimensionException);
/**
* @brief give the vector of all mean pairwise distance between two sites to a LD SequencePolymorphismContainer
*
* pairwise distances are computed for each sequence separately,
* excluding gaps. Then the mean is taken over all the sequences.
*
* @param psc a PolymorphismSequenceContainer
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites is lower than 2
* @author Sylvain Glémin
*/
static Vdouble pairwiseDistances2(
const PolymorphismSequenceContainer& psc,
bool keepsingleton = true,
double freqmin = 0.)
throw (DimensionException);
/**
* @brief give the vector of all mean pairwise D value between two sites (Lewontin & Kojima 1964, Evolution 14 pp458-472)
*
* @param psc a PolymorphismSequenceContainer
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites or the number of
* sequences is lower than 2
* @author Sylvain Glémin
*/
static Vdouble pairwiseD(
const PolymorphismSequenceContainer& psc,
bool keepsingleton = true,
double freqmin = 0.)
throw (DimensionException);
/**
* @brief give the vector of all mean pairwise D' value between two sites (Lewontin 1964, Genetics 49 pp49-67))
*
* @param psc a PolymorphismSequenceContainer
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites or the number of
* sequences is lower than 2
* @author Sylvain Glémin
*/
static Vdouble pairwiseDprime(
const PolymorphismSequenceContainer& psc,
bool keepsingleton = true,
double freqmin = 0.)
throw (DimensionException);
/**
* @brief give the vector of all mean pairwise R² value between two sites (Hill & Robertson 1968, Theor. Appl. Genet., 38 pp226-231)
*
* @param psc a PolymorphismSequenceContainer
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites or the number of
* sequences is lower than 2
* @author Sylvain Glémin
*/
static Vdouble pairwiseR2(
const PolymorphismSequenceContainer& psc,
bool keepsingleton = true,
double freqmin = 0.)
throw (DimensionException);
/**
* @brief give mean D over all pairwise comparisons
*
* @param psc a PolymorphismSequenceContainer
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites or the number of
* sequences is lower than 2
* @author Sylvain Glémin
*/
static double meanD(
const PolymorphismSequenceContainer& psc,
bool keepsingleton = true,
double freqmin = 0.)
throw (DimensionException);
/**
* @brief give mean D' over all pairwise comparisons
*
* @param psc a PolymorphismSequenceContainer
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites or the number of
* sequences is lower than 2
* @author Sylvain Glémin
*/
static double meanDprime(
const PolymorphismSequenceContainer& psc,
bool keepsingleton = true,
double freqmin = 0.)
throw (DimensionException);
/**
* @brief give mean R² over all pairwise comparisons
*
* @param psc a PolymorphismSequenceContainer
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites or the number of
* sequences is lower than 2
* @author Sylvain Glémin
*/
static double meanR2(
const PolymorphismSequenceContainer& psc,
bool keepsingleton = true,
double freqmin = 0.)
throw (DimensionException);
/**
* @brief give mean pairwise distances between sites / method 1: differences between sequences are not taken into account
*
* @param psc a PolymorphismSequenceContainer
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites is lower than 2
* @author Sylvain Glémin
*/
static double meanDistance1(
const PolymorphismSequenceContainer& psc,
bool keepsingleton = true,
double freqmin = 0.)
throw (DimensionException);
/**
* @brief give mean pairwise distances between sites / method 2: differences between sequences are taken into account
*
* @param psc a PolymorphismSequenceContainer
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites is lower than 2
* @author Sylvain Glémin
*/
static double meanDistance2(
const PolymorphismSequenceContainer& psc,
bool keepsingleton = true,
double freqmin = 0.)
throw (DimensionException);
/**
* @brief give the slope of the regression |D| = 1+a*distance
*
* The slope is given in |D| per kb
*
* @param psc a PolymorphismSequenceContainer
* @param distance1 a boolean (true to use distance1, false to use
* distance2, false by default)
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites or the number of
* sequences is lower than 2
* @author Sylvain Glémin
*/
static double originRegressionD(
const PolymorphismSequenceContainer& psc,
bool distance1 = false,
bool keepsingleton = true,
double freqmin = 0.)
throw (DimensionException);
/**
* @brief give the slope of the regression |D'| = 1+a*distance
*
* The slope is given in |D'| per kb
*
* @param psc a PolymorphismSequenceContainer
* @param distance1 a boolean (true to use distance1, false to use
* distance2, false by default)
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites or the number of
* sequences is lower than 2
* @author Sylvain Glémin
*/
static double originRegressionDprime(
const PolymorphismSequenceContainer& psc,
bool distance1 = false,
bool keepsingleton = true,
double freqmin = 0.)
throw (DimensionException);
/**
* @brief give the slope of the regression R² = 1+a*distance
*
* The slope is given in R² per kb
*
* @param psc a PolymorphismSequenceContainer
* @param distance1 a boolean (true to use distance1, false to use
* distance2, false by default)
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites or the number of
* sequences is lower than 2
* @author Sylvain Glémin
*/
static double originRegressionR2(
const PolymorphismSequenceContainer& psc,
bool distance1 = false,
bool keepsingleton = true,
double freqmin = 0.)
throw (DimensionException);
/**
* @brief give the slope and the origin of the regression |D| = a*distance+b
*
* The slope is given in |D| per kb
*
* @param psc a PolymorphismSequenceContainer
* @param distance1 a boolean (true to use distance1, false to use
* distance2, false by default)
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites or the number of
* sequences is lower than 2
* @author Sylvain Glémin
*/
static Vdouble linearRegressionD(
const PolymorphismSequenceContainer& psc,
bool distance1 = false,
bool keepsingleton = true,
double freqmin = 0.)
throw (DimensionException);
/**
* @brief give the slope and the origin of the regression |D'| = a*distance+b
*
* The slope is given in |D'| per kb
*
* @param psc a PolymorphismSequenceContainer
* @param distance1 a boolean (true to use distance1, false to use
* distance2, false by default)
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites or the number of
* sequences is lower than 2
* @author Sylvain Glémin
*/
static Vdouble linearRegressionDprime(
const PolymorphismSequenceContainer& psc,
bool distance1 = false,
bool keepsingleton = true,
double freqmin = 0.) throw (DimensionException);
/**
* @brief give the slope and the origin of the regression R² = a*distance+b
*
* The slope is given in R² per kb
*
* @param psc a PolymorphismSequenceContainer
* @param distance1 a boolean (true to use distance1, false to use
* distance2, false by default)
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites or the number of
* sequences is lower than 2
* @author Sylvain Glémin
*/
static Vdouble linearRegressionR2(
const PolymorphismSequenceContainer& psc,
bool distance1 = false,
bool keepsingleton = true,
double freqmin = 0.)
throw (DimensionException);
/**
* @brief give the slope of the regression R² = 1/(1+a*distance)
*
* To fit the theoretical prediction R² = 1/(1+4Nr)
* The slope is given in R² per kb
*
* @param psc a PolymorphismSequenceContainer
* @param distance1 a boolean (true to use distance1, false to use
* distance2, false by default)
* @param keepsingleton a boolean (true by default, false to exclude
* singleton)
* @param freqmin a float (to exlude site with the lowest allele
* frequency less than the threshold given by freqmin, 0 by default)
* @throw DimensionException if the number of sites or the number of
* sequences is lower than 2
* @author Sylvain Glémin
*/
static double inverseRegressionR2(
const PolymorphismSequenceContainer& psc,
bool distance1 = false,
bool keepsingleton = true,
double freqmin = 0.)
throw (DimensionException);
/**
* @brief give estimate of C=4Nr using Hudson method (Hudson 1987, Genet. Res., 50 pp245-250)
*
* @param psc a PolymorphismSequenceContainer
* @param precision default value = 0.000001
* @param cinf initial value, by default cinf=0.001
* @param csup initial value, by default csup = 10000
* @author Sylvain Glémin
*/
static double hudson87(
const PolymorphismSequenceContainer& psc,
double precision = 0.000001,
double cinf = 0.001,
double csup = 10000.);
/**
* @brief Test useful values
* @param s a ostream where write the values
* @param n then number of observed sequences
* @author Sylvain Gaillard
*/
static void testUsefulValues(
std::ostream& s,
size_t n);
private:
/**
* @brief Count the number of mutation for a site.
*/
static unsigned int getNumberOfMutations_(const Site& site);
/**
* @brief Count the number of singleton for a site.
*/
static unsigned int getNumberOfSingletons_(const Site& site);
/**
* @brief Count the number of singleton for a site.
*
* will count singletons that are not in site_out (a site in outgroup)
* site_in is a site from an ingroup
* @author Khalid Belkhir
*/
static unsigned getNumberOfDerivedSingletons_(
const Site& site_in,
const Site& site_out);
/**
* @brief Get useful values for theta estimators.
*
* @param n the number of observed sequences
*
* @return A map with 11 values. Keys are a1, a2, a1n, b1, b2, c1, c2,
* cn, dn, e1 and e2.
* The values are :
* @f[
* a_1=\sum_{i=1}^{n-1}\frac{1}{i} \qquad a_2=\sum_{i=1}^{n-1}\frac{1}{i^2}
* @f]
* @f[
* a_{1n}=\sum_{i=1}^{n}\frac{1}{i}
* @f]
* @f[
* b_1=\frac{n+1}{3(n-1)} \qquad b_2=\frac{2(n^2+n+3)}{9n(n-1)}
* @f]
* @f[
* c_1=b_1-\frac{1}{a_1} \qquad c_2=b_2-\frac{n+2}{a_1n}+\frac{a_2}{a_1^2}
* @f]
* @f[
* c_n=2\frac{na_1-2(n-1)}{(n-1)(n-2)}
* @f]
* @f[
* d_n=c_n+\frac{n-2}{(n-1)^2}+\frac{2}{n-1}\left(\frac{3}{2}-\frac{2a_{1n}-3}{n-2}-\frac{1}{n}\right)
* @f]
* @f[
* e_1=\frac{c_1}{a_1} \qquad e_2=\frac{c_2}{a_1^2+a_2}
* @f]
* where @f$n@f$ is the number of observed sequences.
*
* @author Sylvain Gaillard
*/
static std::map<std::string, double> getUsefulValues_(
size_t n);
/**
* @brief Get the vD value of equation (32) in Fu & Li 1993, Genetics, 133 pp693-709)
*
* @param n the number of observed sequences
* @param a1 as describe in getUsefulValues
* @param a2 as describe in getUsefulValues
* @param cn as describe in getUsefulValues
*
* @return the vD value as double
*
* @author Sylvain Gaillard
*/
static double getVD_(
size_t n,
double a1,
double a2,
double cn);
/**
* @brief Get the uD value of equation (32) in Fu & Li 1993, Genetics, 133 pp693-709)
*
* @param a1 as describe in getUsefulValues
* @param vD as provided by getVD_
*
* @return the uD value as double
*
* @author Sylvain Gaillard
*/
static double getUD_(
double a1,
double vD);
/**
* @brief Get the vD* value of D* equation in Fu & Li 1993, Genetics, 133 pp693-709)
*
* @param n the number of observed sequences
* @param a1 as describe in getUsefulValues
* @param a2 as describe in getUsefulValues
* @param dn as describe in getUsefulValues
*
* @return the vD* value as double
*
* @author Sylvain Gaillard
*/
static double getVDstar_(
size_t n,
double a1,
double a2,
double dn);
/**
* @brief Get the uD* value of D* equation in Fu & Li 1993, Genetics, 133 pp693-709)
*
* @param n the number of observed sequences
* @param a1 as describe in getUsefulValues
* @param vDs as provided by getVDstar_
*
* @return the uD* value as double
*
* @author Sylvain Gaillard
*/
static double getUDstar_(
size_t n,
double a1,
double vDs);
/**
* @brief give the left hand term of equation (4) in Hudson (Hudson 1987, Genet. Res., 50 pp245-250)
* This term is used in hudson87
* @param psc a PolymorphismSequenceContainer
*/
static double leftHandHudson_(
const PolymorphismSequenceContainer& psc);
/**
* @brief give the right hand term of equation (4) in Hudson (Hudson 1987, Genet. Res., 50 pp245-250)
* This term is used in hudson87
*/
static double rightHandHudson_(
double c,
size_t n);
/************************************************************************/
};
} // end of namespace bpp;
#endif // _SEQUENCESTATISTICS_H_
|