This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from molpopgen/lHaf
Add l-Haf statistic from VariantMatrix. #35
- Loading branch information
Showing
8 changed files
with
111 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
pkgincludedir=$(prefix)/include/Sequence/summstats | ||
|
||
pkginclude_HEADERS = classics.hpp thetapi.hpp thetaw.hpp thetah.hpp thetal.hpp auxillary.hpp nvariablesites.hpp allele_counts.hpp \ | ||
util.hpp ld.hpp nSLiHS.hpp nsl.hpp nslx.hpp garud.hpp generic.hpp \ | ||
util.hpp ld.hpp nSLiHS.hpp nsl.hpp nslx.hpp garud.hpp generic.hpp lhaf.hpp \ | ||
algorithm.hpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef SEQUENCE_SUMMSTATS_LHAF_HPP | ||
#define SEQUENCE_SUMMSTATS_LHAF_HPP | ||
|
||
#include <cstdint> | ||
#include <vector> | ||
#include <Sequence/VariantMatrix.hpp> | ||
|
||
namespace Sequence | ||
{ | ||
/*! \brief l-Haf statistic of \cite Ronen2015-te | ||
* \param m A VariantMatrix | ||
* \param refstate The ancstral state | ||
* \param l The power parameter | ||
* \return vector of the statistic | ||
* \ingroup popgenanalysis | ||
*/ | ||
std::vector<double> lhaf(const VariantMatrix &m, | ||
const std::int8_t refstate, const double l); | ||
} // namespace Sequence | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <cstdint> | ||
#include <algorithm> | ||
#include <numeric> | ||
#include <cmath> | ||
#include <Sequence/VariantMatrix.hpp> | ||
#include <Sequence/VariantMatrixViews.hpp> | ||
|
||
namespace Sequence | ||
{ | ||
std::vector<double> | ||
lhaf(const VariantMatrix &m, const std::int8_t refstate, const double l) | ||
{ | ||
std::vector<long int> dcounts; | ||
dcounts.reserve(m.nsites); | ||
const auto find_nonref = [refstate](const std::int8_t x) { | ||
return x != refstate && !(x < 0); | ||
}; | ||
for (std::size_t i = 0; i < m.nsites; ++i) | ||
{ | ||
auto r = get_ConstRowView(m, i); | ||
dcounts.push_back( | ||
std::count_if(r.begin(), r.end(), find_nonref)); | ||
} | ||
|
||
// Get the values for each element in the data | ||
std::vector<double> rv; | ||
rv.reserve(m.nsites); | ||
for (std::size_t i = 0; i < m.nsam; ++i) | ||
{ | ||
auto c = get_ConstColView(m, i); | ||
auto j = std::find_if(c.cbegin(), c.cend(), find_nonref); | ||
double score = 0.0; | ||
while (j != c.cend()) | ||
{ | ||
size_t d2 = static_cast<std::size_t>( | ||
std::distance(c.cbegin(), j)); | ||
score += std::pow(static_cast<double>(dcounts[d2]), l); | ||
j = std::find_if(c.cbegin(), c.cend(), find_nonref); | ||
} | ||
rv.push_back(score); | ||
} | ||
return rv; | ||
} | ||
} // namespace Sequence |