]> git.donarmstrong.com Git - mothur.git/blob - spearman.cpp
fixed bug with trim.seqs- when a file is blank for a grouping mothur removed it,...
[mothur.git] / spearman.cpp
1 /*
2  *  spearman.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 "spearman.h"
11
12 /***********************************************************************/
13 EstOutput Spearman::getValues(vector<SharedRAbundVector*> shared) {
14         try {
15                 data.resize(1,0);
16                 
17                 SAbundVector savA = shared[0]->getSAbundVector();
18                 SAbundVector savB = shared[1]->getSAbundVector();
19                 
20                 double sumRanks = 0.0;
21                 int numOTUS = shared[0]->getNumBins();
22                 
23                 //calc the 2 denominators
24                 for (int i = 0; i < shared[0]->getNumBins(); i++) { 
25                         
26                         int Aij = shared[0]->getAbundance(i);
27                         int Bij = shared[1]->getAbundance(i);
28                         
29                         int rankA = savA.get(Aij);
30                         int rankB = savB.get(Bij);
31                         
32                         sumRanks += ((rankA - rankB) * (rankA - rankB));
33                 }
34                 
35                 data[0] = 1.0 - ((6 * sumRanks) / (float) (numOTUS * (numOTUS-1)));
36                 
37                 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
38                 
39                 return data;
40         }
41         catch(exception& e) {
42                 m->errorOut(e, "Soergel", "getValues");
43                 exit(1);
44         }
45 }
46 /***********************************************************************/
47