X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=gower.cpp;fp=gower.cpp;h=5f0bf68c60e7df6f4a4d33857ba94e94ba77f2e2;hb=0caf3fbabaa3ece404f8ce77f4c883dc5b1bf1dc;hp=0000000000000000000000000000000000000000;hpb=1b73ff67c83892a025e597dabd9df6fe7b58206a;p=mothur.git diff --git a/gower.cpp b/gower.cpp new file mode 100644 index 0000000..5f0bf68 --- /dev/null +++ b/gower.cpp @@ -0,0 +1,56 @@ +/* + * gower.cpp + * Mothur + * + * Created by westcott on 12/17/10. + * Copyright 2010 Schloss Lab. All rights reserved. + * + */ + +#include "gower.h" + +/***********************************************************************/ +EstOutput Gower::getValues(vector shared) { + try { + data.resize(1,0); + + vector maxOtus; maxOtus.resize(shared[0]->getNumBins()); + vector minOtus; minOtus.resize(shared[0]->getNumBins()); + //for each otu + for (int i = 0; i < shared[0]->getNumBins(); i++) { + + //set otus min and max to first one + minOtus[i] = shared[0]->getAbundance(i); + maxOtus[i] = shared[0]->getAbundance(i); + + //for each group + for (int j = 1; j < shared.size(); j++) { + maxOtus[i] = max(shared[j]->getAbundance(i), maxOtus[i]); + minOtus[i] = min(shared[j]->getAbundance(i), minOtus[i]); + } + } + + double sum = 0.0; + for (int i = 0; i < shared[0]->getNumBins(); i++) { + int A = shared[0]->getAbundance(i); + int B = shared[1]->getAbundance(i); + + double numerator = abs(A - B); + double denominator = maxOtus[i] - minOtus[i]; + + if (denominator != 0) { sum += (numerator / denominator); } + } + + data[0] = sum; + + if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; } + + return data; + } + catch(exception& e) { + m->errorOut(e, "Gower", "getValues"); + exit(1); + } +} +/***********************************************************************/ +