5 // Created by Sarah Westcott on 4/16/12.
6 // Copyright (c) 2012 Schloss Lab. All rights reserved.
9 #include "makebiomcommand.h"
10 #include "sharedrabundvector.h"
11 #include "inputdata.h"
12 #include "sharedutilities.h"
14 //taken from http://biom-format.org/documentation/biom_format.html
18 "format": "Biological Observation Matrix 0.9.1",
19 "format_url": "http://biom-format.org",
21 "generated_by": "QIIME revision 1.4.0-dev",
22 "date": "2011-12-19T19:00:00",
24 {"id":"GG_OTU_1", "metadata":null},
25 {"id":"GG_OTU_2", "metadata":null},
26 {"id":"GG_OTU_3", "metadata":null},
27 {"id":"GG_OTU_4", "metadata":null},
28 {"id":"GG_OTU_5", "metadata":null}
31 {"id":"Sample1", "metadata":null},
32 {"id":"Sample2", "metadata":null},
33 {"id":"Sample3", "metadata":null},
34 {"id":"Sample4", "metadata":null},
35 {"id":"Sample5", "metadata":null},
36 {"id":"Sample6", "metadata":null}
38 "matrix_type": "sparse",
39 "matrix_element_type": "int",
62 "format": "Biological Observation Matrix 0.9.1",
63 "format_url": "http://biom-format.org",
65 "generated_by": "QIIME revision 1.4.0-dev",
66 "date": "2011-12-19T19:00:00",
68 {"id":"GG_OTU_1", "metadata":null},
69 {"id":"GG_OTU_2", "metadata":null},
70 {"id":"GG_OTU_3", "metadata":null},
71 {"id":"GG_OTU_4", "metadata":null},
72 {"id":"GG_OTU_5", "metadata":null}
75 {"id":"Sample1", "metadata":null},
76 {"id":"Sample2", "metadata":null},
77 {"id":"Sample3", "metadata":null},
78 {"id":"Sample4", "metadata":null},
79 {"id":"Sample5", "metadata":null},
80 {"id":"Sample6", "metadata":null}
82 "matrix_type": "dense",
83 "matrix_element_type": "int",
85 "data": [[0,0,1,0,0,0],
92 //**********************************************************************************************************************
93 vector<string> MakeBiomCommand::setParameters(){
95 CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared);
96 CommandParameter pcontaxonomy("contaxonomy", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pcontaxonomy);
97 CommandParameter pmetadata("metadata", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pmetadata);
98 CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
99 CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
100 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
101 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
102 CommandParameter pmatrixtype("matrixtype", "Multiple", "sparse-dense", "sparse", "", "", "",false,false); parameters.push_back(pmatrixtype);
104 vector<string> myArray;
105 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
108 catch(exception& e) {
109 m->errorOut(e, "MakeBiomCommand", "setParameters");
113 //**********************************************************************************************************************
114 string MakeBiomCommand::getHelpString(){
116 string helpString = "";
117 helpString += "The make.biom command parameters are shared, contaxonomy, metadata, groups, matrixtype and label. shared is required, unless you have a valid current file.\n";
118 helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like included. The group names are separated by dashes.\n";
119 helpString += "The label parameter allows you to select what distance levels you would like, and are also separated by dashes.\n";
120 helpString += "The matrixtype parameter allows you to select what type you would like to make. Choices are sparse and dense, default is sparse.\n";
121 helpString += "The contaxonomy file is the taxonomy file outputted by classify.otu(list=yourListfile, taxonomy=yourTaxonomyFile). Be SURE that the you are the constaxonomy file distance matches the shared file distance. ie, for *.0.03.cons.taxonomy set label=0.03. Mothur is smart enough to handle shared files that have been subsampled. It is used to assign taxonomy information to the metadata of rows.\n";
122 helpString += "The metadata parameter is used to provide experimental parameters to the columns. Things like 'sample1 gut human_gut'. \n";
123 helpString += "The make.biom command should be in the following format: make.biom(shared=yourShared, groups=yourGroups, label=yourLabels).\n";
124 helpString += "Example make.biom(shared=abrecovery.an.shared, groups=A-B-C).\n";
125 helpString += "The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n";
126 helpString += "The make.biom command outputs a .biom file.\n";
127 helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n";
130 catch(exception& e) {
131 m->errorOut(e, "MakeBiomCommand", "getHelpString");
135 //**********************************************************************************************************************
136 string MakeBiomCommand::getOutputFileNameTag(string type, string inputName=""){
138 string outputFileName = "";
139 map<string, vector<string> >::iterator it;
141 //is this a type this command creates
142 it = outputTypes.find(type);
143 if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
145 if (type == "biom") { outputFileName = "biom"; }
146 else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; }
148 return outputFileName;
150 catch(exception& e) {
151 m->errorOut(e, "MakeBiomCommand", "getOutputFileNameTag");
156 //**********************************************************************************************************************
157 MakeBiomCommand::MakeBiomCommand(){
159 abort = true; calledHelp = true;
161 vector<string> tempOutNames;
162 outputTypes["biom"] = tempOutNames;
164 catch(exception& e) {
165 m->errorOut(e, "MakeBiomCommand", "MakeBiomCommand");
169 //**********************************************************************************************************************
170 MakeBiomCommand::MakeBiomCommand(string option) {
172 abort = false; calledHelp = false;
175 //allow user to run help
176 if(option == "help") { help(); abort = true; calledHelp = true; }
177 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
180 vector<string> myArray = setParameters();
182 OptionParser parser(option);
183 map<string,string> parameters = parser.getParameters();
184 map<string,string>::iterator it;
186 ValidParameters validParameter;
188 //check to make sure all parameters are valid for command
189 for (it = parameters.begin(); it != parameters.end(); it++) {
190 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
193 //initialize outputTypes
194 vector<string> tempOutNames;
195 outputTypes["biom"] = tempOutNames;
197 //if the user changes the input directory command factory will send this info to us in the output parameter
198 string inputDir = validParameter.validFile(parameters, "inputdir", false);
199 if (inputDir == "not found"){ inputDir = ""; }
202 it = parameters.find("shared");
203 //user has given a template file
204 if(it != parameters.end()){
205 path = m->hasPath(it->second);
206 //if the user has not given a path then, add inputdir. else leave path alone.
207 if (path == "") { parameters["shared"] = inputDir + it->second; }
210 it = parameters.find("contaxonomy");
211 //user has given a template file
212 if(it != parameters.end()){
213 path = m->hasPath(it->second);
214 //if the user has not given a path then, add inputdir. else leave path alone.
215 if (path == "") { parameters["contaxonomy"] = inputDir + it->second; }
218 it = parameters.find("metadata");
219 //user has given a template file
220 if(it != parameters.end()){
221 path = m->hasPath(it->second);
222 //if the user has not given a path then, add inputdir. else leave path alone.
223 if (path == "") { parameters["metadata"] = inputDir + it->second; }
228 sharedfile = validParameter.validFile(parameters, "shared", true);
229 if (sharedfile == "not open") { sharedfile = ""; abort = true; }
230 else if (sharedfile == "not found") {
231 //if there is a current shared file, use it
232 sharedfile = m->getSharedFile();
233 if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
234 else { m->mothurOut("You have no current sharedfile and the shared parameter is required."); m->mothurOutEndLine(); abort = true; }
235 }else { m->setSharedFile(sharedfile); }
238 //if the user changes the output directory command factory will send this info to us in the output parameter
239 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(sharedfile); }
241 contaxonomyfile = validParameter.validFile(parameters, "contaxonomy", true);
242 if (contaxonomyfile == "not found") { contaxonomyfile = ""; }
243 else if (contaxonomyfile == "not open") { contaxonomyfile = ""; abort = true; }
245 metadatafile = validParameter.validFile(parameters, "metadata", true);
246 if (metadatafile == "not found") { metadatafile = ""; }
247 else if (metadatafile == "not open") { metadatafile = ""; abort = true; }
249 //check for optional parameter and set defaults
250 // ...at some point should added some additional type checking...
251 label = validParameter.validFile(parameters, "label", false);
252 if (label == "not found") { label = ""; }
254 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
255 else { allLines = 1; }
258 groups = validParameter.validFile(parameters, "groups", false);
259 if (groups == "not found") { groups = ""; }
261 m->splitAtDash(groups, Groups);
262 m->setGroups(Groups);
265 if ((contaxonomyfile != "") && (labels.size() > 1)) { m->mothurOut("[ERROR]: the contaxonomy parameter cannot be used with multiple labels."); m->mothurOutEndLine(); abort = true; }
267 format = validParameter.validFile(parameters, "matrixtype", false); if (format == "not found") { format = "sparse"; }
269 if ((format != "sparse") && (format != "dense")) {
270 m->mothurOut(format + " is not a valid option for the matrixtype parameter. Options are sparse and dense."); m->mothurOutEndLine(); abort = true;
275 catch(exception& e) {
276 m->errorOut(e, "MakeBiomCommand", "MakeBiomCommand");
280 //**********************************************************************************************************************
282 int MakeBiomCommand::execute(){
285 if (abort == true) { if (calledHelp) { return 0; } return 2; }
287 InputData input(sharedfile, "sharedfile");
288 vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
289 string lastLabel = lookup[0]->getLabel();
291 //if user did not specify a label, then use first one
292 if ((contaxonomyfile != "") && (labels.size() == 0)) {
294 labels.insert(lastLabel);
297 getSampleMetaData(lookup);
299 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
300 set<string> processedLabels;
301 set<string> userLabels = labels;
303 //as long as you are not at the end of the file or done wih the lines you want
304 while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
306 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; }
308 if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
310 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
313 processedLabels.insert(lookup[0]->getLabel());
314 userLabels.erase(lookup[0]->getLabel());
317 if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
318 string saveLabel = lookup[0]->getLabel();
320 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
321 lookup = input.getSharedRAbundVectors(lastLabel);
322 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
326 processedLabels.insert(lookup[0]->getLabel());
327 userLabels.erase(lookup[0]->getLabel());
329 //restore real lastlabel to save below
330 lookup[0]->setLabel(saveLabel);
333 lastLabel = lookup[0]->getLabel();
335 //prevent memory leak and get next set
336 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; }
337 lookup = input.getSharedRAbundVectors();
340 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
342 //output error messages about any remaining user labels
343 set<string>::iterator it;
344 bool needToRun = false;
345 for (it = userLabels.begin(); it != userLabels.end(); it++) {
346 m->mothurOut("Your file does not include the label " + *it);
347 if (processedLabels.count(lastLabel) != 1) {
348 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
351 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
355 //run last label if you need to
356 if (needToRun == true) {
357 for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } }
358 lookup = input.getSharedRAbundVectors(lastLabel);
360 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
363 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
366 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
368 //set sabund file as new current sabundfile
370 itTypes = outputTypes.find("biom");
371 if (itTypes != outputTypes.end()) {
372 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setBiomFile(current); }
376 m->mothurOutEndLine();
377 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
378 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
379 m->mothurOutEndLine();
383 catch(exception& e) {
384 m->errorOut(e, "MakeBiomCommand", "execute");
388 //**********************************************************************************************************************
389 int MakeBiomCommand::getBiom(vector<SharedRAbundVector*>& lookup){
392 string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + lookup[0]->getLabel() + "." + getOutputFileNameTag("biom");
394 m->openOutputFile(outputFileName, out);
395 outputNames.push_back(outputFileName); outputTypes["biom"].push_back(outputFileName);
397 string mothurString = "mothur" + toString(m->getVersion());
399 struct tm * timeinfo;
401 timeinfo = localtime ( &rawtime );
402 string dateString = asctime (timeinfo);
403 int pos = dateString.find('\n');
404 if (pos != string::npos) { dateString = dateString.substr(0, pos);}
408 out << "{\n" + spaces + "\"id\":\"" + sharedfile + "-" + lookup[0]->getLabel() + "\",\n" + spaces + "\"format\": \"Biological Observation Matrix 0.9.1\",\n" + spaces + "\"format_url\": \"http://biom-format.org\",\n";
409 out << spaces + "\"type\": \"OTU table\",\n" + spaces + "\"generated_by\": \"" << mothurString << "\",\n" + spaces + "\"date\": \"" << dateString << "\",\n";
411 vector<string> metadata = getMetaData(lookup);
413 if (m->control_pressed) { out.close(); return 0; }
417 {"id":"GG_OTU_1", "metadata":null},
418 {"id":"GG_OTU_2", "metadata":null},
419 {"id":"GG_OTU_3", "metadata":null},
420 {"id":"GG_OTU_4", "metadata":null},
421 {"id":"GG_OTU_5", "metadata":null}
423 out << spaces + "\"rows\":[\n";
424 string rowFront = spaces + spaces + "{\"id\":\"";
425 string rowBack = "\", \"metadata\":";
426 for (int i = 0; i < m->currentBinLabels.size()-1; i++) {
427 if (m->control_pressed) { out.close(); return 0; }
428 out << rowFront << m->currentBinLabels[i] << rowBack << metadata[i] << "},\n";
430 out << rowFront << m->currentBinLabels[(m->currentBinLabels.size()-1)] << rowBack << metadata[(m->currentBinLabels.size()-1)] << "}\n" + spaces + "],\n";
434 {"id":"Sample1", "metadata":null},
435 {"id":"Sample2", "metadata":null},
436 {"id":"Sample3", "metadata":null},
437 {"id":"Sample4", "metadata":null},
438 {"id":"Sample5", "metadata":null},
439 {"id":"Sample6", "metadata":null}
442 string colBack = "\", \"metadata\":";
443 out << spaces + "\"columns\":[\n";
444 for (int i = 0; i < lookup.size()-1; i++) {
445 if (m->control_pressed) { out.close(); return 0; }
446 out << rowFront << lookup[i]->getGroup() << colBack << sampleMetadata[i] << "},\n";
448 out << rowFront << lookup[(lookup.size()-1)]->getGroup() << colBack << sampleMetadata[lookup.size()-1] << "}\n" + spaces + "],\n";
450 out << spaces + "\"matrix_type\": \"" << format << "\",\n" + spaces + "\"matrix_element_type\": \"int\",\n";
451 out << spaces + "\"shape\": [" << m->currentBinLabels.size() << "," << lookup.size() << "],\n";
452 out << spaces + "\"data\": [";
454 vector<string> dataRows;
455 if (format == "sparse") {
473 for (int i = 0; i < lookup[0]->getNumBins(); i++) {
475 if (m->control_pressed) { out.close(); return 0; }
477 for (int j = 0; j < lookup.size(); j++) {
478 string binInfo = "[" + toString(i) + "," + toString(j) + "," + toString(lookup[j]->getAbundance(i)) + "]";
479 //only print non zero values
480 if (lookup[j]->getAbundance(i) != 0) { dataRows.push_back(binInfo); }
485 /* "matrix_type": "dense",
486 "matrix_element_type": "int",
488 "data": [[0,0,1,0,0,0],
494 for (int i = 0; i < lookup[0]->getNumBins(); i++) {
496 if (m->control_pressed) { out.close(); return 0; }
498 string binInfo = "[";
499 for (int j = 0; j < lookup.size()-1; j++) {
500 binInfo += toString(lookup[j]->getAbundance(i)) + ",";
502 binInfo += toString(lookup[lookup.size()-1]->getAbundance(i)) + "]";
503 dataRows.push_back(binInfo);
507 for (int i = 0; i < dataRows.size()-1; i++) {
508 out << dataRows[i] << ",\n" + spaces + spaces;
510 out << dataRows[dataRows.size()-1] << "]\n";
517 catch(exception& e) {
518 m->errorOut(e, "MakeBiomCommand", "getBiom");
522 //**********************************************************************************************************************
523 vector<string> MakeBiomCommand::getMetaData(vector<SharedRAbundVector*>& lookup){
525 vector<string> metadata;
527 if (contaxonomyfile == "") { for (int i = 0; i < lookup[0]->getNumBins(); i++) { metadata.push_back("null"); } }
530 //read constaxonomy file storing in a map, otulabel -> taxonomy
531 //constaxonomy file will most likely contain more labels than the shared file, because sharedfile could have been subsampled.
533 m->openInputFile(contaxonomyfile, in);
536 m->getline(in); m->gobble(in);
538 string otuLabel, tax;
540 vector<string> otuLabels;
544 if (m->control_pressed) { in.close(); return metadata; }
546 in >> otuLabel >> size >> tax; m->gobble(in);
548 otuLabels.push_back(otuLabel);
553 //should the labels be Otu001 or PhyloType001
554 string firstBin = m->currentBinLabels[0];
555 string binTag = "Otu";
556 if ((firstBin.find("Otu")) == string::npos) { binTag = "PhyloType"; }
558 //convert list file bin labels to shared file bin labels
561 map<string, string> labelTaxMap;
562 string snumBins = toString(otuLabels.size());
563 for (int i = 0; i < otuLabels.size(); i++) {
565 if (m->control_pressed) { return metadata; }
567 //if there is a bin label use it otherwise make one
568 if (m->isContainingOnlyDigits(otuLabels[i])) {
569 string binLabel = binTag;
570 string sbinNumber = otuLabels[i];
571 if (sbinNumber.length() < snumBins.length()) {
572 int diff = snumBins.length() - sbinNumber.length();
573 for (int h = 0; h < diff; h++) { binLabel += "0"; }
575 binLabel += sbinNumber;
576 labelTaxMap[binLabel] = taxs[i];
577 }else { labelTaxMap[otuLabels[i]] = taxs[i]; }
581 //{"taxonomy":["k__Bacteria", "p__Proteobacteria", "c__Gammaproteobacteria", "o__Enterobacteriales", "f__Enterobacteriaceae", "g__Escherichia", "s__"]}
583 //traverse the binLabels forming the metadata strings and saving them
584 //make sure to sanity check
585 map<string, string>::iterator it;
586 for (int i = 0; i < m->currentBinLabels.size(); i++) {
588 if (m->control_pressed) { return metadata; }
590 it = labelTaxMap.find(m->currentBinLabels[i]);
592 if (it == labelTaxMap.end()) { m->mothurOut("[ERROR]: can't find taxonomy information for " + m->currentBinLabels[i] + ".\n"); m->control_pressed = true; }
594 vector<string> bootstrapValues;
595 string data = "{\"taxonomy\":[";
597 vector<string> scores;
598 vector<string> taxonomies = parseTax(it->second, scores);
600 for (int j = 0; j < taxonomies.size()-1; j ++) { data += "\"" + taxonomies[j] + "\", "; }
601 data += "\"" + taxonomies[taxonomies.size()-1] + "\"]";
603 //add bootstrap values if available
604 if (scores[0] != "null") {
605 data += ", \"bootstrap\":[";
607 for (int j = 0; j < scores.size()-1; j ++) { data += scores[j] + ", "; }
608 data += scores[scores.size()-1] + "]";
613 metadata.push_back(data);
621 catch(exception& e) {
622 m->errorOut(e, "MakeBiomCommand", "getMetadata");
627 //**********************************************************************************************************************
628 int MakeBiomCommand::getSampleMetaData(vector<SharedRAbundVector*>& lookup){
631 if (metadatafile == "") { for (int i = 0; i < lookup.size(); i++) { sampleMetadata.push_back("null"); } }
634 m->openInputFile(metadatafile, in);
636 vector<string> groupNames, metadataLabels;
637 map<string, vector<string> > lines;
639 string headerLine = m->getline(in); m->gobble(in);
640 vector<string> pieces = m->splitWhiteSpace(headerLine);
642 //save names of columns you are reading
643 for (int i = 1; i < pieces.size(); i++) {
644 metadataLabels.push_back(pieces[i]);
646 int count = metadataLabels.size();
648 vector<string> groups = m->getGroups();
653 if (m->control_pressed) { in.close(); return 0; }
656 in >> group; m->gobble(in);
657 groupNames.push_back(group);
659 string line = m->getline(in); m->gobble(in);
660 vector<string> thisPieces = m->splitWhiteSpaceWithQuotes(line);
662 if (thisPieces.size() != count) { m->mothurOut("[ERROR]: expected " + toString(count) + " items of data for sample " + group + " read " + toString(thisPieces.size()) + ", quitting.\n"); }
663 else { if (m->inUsersGroups(group, groups)) { lines[group] = thisPieces; } }
669 map<string, vector<string> >::iterator it;
670 for (int i = 0; i < lookup.size(); i++) {
672 if (m->control_pressed) { return 0; }
674 it = lines.find(lookup[i]->getGroup());
676 if (it == lines.end()) { m->mothurOut("[ERROR]: can't find metadata information for " + lookup[i]->getGroup() + ", quitting.\n"); m->control_pressed = true; }
678 vector<string> values = it->second;
681 for (int j = 0; j < metadataLabels.size()-1; j++) {
682 values[j] = m->removeQuotes(values[j]);
683 data += "\"" + metadataLabels[j] + "\":\"" + values[j] + "\", ";
685 values[metadataLabels.size()-1] = m->removeQuotes(values[metadataLabels.size()-1]);
686 data += "\"" + metadataLabels[metadataLabels.size()-1] + "\":\"" + values[metadataLabels.size()-1] + "\"}";
687 sampleMetadata.push_back(data);
695 catch(exception& e) {
696 m->errorOut(e, "MakeBiomCommand", "getSampleMetaData");
702 /**************************************************************************************************/
703 //returns {Bacteria, Bacteroidetes, ..} and scores is filled with {100, 98, ...} or {null, null, null}
704 vector<string> MakeBiomCommand::parseTax(string tax, vector<string>& scores) {
710 while (tax.find_first_of(';') != -1) {
712 if (m->control_pressed) { return taxs; }
715 taxon = tax.substr(0,tax.find_first_of(';'));
717 int pos = taxon.find_last_of('(');
720 int pos2 = taxon.find_last_of(')');
722 string confidenceScore = taxon.substr(pos+1, (pos2-(pos+1)));
723 if (m->isNumeric1(confidenceScore)) {
724 taxon = taxon.substr(0, pos); //rip off confidence
725 scores.push_back(confidenceScore);
726 }else{ scores.push_back("null"); }
728 }else{ scores.push_back("null"); }
730 //strip "" if they are there
731 pos = taxon.find("\"");
732 if (pos != string::npos) {
734 for (int k = 0; k < taxon.length(); k++) {
735 if (taxon[k] != '\"') { newTax += taxon[k]; }
740 //look for bootstrap value
741 taxs.push_back(taxon);
742 tax = tax.substr(tax.find_first_of(';')+1, tax.length());
747 catch(exception& e) {
748 m->errorOut(e, "MakeBiomCommand", "parseTax");
753 //**********************************************************************************************************************