X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=structchord.cpp;fp=structchord.cpp;h=e85846f9d657466a2609837f5db4fe897f9dc472;hb=7d38edc137a66a33f67f8cf55cce88331290aaf7;hp=0000000000000000000000000000000000000000;hpb=75c5a235ac3eb22e0f97d36874f4b2dcf9591f2e;p=mothur.git diff --git a/structchord.cpp b/structchord.cpp new file mode 100644 index 0000000..e85846f --- /dev/null +++ b/structchord.cpp @@ -0,0 +1,55 @@ +/* + * structchord.cpp + * Mothur + * + * Created by westcott on 12/15/10. + * Copyright 2010 Schloss Lab. All rights reserved. + * + */ + +#include "structchord.h" + +/***********************************************************************/ +EstOutput StructChord::getValues(vector shared) { + try { + data.resize(1,0); + + double sumAj2 = 0.0; + double sumBj2 = 0.0; + + //calc the 2 denominators + for (int i = 0; i < shared[0]->getNumBins(); i++) { + + int Aij = shared[0]->getAbundance(i); + int Bij = shared[1]->getAbundance(i); + + //(Aij) ^ 2 + sumAj2 += (Aij * Aij); + sumBj2 += (Bij * Bij); + } + + sumAj2 = sqrt(sumAj2); + sumBj2 = sqrt(sumBj2); + + //calc sum + double sum = 0.0; + for (int i = 0; i < shared[0]->getNumBins(); i++) { + + int Aij = shared[0]->getAbundance(i); + int Bij = shared[1]->getAbundance(i); + + sum += (((Aij / sumAj2) - (Bij / sumBj2)) * ((Aij / sumAj2) - (Bij / sumBj2))); + } + + data[0] = sqrt(sum); + + if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; } + + return data; + } + catch(exception& e) { + m->errorOut(e, "StructChord", "getValues"); + exit(1); + } +} +/***********************************************************************/