]> git.donarmstrong.com Git - mothur.git/blob - memchord.cpp
fixed kw parameter types
[mothur.git] / memchord.cpp
1 /*
2  *  memchord.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 12/17/10.
6  *  Copyright 2010 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "memchord.h"
11
12 /***********************************************************************/
13 EstOutput MemChord::getValues(vector<SharedRAbundVector*> shared) {
14         try {
15                 data.resize(1,0);
16                 
17                 double nonZeroA = 0;
18                 double nonZeroB = 0;
19                 
20                 //for each otu
21                 for (int i = 0; i < shared[0]->getNumBins(); i++) {
22                         if (shared[0]->getAbundance(i) != 0) { nonZeroA++; }
23                         if (shared[1]->getAbundance(i) != 0) { nonZeroB++; }
24                 }
25                 
26                 nonZeroA = sqrt(nonZeroA);
27                 nonZeroB = sqrt(nonZeroB);
28                 
29                 double sum = 0.0;
30                 for (int i = 0; i < shared[0]->getNumBins(); i++) {
31                         int A = shared[0]->getAbundance(i);
32                         int B = shared[1]->getAbundance(i);
33                         
34                         if (A > 0) { A = 1; }
35                         if (B > 0) { B = 1; }
36                         
37                         double Aterm = A / nonZeroA;
38                         double Bterm = B / nonZeroB;
39                         
40                         sum += ((Aterm-Bterm)*(Aterm-Bterm));
41                 }
42                 
43                 data[0] = sqrt(sum);
44                 
45                 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
46                 
47                 return data;
48         }
49         catch(exception& e) {
50                 m->errorOut(e, "MemChord", "getValues");
51                 exit(1);
52         }
53 }
54 /***********************************************************************/
55