X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=canberra.cpp;fp=canberra.cpp;h=2612e16dc6c7d085431819eec046a22a0a48a9ac;hb=75c5a235ac3eb22e0f97d36874f4b2dcf9591f2e;hp=0000000000000000000000000000000000000000;hpb=8f89a92f4ada82a2b3bf51b23b6a977770f2b9e2;p=mothur.git diff --git a/canberra.cpp b/canberra.cpp new file mode 100644 index 0000000..2612e16 --- /dev/null +++ b/canberra.cpp @@ -0,0 +1,47 @@ +/* + * canberra.cpp + * Mothur + * + * Created by westcott on 12/14/10. + * Copyright 2010 Schloss Lab. All rights reserved. + * + */ + +#include "canberra.h" + +/***********************************************************************/ + +EstOutput Canberra::getValues(vector shared) { + try { + data.resize(1,0); + + int numSharedOTUS = 0; + + 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); + + //is this otu shared + if ((Aij != 0) && (Bij != 0)) { numSharedOTUS++; } + + if ((Aij + Bij) != 0) { + sum += ((abs(Aij - Bij)) / (float) (Aij + Bij)); + } + } + + data[0] = (1 / (float) numSharedOTUS) * sum; + + if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; } + + return data; + } + catch(exception& e) { + m->errorOut(e, "Canberra", "getValues"); + exit(1); + } +} + +/***********************************************************************/