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);
vector<string> 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();
#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 {
class Tree {
public:
+ Tree(string);
Tree(); //to generate a tree from a file
~Tree();
int assembleTree();
vector<Node> tree; //the first n nodes are the leaves, where n is the number of sequences.
-
+
+
private:
GlobalData* globaldata;
int numNodes, numLeaves;
int readTreeString(ifstream&);
MothurOut* m;
-
+
};
#endif
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
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<string> namesOfGroups;
vector<string> namesOfSeqs;
map<string,int> seqsPerGroup; //groupname, number of seqs in that group.