/***********************************************************************/
-SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){}
+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){}
+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(), true);
+ }
int hold;
string inputData;
f >> label >> hold;
data.assign(hold, "");
-
+
for(int i=0;i<hold;i++){
f >> inputData;
set(i, inputData);
}
-
+
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function SharedListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the SharedListVector class function SharedListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ m->errorOut(e, "SharedListVector", "SharedListVector");
exit(1);
}
}
/***********************************************************************/
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) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the SharedListVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ m->errorOut(e, "SharedListVector", "set");
exit(1);
}
}
void SharedListVector::push_back(string seqNames){
try {
data.push_back(seqNames);
- int nNames = getNumNames(seqNames);
+ int nNames = m->getNumNames(seqNames);
numBins++;
numSeqs += nNames;
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the SharedListVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ m->errorOut(e, "SharedListVector", "push_back");
exit(1);
}
}
output << endl;
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the SharedListVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ m->errorOut(e, "SharedListVector", "print");
exit(1);
}
}
RAbundVector rav;
for(int i=0;i<data.size();i++){
- int binSize = getNumNames(data[i]);
+ int binSize = m->getNumNames(data[i]);
rav.push_back(binSize);
}
return rav;
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the SharedListVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ m->errorOut(e, "SharedListVector", "getRAbundVector");
exit(1);
}
}
SAbundVector sav(maxRank+1);
for(int i=0;i<data.size();i++){
- int binSize = getNumNames(data[i]);
+ int binSize = m->getNumNames(data[i]);
sav.set(binSize, sav.get(binSize) + 1);
}
sav.set(0, 0);
return sav;
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the SharedListVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ m->errorOut(e, "SharedListVector", "getSAbundVector");
exit(1);
}
}
/***********************************************************************/
SharedOrderVector* SharedListVector::getSharedOrderVector(){
try {
- string groupName, names, name;
-
SharedOrderVector* order = new SharedOrderVector();
order->setLabel(label);
for(int i=0;i<numBins;i++){
- int binSize = getNumNames(get(i)); //find number of individual in given bin
- names = get(i);
- while (names.find_first_of(',') != -1) {
- name = names.substr(0,names.find_first_of(','));
- names = names.substr(names.find_first_of(',')+1, names.length());
- groupName = groupmap->getGroup(name);
- order->push_back(i, binSize, groupName); //i represents what bin you are in
+ int binSize = m->getNumNames(get(i)); //find number of individual in given bin
+ string names = get(i);
+ vector<string> 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
+ }else {
+ vector<int> groupAbundances = countTable->getGroupCounts(binNames[i]);
+ vector<string> 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);
- order->push_back(i, binSize, groupName);
}
random_shuffle(order->begin(), order->end());
return order;
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the SharedListVector class function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ m->errorOut(e, "SharedListVector", "getSharedOrderVector");
exit(1);
}
-
}
/***********************************************************************/
SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) {
try {
SharedRAbundVector rav(data.size());
- string group, names, name;
for(int i=0;i<numBins;i++){
- names = get(i);
- while (names.find_first_of(',') != -1) {
- name = names.substr(0,names.find_first_of(','));
- names = names.substr(names.find_first_of(',')+1, names.length());
- group = groupmap->getGroup(name);
- 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 (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<string> 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);
+ }
}
}
rav.setLabel(label);
rav.setGroup(groupName);
+
return rav;
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the SharedListVector class function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ m->errorOut(e, "SharedListVector", "getSharedRAbundVector");
exit(1);
}
}
try {
SharedUtil* util;
util = new SharedUtil();
- vector<SharedRAbundVector*> lookup;
+ vector<SharedRAbundVector*> lookup; //contains just the groups the user selected
+ vector<SharedRAbundVector*> lookupDelete;
+ map<string, SharedRAbundVector*> finder; //contains all groups in groupmap
- util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups);
-
- for (int i = 0; i < globaldata->Groups.size(); i++) {
- SharedRAbundVector* temp = new SharedRAbundVector();
- *temp = getSharedRAbundVector(globaldata->Groups[i]);
- lookup.push_back(temp);
+ vector<string> Groups = m->getGroups();
+ vector<string> 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 < allGroups.size(); i++) {
+ SharedRAbundVector* temp = new SharedRAbundVector(data.size());
+ 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]]);
+ }
+ }
+
+ //fill vectors
+ for(int i=0;i<numBins;i++){
+ string names = get(i);
+ vector<string> 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<int> 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]);
+ }
+ }
+ }
}
+
+ for (int j = 0; j < lookupDelete.size(); j++) { delete lookupDelete[j]; }
return lookup;
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ m->errorOut(e, "SharedListVector", "getSharedRAbundVector");
exit(1);
}
- catch(...) {
- cout << "An unknown error has occurred in the SharedListVector class function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-
}
/***********************************************************************/
return sav;
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the SharedListVector class function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ m->errorOut(e, "SharedListVector", "getSharedSAbundVector");
exit(1);
}
}
OrderVector ov;
for(int i=0;i<data.size();i++){
- int binSize = getNumNames(data[i]);
+ string names = data[i];
+ vector<string> 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<binSize;j++){
ov.push_back(i);
}
for(int i=0;i<data.size();i++){
string listOTU = data[i];
- int length = listOTU.size();
-
- string seqName="";
-
- for(int j=0;j<length;j++){
-
- if(listOTU[j] != ','){
- seqName += listOTU[j];
- }
- else{
- if(orderMap->count(seqName) == 0){
- cerr << seqName << " not found, check *.names file\n";
- exit(1);
- }
-
- ov.set((*orderMap)[seqName], i);
- seqName = "";
- }
- }
-
- if(orderMap->count(seqName) == 0){
- cerr << seqName << " not found, check *.names file\n";
- exit(1);
+ vector<string> 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);
}
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the SharedListVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ m->errorOut(e, "SharedListVector", "getOrderVector");
exit(1);
}
}