libpappsomspp
Library for mass spectrometry
pappso::XyMsFileReader Class Reference

#include <xymsfilereader.h>

Inheritance diagram for pappso::XyMsFileReader:
pappso::MsFileReader

Public Member Functions

 XyMsFileReader (const QString &file_name)
 
virtual ~XyMsFileReader ()
 
virtual MzFormat getFileFormat () override
 
virtual std::vector< MsRunIdCstSPtrgetMsRunIds (const QString &run_prefix) override
 
MsRunReaderselectMsRunReader (const QString &file_name) const
 

Private Member Functions

virtual std::size_t initialize ()
 
- Private Member Functions inherited from pappso::MsFileReader
 MsFileReader (const QString &file_name)
 
virtual ~MsFileReader ()
 
virtual MzFormat getFileFormat ()=0
 
virtual std::vector< MsRunIdCstSPtrgetMsRunIds (const QString &run_prefix)=0
 

Additional Inherited Members

- Private Attributes inherited from pappso::MsFileReader
QString m_fileName
 
MzFormat m_fileFormat = MzFormat::unknown
 

Detailed Description

Definition at line 16 of file xymsfilereader.h.

Constructor & Destructor Documentation

◆ XyMsFileReader()

pappso::XyMsFileReader::XyMsFileReader ( const QString &  file_name)

Definition at line 28 of file xymsfilereader.cpp.

29 : MsFileReader{file_name}
30{
31 initialize();
32}
MsFileReader(const QString &file_name)
virtual std::size_t initialize()

References initialize().

◆ ~XyMsFileReader()

pappso::XyMsFileReader::~XyMsFileReader ( )
virtual

Definition at line 35 of file xymsfilereader.cpp.

36{
37}

Member Function Documentation

◆ getFileFormat()

MzFormat pappso::XyMsFileReader::getFileFormat ( )
overridevirtual

Implements pappso::MsFileReader.

Definition at line 99 of file xymsfilereader.cpp.

100{
101 return m_fileFormat;
102}

References pappso::MsFileReader::m_fileFormat.

Referenced by pappso::MsFileAccessor::getMsRunIds().

◆ getMsRunIds()

std::vector< MsRunIdCstSPtr > pappso::XyMsFileReader::getMsRunIds ( const QString &  run_prefix)
overridevirtual

Implements pappso::MsFileReader.

Definition at line 106 of file xymsfilereader.cpp.

107{
108 std::vector<MsRunIdCstSPtr> ms_run_ids;
109
110 if(!initialize())
111 return ms_run_ids;
112
113 // Finally create the MsRunId with the file name.
114 MsRunId ms_run_id(m_fileName);
115 ms_run_id.setMzFormat(m_fileFormat);
116
117 // We need to set the unambiguous xmlId string.
118 ms_run_id.setXmlId(
119 QString("%1%2").arg(run_prefix).arg(Utils::getLexicalOrderedString(0)));
120
121 // Craft a meaningful sample name because otherwise all the files loaded from
122 // text files will have the same sample name and it will be difficult to
123 // differentiate them.
124 // Orig version:
125 // ms_run_id.setRunId("Single spectrum");
126 // Now the sample name is nothing but the file name without the path.
127
128 QFileInfo file_info(m_fileName);
129
130 // qDebug() << "file name:" << m_fileName;
131
132 QString sample_name = file_info.fileName();
133
134 // qDebug() << "sample name:" << sample_name;
135
136 ms_run_id.setRunId(sample_name);
137
138 // Now set the sample name to the run id:
139
140 ms_run_id.setSampleName(ms_run_id.getRunId());
141
142 // Now set the sample name to the run id:
143
144 ms_run_id.setSampleName(ms_run_id.getRunId());
145
146 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
147 //<< "Current ms_run_id:" << ms_run_id.toString();
148
149 // Finally make a shared pointer out of it and append it to the vector.
150 ms_run_ids.push_back(std::make_shared<MsRunId>(ms_run_id));
151
152 return ms_run_ids;
153}
static const QString getLexicalOrderedString(unsigned int num)
Definition: utils.cpp:52

References pappso::Utils::getLexicalOrderedString(), pappso::MsRunId::getRunId(), initialize(), pappso::MsFileReader::m_fileFormat, pappso::MsFileReader::m_fileName, pappso::MsRunId::setMzFormat(), pappso::MsRunId::setRunId(), pappso::MsRunId::setSampleName(), and pappso::MsRunId::setXmlId().

Referenced by pappso::MsFileAccessor::getMsRunIds().

◆ initialize()

std::size_t pappso::XyMsFileReader::initialize ( )
privatevirtual

Definition at line 41 of file xymsfilereader.cpp.

42{
43 // Here we just test all the lines of the file to check that they comply with
44 // the xy format.
45
46 std::size_t line_count = 0;
47
48 QFile file(m_fileName);
49
50 if(!file.open(QFile::ReadOnly | QFile::Text))
51 {
52 qDebug() << "Failed to open file" << m_fileName;
53
54 return 0;
55 }
56
57 QRegularExpressionMatch regExpMatch;
58
59 QString line;
60 bool file_reading_failed = false;
61
62 while(!file.atEnd())
63 {
64 line = file.readLine();
65 ++line_count;
66
67 // We only read a given number of lines from the file, that would be
68 // enough to check if that file has the right syntax or not.
69 // if(linesRead >= 2000)
70 // return true;
71
72 if(line.startsWith('#') || line.isEmpty() ||
73 Utils::endOfLineRegExp.match(line).hasMatch())
74 continue;
75
76 // qDebug() << __FILE__ << __LINE__ << "Current xy format line:" << line;
77
78 if(Utils::xyMassDataFormatRegExp.match(line).hasMatch())
79 continue;
80 else
81 {
82 file_reading_failed = true;
83 break;
84 }
85 }
86
87 if(!file_reading_failed && line_count >= 1)
89 else
91
92 qDebug() << "m_fileFormat: " << static_cast<int>(m_fileFormat);
93
94 return line_count;
95}
static QRegularExpression xyMassDataFormatRegExp
Definition: utils.h:53
static QRegularExpression endOfLineRegExp
Regular expression that tracks the end of line in text files.
Definition: utils.h:62
@ xy
(x,y) format
@ unknown
unknown format

References pappso::Utils::endOfLineRegExp, pappso::MsFileReader::m_fileFormat, pappso::MsFileReader::m_fileName, pappso::unknown, pappso::xy, and pappso::Utils::xyMassDataFormatRegExp.

Referenced by XyMsFileReader(), and getMsRunIds().

◆ selectMsRunReader()

MsRunReader * pappso::XyMsFileReader::selectMsRunReader ( const QString &  file_name) const

The documentation for this class was generated from the following files: