From 39a9b207d1046f3409781c45e38b7a871133d224 Mon Sep 17 00:00:00 2001 From: westcott Date: Mon, 23 Mar 2009 18:34:44 +0000 Subject: [PATCH] added sharedochiai and sharedanderberg calculators --- Mothur.xcodeproj/project.pbxproj | 12 ++++++++ collectsharedcommand.cpp | 6 ++++ coverage.cpp | 6 +--- sharedanderberg.cpp | 52 ++++++++++++++++++++++++++++++++ sharedanderberg.h | 30 ++++++++++++++++++ sharedochiai.cpp | 52 ++++++++++++++++++++++++++++++++ sharedochiai.h | 29 ++++++++++++++++++ summarysharedcommand.cpp | 8 +++++ validcalculator.cpp | 4 +++ 9 files changed, 194 insertions(+), 5 deletions(-) create mode 100644 sharedanderberg.cpp create mode 100644 sharedanderberg.h create mode 100644 sharedochiai.cpp create mode 100644 sharedochiai.h diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 57af531..7e2a8e4 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -17,6 +17,8 @@ 374CD63F0F65832000D90B4A /* libshuffcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 374CD63E0F65832000D90B4A /* libshuffcommand.cpp */; }; 374CD6F10F65A4C100D90B4A /* coverage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 374CD6F00F65A4C100D90B4A /* coverage.cpp */; }; 3765B47A0F77D15900C3EDC5 /* nocommands.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3765B4780F77D15900C3EDC5 /* nocommands.cpp */; }; + 3765B4E20F78055000C3EDC5 /* sharedochiai.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3765B4E10F78055000C3EDC5 /* sharedochiai.cpp */; }; + 3765B5160F780A7F00C3EDC5 /* sharedanderberg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3765B5150F780A7F00C3EDC5 /* sharedanderberg.cpp */; }; 3782163D0F616079008E1F6D /* fullmatrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3782163C0F616079008E1F6D /* fullmatrix.cpp */; }; 379293C30F2DE73400B9034A /* treemap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 379293C20F2DE73400B9034A /* treemap.cpp */; }; 379294700F2E191800B9034A /* parsimonycommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3792946F0F2E191800B9034A /* parsimonycommand.cpp */; }; @@ -136,6 +138,10 @@ 374CD6F00F65A4C100D90B4A /* coverage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = coverage.cpp; sourceTree = ""; }; 3765B4780F77D15900C3EDC5 /* nocommands.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = nocommands.cpp; sourceTree = ""; }; 3765B4790F77D15900C3EDC5 /* nocommands.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nocommands.h; sourceTree = ""; }; + 3765B4E00F78055000C3EDC5 /* sharedochiai.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedochiai.h; sourceTree = ""; }; + 3765B4E10F78055000C3EDC5 /* sharedochiai.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedochiai.cpp; sourceTree = ""; }; + 3765B5140F780A7F00C3EDC5 /* sharedanderberg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedanderberg.h; sourceTree = ""; }; + 3765B5150F780A7F00C3EDC5 /* sharedanderberg.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedanderberg.cpp; sourceTree = ""; }; 3782163B0F616079008E1F6D /* fullmatrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fullmatrix.h; sourceTree = ""; }; 3782163C0F616079008E1F6D /* fullmatrix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fullmatrix.cpp; sourceTree = ""; }; 379293C10F2DE73400B9034A /* treemap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = treemap.h; sourceTree = ""; }; @@ -430,6 +436,8 @@ 37D9281E0F21331F001D4494 /* shannon.cpp */, 37D928230F21331F001D4494 /* sharedace.h */, 37D928220F21331F001D4494 /* sharedace.cpp */, + 3765B5140F780A7F00C3EDC5 /* sharedanderberg.h */, + 3765B5150F780A7F00C3EDC5 /* sharedanderberg.cpp */, 37D928250F21331F001D4494 /* sharedchao1.h */, 37D928240F21331F001D4494 /* sharedchao1.cpp */, 37D928290F21331F001D4494 /* sharedjabund.h */, @@ -439,6 +447,8 @@ 37D9282D0F21331F001D4494 /* sharedjest.h */, 37D9282C0F21331F001D4494 /* sharedjest.cpp */, 3709370A0F6E7FC100EB4C2C /* sharednseqs.h */, + 3765B4E00F78055000C3EDC5 /* sharedochiai.h */, + 3765B4E10F78055000C3EDC5 /* sharedochiai.cpp */, 37D928350F21331F001D4494 /* sharedsobs.h */, 37D928340F21331F001D4494 /* sharedsobs.cpp */, 37AFC71D0F445386005F492D /* sharedsobscollectsummary.h */, @@ -715,6 +725,8 @@ 374CD63F0F65832000D90B4A /* libshuffcommand.cpp in Sources */, 374CD6F10F65A4C100D90B4A /* coverage.cpp in Sources */, 3765B47A0F77D15900C3EDC5 /* nocommands.cpp in Sources */, + 3765B4E20F78055000C3EDC5 /* sharedochiai.cpp in Sources */, + 3765B5160F780A7F00C3EDC5 /* sharedanderberg.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp index e989233..93c15f6 100644 --- a/collectsharedcommand.cpp +++ b/collectsharedcommand.cpp @@ -20,6 +20,8 @@ #include "sharedthetayc.h" #include "sharedthetan.h" #include "sharednseqs.h" +#include "sharedochiai.h" +#include "sharedanderberg.h" //********************************************************************************************************************** @@ -59,6 +61,10 @@ CollectSharedCommand::CollectSharedCommand(){ cDisplays.push_back(new CollectDisplay(new SharedThetaN(), new SharedOneColumnFile(fileNameRoot+"shared.thetan"))); }else if (globaldata->Estimators[i] == "sharednseqs") { cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs"))); + }else if (globaldata->Estimators[i] == "sharedochiai") { + cDisplays.push_back(new CollectDisplay(new SharedOchiai(), new SharedOneColumnFile(fileNameRoot+"shared.ochiai"))); + }else if (globaldata->Estimators[i] == "sharedanderberg") { + cDisplays.push_back(new CollectDisplay(new SharedAnderberg(), new SharedOneColumnFile(fileNameRoot+"shared.anderberg"))); } } diff --git a/coverage.cpp b/coverage.cpp index e0f26c9..dea8dff 100644 --- a/coverage.cpp +++ b/coverage.cpp @@ -100,10 +100,7 @@ void Coverage::getValues(FullMatrix* matrix, vector< vector< vector > >& data[l][k].push_back(0.0); } } - - /**************************************/ - //get the minimums for each comparision - /**************************************/ + int count = 0; int count2 = 0; @@ -169,7 +166,6 @@ void Coverage::getValues(FullMatrix* matrix, vector< vector< vector > >& matrix->restore(); } } - count2++; } count += numGroups+1; //go from AA to BB to CC diff --git a/sharedanderberg.cpp b/sharedanderberg.cpp new file mode 100644 index 0000000..52745ec --- /dev/null +++ b/sharedanderberg.cpp @@ -0,0 +1,52 @@ +/* + * sharedanderberg.cpp + * Mothur + * + * Created by Sarah Westcott on 3/23/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +#include "sharedanderberg.h" + +/***********************************************************************/ + +EstOutput SharedAnderberg::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) { + try { + int S1, S2, S12, tempA, tempB; + S1 = 0; S2 = 0; S12 = 0; tempA = 0; tempB = 0; + + /*S1, S2 = number of OTUs observed or estimated in A and B + S12=number of OTUs shared between A and B */ + + data.resize(1,0); + + for (int i = 0; i < shared1->size(); i++) { + //store in temps to avoid multiple repetitive function calls + tempA = shared1->getAbundance(i); + tempB = shared2->getAbundance(i); + + if (tempA != 0) { S1++; } + if (tempB != 0) { S2++; } + + //they are shared + if ((tempA != 0) && (tempB != 0)) { S12++; } + } + + data[0] = S12 / ((float)((2 * S1) + (2 * S2) - (3 * S12))); + + if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; } + + return data; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SharedAnderberg class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SharedAnderberg class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/***********************************************************************/ diff --git a/sharedanderberg.h b/sharedanderberg.h new file mode 100644 index 0000000..44a1e6d --- /dev/null +++ b/sharedanderberg.h @@ -0,0 +1,30 @@ +#ifndef SHAREDANDERBERG_H +#define SHAREDANDERBERG_H +/* + * sharedanderberg.h + * Mothur + * + * Created by Sarah Westcott on 3/23/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +#include "calculator.h" + +/***********************************************************************/ + +class SharedAnderberg : public Calculator { + +public: + SharedAnderberg() : Calculator("SharedAnderberg", 1) {}; + EstOutput getValues(SAbundVector*) {return data;}; + EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*); +private: + +}; + +/***********************************************************************/ + + + +#endif \ No newline at end of file diff --git a/sharedochiai.cpp b/sharedochiai.cpp new file mode 100644 index 0000000..9a64a2c --- /dev/null +++ b/sharedochiai.cpp @@ -0,0 +1,52 @@ +/* + * sharedochiai.cpp + * Mothur + * + * Created by Sarah Westcott on 3/23/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +#include "sharedochiai.h" + +/***********************************************************************/ + +EstOutput SharedOchiai::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) { + try { + int S1, S2, S12, tempA, tempB; + S1 = 0; S2 = 0; S12 = 0; tempA = 0; tempB = 0; + + /*S1, S2 = number of OTUs observed or estimated in A and B + S12=number of OTUs shared between A and B */ + + data.resize(1,0); + + for (int i = 0; i < shared1->size(); i++) { + //store in temps to avoid multiple repetitive function calls + tempA = shared1->getAbundance(i); + tempB = shared2->getAbundance(i); + + if (tempA != 0) { S1++; } + if (tempB != 0) { S2++; } + + //they are shared + if ((tempA != 0) && (tempB != 0)) { S12++; } + } + + data[0] = S12 / ((float)pow((S1 * S2), 0.5)); + + if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; } + + return data; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SharedOchiai class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SharedOchiai class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/***********************************************************************/ diff --git a/sharedochiai.h b/sharedochiai.h new file mode 100644 index 0000000..27de375 --- /dev/null +++ b/sharedochiai.h @@ -0,0 +1,29 @@ +#ifndef SHAREDOCHIAI_H +#define SHAREDOCHIAI_H +/* + * sharedochiai.h + * Mothur + * + * Created by Sarah Westcott on 3/23/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +#include "calculator.h" + +/***********************************************************************/ + +class SharedOchiai : public Calculator { + +public: + SharedOchiai() : Calculator("SharedOchiai", 1) {}; + EstOutput getValues(SAbundVector*) {return data;}; + EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*); +private: + +}; + +/***********************************************************************/ + + +#endif \ No newline at end of file diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index 9e2c668..7698704 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -20,6 +20,8 @@ #include "sharedsorest.h" #include "sharedthetayc.h" #include "sharedthetan.h" +#include "sharedochiai.h" +#include "sharedanderberg.h" //********************************************************************************************************************** @@ -59,7 +61,13 @@ SummarySharedCommand::SummarySharedCommand(){ sumCalculators.push_back(new SharedThetaN()); }else if (globaldata->Estimators[i] == "sharednseqs") { sumCalculators.push_back(new SharedNSeqs()); + }else if (globaldata->Estimators[i] == "sharedochiai") { + sumCalculators.push_back(new SharedOchiai()); + }else if (globaldata->Estimators[i] == "sharedanderberg") { + sumCalculators.push_back(new SharedAnderberg()); } + + } } diff --git a/validcalculator.cpp b/validcalculator.cpp index 7f83ac7..b29ff57 100644 --- a/validcalculator.cpp +++ b/validcalculator.cpp @@ -162,6 +162,8 @@ void ValidCalculators::initialShared() { shared["sharedthetayc"] = "sharedthetayc"; shared["sharedthetan"] = "sharedthetan"; shared["sharednseqs"] = "sharednseqs"; + shared["sharedochiai"] = "sharedochiai"; + shared["sharedanderberg"] = "sharedanderberg"; shared["default"] = "default"; } catch(exception& e) { @@ -238,6 +240,8 @@ void ValidCalculators::initialSharedSummary() { sharedsummary["sharedthetayc"] = "sharedthetayc"; sharedsummary["sharedthetan"] = "sharedthetan"; sharedsummary["sharednseqs"] = "sharednseqs"; + sharedsummary["sharedochiai"] = "sharedochiai"; + sharedsummary["sharedanderberg"] = "sharedanderberg"; sharedsummary["default"] = "default"; } catch(exception& e) { -- 2.39.2