+int OTUAssociationCommand::readMetadata(){
+ try {
+ ifstream in;
+ m->openInputFile(metadatafile, in);
+
+ string headerLine = m->getline(in); m->gobble(in);
+ istringstream iss (headerLine,istringstream::in);
+
+ //read the first label, because it refers to the groups
+ string columnLabel;
+ iss >> columnLabel; m->gobble(iss);
+
+ //save names of columns you are reading
+ while (!iss.eof()) {
+ iss >> columnLabel; m->gobble(iss);
+ metadataLabels.push_back(columnLabel);
+ }
+ int count = metadataLabels.size();
+
+ //read rest of file
+ while (!in.eof()) {
+
+ if (m->control_pressed) { in.close(); return 0; }
+
+ string group = "";
+ in >> group; m->gobble(in);
+
+ SharedRAbundFloatVector* tempLookup = new SharedRAbundFloatVector();
+ tempLookup->setGroup(group);
+ tempLookup->setLabel("1");
+
+ for (int i = 0; i < count; i++) {
+ float temp = 0.0;
+ in >> temp;
+ tempLookup->push_back(temp, group);
+ }
+
+ metadataLookup.push_back(tempLookup);
+
+ m->gobble(in);
+ }
+ in.close();
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "OTUAssociationCommand", "readMetadata");
+ exit(1);
+ }
+}
+/*****************************************************************/
+//eliminate groups user did not pick, remove zeroed out otus, fill metadata vector.
+int OTUAssociationCommand::getMetadata(){
+ try {
+
+ vector<string> mGroups = m->getGroups();
+
+ bool remove = false;
+ for (int i = 0; i < metadataLookup.size(); i++) {
+ //if this sharedrabund is not from a group the user wants then delete it.
+ if (!(m->inUsersGroups(metadataLookup[i]->getGroup(), mGroups))) {
+ delete metadataLookup[i]; metadataLookup[i] = NULL;
+ metadataLookup.erase(metadataLookup.begin()+i);
+ i--;
+ remove = true;
+ }
+ }
+
+ vector<SharedRAbundFloatVector*> newLookup;
+ for (int i = 0; i < metadataLookup.size(); i++) {
+ SharedRAbundFloatVector* temp = new SharedRAbundFloatVector();
+ temp->setLabel(metadataLookup[i]->getLabel());
+ temp->setGroup(metadataLookup[i]->getGroup());
+ newLookup.push_back(temp);
+ }
+
+ //for each bin
+ vector<string> newBinLabels;
+ for (int i = 0; i < metadataLookup[0]->getNumBins(); i++) {
+ if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; }
+
+ //look at each sharedRabund and make sure they are not all zero
+ bool allZero = true;
+ for (int j = 0; j < metadataLookup.size(); j++) {
+ if (metadataLookup[j]->getAbundance(i) != 0) { allZero = false; break; }
+ }
+
+ //if they are not all zero add this bin
+ if (!allZero) {
+ for (int j = 0; j < metadataLookup.size(); j++) {
+ newLookup[j]->push_back(metadataLookup[j]->getAbundance(i), metadataLookup[j]->getGroup());
+ }
+ newBinLabels.push_back(metadataLabels[i]);
+ }
+ }
+
+ metadataLabels = newBinLabels;
+
+ for (int j = 0; j < metadataLookup.size(); j++) { delete metadataLookup[j]; }
+ metadataLookup.clear();
+
+ metadata.resize(newLookup[0]->getNumBins());
+ for (int i = 0; i < newLookup[0]->getNumBins(); i++) { for (int j = 0; j < newLookup.size(); j++) { metadata[i].push_back(newLookup[j]->getAbundance(i)); } }
+
+ for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; }
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "OTUAssociationCommand", "getMetadata");
+ exit(1);
+ }
+}
+/*****************************************************************/