libsequence  1.9.5
pairwiseld.cc
1 #include <Sequence/summstats/ld.hpp>
2 #include <Sequence/VariantMatrix.hpp>
3 
4 #include <vector>
5 namespace Sequence
6 {
7  struct PairwiseLDStats
8  {
9  double i, j, rsq, D, Dprime;
10  bool skipped;
11  };
12 
13  PairwiseLDStats
14  pairwise_ld_details(const VariantMatrix& m, const std::size_t i,
15  const std::size_t j, const std::int8_t refstate)
16  {
17  auto counts = two_locus_haplotype_counts(m, i, j, false);
18 
19  //We must have two alleles at each state and the reference
20  //allele at each state
21  int ref_i = 0, ref_j = 0, nonref_i = 0, nonref_j = 0, num_nonref_i = 0,
22  num_nonref_j = 0;
23  int num_nonref_nonref = 0;
24  for (auto& c : counts)
25  {
26  if (c.i == refstate)
27  {
28  ref_i += c.n;
29  }
30  else if (c.i >= 0)
31  {
32  nonref_i += c.n;
33  ++num_nonref_i;
34  }
35  if (c.j == refstate)
36  {
37  ref_j += c.n;
38  }
39  else if (c.j >= 0)
40  {
41  nonref_j += c.n;
42  ++num_nonref_j;
43  }
44  }
45  }
46 
47  std::vector<PairwiseLDStats>
48  pairwise_ld(const Sequence::VariantMatrix& m, const std::int8_t refstate)
49  {
50  std::vector<PairwiseLDStats> rv;
51  if (m.data.empty() || m.positions.empty() || !m.nsam || !m.nsites
52  || m.nsites < 2)
53  {
54  return rv;
55  }
56  for (std::size_t i = 0; i < m.nsites - 1; ++i)
57  {
58  for (std::size_t j = i + 1; j < m.nsites; ++j)
59  {
60  }
61  }
62  return rv;
63  }
64 } // namespace Sequence
The namespace in which this library resides.
std::size_t nsites
Number of sites in data set.
std::vector< double > positions
Position of sites.
Matrix representation of variation data.
std::size_t nsam
Sample size of data set.
std::vector< std::int8_t > data
Data stored in matrix form with rows as sites.