Skip to content

Commit

Permalink
Doing commit before SVN merge.
Browse files Browse the repository at this point in the history
git-svn-id: svn://sisp.smith.man.ac.uk/svn/rattray/bitseq/cpp@56 c4856536-7db2-4565-afe3-bcf1ab8f3238
  • Loading branch information
mbaxjpg3 committed Jul 5, 2013
1 parent 14a6b68 commit cbc3811
Show file tree
Hide file tree
Showing 29 changed files with 963 additions and 348 deletions.
62 changes: 53 additions & 9 deletions ArgumentParser.h
Expand Up @@ -31,33 +31,77 @@ class ArgumentParser{
template <typename valueType>
void appendDescription(string *desc,valueType defValue);
public:
// The value of verbose option for direct access.
bool verbose;

// Constructor for the class sets: programDescription, additional string
// and minimum number of required arguments.
ArgumentParser(const string &pD="",const string &aD="[FILES]", long minArgs = 1){//{{{
verbose = false;
init(pD,aD,minArgs);
}//}}}
// Init function for initialization, sets the same values as constructor.
void init(const string &pD="",const string &aD="[FILES]", long minArgs = 1){//{{{
programDesc=pD;
argumentDesc=aD;
minimumArguments = minArgs;
}//}}}
// Parse function given number of arguments and array of arguments
// it processes the arguments and makes options available through
// get[S/L/D] functions and args() function.
bool parse(int n,char * argv[]);
void addOptionS(const string &shortName, const string &longName, const string &name, bool comp, const string &description="", const string &defValue="noDefault");
void addOptionL(const string &shortName, const string &longName, const string &name, bool comp, const string &description="", long defValue=-47);
void addOptionD(const string &shortName, const string &longName, const string &name, bool comp, const string &description="", double defValue=-47.47);
void addOptionB(const string &shortName, const string &longName, const string &name, bool comp, const string &description="", bool defValue=false);
bool verb() const { return verbose; }
/*
* SETTERS:
*/
// Add option (string) adds new option, name is the name used for referring
// to it.
void addOptionS(const string &shortName,
const string &longName,
const string &name,
bool comp,
const string &description="",
const string &defValue="noDefault");
// Add option (long).
void addOptionL(const string &shortName, const string &longName,
const string &name, bool comp, const string &description="",
long defValue=-47);
// Add option (double).
void addOptionD(const string &shortName, const string &longName,
const string &name, bool comp, const string &description="",
double defValue=-47.47);
// Add option (boolean or 'flag').
void addOptionB(const string &shortName, const string &longName,
const string &name, bool comp, const string &description="",
bool defValue=false);
/*
* GETTERS:
*/
// Return reference to vector of arguments
// (i.e. the strings provided with no -/-- modifier).
const vector<string>& args() const { return arguments; }
// Return true if option <name> was set.
bool isSet(const string &name) const;
// Return value of string option <name>.
string getS(const string &name) const;
// Return value of integer option <name>.
long getL(const string &name) const;
// Return value of double option <name>.
double getD(const string &name) const;
const vector<string>& args() const { return arguments; }
vector<double> getTokenizedS2D(const string &name) const;
// Return value of bool option <name>.
bool flag(const string &name) const;
bool isSet(const string &name) const;
// Return value of verbose.
bool verb() const { return verbose; }

/*
* OTHER:
*/
// (Advanced get) Return tokenized (comma separated) string as vector of doubles.
vector<double> getTokenizedS2D(const string &name) const;
// Write usage string.
void usage();
// Write all options.
void writeAll();
// Update value of existing option.
// Update value of existing string option.
void updateS(const string &name, const string &value);
};

Expand Down
15 changes: 11 additions & 4 deletions Makefile
@@ -1,7 +1,7 @@
CXX = g++
HOSTNAME = $(shell hostname)
ARCH = -mtune=generic
VERSION = 0.5.4
VERSION = 0.6.0

ifeq ($(HOSTNAME), valiant)
ARCH = -march=core2
Expand Down Expand Up @@ -42,7 +42,7 @@ PROGRAMS = \

all: $(PROGRAMS)

COMMON_DEPS = ArgumentParser.o common.o FileHeader.o misc.o
COMMON_DEPS = ArgumentParser.o common.o FileHeader.o misc.o MyTimer.o
# PROGRAMS:
convertSamples: convertSamples.cpp $(COMMON_DEPS) TranscriptInfo.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) convertSamples.cpp $(COMMON_DEPS) TranscriptInfo.o -o convertSamples
Expand Down Expand Up @@ -90,12 +90,18 @@ ArgumentParser.o: ArgumentParser.cpp ArgumentParser.h
CollapsedSampler.o: CollapsedSampler.cpp CollapsedSampler.h GibbsParameters.h Sampler.h
$(CXX) $(CXXFLAGS) $(BOOSTFLAGS) -c CollapsedSampler.cpp

FileHeader.o: common.h FileHeader.cpp FileHeader.h
$(CXX) $(CXXFLAGS) $(BOOSTFLAGS) -ffunction-sections -fdata-sections -c FileHeader.cpp

