]> git.donarmstrong.com Git - mothur.git/blob - globaldata.cpp
affa4636ab4716746665b6b7c73ccccf1f7b9354
[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::getOrderGroupFile()  {       return ordergroup;              }
30 string GlobalData::getTreeFile()                {       return treefile;                }
31 string GlobalData::getSharedFile()              {       return sharedfile;              }       
32 string GlobalData::getFormat()                  {       return format;                  }
33
34 void GlobalData::setListFile(string file)               {       listfile = file;        inputFileName = file;                                   }
35 void GlobalData::setTreeFile(string file)               {       treefile = file;        inputFileName = file;                                   }
36 void GlobalData::setRabundFile(string file)             {       rabundfile = file;      inputFileName = file;                                   }
37 void GlobalData::setSabundFile(string file)             {       sabundfile = file;      inputFileName = file;                                   }
38 void GlobalData::setPhylipFile(string file)             {       phylipfile = file;    inputFileName = file;                                     }
39 void GlobalData::setColumnFile(string file)             {       columnfile = file;    inputFileName = file;                                     }
40 void GlobalData::setGroupFile(string file)              {       groupfile = file;                                                                                       }
41 void GlobalData::setSharedFile(string file)             {       sharedfile = file;      inputFileName = file;                                   }
42 void GlobalData::setNameFile(string file)               {       namefile = file;                }
43 void GlobalData::setOrderFile(string file)              {       orderfile = file;               }
44 void GlobalData::setOrderGroupFile(string file) {       ordergroup = file;              }
45 void GlobalData::setFormat(string Format)               {       format = Format;                }
46
47
48 /*******************************************************/
49
50 /******************************************************/
51 GlobalData::GlobalData() {
52         m = MothurOut::getInstance();
53         //option definitions should go here...
54         clear();
55         gListVector = NULL;             
56         gSparseMatrix = NULL;   
57         ginput = NULL;
58         gorder = NULL;
59         glist = NULL;
60         gSharedList = NULL;
61         sabund = NULL;
62         rabund = NULL;
63         gGroupmap = NULL;
64         gMatrix = NULL;
65         gTreemap = NULL;
66         gSequenceDB = NULL;
67         nameMap = NULL;
68 }
69 /*******************************************************/
70
71 /******************************************************/
72 void GlobalData::clear() {
73         //option definitions should go here...
74         phylipfile              =       ""; //do we need this?
75         columnfile              =       ""; //do we need this?
76         listfile                =       "";
77         rabundfile              =       "";
78         sabundfile              =       "";
79         namefile                =       ""; //do we need this?
80         groupfile               =       ""; //do we need this?
81         orderfile               =       "";
82         ordergroup              =       "";
83 //      fastafile               =   ""; //do we need this?
84         treefile                =       "";
85         sharedfile              =       "";
86         format = "";
87 }
88
89
90 /*******************************************************/
91
92 /******************************************************/
93 void GlobalData::newRead() {
94         try{    
95                         //remove old file names
96                         clear();
97                         
98                         //free memory
99                         if (gGroupmap != NULL) { delete gGroupmap; gGroupmap = NULL; }
100
101                         if (gListVector != NULL) { delete gListVector; gListVector = NULL;}
102
103                         if (gSparseMatrix != NULL) { delete gSparseMatrix; gSparseMatrix = NULL; }
104
105                         if (ginput != NULL) { delete ginput; ginput = NULL;}
106
107                         if (gorder != NULL) { delete gorder; gorder = NULL; }
108
109                         if (glist != NULL) { delete glist; glist = NULL;}
110
111                         if (gSharedList != NULL) { delete gSharedList; gSharedList = NULL; }
112
113                         if (sabund != NULL) { delete sabund; sabund = NULL;}
114
115                         if (rabund != NULL) { delete rabund; rabund = NULL; }
116
117                         if (gMatrix != NULL) { delete gMatrix; gMatrix = NULL;}
118
119                         if (gTreemap != NULL) { delete gTreemap; gTreemap = NULL; }
120
121                         if (gSequenceDB != NULL) { delete gSequenceDB; gSequenceDB = NULL;}
122                         
123                         if (nameMap != NULL) { delete nameMap; nameMap = NULL; }
124
125
126                         gTree.clear();
127                         Treenames.clear();
128                         labels.clear(); Groups.clear();
129                         allLines = 1;
130                         runParse = true;
131                         names.clear();
132         }
133         catch(exception& e) {
134                 m->errorOut(e, "GlobalData", "newRead");
135                 exit(1);
136         }
137 }
138
139 //******************************************************/
140
141 /******************************************************/
142 GlobalData::~GlobalData() {
143         _uniqueInstance = 0;
144         try {
145                 if (gGroupmap != NULL) { delete gGroupmap; gGroupmap = NULL; }
146                 if (gListVector != NULL) { delete gListVector; gListVector = NULL;}
147                 if (gSparseMatrix != NULL) { delete gSparseMatrix; gSparseMatrix = NULL; }
148                 if (ginput != NULL) { delete ginput; ginput = NULL;}
149                 if (gorder != NULL) { delete gorder; gorder = NULL; }
150                 if (glist != NULL) { delete glist; glist = NULL;}
151                 if (gSharedList != NULL) { delete gSharedList; gSharedList = NULL; }
152                 if (sabund != NULL) { delete sabund; sabund = NULL;}
153                 if (rabund != NULL) { delete rabund; rabund = NULL; }
154                 if (gMatrix != NULL) { delete gMatrix; gMatrix = NULL;}
155                 if (gTreemap != NULL) { delete gTreemap; gTreemap = NULL; }
156                 if (gSequenceDB != NULL) { delete gSequenceDB; gSequenceDB = NULL;}
157                 if (nameMap != NULL) { delete nameMap; nameMap = NULL; }
158         }
159         catch(exception& e) {
160                 m->errorOut(e, "GlobalData", "~GlobalData");
161                 exit(1);
162         }
163 }
164 /*******************************************************/
165
166 /*******************************************************/
167
168