30#include "../../../pappsomspp/pappsoexception.h"
31#include "../../../pappsomspp/exception/exceptionoutofrange.h"
32#include "../../../pappsomspp/exception/exceptionnotimplemented.h"
35#include <liblzf/lzf.h>
50 if(p_bytes !=
nullptr)
63 "TimsFrameType1::TimsFrameType1(%1,%2,nullptr,%3) FAILED")
84 qDebug() <<
" m_scanNumber=" <<
m_scanNumber <<
" len=" << len;
89 qDebug() <<
" count=" << count;
107 qDebug() <<
"offset begin at last :" << count + 4;
111 std::size_t previous_offset = (*(quint32 *)(src));
112 qDebug() <<
"first offset= " << previous_offset;
113 std::size_t cumul_decompressed_size = 0;
118 offset = (*(quint32 *)(src + (i * 4)));
120 std::size_t compressed_size = offset - previous_offset;
122 qDebug() <<
"scan i=" << i <<
" previous_offset=" << previous_offset
123 <<
" offset=" << offset <<
" length=" << compressed_size;
127 if(cumul_decompressed_size < remaining_size)
129 remaining_size = remaining_size - cumul_decompressed_size;
135 qDebug() <<
" remaining_size=" << remaining_size;
136 std::size_t decompressed_size =
145 cumul_decompressed_size += decompressed_size;
146 qDebug() <<
" decompressed_size=" << decompressed_size;
149 previous_offset = offset;
170 unsigned int src_len,
172 unsigned int dest_len)
174 qDebug() <<
"src=" << src <<
" src_len=" << src_len
175 <<
" dest_len=" << dest_len;
178 unsigned int decompressed_size;
179 unsigned int more_space = src_len * 2;
180 decompressed_size = lzf_decompress(src, src_len, dest, dest_len);
181 while(decompressed_size == 0)
183 qDebug() <<
"dest_len=" << dest_len;
184 qDebug() <<
"decompressed_size=" << decompressed_size;
189 QObject::tr(
"ERROR reading TimsFrameType1 %1 TIMS binary file %2: "
190 "LZF decompression error EINVAL")
193 else if(errno == E2BIG)
196 <<
" more_space=" << more_space;
198 dest_len += more_space;
200 decompressed_size = lzf_decompress(src, src_len, dest, dest_len);
207 return decompressed_size;
214 return mass_spectrum_sptr.get()->size();
220 std::map<quint32, quint32> &accumulate_into)
const
233 qint32 tof_index = 0;
234 for(std::size_t i = 0; i < size; i++)
241 tof_index += -1 * value;
246 quint32
x = tof_index;
249 auto ret = accumulate_into.insert(std::pair<quint32, quint32>(
x,
y));
251 if(ret.second ==
false)
254 ret.first->second +=
y;
265 std::map<quint32, quint32> &accumulate_into,
266 quint32 accepted_tof_index_range_begin,
267 quint32 accepted_tof_index_range_end)
const
280 qint32 tof_index = 0;
281 for(std::size_t i = 0; i < size; i++)
288 tof_index += -1 * value;
293 quint32
x = tof_index;
297 if(
x < accepted_tof_index_range_begin)
302 if(
x > accepted_tof_index_range_end)
306 auto ret = accumulate_into.insert(std::pair<quint32, quint32>(
x,
y));
308 if(ret.second ==
false)
311 ret.first->second +=
y;
325 std::vector<quint32> mzindex_values;
333 return mzindex_values;
340 qDebug() <<
" offset=" << offset <<
" size=" << size;
342 return mzindex_values;
345 qint32 tof_index = 0;
347 for(std::size_t i = 0; i < size; i++)
353 tof_index += -1 * value;
357 mzindex_values.push_back(tof_index);
364 return mzindex_values;
373 .arg(error.
qwhat()));
383 qDebug() <<
" scanNum=" << scanNum;
387 std::vector<quint32> int_values;
402 qDebug() <<
" offset=" << offset <<
" size=" << size;
407 qint32 tof_index = 0;
409 for(std::size_t i = 0; i < size; i++)
415 tof_index += -1 * value;
419 int_values.push_back(value);
435 .arg(error.
qwhat()));
443 qDebug() <<
" scanNum=" << scanNum;
452 std::make_shared<pappso::MassSpectrum>();
456 return mass_spectrum_sptr;
463 qDebug() <<
" offset=" << offset <<
" size=" << size;
465 return mass_spectrum_sptr;
473 qint32 tof_index = 0;
476 for(std::size_t i = 0; i < size; i++)
482 tof_index += -1 * value;
486 data_point.
y = value;
494 mass_spectrum_sptr.get()->push_back(data_point);
500 qDebug() << mass_spectrum_sptr.get()->toString();
501 return mass_spectrum_sptr;
506 QObject::tr(
"Error TimsFrameType1::getMassSpectrumSPtr frameId=%1 "
510 .arg(error.
qwhat()));
532 qDebug() <<
" offset=" << offset <<
" size=" << size;
538 qint32 tof_index = 0;
542 for(std::size_t i = 0; i < size; i++)
548 tof_index += -1 * value;
552 data_point.
y = value;
559 data_point.
x = tof_index;
560 trace_sptr.get()->push_back(data_point);
571std::vector<TimsFrameType1::RawValuePair>
573 quint32 accepted_tof_index_range_begin,
574 quint32 accepted_tof_index_range_end)
const
579 std::vector<TimsFrame::RawValuePair> trace_sptr;
590 qDebug() <<
" offset=" << offset <<
" size=" << size;
596 qint32 tof_index = 0;
600 for(std::size_t i = 0; i < size; i++)
606 tof_index += -1 * value;
627 trace_sptr.push_back(data_point);
virtual double getMzFromTofIndex(quint32 tof_index)=0
get m/z from time of flight raw index
virtual const QString & qwhat() const
double m_accumulationTime
accumulation time in milliseconds
quint32 m_scanNumber
total number of scans contained in this frame
std::size_t m_timsId
Tims frame database id (the SQL identifier of this frame)
virtual const MzCalibrationInterfaceSPtr & getMzCalibrationInterfaceSPtr() const final
get the MzCalibration model to compute mz and TOF for this frame
bool checkScanNum(std::size_t scanNum) const
check that this scan number exists
std::size_t getId() const
virtual void cumulateScan2(std::size_t scanNum, std::map< quint32, quint32 > &accumulate_into, quint32 accepted_tof_index_range_begin, quint32 accepted_tof_index_range_end) const override
virtual std::vector< quint32 > getScanIndexList(std::size_t scanNum) const override
get raw index list for one given scan index are not TOF nor m/z, just index on digitizer
std::vector< std::size_t > m_scanSizeList
TimsFrameType1(std::size_t timsId, quint32 scanNum, char *p_bytes, std::size_t len)
void copyAndLzfDecompress(const char *src, std::size_t len)
copy buffer header and lzf decompress each scan for tims compression type 1
virtual std::vector< RawValuePair > getRawValuePairList(std::size_t scanNum, quint32 accepted_tof_index_range_begin, quint32 accepted_tof_index_range_end) const override
get the raw index tof_index and intensities (normalized)
virtual std::size_t getNbrPeaks(std::size_t scanNum) const override
get the number of peaks in this spectrum need the binary file
virtual void cumulateScan(std::size_t scanNum, std::map< quint32, quint32 > &accumulate_into) const override
cumulate a scan into a map
unsigned int lzfDecompressScan(const char *src, unsigned int src_len, char *dest, unsigned int dest_len)
decompress a single LZF compressed scan buffer
virtual pappso::MassSpectrumSPtr getMassSpectrumSPtr(std::size_t scanNum) const override
get the mass spectrum corresponding to a scan number
virtual std::vector< quint32 > getScanIntensities(std::size_t scanNum) const override
get raw intensities without transformation from one scan it needs intensity normalization
std::vector< std::size_t > m_scanOffsetList
virtual pappso::TraceSPtr getRawTraceSPtr(std::size_t scanNum) const override
get the raw index tof_index and intensities (normalized)
virtual ~TimsFrameType1()
QByteArray m_timsDataFrame
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
std::shared_ptr< Trace > TraceSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
handle a single Bruker's TimsTof frame type 1 compression