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