Skip to content

Commit

Permalink
Merge pull request #153 from mcveanlab/DEploid-r
Browse files Browse the repository at this point in the history
DEploid-r version v0.3-beta.1
  • Loading branch information
shajoezhu authored Oct 14, 2016
2 parents c0d75c3 + 57feebf commit 0255a63
Show file tree
Hide file tree
Showing 37 changed files with 688 additions and 386 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
*.a
*.lib

# Backup file generated while rewriting r scripts
utilities/dataExplore.r.bak
utilities/interpretDEploid.r.bak

# Executables
*.exe
*.out
Expand Down Expand Up @@ -79,3 +83,6 @@ vcf.*
*.gcov
libbash_test.info
test_coverage/

# Doxyfile
docs/doxygen/Doxyfile
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ before_script:
script:
- make
- make check
- ./tests/test_binary.sh
- if [ $TRAVIS_OS_NAME == linux ]; then ./tests/test_binary.sh; fi
- ./tests/testPOS.sh
- ./tests/test_binaryVcfVsTxt.sh
- ./tests/test-against-previous-version.sh
Expand Down
21 changes: 11 additions & 10 deletions src/dEploid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* This file is part of dEploid.
*
* scrm is free software: you can redistribute it and/or modify
* dEploid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
Expand All @@ -18,8 +18,8 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*
*/

#include <iostream> // std::cout
#include "mcmc.hpp"
Expand All @@ -30,17 +30,16 @@ using namespace std;

