Skip to content

Commit 569a0d4

Browse files
committed
Merge pull request #24 from camaclean/fixbinning
Fixed binning
2 parents 69dd33e + 06bd023 commit 569a0d4

File tree

7 files changed

+17
-13
lines changed

7 files changed

+17
-13
lines changed

src/calcmpiselect.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <omp.h>
3131
#endif
3232

33-
void calcIhsMpi(const std::string& hapfile, const std::string& mapfile, const std::string& outfile, double cutoff, double minMAF, double scale, double binFactor)
33+
void calcIhsMpi(const std::string& hapfile, const std::string& mapfile, const std::string& outfile, double cutoff, double minMAF, double scale, int binFactor)
3434
{
3535
std::cout << "Calculating iHS using MPI." << std::endl;
3636
HapMap hap;
@@ -138,7 +138,7 @@ void calcIhsMpi(const std::string& hapfile, const std::string& mapfile, const st
138138
delete manager;
139139
}
140140

141-
void calcXpehhMpi(const std::string& hapA, const std::string& hapB, const std::string& mapfile, const std::string& outfile, double cutoff, double minMAF, double scale, double binFactor)
141+
void calcXpehhMpi(const std::string& hapA, const std::string& hapB, const std::string& mapfile, const std::string& outfile, double cutoff, double minMAF, double scale, int binFactor)
142142
{
143143
std::cout << "Calculating XPEHH using MPI." << std::endl;
144144
HapMap mA, mB;

src/calcnompiselect.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <omp.h>
2626
#endif
2727

28-
void calcIhsNoMpi(const std::string& hap, const std::string& map, const std::string& outfile, double cutoff, double minMAF, double scale, double binFactor)
28+
void calcIhsNoMpi(const std::string& hap, const std::string& map, const std::string& outfile, double cutoff, double minMAF, double scale, int bins)
2929
{
3030
HapMap ctcmap;
3131
if (!ctcmap.loadHap(hap.c_str()))
@@ -38,7 +38,7 @@ void calcIhsNoMpi(const std::string& hap, const std::string& map, const std::str
3838
#endif
3939
ctcmap.loadMap(map.c_str());
4040
auto start = std::chrono::high_resolution_clock::now();
41-
IHSFinder *ihsfinder = new IHSFinder(ctcmap.snpLength(), cutoff, minMAF, scale, binFactor);
41+
IHSFinder *ihsfinder = new IHSFinder(ctcmap.snpLength(), cutoff, minMAF, scale, bins);
4242
ihsfinder->run(&ctcmap, 0ULL, ctcmap.numSnps());
4343
IHSFinder::LineMap res = ihsfinder->normalize();
4444

@@ -63,7 +63,7 @@ void calcIhsNoMpi(const std::string& hap, const std::string& map, const std::str
6363
delete ihsfinder;
6464
}
6565

66-
void calcXpehhNoMpi(const std::string& hapA, const std::string& hapB, const std::string& map, const std::string& outfile, double cutoff, double minMAF, double scale, double binFactor)
66+
void calcXpehhNoMpi(const std::string& hapA, const std::string& hapB, const std::string& map, const std::string& outfile, double cutoff, double minMAF, double scale, int bins)
6767
{
6868
HapMap hA, hB;
6969
if (!hA.loadHap(hapA.c_str()))
@@ -81,7 +81,7 @@ void calcXpehhNoMpi(const std::string& hapA, const std::string& hapB, const std:
8181
#endif
8282
hA.loadMap(map.c_str());
8383
auto start = std::chrono::high_resolution_clock::now();
84-
IHSFinder *ihsfinder = new IHSFinder(hA.snpLength(), cutoff, minMAF, scale, binFactor);
84+
IHSFinder *ihsfinder = new IHSFinder(hA.snpLength(), cutoff, minMAF, scale, bins);
8585
ihsfinder->runXpehh(&hA, &hB, 0ULL, hA.numSnps());
8686

8787
auto tend = std::chrono::high_resolution_clock::now();

src/config.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@
2424
#cmakedefine VECLEN @VECLEN@
2525
#cmakedefine VERSION "@VERSION@"
2626
#cmakedefine VERSION_SHORT "@VERSION_SHORT@"
27+
#if !defined(VERSION_SHORT) || !defined(VERSION)
28+
#define VERSION_SHORT "Live"
29+
#define VERSION "HEAD"
30+
#endif

src/ihsfinder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
#include "ihsfinder.hpp"
2121

22-
IHSFinder::IHSFinder(std::size_t snpLength, double cutoff, double minMAF, double scale, double binFactor)
23-
: m_snpLength(snpLength), m_cutoff(cutoff), m_minMAF(minMAF), m_scale(scale), m_binFactor(binFactor), m_counter{}, m_reachedEnd{}, m_outsideMaf{}, m_nanResults{}
22+
IHSFinder::IHSFinder(std::size_t snpLength, double cutoff, double minMAF, double scale, int bins)
23+
: m_snpLength(snpLength), m_cutoff(cutoff), m_minMAF(minMAF), m_scale(scale), m_bins(bins), m_counter{}, m_reachedEnd{}, m_outsideMaf{}, m_nanResults{}
2424
{}
2525

2626
void IHSFinder::processEHH(const EHH& ehh, std::size_t line)
@@ -43,7 +43,7 @@ void IHSFinder::processEHH(const EHH& ehh, std::size_t line)
4343
return;
4444
}
4545

46-
freqs = nearest(m_binFactor, ehh.num/(double)m_snpLength);
46+
freqs = ((int) (m_bins*ehh.num/(double)m_snpLength))/(double)m_bins;
4747

4848
if (ehh.iHH_a > 0)
4949
{

src/ihsfinder.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class IHSFinder
3838
using FreqVecMap = std::map<double, std::vector<double>>;
3939
using StatsMap = std::map<double, Stats>;
4040

41-
IHSFinder(std::size_t snpLength, double cutoff, double minMAF, double scale, double binFactor);
41+
IHSFinder(std::size_t snpLength, double cutoff, double minMAF, double scale, int bins);
4242
FreqVecMap unStdIHSByFreq() const { return m_unStandIHSByFreq; }
4343
LineMap unStdIHSByLine() const { return m_unStandIHSByLine; }
4444
LineMap freqsByLine() const { return m_freqsByLine; }
@@ -61,7 +61,7 @@ class IHSFinder
6161
double m_cutoff;
6262
double m_minMAF;
6363
double m_scale;
64-
double m_binFactor;
64+
int m_bins;
6565

6666
std::mutex m_mutex;
6767
std::mutex m_freqmutex;

src/main-ihs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int main(int argc, char** argv)
4343
Argument<std::string> map('m', "map", "Map file", false, false, "");
4444
Argument<double> cutoff('c', "cutoff", "EHH cutoff value (default: 0.05)", false, false, 0.05);
4545
Argument<double> minMAF('f', "minmaf", "Minimum allele frequency (default: 0.05)", false, false, 0.05);
46-
Argument<double> binfac('b', "bin", "Frequency bin size (default: 0.02)", false, false, 0.02);
46+
Argument<int> binfac('b', "bin", "Number of frequency bins for iHS normalization (default: 50)", false, false, 50);
4747
Argument<unsigned long long> scale('s', "scale", "Gap scale parameter in bp, used to scale gaps > scale parameter as in Voight, et al.", false, false, 20000);
4848
Argument<std::string> outfile('o', "out", "Output file", false, false, "out.txt");
4949
ArgParse argparse({&help, &version, &hap, &map, &outfile, &cutoff, &minMAF, &scale, &binfac}, "Usage: ihsbin --map input.map --hap input.hap [--ascii] [--out outfile]");

src/main-xpehh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int main(int argc, char** argv)
4545
Argument<std::string> map('m', "map", "Map file", false, false, "");
4646
Argument<double> cutoff('c', "cutoff", "EHH cutoff value (default: 0.05)", false, false, 0.05);
4747
Argument<double> minMAF('f', "minmaf", "Minimum allele frequency (default: 0.05)", false, false, 0.00);
48-
Argument<double> binfac('b', "bin", "Frequency bin size (default: 0.02)", false, false, 0.02);
48+
Argument<int> binfac('b', "bin", "Number of frequency bins for iHS normalization (default: 50)", false, false, 50);
4949
Argument<unsigned long long> scale('s', "scale", "Gap scale parameter in bp, used to scale gaps > scale parameter as in Voight, et al.", false, false, 20000);
5050
Argument<std::string> outfile('o', "out", "Output file", false, false, "out.txt");
5151
ArgParse argparse({&help, &version, &hapA, &hapB, &map, &outfile, &cutoff, &minMAF, &scale, &binfac}, "Usage: xpehhbin --map input.map --hapA inputA.hap --hapB inputB.hap");

0 commit comments

Comments
 (0)