]> git.donarmstrong.com Git - mothur.git/blob - structchord.cpp
sffinfo bug with flow grams right index when clipQualRight=0
[mothur.git] / structchord.cpp
1 /*
2  *  structchord.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 12/15/10.
6  *  Copyright 2010 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "structchord.h"
11
12 /***********************************************************************/
13 EstOutput StructChord::getValues(vector<SharedRAbundVector*> shared) {
14         try {
15                 data.resize(1,0);
16                 
17                 double sumAj2 = 0.0;
18                 double sumBj2 = 0.0;
19                 
20                 //calc the 2 denominators
21                 for (int i = 0; i < shared[0]->getNumBins(); i++) { 
22                         
23                         int Aij = shared[0]->getAbundance(i);
24                         int Bij = shared[1]->getAbundance(i);
25                         
26                         //(Aij) ^ 2
27                         sumAj2 += (Aij * Aij);
28                         sumBj2 += (Bij * Bij);
29                 }
30                 
31                 sumAj2 = sqrt(sumAj2);
32                 sumBj2 = sqrt(sumBj2);
33                 
34                 //calc sum
35                 double sum = 0.0;
36                 for (int i = 0; i < shared[0]->getNumBins(); i++) { 
37                         
38                         int Aij = shared[0]->getAbundance(i);
39                         int Bij = shared[1]->getAbundance(i);
40                         
41                         sum += (((Aij / sumAj2) - (Bij / sumBj2)) * ((Aij / sumAj2) - (Bij / sumBj2)));
42                 }
43                 
44                 data[0] = sqrt(sum);
45                 
46                 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
47                 
48                 return data;
49         }
50         catch(exception& e) {
51                 m->errorOut(e, "StructChord", "getValues");
52                 exit(1);
53         }
54 }
55 /***********************************************************************/