5 * Created by Pat Schloss on 8/14/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
12 #include "globaldata.hpp"
13 #include "mothurout.h"
15 /**************************************************************************************************/
17 CommandFactory* CommandFactory::_uniqueInstance = 0;
18 MothurOut* MothurOut::_uniqueInstance = 0;
20 /***********************************************************************/
21 volatile int ctrlc_pressed = 0;
22 void ctrlc_handler ( int sig ) {
23 MothurOut* m = MothurOut::getInstance();
25 m->control_pressed = ctrlc_pressed;
27 if (m->executing) { //if mid command quit execution, else quit mothur
28 m->mothurOutEndLine(); m->mothurOut("quitting command..."); m->mothurOutEndLine();
30 m->mothurOut("quitting mothur"); m->mothurOutEndLine();
34 /***********************************************************************/
35 int main(int argc, char *argv[]){
36 MothurOut* m = MothurOut::getInstance();
38 signal(SIGINT, ctrlc_handler );
40 time_t ltime = time(NULL); /* calendar time */
41 string logFileName = "mothur." + toString(ltime) + ".logfile";
44 MPI_Init(&argc, &argv);
47 m->setFileName(logFileName);
51 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
53 #if defined (__APPLE__) || (__MACH__)
54 m->mothurOutJustToLog("Mac version");
55 m->mothurOutEndLine(); m->mothurOutEndLine();
57 m->mothurOutJustToLog("Linux version");
58 m->mothurOutEndLine(); m->mothurOutEndLine();
63 m->mothurOutJustToLog("Windows version");
64 m->mothurOutEndLine(); m->mothurOutEndLine();
68 m->mothurOutJustToLog("Using ReadLine");
69 m->mothurOutEndLine(); m->mothurOutEndLine();
73 string temp = MOTHUR_FILES;
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 += "/"; }
80 if (lastChar != "\\") { temp += "\\"; }
83 temp = m->getFullPathName(temp);
84 m->setDefaultPath(temp);
86 m->mothurOutJustToLog("Using default file location " + temp);
87 m->mothurOutEndLine(); m->mothurOutEndLine();
91 m->mothurOutJustToLog("Running 64Bit Version");
92 m->mothurOutEndLine(); m->mothurOutEndLine();
94 m->mothurOutJustToLog("Running 32Bit Version");
95 m->mothurOutEndLine(); m->mothurOutEndLine();
98 //get releaseDate from Make
99 string releaseDate = RELEASE_DATE;
100 string mothurVersion = VERSION;
101 m->setReleaseDate(releaseDate);
102 m->setVersion(mothurVersion);
105 m->mothurOut("mothur v." + mothurVersion);
106 m->mothurOutEndLine();
107 m->mothurOut("Last updated: " + releaseDate);
108 m->mothurOutEndLine();
109 m->mothurOutEndLine();
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();
139 m->mothurOutJustToLog("Using MPI\tversion ");
140 int version, subversion;
141 MPI_Get_version(&version, &subversion);
142 m->mothurOutJustToLog(toString(version) + "." + toString(subversion) + "\n");
146 srand( (unsigned)time( NULL ) );
155 if (input[0] == '#') {
156 m->mothurOutJustToLog("Script Mode");
157 m->mothurOutEndLine(); m->mothurOutEndLine();
159 mothur = new ScriptEngine(argv[0], argv[1]);
161 m->mothurOutJustToLog("Batch Mode");
162 m->mothurOutEndLine(); m->mothurOutEndLine();
164 mothur = new BatchEngine(argv[0], argv[1]);
168 m->mothurOutJustToLog("Interactive Mode");
169 m->mothurOutEndLine(); m->mothurOutEndLine();
171 mothur = new InteractEngine(argv[0]);
174 while(bail == 0) { bail = mothur->getInput(); }
176 //closes logfile so we can rename
179 string outputDir = mothur->getOutputDir();
180 string tempLog = mothur->getLogFileName();
181 bool append = mothur->getAppend();
183 string newlogFileName;
185 newlogFileName = outputDir + tempLog;
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
193 m->openOutputFileAppend(newlogFileName, outNewLog);
194 outNewLog << endl << endl << "*********************************************************************************" << endl << endl;
197 m->appendFiles(logFileName, newlogFileName);
198 remove(logFileName.c_str());
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
215 catch(exception& e) {
216 m->errorOut(e, "mothur", "main");
221 /**************************************************************************************************/