Skip to content

Commit

Permalink
check style
Browse files Browse the repository at this point in the history
  • Loading branch information
shajoezhu committed Jan 1, 2021
1 parent 4409c03 commit 949e239
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 71 deletions.
3 changes: 2 additions & 1 deletion .ci/checkedList
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
src/dEploidIO-operation.cpp
src/dEploidIO-workflow.cpp
src/mcmc.hpp
src/dEploid.cpp
src/variantIndex.cpp
Expand All @@ -22,4 +24,3 @@ tests/unittest/test_runner.cpp
tests/unittest/test_utilities.cpp
src/export/dEploidIOExportPosteriorProb.cpp
src/export/writeMcmcRelated.cpp
src/dEploidIO-workflow.cpp
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ PG400*
PG0*
txt.*
vcf.*
data/
docs/

# coverage test
*.gcda
Expand Down
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ common_src = src/random/fastfunc.cpp \
src/panel.cpp \
src/utility.cpp \
src/dEploidIO.cpp \
src/dEploidIO-operation.cpp \
src/dEploidIO-workflow.cpp \
src/updateHap.cpp \
src/txtReader.cpp \
Expand Down
4 changes: 2 additions & 2 deletions src/dEploid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ int main(int argc, char *argv[]) {
std::ostream *output = &std::cout;

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

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

Expand Down
144 changes: 144 additions & 0 deletions src/dEploidIO-operation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* dEploid is used for deconvoluting Plasmodium falciparum genome from
* mix-infected patient sample.
*
* Copyright (C) 2016-2017 University of Oxford
*
* Author: Sha (Joe) Zhu
*
* This file is part of dEploid.
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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 <iomanip> // std::setw
#include "dEploidIO.hpp"


void DEploidIO::operation_printVersion(std::ostream& out) {
out << endl
<< "dEploid " << VERSION
<< endl
<< "Git commit (DEploid): " << dEploidGitVersion_ << endl
<< "Git commit (Lasso): " << lassoGitVersion_ << endl;
}


void DEploidIO::operation_printHelp(std::ostream& out) {
out << endl
<< "dEploid " << VERSION << endl
<< endl;
out << "Contact: Joe Zhu <[email protected]>" << 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) << "-vcf STR" << " -- "
<< "VCF file path." << 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 << setw(20) << "-ibd" << " -- "
<< "Use DEploid-IBD" << endl;
out << setw(20) << "-lasso" << " -- "
<< "Use DEploid-LASSO" << endl;
out << setw(20) << "-best" << " -- "
<< "Use DEploid-Best-practice" << endl;
out << endl;
out << "Note: Please `man docs/_build/man/dEploid.1' for the manual."
<< 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;
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-C-ibd -panel data/testData/labStrains.test.panel.txt "
<< "-ibd" << 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-C-best -panel data/testData/labStrains.test.panel.txt "
<< "-best" << endl;
out << "./dEploid -vcf data/testData/PG0390-C.test.vcf.gz "
<< "-exclude data/testData/labStrains.test.exclude.txt.gz "
<< "-plaf data/testData/labStrains.test.PLAF.txt.gz -o PG0390-C-best "
<< "-panel data/testData/labStrains.test.panel.txt.gz -best" << 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-CPanelExclude "
<< "-panel data/testData/labStrains.test.panel.txt "
<< "-painting PG0390-CPanelExclude.hap" << endl;
out << "./dEploid -vcf data/testData/PG0390-C.test.vcf "
<< "-plaf data/testData/labStrains.test.PLAF.txt "
<< "-o PG0390-CNopanel -noPanel -k 2 -nSample 250 -rate 8 -burn 0.67 "
<< "-ibd " << endl;
out << "./dEploid -vcf data/testData/PG0390-C.test.vcf "
<< "-plaf data/testData/labStrains.test.PLAF.txt "
<< "-o PG0390-CNopanel -initialP 0.2 0.8 -ibdPainting" << 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-CLassoExclude "
<< "-panel data/testData/labStrains.test.panel.txt "
<< "-initialP 0.2 0.8 -writePanel -lasso" << endl;
out << "./dEploid -vcf data/testData/PG0390-C.test.vcf.gz "
<< "-sample PG0390-C -plafFromVcf "
<< "-exclude data/testData/labStrains.test.exclude.txt.gz "
<< "-o PG0390-C-best "
<< "-panel data/testData/labStrains.test.panel.txt.gz -best" << endl;
}

8 changes: 3 additions & 5 deletions src/dEploidIO-workflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ void DEploidIO::workflow_ibd() {
this->paintIBD();
this->writeHap(mcmcSample->hap, "final");
delete mcmcSample;


}


Expand Down Expand Up @@ -281,9 +279,9 @@ void DEploidIO::workflow_best() {
this->writeHap(hap, "final");
this->writeVcf(hap, dEploidLassoIO.initialProp, "final");
}
if (this->inferBestPracticeP() &
(this->initialProp.size() > 1)) {
this->paintIBD();

if (this->inferBestPracticeP() & (this->initialProp.size() > 1)) {
this->paintIBD();
}
}

56 changes: 0 additions & 56 deletions src/dEploidIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <ctime>
#include <iterator>
#include <cassert> // assert
#include <iomanip> // std::setw
#include "utility.hpp" // normailize by sum
#include "updateHap.hpp" // chromPainting
#include "dEploidIO.hpp"
Expand Down Expand Up @@ -652,61 +651,6 @@ void DEploidIO::readNextStringto( string &readto ) {
}


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

