X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=readtreecommand.cpp;h=89efc9abcf0057f68189ddad6975b5e1464fca09;hb=e03de8796670a0c747aed63483daa09c8b86aea0;hp=0a86f36dfdced49cb6151205e82c0372556e1209;hpb=0034e0e7f58987a1e6e0881f5495a4c542842645;p=mothur.git diff --git a/readtreecommand.cpp b/readtreecommand.cpp index 0a86f36..89efc9a 100644 --- a/readtreecommand.cpp +++ b/readtreecommand.cpp @@ -76,8 +76,20 @@ ReadTreeCommand::ReadTreeCommand(string option) { groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { abort = true; } - else if (groupfile == "not found") { groupfile = ""; m->mothurOut("group is a required parameter for the read.tree command."); m->mothurOutEndLine(); abort = true; } - else { + else if (groupfile == "not found") { + groupfile = ""; + + m->mothurOut("You have not provided a group file. I am assumming all sequence are from the same group."); m->mothurOutEndLine(); + + if (treefile != "") { Tree* tree = new Tree(treefile); delete tree; } //extracts names from tree to make faked out groupmap + + globaldata->setGroupFile(groupfile); + //read in group map info. + treeMap = new TreeMap(); + for (int i = 0; i < globaldata->Treenames.size(); i++) { treeMap->addSeq(globaldata->Treenames[i], "Group1"); } + globaldata->gTreemap = treeMap; + + }else { globaldata->setGroupFile(groupfile); //read in group map info. treeMap = new TreeMap(groupfile); @@ -154,46 +166,47 @@ int ReadTreeCommand::execute(){ } -// Sarah, isn't this checking already done when assigning the sequences to the groups? it makes read.tree -// wicked slow... For some reason my tree is coming in here eventhough the number of sequences in the tree -// agrees with the number of lines in the name file and the number of sequences represented by the name file -// agrees with the number of sequences in the group file - - //output any names that are in group file but not in tree + //if you provide a namefile we will use the numNames in the namefile as long as the number of unique match the tree names size. + int numNamesInTree; + if (namefile != "") { + if (numUniquesInName == globaldata->Treenames.size()) { numNamesInTree = nameMap.size(); } + else { numNamesInTree = globaldata->Treenames.size(); } + }else { numNamesInTree = globaldata->Treenames.size(); } -// if (globaldata->Treenames.size() < treeMap->getNumSeqs()) { -// cout << "in here" << endl; -// for (int i = 0; i < treeMap->namesOfSeqs.size(); i++) { -// //is that name in the tree? -// int count = 0; -// for (int j = 0; j < globaldata->Treenames.size(); j++) { -// if (treeMap->namesOfSeqs[i] == globaldata->Treenames[j]) { break; } //found it -// count++; -// } -// -// if (m->control_pressed) { -// for (int i = 0; i < T.size(); i++) { delete T[i]; } -// globaldata->gTree.clear(); -// delete globaldata->gTreemap; -// return 0; -// } -// -// //then you did not find it so report it -// if (count == globaldata->Treenames.size()) { -// //if it is in your namefile then don't remove -// map::iterator it = nameMap.find(treeMap->namesOfSeqs[i]); -// -// if (it == nameMap.end()) { -// m->mothurOut(treeMap->namesOfSeqs[i] + " is in your groupfile and not in your tree. It will be disregarded."); m->mothurOutEndLine(); -// treeMap->removeSeq(treeMap->namesOfSeqs[i]); -// i--; //need this because removeSeq removes name from namesOfSeqs -// } -// } -// } -// -// globaldata->gTreemap = treeMap; -// } + //output any names that are in group file but not in tree + if (numNamesInTree < treeMap->getNumSeqs()) { + for (int i = 0; i < treeMap->namesOfSeqs.size(); i++) { + //is that name in the tree? + int count = 0; + for (int j = 0; j < globaldata->Treenames.size(); j++) { + if (treeMap->namesOfSeqs[i] == globaldata->Treenames[j]) { break; } //found it + count++; + } + + if (m->control_pressed) { + for (int i = 0; i < T.size(); i++) { delete T[i]; } + globaldata->gTree.clear(); + delete globaldata->gTreemap; + return 0; + } + + //then you did not find it so report it + if (count == globaldata->Treenames.size()) { + //if it is in your namefile then don't remove + map::iterator it = nameMap.find(treeMap->namesOfSeqs[i]); + + if (it == nameMap.end()) { + m->mothurOut(treeMap->namesOfSeqs[i] + " is in your groupfile and not in your tree. It will be disregarded."); m->mothurOutEndLine(); + treeMap->removeSeq(treeMap->namesOfSeqs[i]); + i--; //need this because removeSeq removes name from namesOfSeqs + } + } + } + + globaldata->gTreemap = treeMap; + } + return 0; } catch(exception& e) { @@ -205,6 +218,7 @@ int ReadTreeCommand::execute(){ int ReadTreeCommand::readNamesFile() { try { globaldata->names.clear(); + numUniquesInName = 0; ifstream in; m->openInputFile(namefile, in); @@ -215,6 +229,8 @@ int ReadTreeCommand::readNamesFile() { while(!in.eof()) { in >> first >> second; m->gobble(in); + numUniquesInName++; + itNames = globaldata->names.find(first); if (itNames == globaldata->names.end()) { globaldata->names[first] = second; @@ -223,8 +239,8 @@ int ReadTreeCommand::readNamesFile() { vector dupNames; m->splitAtComma(second, dupNames); - for (int i = 0; i < dupNames.size(); i++) { nameMap[dupNames[i]] = dupNames[i]; } - }else { m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); globaldata->names.clear(); return 1; } + for (int i = 0; i < dupNames.size(); i++) { nameMap[dupNames[i]] = dupNames[i]; if ((groupfile == "") && (i != 0)) { globaldata->gTreemap->addSeq(dupNames[i], "Group1"); } } + }else { m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); globaldata->names.clear(); namefile = ""; return 1; } } in.close();