//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);
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 = input->getListVector();
- list = globaldata->glist;
+ 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;
+ set<int> userLines = globaldata->lines;
//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++) {
- groupOfLists[groupMap->namesOfGroups[i]] = new ListVector();
+ 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();
- 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();
+ //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; i<groupMap->getNumGroups(); 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());
}
- list = input->getListVector();
+
+ 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; }
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