]> git.donarmstrong.com Git - mothur.git/blob - slibshuff.cpp
fixed bug with trim.seqs allfiles=t
[mothur.git] / slibshuff.cpp
1 /*
2  *  slibshuff.cpp
3  *  Mothur
4  *
5  *  Created by Pat Schloss on 4/8/09.
6  *  Copyright 2009 Patrick D. Schloss. All rights reserved.
7  *
8  */
9
10 #include "slibshuff.h"
11
12 /***********************************************************************/
13
14 SLibshuff::SLibshuff(FullMatrix* D, int it, float co) : Libshuff(D, it, 0, co){}
15
16 /***********************************************************************/
17
18 float SLibshuff::evaluatePair(int i, int j){
19         return sCalculate(i,j);
20 }
21
22 /***********************************************************************/
23
24 vector<vector<double> > SLibshuff::evaluateAll(){
25         try{
26                 savedMins.resize(numGroups);
27                 vector<vector<double> > dCXYValues(numGroups);
28
29                 for(int i=0;i<numGroups;i++){
30                         dCXYValues[i].resize(numGroups);
31                         savedMins[i].resize(numGroups);
32                         for(int j=0;j<numGroups;j++){
33                                 if(i!=j){
34                                         dCXYValues[i][j] = sCalculate(i,j);     
35                                         savedMins[i][j] = minXY;
36                                 }
37
38                                 if(savedMins[i][i].size() == 0){
39                                         savedMins[i][i] = minX;
40                                 }
41
42                         }
43                 }               
44                 return dCXYValues;
45         }
46         catch(exception& e) {
47                 m->errorOut(e, "SLibshuff", "evaluateAll");
48                 exit(1);
49         }
50 }
51
52 /***********************************************************************/
53
54 double SLibshuff::sCalculate(int x, int y){
55         try{
56                 double sum = 0.0,t=0.0;
57                 
58                 minX = getMinX(x);
59                 
60                 if (m->control_pressed) { return sum; }
61                 
62                 minXY = getMinXY(x,y);
63                 
64                 if (m->control_pressed) { return sum; }
65
66                 sort(minX.begin(), minX.end());
67                 
68                 if (m->control_pressed) { return sum; }
69                 
70                 sort(minXY.begin(), minXY.end());
71                 
72                 if (m->control_pressed) { return sum; }
73
74                 int ix=0,iy=0;
75                 while( (ix < groupSizes[x]) && (iy < groupSizes[x]) ) {
76                         double h = (ix-iy)/double(groupSizes[x]);
77                         
78                         if(minX[ix] < minXY[iy]) {
79                                 sum += (minX[ix] - t)*h*h;
80                                 t = minX[ix++];
81                         }
82                         else {
83                                 sum += (minXY[iy] - t)*h*h;
84                                 t = minXY[iy++];
85                         }
86                         
87                 }
88                 
89                 if(ix < groupSizes[x]) {
90                         
91                         while(ix < groupSizes[x]) {
92                                 double h = (ix-iy)/double(groupSizes[x]);
93                                 sum += (minX[ix] - t)*h*h;
94                                 t = minX[ix++];
95                         }
96                         
97                 }
98                 else {
99                         
100                         while(iy < groupSizes[x]) {
101                                 double h = (ix-iy)/double(groupSizes[x]);
102                                 sum += (minXY[iy] - t)*h*h;
103                                 t = minXY[iy++];
104                         }
105                         
106                 }
107                 
108                 return sum;
109         }
110         catch(exception& e) {
111                 m->errorOut(e, "SLibshuff", "sCalculate");
112                 exit(1);
113         }
114 }
115
116 /***********************************************************************/