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