]> git.donarmstrong.com Git - mothur.git/commitdiff
added sort to heatmap to put shared otus at the top and updated some error checking
authorwestcott <westcott>
Mon, 30 Mar 2009 13:31:37 +0000 (13:31 +0000)
committerwestcott <westcott>
Mon, 30 Mar 2009 13:31:37 +0000 (13:31 +0000)
Mothur.xcodeproj/project.pbxproj
collectsharedcommand.cpp
heatmap.cpp
heatmap.h
helpcommand.cpp
sharedanderbergs.cpp [new file with mode: 0644]
sharedanderbergs.h [new file with mode: 0644]
sharedrabundvector.cpp
sharedrabundvector.h
summarysharedcommand.cpp
validparameter.cpp

index b5cb3f107a6d0b6cba7f9d0f3d493a4a438d8f2a..e71f9ce250b4f4c692b5b9cae6e4b73dbfe82fc1 100644 (file)
@@ -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 */; };
                374610820F40652400460C57 /* unweighted.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unweighted.cpp; sourceTree = "<group>"; };
                3746109B0F40657600460C57 /* unifracunweightedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unifracunweightedcommand.h; sourceTree = "<group>"; };
                3746109C0F40657600460C57 /* unifracunweightedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unifracunweightedcommand.cpp; sourceTree = "<group>"; };
+               37519A690F80E6EB00FED5E8 /* sharedanderbergs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedanderbergs.h; sourceTree = "<group>"; };
+               37519A6A0F80E6EB00FED5E8 /* sharedanderbergs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedanderbergs.cpp; sourceTree = "<group>"; };
                375873E50F7D63E90040F377 /* coverage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = coverage.cpp; sourceTree = "<group>"; };
                375873E60F7D63E90040F377 /* coverage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = coverage.h; sourceTree = "<group>"; };
                375873EA0F7D64520040F377 /* fullmatrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fullmatrix.h; sourceTree = "<group>"; };
                                37D9281E0F21331F001D4494 /* shannon.cpp */,
                                37D928230F21331F001D4494 /* sharedace.h */,
                                37D928220F21331F001D4494 /* sharedace.cpp */,
+                               37519A690F80E6EB00FED5E8 /* sharedanderbergs.h */,
+                               37519A6A0F80E6EB00FED5E8 /* sharedanderbergs.cpp */,
                                375873FB0F7D64DA0040F377 /* sharedbraycurtis.h */,
                                375873FC0F7D64DA0040F377 /* sharedbraycurtis.cpp */,
                                EB6F01590F6AC1670048081A /* sharedbdiversity.h */,
                                375874060F7D64EF0040F377 /* sharedkulczynskicody.cpp in Sources */,
                                3758740C0F7D64FC0040F377 /* sharedmorisitahorn.cpp in Sources */,
                                3758740D0F7D64FC0040F377 /* sharedochiai.cpp in Sources */,
+                               37519A6B0F80E6EB00FED5E8 /* sharedanderbergs.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 3c1ad527c1ce7e881305fb79bf08b027058e9113..ec35dd601e75abd3ea7b65e32aabcaa1c13b1c90 100644 (file)
@@ -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") { 
index fb070567da4bb6f05c95111d067a7795d45b2239..86786e7e309dd718a4c4476d8745c9a0a0cd6f20 100644 (file)
@@ -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<SharedRAbundVector*> 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);
+       }
+
+}
+
 //**********************************************************************************************************************
 
 
 
+
+
index 0678aa0827b8765f72c5012dfc3fa18522d995a6..c26684e3cd832b3c57d0671cb0bb11e8983e247c 100644 (file)
--- a/heatmap.h
+++ b/heatmap.h
@@ -31,7 +31,8 @@ class HeatMap {
 
        private:
                void getSharedVectors(SharedOrderVector*);
-       
+               void sortSharedVectors();
+               
                GlobalData* globaldata;
                vector<SharedRAbundVector*> lookup;
                RAbundVector rabund;
index a0b35d0a34f8ffda7be2c25df53307622fddb65b..cb8785acd54ded4493230cddcb364509b2d92d97 100644 (file)
@@ -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 (file)
index 0000000..77888b5
--- /dev/null
@@ -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 (file)
index 0000000..0443d02
--- /dev/null
@@ -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
index 846f9cdb705c7a801097feaeca59272d4001d361..3d6a2debbc05540cb5d4cb38cba1dab5638c7346 100644 (file)
@@ -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();
index 92f71cdd75eca67df59f1f5cc548e61fe162b41e..ab0c26ad807928a13fbf7c7a6c256c82a7efa719 100644 (file)
@@ -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();
index 8b3a63f8688e557f290aa9db1acda63ae4de5426..526cd8292e2082eccf96c2c25f82c8a4709267e5 100644 (file)
@@ -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") { 
index 9c8ce2e89136a671d775cb6b41484b3bc6cc869a..6af6c15e313975ade4d17d6bd91141defbf205fc 100644 (file)
@@ -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));