libsequence  1.9.5
PolySNPtest.cc
1 #include <Sequence/PolySites.hpp>
2 #include <Sequence/PolySNP.hpp>
3 #include <boost/test/unit_test.hpp>
4 #include <fstream>
5 #include <iostream>
6 #include <set>
7 #include <algorithm>
8 #include <limits>
9 #include <cmath>
10 
11 BOOST_AUTO_TEST_SUITE(PolySNPTest)
12 
13 BOOST_AUTO_TEST_CASE( check_empty_table )
14 {
15  Sequence::PolySites d; //empty data table
16  Sequence::PolySNP ad(&d);
17 
18  //Estimators of theta = 4Neu, numbers of various types of polymorhpisms
19  BOOST_CHECK_EQUAL( ad.ThetaPi(), 0. );
20  BOOST_CHECK_EQUAL( ad.ThetaH(), 0. );
21  BOOST_CHECK_EQUAL( std::isnan(ad.ThetaL()), true );
22  BOOST_CHECK_EQUAL( ad.NumPoly(), 0 );
23  BOOST_CHECK_EQUAL( ad.NumMutations(), 0 );
24  BOOST_CHECK_EQUAL( ad.NumSingletons(), 0 );
25 
26  //This behavior differs from PolySIM.
27  //For PolySIM, if there are no data, the entire block is assumed to be
28  //a matrix of n x L 0s (zeros). In other words, the entire region is
29  //monomorphic for the ancestral state
30  //Here, the n x L region has no variation, but you have no idea that
31  //the sites are monomorphic for ancestral vs derived character states,
32  //hence we return an "impossible" value
33  BOOST_CHECK_EQUAL( ad.NumExternalMutations(), std::numeric_limits<unsigned>::max() );
34 
35  //Variance on theta estimators that no one in their right mind should use
36  //other than for teaching
37  BOOST_CHECK( std::isnan(ad.VarThetaW()) );
38  BOOST_CHECK( std::isnan(ad.VarPi()) );
39  BOOST_CHECK( std::isnan(ad.SamplingVarPi()) );
40  BOOST_CHECK( std::isnan(ad.StochasticVarPi()) );
41 
42  //Haplotype-related stats
43  /*
44  This may seem confusing. But, and empty PolyTable means no segregating sites.
45  But, PolyTables come after filtering. Further, a SimData is
46  assumed to be based on a sample of size n > 0, thus there is a minimum of 1
47  haplotype
48  */
49  BOOST_CHECK_EQUAL( ad.DandVK(), 1 ); // No. unique haps
50  BOOST_CHECK_EQUAL( ad.DandVH(), 0. ); // Haplotype diversity
51  BOOST_CHECK( std::isnan(ad.WallsB()) );
52  BOOST_CHECK( std::isnan(ad.WallsQ()) );
53  BOOST_CHECK_EQUAL( ad.WallsBprime(), 0. );
54  BOOST_CHECK_EQUAL( ad.Minrec(), std::numeric_limits<unsigned>::max() );
55 
56  //Classic summaries of the site-frequency spectrum
57  BOOST_CHECK( std::isnan(ad.TajimasD()) );
58  BOOST_CHECK( std::isnan(ad.Dnominator()) );
59  BOOST_CHECK( std::isnan(ad.FuLiD()) );
60  BOOST_CHECK( std::isnan(ad.FuLiF()) );
61  BOOST_CHECK( std::isnan(ad.FuLiDStar()) );
62  BOOST_CHECK( std::isnan(ad.FuLiFStar()) );
63  BOOST_CHECK( std::isnan(ad.Hprime()) );
64 
65  //Other stats
66  BOOST_CHECK( std::isnan(ad.HudsonsC()) );
67  BOOST_CHECK( ad.Disequilibrium().empty() );
68 }
69 BOOST_AUTO_TEST_SUITE_END()
Polymorphism tables for sequence data.
Definition: PolySites.hpp:33
Molecular population genetic analysis.
Definition: PolySNP.hpp:86
declaration of Sequence::PolySNP, a class to analyze SNP data
Sequence::PolySites, generates polymorphism tables from data.