void DEploidIO::printHelp(std::ostream& out) {
out << endl
<< "dEploid " << VERSION << endl
<< endl;
out << "Contact: Joe Zhu <[email protected]>" << 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) << "-vcf STR" << " -- " << "VCF file path."<<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 << setw(20) << "-ibd" << " -- " << "Use DEploid-IBD"<<endl;
out << setw(20) << "-lasso" << " -- " << "Use DEploid-LASSO"<<endl;
out << setw(20) << "-best" << " -- " << "Use DEploid-Best-practice"<<endl;
out << endl;
out << "Note: Please `man docs/_build/man/dEploid.1' for the manual." << 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;
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-C-ibd -panel data/testData/labStrains.test.panel.txt -ibd" << 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-C-best -panel data/testData/labStrains.test.panel.txt -best" << endl;
out << "./dEploid -vcf data/testData/PG0390-C.test.vcf.gz -exclude data/testData/labStrains.test.exclude.txt.gz -plaf data/testData/labStrains.test.PLAF.txt.gz -o PG0390-C-best -panel data/testData/labStrains.test.panel.txt.gz -best" << 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-CPanelExclude -panel data/testData/labStrains.test.panel.txt -painting PG0390-CPanelExclude.hap" << endl;
out << "./dEploid -vcf data/testData/PG0390-C.test.vcf -plaf data/testData/labStrains.test.PLAF.txt -o PG0390-CNopanel -noPanel -k 2 -nSample 250 -rate 8 -burn 0.67 -ibd " <<endl;
out << "./dEploid -vcf data/testData/PG0390-C.test.vcf -plaf data/testData/labStrains.test.PLAF.txt -o PG0390-CNopanel -initialP 0.2 0.8 -ibdPainting" <<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-CLassoExclude -panel data/testData/labStrains.test.panel.txt -initialP 0.2 0.8 -writePanel -lasso" << endl;
out << "./dEploid -vcf data/testData/PG0390-C.test.vcf.gz -sample PG0390-C -plafFromVcf -exclude data/testData/labStrains.test.exclude.txt.gz -o PG0390-C-best -panel data/testData/labStrains.test.panel.txt.gz -best" << endl;
}


std::ostream& operator<< (std::ostream& stream, const DEploidIO& dEploidIO) {
for (std::string arg : dEploidIO.argv_) stream << " " << arg;
Expand Down
5 changes: 3 additions & 2 deletions src/dEploidIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ class DEploidIO{

ChooseK chooseK;

void printHelp(std::ostream& out);
void operation_printHelp(std::ostream& out);
void operation_printVersion(std::ostream& out);

bool help() const { return help_; }
void printVersion(std::ostream& out);
bool version() const { return version_; }
// Painting related
void chromPainting ();
Expand Down
10 changes: 5 additions & 5 deletions tests/unittest/test_dEploidIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,22 +222,22 @@ class TestIO : public CppUnit::TestCase {
DEploidIO dEploidIO1(1, argv);
CPPUNIT_ASSERT_EQUAL((size_t)0, dEploidIO1.argv_.size());
CPPUNIT_ASSERT_EQUAL(true, dEploidIO1.help());
CPPUNIT_ASSERT_NO_THROW(dEploidIO1.printHelp(*output));
CPPUNIT_ASSERT_NO_THROW(dEploidIO1.operation_printHelp(*output));

char *argv1[] = { "./dEploid", "-h" };
CPPUNIT_ASSERT_NO_THROW(DEploidIO(2, argv1));
DEploidIO dEploidIO2(2, argv1);
CPPUNIT_ASSERT_EQUAL((size_t)1, dEploidIO2.argv_.size());
CPPUNIT_ASSERT_EQUAL(true, dEploidIO2.help());
CPPUNIT_ASSERT_NO_THROW(dEploidIO2.printHelp(*output));
CPPUNIT_ASSERT_NO_THROW(dEploidIO2.operation_printHelp(*output));
CPPUNIT_ASSERT_NO_THROW(DEploidIO(string("-help")));

char *argv2[] = { "./dEploid", "-help" };
CPPUNIT_ASSERT_NO_THROW(DEploidIO(2, argv2));
DEploidIO dEploidIO3(2, argv2);
CPPUNIT_ASSERT_EQUAL((size_t)1, dEploidIO3.argv_.size());
CPPUNIT_ASSERT_EQUAL(true, dEploidIO3.help());
CPPUNIT_ASSERT_NO_THROW(dEploidIO3.printHelp(*output));
CPPUNIT_ASSERT_NO_THROW(dEploidIO3.operation_printHelp(*output));
}


Expand All @@ -247,13 +247,13 @@ class TestIO : public CppUnit::TestCase {
CPPUNIT_ASSERT_NO_THROW(DEploidIO(2, argv1));
DEploidIO dEploidIO1(2, argv1);
CPPUNIT_ASSERT_EQUAL(true, dEploidIO1.version());
CPPUNIT_ASSERT_NO_THROW(dEploidIO1.printVersion(*output));
CPPUNIT_ASSERT_NO_THROW(dEploidIO1.operation_printVersion(*output));

char *argv2[] = { "./dEploid", "-version" };
CPPUNIT_ASSERT_NO_THROW(DEploidIO(2, argv2));
DEploidIO dEploidIO2(2, argv2);
CPPUNIT_ASSERT_EQUAL(true, dEploidIO2.version());
CPPUNIT_ASSERT_NO_THROW(dEploidIO2.printVersion(*output));
CPPUNIT_ASSERT_NO_THROW(dEploidIO2.operation_printVersion(*output));
}


Expand Down

0 comments on commit 949e239

Please sign in to comment.