From: westcott Date: Fri, 17 Apr 2009 15:43:01 +0000 (+0000) Subject: added bootstrap.shared command and fixed some bugs with heatmap X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=51cf89e90eef8b300c2786eb1560dd89e6e83445 added bootstrap.shared command and fixed some bugs with heatmap --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index e9fbcfe..aaeab8d 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + 211C38320F961DD400FEE541 /* sharedutilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 211C38300F961DD400FEE541 /* sharedutilities.cpp */; }; + 211C38380F961E1F00FEE541 /* treegroupscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 211C38360F961E1F00FEE541 /* treegroupscommand.cpp */; }; + 21DDC01B0F97A8FE0060691C /* bootstrapsharedcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21DDC01A0F97A8FE0060691C /* bootstrapsharedcommand.cpp */; }; 370B88070F8A4EE4005AB382 /* getoturepcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 370B88060F8A4EE4005AB382 /* getoturepcommand.cpp */; }; 372E12700F26365B0095CF7E /* readotucommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 372E126F0F26365B0095CF7E /* readotucommand.cpp */; }; 372E12960F263D5A0095CF7E /* readdistcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 372E12950F263D5A0095CF7E /* readdistcommand.cpp */; }; @@ -137,6 +140,12 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 211C38300F961DD400FEE541 /* sharedutilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedutilities.cpp; sourceTree = ""; }; + 211C38310F961DD400FEE541 /* sharedutilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedutilities.h; sourceTree = ""; }; + 211C38360F961E1F00FEE541 /* treegroupscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = treegroupscommand.cpp; sourceTree = ""; }; + 211C38370F961E1F00FEE541 /* treegroupscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = treegroupscommand.h; sourceTree = ""; }; + 21DDC0190F97A8FE0060691C /* bootstrapsharedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bootstrapsharedcommand.h; sourceTree = ""; }; + 21DDC01A0F97A8FE0060691C /* bootstrapsharedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = bootstrapsharedcommand.cpp; sourceTree = ""; }; 370B88050F8A4EE4005AB382 /* getoturepcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = getoturepcommand.h; sourceTree = ""; }; 370B88060F8A4EE4005AB382 /* getoturepcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = getoturepcommand.cpp; sourceTree = ""; }; 372E126E0F26365B0095CF7E /* readotucommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readotucommand.h; sourceTree = ""; }; @@ -334,7 +343,6 @@ 37D928490F21331F001D4494 /* summarydisplay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = summarydisplay.h; sourceTree = ""; }; 37D9284A0F21331F001D4494 /* summarysharedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = summarysharedcommand.cpp; sourceTree = ""; }; 37D9284B0F21331F001D4494 /* summarysharedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = summarysharedcommand.h; sourceTree = ""; }; - 37D9284C0F21331F001D4494 /* utilities.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = utilities.hpp; sourceTree = ""; }; 37D9284D0F21331F001D4494 /* uvest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = uvest.cpp; sourceTree = ""; }; 37D9284E0F21331F001D4494 /* uvest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = uvest.h; sourceTree = ""; }; 37D9284F0F21331F001D4494 /* validcalculator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = validcalculator.cpp; sourceTree = ""; }; @@ -461,10 +469,11 @@ 37D9281C0F21331F001D4494 /* sequence.cpp */, 37D928210F21331F001D4494 /* shared.h */, 37D928200F21331F001D4494 /* shared.cpp */, + 211C38310F961DD400FEE541 /* sharedutilities.h */, + 211C38300F961DD400FEE541 /* sharedutilities.cpp */, 37D928420F21331F001D4494 /* singlelinkage.cpp */, 37D928480F21331F001D4494 /* summarydata.h */, 37D928490F21331F001D4494 /* summarydisplay.h */, - 37D9284C0F21331F001D4494 /* utilities.hpp */, 37519AB30F810FAE00FED5E8 /* venn.h */, 37519AB40F810FAE00FED5E8 /* venn.cpp */, ); @@ -574,6 +583,8 @@ 37D927CD0F21331F001D4494 /* command.hpp */, 37C1D9710F86506E0059E3F0 /* binsequencecommand.h */, 37C1D9720F86506E0059E3F0 /* binsequencecommand.cpp */, + 21DDC0190F97A8FE0060691C /* bootstrapsharedcommand.h */, + 21DDC01A0F97A8FE0060691C /* bootstrapsharedcommand.cpp */, 37D927C40F21331F001D4494 /* clustercommand.h */, 37D927C30F21331F001D4494 /* clustercommand.cpp */, 37D927C80F21331F001D4494 /* collectcommand.h */, @@ -620,6 +631,8 @@ 37D928460F21331F001D4494 /* summarycommand.cpp */, 37D9284B0F21331F001D4494 /* summarysharedcommand.h */, 37D9284A0F21331F001D4494 /* summarysharedcommand.cpp */, + 211C38370F961E1F00FEE541 /* treegroupscommand.h */, + 211C38360F961E1F00FEE541 /* treegroupscommand.cpp */, 3746109B0F40657600460C57 /* unifracunweightedcommand.h */, 3746109C0F40657600460C57 /* unifracunweightedcommand.cpp */, 374610760F40645300460C57 /* unifracweightedcommand.h */, @@ -847,6 +860,9 @@ 7E412F490F8D21B600381DD0 /* slibshuff.cpp in Sources */, 7E412FEA0F8D3E2C00381DD0 /* libshuff.cpp in Sources */, 7E4130F80F8E58FA00381DD0 /* dlibshuff.cpp in Sources */, + 211C38320F961DD400FEE541 /* sharedutilities.cpp in Sources */, + 211C38380F961E1F00FEE541 /* treegroupscommand.cpp in Sources */, + 21DDC01B0F97A8FE0060691C /* bootstrapsharedcommand.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/bergerparker.cpp b/bergerparker.cpp index 41e6e9f..893f2a9 100644 --- a/bergerparker.cpp +++ b/bergerparker.cpp @@ -3,7 +3,7 @@ * Mothur * * Created by Thomas Ryabin on 3/6/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ diff --git a/bergerparker.h b/bergerparker.h index f164ec8..a0fd2aa 100644 --- a/bergerparker.h +++ b/bergerparker.h @@ -5,7 +5,7 @@ * Mothur * * Created by Thomas Ryabin on 3/6/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ diff --git a/bootstrapsharedcommand.cpp b/bootstrapsharedcommand.cpp new file mode 100644 index 0000000..b2a64ed --- /dev/null +++ b/bootstrapsharedcommand.cpp @@ -0,0 +1,309 @@ +/* + * bootstrapsharedcommand.cpp + * Mothur + * + * Created by Sarah Westcott on 4/16/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +#include "bootstrapsharedcommand.h" +#include "sharedjabund.h" +#include "sharedsorabund.h" +#include "sharedjclass.h" +#include "sharedsorclass.h" +#include "sharedjest.h" +#include "sharedsorest.h" +#include "sharedthetayc.h" +#include "sharedthetan.h" +#include "sharedmorisitahorn.h" + + +//********************************************************************************************************************** + +BootSharedCommand::BootSharedCommand(){ + try { + globaldata = GlobalData::getInstance(); + format = globaldata->getFormat(); + convert(globaldata->getIters(), iters); + validCalculator = new ValidCalculators(); + util = new SharedUtil(); + + + int i; + for (i=0; iEstimators.size(); i++) { + if (validCalculator->isValidCalculator("boot", globaldata->Estimators[i]) == true) { + if (globaldata->Estimators[i] == "jabund") { + treeCalculators.push_back(new JAbund()); + }else if (globaldata->Estimators[i] == "sorensonabund") { + treeCalculators.push_back(new SorAbund()); + }else if (globaldata->Estimators[i] == "jclass") { + treeCalculators.push_back(new Jclass()); + }else if (globaldata->Estimators[i] == "sorclass") { + treeCalculators.push_back(new SorClass()); + }else if (globaldata->Estimators[i] == "jest") { + treeCalculators.push_back(new Jest()); + }else if (globaldata->Estimators[i] == "sorest") { + treeCalculators.push_back(new SorEst()); + }else if (globaldata->Estimators[i] == "thetayc") { + treeCalculators.push_back(new ThetaYC()); + }else if (globaldata->Estimators[i] == "thetan") { + treeCalculators.push_back(new ThetaN()); + }else if (globaldata->Estimators[i] == "morisitahorn") { + treeCalculators.push_back(new MorHorn()); + } + } + } + + ofstream* temp; + for (int i=0; i < treeCalculators.size(); i++) { + temp = new ofstream; + out.push_back(temp); + } + + //reset calc for next command + globaldata->setCalc(""); + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the BootSharedCommand class Function BootSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the BootSharedCommand class function BootSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} +//********************************************************************************************************************** + +BootSharedCommand::~BootSharedCommand(){ + delete input; + delete read; + delete util; +} + +//********************************************************************************************************************** + +int BootSharedCommand::execute(){ + try { + int count = 1; + EstOutput data; + + //if the users entered no valid calculators don't execute command + if (treeCalculators.size() == 0) { return 0; } + + if (format == "sharedfile") { + read = new ReadPhilFile(globaldata->inputFileName); + read->read(&*globaldata); + + input = globaldata->ginput; + order = input->getSharedOrderVector(); + }else { + //you are using a list and a groupfile + read = new ReadPhilFile(globaldata->inputFileName); + read->read(&*globaldata); + + input = globaldata->ginput; + SharedList = globaldata->gSharedList; + order = SharedList->getSharedOrderVector(); + } + + //set users groups + util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "treegroup"); + numGroups = globaldata->Groups.size(); + + //clear globaldatas old tree names if any + globaldata->Treenames.clear(); + + //fills globaldatas tree names + globaldata->Treenames = globaldata->Groups; + + //create treemap class from groupmap for tree class to use + tmap = new TreeMap(); + tmap->makeSim(globaldata->gGroupmap); + globaldata->gTreemap = tmap; + + while(order != NULL){ + + if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){ + + cout << order->getLabel() << '\t' << count << endl; + + //open an ostream for each calc to print to + for (int z = 0; z < treeCalculators.size(); z++) { + //create a new filename + outputFile = getRootName(globaldata->inputFileName) + treeCalculators[z]->getName() + ".boot" + order->getLabel() + ".tre"; + openOutputFile(outputFile, *(out[z])); + } + + //create a file for each calculator with the 1000 trees in it. + for (int p = 0; p < iters; p++) { + + util->getSharedVectorswithReplacement(globaldata->Groups, lookup, order); //fills group vectors from order vector. + + //for each calculator + for(int i = 0 ; i < treeCalculators.size(); i++) { + + //initialize simMatrix + simMatrix.clear(); + simMatrix.resize(numGroups); + for (int m = 0; m < simMatrix.size(); m++) { + for (int j = 0; j < simMatrix.size(); j++) { + simMatrix[m].push_back(0.0); + } + } + + //initialize index + index.clear(); + for (int g = 0; g < numGroups; g++) { index[g] = g; } + + for (int k = 0; k < lookup.size(); k++) { // pass cdd each set of groups to commpare + for (int l = k; l < lookup.size(); l++) { + if (k != l) { //we dont need to similiarity of a groups to itself + //get estimated similarity between 2 groups + data = treeCalculators[i]->getValues(lookup[k], lookup[l]); //saves the calculator outputs + //save values in similarity matrix + simMatrix[k][l] = data[0]; + simMatrix[l][k] = data[0]; + } + } + } + + //creates tree from similarity matrix and write out file + createTree(out[i]); + } + } + //close ostream for each calc + for (int z = 0; z < treeCalculators.size(); z++) { out[z]->close(); } + } + + //get next line to process + if (format == "sharedfile") { + order = input->getSharedOrderVector(); + }else { + //you are using a list and a groupfile + SharedList = input->getSharedListVector(); //get new list vector to process + if (SharedList != NULL) { + order = SharedList->getSharedOrderVector(); //gets new order vector with group info. + }else { + break; + } + } + count++; + } + + //reset groups parameter + globaldata->Groups.clear(); globaldata->setGroups(""); + + return 0; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the BootSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the BootSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} +//********************************************************************************************************************** + +void BootSharedCommand::createTree(ostream* out){ + try { + //create tree + t = new Tree(); + + //do merges and create tree structure by setting parents and children + //there are numGroups - 1 merges to do + for (int i = 0; i < (numGroups - 1); i++) { + + float largest = 0.0; + int row, column; + //find largest value in sims matrix by searching lower triangle + for (int j = 1; j < simMatrix.size(); j++) { + for (int k = 0; k < j; k++) { + if (simMatrix[j][k] > largest) { largest = simMatrix[j][k]; row = j; column = k; } + } + } + + //set non-leaf node info and update leaves to know their parents + //non-leaf + t->tree[numGroups + i].setChildren(index[row], index[column]); + + //parents + t->tree[index[row]].setParent(numGroups + i); + t->tree[index[column]].setParent(numGroups + i); + + //blength = distance / 2; + float blength = ((1.0 - largest) / 2); + + //branchlengths + t->tree[index[row]].setBranchLength(blength - t->tree[index[row]].getLengthToLeaves()); + t->tree[index[column]].setBranchLength(blength - t->tree[index[column]].getLengthToLeaves()); + + //set your length to leaves to your childs length plus branchlength + t->tree[numGroups + i].setLengthToLeaves(t->tree[index[row]].getLengthToLeaves() + t->tree[index[row]].getBranchLength()); + + + //update index + index[row] = numGroups+i; + index[column] = numGroups+i; + + //zero out highest value that caused the merge. + simMatrix[row][column] = 0.0; + simMatrix[column][row] = 0.0; + + //merge values in simsMatrix + for (int n = 0; n < simMatrix.size(); n++) { + //row becomes merge of 2 groups + simMatrix[row][n] = (simMatrix[row][n] + simMatrix[column][n]) / 2; + simMatrix[n][row] = simMatrix[row][n]; + //delete column + simMatrix[column][n] = 0.0; + simMatrix[n][column] = 0.0; + } + } + + //assemble tree + t->assembleTree(); + + //print newick file + t->print(*out); + + //delete tree + delete t; + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the BootSharedCommand class Function createTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the BootSharedCommand class function createTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} +/***********************************************************/ +void BootSharedCommand::printSims() { + try { + cout << "simsMatrix" << endl; + for (int m = 0; m < simMatrix.size(); m++) { + for (int n = 0; n < simMatrix.size(); n++) { + cout << simMatrix[m][n] << '\t'; + } + cout << endl; + } + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the BootSharedCommand class Function printSims. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the BootSharedCommand class function printSims. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} +/***********************************************************/ + + diff --git a/bootstrapsharedcommand.h b/bootstrapsharedcommand.h new file mode 100644 index 0000000..194aa33 --- /dev/null +++ b/bootstrapsharedcommand.h @@ -0,0 +1,59 @@ +#ifndef BOOTSTRAPSHAREDCOMMAND_H +#define BOOTSTRAPSHAREDCOMMAND_H + +/* + * bootstrapsharedcommand.h + * Mothur + * + * Created by Sarah Westcott on 4/16/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +#include "command.hpp" +#include "sharedordervector.h" +#include "sharedlistvector.h" +#include "inputdata.h" +#include "groupmap.h" +#include "readmatrix.hpp" +#include "validcalculator.h" +#include "tree.h" +#include "treemap.h" +#include "sharedutilities.h" + +class GlobalData; + +class BootSharedCommand : public Command { + +public: + BootSharedCommand(); + ~BootSharedCommand(); + int execute(); + +private: + void createTree(ostream*); + void printSims(); + + GlobalData* globaldata; + SharedUtil* util; + ReadMatrix* read; + TreeMap* tmap; + Tree* t; + vector treeCalculators; + vector out; + vector< vector > simMatrix; + map index; //maps row in simMatrix to vector index in the tree + InputData* input; + ValidCalculators* validCalculator; + SharedListVector* SharedList; + SharedOrderVector* order; + vector lookup; + string format, outputFile; + int numGroups, iters; + +}; + + +#endif + + diff --git a/bstick.cpp b/bstick.cpp index 0dc67b9..7f12d1d 100644 --- a/bstick.cpp +++ b/bstick.cpp @@ -3,7 +3,7 @@ * Mothur * * Created by Thomas Ryabin on 3/6/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ diff --git a/bstick.h b/bstick.h index f2107b1..f4693b7 100644 --- a/bstick.h +++ b/bstick.h @@ -5,7 +5,7 @@ * Mothur * * Created by Thomas Ryabin on 3/6/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ #include "calculator.h" diff --git a/commandfactory.cpp b/commandfactory.cpp index b4e68e4..ff15613 100644 --- a/commandfactory.cpp +++ b/commandfactory.cpp @@ -36,6 +36,7 @@ #include "binsequencecommand.h" #include "getoturepcommand.h" #include "treegroupscommand.h" +#include "bootstrapsharedcommand.h" /***********************************************************/ @@ -83,7 +84,8 @@ Command* CommandFactory::getCommand(string commandName){ else if(commandName == "venn") { command = new VennCommand(); } else if(commandName == "bin.seqs") { command = new BinSeqCommand(); } else if(commandName == "get.oturep") { command = new GetOTURepCommand(); } - else if(commandName == "tree.groups") { command = new TreeGroupCommand(); } + else if(commandName == "tree.shared") { command = new TreeGroupCommand(); } + else if(commandName == "bootstrap.shared") { command = new BootSharedCommand(); } else { command = new NoCommand(); } return command; diff --git a/errorchecking.cpp b/errorchecking.cpp index 841cad2..4eef3b0 100644 --- a/errorchecking.cpp +++ b/errorchecking.cpp @@ -111,7 +111,7 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "abund" ) { abund = value; } if (parameter == "random" ) { randomtree = value; } if (parameter == "sorted" ) { sorted = value; } - if (parameter == "scaler" ) { scaler = value; } + if (parameter == "scale" ) { scale = value; } } @@ -146,7 +146,7 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "random" ) { randomtree = value; } if (parameter == "abund" ) { abund = value; } if (parameter == "sorted" ) { sorted = value; } - if (parameter == "scaler" ) { scaler = value; } + if (parameter == "scale" ) { scale = value; } } } @@ -219,10 +219,10 @@ bool ErrorCheck::checkInput(string input) { if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a list, sabund or rabund before you can use the collect.single, rarefaction.single or summary.single commands." << endl; return false; } } - if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") || (commandName == "tree.groups") ){ + if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") || (commandName == "tree.shared") || (commandName == "bootstrap.shared")){ if (globaldata->getSharedFile() == "") { - if (globaldata->getListFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared, summary.shared or tree.groups commands." << endl; return false; } - else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared, summary.shared or tree.groups commands." << endl; return false; } + if (globaldata->getListFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared, summary.shared, tree.shared or bootstrap.shared commands." << endl; return false; } + else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared, summary.shared, tree.shared or bootstrap.shared commands." << endl; return false; } } } diff --git a/errorchecking.h b/errorchecking.h index 3ddc65c..05ce5cf 100644 --- a/errorchecking.h +++ b/errorchecking.h @@ -34,7 +34,7 @@ class ErrorCheck { void clear(); void refresh(); string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, treefile, sharedfile, cutoff, format; - string precision, method, fileroot, label, line, iters, jumble, freq, single, rarefaction, shared, summary, randomtree, abund, sorted, scaler; + string precision, method, fileroot, label, line, iters, jumble, freq, single, rarefaction, shared, summary, randomtree, abund, sorted, scale; string commandName, optionText; bool errorFree; diff --git a/fileoutput.cpp b/fileoutput.cpp index e6f069d..9c1f9c0 100644 --- a/fileoutput.cpp +++ b/fileoutput.cpp @@ -90,7 +90,7 @@ void ThreeColumnFile::resetFile(){ renameOk = rename(outName.c_str(), inName.c_str()); //checks to make sure user was able to rename and remove successfully - if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; } + if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; cout << outName << " g " << inName << endl;} } catch(exception& e) { @@ -106,7 +106,7 @@ void ThreeColumnFile::resetFile(){ /***********************************************************************/ /***********************************************************************/ -ThreeColumnFile2::~ThreeColumnFile2(){ +ColumnFile::~ColumnFile(){ inFile.close(); outFile.close(); @@ -115,7 +115,7 @@ ThreeColumnFile2::~ThreeColumnFile2(){ /***********************************************************************/ -void ThreeColumnFile2::initFile(string label, vector tags){ +void ColumnFile::initFile(string label, vector tags){ try { if(counter != 0){ openOutputFile(outName, outFile); @@ -125,7 +125,7 @@ void ThreeColumnFile2::initFile(string label, vector tags){ getline(inFile, inputBuffer); outFile << inputBuffer << '\t'; - for(int i = 1; i < tags.size(); i++) { + for(int i = 0; i < tags.size(); i++) { outFile << label + tags[i] << '\t'; } outFile << endl; @@ -136,52 +136,58 @@ void ThreeColumnFile2::initFile(string label, vector tags){ outFile << label + tags[i] << '\t'; } outFile << endl; - } outFile.setf(ios::fixed, ios::floatfield); outFile.setf(ios::showpoint); } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + cout << "Standard Error: " << e.what() << " has occurred in the ColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; exit(1); } catch(...) { - cout << "An unknown error has occurred in the ThreeColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + cout << "An unknown error has occurred in the ColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; exit(1); } } /***********************************************************************/ -void ThreeColumnFile2::output(vector data){ +void ColumnFile::output(vector data){ try { if(counter != 0){ string inputBuffer; getline(inFile, inputBuffer); - outFile << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl; + outFile << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()); + for (int i = 1; i< data.size(); i++) { + outFile << '\t' << data[i]; + } + outFile << endl; } else{ - outFile << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl; - + outFile << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()); + for (int i = 1; i< data.size(); i++) { + outFile << '\t' << data[i]; + } + outFile << endl; } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile2 class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + cout << "Standard Error: " << e.what() << " has occurred in the ColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; exit(1); } catch(...) { - cout << "An unknown error has occurred in the ThreeColumnFile2 class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + cout << "An unknown error has occurred in the ColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; exit(1); } }; /***********************************************************************/ -void ThreeColumnFile2::resetFile(){ +void ColumnFile::resetFile(){ try { if(counter != 0){ outFile.close(); @@ -200,11 +206,11 @@ void ThreeColumnFile2::resetFile(){ } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile2 class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + cout << "Standard Error: " << e.what() << " has occurred in the ColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; exit(1); } catch(...) { - cout << "An unknown error has occurred in the ThreeColumnFile2 class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + cout << "An unknown error has occurred in the ColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; exit(1); } } diff --git a/fileoutput.h b/fileoutput.h index 7e9d8d2..3b73b14 100644 --- a/fileoutput.h +++ b/fileoutput.h @@ -13,12 +13,13 @@ class FileOutput { public: FileOutput(){}; ~FileOutput(){}; - virtual void output(int, vector) = 0; + virtual void initFile(string) = 0; - virtual void resetFile() = 0; - virtual string getFileName() = 0; virtual void initFile(string, vector) = 0; + virtual void output(int, vector) = 0; virtual void output(vector) = 0; + virtual void resetFile() = 0; + virtual string getFileName() = 0; protected: GlobalData* globaldata; @@ -38,7 +39,7 @@ public: void resetFile(); string getFileName() { return inName; }; - void initFile(string, vector) {}; + void initFile(string, vector){}; void output(vector) {}; private: @@ -125,11 +126,11 @@ private: /***********************************************************************/ -class ThreeColumnFile2 : public FileOutput { +class ColumnFile : public FileOutput { public: - ThreeColumnFile2(string n) : FileOutput(), inName(n), counter(0), outName(getPathName(n) + ".temp." + getSimpleName(n)) { globaldata = GlobalData::getInstance(); }; - ~ThreeColumnFile2(); + ColumnFile(string n) : FileOutput(), inName(n), counter(0), outName(getPathName(n) + ".temp." + getSimpleName(n)) { globaldata = GlobalData::getInstance(); }; + ~ColumnFile(); //to make compatible with parent class void output(int, vector){}; diff --git a/geom.cpp b/geom.cpp index 1a7c2bf..1b8c4ec 100644 --- a/geom.cpp +++ b/geom.cpp @@ -3,7 +3,7 @@ * Mothur * * Created by Thomas Ryabin on 2/23/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ diff --git a/geom.h b/geom.h index 56bc112..b9da73f 100644 --- a/geom.h +++ b/geom.h @@ -6,7 +6,7 @@ * Mothur * * Created by Thomas Ryabin on 2/23/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ #include "calculator.h" diff --git a/getgroupcommand.cpp b/getgroupcommand.cpp index 59987a3..b4d2d74 100644 --- a/getgroupcommand.cpp +++ b/getgroupcommand.cpp @@ -3,7 +3,7 @@ * Mothur * * Created by Thomas Ryabin on 2/2/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ diff --git a/getgroupcommand.h b/getgroupcommand.h index b296735..6750373 100644 --- a/getgroupcommand.h +++ b/getgroupcommand.h @@ -6,7 +6,7 @@ * Mothur * * Created by Thomas Ryabin on 2/2/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ diff --git a/getlabelcommand.cpp b/getlabelcommand.cpp index c5a59ac..1e27267 100644 --- a/getlabelcommand.cpp +++ b/getlabelcommand.cpp @@ -3,7 +3,7 @@ * Mothur * * Created by Thomas Ryabin on 1/30/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ diff --git a/getlabelcommand.h b/getlabelcommand.h index d3797ac..ec0692c 100644 --- a/getlabelcommand.h +++ b/getlabelcommand.h @@ -6,7 +6,7 @@ * Mothur * * Created by Thomas Ryabin on 1/30/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ diff --git a/getlinecommand.cpp b/getlinecommand.cpp index a7ca17f..09b1654 100644 --- a/getlinecommand.cpp +++ b/getlinecommand.cpp @@ -3,7 +3,7 @@ * Mothur * * Created by Thomas Ryabin on 1/30/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ diff --git a/getlinecommand.h b/getlinecommand.h index 7953f9f..2eda1cc 100644 --- a/getlinecommand.h +++ b/getlinecommand.h @@ -6,7 +6,7 @@ * Mothur * * Created by Thomas Ryabin on 1/30/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ diff --git a/globaldata.cpp b/globaldata.cpp index 5bc7f58..714b5ad 100644 --- a/globaldata.cpp +++ b/globaldata.cpp @@ -73,7 +73,7 @@ void GlobalData::parseGlobalData(string commandString, string optionText){ if (key == "step") { step = value; } if (key == "form") { form = value; } if (key == "sorted") { sorted = value; } - if (key == "scaler") { scaler = value; } + if (key == "scale") { scale = value; } @@ -129,7 +129,7 @@ void GlobalData::parseGlobalData(string commandString, string optionText){ if (key == "step") { step = value; } if (key == "form") { form = value; } if (key == "sorted") { sorted = value; } - if (key == "scaler") { scaler = value; } + if (key == "scale") { scale = value; } if (key == "line") {//stores lines to be used in a vector @@ -200,7 +200,7 @@ void GlobalData::parseGlobalData(string commandString, string optionText){ Estimators.clear(); splitAtDash(calc, Estimators); } - if (commandName == "tree.groups") { + if ((commandName == "tree.shared") || (commandName == "bootstrap.shared")) { if (calc != "") { Estimators.clear(); splitAtDash(calc, Estimators); @@ -253,7 +253,7 @@ string GlobalData::getGroups() { return groups; } string GlobalData::getStep() { return step; } string GlobalData::getForm() { return form; } string GlobalData::getSorted() { return sorted; } -string GlobalData::getScaler() { return scaler; } +string GlobalData::getScale() { return scale; } void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;} void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;} void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;} @@ -304,8 +304,8 @@ void GlobalData::clear() { abund = "10"; step = "0.01"; form = "integral"; - sorted = "1"; //0 means don't sort, 1 means sort. - scaler = "log10"; + sorted = "T"; //F means don't sort, T means sort. + scale = "log10"; } //*******************************************************/ @@ -317,7 +317,7 @@ void GlobalData::reset() { iters = "1000"; groups = ""; jumble = "1"; //0 means don't jumble, 1 means jumble. - sorted = "1"; //0 means don't sort, 1 means sort. + sorted = "T"; //F means don't sort, T means sort. randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile. freq = "100"; method = "furthest"; @@ -392,7 +392,7 @@ void GlobalData::parseTreeFile() { //use nexus translation rather than parsing tree to save time if ((holder == "translate") || (holder == "Translate")) { -cout << "there is a translate " << endl; + string number, name, h; h = ""; // so it enters the loop the first time while((h != ";") && (number != ";")) { diff --git a/globaldata.hpp b/globaldata.hpp index 3b688b4..be5b008 100644 --- a/globaldata.hpp +++ b/globaldata.hpp @@ -70,7 +70,7 @@ public: string getStep(); string getForm(); string getSorted(); - string getScaler(); + string getScale(); void setListFile(string); void setPhylipFile(string); @@ -97,7 +97,7 @@ public: private: string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, treefile, sharedfile, line, label, randomtree, groups; - string cutoff, format, precision, method, fileroot, iters, jumble, freq, calc, abund, step, form, sorted, scaler; + string cutoff, format, precision, method, fileroot, iters, jumble, freq, calc, abund, step, form, sorted, scale; static GlobalData* _uniqueInstance; GlobalData( const GlobalData& ); // Disable copy constructor diff --git a/heatmap.cpp b/heatmap.cpp index 523662e..08eb732 100644 --- a/heatmap.cpp +++ b/heatmap.cpp @@ -35,24 +35,24 @@ void HeatMap::getPic(OrderVector* order) { rabund = order->getRAbundVector(); //get users scaling method - scaler = globaldata->getScaler(); + scaler = globaldata->getScale(); float maxbin = 0.0; for (int i = 0; i < rabund.size(); i++) { if (rabund.get(i) != 0) { //don't want log value of 0. if (scaler == "log10") { - colorScale[(log10((rabund.get(i) / (float)rabund.getNumSeqs()) * 100))] = ""; - if (maxbin < (log10((rabund.get(i) / (float)rabund.getNumSeqs()) * 100))) { maxbin = (log10((rabund.get(i) / (float)rabund.getNumSeqs()) * 100)); } + colorScale[(log10((rabund.get(i) / (float)rabund.getNumSeqs()) * 1000))] = ""; + if (maxbin < (log10((rabund.get(i) / (float)rabund.getNumSeqs()) * 1000))) { maxbin = (log10((rabund.get(i) / (float)rabund.getNumSeqs()) * 1000)); } }else if (scaler == "log2") { - colorScale[(log2((rabund.get(i) / (float)rabund.getNumSeqs()) * 100))] = ""; - if (maxbin < (log2((rabund.get(i) / (float)rabund.getNumSeqs()) * 100))) { maxbin = (log2((rabund.get(i) / (float)rabund.getNumSeqs()) * 100)); } + colorScale[(log2((rabund.get(i) / (float)rabund.getNumSeqs()) * 1000))] = ""; + if (maxbin < (log2((rabund.get(i) / (float)rabund.getNumSeqs()) * 1000))) { maxbin = (log2((rabund.get(i) / (float)rabund.getNumSeqs()) * 1000)); } }else if (scaler == "linear") { colorScale[rabund.get(i)] = ""; if (maxbin < rabund.get(i)) { maxbin = rabund.get(i); } }else { //if user enters invalid scaler option. cout << scaler << " is not a valid scaler option. I will use log10." << endl; - colorScale[(log10((rabund.get(i) / (float)rabund.getNumSeqs()) * 100))] = ""; - if (maxbin < (log10((rabund.get(i) / (float)rabund.getNumSeqs()) * 100))) { maxbin = (log10((rabund.get(i)) / (float)rabund.getNumSeqs()) * 100); } + colorScale[(log10((rabund.get(i) / (float)rabund.getNumSeqs()) * 1000))] = ""; + if (maxbin < (log10((rabund.get(i) / (float)rabund.getNumSeqs()) * 1000))) { maxbin = (log10((rabund.get(i)) / (float)rabund.getNumSeqs()) * 1000); } } }else { colorScale[0] = "00"; } } @@ -77,46 +77,21 @@ void HeatMap::getPic(OrderVector* order) { outsvg << "Heatmap at distance " + order->getLabel() + "\n"; //output legend and color labels - //go through map and give each score a color value string color; int x = 0; int y = 103 + (rabund.getNumBins()*5); - if (maxbin != 0) { - //convert maxbin to relative abundance again - if (scaler == "log10") { - maxbin = pow(10, maxbin) / 100; - }else if (scaler == "log2") { - maxbin = pow(2, maxbin) / 100; - }else { maxbin = pow(10, maxbin) / 100; } - }else { maxbin = 0.00; } + printLegend(y, maxbin); - //5 is the number of boxes in the legend - float maxbinScaler = maxbin / 10; - float colorScaler = 255 / 10; - - for (int i = 0; i < 10; i++) { - string label = toString(((i+1) * maxbinScaler)); - //set precision of relative abundance to 3 - int pos = label.find_first_of('.'); - label = label.substr(0,pos+4); - color = toHex(int((float)(i+1) * colorScaler)); - - outsvg << "\n"; - outsvg << "" + label + "\n"; - x += 30; - } - - x = 0; y = 70; for (int i = 0; i <= rabund.getNumBins(); i++) { if (rabund.get(i) != 0) { //don't want log value of 0. if (scaler == "log10") { - color = colorScale[(log10((rabund.get(i) / (float)rabund.getNumSeqs()) * 100))]; + color = colorScale[(log10((rabund.get(i) / (float)rabund.getNumSeqs()) * 1000))]; }else if (scaler == "log2") { - color = colorScale[(log2((rabund.get(i) / (float)rabund.getNumSeqs()) * 100))]; + color = colorScale[(log2((rabund.get(i) / (float)rabund.getNumSeqs()) * 1000))]; }else if (scaler == "linear") { color = colorScale[rabund.get(i)]; - }else { color = colorScale[(log10((rabund.get(i) / (float)rabund.getNumSeqs()) * 100))]; } + }else { color = colorScale[(log10((rabund.get(i) / (float)rabund.getNumSeqs()) * 1000))]; } }else { color = "OO"; } outsvg << "\n"; @@ -143,30 +118,30 @@ void HeatMap::getPic(SharedOrderVector* sharedorder) { //fills vector of sharedsabunds - lookup util->getSharedVectors(globaldata->Groups, lookup, sharedorder); //fills group vectors from order vector. - + //sort lookup so shared bins are on top - if (sorted == "1") { sortSharedVectors(); } - + if (sorted == "T") { sortSharedVectors(); } + //get users scaling method - scaler = globaldata->getScaler(); + scaler = globaldata->getScale(); float maxbin = 0.0; for (int i = 0; i < lookup.size(); i++) { for (int j = 0; j < lookup[i]->size(); j++) { if (lookup[i]->getAbundance(j) != 0) { //don't want log value of 0. if (scaler == "log10") { - colorScale[(log10((lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) * 100))] = ""; - if (maxbin < (log10((lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) * 100))) { maxbin = (log10((lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) * 100)); } + colorScale[(log10((lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) * 1000))] = ""; + if (maxbin < (log10((lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) * 1000))) { maxbin = (log10((lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) * 1000)); } }else if (scaler == "log2") { - colorScale[(log2((lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) * 100))] = ""; - if (maxbin < (log2((lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) * 100))) { maxbin = (log2((lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) * 100)); } + colorScale[(log2((lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) * 1000))] = ""; + if (maxbin < (log2((lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) * 1000))) { maxbin = (log2((lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) * 1000)); } }else if (scaler == "linear") { colorScale[lookup[i]->getAbundance(j)] = ""; if (maxbin < lookup[i]->getAbundance(j)) { maxbin = lookup[i]->getAbundance(j); } }else { //if user enters invalid scaler option. cout << scaler << " is not a valid scaler option. I will use log10." << endl; - colorScale[(log10((lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) * 100))] = ""; - if (maxbin < (log10((lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) * 100))) { maxbin = (log10((lookup[i]->getAbundance(j)) / (float)lookup[i]->getNumSeqs()) * 100); } + colorScale[(log10((lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) * 1000))] = ""; + if (maxbin < (log10((lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) * 1000))) { maxbin = (log10((lookup[i]->getAbundance(j)) / (float)lookup[i]->getNumSeqs()) * 1000); } } }else { colorScale[0] = "00"; } } @@ -199,49 +174,23 @@ void HeatMap::getPic(SharedOrderVector* sharedorder) { } //output legend and color labels - //go through map and give each score a color value string color; int x = 0; int y = 103 + (lookup[0]->getNumBins()*5); - if (maxbin != 0) { - //convert maxbin to relative abundance again - if (scaler == "log10") { - maxbin = pow(10, maxbin) / 100; - }else if (scaler == "log2") { - maxbin = pow(2, maxbin) / 100; - }else { maxbin = pow(10, maxbin) / 100; } - }else { maxbin = 0.00; } - - //((lookup.size() * 300) / 60) is the number of boxes in the legend - float maxbinScaler = maxbin / ((lookup.size() * 300) / 60); - float colorScaler = 255 / ((lookup.size() * 300) / 60); - - for (int i = 0; i < ((lookup.size() * 300) / 60); i++) { - string label = toString(((i+1) * maxbinScaler)); - //set precision of relative abundance to 3 - int pos = label.find_first_of('.'); - label = label.substr(0,pos+4); + printLegend(y, maxbin); - color = toHex(int(((i+1) * colorScaler) + 15)); - outsvg << "\n"; - outsvg << "" + label + "\n"; - x += 30; - } - - x = 0; y = 70; - - for (int i = 0; i <= lookup[0]->getNumBins(); i++) { + for (int i = 0; i < lookup[0]->size(); i++) { for (int j = 0; j < lookup.size(); j++) { if (lookup[j]->getAbundance(i) != 0) { //don't want log value of 0. if (scaler == "log10") { - color = colorScale[(log10((lookup[j]->getAbundance(i) / (float)lookup[j]->getNumSeqs()) * 100))]; + color = colorScale[(log10((lookup[j]->getAbundance(i) / (float)lookup[j]->getNumSeqs()) * 1000))]; }else if (scaler == "log2") { - color = colorScale[(log2((lookup[j]->getAbundance(i) / (float)lookup[j]->getNumSeqs()) * 100))]; + color = colorScale[(log2((lookup[j]->getAbundance(i) / (float)lookup[j]->getNumSeqs()) * 1000))]; }else if (scaler == "linear") { color = colorScale[lookup[j]->getAbundance(i)]; - }else { color = colorScale[(log10((lookup[j]->getAbundance(i) / (float)lookup[j]->getNumSeqs()) * 100))]; } + }else { color = colorScale[(log10((lookup[j]->getAbundance(i) / (float)lookup[j]->getNumSeqs()) * 1000))]; } }else { color = "OO"; } @@ -350,7 +299,55 @@ void HeatMap::sortSharedVectors(){ } //********************************************************************************************************************** +void HeatMap::printLegend(int y, float maxbin) { + try { + + //output legend and color labels + //go through map and give each score a color value + string color; + int x = 0; + if (maxbin != 0) { + //convert maxbin to relative abundance again + if (scaler == "log10") { + maxbin = pow(10, maxbin) / 1000; + }else if (scaler == "log2") { + maxbin = pow(2, maxbin) / 1000; + }else { maxbin = pow(10, maxbin) / 1000; } + }else { maxbin = 0.00; } + + //5 is the number of boxes in the legend + float maxbinScaler = maxbin / 10; + float colorScaler = 255 / 10; + + //prints legend + for (int i = 0; i < 10; i++) { + color = toHex(int((float)(i+1) * colorScaler)); + outsvg << "\n"; + x += 30; + } + + //prints legend labels + x -= 30; + for (int i = 10; i > 0; i = i-2) { + string label = toString((i * maxbinScaler)); + //set precision of relative abundance to 3 + int pos = label.find_first_of('.'); + label = label.substr(0,pos+4); + + outsvg << "" + label + "\n"; + x -= 60; + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function printLegend. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the HeatMap class function printLegend. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} diff --git a/heatmap.h b/heatmap.h index a89500c..54035f0 100644 --- a/heatmap.h +++ b/heatmap.h @@ -32,6 +32,7 @@ class HeatMap { private: void sortSharedVectors(); + void printLegend(int, float); GlobalData* globaldata; SharedUtil* util; diff --git a/helpcommand.cpp b/helpcommand.cpp index 1693807..6cf2134 100644 --- a/helpcommand.cpp +++ b/helpcommand.cpp @@ -14,6 +14,7 @@ HelpCommand::HelpCommand(){ globaldata = GlobalData::getInstance(); validCommands = new ValidCommands(); + validCalcs = new ValidCalculators(); } //********************************************************************************************************************** @@ -77,6 +78,7 @@ int HelpCommand::execute(){ cout << "collect.single(label=yourLabel, line=yourLines, iters=yourIters, freq=yourFreq, calc=yourEstimators)." << "\n"; cout << "Example collect(label=unique-.01-.03, line=0-5-10, iters=10000, freq=10, calc=sobs-chao-ace-jack)." << "\n"; cout << "The default values for freq is 100, and calc are sobs-chao-ace-jack-shannon-npshannon-simpson." << "\n"; + validCalcs->printCalc("single", cout); cout << "The label and line parameters are used to analyze specific lines in your input." << "\n"; cout << "Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq)." << "\n" << "\n"; }else if (globaldata->helpRequest == "collect.shared") { @@ -84,9 +86,10 @@ int HelpCommand::execute(){ cout << "The collect.shared command parameters are label, line, freq, jumble, calc and groups. No parameters are required, but you may not use " << "\n"; cout << "both the line and label parameters at the same time. The collect.shared command should be in the following format: " << "\n"; cout << "collect.shared(label=yourLabel, line=yourLines, freq=yourFreq, jumble=yourJumble, calc=yourEstimators, groups=yourGroups)." << "\n"; - cout << "Example collect.shared(label=unique-.01-.03, line=0-5-10, freq=10, jumble=1, groups=B-C, calc=sharedChao-sharedAce-Jabund-SorensonAbund-Jclass-SorClass-Jest-SorEst-ThetaYC-ThetaN)." << "\n"; - cout << "The default values for jumble is 1 (meaning jumble, if it’s set to 0 then it will not jumble), freq is 100 and calc are sharedsobs-sharedChao-sharedAce-Jabund-SorensonAbund-Jclass-SorClass-Jest-SorEst-ThetaYC-ThetaN." << "\n"; + cout << "Example collect.shared(label=unique-.01-.03, line=0-5-10, freq=10, jumble=1, groups=B-C, calc=sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan)." << "\n"; + cout << "The default values for jumble is 1 (meaning jumble, if it’s set to 0 then it will not jumble), freq is 100 and calc are sharedsobs-sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan." << "\n"; cout << "The default value for groups is all the groups in your groupfile." << "\n"; + validCalcs->printCalc("shared", cout); cout << "The label and line parameters are used to analyze specific lines in your input." << "\n"; cout << "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"; cout << "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile)." << "\n" << "\n"; @@ -116,6 +119,7 @@ int HelpCommand::execute(){ cout << "rarefaction.single(label=yourLabel, line=yourLines, iters=yourIters, freq=yourFreq, calc=yourEstimators)." << "\n"; cout << "Example rarefaction.single(label=unique-.01-.03, line=0-5-10, iters=10000, freq=10, calc=sobs-rchao-race-rjack-rbootstrap-rshannon-rnpshannon-rsimpson)." << "\n"; cout << "The default values for iters is 1000, freq is 100, and calc is rarefaction which calculates the rarefaction curve for the observed richness." << "\n"; + validCalcs->printCalc("rarefaction", cout); cout << "The label and line parameters are used to analyze specific lines in your input." << "\n"; cout << "Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq)." << "\n" << "\n"; }else if (globaldata->helpRequest == "rarefaction.shared") { @@ -126,6 +130,7 @@ int HelpCommand::execute(){ cout << "Example rarefaction.shared(label=unique-.01-.03, line=0-5-10, iters=10000, jumble=1, groups=B-C, calc=sharedobserved)." << "\n"; cout << "The default values for iters is 1000, jumble is 1 (meaning jumble, if it’s set to 0 then it will not jumble), freq is 100, and calc is sharedobserved which calculates the shared rarefaction curve for the observed richness." << "\n"; cout << "The default value for groups is all the groups in your groupfile." << "\n"; + validCalcs->printCalc("sharedrarefaction", cout); cout << "The label and line parameters are used to analyze specific lines in your input." << "\n"; cout << "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"; cout << "Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq)." << "\n" << "\n"; @@ -136,6 +141,7 @@ int HelpCommand::execute(){ cout << "both the line and label parameters at the same time. The summary.single command should be in the following format: " << "\n"; cout << "summary.single(label=yourLabel, line=yourLines, calc=yourEstimators)." << "\n"; cout << "Example summary.single(label=unique-.01-.03, line=0,5,10, calc=sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson)." << "\n"; + validCalcs->printCalc("summary", cout); cout << "The default value calc is sobs-chao-ace-jack-shannon-npshannon-simpson" << "\n"; cout << "The label and line parameters are used to analyze specific lines in your input." << "\n"; cout << "Note: No spaces between parameter labels (i.e. line), '=' and parameters (i.e.yourLines)." << "\n" << "\n"; @@ -144,8 +150,9 @@ int HelpCommand::execute(){ cout << "The summary.shared command parameters are label, line, jumble and calc. No parameters are required, but you may not use " << "\n"; cout << "both the line and label parameters at the same time. The summary.shared command should be in the following format: " << "\n"; cout << "summary.shared(label=yourLabel, line=yourLines, jumble=yourJumble, calc=yourEstimators, groups=yourGroups)." << "\n"; - cout << "Example summary.shared(label=unique-.01-.03, line=0,5,10, jumble=1, groups=B-C, calc=sharedChao-sharedAce-Jabund-SorensonAbund-Jclass-SorClass-Jest-SorEst-ThetaYC-ThetaN)." << "\n"; - cout << "The default value for jumble is 1 (meaning jumble, if it’s set to 0 then it will not jumble) and calc is sharedsobs-sharedChao-sharedAce-Jabund-SorensonAbund-Jclass-SorClass-Jest-SorEst-ThetaYC-ThetaN" << "\n"; + cout << "Example summary.shared(label=unique-.01-.03, line=0,5,10, jumble=1, groups=B-C, calc=sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan)." << "\n"; + validCalcs->printCalc("sharedsummary", cout); + cout << "The default value for jumble is 1 (meaning jumble, if it’s set to 0 then it will not jumble) and calc is sharedsobs-sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan" << "\n"; cout << "The default value for groups is all the groups in your groupfile." << "\n"; cout << "The label and line parameters are used to analyze specific lines in your input." << "\n"; cout << "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"; @@ -194,16 +201,16 @@ int HelpCommand::execute(){ cout << "Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e.yourIters)." << "\n" << "\n"; }else if (globaldata->helpRequest == "heatmap") { cout << "The heatmap command can only be executed after a successful read.otu command." << "\n"; - cout << "The heatmap command parameters are groups, sorted, scaler, line and label. No parameters are required, but you may not use line and label at the same time." << "\n"; + cout << "The heatmap command parameters are groups, sorted, scale, line and label. No parameters are required, but you may not use line and label at the same time." << "\n"; cout << "The groups parameter allows you to specify which of the groups in your groupfile you would like included in your heatmap." << "\n"; cout << "The sorted parameter allows you to choose to see the file with the shared otus at the top or the otus in the order they appear in your input file. " << "\n"; - cout << "The scaler parameter allows you to choose the range of color your bin information will be displayed with." << "\n"; + cout << "The scale parameter allows you to choose the range of color your bin information will be displayed with." << "\n"; cout << "The group names are separated by dashes. The line and label allow you to select what distance levels you would like a heatmap created for, and are also separated by dashes." << "\n"; cout << "The heatmap command should be in the following format: heatmap(groups=yourGroups, sorted=yourSorted, line=yourLines, label=yourLabels)." << "\n"; - cout << "Example heatmap(groups=A-B-C, line=1-3-5, sorted=0, scaler=log10)." << "\n"; + cout << "Example heatmap(groups=A-B-C, line=1-3-5, sorted=F, scale=log10)." << "\n"; cout << "The default value for groups is all the groups in your groupfile, and all lines in your inputfile will be used." << "\n"; - cout << "The default value for sorted is 1 meaning you want the shared otus on top, you may change it to 0 meaning the exact representation of your input file." << "\n"; - cout << "The default value for scaler is log10; your other options are log2 and linear." << "\n"; + cout << "The default value for sorted is T meaning you want the shared otus on top, you may change it to F meaning the exact representation of your input file." << "\n"; + cout << "The default value for scale is log10; your other options are log2 and linear." << "\n"; cout << "The heatmap command outputs a .svg file for each line or label you specify." << "\n"; cout << "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups)." << "\n" << "\n"; }else if (globaldata->helpRequest == "venn") { @@ -211,7 +218,7 @@ int HelpCommand::execute(){ cout << "The venn command parameters are groups, calc, line and label. No parameters are required, but you may not use line and label at the same time." << "\n"; cout << "The groups parameter allows you to specify which of the groups in your groupfile you would like included in your venn diagram, you may only use a maximum of 4 groups." << "\n"; cout << "The group names are separated by dashes. The line and label allow you to select what distance levels you would like a venn diagram created for, and are also separated by dashes." << "\n"; - cout << "The venn command should be in the following format: venn(groups=yourGroups, calc=yourSorted, line=yourLines, label=yourLabels)." << "\n"; + cout << "The venn command should be in the following format: venn(groups=yourGroups, calc=yourCalcs, line=yourLines, label=yourLabels)." << "\n"; cout << "Example venn(groups=A-B-C, line=1-3-5, calc=sharedsobs-sharedchao)." << "\n"; cout << "The default value for groups is all the groups in your groupfile up to 4, and all lines in your inputfile will be used." << "\n"; cout << "The default value for calc is sobs if you have only read a list file or if you have selected only one group, and sharedsobs if you have multiple groups." << "\n"; @@ -219,6 +226,30 @@ int HelpCommand::execute(){ cout << "The only estmiator available four 4 groups is sharedsobs." << "\n"; cout << "The venn command outputs a .svg file for each calculator you specify at each distance you choose." << "\n"; cout << "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups)." << "\n" << "\n"; + }else if (globaldata->helpRequest == "tree.shared") { + cout << "The tree.shared command can only be executed after a successful read.otu command." << "\n"; + cout << "The tree.shared command parameters are groups, calc, line and label. The calc parameter is required, and you may not use line and label at the same time." << "\n"; + cout << "The groups parameter allows you to specify which of the groups in your groupfile you would like included used." << "\n"; + cout << "The group names are separated by dashes. The line and label allow you to select what distance levels you would like trees created for, and are also separated by dashes." << "\n"; + cout << "The tree.shared command should be in the following format: tree.shared(groups=yourGroups, calc=yourCalcs, line=yourLines, label=yourLabels)." << "\n"; + cout << "Example tree.shared(groups=A-B-C, line=1-3-5, calc=jabund-sorensonabund)." << "\n"; + cout << "The default value for groups is all the groups in your groupfile." << "\n"; + cout << "There is no default value for calc." << "\n"; + validCalcs->printCalc("treegroup", cout); + cout << "The tree.shared command outputs a .tre file for each calculator you specify at each distance you choose." << "\n"; + cout << "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups)." << "\n" << "\n"; + }else if (globaldata->helpRequest == "bootstrap.shared") { + cout << "The bootstrap.shared command can only be executed after a successful read.otu command." << "\n"; + cout << "The bootstrap.shared command parameters are groups, calc, iters, line and label. The calc parameter is required, and you may not use line and label at the same time." << "\n"; + cout << "The groups parameter allows you to specify which of the groups in your groupfile you would like included used." << "\n"; + cout << "The group names are separated by dashes. The line and label allow you to select what distance levels you would like trees created for, and are also separated by dashes." << "\n"; + cout << "The bootstrap.shared command should be in the following format: bootstrap.shared(groups=yourGroups, calc=yourCalcs, line=yourLines, label=yourLabels, iters=yourIters)." << "\n"; + cout << "Example bootstrap.shared(groups=A-B-C, line=1-3-5, calc=jabund-sorensonabund, iters=100)." << "\n"; + cout << "The default value for groups is all the groups in your groupfile." << "\n"; + cout << "There is no default value for calc. The default for iters is 1000." << "\n"; + validCalcs->printCalc("boot", cout); + cout << "The bootstrap.shared command outputs a .tre file for each calculator you specify at each distance you choose containing iters number of trees." << "\n"; + cout << "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups)." << "\n" << "\n"; }else if (globaldata->helpRequest == "bin.seqs") { cout << "The bin.seqs command can only be executed after a successful read.otu command of a list file." << "\n"; cout << "The bin.seqs command parameters are fasta, name, line and label. The fasta parameter is required, and you may not use line and label at the same time." << "\n"; diff --git a/helpcommand.h b/helpcommand.h index d8f9b14..58356d1 100644 --- a/helpcommand.h +++ b/helpcommand.h @@ -14,6 +14,7 @@ #include "command.hpp" #include "globaldata.hpp" #include "validcommands.h" +#include "validcalculator.h" class HelpCommand : public Command { @@ -25,6 +26,7 @@ public: private: GlobalData* globaldata; ValidCommands* validCommands; + ValidCalculators* validCalcs; private: diff --git a/logsd.cpp b/logsd.cpp index 7b63e5b..fddee4f 100644 --- a/logsd.cpp +++ b/logsd.cpp @@ -3,7 +3,7 @@ * Mothur * * Created by Thomas Ryabin on 2/23/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ diff --git a/logsd.h b/logsd.h index b96115b..02c2ca5 100644 --- a/logsd.h +++ b/logsd.h @@ -6,7 +6,7 @@ * Mothur * * Created by Thomas Ryabin on 2/23/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ #include "calculator.h" diff --git a/parsimonycommand.cpp b/parsimonycommand.cpp index 4fa4ec5..b5c59e8 100644 --- a/parsimonycommand.cpp +++ b/parsimonycommand.cpp @@ -21,15 +21,13 @@ ParsimonyCommand::ParsimonyCommand() { if (randomtree == "") { T = globaldata->gTree; tmap = globaldata->gTreemap; - parsFile = globaldata->getTreeFile() + ".parsimony"; - parsFileout = globaldata->getTreeFile() + "temp" + ".parsimony"; + output = new ColumnFile(globaldata->getTreeFile() + ".parsimony"); sumFile = globaldata->getTreeFile() + ".psummary"; openOutputFile(sumFile, outSum); }else { //user wants random distribution savetmap = globaldata->gTreemap; getUserInput(); - parsFile = randomtree; - parsFileout = globaldata->getTreeFile() + "temp"; + output = new ColumnFile(randomtree); } //set users groups to analyze @@ -223,12 +221,16 @@ int ParsimonyCommand::execute() { void ParsimonyCommand::printParsimonyFile() { try { vector data; + vector tags; - //format output - out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint); + if (randomtree == "") { + tags.push_back("Score"); tags.push_back("UserFreq"); tags.push_back("UserCumul"); tags.push_back("RandFreq"); tags.push_back("RandCumul"); + }else { + tags.push_back("Score"); tags.push_back("RandFreq"); tags.push_back("RandCumul"); + } for(int a = 0; a < numComp; a++) { - initFile(groupComb[a]); + output->initFile(groupComb[a], tags); //print each line for (it = validScores.begin(); it != validScores.end(); it++) { if (randomtree == "") { @@ -236,15 +238,11 @@ void ParsimonyCommand::printParsimonyFile() { }else{ data.push_back(it->first); data.push_back(rscoreFreq[a][it->first]); data.push_back(rCumul[a][it->first]); } - output(data); + output->output(data); data.clear(); } - resetFile(); + output->resetFile(); } - - out.close(); - inFile.close(); - remove(parsFileout.c_str()); } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the ParsimonyCommand class Function printParsimonyFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; @@ -340,102 +338,7 @@ void ParsimonyCommand::getUserInput() { exit(1); } } -/*****************************************************************/ - -void ParsimonyCommand::initFile(string label){ - try { - if(counter != 0){ - openOutputFile(parsFileout, out); - openInputFile(parsFile, inFile); - - string inputBuffer; - getline(inFile, inputBuffer); - - if (randomtree == "") { - out << inputBuffer << '\t' << label + "Score" << '\t' << label + "UserFreq" << '\t' << label + "UserCumul" << '\t' << label + "RandFreq" << '\t' << label + "RandCumul" << endl; - }else { - out << inputBuffer << '\t' << "Score" << '\t' << "RandFreq" << '\t' << "RandCumul" << endl; - } - }else{ - openOutputFile(parsFileout, out); - //column headers - if (randomtree == "") { - out << label + "Score" << '\t' << label + "UserFreq" << '\t' << label + "UserCumul" << '\t' << label + "RandFreq" << '\t' << label + "RandCumul" << endl; - }else { - out << "Score" << '\t' << "RandFreq" << '\t' << "RandCumul" << endl; - } - } - - out.setf(ios::fixed, ios::floatfield); - out.setf(ios::showpoint); - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ParsimonyCommand class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ParsimonyCommand class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} - -/***********************************************************************/ -void ParsimonyCommand::output(vector data){ - try { - if(counter != 0){ - string inputBuffer; - getline(inFile, inputBuffer); - - if (randomtree == "") { - out << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << '\t' << data[3] << '\t' << data[4] << endl; - }else{ - out << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl; - } - } - else{ - if (randomtree == "") { - out << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << '\t' << data[3] << '\t' << data[4] << endl; - }else{ - out << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl; - } - } - - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ParsimonyCommand class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ParsimonyCommand class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} - -/***********************************************************************/ - -void ParsimonyCommand::resetFile(){ - try { - if(counter != 0){ - out.close(); - inFile.close(); - } - else{ - out.close(); - } - counter = 1; - - remove(parsFile.c_str()); - rename(parsFileout.c_str(), parsFile.c_str()); - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ParsimonyCommand class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ParsimonyCommand class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} +/***********************************************************/ diff --git a/parsimonycommand.h b/parsimonycommand.h index dd4e237..26d392e 100644 --- a/parsimonycommand.h +++ b/parsimonycommand.h @@ -14,6 +14,7 @@ #include "treemap.h" #include "progress.hpp" #include "sharedutilities.h" +#include "fileoutput.h" using namespace std; @@ -23,12 +24,13 @@ class ParsimonyCommand : public Command { public: ParsimonyCommand(); - ~ParsimonyCommand() { delete pars; delete util; } + ~ParsimonyCommand() { delete pars; delete util; delete output; } int execute(); private: GlobalData* globaldata; SharedUtil* util; + FileOutput* output; vector T; //user trees Tree* randT; //random tree Tree* copyUserTree; @@ -36,7 +38,7 @@ class ParsimonyCommand : public Command { TreeMap* savetmap; Parsimony* pars; vector groupComb; // AB. AC, BC... - string parsFile, parsFileout, sumFile, randomtree, allGroups; + string sumFile, randomtree, allGroups; int iters, numGroups, numComp, counter; vector numEachGroup; //vector containing the number of sequences in each group the users wants for random distrib. vector< vector > userTreeScores; //scores for users trees for each comb. @@ -57,10 +59,6 @@ class ParsimonyCommand : public Command { void printParsimonyFile(); void printUSummaryFile(); void getUserInput(); - void initFile(string); - void output(vector); - void resetFile(); - }; diff --git a/qstat.cpp b/qstat.cpp index cac06be..a2f821e 100644 --- a/qstat.cpp +++ b/qstat.cpp @@ -3,7 +3,7 @@ * Mothur * * Created by Thomas Ryabin on 3/4/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ diff --git a/qstat.h b/qstat.h index 3911dc1..16b8b4d 100644 --- a/qstat.h +++ b/qstat.h @@ -5,7 +5,7 @@ * Mothur * * Created by Thomas Ryabin on 3/4/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ #include "calculator.h" diff --git a/raredisplay.cpp b/raredisplay.cpp index 983ed10..8126266 100644 --- a/raredisplay.cpp +++ b/raredisplay.cpp @@ -134,6 +134,7 @@ void RareDisplay::reset(){ void RareDisplay::close(){ try { + output->initFile(label); openInputFile(tempInName, tempInFile); diff --git a/sharedbdiversity.cpp b/sharedbdiversity.cpp index d00385d..ae2753d 100644 --- a/sharedbdiversity.cpp +++ b/sharedbdiversity.cpp @@ -3,7 +3,7 @@ * Mothur * * Created by Thomas Ryabin on 3/13/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ diff --git a/sharedbdiversity.h b/sharedbdiversity.h index 1a8eb87..07b4fe0 100644 --- a/sharedbdiversity.h +++ b/sharedbdiversity.h @@ -5,7 +5,7 @@ * Mothur * * Created by Thomas Ryabin on 3/13/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ #include "calculator.h" diff --git a/sharedkstest.cpp b/sharedkstest.cpp index 604f1f6..1da7c90 100644 --- a/sharedkstest.cpp +++ b/sharedkstest.cpp @@ -3,7 +3,7 @@ * Mothur * * Created by Thomas Ryabin on 3/6/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ diff --git a/sharedkstest.h b/sharedkstest.h index 8944025..67c8525 100644 --- a/sharedkstest.h +++ b/sharedkstest.h @@ -5,7 +5,7 @@ * Mothur * * Created by Thomas Ryabin on 3/6/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ #include "calculator.h" diff --git a/sharedordervector.cpp b/sharedordervector.cpp index 4cc1d18..41daa80 100644 --- a/sharedordervector.cpp +++ b/sharedordervector.cpp @@ -29,7 +29,7 @@ SharedOrderVector::SharedOrderVector(string id, vector ov) : //This function is used to read a .shared file for the collect.shared, rarefaction.shared and summary.shared commands //if you don't use a list and groupfile. -SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() { +SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() { //reads in a shared file try { globaldata = GlobalData::getInstance(); maxRank = 0; numBins = 0; numSeqs = 0; @@ -55,7 +55,7 @@ SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() { f >> inputData; for (int j = 0; j < inputData; j++) { - push_back(i+1, i+1, groupN); + push_back(i, i, groupN); numSeqs++; } } @@ -80,7 +80,7 @@ SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() { f >> inputData; for (int j = 0; j < inputData; j++) { - push_back(i+1, i+1, groupN); + push_back(i, i, groupN); numSeqs++; } } @@ -96,8 +96,9 @@ SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() { f.seekg(pos, ios::beg); if (globaldata->gGroupmap == NULL) { globaldata->gGroupmap = groupmap; } - + updateStats(); + } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function SharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; @@ -111,21 +112,18 @@ SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() { /***********************************************************************/ int SharedOrderVector::getNumBins(){ - if(needToUpdate == 1){ updateStats(); } return numBins; } /***********************************************************************/ int SharedOrderVector::getNumSeqs(){ - if(needToUpdate == 1){ updateStats(); } return numSeqs; } /***********************************************************************/ int SharedOrderVector::getMaxRank(){ - if(needToUpdate == 1){ updateStats(); } return maxRank; } @@ -139,8 +137,8 @@ void SharedOrderVector::set(int index, int binNumber, int abund, string groupNam data[index].group = groupName; data[index].bin = binNumber; data[index].abundance = abund; - needToUpdate = 1; - + //if (abund > maxRank) { maxRank = abund; } + updateStats(); } /***********************************************************************/ @@ -158,8 +156,10 @@ void SharedOrderVector::push_back(int binNumber, int abund, string groupName){ newGuy.abundance = abund; newGuy.bin = binNumber; data.push_back(newGuy); - needToUpdate = 1; - + //numSeqs++; + //numBins++; + //if (abund > maxRank) { maxRank = abund; } + updateStats(); } /***********************************************************************/ diff --git a/sharedrabundvector.cpp b/sharedrabundvector.cpp index 4683c59..9634613 100644 --- a/sharedrabundvector.cpp +++ b/sharedrabundvector.cpp @@ -242,7 +242,8 @@ void SharedRAbundVector::push_front(int binSize, int otu, string groupName){ /***********************************************************************/ void SharedRAbundVector::pop_back(){ - + numSeqs -= data[data.size()-1].abundance; + numBins--; return data.pop_back(); } @@ -276,7 +277,7 @@ void SharedRAbundVector::print(ostream& output){ try { output << numBins << '\t'; - for(int i=0;i Groups, vectorsetGroup(Groups[i]); lookup.push_back(temp); } - + int numSeqs = order->size(); //sample all the members for(int i=0;i Groups, vector Groups, vector& lookup, SharedOrderVector* order) { + try { + + //delete each sharedrabundvector in lookup + for (int j = 0; j < lookup.size(); j++) { + delete lookup[j]; + } + + lookup.clear(); + + //create and initialize vector of sharedvectors, one for each group + for (int i = 0; i < Groups.size(); i++) { + SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins()); + temp->setLabel(order->getLabel()); + temp->setGroup(Groups[i]); + lookup.push_back(temp); + } + + int numSeqs = order->size(); + + //sample all the members + for(int i=0;iget(random); + + int abundance; + //set info for sharedvector in chosens group + for (int j = 0; j < lookup.size(); j++) { + if (chosen.group == lookup[j]->getGroup()) { + abundance = lookup[j]->getAbundance(chosen.bin); + lookup[j]->set(chosen.bin, (abundance + 1), chosen.group); + break; + } + } + } + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function getSharedVectorswithReplacement. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SharedUtil class function getSharedVectorswithReplacement. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} /**************************************************************************************************/ //need to have mode because different commands require different number of valid groups diff --git a/sharedutilities.h b/sharedutilities.h index f4e4631..d43d2b6 100644 --- a/sharedutilities.h +++ b/sharedutilities.h @@ -22,6 +22,7 @@ class SharedUtil { ~SharedUtil() {}; void getSharedVectors(vector, vector&, SharedOrderVector*); + void getSharedVectorswithReplacement(vector, vector&, SharedOrderVector*); void setGroups(vector&, vector&, string); //globaldata->Groups, your tree or group map, mode void setGroups(vector&, vector&, string&, int&, string); //globaldata->Groups, your tree or group map, allgroups, numGroups, mode void getCombos(vector&, vector, int&); //groupcomb, globaldata->Groups, numcomb diff --git a/tree.cpp b/tree.cpp index f93b933..e138121 100644 --- a/tree.cpp +++ b/tree.cpp @@ -453,7 +453,22 @@ void Tree::randomTopology() { exit(1); } } - +/*****************************************************************/ +void Tree::print(ostream& out) { + try { + int root = findRoot(); + printBranch(root, out); + out << ";" << endl; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the Tree class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} /*****************************************************************/ // This prints out the tree in Newick form. void Tree::createNewickFile(string f) { @@ -463,7 +478,7 @@ void Tree::createNewickFile(string f) { filename = f; openOutputFile(filename, out); - printBranch(root); + printBranch(root, out); // you are at the end of the tree out << ";" << endl; @@ -501,15 +516,15 @@ int Tree::findRoot() { } /*****************************************************************/ -void Tree::printBranch(int node) { +void Tree::printBranch(int node, ostream& out) { try { // you are not a leaf if (tree[node].getLChild() != -1) { out << "("; - printBranch(tree[node].getLChild()); + printBranch(tree[node].getLChild(), out); out << ","; - printBranch(tree[node].getRChild()); + printBranch(tree[node].getRChild(), out); out << ")"; //if there is a branch length then print it if (tree[node].getBranchLength() != -1) { diff --git a/tree.h b/tree.h index ac57a4a..58f3a79 100644 --- a/tree.h +++ b/tree.h @@ -34,6 +34,7 @@ public: int getNumLeaves(){ return numLeaves; } map mergeUserGroups(int, vector); //returns a map with a groupname and the number of times that group was seen in the children void printTree(); + void print(ostream&); //this function takes the leaf info and populates the non leaf nodes void assembleTree(); @@ -54,7 +55,7 @@ private: void randomLabels(vector); void randomLabels(string, string); int findRoot(); //return index of root node - void printBranch(int); //recursively print out tree + void printBranch(int, ostream&); //recursively print out tree }; #endif diff --git a/treegroupscommand.cpp b/treegroupscommand.cpp index a6e1918..6cc64fe 100644 --- a/treegroupscommand.cpp +++ b/treegroupscommand.cpp @@ -141,9 +141,9 @@ int TreeGroupCommand::execute(){ for (int g = 0; g < numGroups; g++) { index[g] = g; } //create a new filename - outputFile = getRootName(globaldata->inputFileName) + treeCalculators[i]->getName() + "." + order->getLabel() + groupNames + ".tre"; + outputFile = getRootName(globaldata->inputFileName) + treeCalculators[i]->getName() + "." + order->getLabel() + ".tre"; - for (int k = 0; k < lookup.size(); k++) { // pass cdd each set of groups to commpare + for (int k = 0; k < lookup.size(); k++) { for (int l = k; l < lookup.size(); l++) { if (k != l) { //we dont need to similiarity of a groups to itself //get estimated similarity between 2 groups diff --git a/treemap.cpp b/treemap.cpp index 5880b0c..00ae0e6 100644 --- a/treemap.cpp +++ b/treemap.cpp @@ -152,7 +152,7 @@ void TreeMap::makeSim(GroupMap* groupmap) { //set names of seqs to names of groups namesOfSeqs = groupmap->namesOfGroups; - // make map where key and value are both the group name since that what the tree.groups command wants + // make map where key and value are both the group name since that what the tree.shared command wants for (int i = 0; i < namesOfGroups.size(); i++) { treemap[namesOfGroups[i]].groupname = namesOfGroups[i]; seqsPerGroup[namesOfGroups[i]] = 1; diff --git a/treemap.h b/treemap.h index 1229973..73d02fc 100644 --- a/treemap.h +++ b/treemap.h @@ -38,7 +38,7 @@ public: map seqsPerGroup; //groupname, number of seqs in that group. map treemap; //sequence name and void print(ostream&); - void makeSim(GroupMap*); //takes groupmap info and fills treemap for use by tree.groups command. + void makeSim(GroupMap*); //takes groupmap info and fills treemap for use by tree.shared command. private: diff --git a/unifracunweightedcommand.cpp b/unifracunweightedcommand.cpp index 9d17063..a9b46bf 100644 --- a/unifracunweightedcommand.cpp +++ b/unifracunweightedcommand.cpp @@ -58,8 +58,8 @@ int UnifracUnweightedCommand::execute() { //get pscores for users trees for (int i = 0; i < T.size(); i++) { counter = 0; - unweightedFile = globaldata->getTreeFile() + toString(i+1) + ".unweighted"; - unweightedFileout = globaldata->getTreeFile() + "temp." + toString(i+1) + ".unweighted"; + + output = new ColumnFile(globaldata->getTreeFile() + toString(i+1) + ".unweighted"); outSum << i+1 << '\t'; cout << i+1 << '\t'; @@ -99,31 +99,33 @@ int UnifracUnweightedCommand::execute() { } - for(int a = 0; a < numComp; a++) { - float rcumul = 1.0000; - //this loop fills the cumulative maps and put 0.0000 in the score freq map to make it easier to print. - for (it = validScores.begin(); it != validScores.end(); it++) { - //make rscoreFreq map and rCumul - it2 = rscoreFreq[a].find(it->first); - rCumul[a][it->first] = rcumul; - //get percentage of random trees with that info - if (it2 != rscoreFreq[a].end()) { rscoreFreq[a][it->first] /= iters; rcumul-= it2->second; } - else { rscoreFreq[a][it->first] = 0.0000; } //no random trees with that score + for(int a = 0; a < numComp; a++) { + float rcumul = 1.0000; + //this loop fills the cumulative maps and put 0.0000 in the score freq map to make it easier to print. + for (it = validScores.begin(); it != validScores.end(); it++) { + //make rscoreFreq map and rCumul + it2 = rscoreFreq[a].find(it->first); + rCumul[a][it->first] = rcumul; + //get percentage of random trees with that info + if (it2 != rscoreFreq[a].end()) { rscoreFreq[a][it->first] /= iters; rcumul-= it2->second; } + else { rscoreFreq[a][it->first] = 0.0000; } //no random trees with that score + } + UWScoreSig[a].push_back(rCumul[a][userData[a]]); } - UWScoreSig[a].push_back(rCumul[a][userData[a]]); - } - printUnweightedFile(); - printUWSummaryFile(); + printUnweightedFile(); + printUWSummaryFile(); + + delete output; + rscoreFreq.clear(); + rCumul.clear(); + validScores.clear(); + utreeScores.clear(); + UWScoreSig.clear(); + } - rscoreFreq.clear(); - rCumul.clear(); - validScores.clear(); - utreeScores.clear(); - UWScoreSig.clear(); - } //reset groups parameter globaldata->Groups.clear(); outSum.close(); @@ -144,22 +146,19 @@ int UnifracUnweightedCommand::execute() { void UnifracUnweightedCommand::printUnweightedFile() { try { vector data; + vector tags; + tags.push_back("Score"); tags.push_back("RandFreq"); tags.push_back("RandCumul"); for(int a = 0; a < numComp; a++) { - initFile(groupComb[a]); + output->initFile(groupComb[a], tags); //print each line for (it = validScores.begin(); it != validScores.end(); it++) { data.push_back(it->first); data.push_back(rscoreFreq[a][it->first]); data.push_back(rCumul[a][it->first]); - output(data); + output->output(data); data.clear(); } - resetFile(); + output->resetFile(); } - - out.close(); - inFile.close(); - remove(unweightedFileout.c_str()); - } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the UnifracUnweightedCommand class Function printUnweightedFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; @@ -200,85 +199,7 @@ void UnifracUnweightedCommand::printUWSummaryFile() { exit(1); } } -/*****************************************************************/ - -void UnifracUnweightedCommand::initFile(string label){ - try { - if(counter != 0){ - openOutputFile(unweightedFileout, out); - openInputFile(unweightedFile, inFile); - - string inputBuffer; - getline(inFile, inputBuffer); - - out << inputBuffer << '\t' << label + "RandFreq" << '\t' << label + "RandCumul" << endl; - }else{ - openOutputFile(unweightedFileout, out); - out << label + "Score" << '\t' << label + "RandFreq" << '\t' << label + "RandCumul" << endl; - } - - out.setf(ios::fixed, ios::floatfield); - out.setf(ios::showpoint); - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the UnifracUnweightedCommand class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the UnifracUnweightedCommand class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} - -/***********************************************************************/ -void UnifracUnweightedCommand::output(vector data){ - try { - if(counter != 0){ - string inputBuffer; - getline(inFile, inputBuffer); -// out << inputBuffer << setprecision(6) << '\t' << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl; - - out << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl; - } - else{ - out << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl; - } - - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the UnifracUnweightedCommand class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the UnifracUnweightedCommand class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -}; - -/***********************************************************************/ +/***********************************************************/ -void UnifracUnweightedCommand::resetFile(){ - try { - if(counter != 0){ - out.close(); - inFile.close(); - } - else{ - out.close(); - } - counter = 1; - - remove(unweightedFile.c_str()); - rename(unweightedFileout.c_str(), unweightedFile.c_str()); - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the UnifracUnweightedCommand class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the UnifracUnweightedCommand class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} diff --git a/unifracunweightedcommand.h b/unifracunweightedcommand.h index 3bd9a0d..d9991e8 100644 --- a/unifracunweightedcommand.h +++ b/unifracunweightedcommand.h @@ -14,6 +14,7 @@ #include "unweighted.h" #include "treemap.h" #include "sharedutilities.h" +#include "fileoutput.h" using namespace std; @@ -30,10 +31,11 @@ class UnifracUnweightedCommand : public Command { private: GlobalData* globaldata; SharedUtil* util; + FileOutput* output; vector T; //user trees TreeMap* tmap; Unweighted* unweighted; - string sumFile, unweightedFile, unweightedFileout, allGroups; + string sumFile, allGroups; vector groupComb; // AB. AC, BC... int iters, numGroups, numComp, counter; EstOutput userData; //unweighted score info for user tree @@ -51,10 +53,7 @@ class UnifracUnweightedCommand : public Command { void printUWSummaryFile(); void printUnweightedFile(); - void initFile(string); - void output(vector); - void resetFile(); - + }; diff --git a/unifracweightedcommand.cpp b/unifracweightedcommand.cpp index 5f7b4ad..6dfbd71 100644 --- a/unifracweightedcommand.cpp +++ b/unifracweightedcommand.cpp @@ -56,9 +56,8 @@ int UnifracWeightedCommand::execute() { counter = 0; rScores.resize(numComp); //data[0] = weightedscore AB, data[1] = weightedscore AC... uScores.resize(numComp); //data[0] = weightedscore AB, data[1] = weightedscore AC... - //weightedFile = globaldata->getTreeFile() + toString(i+1) + ".weighted"; - //weightedFileout = globaldata->getTreeFile() + "temp." + toString(i+1) + ".weighted"; - output = new ThreeColumnFile2(globaldata->getTreeFile() + toString(i+1) + ".weighted"); + + output = new ColumnFile(globaldata->getTreeFile() + toString(i+1) + ".weighted"); userData = weighted->getValues(T[i]); //userData[0] = weightedscore @@ -163,11 +162,6 @@ void UnifracWeightedCommand::printWeightedFile() { } output->resetFile(); } - - //out.close(); - //inFile.close(); - //remove(weightedFileout.c_str()); - } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the UnifracWeightedCommand class Function printWeightedFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; @@ -284,92 +278,8 @@ void UnifracWeightedCommand::calculateFreqsCumuls() { } -/***************************************************************** - -void UnifracWeightedCommand::initFile(string label){ - try { - if(counter != 0){ - openOutputFile(weightedFileout, out); - openInputFile(weightedFile, inFile); - - string inputBuffer; - getline(inFile, inputBuffer); - - out << inputBuffer << '\t' << label + "RandFreq" << '\t' << label + "RandCumul" << endl; - }else{ - openOutputFile(weightedFileout, out); - out << label + "Score" << '\t' << label + "RandFreq" << '\t' << label + "RandCumul" << endl; - } - - out.setf(ios::fixed, ios::floatfield); - out.setf(ios::showpoint); - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the UnifracWeightedCommand class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the UnifracWeightedCommand class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} - -/*********************************************************************** - -void UnifracWeightedCommand::output(vector data){ - try { - if(counter != 0){ - string inputBuffer; - getline(inFile, inputBuffer); - - out << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl; - } - else{ - out << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl; - - } - - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the UnifracWeightedCommand class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the UnifracWeightedCommand class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -}; - -/*********************************************************************** - -void UnifracWeightedCommand::resetFile(){ - try { - if(counter != 0){ - out.close(); - inFile.close(); - } - else{ - out.close(); - } - counter = 1; - - remove(weightedFile.c_str()); - rename(weightedFileout.c_str(), weightedFile.c_str()); - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the UnifracWeightedCommand class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the UnifracWeightedCommand class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - - - -} +/***********************************************************/ -*/ diff --git a/unifracweightedcommand.h b/unifracweightedcommand.h index 751343b..5cd93a9 100644 --- a/unifracweightedcommand.h +++ b/unifracweightedcommand.h @@ -39,7 +39,7 @@ class UnifracWeightedCommand : public Command { Tree* randT; //random tree TreeMap* tmap; Weighted* weighted; - string weightedFile, weightedFileout, sumFile; + string sumFile; int iters, numGroups, numComp, counter; EstOutput userData; //weighted score info for user tree EstOutput randomData; //weighted score info for random trees @@ -59,10 +59,7 @@ class UnifracWeightedCommand : public Command { //void removeValidScoresDuplicates(); int findIndex(float, int); void calculateFreqsCumuls(); - //void initFile(string); - //void output(vector); - //void resetFile(); - + }; diff --git a/validcalculator.cpp b/validcalculator.cpp index 4c05e4a..7d3477f 100644 --- a/validcalculator.cpp +++ b/validcalculator.cpp @@ -21,6 +21,7 @@ ValidCalculators::ValidCalculators() { initialVennSingle(); initialVennShared(); initialTreeGroups(); + initialBoot(); } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function ValidCalculator. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; @@ -138,13 +139,23 @@ bool ValidCalculators::isValidCalculator(string parameter, string calculator) { if ((treegroup.find(calculator)) != (treegroup.end())) { return true; }else { - cout << calculator << " is not a valid estimator for the tree.groups command in shared mode and will be disregarded. Valid estimators are "; + cout << calculator << " is not a valid estimator for the tree.shared command in shared mode and will be disregarded. Valid estimators are "; for (it = treegroup.begin(); it != treegroup.end(); it++) { cout << it->first << ", "; } cout << endl; return false; } - + }else if (parameter == "boot") { + //is it valid + if ((boot.find(calculator)) != (boot.end())) { + return true; + }else { + cout << calculator << " is not a valid estimator for the bootstrap.shared command in shared mode and will be disregarded. Valid estimators are "; + for (it = boot.begin(); it != boot.end(); it++) { + cout << it->first << ", "; + } + cout << endl; + return false; } //not a valid parameter }else { return false; } @@ -393,10 +404,90 @@ void ValidCalculators::initialTreeGroups() { exit(1); } } - - /********************************************************************/ +void ValidCalculators::initialBoot() { + try { + boot["jabund"] = "jabund"; + boot["sorensonabund"] = "sorensonabund"; + boot["jclass"] = "jclass"; + boot["sorclass"] = "orclass"; + boot["jest"] = "jest"; + boot["sorest"] = "sorest"; + boot["thetayc"] = "thetayc"; + boot["thetan"] = "thetan"; + boot["morisitahorn"] = "morisitahorn"; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialBoot. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ValidCalculator class function initialBoot. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} +/********************************************************************/ +void ValidCalculators::printCalc(string parameter, ostream& out) { + try{ + out << "The available estimators for calc are "; + //are you looking for a calculator for a single parameter + if (parameter == "single") { + for (it = single.begin(); it != single.end(); it++) { + out << it->first << ", "; + } + //are you looking for a calculator for a shared parameter + }else if (parameter == "shared") { + for (it = shared.begin(); it != shared.end(); it++) { + out << it->first << ", "; + } + //are you looking for a calculator for a rarefaction parameter + }else if (parameter == "rarefaction") { + for (it = rarefaction.begin(); it != rarefaction.end(); it++) { + out << it->first << ", "; + } + //are you looking for a calculator for a summary parameter + }else if (parameter == "summary") { + for (it = summary.begin(); it != summary.end(); it++) { + out << it->first << ", "; + } + //are you looking for a calculator for a sharedsummary parameter + }else if (parameter == "sharedsummary") { + for (it = sharedsummary.begin(); it != sharedsummary.end(); it++) { + out << it->first << ", "; + } + }else if (parameter == "sharedrarefaction") { + for (it = sharedrarefaction.begin(); it != sharedrarefaction.end(); it++) { + out << it->first << ", "; + } + }else if (parameter == "vennsingle") { + for (it = vennsingle.begin(); it != vennsingle.end(); it++) { + out << it->first << ", "; + } + }else if (parameter == "vennshared") { + for (it = vennshared.begin(); it != vennshared.end(); it++) { + out << it->first << ", "; + } + }else if (parameter == "treegroup") { + for (it = treegroup.begin(); it != treegroup.end(); it++) { + out << it->first << ", "; + } + }else if (parameter == "boot") { + for (it = boot.begin(); it != boot.end(); it++) { + out << it->first << ", "; + } + } + out << endl; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function printCalc. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ValidCalculator class function printCalc. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } - +} +/********************************************************************/ diff --git a/validcalculator.h b/validcalculator.h index 6cf3792..9f0d9b4 100644 --- a/validcalculator.h +++ b/validcalculator.h @@ -23,6 +23,7 @@ class ValidCalculators { ValidCalculators(); ~ValidCalculators(); bool isValidCalculator(string, string); + void printCalc(string, ostream&); private: map single; @@ -34,6 +35,7 @@ class ValidCalculators { map vennsingle; map vennshared; map treegroup; + map boot; map::iterator it; void initialSingle(); @@ -45,6 +47,7 @@ class ValidCalculators { void initialVennSingle(); void initialVennShared(); void initialTreeGroups(); + void initialBoot(); }; #endif diff --git a/validcommands.cpp b/validcommands.cpp index bc9f62c..696214e 100644 --- a/validcommands.cpp +++ b/validcommands.cpp @@ -31,12 +31,13 @@ ValidCommands::ValidCommands() { commands["unifrac.weighted"] = "unifrac.weighted"; commands["unifrac.unweighted"] = "unifrac.unweighted"; commands["libshuff"] = "libshuff"; - commands["tree.groups"] = "tree.groups"; + commands["tree.shared"] = "tree.shared"; commands["heatmap"] = "heatmap"; commands["venn"] = "venn"; commands["get.group"] = "get.group"; commands["get.label"] = "get.label"; commands["get.line"] = "get.line"; + commands["bootstrap.shared"] = "bootstrap.shared"; commands["help"] = "help"; commands["quit"] = "quit"; diff --git a/validparameter.cpp b/validparameter.cpp index 98dbde8..3fbf307 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -283,7 +283,7 @@ void ValidParameters::initCommandParameters() { string unifracUnweightedArray[] = {"groups","iters"}; commandParameters["unifrac.unweighted"] = addParameters(unifracUnweightedArray, sizeof(unifracUnweightedArray)/sizeof(string)); - string heatmapArray[] = {"groups","line","label","sorted","scaler"}; + string heatmapArray[] = {"groups","line","label","sorted","scale"}; commandParameters["heatmap"] = addParameters(heatmapArray, sizeof(heatmapArray)/sizeof(string)); string vennArray[] = {"groups","line","label","calc"}; @@ -296,7 +296,10 @@ void ValidParameters::initCommandParameters() { commandParameters["get.oturep"] = addParameters(getOTURepArray, sizeof(getOTURepArray)/sizeof(string)); string treeGroupsArray[] = {"line","label","calc","groups"}; - commandParameters["tree.groups"] = addParameters(treeGroupsArray, sizeof(treeGroupsArray)/sizeof(string)); + commandParameters["tree.shared"] = addParameters(treeGroupsArray, sizeof(treeGroupsArray)/sizeof(string)); + + string bootstrapArray[] = {"line","label","calc","groups","iters"}; + commandParameters["bootstrap.shared"] = addParameters(bootstrapArray, sizeof(bootstrapArray)/sizeof(string)); string quitArray[] = {}; commandParameters["quit"] = addParameters(quitArray, sizeof(quitArray)/sizeof(string)); @@ -376,4 +379,3 @@ vector ValidParameters::addParameters(string parameters[], int size) { } } -