+int PhyloSummary::addSeqToTree(string seqTaxonomy, vector<string> names){
+ try {
+ numSeqs++;
+
+ map<string, int>::iterator childPointer;
+
+ int currentNode = 0;
+ string taxon;
+
+ int level = 0;
+
+ //are there confidence scores, if so remove them
+ if (seqTaxonomy.find_first_of('(') != -1) { m->removeConfidences(seqTaxonomy); }
+
+ while (seqTaxonomy != "") {
+
+ if (m->control_pressed) { return 0; }
+
+ //somehow the parent is getting one too many accnos
+ //use print to reassign the taxa id
+ taxon = getNextTaxon(seqTaxonomy);
+
+ childPointer = tree[currentNode].children.find(taxon);
+
+ if(childPointer != tree[currentNode].children.end()){ //if the node already exists, update count and move on
+ if (groupmap != NULL) {
+
+ map<string, bool> containsGroup;
+ vector<string> mGroups = groupmap->getNamesOfGroups();
+ for (int j = 0; j < mGroups.size(); j++) {
+ containsGroup[mGroups[j]] = false;
+ }
+
+ for (int k = 0; k < names.size(); k++) {
+ //find out the sequences group
+ string group = groupmap->getGroup(names[k]);
+
+ if (group == "not found") { m->mothurOut("[WARNING]: " + names[k] + " is not in your groupfile, and will be included in the overall total, but not any group total."); m->mothurOutEndLine(); }
+ else {
+ containsGroup[group] = true;
+ }
+ }
+
+ for (map<string, bool>::iterator itGroup = containsGroup.begin(); itGroup != containsGroup.end(); itGroup++) {
+ if (itGroup->second == true) {
+ tree[childPointer->second].groupCount[itGroup->first]++;
+ }
+ }
+
+ }
+
+ tree[childPointer->second].total++;
+
+ currentNode = childPointer->second;
+ }else{
+ if (ignore) {
+
+ tree.push_back(rawTaxNode(taxon));
+ int index = tree.size() - 1;
+
+ tree[index].parent = currentNode;
+ tree[index].level = (level+1);
+ tree[index].total = 1;
+ tree[currentNode].children[taxon] = index;
+
+ //initialize groupcounts
+ if (groupmap != NULL) {
+ map<string, bool> containsGroup;
+ vector<string> mGroups = groupmap->getNamesOfGroups();
+ for (int j = 0; j < mGroups.size(); j++) {
+ tree[index].groupCount[mGroups[j]] = 0;
+ containsGroup[mGroups[j]] = false;
+ }
+
+
+ for (int k = 0; k < names.size(); k++) {
+ //find out the sequences group
+ string group = groupmap->getGroup(names[k]);
+
+ if (group == "not found") { m->mothurOut("[WARNING]: " + names[k] + " is not in your groupfile, and will be included in the overall total, but not any group total."); m->mothurOutEndLine(); }
+ else {
+ containsGroup[group] = true;
+ }
+ }
+
+ for (map<string, bool>::iterator itGroup = containsGroup.begin(); itGroup != containsGroup.end(); itGroup++) {
+ if (itGroup->second == true) {
+ tree[index].groupCount[itGroup->first]++;
+ }
+ }
+ }
+
+ currentNode = index;
+
+ }else{ //otherwise, error
+ m->mothurOut("Warning: cannot find taxon " + taxon + " in reference taxonomy tree at level " + toString(tree[currentNode].level) + ". This may cause totals of daughter levels not to add up in summary file."); m->mothurOutEndLine();
+ break;
+ }
+ }
+
+ level++;
+
+ if ((seqTaxonomy == "") && (level < maxLevel)) { //if you think you are done and you are not.
+ for (int k = level; k < maxLevel; k++) { seqTaxonomy += "unclassified;"; }
+ }
+ }
+ return 0;