Skip to content

Commit

Permalink
update lasso
Browse files Browse the repository at this point in the history
  • Loading branch information
shajoezhu committed Oct 6, 2018
1 parent 0eb1304 commit cf00fdf
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 34 deletions.
2 changes: 1 addition & 1 deletion DEploid-Lasso-lib
27 changes: 14 additions & 13 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ TESTS = unit_tests
check_PROGRAMS = unit_tests dEploid_dbg dEploid_prof
PROG = DEPLOID

common_flags = -std=c++0x -Isrc/ -Isrc/codeCogs/ -Isrc/random/ -Isrc/gzstream/ -DDEPLOIDVERSION=\"${DEPLOIDVERSION}\" -DCOMPILEDATE=\"${COMPILEDATE}\"
common_flags = -std=c++0x -Isrc/ -Isrc/codeCogs/ -Isrc/random/ -Isrc/gzstream/ -DDEPLOIDVERSION=\"${DEPLOIDVERSION}\" -DCOMPILEDATE=\"${COMPILEDATE}\" -IDEploid-Lasso-lib/src/
common_LDADD = -lz

common_src = src/random/fastfunc.cpp \
Expand All @@ -33,9 +33,11 @@ common_src = src/random/fastfunc.cpp \
src/gzstream/gzstream.cpp \
src/export/dEploidIOExport.cpp \
src/export/dEploidIOExportPosteriorProb.cpp \
src/export/writeMcmcRelated.cpp
src/export/writeMcmcRelated.cpp \
DEploid-Lasso-lib/src/dEploidLasso.cpp

debug_src = src/debug/mcmcDebug.cpp src/debug/vcfReaderDebug.cpp
debug_src = src/debug/mcmcDebug.cpp src/debug/vcfReaderDebug.cpp \
DEploid-Lasso-lib/src/dEploidLassoDBG.cpp

dEploid_SOURCES = src/dEploid.cpp $(common_src)
dEploid_dbg_SOURCES = $(debug_src) $(dEploid_SOURCES)
Expand All @@ -51,16 +53,15 @@ dEploid_prof_LDADD = $(common_LDADD)

unit_tests_SOURCES = $(common_src) \
tests/unittest/test_runner.cpp \
tests/unittest/test_dEploidIO.cpp

# tests/unittest/test_ibd.cpp \
# tests/unittest/test_updateSingleHap.cpp \
# tests/unittest/test_utilities.cpp \
# tests/unittest/test_panel.cpp \
# tests/unittest/test_txtReader.cpp \
# tests/unittest/test_mcmc.cpp \
# tests/unittest/test_updatePairHap.cpp \
# tests/unittest/test_vcfReader.cpp
tests/unittest/test_dEploidIO.cpp \
tests/unittest/test_ibd.cpp \
tests/unittest/test_updateSingleHap.cpp \
tests/unittest/test_utilities.cpp \
tests/unittest/test_panel.cpp \
tests/unittest/test_txtReader.cpp \
tests/unittest/test_mcmc.cpp \
tests/unittest/test_updatePairHap.cpp \
tests/unittest/test_vcfReader.cpp

