]> git.donarmstrong.com Git - mothur.git/blob - heatmap.cpp
started heatmap command
[mothur.git] / heatmap.cpp
1 /*
2  *  heatmap.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 3/25/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "heatmap.h"
11
12 //**********************************************************************************************************************
13 HeatMap::HeatMap(){
14         try {
15                 globaldata = GlobalData::getInstance();
16                 format = globaldata->getFormat();
17                 
18                 if (format != "list") {  setGroups();  }
19                 
20         }
21         catch(exception& e) {
22                 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function HeatMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
23                 exit(1);
24         }
25         catch(...) {
26                 cout << "An unknown error has occurred in the HeatMap class function HeatMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
27                 exit(1);
28         }
29 }
30 //**********************************************************************************************************************
31 void HeatMap::getPic(OrderVector* order) {
32         try {
33                 sabund = order->getSAbundVector();
34                 string filename = getRootName(globaldata->inputFileName) + order->getLabel();
35         }
36         catch(exception& e) {
37                 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
38                 exit(1);
39         }
40         catch(...) {
41                 cout << "An unknown error has occurred in the HeatMap class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
42                 exit(1);
43         }
44 }
45 //**********************************************************************************************************************
46 void HeatMap::getPic(SharedOrderVector* sharedorder) {
47         try {
48                 getSharedVectors(sharedorder);
49                 
50                 
51         }
52         catch(exception& e) {
53                 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
54                 exit(1);
55         }
56         catch(...) {
57                 cout << "An unknown error has occurred in the HeatMap class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
58                 exit(1);
59         }
60 }
61 //**********************************************************************************************************************
62 void HeatMap::getSharedVectors(SharedOrderVector* order){
63         try {
64                 lookup.clear();
65                 
66                 vector<SharedRAbundVector*> templookup;
67                 
68                 //create and initialize vector of sharedvectors, one for each group
69                 for (int i = 0; i < globaldata->Groups.size(); i++) { 
70                         SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
71                         temp->setLabel(order->getLabel());
72                         temp->setGroup(globaldata->Groups[i]);
73                         templookup.push_back(temp);
74                 }
75                 
76                 int numSeqs = order->size();
77                 //sample all the members
78                 for(int i=0;i<numSeqs;i++){
79                         //get first sample
80                         individual chosen = order->get(i);
81                         int abundance; 
82                                         
83                         //set info for sharedvector in chosens group
84                         for (int j = 0; j < templookup.size(); j++) { 
85                                 if (chosen.group == templookup[j]->getGroup()) {
86                                          abundance = templookup[j]->getAbundance(chosen.bin);
87                                          templookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
88                                          break;
89                                 }
90                         }
91                 }
92                 
93                 //convert templookups rabunds to lookups sabunds
94                 for (int j = 0; j < templookup.size(); j++) { 
95                         lookup.push_back(templookup[j]->getSharedSAbundVector());
96                         delete templookup[j];
97                 }
98                 
99                 
100         }
101         catch(exception& e) {
102                 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
103                 exit(1);
104         }
105         catch(...) {
106                 cout << "An unknown error has occurred in the HeatMap class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
107                 exit(1);
108         }
109
110 }
111
112 //**********************************************************************************************************************
113 void HeatMap::setGroups() {
114         try {
115                 //if the user has not entered specific groups to analyze then do them all
116                 if (globaldata->Groups.size() != 0) {
117                         if (globaldata->Groups[0] != "all") {
118                                 //check that groups are valid
119                                 for (int i = 0; i < globaldata->Groups.size(); i++) {
120                                         if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
121                                                 cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
122                                                 // erase the invalid group from globaldata->Groups
123                                                 globaldata->Groups.erase(globaldata->Groups.begin()+i);
124                                         }
125                                 }
126                         
127                                 //if the user only entered invalid groups
128                                 if (globaldata->Groups.size() == 0) { 
129                                         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; 
130                                         for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
131                                                 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
132                                         }
133                                 }
134                         }else{//user has enter "all" and wants the default groups
135                                 globaldata->Groups.clear();
136                                 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
137                                         globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
138                                 }
139                                 globaldata->setGroups("");
140                         }
141                 }else {
142                         for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
143                                 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
144                         }
145                 }
146                 
147         }
148         catch(exception& e) {
149                 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
150                 exit(1);
151         }
152         catch(...) {
153                 cout << "An unknown error has occurred in the HeatMap class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
154                 exit(1);
155         }               
156
157 }
158 /***********************************************************/