X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sharedcommand.cpp;h=42601f48ead5e872d000e35c9b64852ddccd5eb8;hb=b7cce6e0a45013919e76a266533fcca4052cf157;hp=6c4c8ac9afbda821c545ab3a48d60a993e290620;hpb=20a2d0350a737a434c89f303662d64a8eeea7b05;p=mothur.git diff --git a/sharedcommand.cpp b/sharedcommand.cpp index 6c4c8ac..42601f4 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -36,21 +36,81 @@ SharedCommand::SharedCommand(){ int SharedCommand::execute(){ try { globaldata = GlobalData::getInstance(); + //lookup.clear(); + int count = 1; + string errorOff = "no error"; //read in listfile - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); + input = globaldata->ginput; - list = globaldata->glist; + SharedList = globaldata->gSharedList; + SharedListVector* lastList = SharedList; + //lookup = SharedList->getSharedRAbundVector(); + //vector lastLookup = lookup; + + //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. + set processedLabels; + set userLabels = globaldata->labels; + set userLines = globaldata->lines; shared = new Shared(); - int i = 0; - while(list != NULL){ - shared->getSharedVectors(i, list); //fills sharedGroups with new info and updates sharedVector - list = input->getListVector(); //get new list vector to process + + while((SharedList != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) { + + + if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){ + + 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()); + userLines.erase(count); + } + + 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 + count++; + + //if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } } + //lastLookup = lookup; + //if (SharedList != NULL) { lookup = SharedList->getSharedRAbundVector(); } + } + + //output error messages about any remaining user labels + set::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 - i++; } + + delete lastList; globaldata->gSharedList = NULL; + delete shared; + out.close(); + return 0; } catch(exception& e) { @@ -66,6 +126,12 @@ int SharedCommand::execute(){ //********************************************************************************************************************** void SharedCommand::printSharedData() { try { + + ///for (int i = 0; i < thislookup.size(); i++) { + // out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t'; +//cout << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << endl; + // thislookup[i]->print(out); + // } //prints out horizontally for (it = shared->sharedGroups.begin(); it != shared->sharedGroups.end(); it++) { out << it->second->getLabel() << "\t" << it->first << "\t"; //prints out label and groupname @@ -88,6 +154,7 @@ void SharedCommand::printSharedData() { SharedCommand::~SharedCommand(){ //delete list; delete read; + } //**********************************************************************************************************************