X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=parselistcommand.cpp;h=5de3b72daa63b962ff9be84b5665e7230fb2470b;hb=753dc84cf289b1d5dc0ca5b0c043640927aa951a;hp=5379052d6dd4f1bbfe51b3b346874def78a7b841;hpb=4761e165b4a196fefa57755d3176d9ced19df6b1;p=mothur.git diff --git a/parselistcommand.cpp b/parselistcommand.cpp index 5379052..5de3b72 100644 --- a/parselistcommand.cpp +++ b/parselistcommand.cpp @@ -15,9 +15,8 @@ ParseListCommand::ParseListCommand(){ globaldata = GlobalData::getInstance(); //read in group map info. - groupMap = new GroupMap(globaldata->getGroupFile()); - groupMap->readMap(); - + groupMap = globaldata->gGroupmap; + //fill filehandles with neccessary ofstreams int i; ofstream* temp; @@ -44,7 +43,7 @@ ParseListCommand::ParseListCommand(){ } } /***********************************************************************/ -void ParseListCommand::parse(int index) { +void ParseListCommand::parse(int index, SharedListVector* list) { try { string prefix, suffix, groupsName; suffix = list->get(index); @@ -85,49 +84,90 @@ void ParseListCommand::parse(int index) { int ParseListCommand::execute(){ try{ - globaldata = GlobalData::getInstance(); + int count = 1; //read in listfile - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; list = globaldata->gSharedList; - - //read in group map info. - groupMap = new GroupMap(globaldata->getGroupFile()); - groupMap->readMap(); + 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 processedLabels; + set userLabels = globaldata->labels; + set userLines = globaldata->lines; - string seq, label; - int i; //create new list vectors to fill with parsed data - for (i=0; igetNumGroups(); i++) { + for (int i=0; igetNumGroups(); i++) { groupOfLists[groupMap->namesOfGroups[i]] = new SharedListVector(); } + //parses and sets each groups listvector - while(list != NULL){ - label = list->getLabel(); - for(i=0; isize(); 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(); + //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) || (userLines.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); + + processedLabels.insert(list->getLabel()); + userLabels.erase(list->getLabel()); + userLines.erase(count); } - //prints each new list file - for (i=0; igetNumGroups(); i++) { - groupOfLists[groupMap->namesOfGroups[i]]->setLabel(label); - groupOfLists[groupMap->namesOfGroups[i]]->print(*(filehandles[groupMap->namesOfGroups[i]])); - groupOfLists[groupMap->namesOfGroups[i]]->clear(); + + 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::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; } globaldata->gGroupmap = groupMap; + //close files + for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { + ofstream* temp = it3->second; + (*temp).close(); + delete it3->second; + } + + //delete list vectors to fill with parsed data + for (it2 = groupOfLists.begin(); it2 != groupOfLists.end(); it2++) { + delete it2->second; + } + return 0; } catch(exception& e) { @@ -148,3 +188,33 @@ ParseListCommand::~ParseListCommand(){ delete read; } //********************************************************************************************************************** +void ParseListCommand::process(SharedListVector* thisList) { + try { + string seq; + + for(int i=0; isize(); 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; igetNumGroups(); 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