From: westcott Date: Wed, 25 Mar 2009 14:37:21 +0000 (+0000) Subject: started heatmap command X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=485c02be0cdcd06ce08dd58d551a525b6a1b47c5 started heatmap command --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 4149310..3c32966 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -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 */; }; @@ -157,6 +159,10 @@ 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 = ""; }; + 3765B5360F7A5A9E00C3EDC5 /* heatmapcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = heatmapcommand.h; sourceTree = ""; }; + 3765B5370F7A5A9E00C3EDC5 /* heatmapcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = heatmapcommand.cpp; sourceTree = ""; }; + 3765B5440F7A62A000C3EDC5 /* heatmap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = heatmap.h; sourceTree = ""; }; + 3765B5450F7A62A000C3EDC5 /* heatmap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = heatmap.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 = ""; }; @@ -382,6 +388,8 @@ 37D927DD0F21331F001D4494 /* fileoutput.cpp */, 37D927E00F21331F001D4494 /* globaldata.hpp */, 37D927DF0F21331F001D4494 /* globaldata.cpp */, + 3765B5440F7A62A000C3EDC5 /* heatmap.h */, + 3765B5450F7A62A000C3EDC5 /* heatmap.cpp */, 37D927E60F21331F001D4494 /* inputdata.h */, 37D927E50F21331F001D4494 /* inputdata.cpp */, 37D927EA0F21331F001D4494 /* kmer.hpp */, @@ -519,6 +527,8 @@ A70B53A60F4CD7AD0064797E /* getlabelcommand.cpp */, A70B53A90F4CD7AD0064797E /* getlinecommand.h */, A70B53A80F4CD7AD0064797E /* getlinecommand.cpp */, + 3765B5360F7A5A9E00C3EDC5 /* heatmapcommand.h */, + 3765B5370F7A5A9E00C3EDC5 /* heatmapcommand.cpp */, 37D927E40F21331F001D4494 /* helpcommand.h */, 37D927E30F21331F001D4494 /* helpcommand.cpp */, 374CD63D0F65832000D90B4A /* libshuffcommand.h */, @@ -757,6 +767,8 @@ 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; }; diff --git a/errorchecking.cpp b/errorchecking.cpp index cb2dce4..b9b3100 100644 --- a/errorchecking.cpp +++ b/errorchecking.cpp @@ -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 index 0000000..5a02b9a --- /dev/null +++ b/heatmap.cpp @@ -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 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;iget(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 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 lookup; + SAbundVector sabund; + string format; + + +}; + +#endif + diff --git a/heatmapcommand.cpp b/heatmapcommand.cpp new file mode 100644 index 0000000..5da80d8 --- /dev/null +++ b/heatmapcommand.cpp @@ -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 index 0000000..1b3c108 --- /dev/null +++ b/heatmapcommand.h @@ -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 + diff --git a/sharedjclass.cpp b/sharedjclass.cpp index 6557a0f..2c7d8c9 100644 --- a/sharedjclass.cpp +++ b/sharedjclass.cpp @@ -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++; } diff --git a/sharedsorclass.cpp b/sharedsorclass.cpp index c9debf7..81d8d86 100644 --- a/sharedsorclass.cpp +++ b/sharedsorclass.cpp @@ -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++; } diff --git a/validcommands.cpp b/validcommands.cpp index b2e07ac..2127758 100644 --- a/validcommands.cpp +++ b/validcommands.cpp @@ -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"; diff --git a/validparameter.cpp b/validparameter.cpp index 61fd044..6d325f7 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -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"; +} + +/***********************************************************************/ diff --git a/validparameter.h b/validparameter.h index c59c157..b3d56e5 100644 --- a/validparameter.h +++ b/validparameter.h @@ -41,6 +41,7 @@ class ValidParameters { map unifracweighted; map unifracunweighted; map libshuff; + map heatmap; map::iterator it; @@ -59,6 +60,7 @@ class ValidParameters { void initialUnifracweighted(); void initialUnifracunweighted(); void initialLibshuff(); + void initialHeatmap(); };