]> git.donarmstrong.com Git - mothur.git/commitdiff
started heatmap command
authorwestcott <westcott>
Wed, 25 Mar 2009 14:37:21 +0000 (14:37 +0000)
committerwestcott <westcott>
Wed, 25 Mar 2009 14:37:21 +0000 (14:37 +0000)
Mothur.xcodeproj/project.pbxproj
errorchecking.cpp
heatmap.cpp [new file with mode: 0644]
heatmap.h [new file with mode: 0644]
heatmapcommand.cpp [new file with mode: 0644]
heatmapcommand.h [new file with mode: 0644]
sharedjclass.cpp
sharedsorclass.cpp
validcommands.cpp
validparameter.cpp
validparameter.h

index 41493108bc37806da61b2b6e6d09479df92881e9..3c32966ef460ac5ac4617ae16014c43ebd0cc851 100644 (file)
@@ -24,6 +24,8 @@
                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 */; };
+               3765B5380F7A5A9E00C3EDC5 /* heatmapcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3765B5370F7A5A9E00C3EDC5 /* heatmapcommand.cpp */; };
+               3765B5460F7A62A000C3EDC5 /* heatmap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3765B5450F7A62A000C3EDC5 /* heatmap.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 */; };
                3765B4E10F78055000C3EDC5 /* sharedochiai.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedochiai.cpp; sourceTree = "<group>"; };
                3765B5140F780A7F00C3EDC5 /* sharedanderberg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedanderberg.h; sourceTree = "<group>"; };
                3765B5150F780A7F00C3EDC5 /* sharedanderberg.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedanderberg.cpp; sourceTree = "<group>"; };
+               3765B5360F7A5A9E00C3EDC5 /* heatmapcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = heatmapcommand.h; sourceTree = "<group>"; };
+               3765B5370F7A5A9E00C3EDC5 /* heatmapcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = heatmapcommand.cpp; sourceTree = "<group>"; };
+               3765B5440F7A62A000C3EDC5 /* heatmap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = heatmap.h; sourceTree = "<group>"; };
+               3765B5450F7A62A000C3EDC5 /* heatmap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = heatmap.cpp; sourceTree = "<group>"; };
                3782163B0F616079008E1F6D /* fullmatrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fullmatrix.h; sourceTree = "<group>"; };
                3782163C0F616079008E1F6D /* fullmatrix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fullmatrix.cpp; sourceTree = "<group>"; };
                379293C10F2DE73400B9034A /* treemap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = treemap.h; sourceTree = "<group>"; };
                                37D927DD0F21331F001D4494 /* fileoutput.cpp */,
                                37D927E00F21331F001D4494 /* globaldata.hpp */,
                                37D927DF0F21331F001D4494 /* globaldata.cpp */,
+                               3765B5440F7A62A000C3EDC5 /* heatmap.h */,
+                               3765B5450F7A62A000C3EDC5 /* heatmap.cpp */,
                                37D927E60F21331F001D4494 /* inputdata.h */,
                                37D927E50F21331F001D4494 /* inputdata.cpp */,
                                37D927EA0F21331F001D4494 /* kmer.hpp */,
                                A70B53A60F4CD7AD0064797E /* getlabelcommand.cpp */,
                                A70B53A90F4CD7AD0064797E /* getlinecommand.h */,
                                A70B53A80F4CD7AD0064797E /* getlinecommand.cpp */,
+                               3765B5360F7A5A9E00C3EDC5 /* heatmapcommand.h */,
+                               3765B5370F7A5A9E00C3EDC5 /* heatmapcommand.cpp */,
                                37D927E40F21331F001D4494 /* helpcommand.h */,
                                37D927E30F21331F001D4494 /* helpcommand.cpp */,
                                374CD63D0F65832000D90B4A /* libshuffcommand.h */,
                                217595590F792490001CC3C6 /* sharedlennon.cpp in Sources */,
                                217595640F7927BB001CC3C6 /* sharedmorisitahorn.cpp in Sources */,
                                217595710F792A33001CC3C6 /* sharedbraycurtis.cpp in Sources */,
