X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=sharedlistvector.cpp;h=223ca073fa2c5c9c083d5d20bc024fe82f724b68;hp=6cac9b1d9512a16d15eef553d351de0b16771b6e;hb=1a20e24ee786195ab0e1cccd4f5aede7a88f3f4e;hpb=f5023c911c377e5320c5110c78af98dd8841ef58 diff --git a/sharedlistvector.cpp b/sharedlistvector.cpp index 6cac9b1..223ca07 100644 --- a/sharedlistvector.cpp +++ b/sharedlistvector.cpp @@ -16,35 +16,39 @@ /***********************************************************************/ -SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance(); groupmap = NULL; } +SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){ groupmap = NULL; countTable = NULL; } /***********************************************************************/ -SharedListVector::SharedListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance(); groupmap = NULL; } +SharedListVector::SharedListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){ groupmap = NULL; countTable = NULL; } /***********************************************************************/ SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { try { - globaldata = GlobalData::getInstance(); - + groupmap = NULL; countTable = NULL; //set up groupmap for later. - groupmap = new GroupMap(globaldata->getGroupFile()); - groupmap->readMap(); + if (m->groupMode == "group") { + groupmap = new GroupMap(m->getGroupFile()); + groupmap->readMap(); + }else { + countTable = new CountTable(); + countTable->readTable(m->getCountTableFile()); + } int hold; string inputData; f >> label >> hold; data.assign(hold, ""); - + for(int i=0;i> inputData; set(i, inputData); } - + } catch(exception& e) { - errorOut(e, "SharedListVector", "SharedListVector"); + m->errorOut(e, "SharedListVector", "SharedListVector"); exit(1); } } @@ -52,18 +56,20 @@ SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numB /***********************************************************************/ void SharedListVector::set(int binNumber, string seqNames){ try { - int nNames_old = getNumNames(data[binNumber]); + int nNames_old = m->getNumNames(data[binNumber]); data[binNumber] = seqNames; - int nNames_new = getNumNames(seqNames); + int nNames_new = m->getNumNames(seqNames); if(nNames_old == 0) { numBins++; } if(nNames_new == 0) { numBins--; } if(nNames_new > maxRank) { maxRank = nNames_new; } numSeqs += (nNames_new - nNames_old); + + } catch(exception& e) { - errorOut(e, "SharedListVector", "set"); + m->errorOut(e, "SharedListVector", "set"); exit(1); } } @@ -79,7 +85,7 @@ string SharedListVector::get(int index){ void SharedListVector::push_back(string seqNames){ try { data.push_back(seqNames); - int nNames = getNumNames(seqNames); + int nNames = m->getNumNames(seqNames); numBins++; @@ -88,7 +94,7 @@ void SharedListVector::push_back(string seqNames){ numSeqs += nNames; } catch(exception& e) { - errorOut(e, "SharedListVector", "push_back"); + m->errorOut(e, "SharedListVector", "push_back"); exit(1); } } @@ -128,7 +134,7 @@ void SharedListVector::print(ostream& output){ output << endl; } catch(exception& e) { - errorOut(e, "SharedListVector", "print"); + m->errorOut(e, "SharedListVector", "print"); exit(1); } } @@ -141,7 +147,7 @@ RAbundVector SharedListVector::getRAbundVector(){ RAbundVector rav; for(int i=0;igetNumNames(data[i]); rav.push_back(binSize); } @@ -159,7 +165,7 @@ RAbundVector SharedListVector::getRAbundVector(){ return rav; } catch(exception& e) { - errorOut(e, "SharedListVector", "getRAbundVector"); + m->errorOut(e, "SharedListVector", "getRAbundVector"); exit(1); } } @@ -171,7 +177,7 @@ SAbundVector SharedListVector::getSAbundVector(){ SAbundVector sav(maxRank+1); for(int i=0;igetNumNames(data[i]); sav.set(binSize, sav.get(binSize) + 1); } sav.set(0, 0); @@ -180,7 +186,7 @@ SAbundVector SharedListVector::getSAbundVector(){ return sav; } catch(exception& e) { - errorOut(e, "SharedListVector", "getSAbundVector"); + m->errorOut(e, "SharedListVector", "getSAbundVector"); exit(1); } } @@ -188,27 +194,34 @@ SAbundVector SharedListVector::getSAbundVector(){ /***********************************************************************/ SharedOrderVector* SharedListVector::getSharedOrderVector(){ try { - string groupName, names, name; - SharedOrderVector* order = new SharedOrderVector(); order->setLabel(label); for(int i=0;igetGroup(name); - - if(groupName == "not found") { mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } + int binSize = m->getNumNames(get(i)); //find number of individual in given bin + string names = get(i); + vector binNames; + m->splitAtComma(names, binNames); + if (m->groupMode != "group") { + binSize = 0; + for (int j = 0; j < binNames.size(); j++) { binSize += countTable->getNumSeqs(binNames[i]); } + } + for (int j = 0; j < binNames.size(); j++) { + if (m->control_pressed) { return order; } + if (m->groupMode == "group") { + string groupName = groupmap->getGroup(binNames[i]); + if(groupName == "not found") { m->mothurOut("Error: Sequence '" + binNames[i] + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); } - order->push_back(i, binSize, groupName); //i represents what bin you are in + order->push_back(i, binSize, groupName); //i represents what bin you are in + }else { + vector groupAbundances = countTable->getGroupCounts(binNames[i]); + vector groupNames = countTable->getNamesOfGroups(); + for (int k = 0; k < groupAbundances.size(); k++) { //groupAbundances.size() == 0 if there is a file mismatch and m->control_pressed is true. + if (m->control_pressed) { return order; } + for (int l = 0; l < groupAbundances[k]; l++) { order->push_back(i, binSize, groupNames[k]); } + } + } } - //get last name - groupName = groupmap->getGroup(names); - if(groupName == "not found") { mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } - order->push_back(i, binSize, groupName); } random_shuffle(order->begin(), order->end()); @@ -217,7 +230,7 @@ SharedOrderVector* SharedListVector::getSharedOrderVector(){ return order; } catch(exception& e) { - errorOut(e, "SharedListVector", "getSharedOrderVector"); + m->errorOut(e, "SharedListVector", "getSharedOrderVector"); exit(1); } } @@ -225,25 +238,23 @@ SharedOrderVector* SharedListVector::getSharedOrderVector(){ SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) { try { SharedRAbundVector rav(data.size()); - string group, names, name; for(int i=0;igetGroup(name); - if(group == "not found") { mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } - if (group == groupName) { //this name is in the group you want the vector for. - rav.set(i, rav.getAbundance(i) + 1, group); //i represents what bin you are in - } - } - - //get last name - groupName = groupmap->getGroup(names); - if(groupName == "not found") { mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } - if (group == groupName) { //this name is in the group you want the vector for. - rav.set(i, rav.getAbundance(i) + 1, group); //i represents what bin you are in + string names = get(i); + vector binNames; + m->splitAtComma(names, binNames); + for (int j = 0; j < binNames.size(); j++) { + if (m->control_pressed) { return rav; } + if (m->groupMode == "group") { + string group = groupmap->getGroup(binNames[j]); + if(group == "not found") { m->mothurOut("Error: Sequence '" + binNames[j] + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); } + if (group == groupName) { //this name is in the group you want the vector for. + rav.set(i, rav.getAbundance(i) + 1, group); //i represents what bin you are in + } + }else { + int count = countTable->getGroupCount(binNames[j], groupName); + rav.set(i, rav.getAbundance(i) + count, groupName); + } } } @@ -254,7 +265,7 @@ SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) { } catch(exception& e) { - errorOut(e, "SharedListVector", "getSharedRAbundVector"); + m->errorOut(e, "SharedListVector", "getSharedRAbundVector"); exit(1); } } @@ -263,58 +274,55 @@ vector SharedListVector::getSharedRAbundVector() { try { SharedUtil* util; util = new SharedUtil(); - vector lookup; - vector lookup2; - map finder; - map::iterator it; - string group, names, name; - - util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups); + vector lookup; //contains just the groups the user selected + vector lookupDelete; + map finder; //contains all groups in groupmap + + vector Groups = m->getGroups(); + vector allGroups; + if (m->groupMode == "group") { allGroups = groupmap->getNamesOfGroups(); } + else { allGroups = countTable->getNamesOfGroups(); } + util->setGroups(Groups, allGroups); + m->setGroups(Groups); delete util; - for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) { + for (int i = 0; i < allGroups.size(); i++) { SharedRAbundVector* temp = new SharedRAbundVector(data.size()); - finder[globaldata->gGroupmap->namesOfGroups[i]] = temp; - finder[globaldata->gGroupmap->namesOfGroups[i]]->setLabel(label); - finder[globaldata->gGroupmap->namesOfGroups[i]]->setGroup(globaldata->gGroupmap->namesOfGroups[i]); - //*temp = getSharedRAbundVector(globaldata->Groups[i]); - lookup.push_back(finder[globaldata->gGroupmap->namesOfGroups[i]]); + finder[allGroups[i]] = temp; + finder[allGroups[i]]->setLabel(label); + finder[allGroups[i]]->setGroup(allGroups[i]); + if (m->inUsersGroups(allGroups[i], m->getGroups())) { //if this group is in user groups + lookup.push_back(finder[allGroups[i]]); + }else { + lookupDelete.push_back(finder[allGroups[i]]); + } } -//cout << "after blanks" << endl; + //fill vectors for(int i=0;igetGroup(name); -//cout << i << '\t' << name << '\t' << group << endl; - if(group == "not found") { mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } - finder[group]->set(i, finder[group]->getAbundance(i) + 1, group); //i represents what bin you are in - } - - //get last name - group = groupmap->getGroup(names); -//cout << i << '\t' << names << '\t' << group << endl; - if(group == "not found") { mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } - finder[group]->set(i, finder[group]->getAbundance(i) + 1, group); //i represents what bin you are in - - } - - if (globaldata->Groups.size() == globaldata->gGroupmap->namesOfGroups.size()) { //no groups specified - lookup2 = lookup; - }else{ //delete unwanted groups - for (int i = 0; i < globaldata->Groups.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(*finder[globaldata->Groups[i]]); - lookup2.push_back(temp); - delete finder[globaldata->Groups[i]]; //so we don't get dup memory + string names = get(i); + vector binNames; + m->splitAtComma(names, binNames); + for (int j = 0; j < binNames.size(); j++) { + if (m->groupMode == "group") { + string group = groupmap->getGroup(binNames[j]); + if(group == "not found") { m->mothurOut("Error: Sequence '" + binNames[j] + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); } + finder[group]->set(i, finder[group]->getAbundance(i) + 1, group); //i represents what bin you are in + }else{ + vector counts = countTable->getGroupCounts(binNames[j]); + for (int k = 0; k < allGroups.size(); k++) { + finder[allGroups[k]]->set(i, finder[allGroups[k]]->getAbundance(i) + counts[k], allGroups[k]); + } + } } } - - return lookup2; + + for (int j = 0; j < lookupDelete.size(); j++) { delete lookupDelete[j]; } + + return lookup; } catch(exception& e) { - errorOut(e, "SharedListVector", "getSharedRAbundVector"); + m->errorOut(e, "SharedListVector", "getSharedRAbundVector"); exit(1); } } @@ -331,7 +339,7 @@ SharedSAbundVector SharedListVector::getSharedSAbundVector(string groupName) { return sav; } catch(exception& e) { - errorOut(e, "SharedListVector", "getSharedSAbundVector"); + m->errorOut(e, "SharedListVector", "getSharedSAbundVector"); exit(1); } } @@ -344,7 +352,14 @@ OrderVector SharedListVector::getOrderVector(map* orderMap = NULL){ OrderVector ov; for(int i=0;i binNames; + m->splitAtComma(names, binNames); + int binSize = binNames.size(); + if (m->groupMode != "group") { + binSize = 0; + for (int j = 0; j < binNames.size(); j++) { binSize += countTable->getNumSeqs(binNames[i]); } + } for(int j=0;j* orderMap = NULL){ for(int i=0;icount(seqName) == 0){ - mothurOut(seqName + " not found, check *.names file\n"); - exit(1); - } - - ov.set((*orderMap)[seqName], i); - seqName = ""; - } - } - - if(orderMap->count(seqName) == 0){ - mothurOut(seqName + " not found, check *.names file\n"); - exit(1); + vector binNames; + m->splitAtComma(listOTU, binNames); + for (int j = 0; j < binNames.size(); j++) { + if(orderMap->count(binNames[j]) == 0){ + m->mothurOut(binNames[j] + " not found, check *.names file\n"); + exit(1); + } + ov.set((*orderMap)[binNames[j]], i); } - ov.set((*orderMap)[seqName], i); } ov.setLabel(label); @@ -395,7 +394,7 @@ OrderVector SharedListVector::getOrderVector(map* orderMap = NULL){ } } catch(exception& e) { - errorOut(e, "SharedListVector", "getOrderVector"); + m->errorOut(e, "SharedListVector", "getOrderVector"); exit(1); } }