From: westcott Date: Tue, 23 Jun 2009 15:36:46 +0000 (+0000) Subject: changed how we do "smart" distancing X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=016a30dacbe75869aef5fdb58d2d1bf9eb8f9b33 changed how we do "smart" distancing --- diff --git a/binsequencecommand.cpp b/binsequencecommand.cpp index 0ae5d9e..a291caa 100644 --- a/binsequencecommand.cpp +++ b/binsequencecommand.cpp @@ -164,7 +164,7 @@ int BinSeqCommand::execute(){ input = globaldata->ginput; list = globaldata->gListVector; - ListVector* lastList = list; + string lastLabel = list->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; @@ -184,19 +184,21 @@ int BinSeqCommand::execute(){ userLines.erase(count); } - if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastList->getLabel()) != 1)) { + if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + delete list; + list = input->getListVector(lastLabel); - error = process(lastList, count); + error = process(list, count); if (error == 1) { return 0; } - processedLabels.insert(lastList->getLabel()); - userLabels.erase(lastList->getLabel()); + processedLabels.insert(list->getLabel()); + userLabels.erase(list->getLabel()); } - if (count != 1) { delete lastList; } - lastList = list; - + lastLabel = list->getLabel(); + + delete list; list = input->getListVector(); count++; } @@ -207,21 +209,25 @@ int BinSeqCommand::execute(){ 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastList->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << endl; } } //run last line if you need to if (needToRun == true) { - error = process(lastList, count); - if (error == 1) { return 0; } + delete list; + list = input->getListVector(lastLabel); + + error = process(list, count); + if (error == 1) { return 0; } + + delete list; } - delete lastList; return 0; } catch(exception& e) { diff --git a/bootstrapsharedcommand.cpp b/bootstrapsharedcommand.cpp index a94954a..68ef54a 100644 --- a/bootstrapsharedcommand.cpp +++ b/bootstrapsharedcommand.cpp @@ -201,7 +201,7 @@ int BootSharedCommand::execute(){ read->read(&*globaldata); input = globaldata->ginput; order = input->getSharedOrderVector(); - SharedOrderVector* lastOrder = order; + string lastLabel = order->getLabel(); //if the users entered no valid calculators don't execute command if (treeCalculators.size() == 0) { return 0; } @@ -239,19 +239,22 @@ int BootSharedCommand::execute(){ } //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); + if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + + delete order; + order = input->getSharedOrderVector(lastLabel); + cout << order->getLabel() << '\t' << count << endl; + process(order); - processedLabels.insert(lastOrder->getLabel()); - userLabels.erase(lastOrder->getLabel()); + processedLabels.insert(order->getLabel()); + userLabels.erase(order->getLabel()); } - if (count != 1) { delete lastOrder; } - lastOrder = order; + + lastLabel = order->getLabel(); //get next line to process + delete order; order = input->getSharedOrderVector(); count++; } @@ -261,21 +264,23 @@ int BootSharedCommand::execute(){ 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastOrder->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << endl; } } //run last line if you need to if (needToRun == true) { - process(lastOrder); - cout << lastOrder->getLabel() << '\t' << count << endl; + delete order; + order = input->getSharedOrderVector(lastLabel); + cout << order->getLabel() << '\t' << count << endl; + process(order); + delete order; + } - - delete lastOrder; //reset groups parameter globaldata->Groups.clear(); diff --git a/collectcommand.cpp b/collectcommand.cpp index c65080f..dbb2ede 100644 --- a/collectcommand.cpp +++ b/collectcommand.cpp @@ -220,7 +220,7 @@ int CollectCommand::execute(){ read->read(&*globaldata); order = globaldata->gorder; - lastOrder = order; + string lastLabel = order->getLabel(); input = globaldata->ginput; //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. @@ -244,18 +244,23 @@ int CollectCommand::execute(){ //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); + if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + + delete order; + order = (input->getOrderVector(lastLabel)); + + cCurve = new Collect(order, cDisplays); cCurve->getCurve(freq); delete cCurve; - cout << lastOrder->getLabel() << '\t' << count << endl; - processedLabels.insert(lastOrder->getLabel()); - userLabels.erase(lastOrder->getLabel()); + cout << order->getLabel() << '\t' << count << endl; + processedLabels.insert(order->getLabel()); + userLabels.erase(order->getLabel()); } - if (count != 1) { delete lastOrder; } - lastOrder = order; + lastLabel = order->getLabel(); + + delete order; order = (input->getOrderVector()); count++; } @@ -265,24 +270,28 @@ int CollectCommand::execute(){ 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastOrder->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << endl; } } //run last line if you need to if (needToRun == true) { - cCurve = new Collect(lastOrder, cDisplays); + delete order; + order = (input->getOrderVector(lastLabel)); + + cout << order->getLabel() << '\t' << count << endl; + + cCurve = new Collect(order, cDisplays); cCurve->getCurve(freq); delete cCurve; - - cout << lastOrder->getLabel() << '\t' << count << endl; + delete order; } - delete lastOrder; + for(int i=0;iginput; order = input->getSharedOrderVector(); - SharedOrderVector* lastOrder = order; + string lastLabel = order->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; @@ -268,21 +268,25 @@ int CollectSharedCommand::execute(){ //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)) { + if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + delete order; + order = input->getSharedOrderVector(lastLabel); + //create collectors curve - cCurve = new Collect(lastOrder, cDisplays); + cCurve = new Collect(order, cDisplays); cCurve->getSharedCurve(freq); delete cCurve; - cout << lastOrder->getLabel() << '\t' << count << endl; - processedLabels.insert(lastOrder->getLabel()); - userLabels.erase(lastOrder->getLabel()); + cout << order->getLabel() << '\t' << count << endl; + processedLabels.insert(order->getLabel()); + userLabels.erase(order->getLabel()); } - if (count != 1) { delete lastOrder; } - lastOrder = order; + + lastLabel = order->getLabel(); //get next line to process + delete order; order = input->getSharedOrderVector(); count++; } @@ -292,24 +296,27 @@ int CollectSharedCommand::execute(){ 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastOrder->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << endl; } } //run last line if you need to if (needToRun == true) { - cCurve = new Collect(lastOrder, cDisplays); + delete order; + order = input->getSharedOrderVector(lastLabel); + + cCurve = new Collect(order, cDisplays); cCurve->getCurve(freq); delete cCurve; - cout << lastOrder->getLabel() << '\t' << count << endl; + cout << order->getLabel() << '\t' << count << endl; + delete order; } - delete lastOrder; for(int i=0;iginput; list = globaldata->gListVector; - ListVector* lastList = list; + string lastLabel = list->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; @@ -215,18 +215,22 @@ int GetOTURepCommand::execute(){ userLines.erase(count); } - if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastList->getLabel()) != 1)) { - cout << lastList->getLabel() << '\t' << count << endl; - error = process(lastList); + if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + delete list; + list = input->getListVector(lastLabel); + + cout << list->getLabel() << '\t' << count << endl; + error = process(list); if (error == 1) { return 0; } //there is an error in hte input files, abort command - processedLabels.insert(lastList->getLabel()); - userLabels.erase(lastList->getLabel()); + processedLabels.insert(list->getLabel()); + userLabels.erase(list->getLabel()); } - if (count != 1) { delete lastList; } - lastList = list; + lastLabel = list->getLabel(); + + delete list; list = input->getListVector(); count++; } @@ -235,25 +239,27 @@ int GetOTURepCommand::execute(){ bool needToRun = false; for (set::iterator 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastList->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << endl; } } //run last line if you need to if (needToRun == true) { - cout << lastList->getLabel() << '\t' << count << endl; - error = process(lastList); + delete list; + list = input->getListVector(lastLabel); + + cout << list->getLabel() << '\t' << count << endl; + error = process(list); if (error == 1) { return 0; } //there is an error in hte input files, abort command + delete list; } - delete lastList; delete matrix; globaldata->gSparseMatrix = NULL; - delete list; globaldata->gListVector = NULL; return 0; diff --git a/getrabundcommand.cpp b/getrabundcommand.cpp index 0dfaa63..b8c692b 100644 --- a/getrabundcommand.cpp +++ b/getrabundcommand.cpp @@ -126,7 +126,7 @@ int GetRAbundCommand::execute(){ input = globaldata->ginput; list = globaldata->gListVector; - ListVector* lastList = list; + string lastLabel = list->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; @@ -148,20 +148,23 @@ int GetRAbundCommand::execute(){ userLines.erase(count); } - if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastList->getLabel()) != 1)) { - cout << lastList->getLabel() << '\t' << count << endl; + if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + delete list; + list = input->getListVector(lastLabel); + + cout << list->getLabel() << '\t' << count << endl; rabund = new RAbundVector(); - *rabund = (lastList->getRAbundVector()); + *rabund = (list->getRAbundVector()); rabund->print(out); delete rabund; - processedLabels.insert(lastList->getLabel()); - userLabels.erase(lastList->getLabel()); + processedLabels.insert(list->getLabel()); + userLabels.erase(list->getLabel()); } - if (count != 1) { delete lastList; } - lastList = list; + lastLabel = list->getLabel(); + delete list; list = input->getListVector(); count++; } @@ -171,23 +174,26 @@ int GetRAbundCommand::execute(){ 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastList->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << endl; } } //run last line if you need to if (needToRun == true) { - cout << lastList->getLabel() << '\t' << count << endl; + delete list; + list = input->getListVector(lastLabel); + + cout << list->getLabel() << '\t' << count << endl; rabund = new RAbundVector(); - *rabund = (lastList->getRAbundVector()); + *rabund = (list->getRAbundVector()); rabund->print(out); delete rabund; + delete list; } - delete lastList; out.close(); return 0; diff --git a/getsabundcommand.cpp b/getsabundcommand.cpp index 1e10736..f5beb32 100644 --- a/getsabundcommand.cpp +++ b/getsabundcommand.cpp @@ -124,7 +124,7 @@ int GetSAbundCommand::execute(){ read->read(&*globaldata); order = globaldata->gorder; - lastOrder = order; + string lastLabel = order->getLabel(); input = globaldata->ginput; //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. @@ -147,20 +147,24 @@ int GetSAbundCommand::execute(){ userLines.erase(count); } - if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastOrder->getLabel()) != 1)) { - cout << lastOrder->getLabel() << '\t' << count << endl; + if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + delete order; + order = (input->getOrderVector(lastLabel)); + + cout << order->getLabel() << '\t' << count << endl; sabund = new SAbundVector(); - *sabund = (lastOrder->getSAbundVector()); + *sabund = (order->getSAbundVector()); sabund->print(out); delete sabund; - processedLabels.insert(lastOrder->getLabel()); - userLabels.erase(lastOrder->getLabel()); + processedLabels.insert(order->getLabel()); + userLabels.erase(order->getLabel()); } - if (count != 1) { delete lastOrder; } - lastOrder = order; - + + lastLabel = order->getLabel(); + + delete order; order = (input->getOrderVector()); count++; } @@ -170,23 +174,27 @@ int GetSAbundCommand::execute(){ 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastOrder->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << endl; } } //run last line if you need to if (needToRun == true) { - cout << lastOrder->getLabel() << '\t' << count << endl; + delete order; + order = (input->getOrderVector(lastLabel)); + + cout << order->getLabel() << '\t' << count << endl; sabund = new SAbundVector(); - *sabund = (lastOrder->getSAbundVector()); + *sabund = (order->getSAbundVector()); sabund->print(out); delete sabund; + delete order; } - delete lastOrder; globaldata->gorder = NULL; + globaldata->gorder = NULL; out.close(); return 0; diff --git a/getsabundcommand.h b/getsabundcommand.h index dcda3aa..2612b7d 100644 --- a/getsabundcommand.h +++ b/getsabundcommand.h @@ -31,7 +31,6 @@ private: ofstream out; ReadOTUFile* read; OrderVector* order; - OrderVector* lastOrder; InputData* input; SAbundVector* sabund; diff --git a/heatmapcommand.cpp b/heatmapcommand.cpp index 7a729c6..413889e 100644 --- a/heatmapcommand.cpp +++ b/heatmapcommand.cpp @@ -142,8 +142,7 @@ int HeatMapCommand::execute(){ if (abort == true) { return 0; } int count = 1; - RAbundVector* lastRAbund; - vector lastLookup; + string lastLabel; if (format == "sharedfile") { //you have groups @@ -152,14 +151,14 @@ int HeatMapCommand::execute(){ input = globaldata->ginput; lookup = input->getSharedRAbundVectors(); - lastLookup = lookup; + lastLabel = lookup[0]->getLabel(); }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; + lastLabel = rabund->getLabel(); input = globaldata->ginput; } @@ -183,18 +182,21 @@ int HeatMapCommand::execute(){ userLines.erase(count); } - if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) { - cout << lastLookup[0]->getLabel() << '\t' << count << endl; - heatmap->getPic(lastLookup); + if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + cout << lastLabel << '\t' << count << endl; + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + lookup = input->getSharedRAbundVectors(lastLabel); - processedLabels.insert(lastLookup[0]->getLabel()); - userLabels.erase(lastLookup[0]->getLabel()); + heatmap->getPic(lookup); + + processedLabels.insert(lookup[0]->getLabel()); + userLabels.erase(lookup[0]->getLabel()); } + lastLabel = lookup[0]->getLabel(); //prevent memory leak - if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } } - lastLookup = lookup; - + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + //get next line to process lookup = input->getSharedRAbundVectors(); count++; @@ -205,21 +207,25 @@ int HeatMapCommand::execute(){ 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << endl; } } //run last line if you need to if (needToRun == true) { - cout << lastLookup[0]->getLabel() << '\t' << count << endl; - heatmap->getPic(lastLookup); + cout << lastLabel << '\t' << count << endl; + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + lookup = input->getSharedRAbundVectors(lastLabel); + + heatmap->getPic(lookup); + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } - for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } + //reset groups parameter globaldata->Groups.clear(); @@ -238,18 +244,22 @@ int HeatMapCommand::execute(){ userLines.erase(count); } - if ((anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastRAbund->getLabel()) != 1)) { + if ((anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - cout << lastRAbund->getLabel() << '\t' << count << endl; - heatmap->getPic(lastRAbund); + cout << lastLabel << '\t' << count << endl; + delete rabund; + rabund = input->getRAbundVector(lastLabel); - processedLabels.insert(lastRAbund->getLabel()); - userLabels.erase(lastRAbund->getLabel()); + heatmap->getPic(rabund); + + processedLabels.insert(rabund->getLabel()); + userLabels.erase(rabund->getLabel()); } - if (count != 1) { delete lastRAbund; } - lastRAbund = rabund; - + + + lastLabel = rabund->getLabel(); + delete rabund; rabund = input->getRAbundVector(); count++; } @@ -259,22 +269,24 @@ int HeatMapCommand::execute(){ 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastRAbund->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << endl; } } //run last line if you need to if (needToRun == true) { - cout << lastRAbund->getLabel() << '\t' << count << endl; - heatmap->getPic(lastRAbund); + cout << lastLabel << '\t' << count << endl; + delete rabund; + rabund = input->getRAbundVector(lastLabel); + + heatmap->getPic(rabund); + delete rabund; globaldata->rabund = NULL; } - delete lastRAbund; globaldata->rabund = NULL; - } delete input; globaldata->ginput = NULL; diff --git a/heatmapsimcommand.cpp b/heatmapsimcommand.cpp index f332994..331ff79 100644 --- a/heatmapsimcommand.cpp +++ b/heatmapsimcommand.cpp @@ -197,7 +197,7 @@ int HeatMapSimCommand::execute(){ input = globaldata->ginput; lookup = input->getSharedRAbundVectors(); - vector lastLookup = lookup; + string lastLabel = lookup[0]->getLabel(); if (lookup.size() < 2) { cout << "You have not provided enough valid groups. I cannot run the command." << endl; return 0;} @@ -220,19 +220,24 @@ int HeatMapSimCommand::execute(){ userLines.erase(count); } - if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) { - cout << lastLookup[0]->getLabel() << '\t' << count << endl; - heatmap->getPic(lastLookup, heatCalculators); + if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + lookup = input->getSharedRAbundVectors(lastLabel); + + cout << lookup[0]->getLabel() << '\t' << count << endl; + heatmap->getPic(lookup, heatCalculators); - processedLabels.insert(lastLookup[0]->getLabel()); - userLabels.erase(lastLookup[0]->getLabel()); + processedLabels.insert(lookup[0]->getLabel()); + userLabels.erase(lookup[0]->getLabel()); } //prevent memory leak - if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } } - lastLookup = lookup; + + lastLabel = lookup[0]->getLabel(); //get next line to process + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup = input->getSharedRAbundVectors(); count++; } @@ -242,21 +247,24 @@ int HeatMapSimCommand::execute(){ 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel<< "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << endl; } } //run last line if you need to if (needToRun == true) { - cout << lastLookup[0]->getLabel() << '\t' << count << endl; - heatmap->getPic(lastLookup, heatCalculators); + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + lookup = input->getSharedRAbundVectors(lastLabel); + + cout << lookup[0]->getLabel() << '\t' << count << endl; + heatmap->getPic(lookup, heatCalculators); + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } - for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } //reset groups parameter globaldata->Groups.clear(); diff --git a/inputdata.cpp b/inputdata.cpp index b4373c9..c2f4e4e 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -17,6 +17,7 @@ InputData::InputData(string fName, string f) : format(f){ openInputFile(fName, fileHandle); + filename = fName; } @@ -76,15 +77,58 @@ ListVector* InputData::getListVector(){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; exit(1); } catch(...) { - cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + cout << "An unknown error has occurred in the InputData class function getListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/***********************************************************************/ + +ListVector* InputData::getListVector(string label){ + try { + ifstream in; + string thisLabel; + openInputFile(filename, in); + + if(in){ + + if (format == "list") { + + while (in.eof() != true) { + + list = new ListVector(in); + thisLabel = list->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete list; } + gobble(in); + } + } + + in.close(); + return list; + } + else{ + return NULL; + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the InputData class function getListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; exit(1); } } + /***********************************************************************/ SharedListVector* InputData::getSharedListVector(){ @@ -110,6 +154,50 @@ SharedListVector* InputData::getSharedListVector(){ exit(1); } } +/***********************************************************************/ + +SharedListVector* InputData::getSharedListVector(string label){ + try { + ifstream in; + string thisLabel; + openInputFile(filename, in); + + if(in){ + + if (format == "shared") { + + while (in.eof() != true) { + + SharedList = new SharedListVector(in); + thisLabel = SharedList->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete SharedList; } + gobble(in); + } + + } + + in.close(); + return SharedList; + + }else{ + return NULL; + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the InputData class function getSharedListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + + /***********************************************************************/ @@ -137,6 +225,49 @@ SharedOrderVector* InputData::getSharedOrderVector(){ } } +/***********************************************************************/ + +SharedOrderVector* InputData::getSharedOrderVector(string label){ + try { + ifstream in; + string thisLabel; + openInputFile(filename, in); + + if(in){ + + if (format == "sharedfile") { + + while (in.eof() != true) { + + SharedOrder = new SharedOrderVector(in); + thisLabel = SharedOrder->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete SharedOrder; } + gobble(in); + } + + } + + in.close(); + return SharedOrder; + + }else{ + return NULL; + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the InputData class function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + /***********************************************************************/ @@ -144,7 +275,7 @@ SharedOrderVector* InputData::getSharedOrderVector(){ OrderVector* InputData::getOrderVector(){ try { if(fileHandle){ - if(format == "list") { + if((format == "list") || (format == "listorder")) { input = new ListVector(fileHandle); } else if (format == "shared") { @@ -159,10 +290,7 @@ OrderVector* InputData::getOrderVector(){ else if(format == "sabund"){ input = new SAbundVector(fileHandle); } - else if(format == "listorder"){ - input = new ListVector(fileHandle); - } - + gobble(fileHandle); output = new OrderVector(); *output = (input->getOrderVector()); @@ -182,6 +310,114 @@ OrderVector* InputData::getOrderVector(){ exit(1); } } + +/***********************************************************************/ +OrderVector* InputData::getOrderVector(string label){ + try { + + ifstream in; + string thisLabel; + openInputFile(filename, in); + + if(in){ + if((format == "list") || (format == "listorder")) { + + while (in.eof() != true) { + + input = new ListVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + } + else if (format == "shared") { + + while (in.eof() != true) { + + input = new SharedListVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "rabund"){ + + while (in.eof() != true) { + + input = new RAbundVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "order"){ + + while (in.eof() != true) { + + input = new OrderVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "sabund"){ + + while (in.eof() != true) { + + input = new SAbundVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + + } + + } + + in.close(); + + output = new OrderVector(); + *output = (input->getOrderVector()); + + return output; + + } + else{ + return NULL; + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + /***********************************************************************/ //this is used when you don't need the order vector vector InputData::getSharedRAbundVectors(){ @@ -215,6 +451,68 @@ vector InputData::getSharedRAbundVectors(){ exit(1); } } +/***********************************************************************/ +vector InputData::getSharedRAbundVectors(string label){ + try { + ifstream in; + string thisLabel; + + openInputFile(filename, in); + + if(in){ + if (format == "sharedfile") { + while (in.eof() != true) { + + SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in); + if (SharedRAbund != NULL) { + thisLabel = SharedRAbund->getLabel(); + //if you are at the last label + if (thisLabel == label) { in.close(); return SharedRAbund->getSharedRAbundVectors(); } + else { + //so you don't loose this memory + vector lookup = SharedRAbund->getSharedRAbundVectors(); + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete SharedRAbund; + } + }else{ break; } + gobble(in); + + } + }else if (format == "shared") { + while (in.eof() != true) { + + SharedList = new SharedListVector(in); + if (SharedList != NULL) { + thisLabel = SharedList->getLabel(); + //if you are at the last label + if (thisLabel == label) { in.close(); return SharedList->getSharedRAbundVector(); } + else { + //so you don't loose this memory + delete SharedList; + } + }else{ break; } + gobble(in); + + } + + } + } + + //this is created to signal to calling function that the input file is at eof + vector null; null.push_back(NULL); + in.close(); + return null; + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the InputData class function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} /***********************************************************************/ @@ -258,6 +556,112 @@ SAbundVector* InputData::getSAbundVector(){ exit(1); } } +/***********************************************************************/ +SAbundVector* InputData::getSAbundVector(string label){ + try { + + ifstream in; + string thisLabel; + openInputFile(filename, in); + + if(in){ + if (format == "list") { + + while (in.eof() != true) { + + input = new ListVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + } + else if (format == "shared") { + + while (in.eof() != true) { + + input = new SharedListVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "rabund"){ + + while (in.eof() != true) { + + input = new RAbundVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "order"){ + + while (in.eof() != true) { + + input = new OrderVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "sabund"){ + + while (in.eof() != true) { + + input = new SAbundVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + + } + + } + + in.close(); + + sabund = new SAbundVector(); + *sabund = (input->getSAbundVector()); + + return sabund; + + } + else{ + return NULL; + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the InputData class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} /***********************************************************************/ RAbundVector* InputData::getRAbundVector(){ @@ -300,6 +704,112 @@ RAbundVector* InputData::getRAbundVector(){ } } /***********************************************************************/ +RAbundVector* InputData::getRAbundVector(string label){ + try { + + ifstream in; + string thisLabel; + openInputFile(filename, in); + + if(in){ + if (format == "list") { + + while (in.eof() != true) { + + input = new ListVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + } + else if (format == "shared") { + + while (in.eof() != true) { + + input = new SharedListVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "rabund"){ + + while (in.eof() != true) { + + input = new RAbundVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "order"){ + + while (in.eof() != true) { + + input = new OrderVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "sabund"){ + + while (in.eof() != true) { + + input = new SAbundVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + + } + + } + + in.close(); + + rabund = new RAbundVector(); + *rabund = (input->getRAbundVector()); + + return rabund; + } + else{ + return NULL; + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the InputData class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/***********************************************************************/ diff --git a/inputdata.h b/inputdata.h index e9deb9d..6d2d004 100644 --- a/inputdata.h +++ b/inputdata.h @@ -15,12 +15,19 @@ public: InputData(string, string, string); ~InputData(); ListVector* getListVector(); + ListVector* getListVector(string); //pass the label you want SharedListVector* getSharedListVector(); - OrderVector* getOrderVector(); + SharedListVector* getSharedListVector(string); //pass the label you want + OrderVector* getOrderVector(); + OrderVector* getOrderVector(string); //pass the label you want SharedOrderVector* getSharedOrderVector(); + SharedOrderVector* getSharedOrderVector(string); //pass the label you want SAbundVector* getSAbundVector(); + SAbundVector* getSAbundVector(string); //pass the label you want RAbundVector* getRAbundVector(); + RAbundVector* getRAbundVector(string); //pass the label you want vector getSharedRAbundVectors(); + vector getSharedRAbundVectors(string); //pass the label you want private: string format; @@ -33,6 +40,7 @@ private: SAbundVector* sabund; RAbundVector* rabund; map orderMap; + string filename; }; diff --git a/matrixoutputcommand.cpp b/matrixoutputcommand.cpp index 4ae8e24..e8fb553 100644 --- a/matrixoutputcommand.cpp +++ b/matrixoutputcommand.cpp @@ -195,7 +195,7 @@ int MatrixOutputCommand::execute(){ input = globaldata->ginput; lookup = input->getSharedRAbundVectors(); - vector lastLookup = lookup; + string lastLabel = lookup[0]->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; @@ -218,19 +218,23 @@ int MatrixOutputCommand::execute(){ userLines.erase(count); } - if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) { - cout << lastLookup[0]->getLabel() << '\t' << count << endl; - process(lastLookup); + if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + lookup = input->getSharedRAbundVectors(lastLabel); + + cout << lookup[0]->getLabel() << '\t' << count << endl; + process(lookup); - processedLabels.insert(lastLookup[0]->getLabel()); - userLabels.erase(lastLookup[0]->getLabel()); + processedLabels.insert(lookup[0]->getLabel()); + userLabels.erase(lookup[0]->getLabel()); } - //prevent memory leak - if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } } - lastLookup = lookup; + + lastLabel = lookup[0]->getLabel(); //get next line to process + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup = input->getSharedRAbundVectors(); count++; } @@ -240,23 +244,25 @@ int MatrixOutputCommand::execute(){ 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << 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 < lookup.size(); i++) { delete lookup[i]; } + lookup = input->getSharedRAbundVectors(lastLabel); + cout << lookup[0]->getLabel() << '\t' << count << endl; + process(lookup); + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + } + //reset groups parameter globaldata->Groups.clear(); diff --git a/rarefactcommand.cpp b/rarefactcommand.cpp index 8820328..9bb3daa 100644 --- a/rarefactcommand.cpp +++ b/rarefactcommand.cpp @@ -195,7 +195,7 @@ int RareFactCommand::execute(){ read->read(&*globaldata); order = globaldata->gorder; - OrderVector* lastOrder = order; + string lastLabel = order->getLabel(); input = globaldata->ginput; //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. @@ -218,19 +218,22 @@ int RareFactCommand::execute(){ userLines.erase(count); } - if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastOrder->getLabel()) != 1)) { - rCurve = new Rarefact(lastOrder, rDisplays); + if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + delete order; + order = (input->getOrderVector(lastLabel)); + + rCurve = new Rarefact(order, rDisplays); rCurve->getCurve(freq, nIters); delete rCurve; - cout << lastOrder->getLabel() << '\t' << count << endl; - processedLabels.insert(lastOrder->getLabel()); - userLabels.erase(lastOrder->getLabel()); + cout << order->getLabel() << '\t' << count << endl; + processedLabels.insert(order->getLabel()); + userLabels.erase(order->getLabel()); } - if (count != 1) { delete lastOrder; } - lastOrder = order; - + lastLabel = order->getLabel(); + + delete order; order = (input->getOrderVector()); count++; } @@ -240,24 +243,27 @@ int RareFactCommand::execute(){ 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastOrder->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << endl; } } //run last line if you need to if (needToRun == true) { - rCurve = new Rarefact(lastOrder, rDisplays); + delete order; + order = (input->getOrderVector(lastLabel)); + + rCurve = new Rarefact(order, rDisplays); rCurve->getCurve(freq, nIters); delete rCurve; - cout << lastOrder->getLabel() << '\t' << count << endl; + cout << order->getLabel() << '\t' << count << endl; + delete order; } - delete lastOrder; for(int i=0;iginput; lookup = input->getSharedRAbundVectors(); - vector lastLookup = lookup; + string lastLabel = lookup[0]->getLabel(); if (lookup.size() < 2) { cout << "I cannot run the command without at least 2 valid groups."; @@ -206,21 +206,24 @@ int RareFactSharedCommand::execute(){ userLines.erase(count); } - 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); + if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + lookup = input->getSharedRAbundVectors(lastLabel); + + cout << lookup[0]->getLabel() << '\t' << count << endl; + rCurve = new Rarefact(lookup, rDisplays); rCurve->getSharedCurve(freq, nIters); delete rCurve; - processedLabels.insert(lastLookup[0]->getLabel()); - userLabels.erase(lastLookup[0]->getLabel()); + processedLabels.insert(lookup[0]->getLabel()); + userLabels.erase(lookup[0]->getLabel()); } - //prevent memory leak - if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } } - lastLookup = lookup; + + lastLabel = lookup[0]->getLabel(); //get next line to process + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup = input->getSharedRAbundVectors(); count++; } @@ -230,24 +233,26 @@ int RareFactSharedCommand::execute(){ 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << endl; } } //run last line if you need to if (needToRun == true) { - cout << lastLookup[0]->getLabel() << '\t' << count << endl; - rCurve = new Rarefact(lastLookup, rDisplays); + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + lookup = input->getSharedRAbundVectors(lastLabel); + + cout << lookup[0]->getLabel() << '\t' << count << endl; + rCurve = new Rarefact(lookup, rDisplays); rCurve->getSharedCurve(freq, nIters); delete rCurve; + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } - for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } - for(int i=0;iginput; SharedList = globaldata->gSharedList; - SharedListVector* lastList = SharedList; + string lastLabel = SharedList->getLabel(); vector lookup; //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. @@ -69,18 +69,22 @@ int SharedCommand::execute(){ userLines.erase(count); } - if ((anyLabelsToProcess(SharedList->getLabel(), userLabels, errorOff) == true) && (processedLabels.count(lastList->getLabel()) != 1)) { - lookup = lastList->getSharedRAbundVector(); + if ((anyLabelsToProcess(SharedList->getLabel(), userLabels, errorOff) == true) && (processedLabels.count(lastLabel) != 1)) { + delete SharedList; + SharedList = input->getSharedListVector(lastLabel); //get new list vector to process + + lookup = SharedList->getSharedRAbundVector(); printSharedData(lookup); //prints info to the .shared file for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - processedLabels.insert(lastList->getLabel()); - userLabels.erase(lastList->getLabel()); + processedLabels.insert(SharedList->getLabel()); + userLabels.erase(SharedList->getLabel()); } - if (count != 1) { delete lastList; } - lastList = SharedList; - + + lastLabel = SharedList->getLabel(); + + delete SharedList; SharedList = input->getSharedListVector(); //get new list vector to process count++; @@ -91,7 +95,7 @@ int SharedCommand::execute(){ 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) { + if (processedLabels.count(lastLabel) != 1) { //cout << ". I will use " << lastList->getLabel() << "." << endl; needToRun = true; }else { @@ -101,13 +105,16 @@ int SharedCommand::execute(){ //run last line if you need to if (needToRun == true) { - lookup = lastList->getSharedRAbundVector(); + delete SharedList; + SharedList = input->getSharedListVector(lastLabel); //get new list vector to process + + lookup = SharedList->getSharedRAbundVector(); printSharedData(lookup); //prints info to the .shared file for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - + delete SharedList; } - delete lastList; globaldata->gSharedList = NULL; + globaldata->gSharedList = NULL; delete read; out.close(); diff --git a/sharedrabundvector.cpp b/sharedrabundvector.cpp index 6bf4916..2467128 100644 --- a/sharedrabundvector.cpp +++ b/sharedrabundvector.cpp @@ -16,6 +16,12 @@ /***********************************************************************/ SharedRAbundVector::SharedRAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {globaldata = GlobalData::getInstance();} +/***********************************************************************/ + +SharedRAbundVector::~SharedRAbundVector() { + //for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + +} /***********************************************************************/ diff --git a/sharedrabundvector.h b/sharedrabundvector.h index 8944a26..0c71394 100644 --- a/sharedrabundvector.h +++ b/sharedrabundvector.h @@ -32,7 +32,7 @@ public: //SharedRAbundVector(string, vector); 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(); diff --git a/summarycommand.cpp b/summarycommand.cpp index ee4ba9f..e228dbe 100644 --- a/summarycommand.cpp +++ b/summarycommand.cpp @@ -222,7 +222,7 @@ int SummaryCommand::execute(){ read->read(&*globaldata); sabund = globaldata->sabund; - SAbundVector* lastSAbund = sabund; + string lastLabel = sabund->getLabel(); input = globaldata->ginput; for(int i=0;igetLabel(), userLabels, "") == true) && (processedLabels.count(lastSAbund->getLabel()) != 1)) { - - cout << lastSAbund->getLabel() << '\t' << count << endl; - processedLabels.insert(lastSAbund->getLabel()); - userLabels.erase(lastSAbund->getLabel()); + if ((anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + delete sabund; + sabund = input->getSAbundVector(lastLabel); + + cout << sabund->getLabel() << '\t' << count << endl; + processedLabels.insert(sabund->getLabel()); + userLabels.erase(sabund->getLabel()); - outputFileHandle << lastSAbund->getLabel(); + outputFileHandle << sabund->getLabel(); for(int i=0;i data = sumCalculators[i]->getValues(lastSAbund); + vector data = sumCalculators[i]->getValues(sabund); outputFileHandle << '\t'; sumCalculators[i]->print(outputFileHandle); } outputFileHandle << endl; } - if (count != 1) { delete lastSAbund; } - lastSAbund = sabund; - + lastLabel = sabund->getLabel(); + + delete sabund; sabund = input->getSAbundVector(); count++; } @@ -286,29 +288,32 @@ int SummaryCommand::execute(){ 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastSAbund->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << endl; } } //run last line if you need to if (needToRun == true) { - cout << lastSAbund->getLabel() << '\t' << count << endl; - outputFileHandle << lastSAbund->getLabel(); + delete sabund; + sabund = input->getSAbundVector(lastLabel); + + cout << sabund->getLabel() << '\t' << count << endl; + outputFileHandle << sabund->getLabel(); for(int i=0;i data = sumCalculators[i]->getValues(lastSAbund); + vector data = sumCalculators[i]->getValues(sabund); outputFileHandle << '\t'; sumCalculators[i]->print(outputFileHandle); } outputFileHandle << endl; + delete sabund; } outputFileHandle.close(); - delete lastSAbund; return 0; } catch(exception& e) { diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index 1a3ecf0..9f815cd 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -234,7 +234,7 @@ int SummarySharedCommand::execute(){ input = globaldata->ginput; lookup = input->getSharedRAbundVectors(); - vector lastLookup = lookup; + string lastLabel = lookup[0]->getLabel(); //output estimator names as column headers outputFileHandle << "label" <<'\t' << "comparison" << '\t'; @@ -289,20 +289,24 @@ int SummarySharedCommand::execute(){ userLines.erase(count); } - if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) { - cout << lastLookup[0]->getLabel() << '\t' << count << endl; - process(lastLookup); + if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + lookup = input->getSharedRAbundVectors(lastLabel); + + cout << lookup[0]->getLabel() << '\t' << count << endl; + process(lookup); - processedLabels.insert(lastLookup[0]->getLabel()); - userLabels.erase(lastLookup[0]->getLabel()); + processedLabels.insert(lookup[0]->getLabel()); + userLabels.erase(lookup[0]->getLabel()); } - //prevent memory leak - if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } } - lastLookup = lookup; + + lastLabel = lookup[0]->getLabel(); //get next line to process + //prevent memory leak + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup = input->getSharedRAbundVectors(); count++; } @@ -312,21 +316,24 @@ int SummarySharedCommand::execute(){ 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << 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 < lookup.size(); i++) { delete lookup[i]; } + lookup = input->getSharedRAbundVectors(lastLabel); + + cout << lookup[0]->getLabel() << '\t' << count << endl; + process(lookup); + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } - for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } //reset groups parameter globaldata->Groups.clear(); diff --git a/treegroupscommand.cpp b/treegroupscommand.cpp index 83443d0..cb80ca8 100644 --- a/treegroupscommand.cpp +++ b/treegroupscommand.cpp @@ -232,7 +232,7 @@ int TreeGroupCommand::execute(){ input = globaldata->ginput; lookup = input->getSharedRAbundVectors(); - lastLookup = lookup; + lastLabel = lookup[0]->getLabel(); if (lookup.size() < 2) { cout << "You have not provided enough valid groups. I cannot run the command." << endl; return 0; } @@ -478,19 +478,21 @@ void TreeGroupCommand::makeSimsShared() { userLines.erase(count); } - if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) { - cout << lastLookup[0]->getLabel() << '\t' << count << endl; - process(lastLookup); + if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + lookup = input->getSharedRAbundVectors(lastLabel); + + cout << lookup[0]->getLabel() << '\t' << count << endl; + process(lookup); - processedLabels.insert(lastLookup[0]->getLabel()); - userLabels.erase(lastLookup[0]->getLabel()); + processedLabels.insert(lookup[0]->getLabel()); + userLabels.erase(lookup[0]->getLabel()); } - //prevent memory leak - if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } } - lastLookup = lookup; + lastLabel = lookup[0]->getLabel(); //get next line to process + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup = input->getSharedRAbundVectors(); count++; } @@ -500,21 +502,24 @@ void TreeGroupCommand::makeSimsShared() { 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << 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 < lookup.size(); i++) { delete lookup[i]; } + lookup = input->getSharedRAbundVectors(lastLabel); + + cout << lookup[0]->getLabel() << '\t' << count << endl; + process(lookup); + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } - 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) { diff --git a/treegroupscommand.h b/treegroupscommand.h index 1e1f284..08389f8 100644 --- a/treegroupscommand.h +++ b/treegroupscommand.h @@ -59,7 +59,7 @@ private: InputData* input; ValidCalculators* validCalculator; vector lookup; - vector lastLookup; + string lastLabel; string format, outputFile, groupNames, filename; int numGroups; ofstream out; diff --git a/venncommand.cpp b/venncommand.cpp index 6821e1d..fda3333 100644 --- a/venncommand.cpp +++ b/venncommand.cpp @@ -198,9 +198,8 @@ int VennCommand::execute(){ if (abort == true) { return 0; } int count = 1; - SAbundVector* lastSAbund; - vector lastLookup; - + string lastLabel; + //if the users entered no valid calculators don't execute command if (vennCalculators.size() == 0) { return 0; } @@ -211,14 +210,14 @@ int VennCommand::execute(){ input = globaldata->ginput; lookup = input->getSharedRAbundVectors(); - lastLookup = lookup; + lastLabel = lookup[0]->getLabel(); }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; + lastLabel = sabund->getLabel(); input = globaldata->ginput; } @@ -245,23 +244,26 @@ int VennCommand::execute(){ venn->getPic(lookup, vennCalculators); } - 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 ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + lookup = input->getSharedRAbundVectors(lastLabel); + + cout << lookup[0]->getLabel() << '\t' << count << endl; + processedLabels.insert(lookup[0]->getLabel()); + userLabels.erase(lookup[0]->getLabel()); - if (lastLookup.size() > 4) { + 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 = lastLookup.size(); i > 4; i--) { lastLookup.pop_back(); } //no memmory leak because pop_back calls destructor + for (int i = lookup.size(); i > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor } - venn->getPic(lastLookup, vennCalculators); + venn->getPic(lookup, vennCalculators); } - //prevent memory leak - if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } } - lastLookup = lookup; + + lastLabel = lookup[0]->getLabel(); //get next line to process + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup = input->getSharedRAbundVectors(); count++; } @@ -271,25 +273,31 @@ int VennCommand::execute(){ 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << 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 < lookup.size(); i++) { delete lookup[i]; } + lookup = input->getSharedRAbundVectors(lastLabel); + + 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 > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor + } + venn->getPic(lookup, vennCalculators); + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } - for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } //reset groups parameter globaldata->Groups.clear(); @@ -308,18 +316,20 @@ int VennCommand::execute(){ userLines.erase(count); } - if ((anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastSAbund->getLabel()) != 1)) { - - cout << lastSAbund->getLabel() << '\t' << count << endl; - venn->getPic(lastSAbund, vennCalculators); + if ((anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + delete sabund; + sabund = input->getSAbundVector(lastLabel); + + cout << sabund->getLabel() << '\t' << count << endl; + venn->getPic(sabund, vennCalculators); - processedLabels.insert(lastSAbund->getLabel()); - userLabels.erase(lastSAbund->getLabel()); + processedLabels.insert(sabund->getLabel()); + userLabels.erase(sabund->getLabel()); } - if (count != 1) { delete lastSAbund; } - lastSAbund = sabund; - + lastLabel = sabund->getLabel(); + + delete sabund; sabund = input->getSAbundVector(); count++; } @@ -329,20 +339,25 @@ int VennCommand::execute(){ 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; + if (processedLabels.count(lastLabel) != 1) { + cout << ". I will use " << lastLabel << "." << endl; needToRun = true; }else { - cout << ". Please refer to " << lastSAbund->getLabel() << "." << endl; + cout << ". Please refer to " << lastLabel << "." << endl; } } //run last line if you need to if (needToRun == true) { - cout << lastSAbund->getLabel() << '\t' << count << endl; - venn->getPic(lastSAbund, vennCalculators); + delete sabund; + sabund = input->getSAbundVector(lastLabel); + + cout << sabund->getLabel() << '\t' << count << endl; + venn->getPic(sabund, vennCalculators); + delete sabund; + } - delete lastSAbund; + } for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; }