libpappsomspp
Library for mass spectrometry
msrunid.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>.
3  *
4  * This file is part of the PAPPSOms++ library.
5  *
6  * PAPPSOms++ is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * PAPPSOms++ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Contributors:
20  * Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and
21  *implementation
22  ******************************************************************************/
23 
24 #include "msrunid.h"
25 #include <QFileInfo>
26 #include <QDir>
27 
28 
29 int msRunIdMetaTypeId = qRegisterMetaType<pappso::MsRunId>("pappso::MsRunId");
30 
31 
33  qRegisterMetaType<pappso::MsRunIdCstSPtr>("pappso::MsRunIdCstSPtr");
34 
35 
36 namespace pappso
37 {
38 
40 {
41 }
42 
43 
44 MsRunId::MsRunId(const QString &file_name) : m_fileName(file_name)
45 {
46  // by default, the sample name is given by the file name
47  QFileInfo fileinfo(m_fileName);
48  if(fileinfo.fileName() == "analysis.tdf")
49  {
50  m_fileName = fileinfo.absoluteDir().absolutePath();
51  }
52  m_sampleName = QFileInfo(m_fileName).baseName();
53 }
54 
55 
56 MsRunId::MsRunId(const QString &file_name, const QString &run_id)
57  : MsRunId(file_name)
58 {
59  m_runId = run_id;
60 }
61 
62 
64  : m_fileName(other.m_fileName),
65  m_runId(other.m_runId),
66  m_xmlId(other.m_xmlId),
67  m_sampleName(other.m_sampleName),
68  m_mzFormat(other.m_mzFormat)
69 {
70 }
71 
72 
74 {
75 }
76 
77 
78 void
79 MsRunId::setSampleName(const QString &name)
80 {
81  m_sampleName = name;
82 }
83 
84 
85 const QString &
87 {
88  return m_sampleName;
89 }
90 
91 
92 void
93 MsRunId::setFileName(const QString &file_name)
94 {
95  m_fileName = file_name;
96 
97  QFileInfo file_info(file_name);
98  QString extension = file_info.suffix();
99 
100  if(m_sampleName.isEmpty())
101  {
102  // set sample name by default :
103  m_sampleName = file_info.baseName();
104  }
105 
107 
108  if(extension.toLower() == "mzxml")
109  {
111  }
112  else if(extension.toLower() == "mgf")
113  {
115  }
116  else if(extension.toLower() == "mzml")
117  {
119  }
120 }
121 
122 void
123 MsRunId::setRunId(const QString &run_id)
124 {
125  m_runId = run_id;
126 }
127 
128 
129 const QString &
131 {
132  return m_runId;
133 }
134 
135 
136 void
137 MsRunId::setXmlId(const QString &xml_id)
138 {
139  m_xmlId = xml_id;
140 }
141 
142 
143 const QString &
145 {
146  return m_xmlId;
147 }
148 
149 
150 const QString &
152 {
153  return m_fileName;
154 }
155 
156 
157 void
159 {
160  m_mzFormat = format;
161 }
162 
163 
164 MzFormat
166 {
167  return m_mzFormat;
168 }
169 
170 
171 bool
172 MsRunId::operator==(const MsRunId &other) const
173 {
174  if(m_xmlId == other.m_xmlId)
175  return true;
176  return false;
177 }
178 
179 
180 MsRunId &
182 {
183  m_xmlId = other.m_xmlId;
184  m_fileName = other.m_fileName;
185  m_sampleName = other.m_sampleName;
186  m_mzFormat = other.m_mzFormat;
187 
188  return *this;
189 }
190 
191 
192 QString
194 {
195  QString text = QString(
196  "file name: '%1'\n"
197  "run id: '%2'\n"
198  "xml id: '%3'\n"
199  "sample name: '%4'\n")
200  .arg(m_fileName)
201  .arg(m_runId)
202  .arg(m_xmlId)
203  .arg(m_sampleName);
204 
205  return text;
206 }
207 
208 
209 bool
211 {
212  return !m_fileName.isEmpty() && !m_runId.isEmpty() && !m_xmlId.isEmpty() &&
214 }
215 
216 
217 } // namespace pappso
MS run identity MsRunId identifies an MS run with a unique ID (XmlId) and contains eventually informa...
Definition: msrunid.h:53
QString m_runId
Definition: msrunid.h:90
MzFormat m_mzFormat
Definition: msrunid.h:93
MzFormat getMzFormat() const
Definition: msrunid.cpp:165
QString m_xmlId
Definition: msrunid.h:91
const QString & getFileName() const
Definition: msrunid.cpp:151
QString toString() const
Definition: msrunid.cpp:193
const QString & getXmlId() const
Definition: msrunid.cpp:144
virtual ~MsRunId()
Definition: msrunid.cpp:73
QString m_sampleName
Definition: msrunid.h:92
void setFileName(const QString &file_name)
Definition: msrunid.cpp:93
MsRunId & operator=(const MsRunId &other)
Definition: msrunid.cpp:181
const QString & getRunId() const
Definition: msrunid.cpp:130
const QString & getSampleName() const
Definition: msrunid.cpp:86
void setRunId(const QString &run_id)
Definition: msrunid.cpp:123
void setMzFormat(MzFormat format)
Definition: msrunid.cpp:158
void setXmlId(const QString &xml_id)
set an XML unique identifier for this MsRunId
Definition: msrunid.cpp:137
QString m_fileName
Definition: msrunid.h:89
bool isValid() const
Definition: msrunid.cpp:210
void setSampleName(const QString &name)
set a sample name for this MsRunId
Definition: msrunid.cpp:79
bool operator==(const MsRunId &other) const
Definition: msrunid.cpp:172
int msRunIdCstSPtrMetaTypeId
Definition: msrunid.cpp:32
int msRunIdMetaTypeId
Definition: msrunid.cpp:29
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
MzFormat
Definition: types.h:108
@ unknown
unknown format
@ MGF
Mascot format.