]> git.donarmstrong.com Git - mothur.git/blob - heatmap.cpp
heatmap
[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) + "heatmap" + 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                 //fills vector of sharedsabunds - lookup
49                 getSharedVectors(sharedorder);
50                 
51                 string filename = getRootName(globaldata->inputFileName) + "heatmap" + sharedorder->getLabel();
52                 
53                 
54         }
55         catch(exception& e) {
56                 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
57                 exit(1);
58         }
59         catch(...) {
60                 cout << "An unknown error has occurred in the HeatMap class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
61                 exit(1);
62         }
63 }
64 //**********************************************************************************************************************
65 void HeatMap::getSharedVectors(SharedOrderVector* order){
66         try {
67                 lookup.clear();
68                 
69                 vector<SharedRAbundVector*> templookup;
70                 
71                 //create and initialize vector of sharedvectors, one for each group
72                 for (int i = 0; i < globaldata->Groups.size(); i++) { 
73                         SharedRAbundVector* temp = new SharedRAbundVector(order->getMaxRank());
74                         temp->setLabel(order->getLabel());
75                         temp->setGroup(globaldata->Groups[i]);
76                         templookup.push_back(temp);
77                 }
78                 
79                 int numSeqs = order->size();
80                 //sample all the members
81                 for(int i=0;i<numSeqs;i++){
82                         //get first sample
83                         individual chosen = order->get(i);
84                         int abundance; 
85                                         
86                         //set info for sharedvector in chosens group
87                         for (int j = 0; j < templookup.size(); j++) { 
88                                 if (chosen.group == templookup[j]->getGroup()) {
89                                          abundance = templookup[j]->getAbundance(chosen.bin);
90                                          templookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
91                                          break;
92                                 }
93                         }
94                 }
95                 
96                 //convert templookups rabunds to lookups sabunds
97                 for (int j = 0; j < templookup.size(); j++) { 
98                         lookup.push_back(templookup[j]->getSharedSAbundVector());
99                         delete templookup[j];
100                 }
101                 
102                 
103         }
104         catch(exception& e) {
105                 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
106                 exit(1);
107         }
108         catch(...) {
109                 cout << "An unknown error has occurred in the HeatMap class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
110                 exit(1);
111         }
112
113 }
114
115 //**********************************************************************************************************************
116 void HeatMap::setGroups() {
117         try {
118                 //if the user has not entered specific groups to analyze then do them all
119                 if (globaldata->Groups.size() != 0) {
120                         if (globaldata->Groups[0] != "all") {
121                                 //check that groups are valid
122                                 for (int i = 0; i < globaldata->Groups.size(); i++) {
123                                         if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
124                                                 cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
125                                                 // erase the invalid group from globaldata->Groups
126                                                 globaldata->Groups.erase(globaldata->Groups.begin()+i);
127                                         }
128                                 }
129                         
130                                 //if the user only entered invalid groups
131                                 if (globaldata->Groups.size() == 0) { 
132                                         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; 
133                                         for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
134                                                 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
135                                         }
136                                 }
137                         }else{//user has enter "all" and wants the default groups
138                                 globaldata->Groups.clear();
139                                 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
140                                         globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
141                                 }
142                                 globaldata->setGroups("");
143                         }
144                 }else {
145                         for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
146                                 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
147                         }
148                 }
149                 
150         }
151         catch(exception& e) {
152                 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
153                 exit(1);
154         }
155         catch(...) {
156                 cout << "An unknown error has occurred in the HeatMap class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
157                 exit(1);
158         }               
159
160 }
161 /***********************************************************/