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;
268 std::vector<quint32> mzindex_values;
276 return mzindex_values;
283 qDebug() <<
" offset=" << offset <<
" size=" << size;
285 return mzindex_values;
288 qint32 tof_index = 0;
290 for(std::size_t i = 0; i < size; i++)
296 tof_index += -1 * value;
300 mzindex_values.push_back(tof_index);
307 return mzindex_values;
316 .arg(error.
qwhat()));
326 qDebug() <<
" scanNum=" << scanNum;
330 std::vector<quint32> int_values;
345 qDebug() <<
" offset=" << offset <<
" size=" << size;
350 qint32 tof_index = 0;
352 for(std::size_t i = 0; i < size; i++)
358 tof_index += -1 * value;
362 int_values.push_back(value);
378 .arg(error.
qwhat()));
386 qDebug() <<
" scanNum=" << scanNum;
395 std::make_shared<pappso::MassSpectrum>();
399 return mass_spectrum_sptr;
406 qDebug() <<
" offset=" << offset <<
" size=" << size;
408 return mass_spectrum_sptr;
416 qint32 tof_index = 0;
419 for(std::size_t i = 0; i < size; i++)
425 tof_index += -1 * value;
429 data_point.
y = value;
437 mass_spectrum_sptr.get()->push_back(data_point);
443 qDebug() << mass_spectrum_sptr.get()->toString();
444 return mass_spectrum_sptr;
449 QObject::tr(
"Error TimsFrameType1::getMassSpectrumSPtr frameId=%1 "
453 .arg(error.
qwhat()));
475 qDebug() <<
" offset=" << offset <<
" size=" << size;
481 qint32 tof_index = 0;
485 for(std::size_t i = 0; i < size; i++)
491 tof_index += -1 * value;
495 data_point.
y = value;
502 data_point.
x = tof_index;
503 trace_sptr.get()->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 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::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