masschroq_cli.cpp 11.3 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
/*
    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>
23
#include <QCommandLineParser>
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41



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()
{
42
//#if (WIN32)
43
44
//    mcqout() << "Press any key then enter to exit" << endl;
//    getchar();
45
//#endif
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
80
}

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()
{

81
    // QCoreApplication * app(this);
82
83
84
85
86
87
    // Add your main code here
    qDebug() << "MainClass.Run is executing";

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

88
89
90
91
92
93
    QCommandLineParser parser;
    parser.setApplicationDescription("Perform Mass Chromatogram Quantification as indicated in the XML input FILE.");
    parser.addHelpOption();
    parser.addVersionOption();


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    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 :
113
        qDebug() << "masschroqml cli case 2";
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
        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 :
139
        qDebug() << "masschroqml cli case 3";
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
        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 :
162
        qDebug() << "masschroqml cli case 4";
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
        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 :
190
191
        qDebug() << "masschroqml cli case 6";
        option = arguments.at(1);
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
232
233
234
235
236
237
238
        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 :
239
240
        qDebug() << "masschroqml cli case 1";
        mcqerr() << "masschroq : missing input filename." << endl;
241
242
243
244
245
        mcqerr() << "Try 'masschroq --help' for more information." << endl;
        windaube_exit();
        app->exit(1);
        break;
    default :
246
        qDebug() << "masschroqml cli default";
247

248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
        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) {
266
            qDebug() << "masschroqml_validation == true";
267
268
269
            mass_chroq_engine.validateXmlFile();
// you must call quit when complete or the program will stay in the
            // messaging loop
270
            // quit();
271
        }
272
        else {
273
            qDebug() << "masschroqml_validation == false";
274

275
            mass_chroq_engine.setTmpDir(tmpDirName);
276

277
278
279
280
281
282
            if (tmpDirName != QDir::tempPath())
            {
                mcqout() << "MassChroQ : temporary working directory is : "
                         << mass_chroq_engine.getTmpDirName() << endl;
            }
            mass_chroq_engine.setBeginDateTime(dt_begin);
283

284
            mass_chroq_engine.runDomParser();
285

286
287
288
            if (!peptide_translation) {
                mass_chroq_engine.runXmlFile();
            }
289

290
            const QDateTime dt_end = QDateTime::currentDateTime();
291

292
293
            const Duration dur =
                Utilities::getDurationFromDates(dt_begin, dt_end);
294

295
296
297
298
299
300
301
            mcqout() << "MassChroQ's execution time was : "
                     << Utilities::getDaysFromDuration(dur) << " days, "
                     << Utilities::getHoursFromDuration(dur) << " hours, "
                     << Utilities::getMinutesFromDuration(dur) << " minutes, "
                     << Utilities::getSecondsFromDuration(dur) << " seconds."
                     << endl;
        }
302
303
304
305
306
307
308
309
310
311
312
313
        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();
314
        exit(1);
315
316
        app->exit(1);
    }
317
    qDebug() << "before final quit()";
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341

    // 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
}