unit_tests_CXXFLAGS = $(common_flags) -DNDEBUG -DUNITTEST -Wno-write-strings --coverage
unit_tests_LDADD = -lcppunit -ldl $(common_LDADD)
Expand Down
8 changes: 2 additions & 6 deletions src/dEploid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,8 @@ int main(int argc, char *argv[]) {
} else if (dEploidIO.doIbdPainting()) {
dEploidIO.paintIBD();
} else if (dEploidIO.useLasso()) {
dEploidIO.computeObsWsaf();
// for loop, for each chromosome
// First produce reference panels
// run mcmc on chromsome by chromosome
// collect chromosome
cout << "to do" << endl;
dEploidIO.dEploidLasso();
//cout << "to do" << endl;
} else {
if (dEploidIO.useIBD()) { // ibd
McmcSample * ibdMcmcSample = new McmcSample();
Expand Down
40 changes: 36 additions & 4 deletions src/dEploidIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "updateHap.hpp" // chromPainting
#include "dEploidIO.hpp"
#include "ibd.hpp"
#include "dEploidLasso.hpp"

DEploidIO::DEploidIO() {
this->init();
Expand Down Expand Up @@ -791,10 +792,41 @@ void DEploidIO::computeAdjustedEffectiveKstrain() {
}


void DEploidIO::computeObsWsaf() {
for ( size_t i = 0; i < nLoci(); i++) {
double wsaf = this->altCount_[i] / (this->refCount_[i] + this->altCount_[i] + 0.00000000000001);
obsWsaf_.push_back(wsaf);
vector <double> DEploidIO::lassoComputeObsWsaf(size_t segmentStartIndex, size_t nLoci) {
vector <double> ret(nLoci, 0.0);
for ( size_t i = 0; i < nLoci; i++) {
size_t idx = i + segmentStartIndex;
ret[i] = this->altCount_[idx] / (this->refCount_[idx] + this->altCount_[idx] + 0.00000000000001);
}
return ret;
}


vector < vector <double> > DEploidIO::lassoSubsetPanel(size_t segmentStartIndex, size_t nLoci) {
vector < vector <double> > ret;
for ( size_t i = 0; i < nLoci; i++) {
size_t idx = i + segmentStartIndex;
ret.push_back(this->panel->content_[idx]);
}
return ret;
}


void DEploidIO::dEploidLasso() {
for ( size_t chromi = 0 ; chromi < this->indexOfChromStarts_.size(); chromi++ ) {
size_t start = this->indexOfChromStarts_[chromi];
size_t length = this->position_[chromi].size();
cout << " lasso Chrom with index " << chromi << ", starts at "<< start << ", with " << length << " sites" << endl;
vector <double> wsaf = lassoComputeObsWsaf(start, length);
vector < vector <double> > tmpPanel = lassoSubsetPanel(start, length);
DEploidLASSO dummy(tmpPanel, wsaf, 250);

////dummy.printResults();

// for loop, for each chromosome
// First produce reference panels
// run mcmc on chromsome by chromosome
// collect chromosome
}
}

5 changes: 4 additions & 1 deletion src/dEploidIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class DEploidIO{
double ibdLLK_;
void getIBDprobsIntegrated(vector < vector <double> > &prob);
// Lasso related
void computeObsWsaf();
void dEploidLasso();

// Log
void wrapUp();
Expand Down Expand Up @@ -382,6 +382,9 @@ class DEploidIO{
double adjustedEffectiveKstrain_;
void computeAdjustedEffectiveKstrain();

// Lasso related
vector <double> lassoComputeObsWsaf(size_t segmentStartIndex, size_t nLoci);
vector < vector <double> > lassoSubsetPanel(size_t segmentStartIndex, size_t nLoci);
};

#endif
17 changes: 8 additions & 9 deletions tests/unittest/test_dEploidIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,15 +823,14 @@ class TestIO : public CppUnit::TestCase {
"-lasso" };
CPPUNIT_ASSERT_NO_THROW(DEploidIO(10, argv));
DEploidIO dEploidIOlasso(10, argv);
CPPUNIT_ASSERT_NO_THROW(dEploidIOlasso.computeObsWsaf());
CPPUNIT_ASSERT_EQUAL(dEploidIOlasso.obsWsaf_.size(), (size_t)594);
CPPUNIT_ASSERT_DOUBLES_EQUAL(dEploidIOlasso.obsWsaf_[0], 0, epsilon3);
CPPUNIT_ASSERT_DOUBLES_EQUAL(dEploidIOlasso.obsWsaf_[4],
0.22772277, epsilon2);
CPPUNIT_ASSERT_DOUBLES_EQUAL(dEploidIOlasso.obsWsaf_[11],
0.21111111, epsilon2);
CPPUNIT_ASSERT_DOUBLES_EQUAL(dEploidIOlasso.obsWsaf_[589],
0.18324607, epsilon2);
//CPPUNIT_ASSERT_EQUAL(dEploidIOlasso.obsWsaf_.size(), (size_t)594);
//CPPUNIT_ASSERT_DOUBLES_EQUAL(dEploidIOlasso.obsWsaf_[0], 0, epsilon3);
//CPPUNIT_ASSERT_DOUBLES_EQUAL(dEploidIOlasso.obsWsaf_[4],
//0.22772277, epsilon2);
//CPPUNIT_ASSERT_DOUBLES_EQUAL(dEploidIOlasso.obsWsaf_[11],
//0.21111111, epsilon2);
//CPPUNIT_ASSERT_DOUBLES_EQUAL(dEploidIOlasso.obsWsaf_[589],
//0.18324607, epsilon2);
}
};

Expand Down

0 comments on commit cf00fdf

Please sign in to comment.