int BinSeqCommand::execute(){
try {
int count = 1;
- string binnames, name, sequence;
+ int error = 0;
//read fastafile
fasta->readFastaFile(in);
input = globaldata->ginput;
list = globaldata->gListVector;
+ ListVector* lastList = list;
+
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = globaldata->labels;
+
- while(list != NULL){
+ while((list != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(list->getLabel()) == 1){
+ error = process(list, count);
+ if (error == 1) { return 0; }
+
+ processedLabels.insert(list->getLabel());
+ userLabels.erase(list->getLabel());
+
+ }
+
+ if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
+
+ error = process(lastList, count);
+ if (error == 1) { return 0; }
+
+ processedLabels.insert(lastList->getLabel());
+ userLabels.erase(lastList->getLabel());
+
+ }
+
+ if (count != 1) { delete lastList; }
+ lastList = list;
+
+ list = input->getListVector();
+ count++;
+ }
+
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastList->getLabel()) != 1) {
+ cout << ". I will use " << lastList->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastList->getLabel() << "." << endl;
+ }
+ }
+
+ //run last line if you need to
+ if (needToRun == true) {
+ error = process(lastList, count);
+ if (error == 1) { return 0; }
+ }
+
+ delete lastList;
+ return 0;
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the BinSeqCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the BinSeqCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+void BinSeqCommand::readNamesFile() {
+ try {
+ vector<string> dupNames;
+ openInputFile(namesfile, inNames);
+
+ string name, names, sequence;
+
+ while(inNames){
+ inNames >> name; //read from first column A
+ inNames >> names; //read from second column A,B,C,D
+
+ dupNames.clear();
+
+ //parse names into vector
+ splitAtComma(names, dupNames);
+
+ //store names in fasta map
+ sequence = fasta->getSequence(name);
+ for (int i = 0; i < dupNames.size(); i++) {
+ fasta->push_back(dupNames[i], sequence);
+ }
+
+ gobble(inNames);
+ }
+ inNames.close();
+
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the BinSeqCommand class Function readNamesFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the BinSeqCommand class function readNamesFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+//return 1 if error, 0 otherwise
+int BinSeqCommand::process(ListVector* list, int count) {
+ try {
+ string binnames, name, sequence;
string outputFileName = getRootName(globaldata->getListFile()) + list->getLabel() + ".fasta";
openOutputFile(outputFileName, out);
if (group == "not found") {
cout << name << " is missing from your group file. Please correct. " << endl;
remove(outputFileName.c_str());
- return 0;
+ return 1;
}else{
name = name + "|" + group + "|" + toString(i+1);
out << ">" << name << endl;
}else {
cout << name << " is missing from your fasta or name file. Please correct. " << endl;
remove(outputFileName.c_str());
- return 0;
+ return 1;
}
}
if (group == "not found") {
cout << binnames << " is missing from your group file. Please correct. " << endl;
remove(outputFileName.c_str());
- return 0;
+ return 1;
}else{
binnames = binnames + "|" + group + "|" + toString(i+1);
out << ">" << binnames << endl;
}else {
cout << binnames << " is missing from your fasta or name file. Please correct. " << endl;
remove(outputFileName.c_str());
- return 0;
+ return 1;
}
-
}
+
out.close();
- }
-
- delete list;
- list = input->getListVector();
- count++;
- }
-
- return 0;
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the BinSeqCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the BinSeqCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-}
-
-//**********************************************************************************************************************
-void BinSeqCommand::readNamesFile() {
- try {
- vector<string> dupNames;
- openInputFile(namesfile, inNames);
-
- string name, names, sequence;
-
- while(inNames){
- inNames >> name; //read from first column A
- inNames >> names; //read from second column A,B,C,D
-
- dupNames.clear();
-
- //parse names into vector
- splitAtComma(names, dupNames);
-
- //store names in fasta map
- sequence = fasta->getSequence(name);
- for (int i = 0; i < dupNames.size(); i++) {
- fasta->push_back(dupNames[i], sequence);
- }
-
- gobble(inNames);
- }
- inNames.close();
+ return 0;
}
catch(exception& e) {
//**********************************************************************************************************************
-
ifstream in, inNames;
void readNamesFile();
+ int process(ListVector*, int);
};
#endif
int BootSharedCommand::execute(){
try {
int count = 1;
- EstOutput data;
- vector<SharedRAbundVector*> subset;
//if the users entered no valid calculators don't execute command
if (treeCalculators.size() == 0) { return 0; }
read->read(&*globaldata);
input = globaldata->ginput;
order = input->getSharedOrderVector();
+ SharedOrderVector* lastOrder = order;
+
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = globaldata->labels;
//set users groups
util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "treegroup");
tmap->makeSim(globaldata->gGroupmap);
globaldata->gTreemap = tmap;
- while(order != NULL){
+ while((order != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
cout << order->getLabel() << '\t' << count << endl;
+ process(order);
- //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
- subset.clear(); //clear out old pair of sharedrabunds
- //add new pair of sharedrabunds
- subset.push_back(lookup[k]); subset.push_back(lookup[l]);
-
- //get estimated similarity between 2 groups
- data = treeCalculators[i]->getValues(subset); //saves the calculator outputs
- //save values in similarity matrix
- simMatrix[k][l] = data[0];
- simMatrix[l][k] = data[0];
- }
- }
- }
+ processedLabels.insert(order->getLabel());
+ userLabels.erase(order->getLabel());
- //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(); }
+ //you have a label the user want that is smaller than this line and the last line has not already been processed
}
-
+
+ if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastOrder->getLabel()) != 1)) {
+
+ cout << lastOrder->getLabel() << '\t' << count << endl;
+ process(lastOrder);
+
+ processedLabels.insert(lastOrder->getLabel());
+ userLabels.erase(lastOrder->getLabel());
+ }
+
+ if (count != 1) { delete lastOrder; }
+ lastOrder = order;
+
//get next line to process
order = input->getSharedOrderVector();
count++;
}
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastOrder->getLabel()) != 1) {
+ cout << ". I will use " << lastOrder->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastOrder->getLabel() << "." << endl;
+ }
+ }
+
+ //run last line if you need to
+ if (needToRun == true) {
+ process(lastOrder);
+ cout << lastOrder->getLabel() << '\t' << count << endl;
+ }
+
+ delete lastOrder;
+
//reset groups parameter
globaldata->Groups.clear(); globaldata->setGroups("");
}
}
/***********************************************************/
+void BootSharedCommand::process(SharedOrderVector* order) {
+ try{
+ EstOutput data;
+ vector<SharedRAbundVector*> subset;
+
+ //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
+ subset.clear(); //clear out old pair of sharedrabunds
+ //add new pair of sharedrabunds
+ subset.push_back(lookup[k]); subset.push_back(lookup[l]);
+
+ //get estimated similarity between 2 groups
+ data = treeCalculators[i]->getValues(subset); //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(); }
+
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the BootSharedCommand class Function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the BootSharedCommand class function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+/***********************************************************/
+
#include "command.hpp"
#include "sharedordervector.h"
-#include "sharedlistvector.h"
#include "inputdata.h"
#include "groupmap.h"
#include "readotu.h"
private:
void createTree(ostream*);
void printSims();
+ void process(SharedOrderVector*);
+
GlobalData* globaldata;
SharedUtil* util;
map<int, int> index; //maps row in simMatrix to vector index in the tree
InputData* input;
ValidCalculators* validCalculator;
- SharedListVector* SharedList;
SharedOrderVector* order;
vector<SharedRAbundVector*> lookup;
string format, outputFile;
globaldata = GlobalData::getInstance();
string fileNameRoot;
fileNameRoot = getRootName(globaldata->inputFileName);
+ convert(globaldata->getFreq(), freq);
int i;
validCalculator = new ValidCalculators();
+
for (i=0; i<globaldata->Estimators.size(); i++) {
if (validCalculator->isValidCalculator("single", globaldata->Estimators[i]) == true) {
if (globaldata->Estimators[i] == "sobs") {
read->read(&*globaldata);
order = globaldata->gorder;
+ lastOrder = order;
input = globaldata->ginput;
- set<string> orderList;
- while(order != NULL){
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = globaldata->labels;
+
+ while((order != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
- orderList.insert(order->getLabel());
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
+
cCurve = new Collect(order, cDisplays);
- convert(globaldata->getFreq(), freq);
cCurve->getCurve(freq);
-
delete cCurve;
cout << order->getLabel() << '\t' << count << endl;
+ processedLabels.insert(order->getLabel());
+ userLabels.erase(order->getLabel());
+
+ //you have a label the user want that is smaller than this line and the last line has not already been processed
+ }
+
+ if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastOrder->getLabel()) != 1)) {
+ cCurve = new Collect(lastOrder, cDisplays);
+ cCurve->getCurve(freq);
+ delete cCurve;
+
+ cout << lastOrder->getLabel() << '\t' << count << endl;
+ processedLabels.insert(lastOrder->getLabel());
+ userLabels.erase(lastOrder->getLabel());
}
- delete order;
+ if (count != 1) { delete lastOrder; }
+ lastOrder = order;
order = (input->getOrderVector());
count++;
}
- set<string>::iterator i;
- for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
- if(orderList.count(*i) == 0)
- cout << "'" << *i << "'" << " is not a valid label.\n";
- for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastOrder->getLabel()) != 1) {
+ cout << ". I will use " << lastOrder->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastOrder->getLabel() << "." << endl;
+ }
+ }
+
+ //run last line if you need to
+ if (needToRun == true) {
+ cCurve = new Collect(lastOrder, cDisplays);
+ cCurve->getCurve(freq);
+ delete cCurve;
+
+ cout << lastOrder->getLabel() << '\t' << count << endl;
+ }
+
+ delete lastOrder;
+ for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
return 0;
}
catch(exception& e) {
GlobalData* globaldata;
ReadOTUFile* read;
OrderVector* order;
+ OrderVector* lastOrder;
InputData* input;
Collect* cCurve;
ValidCalculators* validCalculator;
string fileNameRoot;
fileNameRoot = getRootName(globaldata->inputFileName);
format = globaldata->getFormat();
+ convert(globaldata->getFreq(), freq);
validCalculator = new ValidCalculators();
util = new SharedUtil();
input = globaldata->ginput;
order = input->getSharedOrderVector();
+ SharedOrderVector* lastOrder = order;
- set<string> orderList;
-
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = globaldata->labels;
+
//set users groups
util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "collect");
util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex);
- while(order != NULL){
+ while((order != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
- orderList.insert(order->getLabel());
-
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
//create collectors curve
cCurve = new Collect(order, cDisplays);
- convert(globaldata->getFreq(), freq);
cCurve->getSharedCurve(freq);
-
delete cCurve;
cout << order->getLabel() << '\t' << count << endl;
+ processedLabels.insert(order->getLabel());
+ userLabels.erase(order->getLabel());
+
+ //you have a label the user want that is smaller than this line and the last line has not already been processed
+ }
+
+ if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastOrder->getLabel()) != 1)) {
+ //create collectors curve
+ cCurve = new Collect(lastOrder, cDisplays);
+ cCurve->getSharedCurve(freq);
+ delete cCurve;
+
+ cout << lastOrder->getLabel() << '\t' << count << endl;
+ processedLabels.insert(lastOrder->getLabel());
+ userLabels.erase(lastOrder->getLabel());
}
+ if (count != 1) { delete lastOrder; }
+ lastOrder = order;
+
//get next line to process
- delete order;
order = input->getSharedOrderVector();
count++;
}
- set<string>::iterator i;
- for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
- if(orderList.count(*i) == 0)
- cout << "'" << *i << "'" << " is not a valid label.\n";
-
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastOrder->getLabel()) != 1) {
+ cout << ". I will use " << lastOrder->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastOrder->getLabel() << "." << endl;
+ }
+ }
+
+ //run last line if you need to
+ if (needToRun == true) {
+ cCurve = new Collect(lastOrder, cDisplays);
+ cCurve->getCurve(freq);
+ delete cCurve;
+
+ cout << lastOrder->getLabel() << '\t' << count << endl;
+ }
+
+ delete lastOrder;
for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
//reset groups parameter
errorFree = false;
}
if (listfile == "") { cout << "list is a required parameter for the get.oturep command." << endl; errorFree = false; }
+ if (fastafile == "") { cout << "fasta is a required parameter for the get.oturep command." << endl; errorFree = false; }
validateBinFiles();
}
//**********************************************************************************************************************
GetOTURepCommand::~GetOTURepCommand(){
- delete matrix;
- delete list;
delete input;
delete read;
delete fasta;
int GetOTURepCommand::execute(){
try {
int count = 1;
- string nameRep, name, sequence;
+ int error;
//read fastafile
fasta->readFastaFile(in);
input = globaldata->ginput;
list = globaldata->gListVector;
+ ListVector* lastList = list;
- while(list != NULL){
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = globaldata->labels;
+
+
+ while((list != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(list->getLabel()) == 1){
-
- //create output file
- string outputFileName = getRootName(globaldata->getListFile()) + list->getLabel() + ".rep.fasta";
- openOutputFile(outputFileName, out);
-
- cout << list->getLabel() << '\t' << count << endl;
-
- //for each bin in the list vector
- for (int i = 0; i < list->size(); i++) {
- string groups;
- nameRep = FindRep(i, groups);
+ cout << list->getLabel() << '\t' << count << endl;
+ error = process(list);
+ if (error == 1) { return 0; } //there is an error in hte input files, abort command
- //print out name and sequence for that bin
- sequence = fasta->getSequence(nameRep);
-
- if (sequence != "not found") {
- if (groupfile == "") {
- nameRep = nameRep + "|" + toString(i+1);
- out << ">" << nameRep << endl;
- out << sequence << endl;
- }else {
- nameRep = nameRep + "|" + groups + "|" + toString(i+1);
- out << ">" << nameRep << endl;
- out << sequence << endl;
- }
- }else {
- cout << nameRep << " is missing from your fasta or name file. Please correct. " << endl;
- remove(outputFileName.c_str());
- return 0;
- }
- }
-
- out.close();
+ processedLabels.insert(list->getLabel());
+ userLabels.erase(list->getLabel());
+ }
+
+ if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
+ cout << lastList->getLabel() << '\t' << count << endl;
+ error = process(lastList);
+ if (error == 1) { return 0; } //there is an error in hte input files, abort command
+
+ processedLabels.insert(lastList->getLabel());
+ userLabels.erase(lastList->getLabel());
}
+ if (count != 1) { delete lastList; }
+ lastList = list;
+
list = input->getListVector();
count++;
}
-
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastList->getLabel()) != 1) {
+ cout << ". I will use " << lastList->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastList->getLabel() << "." << endl;
+ }
+ }
+
+ //run last line if you need to
+ if (needToRun == true) {
+ cout << lastList->getLabel() << '\t' << count << endl;
+ error = process(lastList);
+ if (error == 1) { return 0; } //there is an error in hte input files, abort command
+ }
+ delete lastList;
+
+ delete matrix;
+ globaldata->gSparseMatrix = NULL;
+ delete list;
+ globaldata->gListVector = NULL;
+
return 0;
}
catch(exception& e) {
}
}
//**********************************************************************************************************************
-string GetOTURepCommand::FindRep(int bin, string& group) {
+string GetOTURepCommand::FindRep(int bin, string& group, ListVector* thisList) {
try{
vector<string> names;
map<string, float> sums;
map<string, string> groups;
map<string, string>::iterator groupIt;
- binnames = list->get(bin);
+ binnames = thisList->get(bin);
//parse names into vector
splitAtComma(binnames, names);
}
}
+//**********************************************************************************************************************
+int GetOTURepCommand::process(ListVector* processList) {
+ try{
+ string nameRep, name, sequence;
+
+ //create output file
+ string outputFileName = getRootName(globaldata->getListFile()) + processList->getLabel() + ".rep.fasta";
+ openOutputFile(outputFileName, out);
+
+ //for each bin in the list vector
+ for (int i = 0; i < processList->size(); i++) {
+ string groups;
+ nameRep = FindRep(i, groups, processList);
+
+ //print out name and sequence for that bin
+ sequence = fasta->getSequence(nameRep);
+
+ if (sequence != "not found") {
+ if (groupfile == "") {
+ nameRep = nameRep + "|" + toString(i+1);
+ out << ">" << nameRep << endl;
+ out << sequence << endl;
+ }else {
+ nameRep = nameRep + "|" + groups + "|" + toString(i+1);
+ out << ">" << nameRep << endl;
+ out << sequence << endl;
+ }
+ }else {
+ cout << nameRep << " is missing from your fasta or name file. Please correct. " << endl;
+ remove(outputFileName.c_str());
+ return 1;
+ }
+ }
+
+ out.close();
+ return 0;
+
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the GetOTURepCommand class Function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the GetOTURepCommand class function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+
map<string, int>::iterator it3;
void readNamesFile();
- string FindRep(int, string&); // returns name of "representative" sequence of given bin. //and fill a string containing the groups in that bin if a groupfile is given
+ int process(ListVector*);
+ string FindRep(int, string&, ListVector*); // returns name of "representative" sequence of given bin. //and fill a string containing the groups in that bin if a groupfile is given
};
if (key == "gapopen") { gapopen = value; }
if (key == "gapextend" ) { gapextend = value; }
- if (key == "line") {//stores lines to be used in a set
+ if (key == "line") {//stores lines to be used in a vector
lines.clear();
labels.clear();
line = value;
label = "";
- splitAtDash(value, lines);
- allLines = 0;
+ if (line != "all") { splitAtDash(value, lines); allLines = 0; }
+ else { allLines = 1; }
}
- if (key == "label") {//stores labels to be used in a set
+
+ if (key == "label") {//stores lines to be used in a vector
labels.clear();
lines.clear();
label = value;
line = "";
- splitAtDash(value, labels);
- allLines = 0;
+ if (label != "all") { splitAtDash(value, labels); allLines = 0; }
+ else { allLines = 1; }
}
if (key == "groups") {//stores groups to be used in a vector
int HeatMapCommand::execute(){
try {
int count = 1;
+ RAbundVector* lastRAbund;
+ vector<SharedRAbundVector*> lastLookup;
if (format == "sharedfile") {
//you have groups
input = globaldata->ginput;
lookup = input->getSharedRAbundVectors();
+ lastLookup = lookup;
}else if (format == "list") {
//you are using just a list file and have only one group
read = new ReadOTUFile(globaldata->inputFileName);
read->read(&*globaldata);
rabund = globaldata->rabund;
+ lastRAbund = globaldata->rabund;
input = globaldata->ginput;
}
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = globaldata->labels;
+
if (format != "list") {
- while(lookup[0] != NULL){
+ //as long as you are not at the end of the file or done wih the lines you want
+ while((lookup[0] != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){
cout << lookup[0]->getLabel() << '\t' << count << endl;
heatmap->getPic(lookup);
+
+ processedLabels.insert(lookup[0]->getLabel());
+ userLabels.erase(lookup[0]->getLabel());
}
- //prevent memory leak
- for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+ if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) {
+ cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+ heatmap->getPic(lastLookup);
+
+ processedLabels.insert(lastLookup[0]->getLabel());
+ userLabels.erase(lastLookup[0]->getLabel());
+ }
+ //prevent memory leak
+ if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } }
+ lastLookup = lookup;
+
//get next line to process
lookup = input->getSharedRAbundVectors();
count++;
}
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastLookup[0]->getLabel()) != 1) {
+ cout << ". I will use " << lastLookup[0]->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl;
+ }
+ }
+
+ //run last line if you need to
+ if (needToRun == true) {
+ cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+ heatmap->getPic(lastLookup);
+ }
+
+ for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; }
+
//reset groups parameter
globaldata->Groups.clear();
}else{
- while(rabund != NULL){
-
+ while((rabund != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
+
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(rabund->getLabel()) == 1){
cout << rabund->getLabel() << '\t' << count << endl;
heatmap->getPic(rabund);
+
+ processedLabels.insert(rabund->getLabel());
+ userLabels.erase(rabund->getLabel());
}
- delete rabund;
+ if ((anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastRAbund->getLabel()) != 1)) {
+
+ cout << lastRAbund->getLabel() << '\t' << count << endl;
+ heatmap->getPic(lastRAbund);
+
+ processedLabels.insert(lastRAbund->getLabel());
+ userLabels.erase(lastRAbund->getLabel());
+ }
+
+ if (count != 1) { delete lastRAbund; }
+ lastRAbund = rabund;
+
rabund = input->getRAbundVector();
count++;
}
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastRAbund->getLabel()) != 1) {
+ cout << ". I will use " << lastRAbund->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastRAbund->getLabel() << "." << endl;
+ }
+ }
+
+ //run last line if you need to
+ if (needToRun == true) {
+ cout << lastRAbund->getLabel() << '\t' << count << endl;
+ heatmap->getPic(lastRAbund);
+ }
+
+ delete lastRAbund;
+
}
globaldata->setGroups("");
int MatrixOutputCommand::execute(){
try {
int count = 1;
- EstOutput data;
- vector<SharedRAbundVector*> subset;
-
+
//if the users entered no valid calculators don't execute command
if (matrixCalculators.size() == 0) { cout << "No valid calculators." << endl; return 0; }
input = globaldata->ginput;
lookup = input->getSharedRAbundVectors();
+ vector<SharedRAbundVector*> lastLookup = lookup;
+
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = globaldata->labels;
if (lookup.size() < 2) { cout << "You have not provided enough valid groups. I cannot run the command." << endl; return 0;}
numGroups = globaldata->Groups.size();
- while(lookup[0] != NULL){
+ //as long as you are not at the end of the file or done wih the lines you want
+ while((lookup[0] != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){
-
cout << lookup[0]->getLabel() << '\t' << count << endl;
+ process(lookup);
- //for each calculator
- for(int i = 0 ; i < matrixCalculators.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);
- }
- }
-
- 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
-
- subset.clear(); //clear out old pair of sharedrabunds
- //add new pair of sharedrabunds
- subset.push_back(lookup[k]); subset.push_back(lookup[l]);
-
- data = matrixCalculators[i]->getValues(subset); //saves the calculator outputs
- //save values in similarity matrix
- simMatrix[k][l] = 1.0 - data[0]; //convert similiarity to distance
- simMatrix[l][k] = 1.0 - data[0]; //convert similiarity to distance
- }
- }
- }
-
- exportFileName = getRootName(globaldata->inputFileName) + matrixCalculators[i]->getName() + "." + lookup[0]->getLabel() + ".dist";
- openOutputFile(exportFileName, out);
- printSims(out);
- out.close();
-
- }
+ processedLabels.insert(lookup[0]->getLabel());
+ userLabels.erase(lookup[0]->getLabel());
}
+ if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) {
+ cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+ process(lastLookup);
+
+ processedLabels.insert(lastLookup[0]->getLabel());
+ userLabels.erase(lastLookup[0]->getLabel());
+ }
+
//prevent memory leak
- for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+ if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } }
+ lastLookup = lookup;
//get next line to process
lookup = input->getSharedRAbundVectors();
count++;
}
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastLookup[0]->getLabel()) != 1) {
+ cout << ". I will use " << lastLookup[0]->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl;
+ }
+ }
+
+ //run last line if you need to
+ if (needToRun == true) {
+ cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+ process(lastLookup);
+ }
+
+ for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; }
+
+
//reset groups parameter
globaldata->Groups.clear(); globaldata->setGroups("");
}
}
/***********************************************************/
+void MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
+ try {
+
+ EstOutput data;
+ vector<SharedRAbundVector*> subset;
+
+ //for each calculator
+ for(int i = 0 ; i < matrixCalculators.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);
+ }
+ }
+
+ for (int k = 0; k < thisLookup.size(); k++) {
+ for (int l = k; l < thisLookup.size(); l++) {
+ if (k != l) { //we dont need to similiarity of a groups to itself
+ //get estimated similarity between 2 groups
+
+ subset.clear(); //clear out old pair of sharedrabunds
+ //add new pair of sharedrabunds
+ subset.push_back(thisLookup[k]); subset.push_back(thisLookup[l]);
+
+ data = matrixCalculators[i]->getValues(subset); //saves the calculator outputs
+ //save values in similarity matrix
+ simMatrix[k][l] = 1.0 - data[0]; //convert similiarity to distance
+ simMatrix[l][k] = 1.0 - data[0]; //convert similiarity to distance
+ }
+ }
+ }
+
+ exportFileName = getRootName(globaldata->inputFileName) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".dist";
+ openOutputFile(exportFileName, out);
+ printSims(out);
+ out.close();
+
+ }
+
+
+
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the MatrixOutputCommand class Function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the MatrixOutputCommand class function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+/***********************************************************/
+
private:
void printSims(ostream&);
+ void process(vector<SharedRAbundVector*>);
GlobalData* globaldata;
ReadOTUFile* read;
string exportFileName;
int numGroups;
ofstream out;
+
};
}
//**********************************************************************************************************************
+template<typename T>
+inline bool convertTestFloat(const string& s, T& x, bool failIfLeftoverChars = true){
+ istringstream i(s);
+ char c;
+ if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
+ {
+ return false;
+ }
+ return true;
+}
+
+//**********************************************************************************************************************
+
template<typename T>
inline bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){
istringstream i(s);
}
}
-/**************************************************************************************************/
+/***********************************************************************/
+//this function determines if the user has given us labels that are smaller than the given label.
+//if so then it returns true so that the calling function can run the previous valid distance.
+//it's a "smart" distance function. It also checks for invalid labels.
+inline bool anyLabelsToProcess(string label, set<string>& userLabels, string errorOff) {
+ try {
+ set<string>::iterator it;
+ vector<float> orderFloat;
+ map<string, float> userMap; //the conversion process removes trailing 0's which we need to put back
+ map<string, float>::iterator it2;
+ float labelFloat;
+ bool smaller = false;
+
+ //unique is the smallest line
+ if (label == "unique") { return false; }
+ else { convert(label, labelFloat); }
+
+ //go through users set and make them floats
+ for(it = userLabels.begin(); it != userLabels.end(); ++it) {
+
+ float temp;
+ if ((*it != "unique") && (convertTestFloat(*it, temp) == true)){
+ convert(*it, temp);
+ orderFloat.push_back(temp);
+ userMap[*it] = temp;
+ }else if (*it == "unique") {
+ orderFloat.push_back(-1.0);
+ userMap["unique"] = -1.0;
+ }else {
+ if (errorOff == "") { cout << *it << " is not a valid label." << endl; }
+ userLabels.erase(*it);
+ it--;
+ }
+ }
+
+ //sort order
+ sort(orderFloat.begin(), orderFloat.end());
+
+ /*************************************************/
+ //is this label bigger than any of the users labels
+ /*************************************************/
+
+ //loop through order until you find a label greater than label
+ for (int i = 0; i < orderFloat.size(); i++) {
+ if (orderFloat[i] < labelFloat) {
+ smaller = true;
+ if (orderFloat[i] == -1) {
+ if (errorOff == "") { cout << "Your file does not include the label unique." << endl; }
+ userLabels.erase("unique");
+ }
+ else {
+ if (errorOff == "") { cout << "Your file does not include the label "; }
+ string s = "";
+ for (it2 = userMap.begin(); it2!= userMap.end(); it2++) {
+ if (it2->second == orderFloat[i]) {
+ s = it2->first;
+ //remove small labels
+ userLabels.erase(s);
+ break;
+ }
+ }
+ if (errorOff == "") { cout << s << ". I will use the next smallest distance. " << endl; }
+ }
+ //since they are sorted once you find a bigger one stop looking
+ }else { break; }
+ }
+
+ return smaller;
+
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the mothur class Function anyLabelsToProcess. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the mothur class function anyLabelsToProcess. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+/**************************************************************************************************/
#endif
//read in group map info.
groupMap = new GroupMap(globaldata->getGroupFile());
groupMap->readMap();
-
+
+
//fill filehandles with neccessary ofstreams
int i;
ofstream* temp;
}
}
/***********************************************************************/
-void ParseListCommand::parse(int index) {
+void ParseListCommand::parse(int index, SharedListVector* list) {
try {
string prefix, suffix, groupsName;
suffix = list->get(index);
read->read(&*globaldata);
input = globaldata->ginput;
list = globaldata->gSharedList;
+ SharedListVector* lastList = list;
+
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = globaldata->labels;
//read in group map info.
groupMap = new GroupMap(globaldata->getGroupFile());
groupMap->readMap();
- string seq, label;
- int i;
//create new list vectors to fill with parsed data
- for (i=0; i<groupMap->getNumGroups(); i++) {
+ for (int i=0; i<groupMap->getNumGroups(); i++) {
groupOfLists[groupMap->namesOfGroups[i]] = new SharedListVector();
}
+
//parses and sets each groups listvector
- while(list != NULL){
- label = list->getLabel();
-
- if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(label) == 1){
-
- for(i=0; i<list->size(); i++) {
- parse(i); //parses data[i] list of sequence names
- for (it=listGroups.begin(); it != listGroups.end(); it++) { //loop through map and set new list vectors
- seq = it->second;
- seq = seq.substr(1, seq.length()); //rips off extra comma
- groupOfLists[it->first]->push_back(seq); //sets new listvector for each group
- }
- listGroups.clear();
- }
- //prints each new list file
- for (i=0; i<groupMap->getNumGroups(); i++) {
- groupOfLists[groupMap->namesOfGroups[i]]->setLabel(label);
- groupOfLists[groupMap->namesOfGroups[i]]->print(*(filehandles[groupMap->namesOfGroups[i]]));
- groupOfLists[groupMap->namesOfGroups[i]]->clear();
- }
+ //as long as you are not at the end of the file or done wih the lines you want
+ while((list != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
+
+ if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(list->getLabel()) == 1){
+ cout << list->getLabel() << '\t' << count << endl;
+ process(list);
- cout << label << '\t' << count << endl;
+ processedLabels.insert(list->getLabel());
+ userLabels.erase(list->getLabel());
}
+ if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
+ cout << lastList->getLabel() << '\t' << count << endl;
+ process(lastList);
+
+ processedLabels.insert(lastList->getLabel());
+ userLabels.erase(lastList->getLabel());
+ }
+
+ if (count != 1) { delete lastList; }
+ lastList = list;
+
list = input->getSharedListVector();
count++;
}
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastList->getLabel()) != 1) {
+ cout << ". I will use " << lastList->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastList->getLabel() << "." << endl;
+ }
+ }
+
+ //run last line if you need to
+ if (needToRun == true) {
+ cout << lastList->getLabel() << '\t' << count << endl;
+ process(lastList);
+ }
+ delete lastList;
+
//set groupmap for .shared commands
- //if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; }
+ if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; }
globaldata->gGroupmap = groupMap;
return 0;
delete read;
}
//**********************************************************************************************************************
+void ParseListCommand::process(SharedListVector* thisList) {
+ try {
+ string seq;
+
+ for(int i=0; i<thisList->size(); i++) {
+ parse(i, thisList); //parses data[i] list of sequence names
+ for (it=listGroups.begin(); it != listGroups.end(); it++) { //loop through map and set new list vectors
+ seq = it->second;
+ seq = seq.substr(1, seq.length()); //rips off extra comma
+ groupOfLists[it->first]->push_back(seq); //sets new listvector for each group
+ }
+ listGroups.clear();
+ }
+ //prints each new list file
+ for (int i=0; i<groupMap->getNumGroups(); i++) {
+ groupOfLists[groupMap->namesOfGroups[i]]->setLabel(thisList->getLabel());
+ groupOfLists[groupMap->namesOfGroups[i]]->print(*(filehandles[groupMap->namesOfGroups[i]]));
+ groupOfLists[groupMap->namesOfGroups[i]]->clear();
+ }
+
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the ParseListCommand class Function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the ParseListCommand class function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
\ No newline at end of file
SharedListVector* list;
map<string, string> listGroups; //maps group name to sequences from that group in a specific OTU
map<string, string>::iterator it;
- map<string, SharedListVector*>::iterator it2;
map<string, ofstream*>::iterator it3;
- void parse(int);
+ void parse(int, SharedListVector*);
+ void process(SharedListVector*);
string fileroot;
};
globaldata = GlobalData::getInstance();
string fileNameRoot;
fileNameRoot = getRootName(globaldata->inputFileName);
+ convert(globaldata->getFreq(), freq);
+ convert(globaldata->getIters(), nIters);
validCalculator = new ValidCalculators();
int i;
read->read(&*globaldata);
order = globaldata->gorder;
+ OrderVector* lastOrder = order;
input = globaldata->ginput;
-
- while(order != NULL){
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = globaldata->labels;
+
+ //as long as you are not at the end of the file or done wih the lines you want
+ while((order != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
+
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
rCurve = new Rarefact(order, rDisplays);
- convert(globaldata->getFreq(), freq);
- convert(globaldata->getIters(), nIters);
rCurve->getCurve(freq, nIters);
-
delete rCurve;
cout << order->getLabel() << '\t' << count << endl;
+ processedLabels.insert(order->getLabel());
+ userLabels.erase(order->getLabel());
+ }
+
+ if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastOrder->getLabel()) != 1)) {
+ rCurve = new Rarefact(lastOrder, rDisplays);
+ rCurve->getCurve(freq, nIters);
+ delete rCurve;
+
+ cout << lastOrder->getLabel() << '\t' << count << endl;
+ processedLabels.insert(lastOrder->getLabel());
+ userLabels.erase(lastOrder->getLabel());
}
- delete order;
+ if (count != 1) { delete lastOrder; }
+ lastOrder = order;
+
order = (input->getOrderVector());
count++;
+ }
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastOrder->getLabel()) != 1) {
+ cout << ". I will use " << lastOrder->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastOrder->getLabel() << "." << endl;
+ }
}
-
+
+ //run last line if you need to
+ if (needToRun == true) {
+ rCurve = new Rarefact(lastOrder, rDisplays);
+ rCurve->getCurve(freq, nIters);
+ delete rCurve;
+
+ cout << lastOrder->getLabel() << '\t' << count << endl;
+ }
+
+ delete lastOrder;
+
for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; }
return 0;
}
string fileNameRoot;
fileNameRoot = getRootName(globaldata->inputFileName);
format = globaldata->getFormat();
+ convert(globaldata->getFreq(), freq);
+ convert(globaldata->getIters(), nIters);
validCalculator = new ValidCalculators();
int i;
input = globaldata->ginput;
lookup = input->getSharedRAbundVectors();
+ vector<SharedRAbundVector*> lastLookup = lookup;
if (lookup.size() < 2) {
cout << "I cannot run the command without at least 2 valid groups.";
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
return 0;
}
-
-
- while(lookup[0] != NULL){
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = globaldata->labels;
+
+ //as long as you are not at the end of the file or done wih the lines you want
+ while((lookup[0] != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
+
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){
- //create collectors curve
+
rCurve = new Rarefact(lookup, rDisplays);
- convert(globaldata->getFreq(), freq);
- convert(globaldata->getIters(), nIters);
rCurve->getSharedCurve(freq, nIters);
-
delete rCurve;
cout << lookup[0]->getLabel() << '\t' << count << endl;
+ processedLabels.insert(lookup[0]->getLabel());
+ userLabels.erase(lookup[0]->getLabel());
}
- //prevent memory leak
- for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+ if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) {
+ cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+ rCurve = new Rarefact(lastLookup, rDisplays);
+ rCurve->getSharedCurve(freq, nIters);
+ delete rCurve;
+
+ processedLabels.insert(lastLookup[0]->getLabel());
+ userLabels.erase(lastLookup[0]->getLabel());
+ }
+ //prevent memory leak
+ if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } }
+ lastLookup = lookup;
+
//get next line to process
lookup = input->getSharedRAbundVectors();
count++;
}
-
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastLookup[0]->getLabel()) != 1) {
+ cout << ". I will use " << lastLookup[0]->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl;
+ }
+ }
+
+ //run last line if you need to
+ if (needToRun == true) {
+ cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+ rCurve = new Rarefact(lastLookup, rDisplays);
+ rCurve->getSharedCurve(freq, nIters);
+ delete rCurve;
+ }
+
+ for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; }
+
for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; }
//reset groups parameter
}
/**************************************************************************************************/
-void Shared::getSharedVectors(int index, SharedListVector* list) {
+void Shared::getSharedVectors(SharedListVector* list) {
string label, group;
int i,j;
label = list->getLabel();
class Shared {
public:
Shared();
- ~Shared();
- void getSharedVectors(int, SharedListVector*);
+ ~Shared() {};
+ void getSharedVectors(SharedListVector*);
map<string, SharedRAbundVector*> sharedGroups; //string is groupname, SharedVector* is out info for that group
private:
int SharedCommand::execute(){
try {
globaldata = GlobalData::getInstance();
+ int count = 1;
+ string errorOff = "no error";
//read in listfile
read = new ReadOTUFile(globaldata->inputFileName);
read->read(&*globaldata);
input = globaldata->ginput;
SharedList = globaldata->gSharedList;
+ SharedListVector* lastList = SharedList;
+
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = globaldata->labels;
shared = new Shared();
- int i = 0;
- while(SharedList != NULL){
- if(globaldata->allLines == 1 || globaldata->lines.count(i+1) == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){
+ while((SharedList != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
+
+
+ if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){
- shared->getSharedVectors(i, SharedList); //fills sharedGroups with new info and updates sharedVector
- printSharedData(); //prints info to the .shared file
+ shared->getSharedVectors(SharedList); //fills sharedGroups with new info and updates sharedVector
+ printSharedData(); //prints info to the .shared file
+
+ processedLabels.insert(SharedList->getLabel());
+ userLabels.erase(SharedList->getLabel());
}
+ if ((anyLabelsToProcess(SharedList->getLabel(), userLabels, errorOff) == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
+ shared->getSharedVectors(lastList); //fills sharedGroups with new info and updates sharedVector
+ printSharedData(); //prints info to the .shared file
+
+ processedLabels.insert(lastList->getLabel());
+ userLabels.erase(lastList->getLabel());
+ }
+
+ if (count != 1) { delete lastList; }
+ lastList = SharedList;
+
SharedList = input->getSharedListVector(); //get new list vector to process
- i++;
}
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ //cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastList->getLabel()) != 1) {
+ //cout << ". I will use " << lastList->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ //cout << ". Please refer to " << lastList->getLabel() << "." << endl;
+ }
+ }
+
+ //run last line if you need to
+ if (needToRun == true) {
+ shared->getSharedVectors(lastList); //fills sharedGroups with new info and updates sharedVector
+ printSharedData(); //prints info to the .shared file
+ }
+
+ delete lastList;
+ delete shared;
+
return 0;
}
catch(exception& e) {
SharedCommand::~SharedCommand(){
//delete list;
delete read;
+
}
//**********************************************************************************************************************
/***********************************************************************/
-SharedRAbundVector::~SharedRAbundVector() {
-
-}
-
-/***********************************************************************/
-
void SharedRAbundVector::set(int binNumber, int newBinSize, string groupname){
try {
int oldBinSize = data[binNumber].abundance;
//SharedRAbundVector(string, vector<int>);
SharedRAbundVector(const SharedRAbundVector& bv) : DataVector(bv), data(bv.data), maxRank(bv.maxRank), numBins(bv.numBins), numSeqs(bv.numSeqs){};
SharedRAbundVector(ifstream&);
- ~SharedRAbundVector();
+ ~SharedRAbundVector(){};
int getNumBins();
int getNumSeqs();
int SummaryCommand::execute(){
try {
-
+ int count = 1;
+
//if the users entered no valid calculators don't execute command
if (sumCalculators.size() == 0) { return 0; }
read = new ReadOTUFile(globaldata->inputFileName);
read->read(&*globaldata);
-
+
+ sabund = globaldata->sabund;
+ SAbundVector* lastSAbund = sabund;
+ input = globaldata->ginput;
+
for(int i=0;i<sumCalculators.size();i++){
if(sumCalculators[i]->getCols() == 1){
outputFileHandle << '\t' << sumCalculators[i]->getName();
}
outputFileHandle << endl;
- sabund = globaldata->sabund;
- input = globaldata->ginput;
- int count = 1;
- while(sabund != NULL){
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = globaldata->labels;
+ while((sabund != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
+
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(sabund->getLabel()) == 1){
cout << sabund->getLabel() << '\t' << count << endl;
+ processedLabels.insert(sabund->getLabel());
+ userLabels.erase(sabund->getLabel());
+
outputFileHandle << sabund->getLabel();
for(int i=0;i<sumCalculators.size();i++){
outputFileHandle << '\t';
sumCalculators[i]->print(outputFileHandle);
}
-
outputFileHandle << endl;
}
+
+ if ((anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastSAbund->getLabel()) != 1)) {
+
+ cout << lastSAbund->getLabel() << '\t' << count << endl;
+ processedLabels.insert(lastSAbund->getLabel());
+ userLabels.erase(lastSAbund->getLabel());
+
+ outputFileHandle << lastSAbund->getLabel();
+ for(int i=0;i<sumCalculators.size();i++){
+ vector<double> data = sumCalculators[i]->getValues(lastSAbund);
+ outputFileHandle << '\t';
+ sumCalculators[i]->print(outputFileHandle);
+ }
+ outputFileHandle << endl;
+ }
+
+ if (count != 1) { delete lastSAbund; }
+ lastSAbund = sabund;
+
sabund = input->getSAbundVector();
count++;
}
-
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastSAbund->getLabel()) != 1) {
+ cout << ". I will use " << lastSAbund->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastSAbund->getLabel() << "." << endl;
+ }
+ }
+
+ //run last line if you need to
+ if (needToRun == true) {
+ cout << lastSAbund->getLabel() << '\t' << count << endl;
+ outputFileHandle << lastSAbund->getLabel();
+ for(int i=0;i<sumCalculators.size();i++){
+ vector<double> data = sumCalculators[i]->getValues(lastSAbund);
+ outputFileHandle << '\t';
+ sumCalculators[i]->print(outputFileHandle);
+ }
+ outputFileHandle << endl;
+ }
+
+ delete lastSAbund;
return 0;
}
catch(exception& e) {
input = globaldata->ginput;
lookup = input->getSharedRAbundVectors();
+ vector<SharedRAbundVector*> lastLookup = lookup;
//output estimator names as column headers
outputFileHandle << "label" <<'\t' << "comparison" << '\t';
return 0;
}
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = globaldata->labels;
- while(lookup[0] != NULL){
+ //as long as you are not at the end of the file or done wih the lines you want
+ while((lookup[0] != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){
-
cout << lookup[0]->getLabel() << '\t' << count << endl;
+ process(lookup);
+ processedLabels.insert(lookup[0]->getLabel());
+ userLabels.erase(lookup[0]->getLabel());
+ }
+
+ if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) {
+ cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+ process(lastLookup);
+
+ processedLabels.insert(lastLookup[0]->getLabel());
+ userLabels.erase(lastLookup[0]->getLabel());
+ }
+
+
+ //prevent memory leak
+ if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } }
+ lastLookup = lookup;
+
+ //get next line to process
+ lookup = input->getSharedRAbundVectors();
+ count++;
+ }
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastLookup[0]->getLabel()) != 1) {
+ cout << ". I will use " << lastLookup[0]->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl;
+ }
+ }
+
+ //run last line if you need to
+ if (needToRun == true) {
+ cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+ process(lastLookup);
+ }
+
+ for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; }
+
+ //reset groups parameter
+ globaldata->Groups.clear(); globaldata->setGroups("");
+
+ //close files
+ outputFileHandle.close();
+ if (mult == true) { outAll.close(); }
+
+ return 0;
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the SummarySharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+
+/***********************************************************/
+void SummarySharedCommand::process(vector<SharedRAbundVector*> thisLookup) {
+ try {
//loop through calculators and add to file all for all calcs that can do mutiple groups
if (mult == true) {
//output label
- outAll << lookup[0]->getLabel() << '\t';
+ outAll << thisLookup[0]->getLabel() << '\t';
//output groups names
string outNames = "";
- for (int j = 0; j < lookup.size(); j++) {
- outNames += lookup[j]->getGroup() + "-";
+ for (int j = 0; j < thisLookup.size(); j++) {
+ outNames += thisLookup[j]->getGroup() + "-";
}
outNames = outNames.substr(0, outNames.length()-1); //rip off extra '-';
outAll << outNames << '\t';
for(int i=0;i<sumCalculators.size();i++){
if (sumCalculators[i]->getMultiple() == true) {
- sumCalculators[i]->getValues(lookup);
+ sumCalculators[i]->getValues(thisLookup);
outAll << '\t';
sumCalculators[i]->print(outAll);
}
int n = 1;
vector<SharedRAbundVector*> subset;
- for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
- for (int l = n; l < lookup.size(); l++) {
+ for (int k = 0; k < (thisLookup.size() - 1); k++) { // pass cdd each set of groups to commpare
+ for (int l = n; l < thisLookup.size(); l++) {
- outputFileHandle << lookup[0]->getLabel() << '\t';
+ outputFileHandle << thisLookup[0]->getLabel() << '\t';
subset.clear(); //clear out old pair of sharedrabunds
//add new pair of sharedrabunds
- subset.push_back(lookup[k]); subset.push_back(lookup[l]);
+ subset.push_back(thisLookup[k]); subset.push_back(thisLookup[l]);
//sort groups to be alphanumeric
- if (lookup[k]->getGroup() > lookup[l]->getGroup()) {
- outputFileHandle << (lookup[l]->getGroup() +'\t' + lookup[k]->getGroup()) << '\t'; //print out groups
+ if (thisLookup[k]->getGroup() > thisLookup[l]->getGroup()) {
+ outputFileHandle << (thisLookup[l]->getGroup() +'\t' + thisLookup[k]->getGroup()) << '\t'; //print out groups
}else{
- outputFileHandle << (lookup[k]->getGroup() +'\t' + lookup[l]->getGroup()) << '\t'; //print out groups
+ outputFileHandle << (thisLookup[k]->getGroup() +'\t' + thisLookup[l]->getGroup()) << '\t'; //print out groups
}
for(int i=0;i<sumCalculators.size();i++) {
}
n++;
}
- }
-
- //prevent memory leak
- for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
-
- //get next line to process
- lookup = input->getSharedRAbundVectors();
- count++;
- }
-
- //reset groups parameter
- globaldata->Groups.clear(); globaldata->setGroups("");
-
- //close files
- outputFileHandle.close();
- if (mult == true) { outAll.close(); }
- return 0;
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
exit(1);
}
catch(...) {
- cout << "An unknown error has occurred in the SummarySharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ cout << "An unknown error has occurred in the SummarySharedCommand class function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
exit(1);
}
}
-/***********************************************************/
+/***********************************************************/
\ No newline at end of file
string outputFileName, format, outAllFileName;
ofstream outputFileHandle, outAll;
bool mult;
+ void process(vector<SharedRAbundVector*>);
};
input = globaldata->ginput;
lookup = input->getSharedRAbundVectors();
+ lastLookup = lookup;
if (lookup.size() < 2) { cout << "You have not provided enough valid groups. I cannot run the command." << endl; return 0; }
void TreeGroupCommand::makeSimsShared() {
try {
int count = 1;
- EstOutput data;
- vector<SharedRAbundVector*> subset;
- numGroups = globaldata->Groups.size();
-
//clear globaldatas old tree names if any
globaldata->Treenames.clear();
tmap->makeSim(globaldata->gGroupmap);
globaldata->gTreemap = tmap;
- while(lookup[0] != NULL){
+ set<string> processedLabels;
+ set<string> userLabels = globaldata->labels;
+
+ //as long as you are not at the end of the file or done wih the lines you want
+ while((lookup[0] != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){
-
cout << lookup[0]->getLabel() << '\t' << count << endl;
+ process(lookup);
+
+ processedLabels.insert(lookup[0]->getLabel());
+ userLabels.erase(lookup[0]->getLabel());
+ }
+
+ if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) {
+ cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+ process(lastLookup);
+
+ processedLabels.insert(lastLookup[0]->getLabel());
+ userLabels.erase(lastLookup[0]->getLabel());
+ }
+
+ //prevent memory leak
+ if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } }
+ lastLookup = lookup;
+
+ //get next line to process
+ lookup = input->getSharedRAbundVectors();
+ count++;
+ }
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastLookup[0]->getLabel()) != 1) {
+ cout << ". I will use " << lastLookup[0]->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl;
+ }
+ }
+
+ //run last line if you need to
+ if (needToRun == true) {
+ cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+ process(lastLookup);
+ }
+
+ for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; }
+ for(int i = 0 ; i < treeCalculators.size(); i++) { delete treeCalculators[i]; }
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the TreeGroupCommand class Function makeSimsShared. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the TreeGroupCommand class function makeSimsShared. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+
+/***********************************************************/
+void TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
+ try{
+ EstOutput data;
+ vector<SharedRAbundVector*> subset;
+ numGroups = globaldata->Groups.size();
//for each calculator
for(int i = 0 ; i < treeCalculators.size(); i++) {
for (int g = 0; g < numGroups; g++) { index[g] = g; }
//create a new filename
- outputFile = getRootName(globaldata->inputFileName) + treeCalculators[i]->getName() + "." + lookup[0]->getLabel() + ".tre";
+ outputFile = getRootName(globaldata->inputFileName) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".tre";
- for (int k = 0; k < lookup.size(); k++) {
- for (int l = k; l < lookup.size(); l++) {
+ for (int k = 0; k < thisLookup.size(); k++) {
+ for (int l = k; l < thisLookup.size(); l++) {
if (k != l) { //we dont need to similiarity of a groups to itself
//get estimated similarity between 2 groups
subset.clear(); //clear out old pair of sharedrabunds
//add new pair of sharedrabunds
- subset.push_back(lookup[k]); subset.push_back(lookup[l]);
+ subset.push_back(thisLookup[k]); subset.push_back(thisLookup[l]);
data = treeCalculators[i]->getValues(subset); //saves the calculator outputs
//save values in similarity matrix
//creates tree from similarity matrix and write out file
createTree();
}
- }
-
- //prevent memory leak
- for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
-
- //get next line to process
- lookup = input->getSharedRAbundVectors();
- count++;
- }
-
- for(int i = 0 ; i < treeCalculators.size(); i++) { delete treeCalculators[i]; }
+
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the TreeGroupCommand class Function makeSimsShared. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ cout << "Standard Error: " << e.what() << " has occurred in the TreeGroupCommand class Function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
exit(1);
}
catch(...) {
- cout << "An unknown error has occurred in the TreeGroupCommand class function makeSimsShared. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ cout << "An unknown error has occurred in the TreeGroupCommand class function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
exit(1);
}
}
-
/***********************************************************/
+
InputData* input;
ValidCalculators* validCalculator;
vector<SharedRAbundVector*> lookup;
+ vector<SharedRAbundVector*> lastLookup;
string format, outputFile, groupNames, filename;
int numGroups;
ofstream out;
float precision, cutoff;
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ void process(vector<SharedRAbundVector*>);
};
int VennCommand::execute(){
try {
- int count = 1;
+ int count = 1;
+ SAbundVector* lastSAbund;
+ vector<SharedRAbundVector*> lastLookup;
//if the users entered no valid calculators don't execute command
if (vennCalculators.size() == 0) { return 0; }
input = globaldata->ginput;
lookup = input->getSharedRAbundVectors();
+ lastLookup = lookup;
}else if (format == "list") {
//you are using just a list file and have only one group
read = new ReadOTUFile(globaldata->inputFileName);
read->read(&*globaldata);
sabund = globaldata->sabund;
+ lastSAbund = globaldata->sabund;
input = globaldata->ginput;
}
-
+
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = globaldata->labels;
if (format != "list") {
- while(lookup[0] != NULL){
+ //as long as you are not at the end of the file or done wih the lines you want
+ while((lookup[0] != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){
-
cout << lookup[0]->getLabel() << '\t' << count << endl;
+ processedLabels.insert(lookup[0]->getLabel());
+ userLabels.erase(lookup[0]->getLabel());
if (lookup.size() > 4) {
cout << "Error: Too many groups chosen. You may use up to 4 groups with the venn command. I will use the first four groups in your groupfile." << endl;
- for (int i = lookup.size(); i > 3; i--) { delete lookup[i]; lookup.pop_back(); }
+ for (int i = lookup.size(); i > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor
}
-
- //util->getSharedVectors(globaldata->Groups, lookup, order); //fills group vectors from order vector.
venn->getPic(lookup, vennCalculators);
}
- //prevent memory leak
- for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+ if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) {
+ cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+ processedLabels.insert(lastLookup[0]->getLabel());
+ userLabels.erase(lastLookup[0]->getLabel());
+
+ if (lastLookup.size() > 4) {
+ cout << "Error: Too many groups chosen. You may use up to 4 groups with the venn command. I will use the first four groups in your groupfile." << endl;
+ for (int i = lastLookup.size(); i > 4; i--) { lastLookup.pop_back(); } //no memmory leak because pop_back calls destructor
+ }
+ venn->getPic(lastLookup, vennCalculators);
+ }
+ //prevent memory leak
+ if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } }
+ lastLookup = lookup;
+
//get next line to process
lookup = input->getSharedRAbundVectors();
count++;
}
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastLookup[0]->getLabel()) != 1) {
+ cout << ". I will use " << lastLookup[0]->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl;
+ }
+ }
+
+ //run last line if you need to
+ if (needToRun == true) {
+ cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+ if (lastLookup.size() > 4) {
+ cout << "Error: Too many groups chosen. You may use up to 4 groups with the venn command. I will use the first four groups in your groupfile." << endl;
+ for (int i = lastLookup.size(); i > 3; i--) { delete lastLookup[i]; lastLookup.pop_back(); }
+ }
+ venn->getPic(lastLookup, vennCalculators);
+ }
+
+ for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; }
+
//reset groups parameter
globaldata->Groups.clear();
}else{
- while(sabund != NULL){
+ while((sabund != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(sabund->getLabel()) == 1){
cout << sabund->getLabel() << '\t' << count << endl;
venn->getPic(sabund, vennCalculators);
+
+ processedLabels.insert(sabund->getLabel());
+ userLabels.erase(sabund->getLabel());
}
- delete sabund;
+ if ((anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastSAbund->getLabel()) != 1)) {
+
+ cout << lastSAbund->getLabel() << '\t' << count << endl;
+ venn->getPic(lastSAbund, vennCalculators);
+
+ processedLabels.insert(lastSAbund->getLabel());
+ userLabels.erase(lastSAbund->getLabel());
+ }
+
+ if (count != 1) { delete lastSAbund; }
+ lastSAbund = sabund;
+
sabund = input->getSAbundVector();
count++;
}
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastSAbund->getLabel()) != 1) {
+ cout << ". I will use " << lastSAbund->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastSAbund->getLabel() << "." << endl;
+ }
+ }
+
+ //run last line if you need to
+ if (needToRun == true) {
+ cout << lastSAbund->getLabel() << '\t' << count << endl;
+ venn->getPic(lastSAbund, vennCalculators);
+ }
+ delete lastSAbund;
}
+
globaldata->setGroups("");
return 0;
}