From e03de8796670a0c747aed63483daa09c8b86aea0 Mon Sep 17 00:00:00 2001 From: westcott Date: Fri, 27 Aug 2010 15:21:38 +0000 Subject: [PATCH] made read.tree not require a groupfile, if one is not given all seqs are assumed to be from one group --- readtreecommand.cpp | 18 +++++++++++++++--- tree.cpp | 14 +++++++++++++- tree.h | 6 ++++-- treemap.cpp | 15 +++++++++++++++ treemap.h | 1 + 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/readtreecommand.cpp b/readtreecommand.cpp index fdfdb05..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); @@ -227,7 +239,7 @@ int ReadTreeCommand::readNamesFile() { vector dupNames; m->splitAtComma(second, dupNames); - for (int i = 0; i < dupNames.size(); i++) { nameMap[dupNames[i]] = dupNames[i]; } + 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(); diff --git a/tree.cpp b/tree.cpp index dbb3f44..3cb2611 100644 --- a/tree.cpp +++ b/tree.cpp @@ -9,7 +9,19 @@ #include "tree.h" - +/*****************************************************************/ +Tree::Tree(string g) { + try { + globaldata = GlobalData::getInstance(); + m = MothurOut::getInstance(); + + parseTreeFile(); globaldata->runParse = false; + } + catch(exception& e) { + m->errorOut(e, "Tree", "Tree - just parse"); + exit(1); + } +} /*****************************************************************/ Tree::Tree() { try { diff --git a/tree.h b/tree.h index 603f1c3..59343d5 100644 --- a/tree.h +++ b/tree.h @@ -18,6 +18,7 @@ class GlobalData; class Tree { public: + Tree(string); Tree(); //to generate a tree from a file ~Tree(); @@ -40,7 +41,8 @@ public: int assembleTree(); vector tree; //the first n nodes are the leaves, where n is the number of sequences. - + + private: GlobalData* globaldata; int numNodes, numLeaves; @@ -64,7 +66,7 @@ private: int readTreeString(ifstream&); MothurOut* m; - + }; #endif diff --git a/treemap.cpp b/treemap.cpp index b2fc591..52a9003 100644 --- a/treemap.cpp +++ b/treemap.cpp @@ -44,6 +44,21 @@ void TreeMap::readMap() { fileHandle.close(); } /************************************************************/ +void TreeMap::addSeq(string seqName, string seqGroup) { + + namesOfSeqs.push_back(seqName); + setNamesOfGroups(seqGroup); + + treemap[seqName].groupname = seqGroup; //store data in map + + it2 = seqsPerGroup.find(seqGroup); + if (it2 == seqsPerGroup.end()) { //if it's a new group + seqsPerGroup[seqGroup] = 1; + }else {//it's a group we already have + seqsPerGroup[seqGroup]++; + } +} +/************************************************************/ void TreeMap::removeSeq(string seqName) { //erase name from namesOfSeqs diff --git a/treemap.h b/treemap.h index bda6926..d4b506e 100644 --- a/treemap.h +++ b/treemap.h @@ -36,6 +36,7 @@ public: bool isValidGroup(string); //return true if string is a valid group void removeSeq(string); //removes a sequence, this is to accomadate trees that do not contain all the seqs in your groupfile string getGroup(string); + void addSeq(string, string); vector namesOfGroups; vector namesOfSeqs; map seqsPerGroup; //groupname, number of seqs in that group. -- 2.39.2