+//**********************************************************************************************************************
+int MakeBiomCommand::getSampleMetaData(vector<SharedRAbundVector*>& lookup){
+ try {
+
+ if (metadatafile == "") { for (int i = 0; i < lookup.size(); i++) { sampleMetadata.push_back("null"); } }
+ else {
+ ifstream in;
+ m->openInputFile(metadatafile, in);
+
+ vector<string> groupNames, metadataLabels;
+ map<string, vector<string> > lines;
+
+ string headerLine = m->getline(in); m->gobble(in);
+ vector<string> pieces = m->splitWhiteSpace(headerLine);
+
+ //save names of columns you are reading
+ for (int i = 1; i < pieces.size(); i++) {
+ metadataLabels.push_back(pieces[i]);
+ }
+ int count = metadataLabels.size();
+
+ vector<string> groups = m->getGroups();
+
+ //read rest of file
+ while (!in.eof()) {
+
+ if (m->control_pressed) { in.close(); return 0; }
+
+ string group = "";
+ in >> group; m->gobble(in);
+ groupNames.push_back(group);
+
+ string line = m->getline(in); m->gobble(in);
+ vector<string> thisPieces = m->splitWhiteSpaceWithQuotes(line);
+
+ if (thisPieces.size() != count) { m->mothurOut("[ERROR]: expected " + toString(count) + " items of data for sample " + group + " read " + toString(thisPieces.size()) + ", quitting.\n"); }
+ else { if (m->inUsersGroups(group, groups)) { lines[group] = thisPieces; } }
+
+ m->gobble(in);
+ }
+ in.close();
+
+ map<string, vector<string> >::iterator it;
+ for (int i = 0; i < lookup.size(); i++) {
+
+ if (m->control_pressed) { return 0; }
+
+ it = lines.find(lookup[i]->getGroup());
+
+ if (it == lines.end()) { m->mothurOut("[ERROR]: can't find metadata information for " + lookup[i]->getGroup() + ", quitting.\n"); m->control_pressed = true; }
+ else {
+ vector<string> values = it->second;
+
+ string data = "{";
+ for (int j = 0; j < metadataLabels.size()-1; j++) {
+ values[j] = m->removeQuotes(values[j]);
+ data += "\"" + metadataLabels[j] + "\":\"" + values[j] + "\", ";
+ }
+ values[metadataLabels.size()-1] = m->removeQuotes(values[metadataLabels.size()-1]);
+ data += "\"" + metadataLabels[metadataLabels.size()-1] + "\":\"" + values[metadataLabels.size()-1] + "\"}";
+ sampleMetadata.push_back(data);
+ }
+ }
+ }
+
+ return 0;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "MakeBiomCommand", "getSampleMetaData");
+ exit(1);
+ }
+
+}
+