X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=readtree.cpp;h=be7dc79509abbc78aeeb0a66ab45ca57b0d1324a;hb=ca9ac1d80c62f57270b0dcd49410ebe08a8aecd6;hp=e8aeacc4431688ca0dfc8f94bf546c1fea2a91dd;hpb=7762fd5ec7582a78a31bb690a5c05b76e5b899c2;p=mothur.git diff --git a/readtree.cpp b/readtree.cpp index e8aeacc..be7dc79 100644 --- a/readtree.cpp +++ b/readtree.cpp @@ -12,9 +12,7 @@ /***********************************************************************/ ReadTree::ReadTree() { try { - globaldata = GlobalData::getInstance(); m = MothurOut::getInstance(); - globaldata->gTree.clear(); } catch(exception& e) { m->errorOut(e, "ReadTree", "ReadTree"); @@ -22,6 +20,21 @@ ReadTree::ReadTree() { } } /***********************************************************************/ +int ReadTree::AssembleTrees() { + try { + //assemble users trees + for (int i = 0; i < Trees.size(); i++) { + if (m->control_pressed) { return 0; } + Trees[i]->assembleTree(); + } + return 0; + } + catch(exception& e) { + m->errorOut(e, "ReadTree", "AssembleTrees"); + exit(1); + } +} +/***********************************************************************/ int ReadTree::readSpecialChar(istream& f, char c, string name) { try { @@ -94,7 +107,7 @@ float ReadTree::readBranchLength(istream& f) { /***********************************************************************/ //This class reads a file in Newick form and stores it in a tree. -int ReadNewickTree::read() { +int ReadNewickTree::read(TreeMap* tmap) { try { holder = ""; int c, error; @@ -116,23 +129,23 @@ int ReadNewickTree::read() { } //make new tree - T = new Tree(); + T = new Tree(tmap); numNodes = T->getNumNodes(); numLeaves = T->getNumLeaves(); - error = readTreeString(); + error = readTreeString(tmap); //save trees for later commands - globaldata->gTree.push_back(T); + Trees.push_back(T); m->gobble(filehandle); } //if you are a nexus file }else if ((c = filehandle.peek()) == '#') { //get right number of seqs from nexus file. - Tree* temp = new Tree(); delete temp; + Tree* temp = new Tree(tmap); delete temp; - nexusTranslation(); //reads file through the translation and updates treemap + nexusTranslation(tmap); //reads file through the translation and updates treemap while((c = filehandle.peek()) != EOF) { // get past comments while ((c = filehandle.peek()) != EOF) { @@ -153,15 +166,15 @@ int ReadNewickTree::read() { filehandle.putback(c); //put back first ( of tree. //make new tree - T = new Tree(); + T = new Tree(tmap); numNodes = T->getNumNodes(); numLeaves = T->getNumLeaves(); //read tree info - error = readTreeString(); + error = readTreeString(tmap); //save trees for later commands - globaldata->gTree.push_back(T); + Trees.push_back(T); } } @@ -178,11 +191,11 @@ int ReadNewickTree::read() { } /**************************************************************************************************/ //This function read the file through the translation of the sequences names and updates treemap. -string ReadNewickTree::nexusTranslation() { +string ReadNewickTree::nexusTranslation(TreeMap* tmap) { try { holder = ""; - int numSeqs = globaldata->Treenames.size(); //must save this some when we clear old names we can still know how many sequences there were + int numSeqs = m->Treenames.size(); //must save this some when we clear old names we can still know how many sequences there were int comment = 0; // get past comments @@ -198,7 +211,7 @@ string ReadNewickTree::nexusTranslation() { } //update treemap - globaldata->gTreemap->namesOfSeqs.clear(); + tmap->namesOfSeqs.clear(); /*char c; string number, name; @@ -217,7 +230,7 @@ string ReadNewickTree::nexusTranslation() { if (lastChar == ',') { name.erase(name.end()-1); } //erase the comma */ - cout << "numseqs = " << numSeqs << endl; + string number, name; for(int i=0;igTreemap->getGroup(name); - globaldata->gTreemap->treemap[toString(number)].groupname = group; - globaldata->gTreemap->treemap[toString(number)].vectorIndex = globaldata->gTreemap->getIndex(name); + string group = tmap->getGroup(name); + tmap->treemap[toString(number)].groupname = group; + tmap->treemap[toString(number)].vectorIndex = tmap->getIndex(name); //erase old one. so treemap[sarah].groupnumber is now treemap[1].groupnumber. if number is 1 and name is sarah. - globaldata->gTreemap->treemap.erase(name); - globaldata->gTreemap->namesOfSeqs.push_back(number); + tmap->treemap.erase(name); + tmap->namesOfSeqs.push_back(number); } return name; @@ -243,7 +256,7 @@ string ReadNewickTree::nexusTranslation() { } /**************************************************************************************************/ -int ReadNewickTree::readTreeString() { +int ReadNewickTree::readTreeString(TreeMap* tmap) { try { int n = 0; @@ -256,7 +269,7 @@ int ReadNewickTree::readTreeString() { if(ch == '('){ n = numLeaves; //number of leaves / sequences, we want node 1 to start where the leaves left off - lc = readNewickInt(filehandle, n, T); + lc = readNewickInt(filehandle, n, T, tmap); if (lc == -1) { m->mothurOut("error with lc"); m->mothurOutEndLine(); return -1; } //reports an error in reading if(filehandle.peek()==','){ @@ -268,7 +281,7 @@ int ReadNewickTree::readTreeString() { } if(rooted != 1){ - rc = readNewickInt(filehandle, n, T); + rc = readNewickInt(filehandle, n, T, tmap); if (rc == -1) { m->mothurOut("error with rc"); m->mothurOutEndLine(); return -1; } //reports an error in reading if(filehandle.peek() == ')'){ readSpecialChar(filehandle,')',"right parenthesis"); @@ -313,7 +326,7 @@ int ReadNewickTree::readTreeString() { } /**************************************************************************************************/ -int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) { +int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T, TreeMap* tmap) { try { if (m->control_pressed) { return -1; } @@ -326,7 +339,7 @@ int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) { //read all children vector childrenNodes; while(f.peek() != ')'){ - int child = readNewickInt(f, n, T); + int child = readNewickInt(f, n, T, tmap); if (child == -1) { return -1; } //reports an error in reading //cout << "child = " << child << endl; childrenNodes.push_back(child); @@ -397,7 +410,7 @@ int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) { f.putback(d); //set group info - string group = globaldata->gTreemap->getGroup(name); + string group = tmap->getGroup(name); //find index in tree of name int n1 = T->getIndex(name); @@ -406,16 +419,16 @@ int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) { if(group == "not found") { m->mothurOut("Name: " + name + " is not in your groupfile, and will be disregarded. \n"); //readOk = -1; return n1; - globaldata->gTreemap->namesOfSeqs.push_back(name); - globaldata->gTreemap->treemap[name].groupname = "xxx"; + tmap->namesOfSeqs.push_back(name); + tmap->treemap[name].groupname = "xxx"; map::iterator it; - it = globaldata->gTreemap->seqsPerGroup.find("xxx"); - if (it == globaldata->gTreemap->seqsPerGroup.end()) { //its a new group - globaldata->gTreemap->namesOfGroups.push_back("xxx"); - globaldata->gTreemap->seqsPerGroup["xxx"] = 1; + it = tmap->seqsPerGroup.find("xxx"); + if (it == tmap->seqsPerGroup.end()) { //its a new group + tmap->namesOfGroups.push_back("xxx"); + tmap->seqsPerGroup["xxx"] = 1; }else { - globaldata->gTreemap->seqsPerGroup["xxx"]++; + tmap->seqsPerGroup["xxx"]++; } group = "xxx";