}
- if (conTax == "") { conTax = "unclassified;"; }
+ if (conTax == "") { conTax = "no_consensus;"; }
delete phylo;
virtual void init(string) = 0;
virtual void reset() = 0;
virtual void close() = 0;
+ virtual void outputTempFiles(string) {}
+ virtual void inputTempFiles(string) {}
virtual bool isCalcMultiple() = 0;
virtual void setAll(bool){}
virtual bool hasLciHci(){ return false; }
try {
m->mothurOut("The filter.seqs command reads a file containing sequences and creates a .filter and .filter.fasta file.\n");
- m->mothurOut("The filter.seqs command parameters are fasta, trump, soft, hard and vertical. \n");
+ m->mothurOut("The filter.seqs command parameters are fasta, trump, soft, hard, processors and vertical. \n");
m->mothurOut("The fasta parameter is required. You may enter several fasta files to build the filter from and filter, by separating their names with -'s.\n");
m->mothurOut("For example: fasta=abrecovery.fasta-amazon.fasta \n");
m->mothurOut("The trump parameter .... The default is ...\n");
m->mothurOut("The soft parameter .... The default is ....\n");
m->mothurOut("The hard parameter allows you to enter a file containing the filter you want to use.\n");
m->mothurOut("The vertical parameter removes columns where all sequences contain a gap character. The default is T.\n");
+ m->mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n");
m->mothurOut("The filter.seqs command should be in the following format: \n");
m->mothurOut("filter.seqs(fasta=yourFastaFile, trump=yourTrump) \n");
m->mothurOut("Example filter.seqs(fasta=abrecovery.fasta, trump=.).\n");
exit(1);
}
}
+/***********************************************************************/
+
+void RareDisplay::inputTempFiles(string filename){
+ try {
+ ifstream in;
+ m->openInputFile(filename, in);
+
+ int thisIters;
+ in >> thisIters; m->gobble(in);
+
+ for (int i = 0; i < seqs.size(); i++) {
+ double tempresult, tempvar;
+ in >> tempresult >> tempvar; m->gobble(in);
+
+ //find weighted result
+ results[i] = ((nIters * results[i]) + (thisIters * tempresult)) / (float)(nIters + thisIters);
+
+ var[i] = ((nIters * var[i]) + (thisIters * tempvar)) / (float)(nIters + thisIters);
+ }
+
+ in.close();
+ }
+ catch(exception& e) {
+ m->errorOut(e, "RareDisplay", "inputTempFiles");
+ exit(1);
+ }
+}
+
+/***********************************************************************/
+
+void RareDisplay::outputTempFiles(string filename){
+ try {
+ ofstream out;
+ m->openOutputFile(filename, out);
+
+ out << nIters << endl;
+
+ for (int i = 0; i < seqs.size(); i++) {
+ out << results[i] << '\t' << var[i] << endl;
+ }
+
+ out.close();
+ }
+ catch(exception& e) {
+ m->errorOut(e, "RareDisplay", "outputTempFiles");
+ exit(1);
+ }
+}
+
/***********************************************************************/
void close();
bool isCalcMultiple() { return estimate->getMultiple(); }
+ void outputTempFiles(string);
+ void inputTempFiles(string);
+
private:
Calculator* estimate;
FileOutput* output;
int increment = 1;
if (percentFreq < 1.0) { increment = numSeqs * percentFreq; }
else { increment = percentFreq; }
+
+ #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+ if(processors == 1){
+ driver(rcd, increment, nIters);
+ }else{
+ vector<int> procIters;
+
+ int numItersPerProcessor = nIters / processors;
+
+ //divide iters between processes
+ for (int i = 0; i < processors; i++) {
+ if(i == processors - 1){
+ numItersPerProcessor = nIters - i * numItersPerProcessor;
+ }
+ procIters.push_back(numItersPerProcessor);
+ }
+
+ createProcesses(procIters, rcd, increment);
+ }
+
+ #else
+ driver(rcd, increment, nIters);
+ #endif
+
+ for(int i=0;i<displays.size();i++){
+ displays[i]->close();
+ }
+
+ delete rcd;
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "Rarefact", "getCurve");
+ exit(1);
+ }
+}
+/***********************************************************************/
+int Rarefact::driver(RarefactionCurveData* rcd, int increment, int nIters = 1000){
+ try {
for(int iter=0;iter<nIters;iter++){
delete rank;
}
- for(int i=0;i<displays.size();i++){
- displays[i]->close();
- }
- delete rcd;
return 0;
}
catch(exception& e) {
- m->errorOut(e, "Rarefact", "getCurve");
+ m->errorOut(e, "Rarefact", "driver");
exit(1);
}
}
+/**************************************************************************************************/
+int Rarefact::createProcesses(vector<int>& procIters, RarefactionCurveData* rcd, int increment) {
+ try {
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+ int process = 1;
+ int num = 0;
+ vector<int> processIDS;
+
+ EstOutput results;
+
+ //loop through and create all the processes you want
+ while (process != processors) {
+ int pid = fork();
+
+ if (pid > 0) {
+ processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
+ process++;
+ }else if (pid == 0){
+ driver(rcd, increment, procIters[process]);
+
+ //pass numSeqs to parent
+ for(int i=0;i<displays.size();i++){
+ string tempFile = toString(getpid()) + toString(i) + ".rarefact.temp";
+ displays[i]->outputTempFiles(tempFile);
+ }
+ exit(0);
+ }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
+ }
+
+ driver(rcd, increment, procIters[0]);
+
+ //force parent to wait until all the processes are done
+ for (int i=0;i<(processors-1);i++) {
+ int temp = processIDS[i];
+ wait(&temp);
+ }
+
+ //get data created by processes
+ for (int i=0;i<(processors-1);i++) {
+ for(int j=0;j<displays.size();j++){
+ string s = toString(processIDS[i]) + toString(j) + ".rarefact.temp";
+ displays[j]->inputTempFiles(s);
+ remove(s.c_str());
+ }
+ }
+
+ return 0;
+#endif
+ }
+ catch(exception& e) {
+ m->errorOut(e, "Rarefact", "createProcesses");
+ exit(1);
+ }
+}
/***********************************************************************/
int Rarefact::getSharedCurve(float percentFreq = 0.01, int nIters = 1000){
class Rarefact {
public:
- Rarefact(OrderVector* o, vector<Display*> disp) :
- numSeqs(o->getNumSeqs()), order(o), displays(disp), label(o->getLabel()) { m = MothurOut::getInstance(); }
+ Rarefact(OrderVector* o, vector<Display*> disp, int p) :
+ numSeqs(o->getNumSeqs()), order(o), displays(disp), label(o->getLabel()), processors(p) { m = MothurOut::getInstance(); }
Rarefact(vector<SharedRAbundVector*> shared, vector<Display*> disp) :
lookup(shared), displays(disp) { globaldata = GlobalData::getInstance(); m = MothurOut::getInstance(); }
GlobalData* globaldata;
OrderVector* order;
vector<Display*> displays;
- int numSeqs, numGroupComb;
+ int numSeqs, numGroupComb, processors;
string label;
void mergeVectors(SharedRAbundVector*, SharedRAbundVector*);
vector<SharedRAbundVector*> lookup;
MothurOut* m;
+
+ int createProcesses(vector<int>&, RarefactionCurveData*, int);
+ int driver(RarefactionCurveData*, int, int);
};
else {
//valid paramters for this command
- string Array[] = {"iters","freq","label","calc","abund","outputdir","inputdir"};
+ string Array[] = {"iters","freq","label","calc","abund","processors","outputdir","inputdir"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
OptionParser parser(option);
temp = validParameter.validFile(parameters, "iters", false); if (temp == "not found") { temp = "1000"; }
convert(temp, nIters);
+
+ temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; }
+ convert(temp, processors);
}
}
try {
m->mothurOut("The rarefaction.single command can only be executed after a successful read.otu WTIH ONE EXECEPTION.\n");
m->mothurOut("The rarefaction.single command can be executed after a successful cluster command. It will use the .list file from the output of the cluster.\n");
- m->mothurOut("The rarefaction.single command parameters are label, iters, freq, calc and abund. No parameters are required. \n");
+ m->mothurOut("The rarefaction.single command parameters are label, iters, freq, calc, processors and abund. No parameters are required. \n");
m->mothurOut("The freq parameter is used indicate when to output your data, by default it is set to 100. But you can set it to a percentage of the number of sequence. For example freq=0.10, means 10%. \n");
+ m->mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n");
m->mothurOut("The rarefaction.single command should be in the following format: \n");
m->mothurOut("rarefaction.single(label=yourLabel, iters=yourIters, freq=yourFreq, calc=yourEstimators).\n");
m->mothurOut("Example rarefaction.single(label=unique-.01-.03, iters=10000, freq=10, calc=sobs-rchao-race-rjack-rbootstrap-rshannon-rnpshannon-rsimpson).\n");
if(allLines == 1 || labels.count(order->getLabel()) == 1){
m->mothurOut(order->getLabel()); m->mothurOutEndLine();
- rCurve = new Rarefact(order, rDisplays);
+ rCurve = new Rarefact(order, rDisplays, processors);
rCurve->getCurve(freq, nIters);
delete rCurve;
order = (input->getOrderVector(lastLabel));
m->mothurOut(order->getLabel()); m->mothurOutEndLine();
- rCurve = new Rarefact(order, rDisplays);
+ rCurve = new Rarefact(order, rDisplays, processors);
rCurve->getCurve(freq, nIters);
delete rCurve;
order = (input->getOrderVector(lastLabel));
m->mothurOut(order->getLabel()); m->mothurOutEndLine();
- rCurve = new Rarefact(order, rDisplays);
+ rCurve = new Rarefact(order, rDisplays, processors);
rCurve->getCurve(freq, nIters);
delete rCurve;
InputData* input;
ValidCalculators* validCalculator;
Rarefact* rCurve;
- int nIters, abund;
+ int nIters, abund, processors;
float freq;
bool abort, allLines;
void UnifracUnweightedCommand::help(){
try {
m->mothurOut("The unifrac.unweighted command can only be executed after a successful read.tree command.\n");
- m->mothurOut("The unifrac.unweighted command parameters are groups, iters, distance and random. No parameters are required.\n");
+ m->mothurOut("The unifrac.unweighted command parameters are groups, iters, distance, processors and random. No parameters are required.\n");
m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 1 valid group.\n");
m->mothurOut("The group names are separated by dashes. The iters parameter allows you to specify how many random trees you would like compared to your tree.\n");
m->mothurOut("The distance parameter allows you to create a distance file from the results. The default is false.\n");
m->mothurOut("The random parameter allows you to shut off the comparison to random trees. The default is false, meaning compare don't your trees with randomly generated trees.\n");
+ m->mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n");
m->mothurOut("The unifrac.unweighted command should be in the following format: unifrac.unweighted(groups=yourGroups, iters=yourIters).\n");
m->mothurOut("Example unifrac.unweighted(groups=A-B-C, iters=500).\n");
m->mothurOut("The default value for groups is all the groups in your groupfile, and iters is 1000.\n");
void UnifracWeightedCommand::help(){
try {
m->mothurOut("The unifrac.weighted command can only be executed after a successful read.tree command.\n");
- m->mothurOut("The unifrac.weighted command parameters are groups, iters, distance and random. No parameters are required.\n");
+ m->mothurOut("The unifrac.weighted command parameters are groups, iters, distance, processors and random. No parameters are required.\n");
m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 2 valid groups.\n");
m->mothurOut("The group names are separated by dashes. The iters parameter allows you to specify how many random trees you would like compared to your tree.\n");
m->mothurOut("The distance parameter allows you to create a distance file from the results. The default is false.\n");
m->mothurOut("The random parameter allows you to shut off the comparison to random trees. The default is false, meaning don't compare your trees with randomly generated trees.\n");
+ m->mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n");
m->mothurOut("The unifrac.weighted command should be in the following format: unifrac.weighted(groups=yourGroups, iters=yourIters).\n");
m->mothurOut("Example unifrac.weighted(groups=A-B-C, iters=500).\n");
m->mothurOut("The default value for groups is all the groups in your groupfile, and iters is 1000.\n");