masschroq_cli.cpp 11 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
    MassChroQ : Mass Chromatogram Quantification
    Copyright (C) 2014  Olivier Langella <Olivier.Langella@moulon.inra.fr>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


#include "masschroq_cli.h"

#include <QDebug>



masschroqCli::masschroqCli(QObject *parent) :
    QObject(parent)
{
    // get the instance of the main application
    app = QCoreApplication::instance();
    // setup everything here
    // create any global objects
    // setup debug and warning mode
}



void
masschroqCli::windaube_exit()
{
41
//#if (WIN32)
42
43
//    mcqout() << "Press any key then enter to exit" << endl;
//    getchar();
44
//#endif
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
}

void
masschroqCli::display_help(QTextStream & out)
{
    out << "Usage: masschroq [OPTION] [FILE]" << endl;
    out << "Perform Mass Chromatogram Quantification as indicated in the XML input FILE." << endl;
    out << endl;
    out << "Options:" << endl;
    out << "  -h, --help\t\t\tdisplay this help and exit" << endl;
    out << endl;
    out << "  --validate\t\t\tcheck xml validity without running masschroq" << endl;
    out << endl;
    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 << "  -c, --cpus integer\tsets the number of cpus you want to use" << endl;
    out << endl;
    out << "  -v, --version\t\t\tdisplay version number and exit" << endl;
    //  out << "\n" << endl;
    out << endl;
    out << "For additional information, see the MassChroQ Homepage :" <<endl;
    out << "http://pappso.inra.fr/bioinfo/masschroq/" << endl;
    out.flush();
}



