tandemparameters.cpp 7.6 KB
Newer Older
1
2
3
4
5
6
7
8
/**
 * \file /core/tandem_run/tandemparameters.cpp
 * \date 19/9/2017
 * \author Olivier Langella
 * \brief handles X!Tandem parameters
 */

/*******************************************************************************
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 * Copyright (c) 2017 Olivier Langella <olivier.langella@u-psud.fr>.
 *
 * This file is part of XTPcpp.
 *
 *     XTPcpp 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.
 *
 *     XTPcpp 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 XTPcpp.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Contributors:
 *     Olivier Langella <olivier.langella@u-psud.fr> - initial API and
 *implementation
 ******************************************************************************/
30
31

#include "tandemparameters.h"
32
#include <QDebug>
33
#include <pappsomspp/exception/exceptionnotfound.h>
Langella Olivier's avatar
Langella Olivier committed
34
#include <pappsomspp/exception/exceptionnotpossible.h>
35

36
37
TandemParameters::TandemParameters()
{
38
}
39
40
TandemParameters::~TandemParameters()
{
41
42
}

43
44
45
46
47
TandemParameters::TandemParameters(const TandemParameters &other)
{
  qDebug() << "TandemParameters::TandemParameters copy begin";
  //_map_label_value = other._map_label_value;
  _method_name = other._method_name;
Olivier Langella's avatar
Olivier Langella committed
48

49
50
51
52
53
54
55
56
  QMap<QString, QString>::const_iterator i =
    other._map_label_value.constBegin();
  while(i != other._map_label_value.constEnd())
    {
      qDebug() << "TandemParameters::TandemParameters copy " << i.key() << " "
               << i.value();
      _map_label_value.insert(i.key(), i.value());
      i++; // added
Olivier Langella's avatar
Olivier Langella committed
57
    }
58
  qDebug() << "TandemParameters::TandemParameters copy end";
59
}
Langella Olivier's avatar
Langella Olivier committed
60
61


62
63
64
65
66
67
bool
TandemParameters::equals(const TandemParameters &other) const
{
  if(_method_name != other._method_name)
    {
      return false;
Langella Olivier's avatar
Langella Olivier committed
68
    }
69
70
71
  if(_map_label_value.size() != other._map_label_value.size())
    {
      return false;
Langella Olivier's avatar
Langella Olivier committed
72
    }
73
74
75
76
77
78
  QMap<QString, QString>::const_iterator i = _map_label_value.constBegin();
  while(i != _map_label_value.constEnd())
    {
      if(i.value() != other.getValue(i.key()))
        {
          return false;
Langella Olivier's avatar
Langella Olivier committed
79
        }
80
      i++; // added
Langella Olivier's avatar
Langella Olivier committed
81
    }
82
  return true;
Langella Olivier's avatar
Langella Olivier committed
83
84
}

