From 2657127a3e1f3b5463f2b3a3b49bc19843f5c9d2 Mon Sep 17 00:00:00 2001 From: westcott Date: Mon, 30 Mar 2009 13:31:37 +0000 Subject: [PATCH] added sort to heatmap to put shared otus at the top and updated some error checking --- Mothur.xcodeproj/project.pbxproj | 6 +++ collectsharedcommand.cpp | 6 +-- heatmap.cpp | 77 ++++++++++++++++++++++++++++++++ heatmap.h | 3 +- helpcommand.cpp | 10 +++++ sharedanderbergs.cpp | 52 +++++++++++++++++++++ sharedanderbergs.h | 30 +++++++++++++ sharedrabundvector.cpp | 28 ++++++++++++ sharedrabundvector.h | 3 +- summarysharedcommand.cpp | 6 +-- validparameter.cpp | 31 +++++++++---- 11 files changed, 236 insertions(+), 16 deletions(-) create mode 100644 sharedanderbergs.cpp create mode 100644 sharedanderbergs.h diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index b5cb3f1..e71f9ce 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 3746107E0F4064D100460C57 /* weighted.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3746107D0F4064D100460C57 /* weighted.cpp */; }; 374610830F40652400460C57 /* unweighted.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 374610820F40652400460C57 /* unweighted.cpp */; }; 3746109D0F40657600460C57 /* unifracunweightedcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3746109C0F40657600460C57 /* unifracunweightedcommand.cpp */; }; + 37519A6B0F80E6EB00FED5E8 /* sharedanderbergs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37519A6A0F80E6EB00FED5E8 /* sharedanderbergs.cpp */; }; 375873E70F7D63E90040F377 /* coverage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 375873E50F7D63E90040F377 /* coverage.cpp */; }; 375873EC0F7D64520040F377 /* fullmatrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 375873EB0F7D64520040F377 /* fullmatrix.cpp */; }; 375873EF0F7D646F0040F377 /* heatmap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 375873EE0F7D646F0040F377 /* heatmap.cpp */; }; @@ -143,6 +144,8 @@ 374610820F40652400460C57 /* unweighted.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unweighted.cpp; sourceTree = ""; }; 3746109B0F40657600460C57 /* unifracunweightedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unifracunweightedcommand.h; sourceTree = ""; }; 3746109C0F40657600460C57 /* unifracunweightedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unifracunweightedcommand.cpp; sourceTree = ""; }; + 37519A690F80E6EB00FED5E8 /* sharedanderbergs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedanderbergs.h; sourceTree = ""; }; + 37519A6A0F80E6EB00FED5E8 /* sharedanderbergs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedanderbergs.cpp; sourceTree = ""; }; 375873E50F7D63E90040F377 /* coverage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = coverage.cpp; sourceTree = ""; }; 375873E60F7D63E90040F377 /* coverage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = coverage.h; sourceTree = ""; }; 375873EA0F7D64520040F377 /* fullmatrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fullmatrix.h; sourceTree = ""; }; @@ -489,6 +492,8 @@ 37D9281E0F21331F001D4494 /* shannon.cpp */, 37D928230F21331F001D4494 /* sharedace.h */, 37D928220F21331F001D4494 /* sharedace.cpp */, + 37519A690F80E6EB00FED5E8 /* sharedanderbergs.h */, + 37519A6A0F80E6EB00FED5E8 /* sharedanderbergs.cpp */, 375873FB0F7D64DA0040F377 /* sharedbraycurtis.h */, 375873FC0F7D64DA0040F377 /* sharedbraycurtis.cpp */, EB6F01590F6AC1670048081A /* sharedbdiversity.h */, @@ -805,6 +810,7 @@ 375874060F7D64EF0040F377 /* sharedkulczynskicody.cpp in Sources */, 3758740C0F7D64FC0040F377 /* sharedmorisitahorn.cpp in Sources */, 3758740D0F7D64FC0040F377 /* sharedochiai.cpp in Sources */, + 37519A6B0F80E6EB00FED5E8 /* sharedanderbergs.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp index 3c1ad52..ec35dd6 100644 --- a/collectsharedcommand.cpp +++ b/collectsharedcommand.cpp @@ -23,7 +23,7 @@ #include "sharedbdiversity.h" #include "sharednseqs.h" #include "sharedochiai.h" -//#include "sharedanderberg.h" +#include "sharedanderbergs.h" #include "sharedkulczynski.h" #include "sharedkulczynskicody.h" #include "sharedlennon.h" @@ -75,8 +75,8 @@ CollectSharedCommand::CollectSharedCommand(){ 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"))); + }else if (globaldata->Estimators[i] == "sharedanderberg") { + cDisplays.push_back(new CollectDisplay(new SharedAnderberg(), new SharedOneColumnFile(fileNameRoot+"shared.anderberg"))); }else if (globaldata->Estimators[i] == "sharedkulczynski") { cDisplays.push_back(new CollectDisplay(new SharedKulczynski(), new SharedOneColumnFile(fileNameRoot+"shared.kulczynski"))); }else if (globaldata->Estimators[i] == "sharedkulczynskicody") { diff --git a/heatmap.cpp b/heatmap.cpp index fb07056..86786e7 100644 --- a/heatmap.cpp +++ b/heatmap.cpp @@ -87,6 +87,9 @@ void HeatMap::getPic(SharedOrderVector* sharedorder) { //fills vector of sharedsabunds - lookup getSharedVectors(sharedorder); + //sort lookup so shared bins are on top + sortSharedVectors(); + //get maxBin for (int i = 0; i < lookup.size(); i++) { for (int j = 0; j < lookup[i]->size(); j++) { @@ -145,6 +148,12 @@ void HeatMap::getPic(SharedOrderVector* sharedorder) { //********************************************************************************************************************** void HeatMap::getSharedVectors(SharedOrderVector* order){ try { + + //delete lookup + for (int j = 0; j < lookup.size(); j++) { + delete lookup[j]; + } + lookup.clear(); groupComb = ""; @@ -187,7 +196,75 @@ void HeatMap::getSharedVectors(SharedOrderVector* order){ } + +//********************************************************************************************************************** +void HeatMap::sortSharedVectors(){ + try { + //copy lookup and then clear it to refill with sorted. + //loop though lookup and determine if they are shared + //if they are then insert in the front + //if not push to back + + bool shared; + vector looktemp; + + //create and initialize looktemp as a copy of lookup + for (int i = 0; i < lookup.size(); i++) { + SharedRAbundVector* temp = new SharedRAbundVector(lookup[i]->getNumBins()); + temp->setLabel(lookup[i]->getLabel()); + temp->setGroup(lookup[i]->getGroup()); + //copy lookup i's info + for (int j = 0; j < lookup[i]->size(); j++) { + temp->set(j, lookup[i]->getAbundance(j), lookup[i]->getGroup()); + } + looktemp.push_back(temp); + } + + //clear out lookup to create sorted lookup + lookup.clear(); + + //create and initialize lookup to empty vectors + for (int i = 0; i < looktemp.size(); i++) { + SharedRAbundVector* temp = new SharedRAbundVector(); + lookup.push_back(temp); + } + + //for each bin + for (int i = 0; i < looktemp[0]->size(); i++) { + shared = true; + //for each group + for (int j = 0; j < looktemp.size(); j++) { + if (looktemp[j]->getAbundance(i) == 0) { shared = false; } + } + + //fill lookup + for (int j = 0; j < looktemp.size(); j++) { + //if they are not shared then push to back, if they are not insert in front + if (shared == false) { lookup[j]->push_back(looktemp[j]->getAbundance(i), i, looktemp[j]->getGroup()); } + else { lookup[j]->push_front(looktemp[j]->getAbundance(i), i, looktemp[j]->getGroup()); } + } + } + + //delete looktemp + for (int j = 0; j < looktemp.size(); j++) { + delete looktemp[j]; + } + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function sortSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the HeatMap class function sortSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + +} + //********************************************************************************************************************** + + diff --git a/heatmap.h b/heatmap.h index 0678aa0..c26684e 100644 --- a/heatmap.h +++ b/heatmap.h @@ -31,7 +31,8 @@ class HeatMap { private: void getSharedVectors(SharedOrderVector*); - + void sortSharedVectors(); + GlobalData* globaldata; vector lookup; RAbundVector rabund; diff --git a/helpcommand.cpp b/helpcommand.cpp index a0b35d0..cb8785a 100644 --- a/helpcommand.cpp +++ b/helpcommand.cpp @@ -186,6 +186,16 @@ int HelpCommand::execute(){ cout << "The default value for groups is all the groups in your groupfile, iters is 10000, cutoff is 1.0, form is integral and step is 0.01." << "\n"; cout << "The libshuff command output two files: .coverage and .slsummary their descriptions are in the manual." << "\n"; cout << "Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e.yourIters)." << "\n" << "\n"; + }else if (globaldata->helpRequest == "heatmap") { + cout << "The heatmap command can only be executed after a successful read.otu command." << "\n"; + cout << "The heatmap command parameters are groups, line and label. No parameters are required, but you may not use line and label at the same time." << "\n"; + cout << "The groups parameter allows you to specify which of the groups in your groupfile you would like included in your heatmap." << "\n"; + cout << "The group names are separated by dashes. The line and label allow you to select what distance levels you would like a heatmap created for, and are also separated by dashes." << "\n"; + cout << "The heatmap command should be in the following format: heatmap(groups=yourGroups, line=yourLines, label=yourLabels)." << "\n"; + cout << "Example heatmap(groups=A-B-C, line=1-3-5)." << "\n"; + cout << "The default value for groups is all the groups in your groupfile, and all lines in your inputfile will be used." << "\n"; + cout << "The heatmap command outputs a .svg file for each line or label you specify." << "\n"; + cout << "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups)." << "\n" << "\n"; }else if (globaldata->helpRequest == "quit") { cout << "The quit command will terminate Dotur and should be in the following format: " << "\n"; cout << "quit()" << "\n" << "\n"; diff --git a/sharedanderbergs.cpp b/sharedanderbergs.cpp new file mode 100644 index 0000000..77888b5 --- /dev/null +++ b/sharedanderbergs.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 "sharedanderbergs.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/sharedanderbergs.h b/sharedanderbergs.h new file mode 100644 index 0000000..0443d02 --- /dev/null +++ b/sharedanderbergs.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/sharedrabundvector.cpp b/sharedrabundvector.cpp index 846f9cd..3d6a2de 100644 --- a/sharedrabundvector.cpp +++ b/sharedrabundvector.cpp @@ -186,8 +186,36 @@ void SharedRAbundVector::push_back(int binSize, int otu, string groupName){ } } + /***********************************************************************/ +void SharedRAbundVector::push_front(int binSize, int otu, string groupName){ + try { + individual newGuy; + newGuy.abundance = binSize; + newGuy.group = groupName; + newGuy.bin = otu; + + data.insert(data.begin(), newGuy); + numBins++; + + if(binSize > maxRank){ + maxRank = binSize; + } + + numSeqs += binSize; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function push_front. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SharedRAbundVector class function push_front. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/***********************************************************************/ void SharedRAbundVector::pop_back(){ return data.pop_back(); diff --git a/sharedrabundvector.h b/sharedrabundvector.h index 92f71cd..ab0c26a 100644 --- a/sharedrabundvector.h +++ b/sharedrabundvector.h @@ -48,7 +48,8 @@ public: int getAbundance(int); int numNZ(); void sortD(); //Sorts the data in descending order. - void push_back(int, int, string); //abundance, OTU, groupname + void push_front(int, int, string); //abundance, otu, groupname + void push_back(int, int, string); //abundance, otu, groupname void pop_back(); void resize(int); int size(); diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index 8b3a63f..526cd82 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -23,7 +23,7 @@ #include "sharedkstest.h" #include "sharedbdiversity.h" #include "sharedochiai.h" -//#include "sharedanderberg.h" +#include "sharedanderbergs.h" #include "sharedkulczynski.h" #include "sharedkulczynskicody.h" #include "sharedlennon.h" @@ -72,8 +72,8 @@ SummarySharedCommand::SummarySharedCommand(){ 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()); + }else if (globaldata->Estimators[i] == "sharedanderberg") { + sumCalculators.push_back(new SharedAnderberg()); }else if (globaldata->Estimators[i] == "sharedkulczynski") { sumCalculators.push_back(new SharedKulczynski()); }else if (globaldata->Estimators[i] == "sharedkulczynskicody") { diff --git a/validparameter.cpp b/validparameter.cpp index 9c8ce2e..6af6c15 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -223,22 +223,25 @@ void ValidParameters::initCommandParameters() { try { //{"parameter1","parameter2",...,"last parameter"}; - string readdistArray[] = {"phylip","name","cutoff","precision"}; + string readdistArray[] = {"phylip","column", "name","cutoff","precision"}; commandParameters["read.dist"] = addParameters(readdistArray, sizeof(readdistArray)/sizeof(string)); - string readotuArray[] = {"list","order","group","shared", "sabund"}; + string readotuArray[] = {"list","order","shared", "line", "label","group","shared", "sabund", "rabund"}; commandParameters["read.otu"] = addParameters(readotuArray, sizeof(readotuArray)/sizeof(string)); + string readtreeArray[] = {"tree","group"}; + commandParameters["read.tree"] = addParameters(readtreeArray, sizeof(readtreeArray)/sizeof(string)); + string clusterArray[] = {"cutoff","precision","method"}; commandParameters["cluster"] = addParameters(clusterArray, sizeof(clusterArray)/sizeof(string)); string deconvoluteArray[] = {"fasta"}; commandParameters["deconvolute"] = addParameters(deconvoluteArray, sizeof(deconvoluteArray)/sizeof(string)); - string collectsingleArray[] = {"freq","line","label","single","precision","abund"}; + string collectsingleArray[] = {"freq","line","label","calc","precision","abund"}; commandParameters["collect.single"] = addParameters(collectsingleArray, sizeof(collectsingleArray)/sizeof(string)); - string collectsharedArray[] = {"jumble","freq","line","label","shared","groups"}; + string collectsharedArray[] = {"jumble","freq","line","label","calc","groups"}; commandParameters["collect.shared"] = addParameters(collectsharedArray, sizeof(collectsharedArray)/sizeof(string)); string getgroupArray[] = {}; @@ -250,21 +253,33 @@ void ValidParameters::initCommandParameters() { string getlineArray[] = {}; commandParameters["get.line"] = addParameters(getlineArray, sizeof(getlineArray)/sizeof(string)); - string rarefactionsingleArray[] = {"iters","freq","line","label","rarefaction","abund"}; + string rarefactionsingleArray[] = {"iters","freq","line","label","calc","abund"}; commandParameters["rarefaction.single"] = addParameters(rarefactionsingleArray, sizeof(rarefactionsingleArray)/sizeof(string)); - string rarefactionsharedArray[] = {"iters","jumble","line","label","sharedrarefaction"}; + string rarefactionsharedArray[] = {"iters","jumble","line","label","calc"}; commandParameters["rarefaction.shared"] = addParameters(rarefactionsharedArray, sizeof(rarefactionsharedArray)/sizeof(string)); string libshuffArray[] = {"iters","groups","step","form","cutoff"}; commandParameters["libshuff"] = addParameters(libshuffArray, sizeof(libshuffArray)/sizeof(string)); - string summarysingleArray[] = {"line","label","summary","abund"}; + string summarysingleArray[] = {"line","label","calc","abund"}; commandParameters["summary.single"] = addParameters(summarysingleArray, sizeof(summarysingleArray)/sizeof(string)); - string summarysharedArray[] = {"jumble","line","label","sharedsummary"}; + string summarysharedArray[] = {"jumble","line","label","calc"}; commandParameters["summary.shared"] = addParameters(summarysharedArray, sizeof(summarysharedArray)/sizeof(string)); + string parsimonyArray[] = {"random","group","iters"}; + commandParameters["parsimony"] = addParameters(parsimonyArray, sizeof(parsimonyArray)/sizeof(string)); + + string unifracWeightedArray[] = {"group","iters"}; + commandParameters["unifrac.weighted"] = addParameters(unifracWeightedArray, sizeof(unifracWeightedArray)/sizeof(string)); + + string unifracUnweightedArray[] = {"group","iters"}; + commandParameters["unifrac.unweighted"] = addParameters(unifracUnweightedArray, sizeof(unifracUnweightedArray)/sizeof(string)); + + string heatmapArray[] = {"group","line","label"}; + commandParameters["heatmap"] = addParameters(heatmapArray, sizeof(heatmapArray)/sizeof(string)); + string quitArray[] = {}; commandParameters["quit"] = addParameters(quitArray, sizeof(quitArray)/sizeof(string)); -- 2.39.2