]> git.donarmstrong.com Git - mothur.git/commitdiff
changed unifrac.weighted()
authorwestcott <westcott>
Tue, 24 Feb 2009 17:13:33 +0000 (17:13 +0000)
committerwestcott <westcott>
Tue, 24 Feb 2009 17:13:33 +0000 (17:13 +0000)
weighted.cpp

index b8e8974657127994a919490bc02cf2564e4179a8..a0d2f5ef4117191886cb3abcc078a4620b609abc 100644 (file)
@@ -36,61 +36,61 @@ EstOutput Weighted::getValues(Tree* t) {
                                        WScore[globaldata->Groups[i-1]+globaldata->Groups[l]] = 0.0;
                                        D.push_back(0.0000); //initialize a spot in D for each combination
                                }
-                       }
-               }
-               
-               data.clear(); //clear out old values
-       
-               for(int i=0;i<t->getNumNodes();i++){
-                       //calculate weighted score for each of the group comb i.e. with groups A,B,C = AB, AC, BC.
-                       n = 1;
-                       for (int b=1; b<numGroups; b++) { 
-                               for (int l = n; l < numGroups; l++) {
                                
                                /********************************************************/
                                //calculate a D value for each group combo
-                                       for(int v=0;v<t->getNumLeaves();v++){
-                                               int index = v;
-                                               double sum = 0.0000;
+                               for(int v=0;v<t->getNumLeaves();v++){
+                                       int index = v;
+                                       double sum = 0.0000;
                
-                                               //while you aren't at root
-                                               while(t->tree[index].getParent() != -1){
+                                       //while you aren't at root
+                                       while(t->tree[index].getParent() != -1){
                                                        
-                                                       //if you have a BL
-                                                       if(t->tree[index].getBranchLength() != -1){
-                                                               sum += t->tree[index].getBranchLength();
-                                                       }
-                       
-                                                       index = t->tree[index].getParent();
-                                               }
-                                               
-                                               //get last breanch length added
+                                               //if you have a BL
                                                if(t->tree[index].getBranchLength() != -1){
-                                                               sum += t->tree[index].getBranchLength();
+                                                       sum += t->tree[index].getBranchLength();
                                                }
+                                               index = t->tree[index].getParent();
+                                       }
+                                               
+                                       //get last breanch length added
+                                       if(t->tree[index].getBranchLength() != -1){
+                                               sum += t->tree[index].getBranchLength();
+                                       }
                                                
-                                               if (globaldata->Groups.size() == 0) {
-                                                       //is this sum from a sequence which is in one of the users groups
-                                                       if (inUsersGroups(t->tree[v].getGroup(), tmap->namesOfGroups) == true) {
-                                                               //is this sum from a sequence which is in this groupCombo
-                                                               if ((t->tree[v].getGroup() == tmap->namesOfGroups[b-1]) || (t->tree[v].getGroup() == tmap->namesOfGroups[l])) {
-                                                                       sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()];
-                                                                       D[n-1] += sum; 
-                                                               }
+                                       if (globaldata->Groups.size() == 0) {
+                                               //is this sum from a sequence which is in one of the users groups
+                                               if (inUsersGroups(t->tree[v].getGroup(), tmap->namesOfGroups) == true) {
+                                                       //is this sum from a sequence which is in this groupCombo
+                                                       if ((t->tree[v].getGroup() == tmap->namesOfGroups[i-1]) || (t->tree[v].getGroup() == tmap->namesOfGroups[l])) {
+                                                               sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()];
+                                                               D[n-1] += sum; 
                                                        }
-                                               }else {
-                                                       //is this sum from a sequence which is in one of the users groups
-                                                       if (inUsersGroups(t->tree[v].getGroup(), globaldata->Groups) == true) {
-                                                               //is this sum from a sequence which is in this groupCombo
-                                                               if ((t->tree[v].getGroup() == globaldata->Groups[b-1]) || (t->tree[v].getGroup() == globaldata->Groups[l])) {
-                                                                       sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()];
-                                                                       D[n-1] += sum; 
-                                                               }
+                                               }
+                                       }else {
+                                               //is this sum from a sequence which is in one of the users groups
+                                               if (inUsersGroups(t->tree[v].getGroup(), globaldata->Groups) == true) {
+                                                       //is this sum from a sequence which is in this groupCombo
+                                                       if ((t->tree[v].getGroup() == globaldata->Groups[i-1]) || (t->tree[v].getGroup() == globaldata->Groups[l])) {
+                                                               sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()];
+                                                               D[n-1] += sum; 
                                                        }
                                                }
                                        }
+                               }
                                /*********************************************************/
-                               //calculate a u value for each combo
+                       }
+               }
+               
+               
+               data.clear(); //clear out old values
+       
+               for(int i=0;i<t->getNumNodes();i++){
+                       //calculate weighted score for each of the group comb i.e. with groups A,B,C = AB, AC, BC.
+                       n = 1;
+                       for (int b=1; b<numGroups; b++) { 
+                               for (int l = n; l < numGroups; l++) {
+                                       //calculate a u value for each combo
                                        double u;
                                        //the user has not entered specific groups
                                        if (globaldata->Groups.size() == 0) {
@@ -148,9 +148,12 @@ EstOutput Weighted::getValues(Tree* t) {
                                //the user has not entered specific groups
                                if (globaldata->Groups.size() == 0) {
                                        UN = (WScore[tmap->namesOfGroups[i-1]+tmap->namesOfGroups[l]] / D[n-1]);
+cout << "W score = " << WScore[tmap->namesOfGroups[i-1]+tmap->namesOfGroups[l]] << endl;
                                }else {//they have entered specific groups
                                        UN = (WScore[globaldata->Groups[i-1]+globaldata->Groups[l]] / D[n-1]);
+cout << "W score = " << WScore[globaldata->Groups[i-1]+globaldata->Groups[l]] << endl;
                                }
+cout << " D = "<< D[n-1] << endl;
                                if (isnan(UN) || isinf(UN)) { UN = 0; } 
                                data.push_back(UN);
                        }