libpappsomspp
Library for mass spectrometry
msrunxicextractordiskbuffer.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/xicextractor/private/msrunxicextractordiskbuffer.cpp
3 * \date 18/05/2018
4 * \author Olivier Langella
5 * \brief proteowizard based XIC extractor featuring disk cache + write buffer
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2018 Olivier Langella <Olivier.Langella@u-psud.fr>.
10 *
11 * This file is part of the PAPPSOms++ library.
12 *
13 * PAPPSOms++ is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * PAPPSOms++ is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
25 *
26 * Contributors:
27 * Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and
28 *implementation
29 ******************************************************************************/
30
31
33#include <QDebug>
34#include "../../pappsoexception.h"
35#include "../../massspectrum/massspectrum.h"
36
37namespace pappso
38{
39
41 MsRunReaderSPtr &msrun_reader, const QDir &temporary_dir)
42 : MsRunXicExtractorDisk(msrun_reader, temporary_dir)
43{
44
45 m_sliceBufferMap.clear();
46}
47
49 const MsRunXicExtractorDiskBuffer &other)
51{
52
53 m_sliceBufferMap.clear();
54}
55
57{
58}
59
60void
62 std::map<unsigned int, MassSpectrum> &slice_vector, std::size_t ipos)
63{
64
66 for(auto &&msrun_slice : slice_vector)
67 {
68 appendSliceInBuffer(msrun_slice.first, msrun_slice.second, ipos);
69 }
70
72 {
74 }
75}
76
77void
79 MassSpectrum &spectrum,
80 std::size_t ipos)
81{
82 qDebug();
83
84 std::size_t spectrum_size = spectrum.size();
85
86 if(spectrum_size == 0)
87 return;
88 try
89 {
90 std::pair<std::map<unsigned int, QByteArray>::iterator, bool> ret =
91 m_sliceBufferMap.insert(
92 std::pair<unsigned int, QByteArray>(slice_number, QByteArray()));
93
94
95 if(ret.second)
96 { // new buffer
97 ret.first->second.resize(0);
98 QDataStream outstream(&ret.first->second, QIODevice::WriteOnly);
99 outstream << (quint32)ipos;
100 outstream << spectrum;
101 }
102 else
103 {
104 QDataStream outstream(&ret.first->second,
105 QIODevice::WriteOnly | QIODevice::Append);
106 outstream << (quint32)ipos;
107 outstream << spectrum;
108 }
109 }
110 catch(PappsoException &error_pappso)
111 {
113 QObject::tr("appendSliceInBuffer : error ipos=%1 :\n%2")
114 .arg(ipos)
115 .arg(error_pappso.qwhat()));
116 }
117 catch(std::exception &error)
118 {
120 QObject::tr("appendSliceInBuffer slice_number=%1 ipos=%2 error :\n%3")
121 .arg(slice_number)
122 .arg(ipos)
123 .arg(error.what()));
124 }
125 qDebug();
126}
127
128
129void
131{
132 qDebug();
133
134 try
135 {
136 for(auto &buffer_pair : m_sliceBufferMap)
137 {
138
139 if(buffer_pair.second.size() > 0)
140 {
141 QFile slice_file(QString("%1/%2")
142 .arg(mpa_temporaryDirectory->path())
143 .arg(buffer_pair.first));
144 bool new_file = false;
145 if(!slice_file.exists())
146 {
147 new_file = true;
148
149 if(!slice_file.open(QIODevice::WriteOnly))
150 {
152 QObject::tr("unable to open file %1")
153 .arg(slice_file.fileName()));
154 }
155 }
156 else
157 {
158 if(!slice_file.open(QIODevice::WriteOnly | QIODevice::Append))
159 {
161 QObject::tr("unable to open file %1")
162 .arg(slice_file.fileName()));
163 }
164 }
165
166 QDataStream stream(&slice_file);
167
168 if(new_file)
169 {
170 stream << (quint32)buffer_pair.first;
171 stream << (quint32)m_rtSize;
172 stream.writeRawData(buffer_pair.second.constData(),
173 buffer_pair.second.size());
174 }
175 else
176 {
177 stream.writeRawData(buffer_pair.second.constData(),
178 buffer_pair.second.size());
179 }
180
181
182 slice_file.flush();
183 slice_file.close();
184 }
185 // buffer_pair.second = std::vector<MassSpectrum>();
186 }
187
188 m_bufferSize = 0;
189 m_sliceBufferMap.clear();
190 }
191 catch(PappsoException &error_pappso)
192 {
194 QObject::tr("flushBufferOnDisk error :\n%1").arg(error_pappso.qwhat()));
195 }
196 catch(std::exception &error)
197 {
199 QObject::tr("flushBufferOnDisk error :\n%1").arg(error.what()));
200 }
201 qDebug();
202}
203
204
205void
207{
209
210 m_sliceBufferMap.clear();
211
212 msp_msrun_reader.get()->releaseDevice();
213}
214} // namespace pappso
Class to represent a mass spectrum.
Definition: massspectrum.h:71
void appendSliceInBuffer(unsigned int slice_number, MassSpectrum &spectrum, std::size_t ipos)
std::map< unsigned int, QByteArray > m_sliceBufferMap
MsRunXicExtractorDiskBuffer(const MsRunXicExtractorDiskBuffer &other)
virtual void storeSlices(std::map< unsigned int, MassSpectrum > &slice_vector, std::size_t ipos) override
store MassSpectrum slices (by daltons) for a given retention time
virtual const QString & qwhat() const
proteowizard based XIC extractor featuring disk cache + write buffer
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
std::shared_ptr< MsRunReader > MsRunReaderSPtr
Definition: msrunreader.h:185