main.cpp 6.12 KB
Newer Older
1
#include "lib/mass_chroq.h"
2
#include "lib/share/utilities.h"
3
#include "reporters/ReporterConsole.h"
Olivier Langella's avatar
   
Olivier Langella committed
4
#include <QString>
5
6
#include <QLocale>
#include <QCoreApplication>
7
#include <QDateTime>
8
#include <QFont>
9
#include <QDir>
Olivier Langella's avatar
   
Olivier Langella committed
10
#include <QFile>
Edlira Nano's avatar
Edlira Nano committed
11
#include <QDebug>
Olivier Langella's avatar
Olivier Langella committed
12
13
//#include <iostream>
#include "lib/consoleout.h"
Olivier Langella's avatar
 
Olivier Langella committed
14

Olivier Langella's avatar
Olivier Langella committed
15
//using namespace std;
Olivier Langella's avatar
 
Olivier Langella committed
16

17
void
18
19
windaube_exit()
{
20
#  if (WIN32)
21
	mcqout() << "Press any key then enter to exit" << endl;
22
	getchar();
23
24
25
#endif
}

26
void
Olivier Langella's avatar
Olivier Langella committed
27
display_help(QTextStream & out)
28
29
{
	out << "Usage: masschroq [OPTION] [FILE]" << endl;
30
	out << "Perform Mass Chromatogram Quantification as indicated in the XML input FILE." << endl; 
31
32
33
34
	out << endl;
	out << "Options:" << endl;
	out << "  -h, --help\t\t\tdisplay this help and exit" << endl;
	out << endl;
Benoit Valot's avatar
Benoit Valot committed
35
36
	out << "  --validate\t\t\tcheck xml validity without running masschroq" << endl;
	out << endl;
37
38
39
40
41
42
43
	out << "  -t, --tmpdir DIRECTORY\tuse DIRECTORY as temporary working direcory for masschroq : temporary files generated by masschroq during execution time (one file or several slices at a time per xml data file being analysed) will go there. By default DIRECTORY is the current working directory of masschroq. Use this option if you want to set another one." << endl;
	out << endl;
	out << "  -p, --parse-peptides\t\tperform peptide text file parsing only, no quantification. If the identified peptides are given to masschroq via peptide text files (defined in FILE), he parses them, creates a new file called parsed-peptides_FILE which contains the FILE content (minus the lines relative to thr peptide text files to parse) plus the parsed peptides information. By default masschroq continues analysis and quantification on this new file. Use this option if you want masschroq only to parse the petide files but not to continue quantification on them. This allows you to check the parsed peptides and to add trace information on specific peptides before quantification." << endl;
	out << endl;
	out << "  -v, --version\t\t\tdisplay version number and exit" << endl;
	//  out << "\n" << endl;
	out << endl;
44
	out << "For additional information, see the MassChroQ Homepage :" <<endl;
45
	out << "http://pappso.inra.fr/bioinfo/masschroq/" << endl;
Olivier Langella's avatar
Olivier Langella committed
46
	out.flush();
47
}
48

