]> git.donarmstrong.com Git - mothur.git/blob - mothur.cpp
removed read.dist, read.otu, read.tree and globaldata. added current to defaults...
[mothur.git] / mothur.cpp
1 /*
2  *  interface.cpp
3  *  
4  *
5  *  Created by Pat Schloss on 8/14/08.
6  *  Copyright 2008 Patrick D. Schloss. All rights reserved.
7  *
8  */
9  
10 #include "mothur.h"
11 #include "engine.hpp"
12 #include "globaldata.hpp"
13 #include "mothurout.h"
14
15 /**************************************************************************************************/
16
17 CommandFactory* CommandFactory::_uniqueInstance = 0;
18 MothurOut* MothurOut::_uniqueInstance = 0;
19
20 /***********************************************************************/
21 volatile int ctrlc_pressed = 0;
22 void ctrlc_handler ( int sig ) {
23         MothurOut* m = MothurOut::getInstance();
24     ctrlc_pressed = 1;
25         m->control_pressed = ctrlc_pressed;
26         
27         if (m->executing) { //if mid command quit execution, else quit mothur
28                 m->mothurOutEndLine(); m->mothurOut("quitting command...");  m->mothurOutEndLine();
29         }else{
30                 m->mothurOut("quitting mothur");  m->mothurOutEndLine();
31                 exit(1);
32         }
33 }
34 /***********************************************************************/
35 int main(int argc, char *argv[]){
36         MothurOut* m = MothurOut::getInstance();
37         try {   
38                 signal(SIGINT, ctrlc_handler );
39                                 
40                 time_t ltime = time(NULL); /* calendar time */  
41                 string logFileName = "mothur." + toString(ltime) + ".logfile";
42                 
43                 #ifdef USE_MPI
44                         MPI_Init(&argc, &argv); 
45                 #endif
46
47                 m->setFileName(logFileName);
48                 
49                                 
50                 //version
51                 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
52                         system("clear");
53                         #if defined (__APPLE__) || (__MACH__)
54                                 m->mothurOutJustToLog("Mac version");
55                                 m->mothurOutEndLine(); m->mothurOutEndLine();
56                         #else
57                                 m->mothurOutJustToLog("Linux version");
58                                 m->mothurOutEndLine(); m->mothurOutEndLine();
59                         #endif
60
61                 #else
62                         system("CLS");
63                         m->mothurOutJustToLog("Windows version");
64                         m->mothurOutEndLine(); m->mothurOutEndLine();
65                 #endif          
66                 
67                 #ifdef USE_READLINE
68                         m->mothurOutJustToLog("Using ReadLine");
69                         m->mothurOutEndLine(); m->mothurOutEndLine();
70                 #endif
71                 
72                 #ifdef MOTHUR_FILES
73                         string temp = MOTHUR_FILES; 
74                         
75                         //add / to name if needed
76                         string lastChar = temp.substr(temp.length()-1);
77                         #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
78                                 if (lastChar != "/") { temp += "/"; }
79                         #else
80                                 if (lastChar != "\\") { temp += "\\"; } 
81                         #endif
82                         
83                         temp = m->getFullPathName(temp);
84                         m->setDefaultPath(temp);
85                         
86                         m->mothurOutJustToLog("Using default file location " + temp);
87                         m->mothurOutEndLine(); m->mothurOutEndLine();
88                 #endif
89                 
90                 #ifdef BIT_VERSION
91                         m->mothurOutJustToLog("Running 64Bit Version");
92                         m->mothurOutEndLine(); m->mothurOutEndLine();
93                 #else
94                         m->mothurOutJustToLog("Running 32Bit Version");
95                         m->mothurOutEndLine(); m->mothurOutEndLine();
96                 #endif
97                 
98                 //get releaseDate from Make
99                 string releaseDate = RELEASE_DATE; 
100                 string mothurVersion = VERSION; 
101                 m->setReleaseDate(releaseDate);
102                 m->setVersion(mothurVersion);
103                 
104                 //header
105                 m->mothurOut("mothur v." + mothurVersion);
106                 m->mothurOutEndLine();          
107                 m->mothurOut("Last updated: " + releaseDate);
108                 m->mothurOutEndLine();  
109                 m->mothurOutEndLine();          
110                 m->mothurOut("by");
111                 m->mothurOutEndLine();          
112                 m->mothurOut("Patrick D. Schloss");
113                 m->mothurOutEndLine();
114                 m->mothurOutEndLine();                  
115                 m->mothurOut("Department of Microbiology & Immunology");
116                 m->mothurOutEndLine();  
117                 m->mothurOut("University of Michigan");
118                 m->mothurOutEndLine();                  
119                 m->mothurOut("pschloss@umich.edu");
120                 m->mothurOutEndLine();          
121                 m->mothurOut("http://www.mothur.org");
122                 m->mothurOutEndLine();
123                 m->mothurOutEndLine();
124                 m->mothurOut("When using, please cite:");
125                 m->mothurOutEndLine();
126                 m->mothurOut("Schloss, P.D., et al., Introducing mothur: Open-source, platform-independent, community-supported software for describing and comparing microbial communities. Appl Environ Microbiol, 2009. 75(23):7537-41.");
127                 m->mothurOutEndLine();  
128                 m->mothurOutEndLine();          
129                 m->mothurOut("Distributed under the GNU General Public License");
130                 m->mothurOutEndLine();
131                 m->mothurOutEndLine();                  
132                 m->mothurOut("Type 'help()' for information on the commands that are available");
133                 m->mothurOutEndLine();
134                 m->mothurOutEndLine();                  
135                 m->mothurOut("Type 'quit()' to exit program");
136                 m->mothurOutEndLine();  
137                 
138                 #ifdef USE_MPI
139                         m->mothurOutJustToLog("Using MPI\tversion ");
140                         int version, subversion;
141                         MPI_Get_version(&version, &subversion);
142                         m->mothurOutJustToLog(toString(version) + "." + toString(subversion) + "\n");
143                 #endif
144                 
145                 //srand(54321);
146                 srand( (unsigned)time( NULL ) );
147                 
148                 Engine* mothur;
149                 bool bail = 0;
150                 string input;
151  
152                 if(argc>1){
153                         input = argv[1];
154
155                         if (input[0] == '#') {
156                                 m->mothurOutJustToLog("Script Mode");
157                                 m->mothurOutEndLine(); m->mothurOutEndLine();
158
159                                 mothur = new ScriptEngine(argv[0], argv[1]);
160                         }else{
161                                 m->mothurOutJustToLog("Batch Mode");
162                                 m->mothurOutEndLine(); m->mothurOutEndLine();
163                                 
164                                 mothur = new BatchEngine(argv[0], argv[1]);
165                         }
166                 }
167                 else{
168                         m->mothurOutJustToLog("Interactive Mode");
169                         m->mothurOutEndLine(); m->mothurOutEndLine();
170                         
171                         mothur = new InteractEngine(argv[0]);   
172                 }
173                 
174                 while(bail == 0)        {       bail = mothur->getInput();      }
175                 
176                 //closes logfile so we can rename
177                 m->closeLog();
178                 
179                 string outputDir = mothur->getOutputDir();
180                 string tempLog = mothur->getLogFileName();
181                 bool append = mothur->getAppend();
182                 
183                 string newlogFileName;
184                 if (tempLog != "") {
185                         newlogFileName = outputDir + tempLog;
186                         
187                         if (!append) {  
188                                 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
189                                 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
190
191                         }else {
192                                 ofstream outNewLog;
193                                 m->openOutputFileAppend(newlogFileName, outNewLog);
194                                 outNewLog << endl << endl << "*********************************************************************************" << endl << endl;
195                                 outNewLog.close();
196                                 
197                                 m->appendFiles(logFileName, newlogFileName);
198                                 remove(logFileName.c_str());
199                         }
200                 }else{  
201                         newlogFileName = outputDir + logFileName;
202                         //need this because m->mothurOut makes the logfile, but doesn't know where to put it
203                         rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
204                 }
205                 
206                                 
207                 delete mothur;
208                 
209                 #ifdef USE_MPI
210                         MPI_Finalize();
211                 #endif
212                 
213                 return 0;
214         }
215         catch(exception& e) {
216                 m->errorOut(e, "mothur", "main");
217                 exit(1);
218         }
219 }
220
221 /**************************************************************************************************/
222