// 10ms after the application starts this method will run
// all QT messaging is running at this point so threads, signals and slots
// will all work as expected.
void masschroqCli::run()
{

80
    // QCoreApplication * app(this);
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
    // Add your main code here
    qDebug() << "MainClass.Run is executing";

    const QDateTime dt_begin = QDateTime::currentDateTime();
    const QString masschroq_dir_path(QCoreApplication::applicationDirPath());

    QStringList arguments = app->arguments();
    QString fileName;
    /// by default, temporary files go in the temporary directory of the system
    //  QString tmpDirName = QDir::tempPath();

    /// by default, temporary files go in the current working directory
    QString tmpDirName = QDir::currentPath();


    bool peptide_translation = false;
    bool masschroqml_validation = false;
    uint cpu_number = 1;

    int args_number = arguments.size();
    QString first, option;

    switch (args_number) {

    case 2 :
106
      qDebug() << "masschroqml cli case 2";
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
        first = arguments.at(1);
        if ( (first == "--help") ||
                (first == "-h") )
        {
            display_help(mcqout());
            windaube_exit();
            // you must call quit when complete or the program will stay in the
            // messaging loop
            quit();
        }
        else if ((first == "--version") ||
                 (first == "-v"))
        {
            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;
            windaube_exit();
// you must call quit when complete or the program will stay in the
            // messaging loop
            quit();
        }
        else
            fileName = first;
        break;

    case 3 :
132
      qDebug() << "masschroqml cli case 3";
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
        fileName = arguments.at(2);
        option = arguments.at(1);
        if ( (option == "--parse-peptides") ||
                (option == "-p"))
        {
            peptide_translation = true;
        }
        else if ((option == "--validate"))
        {
            masschroqml_validation = true;
        }

        else
        {
            mcqerr() << "Invalid use of option " << option << "." << endl;
            mcqerr() << "Try 'masschroq --help' for more information." << endl;
            windaube_exit();
            //return 1;
            app->exit(1);
        }
        break;
    case 4 :
155
      qDebug() << "masschroqml cli case 4";
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
        option = arguments.at(1);
        fileName = arguments.at(3);

        if ( (option == "--tmpdir") ||
                (option == "-t"))
        {
            tmpDirName = arguments.at(2);
        }
        else
        {
            if ( (option == "--cpus") ||
                    (option == "-c"))
            {
                cpu_number = arguments.at(2).toUInt();
                Quantificator::setCpuNumber(cpu_number);
            }
            else
            {
                mcqerr() << "Invalid use of option " << option << "." << endl;
                mcqerr() << "Try 'masschroq --help' for more information." << endl;
                windaube_exit();
                app->exit(1);
            }
        }
        break;

    case 6 :
183
184
        	  qDebug() << "masschroqml cli case 6";
       option = arguments.at(1);
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
        fileName = arguments.at(5);

        if ( (option == "--tmpdir") ||
                (option == "-t"))
        {
            tmpDirName = arguments.at(2);
        }
        else
        {
            if ( (option == "--cpus") ||
                    (option == "-c"))
            {
                cpu_number = arguments.at(2).toUInt();
                Quantificator::setCpuNumber(cpu_number);
            }
            else
            {
                mcqerr() << "Invalid use of option " << option << "." << endl;
                mcqerr() << "Try 'masschroq --help' for more information." << endl;
                windaube_exit();
                app->exit(1);
            }
        }
        option = arguments.at(3);
        if ( (option == "--tmpdir") ||
                (option == "-t"))
        {
            tmpDirName = arguments.at(4);
        }
        else
        {
            if ( (option == "--cpus") ||
                    (option == "-c"))
            {
                cpu_number = arguments.at(4).toUInt();
                Quantificator::setCpuNumber(cpu_number);
            }
            else
            {
                mcqerr() << "Invalid use of option " << option << "." << endl;
                mcqerr() << "Try 'masschroq --help' for more information." << endl;
                windaube_exit();
                app->exit(1);
            }
        }
        break;
    case 1 :
232
233
       	  qDebug() << "masschroqml cli case 1";
       mcqerr() << "masschroq : missing input filename." << endl;
234
235
236
237
238
        mcqerr() << "Try 'masschroq --help' for more information." << endl;
        windaube_exit();
        app->exit(1);
        break;
    default :
239
240
      	  qDebug() << "masschroqml cli default";

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
        mcqerr() << "masschroq : invalid use." << endl;
        mcqerr() << "Try 'masschroq --help' for more information." << endl;
        windaube_exit();
        app->exit(1);
    }

    //ReporterBase * logger = new ReporterConsole();
    //logger->write("Test HOOOOOO \n");

    MassChroq mass_chroq_engine;

    try
    {
        //defined application directory
        mass_chroq_engine.setMasschroqDir(masschroq_dir_path);
        mass_chroq_engine.setXmlFilename(fileName);

        if (masschroqml_validation == true) {
259
	  qDebug() << "masschroqml_validation == true";
260
261
262
            mass_chroq_engine.validateXmlFile();
// you must call quit when complete or the program will stay in the
            // messaging loop
263
           // quit();
264
        }
265
266
        else {
	  qDebug() << "masschroqml_validation == false";
267

268
            mass_chroq_engine.setTmpDir(tmpDirName);
269

270
271
272
273
274
275
            if (tmpDirName != QDir::tempPath())
            {
                mcqout() << "MassChroQ : temporary working directory is : "
                         << mass_chroq_engine.getTmpDirName() << endl;
            }
            mass_chroq_engine.setBeginDateTime(dt_begin);
276

277
            mass_chroq_engine.runDomParser();
278

279
280
281
            if (!peptide_translation) {
                mass_chroq_engine.runXmlFile();
            }
282

283
            const QDateTime dt_end = QDateTime::currentDateTime();
284

285
286
            const Duration dur =
                Utilities::getDurationFromDates(dt_begin, dt_end);
287

288
289
290
291
292
293
294
            mcqout() << "MassChroQ's execution time was : "
                     << Utilities::getDaysFromDuration(dur) << " days, "
                     << Utilities::getHoursFromDuration(dur) << " hours, "
                     << Utilities::getMinutesFromDuration(dur) << " minutes, "
                     << Utilities::getSecondsFromDuration(dur) << " seconds."
                     << endl;
        }
295
296
297
298
299
300
301
302
303
304
305
306
        windaube_exit();
// you must call quit when complete or the program will stay in the
        // messaging loop
        quit();
        //    delete logger;
    }
    catch (mcqError& error)
    {
        mcqerr() << "Oops! an error occurred in MassChroQ. Dont Panic :" << endl;
        mcqerr() << error.qwhat() << endl;

        windaube_exit();
Olivier Langella's avatar
Olivier Langella committed
307
	exit(1);
308
309
        app->exit(1);
    }
310
qDebug() << "before final quit()";
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334

    // you must call quit when complete or the program will stay in the
    // messaging loop
    quit();
}

// call this routine to quit the application
void masschroqCli::quit()
{
    // you can do some cleanup here
    // then do emit finished to signal CoreApplication to quit
    emit finished();
}

// shortly after quit is called the CoreApplication will signal this routine
// this is a good place to delete any objects that were created in the
// constructor and/or to stop any threads
void masschroqCli::aboutToQuitApp()
{
    // stop threads
    // sleep(1);   // wait for threads to stop.
    // delete any objects
}