49
50
int main(int argc, char **argv)
{
Olivier Langella's avatar
   
Olivier Langella committed
51

52
	//QTextStream consoleErr(stderr);
Olivier Langella's avatar
Olivier Langella committed
53
	//QTextStream consoleOut(stdout, QIODevice::WriteOnly);
Olivier Langella's avatar
Olivier Langella committed
54
55
56
	ConsoleOut::setCout(new QTextStream(stdout, QIODevice::WriteOnly));
	ConsoleOut::setCerr(new QTextStream(stderr, QIODevice::WriteOnly));
	
57
58
59
60
	QCoreApplication app(argc, argv);
	QLocale::setDefault(QLocale::system());
	const QDateTime dt_begin = QDateTime::currentDateTime();
	const QString masschroq_dir_path(QCoreApplication::applicationDirPath());
Edlira Nano's avatar
Edlira Nano committed
61

62
63
64
65
	QStringList arguments = app.arguments();
	QString fileName;
	/// by default, temporary files go in the temporary directory of the system
	//  QString tmpDirName = QDir::tempPath();
66
  
67
68
	/// by default, temporary files go in the current working directory
	QString tmpDirName = QDir::currentPath();
69
70
  
  
71
	bool peptide_translation = false;
Edlira Nano's avatar
Edlira Nano committed
72
	bool masschroqml_validation = false;
73
  
74
75
	int args_number = arguments.size();
	QString first, option;
76
  
77
	switch (args_number) {
78
  
79
80
81
82
83
	case 2 :
		first = arguments.at(1); 
		if ( (first == "--help") || 
			 (first == "-h") )
		{
Olivier Langella's avatar
Olivier Langella committed
84
		  display_help(mcqout());
85
86
87
88
89
90
			windaube_exit();
			return 0;
		} 
		else if ((first == "--version") || 
				 (first == "-v"))
		{
Olivier Langella's avatar
Olivier Langella committed
91
92
		  mcqout() << QObject::tr("This is MassChroq version %1,").arg(MASSCHROQ_VERSION) << endl;
		  mcqout() << QObject::tr("using the masschroqML schema version %1.").arg(MASSCHROQ_SCHEMA_VERSION) << endl;
93
94
95
96
97
98
			windaube_exit();
			return 0;
		}
		else
			fileName = first;
		break;
99

100
101
102
103
104
105
106
107
	case 3 :
		fileName = arguments.at(2);
		option = arguments.at(1);
		if ( (option == "--parse-peptides") ||
			 (option == "-p"))
		{
			peptide_translation = true;
		}
Edlira Nano's avatar
Edlira Nano committed
108
109
110
111
112
		else if ((option == "--validate"))
		{
			masschroqml_validation = true;
		}
		
113
114
		else
		{
Olivier Langella's avatar
Olivier Langella committed
115
116
			mcqerr() << "Invalid use of option " << option << "." << endl;
			mcqerr() << "Try 'masschroq --help' for more information." << endl;
117
118
119
120
121
122
123
124
125
126
127
128
129
130
			windaube_exit();
			return 1;
		}
		break;
	case 4 :
		option = arguments.at(1);    fileName = arguments.at(3);
		
		if ( (option == "--tmpdir") ||
			 (option == "-t"))
		{
			tmpDirName = arguments.at(2);      
		}
		else
		{
Olivier Langella's avatar
Olivier Langella committed
131
132
			mcqerr() << "Invalid use of option " << option << "." << endl;
			mcqerr() << "Try 'masschroq --help' for more information." << endl;
133
134
135
136
137
			windaube_exit();
			return 1;
		}
		break;
	case 1 :
Olivier Langella's avatar
Olivier Langella committed
138
139
		mcqerr() << "masschroq : missing input filename." << endl;
		mcqerr() << "Try 'masschroq --help' for more information." << endl;
140
141
142
143
		windaube_exit();
		return 1;
		break;
	default :
Olivier Langella's avatar
Olivier Langella committed
144
145
	  mcqerr() << "masschroq : invalid use." << endl;
	  mcqerr() << "Try 'masschroq --help' for more information." << endl; 
146
147
148
		windaube_exit();
		return 1;
	}
149
  
150
  
Edlira Nano's avatar
Edlira Nano committed
151
152
	//ReporterBase * logger = new ReporterConsole();
	//logger->write("Test HOOOOOO \n");
153
    
154
	MassChroq mass_chroq_engine;
155
  
156
157
	try
	{
158
		//defined application directory
159
160
		mass_chroq_engine.setMasschroqDir(masschroq_dir_path);
		mass_chroq_engine.setXmlFilename(fileName);
Edlira Nano's avatar
Edlira Nano committed
161
162
163
164
165

		if (masschroqml_validation == true) {
			mass_chroq_engine.validateXmlFile();
			return 0;
		}
166
167
168
169
170
		
		mass_chroq_engine.setTmpDir(tmpDirName);
		
		if (tmpDirName != QDir::tempPath())
		{
Olivier Langella's avatar
Olivier Langella committed
171
172
			mcqout() << "MassChroQ : temporary working directory is : " 
				 << mass_chroq_engine.getTmpDirName() << endl;
173
174
		}
		mass_chroq_engine.setBeginDateTime(dt_begin);
175
    
176
		mass_chroq_engine.runDomParser();
177
    
178
179
180
		if (!peptide_translation) {
			mass_chroq_engine.runXmlFile();
		}
181
    
182
		const QDateTime dt_end = QDateTime::currentDateTime();
183
    
184
185
		const Duration dur =
			Utilities::getDurationFromDates(dt_begin, dt_end);
186
        
Olivier Langella's avatar
Olivier Langella committed
187
		mcqout() << "MassChroQ's execution time was : " 
188
189
190
191
192
193
194
			 << Utilities::getDaysFromDuration(dur) << " days, " 
			 << Utilities::getHoursFromDuration(dur) << " hours, "
			 << Utilities::getMinutesFromDuration(dur) << " minutes, "
			 << Utilities::getSecondsFromDuration(dur) << " seconds."
			 << endl;
		windaube_exit();
		return 0;
195

196
197
		//    delete logger;
	}
Benoit Valot's avatar
Benoit Valot committed
198
	catch (mcqError& error)
199
	{
Olivier Langella's avatar
Olivier Langella committed
200
201
		mcqerr() << "Oops! an error occurred in MassChroQ. Dont Panic :" << endl;
		mcqerr() << error.qwhat() << endl;
202

203
204
205
		windaube_exit();
		return 1;
	}
Olivier Langella's avatar
 
Olivier Langella committed
206
}