}
//if you are a nexus file
}else if ((c = filehandle.peek()) == '#') {
- holder = nexusTranslation(); //reads file through the translation and updates treemap
+ //get right number of seqs from nexus file.
+ Tree* temp = new Tree(); delete temp;
+
+ nexusTranslation(); //reads file through the translation and updates treemap
while((c = filehandle.peek()) != EOF) {
// get past comments
while ((c = filehandle.peek()) != EOF) {
try {
holder = "";
- //int numSeqs = globaldata->gTreemap->getNumSeqs(); //must save this some when we clear old names we can still know how many sequences there were
+ int numSeqs = globaldata->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
//update treemap
globaldata->gTreemap->namesOfSeqs.clear();
- char c;
+ /*char c;
string number, name;
while ((c = filehandle.peek()) != EOF) {
if ((name == "tree") || (name == ";") ) { break; }
if (lastChar == ',') { name.erase(name.end()-1); } //erase the comma
-
+ */
+ cout << "numseqs = " << numSeqs << endl;
+ string number, name;
+ for(int i=0;i<numSeqs;i++){
+
+ filehandle >> number;
+ filehandle >> name;
+ name.erase(name.end()-1); //erase the comma
+
//insert new one with new name
string group = globaldata->gTreemap->getGroup(name);
globaldata->gTreemap->treemap[toString(number)].groupname = group;
copy->tree[i].setParent(grandparent);
copy->tree[i].setBranchLength((copy->tree[i].getBranchLength()+copy->tree[parent].getBranchLength()));
- copy->tree[grandparent].setChildren(grandparentLC, grandparentRC);
+ if (grandparent != -1) {
+ copy->tree[grandparent].setChildren(grandparentLC, grandparentRC);
+ }
removedLeaves.insert(sibIndex);
}
}else{
copy->tree[sibIndex].setParent(grandparent);
copy->tree[sibIndex].setBranchLength((copy->tree[sibIndex].getBranchLength()+copy->tree[parent].getBranchLength()));
- copy->tree[grandparent].setChildren(grandparentLC, grandparentRC);
+ if (grandparent != -1) {
+ copy->tree[grandparent].setChildren(grandparentLC, grandparentRC);
+ }
removedLeaves.insert(i);
}else{
//neither of us are, so we want to eliminate ourselves and our parent
int parentsSibIndex;
if (grandparent != -1) {
int greatgrandparent = copy->tree[grandparent].getParent();
- int greatgrandparentLC = copy->tree[greatgrandparent].getLChild();
- int greatgrandparentRC = copy->tree[greatgrandparent].getRChild();
+ int greatgrandparentLC, greatgrandparentRC;
+ if (greatgrandparent != -1) {
+ greatgrandparentLC = copy->tree[greatgrandparent].getLChild();
+ greatgrandparentRC = copy->tree[greatgrandparent].getRChild();
+ }
int grandparentLC = copy->tree[grandparent].getLChild();
int grandparentRC = copy->tree[grandparent].getRChild();
copy->tree[parentsSibIndex].setParent(greatgrandparent);
copy->tree[parentsSibIndex].setBranchLength((copy->tree[parentsSibIndex].getBranchLength()+copy->tree[grandparent].getBranchLength()));
- copy->tree[greatgrandparent].setChildren(greatgrandparentLC, greatgrandparentRC);
+ if (greatgrandparent != -1) {
+ copy->tree[greatgrandparent].setChildren(greatgrandparentLC, greatgrandparentRC);
+ }
}else{
- copy->tree[parent].setChildren(-1, -1);
- cout << "issues with making subtree" << endl;
+ copy->tree[parent].setParent(-1);
+ //cout << "issues with making subtree" << endl;
}
removedLeaves.insert(sibIndex);
removedLeaves.insert(i);
int nextSpot = numLeaves;
populateNewTree(copy->tree, root, nextSpot);
-
}
catch(exception& e) {
m->errorOut(e, "Tree", "getCopy");
out << name << '\t';
//output distances
- for (int l = 0; l < globaldata->Groups.size(); l++) { out << setprecision(11) << dists[r][l] << '\t'; }
+ for (int l = 0; l < globaldata->Groups.size(); l++) { out << dists[r][l] << '\t'; }
out << endl;
}else{
//output distances
processors = p;
outputDir = o;
-
//if the users enters no groups then give them the score of all groups
int numGroups = globaldata->Groups.size();
D[count] += weightedSum;
}
-
+
//adding the wieghted sums from group l
for (int j = 0; j < t->groupNodeInfo[groupB].size(); j++) { //the leaf nodes that have seqs from group l
map<string, int>::iterator it = t->tree[t->groupNodeInfo[groupB][j]].pcount.find(groupB);
D[count] += weightedSum;
}
-
count++;
}
-
+
//calculate u for the group comb
-
for (int h = start; h < (start+num); h++) {
//report progress
- m->mothurOut("Processing combo: " + toString(h)); m->mothurOutEndLine();
+ //m->mothurOut("Processing combo: " + toString(h)); m->mothurOutEndLine();
string groupA = namesOfGroupCombos[h][0];
string groupB = namesOfGroupCombos[h][1];
//does this node have descendants from group l
it = t->tree[i].pcount.find(groupB);
+
//if it does subtract their percentage from u
if (it != t->tree[i].pcount.end()) {
u -= (double) t->tree[i].pcount[groupB] / (double) tmap->seqsPerGroup[groupB];
WScore[(groupA+groupB)] += u;
}
}
-
-
}
+
}
/********************************************************/
int sib = lc;
if (lc == index) { sib = rc; }
-
+
map<string, int>::iterator itGroup;
int pcountSize = 0;
itGroup = t->tree[sib].pcount.find(groupA);
//get all nodes above the root to add so we don't add their u values above
index = *(rootForGrouping[grouping].begin());
+
while(t->tree[index].getParent() != -1){
int parent = t->tree[index].getParent();
rootForGrouping[grouping].insert(parent);
index = parent;
}
-
return sum;
}
catch(exception& e) {