GibbsSampler.o: GibbsSampler.cpp GibbsSampler.h GibbsParameters.h Sampler.h
$(CXX) $(CXXFLAGS) $(BOOSTFLAGS) -c GibbsSampler.cpp

misc.o: ArgumentParser.h PosteriorSamples.h misc.cpp misc.h
$(CXX) $(CXXFLAGS) -ffunction-sections -fdata-sections -c misc.cpp

MyTimer.o: MyTimer.h MyTimer.cpp
$(CXX) $(CXXFLAGS) -ffunction-sections -fdata-sections -c MyTimer.cpp

PosteriorSamples.o: PosteriorSamples.cpp PosteriorSamples.h FileHeader.h
$(CXX) $(CXXFLAGS) -ffunction-sections -fdata-sections -c PosteriorSamples.cpp

Expand All @@ -112,7 +118,6 @@ VariationalBayes.o: VariationalBayes.cpp VariationalBayes.h SimpleSparse.h
$(CXX) $(CXXFLAGS) $(BOOSTFLAGS) $(OPENMP) -c VariationalBayes.cpp

common.o: common.cpp common.h
FileHeader.o: common.h FileHeader.cpp FileHeader.h
GibbsParameters.o: ArgumentParser.h GibbsParameters.cpp GibbsParameters.h
lowess.o: lowess.cpp lowess.h
TagAlignments.o: TagAlignments.cpp TagAlignments.h
Expand All @@ -130,5 +135,7 @@ samtools/sam.o:

# CLEAN:
clean:
rm samtools/*.o asa103/*.o *.o $(PROGRAMS)
rm asa103/*.o *.o $(PROGRAMS)

clean-all:
rm samtools/*.o asa103/*.o *.o $(PROGRAMS)
53 changes: 53 additions & 0 deletions MyTimer.cpp
@@ -0,0 +1,53 @@
#include<ctime>

#include "MyTimer.h"

#include "common.h"

void MyTimer::adjust(double &time,char f){//{{{
if(f=='m')time/=60.0;
if(f=='h')time/=3600.0;
}//}}}
void MyTimer::write(double time,char f){//{{{
if(!quiet)messageF("[time: +%lf %c]\n",time,f);
}//}}}
MyTimer::MyTimer(){//{{{
N=1;
quiet=false;
times.resize(N);
times[0]=time(NULL);
}//}}}
void MyTimer::start(long timer){//{{{
if(timer>=N){
N=timer+1;
times.resize(N);
}
times[timer]=time(NULL);
}//}}}
double MyTimer::split(long timer, char f){//{{{
if(timer>=N)return 0;
double ret;
ret=time(NULL)-times[timer];
adjust(ret,f);
write(ret,f);
times[timer]=time(NULL);
return ret;
}//}}}
double MyTimer::current(long timer, char f){//{{{
if(timer>=N)return 0;
double ret;
ret=time(NULL)-times[timer];
adjust(ret,f);
write(ret,f);
return ret;
}//}}}
double MyTimer::stop(long timer, char f){//{{{
if(timer>=N)return 0;
double ret;
ret=time(NULL)-times[timer];
adjust(ret,f);
write(ret,f);
times[timer]=time(NULL);
return ret;
}//}}}

63 changes: 11 additions & 52 deletions MyTimer.h
Expand Up @@ -2,67 +2,26 @@
#define MYTIMER_H

#include<vector>
#include<cstdlib>
#include<ctime>

using namespace std;

#include "common.h"

class MyTimer{
private:
private:
vector<time_t> times;
long N;
bool quiet;
void adjust(double &time,char f){//{{{
if(f=='m')time/=60.0;
if(f=='h')time/=3600.0;
}//}}}
void write(double time,char f){//{{{
if(!quiet)message("[time: +%lf %c]\n",time,f);
}//}}}
public:
MyTimer(){//{{{
N=1;
quiet=false;
times.resize(N);
times[0]=time(NULL);
}//}}}
// Adjust time to format m or h.
void adjust(double &time,char f);
// Write time in format.
void write(double time,char f);
public:
MyTimer();
void setQuiet(){quiet=true;}
void setVerbose(){quiet=false;}
void start(long timer=0){//{{{
if(timer>=N){
N=timer+1;
times.resize(N);
}
times[timer]=time(NULL);
}//}}}
double split(long timer=0, char f='s'){//{{{
if(timer>=N)return 0;
double ret;
ret=time(NULL)-times[timer];
adjust(ret,f);
write(ret,f);
times[timer]=time(NULL);
return ret;
}//}}}
double current(long timer=0, char f='s'){//{{{
if(timer>=N)return 0;
double ret;
ret=time(NULL)-times[timer];
adjust(ret,f);
write(ret,f);
return ret;
}//}}}
double stop(long timer=0, char f='s'){//{{{
if(timer>=N)return 0;
double ret;
ret=time(NULL)-times[timer];
adjust(ret,f);
write(ret,f);
times[timer]=time(NULL);
return ret;
}//}}}
void start(long timer=0);
double split(long timer=0, char f='s');
double current(long timer=0, char f='s');
double stop(long timer=0, char f='s');
};

#endif

0 comments on commit cbc3811

Please sign in to comment.