libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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 MsDataFormat getFileFormat () override
 
virtual std::vector< MsRunIdCstSPtrgetMsRunIds (const QString &run_prefix) override
 
MsRunReaderselectMsRunReader (const QString &file_name) const
 

Private Member Functions

virtual bool initialize (std::size_t &line_count)
 
- Private Member Functions inherited from pappso::MsFileReader
 MsFileReader (const QString &file_name)
 
virtual ~MsFileReader ()
 

Additional Inherited Members

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

Detailed Description

Definition at line 17 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}
MsFileReader(const QString &file_name)

◆ ~XyMsFileReader()

pappso::XyMsFileReader::~XyMsFileReader ( )
virtual

Definition at line 34 of file xymsfilereader.cpp.

35{
36}

Member Function Documentation

◆ getFileFormat()

MsDataFormat pappso::XyMsFileReader::getFileFormat ( )
overridevirtual

Implements pappso::MsFileReader.

Definition at line 107 of file xymsfilereader.cpp.

108{
109 return m_fileFormat;
110}
MsDataFormat m_fileFormat

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 114 of file xymsfilereader.cpp.

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

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

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

◆ initialize()

bool pappso::XyMsFileReader::initialize ( std::size_t & line_count)
privatevirtual

Definition at line 40 of file xymsfilereader.cpp.

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

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

Referenced by getMsRunIds().

◆ selectMsRunReader()

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

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