+                               3765B5380F7A5A9E00C3EDC5 /* heatmapcommand.cpp in Sources */,
+                               3765B5460F7A62A000C3EDC5 /* heatmap.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index cb2dce42fbf4f40e4c5e2a5107a6e1d33c1b89c7..b9b3100b20f6b840f5f296964a7dc6f8aefd5d3d 100644 (file)
@@ -218,6 +218,12 @@ bool ErrorCheck::checkInput(string input) {
                                else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared or summary.shared commands." << endl; return false; }
                        }
                }
+               
+               if (commandName == "heatmap"){ 
+                       if ((globaldata->getListFile() == "") && (globaldata->getSharedFile() == "")) {
+                                cout << "You must read a list, or a list and a group, or a shared before you can use the heatmap command." << endl; return false; 
+                       }
+               }
 
                return errorFree;
 }
diff --git a/heatmap.cpp b/heatmap.cpp
new file mode 100644 (file)
index 0000000..5a02b9a
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ *  heatmap.cpp
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 3/25/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "heatmap.h"
+
+//**********************************************************************************************************************
+HeatMap::HeatMap(){
+       try {
+               globaldata = GlobalData::getInstance();
+               format = globaldata->getFormat();
+               
+               if (format != "list") {  setGroups();  }
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function HeatMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the HeatMap class function HeatMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+void HeatMap::getPic(OrderVector* order) {
+       try {
+               sabund = order->getSAbundVector();
+               string filename = getRootName(globaldata->inputFileName) + order->getLabel();
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the HeatMap class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+void HeatMap::getPic(SharedOrderVector* sharedorder) {
+       try {
+               getSharedVectors(sharedorder);
+               
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the HeatMap class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+void HeatMap::getSharedVectors(SharedOrderVector* order){
+       try {
+               lookup.clear();
+               
+               vector<SharedRAbundVector*> templookup;
+               
+               //create and initialize vector of sharedvectors, one for each group
+               for (int i = 0; i < globaldata->Groups.size(); i++) { 
+                       SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
+                       temp->setLabel(order->getLabel());
+                       temp->setGroup(globaldata->Groups[i]);
+                       templookup.push_back(temp);
+               }
+               
+               int numSeqs = order->size();
+               //sample all the members
+               for(int i=0;i<numSeqs;i++){
+                       //get first sample
+                       individual chosen = order->get(i);
+                       int abundance; 
+                                       
+                       //set info for sharedvector in chosens group
+                       for (int j = 0; j < templookup.size(); j++) { 
+                               if (chosen.group == templookup[j]->getGroup()) {
+                                        abundance = templookup[j]->getAbundance(chosen.bin);
+                                        templookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
+                                        break;
+                               }
+                       }
+               }
+               
+               //convert templookups rabunds to lookups sabunds
+               for (int j = 0; j < templookup.size(); j++) { 
+                       lookup.push_back(templookup[j]->getSharedSAbundVector());
+                       delete templookup[j];
+               }
+               
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the HeatMap class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+
+//**********************************************************************************************************************
+void HeatMap::setGroups() {
+       try {
+               //if the user has not entered specific groups to analyze then do them all
+               if (globaldata->Groups.size() != 0) {
+                       if (globaldata->Groups[0] != "all") {
+                               //check that groups are valid
+                               for (int i = 0; i < globaldata->Groups.size(); i++) {
+                                       if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
+                                               cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
+                                               // erase the invalid group from globaldata->Groups
+                                               globaldata->Groups.erase(globaldata->Groups.begin()+i);
+                                       }
+                               }
+                       
+                               //if the user only entered invalid groups
+                               if (globaldata->Groups.size() == 0) { 
+                                       cout << "When using the groups parameter you must have at least 1 valid groups. I will run the command using all the groups in your groupfile." << endl; 
+                                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
+                                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
+                                       }
+                               }
+                       }else{//user has enter "all" and wants the default groups
+                               globaldata->Groups.clear();
+                               for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
+                                       globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
+                               }
+                               globaldata->setGroups("");
+                       }
+               }else {
+                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
+                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
+                       }
+               }
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the HeatMap class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+
+}
+/***********************************************************/
diff --git a/heatmap.h b/heatmap.h
new file mode 100644 (file)
index 0000000..fe79e43
--- /dev/null
+++ b/heatmap.h
@@ -0,0 +1,45 @@
+#ifndef HEATMAP_H
+#define HEATMAP_H
+/*
+ *  heatmap.h
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 3/25/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+using namespace std;
+
+#include "ordervector.hpp"
+#include "sabundvector.hpp"
+#include "sharedsabundvector.h"
+#include "sharedordervector.h"
+#include "datavector.hpp"
+#include "globaldata.hpp"
+
+/***********************************************************************/
+
+class HeatMap {
+       
+       public:
+               HeatMap();
+               ~HeatMap(){};
+       
+               void getPic(OrderVector*);
+               void getPic(SharedOrderVector*);
+
+       private:
+               void getSharedVectors(SharedOrderVector*);
+               void setGroups();
+       
+               GlobalData* globaldata;
+               vector<SharedSAbundVector> lookup;
+               SAbundVector sabund;
+               string format;
+
+                       
+};
+
+#endif
+
diff --git a/heatmapcommand.cpp b/heatmapcommand.cpp
new file mode 100644 (file)
index 0000000..5da80d8
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ *  heatmapcommand.cpp
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 3/25/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "heatmapcommand.h"
+
+
+//**********************************************************************************************************************
+
+HeatMapCommand::HeatMapCommand(){
+       try {
+               globaldata = GlobalData::getInstance();
+               format = globaldata->getFormat();
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the HeatMapCommand class Function HeatMapCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the HeatMapCommand class function HeatMapCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+//**********************************************************************************************************************
+
+HeatMapCommand::~HeatMapCommand(){
+       delete input;
+       delete read;
+}
+
+//**********************************************************************************************************************
+
+int HeatMapCommand::execute(){
+       try {
+               int count = 1;  
+               
+               if (format == "sharedfile") {
+                       //you have groups
+                       read = new ReadPhilFile(globaldata->inputFileName);     
+                       read->read(&*globaldata); 
+                       
+                       input = globaldata->ginput;
+                       order = input->getSharedOrderVector();
+               }else if (format == "shared") {
+                       //you are using a list and a groupfile
+                       read = new ReadPhilFile(globaldata->inputFileName);     
+                       read->read(&*globaldata); 
+               
+                       input = globaldata->ginput;
+                       SharedList = globaldata->gSharedList;
+                       order = SharedList->getSharedOrderVector();
+               }else if (format == "list") {
+                       //you are using just a list file and have only one group
+                       read = new ReadPhilFile(globaldata->inputFileName);     
+                       read->read(&*globaldata); 
+               
+                       ordersingle = globaldata->gorder;
+                       input = globaldata->ginput;
+               }
+               
+               if (format != "list") { 
+                       while(order != NULL){
+               
+                               if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){                       
+       
+                                       cout << order->getLabel() << '\t' << count << endl;
+//call heatmap class to make file
+                               }
+                                               
+                               //get next line to process
+                               if (format == "sharedfile") {
+                                       order = input->getSharedOrderVector();
+                               }else {
+                                       //you are using a list and a groupfile
+                                       SharedList = input->getSharedListVector(); //get new list vector to process
+                                       if (SharedList != NULL) {
+                                               order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
+                                       }else {
+                                               break;
+                                       }
+                               }
+                               count++;
+                       }
+                       
+                       //reset groups parameter
+                       globaldata->Groups.clear();  globaldata->setGroups("");
+                       
+               }else{
+                       while(ordersingle != NULL){
+               
+                               if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){                       
+       
+                                       cout << order->getLabel() << '\t' << count << endl;
+//call heatmap class to make file
+                               }
+                               
+                               ordersingle = (input->getOrderVector());
+                               count++;
+                       }
+               }
+               
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the HeatMapCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the HeatMapCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+//**********************************************************************************************************************
+
diff --git a/heatmapcommand.h b/heatmapcommand.h
new file mode 100644 (file)
index 0000000..1b3c108
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef HEATMAPCOMMAND_H
+#define HEATMAPCOMMAND_H
+
+/*
+ *  heatmapcommand.h
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 3/25/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+
+#include "command.hpp"
+#include "inputdata.h"
+#include "readmatrix.hpp"
+#include "sharedlistvector.h"
+
+
+class GlobalData;
+
+
+class HeatMapCommand : public Command {
+
+public:
+       HeatMapCommand();
+       ~HeatMapCommand();
+       int execute();
+       
+private:
+       GlobalData* globaldata;
+       ReadMatrix* read;
+       InputData* input;
+       SharedListVector* SharedList;
+       SharedOrderVector* order;
+       OrderVector* ordersingle;
+       string format;
+
+};
+
+#endif
+
index 6557a0f16b8d4eab412d82616e8d74cb99374b86..2c7d8c9422d4c4c95b74374f05e5f7b0291aa2d9 100644 (file)
@@ -25,9 +25,10 @@ EstOutput SharedJclass::getValues(SharedRAbundVector* shared1, SharedRAbundVecto
                        //store in temps to avoid multiple repetitive function calls
                        tempA = shared1->getAbundance(i);
                        tempB = shared2->getAbundance(i);
-
-                       S1 += tempA;
-                       S2 += tempB;
+                       
+                       //find number of bins in shared1 and shared2
+                       if (tempA != 0) { S1++; }
+                       if (tempB != 0) { S2++; } 
                        
                        //they are shared
                        if ((tempA != 0) && (tempB != 0)) {     S12++; }
index c9debf7748662b8ebc2464f3d2e70fd7610a72ce..81d8d86b7d295502dc2d75b85cd5accdbc167cdc 100644 (file)
@@ -26,8 +26,9 @@ EstOutput SharedSorClass::getValues(SharedRAbundVector* shared1, SharedRAbundVec
                        tempA = shared1->getAbundance(i);
                        tempB = shared2->getAbundance(i);
 
-                       S1 += tempA;
-                       S2 += tempB;
+                       //find number of bins in shared1 and shared2
+                       if (tempA != 0) { S1++; }
+                       if (tempB != 0) { S2++; } 
                        
                        //they are shared
                        if ((tempA != 0) && (tempB != 0)) {     S12++; }
index b2e07acae111e10f0324b95b18ca74034249315b..2127758094b2e3cff802fd567ec78ad522c7fd8a 100644 (file)
@@ -29,6 +29,7 @@ ValidCommands::ValidCommands() {
                commands["unifrac.weighted"]    = "unifrac.weighted"; 
                commands["unifrac.unweighted"]  = "unifrac.unweighted"; 
                commands["libshuff"]                    = "libshuff";
+               commands["heatmap"]                             = "heatmap";
                commands["get.group"]           = "get.group";
                commands["get.label"]           = "get.label";
                commands["get.line"]            = "get.line";
index 61fd0445e81f9ae277f3c54f9c69ce313646e66d..6d325f7ccc8c7dd2d51a72c787d84f4902f7ce74 100644 (file)
@@ -214,6 +214,18 @@ bool ValidParameters::isValidParameter(string parameter, string command) {
                                }
                                cout << endl;
                                return false; }
+               }else if (command == "heatmap") {
+                       //is it valid
+                       if ((heatmap.find(parameter)) != (heatmap.end())) {
+                               return true;
+                       }else { 
+                               cout << parameter << " is not a valid parameter for the " + command + " command. Valid parameters are ";
+                               for (it = heatmap.begin(); it != heatmap.end(); it++) {
+                                       cout << it->first << ", ";
+                               }
+                               cout << endl;
+                               return false; }
+
                //not a valid paramter
                }else if (command == "help") { cout << parameter << " is not a valid parameter for the " + command + " command. There are no vaild parameters." << endl;  
                }else if (command == "quit") { cout << parameter << " is not a valid parameter for the " + command + " command. There are no vaild parameters." << endl; 
@@ -339,3 +351,9 @@ void ValidParameters::initialLibshuff() {
        libshuff["form"]                = "form";
 }
 /***********************************************************************/
+void ValidParameters::initialHeatmap() {
+       heatmap["label"]        = "label"; 
+       heatmap["line"]         = "line";
+}
+
+/***********************************************************************/
index c59c1571e38d5b4ffba3004dd19957752d4339bb..b3d56e5c7eb0a69c0e4e0e4fdc9b3b224a2e225b 100644 (file)
@@ -41,6 +41,7 @@ class ValidParameters {
                map<string, string> unifracweighted;
                map<string, string> unifracunweighted;
                map<string, string> libshuff;
+               map<string, string> heatmap;
                
                map<string, string>::iterator it;
                
@@ -59,6 +60,7 @@ class ValidParameters {
                void initialUnifracweighted();
                void initialUnifracunweighted();
                void initialLibshuff();
+               void initialHeatmap();
 
 };