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 GlobalData* GlobalData::_uniqueInstance = 0;
18 CommandFactory* CommandFactory::_uniqueInstance = 0;
19 MothurOut* MothurOut::_uniqueInstance = 0;
21 /***********************************************************************/
22 volatile int ctrlc_pressed = 0;
23 void ctrlc_handler ( int sig ) {
24 MothurOut* m = MothurOut::getInstance();
26 m->control_pressed = ctrlc_pressed;
28 if (m->executing) { //if mid command quit execution, else quit mothur
29 m->mothurOutEndLine(); m->mothurOut("quitting command..."); m->mothurOutEndLine();
31 m->mothurOut("quitting mothur"); m->mothurOutEndLine();
35 /***********************************************************************/
36 int main(int argc, char *argv[]){
37 MothurOut* m = MothurOut::getInstance();
40 signal(SIGINT, ctrlc_handler );
42 time_t ltime = time(NULL); /* calendar time */
43 string logFileName = "mothur." + toString(ltime) + ".logfile";
46 MPI_Init(&argc, &argv);
49 m->setFileName(logFileName);
53 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
55 #if defined (__APPLE__) || (__MACH__)
56 m->mothurOutJustToLog("Mac version");
57 m->mothurOutEndLine(); m->mothurOutEndLine();
59 m->mothurOutJustToLog("Linux version");
60 m->mothurOutEndLine(); m->mothurOutEndLine();
65 m->mothurOutJustToLog("Windows version");
66 m->mothurOutEndLine(); m->mothurOutEndLine();
70 m->mothurOutJustToLog("Using ReadLine");
71 m->mothurOutEndLine(); m->mothurOutEndLine();
75 string temp = MOTHUR_FILES;
77 //add / to name if needed
78 string lastChar = temp.substr(temp.length()-1);
79 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
80 if (lastChar != "/") { temp += "/"; }
82 if (lastChar != "\\") { temp += "\\"; }
85 temp = getFullPathName(temp);
86 m->setDefaultPath(temp);
88 m->mothurOutJustToLog("Using default file location " + temp);
89 m->mothurOutEndLine(); m->mothurOutEndLine();
93 m->mothurOutJustToLog("Running 64Bit Version");
94 m->mothurOutEndLine(); m->mothurOutEndLine();
96 m->mothurOutJustToLog("Running 32Bit Version");
97 m->mothurOutEndLine(); m->mothurOutEndLine();
101 m->mothurOut("mothur v.1.12.2");
102 m->mothurOutEndLine();
103 m->mothurOut("Last updated: 7/30/2010");
104 m->mothurOutEndLine();
105 m->mothurOutEndLine();
107 m->mothurOutEndLine();
108 m->mothurOut("Patrick D. Schloss");
109 m->mothurOutEndLine();
110 m->mothurOutEndLine();
111 m->mothurOut("Department of Microbiology & Immunology");
112 m->mothurOutEndLine();
113 m->mothurOut("University of Michigan");
114 m->mothurOutEndLine();
115 m->mothurOut("pschloss@umich.edu");
116 m->mothurOutEndLine();
117 m->mothurOut("http://www.mothur.org");
118 m->mothurOutEndLine();
119 m->mothurOutEndLine();
120 m->mothurOut("When using, please cite:");
121 m->mothurOutEndLine();
122 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.");
123 m->mothurOutEndLine();
124 m->mothurOutEndLine();
125 m->mothurOut("Distributed under the GNU General Public License");
126 m->mothurOutEndLine();
127 m->mothurOutEndLine();
128 m->mothurOut("Type 'help()' for information on the commands that are available");
129 m->mothurOutEndLine();
130 m->mothurOutEndLine();
131 m->mothurOut("Type 'quit()' to exit program");
132 m->mothurOutEndLine();
135 m->mothurOutJustToLog("Using MPI\tversion ");
136 int version, subversion;
137 MPI_Get_version(&version, &subversion);
138 m->mothurOutJustToLog(toString(version) + "." + toString(subversion) + "\n");
142 srand( (unsigned)time( NULL ) );
151 if (input[0] == '#') {
152 m->mothurOutJustToLog("Script Mode");
153 m->mothurOutEndLine(); m->mothurOutEndLine();
155 mothur = new ScriptEngine(argv[0], argv[1]);
157 m->mothurOutJustToLog("Batch Mode");
158 m->mothurOutEndLine(); m->mothurOutEndLine();
160 mothur = new BatchEngine(argv[0], argv[1]);
164 m->mothurOutJustToLog("Interactive Mode");
165 m->mothurOutEndLine(); m->mothurOutEndLine();
167 mothur = new InteractEngine(argv[0]);
170 while(bail == 0) { bail = mothur->getInput(); }
172 //closes logfile so we can rename
175 string outputDir = mothur->getOutputDir();
176 string tempLog = mothur->getLogFileName();
177 bool append = mothur->getAppend();
179 string newlogFileName;
181 newlogFileName = outputDir + tempLog;
184 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
185 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
189 openOutputFileAppend(newlogFileName, outNewLog);
190 outNewLog << endl << endl << "*********************************************************************************" << endl << endl;
193 appendFiles(logFileName, newlogFileName);
194 remove(logFileName.c_str());
197 newlogFileName = outputDir + logFileName;
198 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
199 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
211 catch(exception& e) {
212 m->errorOut(e, "mothur", "main");
217 /**************************************************************************************************/