]> git.donarmstrong.com Git - mothur.git/blob - dlibshuff.cpp
working on pam
[mothur.git] / dlibshuff.cpp
1 /*
2  *  DLibshuff.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 "dlibshuff.h"
11
12 /***********************************************************************/
13
14 DLibshuff::DLibshuff(FullMatrix* D, int it, float step, float co) : Libshuff(D, it, step, co){
15
16         numDXs = int(cutOff / stepSize);
17
18 }
19
20 /***********************************************************************/
21
22 float DLibshuff::evaluatePair(int i, int j){
23         return dCalculate(i,j);
24 }
25
26 /***********************************************************************/
27
28 vector<vector<double> > DLibshuff::evaluateAll(){
29         savedMins.resize(numGroups);
30         vector<vector<double> > dCXYValues(numGroups);
31         
32         for(int i=0;i<numGroups;i++){
33                 savedMins[i].resize(numGroups);
34                 dCXYValues[i].resize(numGroups);
35                 for(int j=0;j<numGroups;j++){
36                         if(i!=j){       dCXYValues[i][j] = dCalculate(i,j);     }
37                         savedMins[i][i] = minX;
38                         savedMins[i][j] = minXY;
39                 }
40         }
41         
42         return dCXYValues;
43 }
44
45 /***********************************************************************/
46
47 double DLibshuff::dCalculate(int x, int y){
48         
49         double sum = 0;
50         
51         minX = getMinX(x);
52         
53         if (m->control_pressed) { return sum; }
54         
55         minXY = getMinXY(x, y);
56         
57         if (m->control_pressed) { return sum; }
58         
59         vector<int> nx = calcN(minX);
60         
61         if (m->control_pressed) { return sum; }
62         
63         vector<int> nxy = calcN(minXY);
64         
65         if (m->control_pressed) { return sum; }
66
67         for(int i=0;i<numDXs;i++){
68                 float h = (nx[i] - nxy[i]) / (float) groupSizes[x];
69                 sum += h * h * stepSize;
70         }
71
72         return sum;
73 }
74
75 /***********************************************************************/
76
77 vector<int> DLibshuff::calcN(vector<double> minVector){
78
79         vector<int> counts(numDXs,0);
80         
81         int precision = int(1 / stepSize);
82         
83         for(int i=0;i<minVector.size();i++){
84                 int bin = int (precision * minVector[i]);
85                 if(bin < numDXs){       counts[bin]++;  }
86         }
87
88         for(int i=1;i<numDXs;i++){
89                 counts[i] += counts[i-1];
90         }
91         
92         return counts;
93 }
94
95 /***********************************************************************/