]> git.donarmstrong.com Git - mothur.git/blob - globaldata.cpp
58d00ffbee1166e3422cf070978c8c97fa964cc1
[mothur.git] / globaldata.cpp
1
2
3 #include "globaldata.hpp"
4 #include "sharedlistvector.h"
5 #include "inputdata.h"
6 #include "fullmatrix.h"
7
8 /*******************************************************/
9
10 /******************************************************/
11 GlobalData* GlobalData::getInstance() {
12         if( _uniqueInstance == 0) {
13                 _uniqueInstance = new GlobalData();
14         }
15         return _uniqueInstance;
16 }
17 /*******************************************************/
18
19 /******************************************************/
20 // These functions give you the option parameters of the commands
21 string GlobalData::getPhylipFile()              {       return phylipfile;              }
22 string GlobalData::getColumnFile()              {       return columnfile;              }
23 string GlobalData::getListFile()                {       return listfile;                }
24 string GlobalData::getRabundFile()              {       return rabundfile;              }
25 string GlobalData::getSabundFile()              {       return sabundfile;              }
26 string GlobalData::getNameFile()                {       return namefile;                }
27 string GlobalData::getGroupFile()               {       return groupfile;               }
28 string GlobalData::getOrderFile()               {       return orderfile;               }
29 string GlobalData::getTreeFile()                {       return treefile;                }
30 string GlobalData::getSharedFile()              {       return sharedfile;              }       
31 string GlobalData::getFormat()                  {       return format;                  }
32
33 void GlobalData::setListFile(string file)               {       listfile = file;        inputFileName = file;                                   }
34 void GlobalData::setTreeFile(string file)               {       treefile = file;        inputFileName = file;                                   }
35 void GlobalData::setRabundFile(string file)             {       rabundfile = file;      inputFileName = file;                                   }
36 void GlobalData::setSabundFile(string file)             {       sabundfile = file;      inputFileName = file;                                   }
37 void GlobalData::setPhylipFile(string file)             {       phylipfile = file;    inputFileName = file;                                     }
38 void GlobalData::setColumnFile(string file)             {       columnfile = file;    inputFileName = file;                                     }
39 void GlobalData::setGroupFile(string file)              {       groupfile = file;                                                                                       }
40 void GlobalData::setSharedFile(string file)             {       sharedfile = file;      inputFileName = file;                                   }
41 void GlobalData::setNameFile(string file)               {       namefile = file;                }
42 void GlobalData::setOrderFile(string file)              {       orderfile = file;               }
43 void GlobalData::setFormat(string Format)               {       format = Format;                }
44
45
46 /*******************************************************/
47
48 /******************************************************/
49 GlobalData::GlobalData() {
50         m = MothurOut::getInstance();
51         //option definitions should go here...
52         clear();
53         gListVector = NULL;             
54         gSparseMatrix = NULL;   
55         ginput = NULL;
56         gorder = NULL;
57         glist = NULL;
58         gSharedList = NULL;
59         sabund = NULL;
60         rabund = NULL;
61         gGroupmap = NULL;
62         gMatrix = NULL;
63         gTreemap = NULL;
64         gSequenceDB = NULL;
65         nameMap = NULL;
66 }
67 /*******************************************************/
68
69 /******************************************************/
70 void GlobalData::clear() {
71         //option definitions should go here...
72         phylipfile              =       ""; //do we need this?
73         columnfile              =       ""; //do we need this?
74         listfile                =       "";
75         rabundfile              =       "";
76         sabundfile              =       "";
77         namefile                =       ""; //do we need this?
78         groupfile               =       ""; //do we need this?
79         orderfile               =       "";
80 //      fastafile               =   ""; //do we need this?
81         treefile                =       "";
82         sharedfile              =       "";
83 }
84
85
86 /*******************************************************/
87
88 /******************************************************/
89 void GlobalData::newRead() {
90         try{    
91                         //remove old file names
92                         clear();
93                         
94                         //free memory
95                         if (gGroupmap != NULL) { delete gGroupmap; gGroupmap = NULL; }
96
97                         if (gListVector != NULL) { delete gListVector; gListVector = NULL;}
98
99                         if (gSparseMatrix != NULL) { delete gSparseMatrix; gSparseMatrix = NULL; }
100
101                         if (ginput != NULL) { delete ginput; ginput = NULL;}
102
103                         if (gorder != NULL) { delete gorder; gorder = NULL; }
104
105                         if (glist != NULL) { delete glist; glist = NULL;}
106
107                         if (gSharedList != NULL) { delete gSharedList; gSharedList = NULL; }
108
109                         if (sabund != NULL) { delete sabund; sabund = NULL;}
110
111                         if (rabund != NULL) { delete rabund; rabund = NULL; }
112
113                         if (gMatrix != NULL) { delete gMatrix; gMatrix = NULL;}
114
115                         if (gTreemap != NULL) { delete gTreemap; gTreemap = NULL; }
116
117                         if (gSequenceDB != NULL) { delete gSequenceDB; gSequenceDB = NULL;}
118                         
119                         if (nameMap != NULL) { delete nameMap; nameMap = NULL; }
120
121
122                         gTree.clear();
123                         Treenames.clear();
124                         labels.clear(); Groups.clear();
125                         allLines = 1;
126                         runParse = true;
127                         names.clear();
128         }
129         catch(exception& e) {
130                 m->errorOut(e, "GlobalData", "newRead");
131                 exit(1);
132         }
133 }
134
135 //******************************************************/
136
137 /******************************************************/
138 GlobalData::~GlobalData() {
139         _uniqueInstance = 0;
140         try {
141                 if (gGroupmap != NULL) { delete gGroupmap; gGroupmap = NULL; }
142                 if (gListVector != NULL) { delete gListVector; gListVector = NULL;}
143                 if (gSparseMatrix != NULL) { delete gSparseMatrix; gSparseMatrix = NULL; }
144                 if (ginput != NULL) { delete ginput; ginput = NULL;}
145                 if (gorder != NULL) { delete gorder; gorder = NULL; }
146                 if (glist != NULL) { delete glist; glist = NULL;}
147                 if (gSharedList != NULL) { delete gSharedList; gSharedList = NULL; }
148                 if (sabund != NULL) { delete sabund; sabund = NULL;}
149                 if (rabund != NULL) { delete rabund; rabund = NULL; }
150                 if (gMatrix != NULL) { delete gMatrix; gMatrix = NULL;}
151                 if (gTreemap != NULL) { delete gTreemap; gTreemap = NULL; }
152                 if (gSequenceDB != NULL) { delete gSequenceDB; gSequenceDB = NULL;}
153                 if (nameMap != NULL) { delete nameMap; nameMap = NULL; }
154         }
155         catch(exception& e) {
156                 m->errorOut(e, "GlobalData", "~GlobalData");
157                 exit(1);
158         }
159 }
160 /*******************************************************/
161
162 /*******************************************************/
163
164