libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
Loading...
Searching...
No Matches
xymsfilereader.cpp
Go to the documentation of this file.
1
/////////////////////// StdLib includes
2
3
4
/////////////////////// Qt includes
5
#include <QDebug>
6
#include <QFile>
7
#include <QFileInfo>
8
9
10
/////////////////////// libpwiz includes
11
#include <pwiz/data/msdata/DefaultReaderList.hpp>
12
13
14
/////////////////////// Local includes
15
#include "
xymsfilereader.h
"
16
#include "
pappsomspp/core/utils.h
"
17
#include "
pappsomspp/core/types.h
"
18
#include "
pappsomspp/core/msrun/msrunid.h
"
19
20
namespace
pappso
21
{
22
23
24
XyMsFileReader::XyMsFileReader
(
const
QString &file_name)
25
:
MsFileReader
{file_name}
26
{
27
}
28
29
XyMsFileReader::~XyMsFileReader
()
30
{
31
}
32
33
bool
34
XyMsFileReader::initialize
(std::size_t &line_count)
35
{
36
// Here we just test all the lines of the file to check that they comply with
37
// the xy format.
38
39
line_count = 0;
40
41
QFile file(
m_fileName
);
42
43
if
(!file.open(QFile::ReadOnly | QFile::Text))
44
{
45
qDebug() <<
"Failed to open file"
<<
m_fileName
;
46
47
return
0;
48
}
49
50
QRegularExpressionMatch regExpMatch;
51
52
QString
line
;
53
bool
file_reading_failed =
false
;
54
55
while
(!file.atEnd())
56
{
57
line
= file.readLine();
58
59
// We only read a given number of lines from the file, that would be
60
// enough to check if that file has the right syntax or not.
61
// if(linesRead >= 2000)
62
// return true;
63
64
if
(
line
.startsWith(
'#'
) ||
line
.isEmpty() ||
65
Utils::endOfLineRegExp
.match(
line
).hasMatch())
66
continue
;
67
68
// qDebug() << "Current xy format line:" << line;
69
70
if
(
Utils::xyMassDataFormatRegExp
.match(
line
).hasMatch())
71
{
72
++line_count;
73
continue
;
74
}
75
else
76
{
77
// the first line of the text file may include column titles
78
if
(line_count > 0)
79
{
80
file_reading_failed =
true
;
81
break
;
82
}
83
}
84
}
85
86
if
(!file_reading_failed && line_count >= 1)
87
{
88
m_fileFormat
=
Enums::MsDataFormat::xy
;
89
return
true
;
90
}
91
92
m_fileFormat
=
Enums::MsDataFormat::unknown
;
93
94
// qDebug() << "m_fileFormat: " << static_cast<int>(m_fileFormat);
95
96
return
false
;
97
}
98
99
Enums::MsDataFormat
100
XyMsFileReader::getFileFormat
()
101
{
102
return
m_fileFormat
;
103
}
104
105
std::vector<MsRunIdCstSPtr>
106
XyMsFileReader::getMsRunIds
(
const
QString &run_prefix)
107
{
108
std::vector<MsRunIdCstSPtr> ms_run_ids;
109
110
std::size_t line_count = 0;
111
112
if
(!
initialize
(line_count))
113
return
ms_run_ids;
114
115
// Finally create the MsRunId with the file name.
116
MsRunId
ms_run_id(
m_fileName
);
117
ms_run_id.
setMsDataFormat
(
m_fileFormat
);
118
119
// We need to set the unambiguous xmlId string.
120
ms_run_id.
setXmlId
(
121
QString(
"%1%2"
).arg(run_prefix).arg(
Utils::getLexicalOrderedString
(0)));
122
123
// Craft a meaningful sample name because otherwise all the files loaded from
124
// text files will have the same sample name and it will be difficult to
125
// differentiate them.
126
// Orig version:
127
// ms_run_id.setRunId("Single spectrum");
128
// Now the sample name is nothing but the file name without the path.
129
130
QFileInfo file_info(
m_fileName
);
131
132
// qDebug() << "file name:" << m_fileName;
133
134
QString sample_name = file_info.fileName();
135
136
// qDebug() << "sample name:" << sample_name;
137
138
ms_run_id.
setRunId
(sample_name);
139
140
// Now set the sample name to the run id:
141
142
ms_run_id.
setSampleName
(ms_run_id.
getRunId
());
143
144
// Now set the sample name to the run id:
145
146
ms_run_id.
setSampleName
(ms_run_id.
getRunId
());
147
148
// qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
149
//<< "Current ms_run_id:" << ms_run_id.toString();
150
151
// Finally make a shared pointer out of it and append it to the vector.
152
ms_run_ids.push_back(std::make_shared<MsRunId>(ms_run_id));
153
154
return
ms_run_ids;
155
}
156
157
158
}
// namespace pappso
CardanoResultCase::line
@ line
Definition
cardano.h:42
pappso::MsFileReader::MsFileReader
MsFileReader(const QString &file_name)
Definition
msfilereader.cpp:19
pappso::MsFileReader::m_fileFormat
Enums::MsDataFormat m_fileFormat
Definition
msfilereader.h:17
pappso::MsFileReader::m_fileName
QString m_fileName
Definition
msfilereader.h:16
pappso::MsRunId
MS run identity MsRunId identifies an MS run with a unique ID (XmlId) and contains eventually informa...
Definition
msrunid.h:54
pappso::MsRunId::setMsDataFormat
void setMsDataFormat(Enums::MsDataFormat format)
Definition
msrunid.cpp:168
pappso::MsRunId::getRunId
const QString & getRunId() const
Definition
msrunid.cpp:140
pappso::MsRunId::setRunId
void setRunId(const QString &run_id)
Definition
msrunid.cpp:133
pappso::MsRunId::setXmlId
void setXmlId(const QString &xml_id)
set an XML unique identifier for this MsRunId
Definition
msrunid.cpp:147
pappso::MsRunId::setSampleName
void setSampleName(const QString &name)
set a sample name for this MsRunId
Definition
msrunid.cpp:77
pappso::Utils::xyMassDataFormatRegExp
static QRegularExpression xyMassDataFormatRegExp
Regular expression matching <numerical value><non-numerical*><numericalvalue>.
Definition
utils.h:60
pappso::Utils::getLexicalOrderedString
static const QString getLexicalOrderedString(unsigned int num)
Definition
utils.cpp:72
pappso::Utils::endOfLineRegExp
static QRegularExpression endOfLineRegExp
Regular expression that tracks the end of line in text files.
Definition
utils.h:69
pappso::XyMsFileReader::getMsRunIds
virtual std::vector< MsRunIdCstSPtr > getMsRunIds(const QString &run_prefix) override
Definition
xymsfilereader.cpp:106
pappso::XyMsFileReader::getFileFormat
virtual Enums::MsDataFormat getFileFormat() override
Definition
xymsfilereader.cpp:100
pappso::XyMsFileReader::initialize
virtual bool initialize(std::size_t &line_count)
Definition
xymsfilereader.cpp:34
pappso::XyMsFileReader::XyMsFileReader
XyMsFileReader(const QString &file_name)
Definition
xymsfilereader.cpp:24
pappso::XyMsFileReader::~XyMsFileReader
virtual ~XyMsFileReader()
Definition
xymsfilereader.cpp:29
msrunid.h
pappso::Enums::MsDataFormat
MsDataFormat
Definition
types.h:141
pappso::Enums::MsDataFormat::xy
@ xy
(x,y) format
Definition
types.h:147
pappso::Enums::MsDataFormat::unknown
@ unknown
unknown format
Definition
types.h:142
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition
aa.cpp:39
types.h
utils.h
xymsfilereader.h
pappsomspp
core
msfile
xymsfilereader.cpp
Generated on
for libpappsomspp by
1.17.0