+}
+//**********************************************************************************************************************
+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);
+ }
+
+}
+
+/**************************************************************************************************/
+//returns {Bacteria, Bacteroidetes, ..} and scores is filled with {100, 98, ...} or {null, null, null}
+vector<string> MakeBiomCommand::parseTax(string tax, vector<string>& scores) {
+ try {
+
+ string taxon;
+ vector<string> taxs;
+
+ while (tax.find_first_of(';') != -1) {
+
+ if (m->control_pressed) { return taxs; }
+
+ //get taxon
+ taxon = tax.substr(0,tax.find_first_of(';'));
+
+ int pos = taxon.find_last_of('(');
+ if (pos != -1) {
+ //is it a number?
+ int pos2 = taxon.find_last_of(')');
+ if (pos2 != -1) {
+ string confidenceScore = taxon.substr(pos+1, (pos2-(pos+1)));
+ if (m->isNumeric1(confidenceScore)) {
+ taxon = taxon.substr(0, pos); //rip off confidence
+ scores.push_back(confidenceScore);
+ }else{ scores.push_back("null"); }
+ }
+ }else{ scores.push_back("null"); }
+
+ //strip "" if they are there
+ pos = taxon.find("\"");
+ if (pos != string::npos) {
+ string newTax = "";
+ for (int k = 0; k < taxon.length(); k++) {
+ if (taxon[k] != '\"') { newTax += taxon[k]; }
+ }
+ taxon = newTax;
+ }
+
+ //look for bootstrap value
+ taxs.push_back(taxon);
+ tax = tax.substr(tax.find_first_of(';')+1, tax.length());
+ }
+
+ return taxs;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "MakeBiomCommand", "parseTax");
+ exit(1);
+ }
+}
+