85
86
87
88
const QString
TandemParameters::getLabelCategory(const QString &value) const
{
  return value.split(", ").at(0);
89
}
90
91
92
93
94
95
96
97
98
99
const QString &
TandemParameters::getValue(const QString &label) const
{
  QMap<QString, QString>::const_iterator it = _map_label_value.constFind(label);
  if(it == _map_label_value.end())
    {
      throw pappso::ExceptionNotFound(
        QObject::tr("X!Tandem preset label %1 not found in method %2")
          .arg(label)
          .arg(_method_name));
100
    }
101
  return it.value();
102
}
103
104
105
106
107
void
TandemParameters::setParamLabelValue(const QString &label, const QString &value)
{
  // list path
  //<note type="input" label="list path, default
Langella Olivier's avatar
Langella Olivier committed
108
  // parameters">/gorgone/pappso/tmp/temp_condor_job24872841484824316495370334631825647/QExactive_analysis_FDR_nosemi.xml</note>
109
  //<note type="input" label="list path, taxonomy
Langella Olivier's avatar
Langella Olivier committed
110
  // information">/gorgone/pappso/tmp/temp_condor_job24872841484824316495370334631825647/database.xml</note>
111
112
113
  if(getLabelCategory(label) == "list path")
    {
      return;
114
    }
115
116
117
  if(label == "spectrum, path")
    {
      return;
118
    }
119

120
121
122
  if((label == "spectrum, parent monoisotopic mass error units") ||
     (label == "spectrum, fragment monoisotopic mass error units"))
    {
123
      if((value != "Da") && (value != "Daltons") && (value != "ppm"))
124
125
126
127
128
        {
          throw pappso::ExceptionNotPossible(
            QObject::tr("%1 value must be Daltons or ppm (not %2)")
              .arg(label)
              .arg(value));
Langella Olivier's avatar
Langella Olivier committed
129
130
        }
    }
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
  if((label == "spectrum, parent monoisotopic mass isotope error") ||
     (label == "spectrum, use neutral loss window") ||
     (label == "spectrum, use contrast angle") ||
     (label == "protein, cleavage semi") ||
     (label == "protein, quick acetyl") ||
     (label == "protein, quick pyrolidone") || (label == "protein, stP bias") ||
     (label == "scoring, cyclic permutation") ||
     (label == "scoring, include reverse") || (label == "scoring, y ions") ||
     (label == "scoring, b ions") || (label == "scoring, c ions") ||
     (label == "scoring, z ions") || (label == "scoring, a ions") ||
     (label == "scoring, x ions") || (label == "refine") ||
     (label == "refine, use potential modifications for full refinement") ||
     (label == "refine, cleavage semi") ||
     (label == "refine, unanticipated cleavage") ||
     (label == "refine, spectrum synthesis") ||
     (label == "refine, point mutations") || (label == "output, mzid") ||
     (label == "output, spectra") ||
     (label == "spectrum, use noise suppression"))
    {
      if((value != "yes") && (value != "no"))
        {
          throw pappso::ExceptionNotPossible(
            QObject::tr("%1 value must be yes or no (not %2)")
              .arg(label)
              .arg(value));
Langella Olivier's avatar
Langella Olivier committed
156
157
        }
    }
Langella Olivier's avatar
Langella Olivier committed
158
159


160
161
162
163
164
165
166
167
168
169
170
  if((label == "spectrum, parent monoisotopic mass error minus") ||
     (label == "spectrum, parent monoisotopic mass error plus") ||
     (label == "spectrum, dynamic range") ||
     (label == "spectrum, minimum parent m+h") ||
     (label == "protein, cleavage C-terminal mass change") ||
     (label == "protein, cleavage N-terminal mass change") ||
     (label == "protein, C-terminal residue modification mass") ||
     (label == "protein, N-terminal residue modification mass") ||
     (label == "refine, maximum valid expectation value"))
    {
      bool ok;
171
172
173
174
175
176
      QString value_bis = value.simplified();
      if(value_bis.isEmpty())
        {
          value_bis = "0.0";
        }
      value_bis.toDouble(&ok);
177
178
179
180
181
182
      if(!ok)
        { // not an integer
          throw pappso::ExceptionNotPossible(
            QObject::tr("%1 value must be a number (not %2)")
              .arg(label)
              .arg(value));
Langella Olivier's avatar
Langella Olivier committed
183
184
        }
    }
Langella Olivier's avatar
Langella Olivier committed
185
186


187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
  if((label == "spectrum, maximum parent charge") ||
     (label == "spectrum, total peaks") ||
     (label == "spectrum, minimum peaks") ||
     (label == "spectrum, sequence batch size") ||
     (label == "spectrum, threads") ||
     (label == "scoring, minimum ion count") ||
     (label == "scoring, maximum missed cleavage sites"))
    {
      bool ok;
      value.toInt(&ok);
      if(!ok)
        { // not an integer
          throw pappso::ExceptionNotPossible(
            QObject::tr("%1 value must be an integer (not %2)")
              .arg(label)
              .arg(value));
Langella Olivier's avatar
Langella Olivier committed
203
204
        }
    }
205
206
207
208
209
210
211
212
  if(label == "spectrum, fragment mass type")
    {
      if((value != "monoisotopic") && (value != "average"))
        {
          throw pappso::ExceptionNotPossible(
            QObject::tr("%1 value must be monoisotopic or average (not %2)")
              .arg(label)
              .arg(value));
Langella Olivier's avatar
Langella Olivier committed
213
214
215
        }
    }

216
217
218
219
220
  // text "protein, cleavage site" "protein, modified residue mass file"
  // "residue, modification mass"  || (label == "refine, potential N-terminus
  // modifications") || (label == "refine, potential C-terminus modifications")
  // spectrum, neutral loss mass
  // spectrum, neutral loss window
Langella Olivier's avatar
Langella Olivier committed
221

222
  _map_label_value.insert(label, value);
223
}
224
225
226
227
void
TandemParameters::setMethodName(const QString &method)
{
  _method_name = method;
228
}
229
230
231
232
const QString &
TandemParameters::getMethodName() const
{
  return _method_name;
233
}
234
235
236
237
const QMap<QString, QString> &
TandemParameters::getMapLabelValue() const
{
  return _map_label_value;
238
}