libpappsomspp
Library for mass spectrometry
obopsimod.cpp
Go to the documentation of this file.
1 
2 /*******************************************************************************
3  * Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>.
4  *
5  * This file is part of the PAPPSOms++ library.
6  *
7  * PAPPSOms++ is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * PAPPSOms++ is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
19  *
20  * Contributors:
21  * Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and
22  *implementation
23  ******************************************************************************/
24 
25 #include <QDir>
26 #include <QDebug>
27 #include "obopsimod.h"
28 #include "../pappsoexception.h"
29 #include <iostream>
30 
31 inline void
33 {
34  Q_INIT_RESOURCE(libpappsomsppresources);
35 }
36 
37 
38 namespace pappso
39 {
40 
41 
42 QRegExp OboPsiModTerm::m_firstParse("^([a-z,A-Z]+):\\s(.*)$");
44  "^(.*)\\sEXACT\\sPSI-MOD-label\\s\\[\\]$");
45 
46 // synonym: "Carbamidomethyl" RELATED PSI-MS-label []
48  "^(.*)\\sRELATED\\sPSI-MS-label\\s\\[\\]$");
49 
50 void
51 OboPsiModTerm::parseLine(const QString &line)
52 {
53  // qDebug() << "OboPsiModTerm::parseLine begin " << line;
54  // id: MOD:00007
55  if(m_firstParse.exactMatch(line))
56  {
57  QStringList pline = m_firstParse.capturedTexts();
58  // qDebug() << "OboPsiModTerm::parseLine match " << pline[0] << pline[1];
59  if(pline[1] == "id")
60  {
61  m_accession = pline[2].trimmed();
62  // qDebug() << "OboPsiModTerm::parseLine accession = " << m_accession;
63  }
64  else if(pline[1] == "name")
65  {
66  m_name = pline[2].trimmed();
67  // qDebug() << "OboPsiModTerm::parseLine accession = " << m_accession;
68  }
69  else if(pline[1] == "xref")
70  {
71  // xref: DiffMono: "1.007276"
72  if(m_firstParse.exactMatch(pline[2]))
73  {
74  QStringList psecond = m_firstParse.capturedTexts();
75  if(psecond[1] == "DiffMono")
76  {
77  m_diffMono = psecond[2].replace("\"", "").toDouble();
78  // qDebug() << "OboPsiModTerm::parseLine m_diffMono = " <<
79  // m_diffMono;
80  }
81  else if(psecond[1] == "DiffFormula")
82  {
83  m_diffFormula = psecond[2].trimmed().replace("\"", "");
84  // qDebug() << "OboPsiModTerm::parseLine m_diffFormula = |" <<
85  // m_diffFormula<<"|";
86  }
87  else if(psecond[1] == "Origin")
88  {
89  m_origin =
90  psecond[2].trimmed().replace("\"", "").replace(",", "");
91  // qDebug() << "OboPsiModTerm::parseLine m_diffFormula = |" <<
92  // m_diffFormula<<"|";
93  }
94  }
95  }
96  else if(pline[1] == "synonym")
97  {
98  // synonym: "Se(S)Res" EXACT PSI-MOD-label []
99  if(m_findExactPsiModLabel.exactMatch(pline[2]))
100  {
101  m_psiModLabel =
102  m_findExactPsiModLabel.capturedTexts()[1].trimmed().replace(
103  "\"", "");
104  // qDebug() << "OboPsiModTerm::parseLine m_psiModLabel = |" <<
105  // m_psiModLabel<<"|";
106  }
107  else if(m_findRelatedPsiMsLabel.exactMatch(pline[2]))
108  {
109  m_psiMsLabel =
110  m_findRelatedPsiMsLabel.capturedTexts()[1].trimmed().replace(
111  "\"", "");
112  // qDebug() << "OboPsiModTerm::parseLine m_psiModLabel = |" <<
113  // m_psiModLabel<<"|";
114  }
115  }
116  }
117 }
118 void
120 {
121  m_accession = "";
122  m_name = "";
123  m_psiModLabel = "";
124  m_diffFormula = "";
125  m_diffMono = 0;
126  m_origin = "";
127 }
128 
129 OboPsiMod::OboPsiMod(OboPsiModHandlerInterface &handler) : m_handler(handler)
130 {
131  qDebug() << "OboPsiMod::OboPsiMod";
132  initMyResource();
133  parse();
134 }
135 
137 {
138 }
139 
140 
141 void
143 {
144  // std::cout << "OboPsiMod::parse Begin parsing OBO file" << endl;
145  qDebug() << "OboPsiMod::parse Begin parsing OBO file";
146  QFile obofile(":/resources/PSI-MOD.obo");
147  if(!obofile.exists())
148  {
149  throw PappsoException(
150  QObject::tr("PSI-MOD OBO resource file : %1 not found")
151  .arg(obofile.fileName()));
152  }
153  obofile.open(QIODevice::ReadOnly);
154  QTextStream p_in(&obofile);
155 
156  // Search accession conta
157  // QTextStream in(p_in);
158  QString line = p_in.readLine();
159  bool in_term = false;
160  while(!p_in.atEnd())
161  {
162  // qDebug() << "OboPsiMod::parse line "<< line;
163  if(line.startsWith("[Term]"))
164  {
165  in_term = true;
166  m_term.clearTerm();
167  }
168  else if(line.isEmpty())
169  {
170  if(in_term)
171  {
173  in_term = false;
174  }
175  }
176  else
177  {
178  if(in_term)
179  m_term.parseLine(line);
180  // m_handler.setSequence(line);
181  }
182  line = p_in.readLine();
183  }
184  if(in_term)
185  {
187  }
188  // p_in->close();
189 
190  obofile.close();
191 }
192 
193 } // namespace pappso
pappso::OboPsiModTerm::m_psiModLabel
QString m_psiModLabel
Definition: obopsimod.h:71
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
pappso::OboPsiMod::parse
void parse()
Definition: obopsimod.cpp:142
pappso::OboPsiModTerm::m_findExactPsiModLabel
static QRegExp m_findExactPsiModLabel
Definition: obopsimod.h:65
pappso::OboPsiModTerm::m_diffFormula
QString m_diffFormula
Definition: obopsimod.h:73
pappso::OboPsiModTerm::parseLine
void parseLine(const QString &line)
Definition: obopsimod.cpp:51
pappso::OboPsiModTerm::m_accession
QString m_accession
Definition: obopsimod.h:69
pappso::OboPsiMod::~OboPsiMod
~OboPsiMod()
Definition: obopsimod.cpp:136
pappso::OboPsiModHandlerInterface::setOboPsiModTerm
virtual void setOboPsiModTerm(const OboPsiModTerm &term)=0
pappso::OboPsiModTerm::clearTerm
void clearTerm()
Definition: obopsimod.cpp:119
pappso::OboPsiModHandlerInterface
Definition: obopsimod.h:86
pappso::OboPsiMod::m_term
OboPsiModTerm m_term
Definition: obopsimod.h:94
obopsimod.h
pappso::OboPsiModTerm::m_firstParse
static QRegExp m_firstParse
Definition: obopsimod.h:64
initMyResource
void initMyResource()
Definition: obopsimod.cpp:32
pappso::OboPsiModTerm::m_name
QString m_name
Definition: obopsimod.h:70
pappso::OboPsiMod::OboPsiMod
OboPsiMod(OboPsiModHandlerInterface &handler)
Definition: obopsimod.cpp:129
pappso::OboPsiMod::m_handler
OboPsiModHandlerInterface & m_handler
Definition: obopsimod.h:95
pappso::OboPsiModTerm::m_findRelatedPsiMsLabel
static QRegExp m_findRelatedPsiMsLabel
Definition: obopsimod.h:66
pappso::OboPsiModTerm::m_diffMono
pappso_double m_diffMono
Definition: obopsimod.h:76
pappso::OboPsiModTerm::m_psiMsLabel
QString m_psiMsLabel
Definition: obopsimod.h:72
pappso::PappsoException
Definition: pappsoexception.h:63
pappso::OboPsiModTerm::m_origin
QString m_origin
Definition: obopsimod.h:74