int main( int argc, char *argv[] ){
try {

DEploidIO dEploidIO;
(void)dEploidIO.core( argc, argv );
DEploidIO dEploidIO(argc, argv);
std::ostream *output = &std::cout;

if ( dEploidIO.version() ){
dEploidIO.printVersion();
dEploidIO.printVersion(*output);
return EXIT_SUCCESS;
}

if ( dEploidIO.help() ){
dEploidIO.printHelp();
dEploidIO.printHelp(*output);
return EXIT_SUCCESS;
}

Expand All @@ -58,12 +57,14 @@ int main( int argc, char *argv[] ){
}

McmcSample * mcmcSample = new McmcSample();
MersenneTwister rg(dEploidIO.randomSeed());

McmcMachinery mcmcMachinery(&dEploidIO, panel, mcmcSample);
mcmcMachinery.runMcmcChain();
McmcMachinery mcmcMachinery(&dEploidIO, panel, mcmcSample, &rg);
mcmcMachinery.runMcmcChain(true);

dEploidIO.write(mcmcSample, panel);

rg.clearFastFunc();
if ( panel ){
delete panel;
}
Expand Down
104 changes: 63 additions & 41 deletions src/dEploidIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* This file is part of dEploid.
*
* scrm is free software: you can redistribute it and/or modify
* dEploid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
Expand All @@ -18,21 +18,40 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "dEploidIO.hpp"
#include "utility.hpp" // normailize by sum
#include <cassert> // assert
#include <iomanip> // std::setw
#include <ctime>
#include <iterator>


DEploidIO::DEploidIO(){
this->init();
}


DEploidIO::DEploidIO(const std::string &arg) {
this->init();
std::istringstream iss(arg);
copy(std::istream_iterator<std::string>(iss),
std::istream_iterator<std::string>(),
std::back_inserter(argv_));
this->argv_i = argv_.begin();
this->core();
}


DEploidIO::DEploidIO(int argc, char *argv[]) {
this->init();
argv_ = std::vector<std::string>(argv + 1, argv + argc);
this->argv_i = argv_.begin();
this->core();
}


DEploidIO::~DEploidIO(){
if ( this->excludedMarkers != NULL ){
delete this->excludedMarkers;
Expand All @@ -45,10 +64,7 @@ DEploidIO::~DEploidIO(){
}


void DEploidIO::core(int argc, char *argv[]) {
argv_ = std::vector<std::string>(argv + 1, argv + argc);
this->argv_i = argv_.begin();

void DEploidIO::core() {
if ( argv_.size() == 0 ) {
this->set_help(true);
return;
Expand Down Expand Up @@ -394,41 +410,47 @@ void DEploidIO::readNextStringto( string &readto ){
}


void DEploidIO::printVersion(){
cout << endl
<< "dEploid " << VERSION
<< endl
<< "Git commit: " << dEploidGitVersion_ << endl;
void DEploidIO::printVersion(std::ostream& out){
out << endl
<< "dEploid " << VERSION
<< endl
<< "Git commit: " << dEploidGitVersion_ << endl;
}

void DEploidIO::printHelp(std::ostream& out){
out << endl
<< "dEploid " << VERSION
<< endl
<< endl;
out << "Usage:"
<< endl;
out << setw(20) << "-h or -help" << " -- " << "Help. List the following content."<<endl;
out << setw(20) << "-v or -version" << " -- " << "DEploid version."<<endl;
out << setw(20) << "-ref STR" << " -- " << "File path of reference allele count."<<endl;
out << setw(20) << "-alt STR" << " -- " << "File path of alternative allele count."<<endl;
out << setw(20) << "-plaf STR" << " -- " << "File path of population level allele frequencies."<<endl;
out << setw(20) << "-panel STR" << " -- " << "File path of the reference panel."<<endl;
out << setw(20) << "-exclude STR" << " -- " << "File path of sites to be excluded."<<endl;
out << setw(20) << "-o STR" << " -- " << "Specify the file name prefix of the output."<<endl;
out << setw(20) << "-p INT" << " -- " << "Out put precision (default value 8)."<<endl;
out << setw(20) << "-k INT" << " -- " << "Number of strain (default value 5)."<<endl;
out << setw(20) << "-seed INT" << " -- " << "Random seed."<<endl;
out << setw(20) << "-nSample INT" << " -- " << "Number of MCMC samples."<<endl;
out << setw(20) << "-rate INT" << " -- " << "MCMC sample rate."<<endl;
out << setw(20) << "-noPanel" << " -- " << "Use population level allele frequency as prior."<<endl;
out << setw(20) << "-forbidUpdateProp" << " -- " << "Forbid MCMC moves to update proportions."<<endl;
out << setw(20) << "-forbidUpdateSingle" << " -- " << "Forbid MCMC moves to update single haplotype."<<endl;
out << setw(20) << "-forbidUpdatePair" << " -- " << "Forbid MCMC moves to update pair haplotypes."<<endl;
out << setw(20) << "-initialP FLT ..." << " -- " << "Initialize proportions."<<endl;
out << endl;
out << "Examples:" << endl;
out << endl;
out << "./dEploid -vcf data/testData/PG0390-C.test.vcf -plaf data/testData/labStrains.test.PLAF.txt -o PG0390-CNopanel -noPanel"<< endl;
out << "./dEploid -vcf data/testData/PG0390-C.test.vcf -exclude data/testData/labStrains.test.exclude.txt -plaf data/testData/labStrains.test.PLAF.txt -o PG0390-CNopanelExclude -noPanel"<< endl;
}

void DEploidIO::printHelp(){
cout << endl
<< "dEploid " << VERSION
<< endl
<< endl;
cout << "Usage:"
<< endl;
cout << setw(20) << "-h or -help" << " -- " << "Help. List the following content."<<endl;
cout << setw(20) << "-v or -version" << " -- " << "DEploid version."<<endl;
cout << setw(20) << "-ref STR" << " -- " << "File path of reference allele count."<<endl;
cout << setw(20) << "-alt STR" << " -- " << "File path of alternative allele count."<<endl;
cout << setw(20) << "-plaf STR" << " -- " << "File path of population level allele frequencies."<<endl;
cout << setw(20) << "-panel STR" << " -- " << "File path of the reference panel."<<endl;
cout << setw(20) << "-exclude STR" << " -- " << "File path of sites to be excluded."<<endl;
cout << setw(20) << "-o STR" << " -- " << "Specify the file name prefix of the output."<<endl;
cout << setw(20) << "-p INT" << " -- " << "Out put precision (default value 8)."<<endl;
cout << setw(20) << "-k INT" << " -- " << "Number of strain (default value 5)."<<endl;
cout << setw(20) << "-seed INT" << " -- " << "Random seed."<<endl;
cout << setw(20) << "-nSample INT" << " -- " << "Number of MCMC samples."<<endl;
cout << setw(20) << "-rate INT" << " -- " << "MCMC sample rate."<<endl;
cout << setw(20) << "-noPanel" << " -- " << "Use population level allele frequency as prior."<<endl;
cout << setw(20) << "-forbidUpdateProp" << " -- " << "Forbid MCMC moves to update proportions."<<endl;
cout << setw(20) << "-forbidUpdateSingle" << " -- " << "Forbid MCMC moves to update single haplotype."<<endl;
cout << setw(20) << "-forbidUpdatePair" << " -- " << "Forbid MCMC moves to update pair haplotypes."<<endl;
cout << setw(20) << "-initialP FLT ..." << " -- " << "Initialize proportions."<<endl;
cout << endl;
cout << "Examples:" << endl;
cout << endl;
cout << "./dEploid -vcf data/testData/PG0390-C.test.vcf -plaf data/testData/labStrains.test.PLAF.txt -o PG0390-CNopanel -noPanel"<< endl;
cout << "./dEploid -vcf data/testData/PG0390-C.test.vcf -exclude data/testData/labStrains.test.exclude.txt -plaf data/testData/labStrains.test.PLAF.txt -o PG0390-CNopanelExclude -noPanel"<< endl;

std::ostream& operator<< (std::ostream& stream, const DEploidIO& dEploidIO) {
for (std::string arg : dEploidIO.argv_) stream << " " << arg;
return stream;
}
23 changes: 15 additions & 8 deletions src/dEploidIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* This file is part of dEploid.
*
* scrm is free software: you can redistribute it and/or modify
* dEploid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
Expand All @@ -18,8 +18,8 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*
*/

#include <stdlib.h> /* strtol, strtod */
#include <fstream>
Expand Down Expand Up @@ -48,14 +48,17 @@ class DEploidIO{
friend class TestMcmcMachinery;
#endif
friend class McmcMachinery;
friend class RMcmcSample;
public:
DEploidIO();
DEploidIO(const std::string &arg);
DEploidIO(int argc, char *argv[]);
~DEploidIO ();

void core(int argc, char *argv[]);
void printHelp();
void core();
void printHelp(std::ostream& out);
bool help() const { return help_; }
void printVersion();
void printVersion(std::ostream& out);
bool version() const { return version_; }

bool initialPropWasGiven() const { return initialPropWasGiven_; }
Expand All @@ -65,6 +68,8 @@ class DEploidIO{
string panelFileName_;

size_t nLoci() const { return this->nLoci_; }
size_t kStrain() const { return this->kStrain_;}
size_t nMcmcSample() const { return this->nMcmcSample_; }
double averageCentimorganDistance() const { return this->averageCentimorganDistance_; }
double Ne() const { return this->Ne_; }
double constRecombProb() const { return this->constRecombProb_; }
Expand All @@ -80,6 +85,10 @@ class DEploidIO{

// Log
void write (McmcSample * mcmcSample, Panel * panel );
bool randomSeedWasSet() const {return this->randomSeedWasSet_; }

friend std::ostream& operator<< (std::ostream& stream, const DEploidIO& dEploidIO);
size_t randomSeed() const { return randomSeed_;}

private:

Expand All @@ -91,10 +100,8 @@ class DEploidIO{
string excludeFileName_;
string prefix_;
size_t randomSeed_;
size_t randomSeed() const { return randomSeed_;}
bool randomSeedWasSet_;
void setRandomSeedWasSet(const bool random){ this->randomSeedWasSet_ = random; }
bool randomSeedWasSet() const {return this->randomSeedWasSet_; }


bool initialPropWasGiven_;
Expand Down
6 changes: 3 additions & 3 deletions src/debug/mcmcDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* This file is part of dEploid.
*
* scrm is free software: you can redistribute it and/or modify
* dEploid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
Expand All @@ -18,8 +18,8 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*
*/

#include "mcmc.hpp"
//#include "utility.hpp"
Expand Down
6 changes: 3 additions & 3 deletions src/debug/vcfReaderDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* This file is part of dEploid.
*
* scrm is free software: you can redistribute it and/or modify
* dEploid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
Expand All @@ -18,8 +18,8 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*
*/

#include "global.h"
#include <iostream> // std::cout
Expand Down
6 changes: 3 additions & 3 deletions src/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* This file is part of dEploid.
*
* scrm is free software: you can redistribute it and/or modify
* dEploid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
Expand All @@ -18,8 +18,8 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*
*/


#include <string> /* string */
Expand Down
6 changes: 3 additions & 3 deletions src/export/dEploidIOExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* This file is part of dEploid.
*
* scrm is free software: you can redistribute it and/or modify
* dEploid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
Expand All @@ -18,8 +18,8 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*
*/

#include "dEploidIO.hpp"
#include "mcmc.hpp"
Expand Down
Loading

0 comments on commit 0255a63

Please sign in to comment.