libpappsomspp
Library for mass spectrometry
pappso::TimsBinDec Class Reference

#include <timsbindec.h>

Public Member Functions

 TimsBinDec (const QFileInfo &timsBinFile, int timsCompressionType)
 
 TimsBinDec (const TimsBinDec &other)
 
 ~TimsBinDec ()
 
TimsFrameSPtr getTimsFrameSPtrByOffset (std::size_t timsId, std::size_t timsOffset) const
 

Private Member Functions

void indexingFile ()
 

Private Attributes

QString m_timsBinFile
 

Detailed Description

Todo:
write docs

Definition at line 58 of file timsbindec.h.

Constructor & Destructor Documentation

◆ TimsBinDec() [1/2]

TimsBinDec::TimsBinDec ( const QFileInfo &  timsBinFile,
int  timsCompressionType 
)

Default constructor

Definition at line 35 of file timsbindec.cpp.

36  : m_timsBinFile(timsBinFile.absoluteFilePath())
37 {
38 
39  if(timsCompressionType != 2)
40  {
42  QObject::tr("compression type %1 not handled by this library")
43  .arg(timsCompressionType));
44  }
45  if(m_timsBinFile.isEmpty())
46  {
48  QObject::tr("No TIMS binary file name specified"));
49  }
50  QFile file(m_timsBinFile);
51  if(!file.open(QIODevice::ReadOnly))
52  {
53  throw PappsoException(
54  QObject::tr("ERROR opening TIMS binary file %1 for read")
55  .arg(timsBinFile.absoluteFilePath()));
56  }
57 }

References m_timsBinFile.

◆ TimsBinDec() [2/2]

TimsBinDec::TimsBinDec ( const TimsBinDec other)

Copy constructor

Parameters
otherTODO

Definition at line 60 of file timsbindec.cpp.

62 {
63 }

◆ ~TimsBinDec()

TimsBinDec::~TimsBinDec ( )

Destructor

Definition at line 65 of file timsbindec.cpp.

66 {
67 }

Member Function Documentation

◆ getTimsFrameSPtrByOffset()

TimsFrameSPtr TimsBinDec::getTimsFrameSPtrByOffset ( std::size_t  timsId,
std::size_t  timsOffset 
) const

Definition at line 143 of file timsbindec.cpp.

145 {
146  qDebug() << "timsId:" << timsId << "timsOffset:" << timsOffset;
147 
148  // QMutexLocker locker(&m_mutex);
149  QFile file(m_timsBinFile);
150  if(!file.open(QIODevice::ReadOnly))
151  {
152  throw PappsoException(
153  QObject::tr("ERROR opening TIMS binary file %1 for read")
154  .arg(m_timsBinFile));
155  }
156 
157  bool seekpos_ok = file.seek(timsOffset);
158  if(!seekpos_ok)
159  {
160  throw PappsoException(
161  QObject::tr("ERROR reading TIMS frame %1 TIMS binary file %2: "
162  "m_timsBinFile.seek(%3) failed")
163  .arg(timsId)
164  .arg(m_timsBinFile)
165  .arg(timsOffset));
166  }
167 
168  quint32 frame_length;
169  file.read((char *)&frame_length, 4);
170  // frame_length = qToBigEndian(frame_length);
171 
172  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
173  // << " frame_length=" << frame_length;
174 
175  quint32 scan_number;
176  file.read((char *)&scan_number, 4);
177  // scan_number = qToBigEndian(scan_number);
178  frame_length -= 8;
179 
180  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
181  // << " pos=" << m_timsBinFile.pos();
182 
183  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
184  // << " scan_number=" << scan_number;
185  // m_timsBinFile.seek(m_indexArray.at(timsId) + 8);
186 
187 
188  qDebug();
189 
190  QByteArray frame_byte_array = file.read((qint64)frame_length + 2);
191 
192  file.close();
193 
194  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
195  // << " +frame_length-1="
196  // << (quint8) * (frame_byte_array.constData() + frame_length - 1);
197  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
198  // << " +frame_length="
199  // << (quint8) * (frame_byte_array.constData() + frame_length);
200  // m_timsBinFile.seek(m_indexArray.at(timsId) + 8);
201 
202  if(frame_byte_array.size() - 2 != (qint64)frame_length)
203  {
204  throw PappsoException(
205  QObject::tr("ERROR reading TIMS frame %1 TIMS binary file %2: "
206  "frame_byte_array.size()%3 != %4frame_length")
207  .arg(timsId)
208  .arg(m_timsBinFile)
209  .arg(frame_byte_array.size())
210  .arg(frame_length));
211  }
212  TimsFrameSPtr frame_sptr;
213  if(frame_length > 0)
214  {
215  auto decompressed_size2 =
216  ZSTD_getFrameContentSize(frame_byte_array.constData(), frame_length);
217 
218  if(decompressed_size2 == ZSTD_CONTENTSIZE_UNKNOWN)
219  {
220  throw PappsoException(
221  QObject::tr("ERROR reading TIMS frame %1 TIMS binary file %2: "
222  " decompressed_size2 == ZSTD_CONTENTSIZE_UNKNOWN, "
223  "frame_length=%3")
224  .arg(timsId)
225  .arg(m_timsBinFile)
226  .arg(frame_length));
227  }
228 
229  if(decompressed_size2 == ZSTD_CONTENTSIZE_ERROR)
230  {
231  throw PappsoException(
232  QObject::tr(
233  "ERROR reading TIMS frame %1 TIMS binary file %2: "
234  " decompressed_size2 == ZSTD_CONTENTSIZE_ERROR, frame_length=%3")
235  .arg(timsId)
236  .arg(m_timsBinFile)
237  .arg(frame_length));
238  }
239  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
240  << " decompressed_size2=" << decompressed_size2;
241 
242  char *uncompress = new char[decompressed_size2 + 10];
243  std::size_t decompressed_size =
244  ZSTD_decompress(uncompress,
245  decompressed_size2 + 10,
246  frame_byte_array.constData(),
247  frame_length);
248  qDebug();
249 
250  if(decompressed_size != decompressed_size2)
251  {
252  throw PappsoException(
253  QObject::tr("ERROR reading TIMS frame %1 TIMS binary file %2: "
254  "decompressed_size != decompressed_size2")
255  .arg(timsId)
256  .arg(m_timsBinFile)
257  .arg(decompressed_size)
258  .arg(decompressed_size2));
259  }
260 
261  qDebug();
262 
263  frame_sptr = std::make_shared<TimsFrame>(
264  timsId, scan_number, uncompress, decompressed_size);
265 
266  delete[] uncompress;
267  }
268  else
269  {
270  frame_sptr = std::make_shared<TimsFrame>(timsId, scan_number, nullptr, 0);
271  }
272  return frame_sptr;
273 }

References m_timsBinFile.

Referenced by pappso::TimsData::getTimsFrameCstSPtr().

◆ indexingFile()

void TimsBinDec::indexingFile ( )
private

Definition at line 71 of file timsbindec.cpp.

72 {
73 
74  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
75  QFile file(m_timsBinFile);
76  QDataStream bin_in(&file);
77  bin_in.setByteOrder(QDataStream::ByteOrder::LittleEndian);
78  // m_indexArray.push_back(0);
79 
80  // QChar first_char;
81  // txt_in >> first_char;
82  quint32 number_in;
83  qint64 position(0);
84  qint8 trash;
85  while(!bin_in.atEnd())
86  {
87  while((!bin_in.atEnd()) && (position % 4 != 0))
88  {
89  bin_in >> trash;
90  position += 1;
91  if(trash != 0)
92  { /*
93  throw PappsoException(
94  QObject::tr("ERROR reading TIMS frame %1 TIMS binary file %2: "
95  "trash%3 != 0")
96  .arg(m_indexArray.size())
97  .arg(m_timsBinFile.fileName())
98  .arg(trash));*/
99  }
100  }
101  quint32 frame_len(0);
102  while((!bin_in.atEnd()) && (frame_len == 0))
103  {
104  bin_in >> frame_len;
105  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
106  // << " i=" << i;
107  position += 4;
108  }
109 
110  // m_indexArray.push_back(position - 4);
111  /*
112  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
113  << " frame_len=" << frame_len
114  << " frameid=" << m_indexArray.size() - 1
115  << " back=" << m_indexArray.back() << " position=" <<
116  position;
117 
118 
119  quint64 next_frame = m_indexArray.back() + frame_len;
120  */
121 
122  bin_in >> number_in;
123  position += 4;
124  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
125  << " number_in(nb scans)=" << number_in
126  << " position=" << position;
127  ;
128  /*
129 
130  while((!bin_in.atEnd()) && (position < next_frame))
131  {
132  bin_in >> trash;
133  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " <<
134  __LINE__
135  // << " i=" << i;
136  position += 1;
137  }*/
138  }
139  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
140 }

References m_timsBinFile.

Member Data Documentation

◆ m_timsBinFile

QString pappso::TimsBinDec::m_timsBinFile
private

Definition at line 105 of file timsbindec.h.

Referenced by getTimsFrameSPtrByOffset(), indexingFile(), and TimsBinDec().


The documentation for this class was generated from the following files:
pappso::TimsFrameSPtr
std::shared_ptr< TimsFrame > TimsFrameSPtr
Definition: timsframe.h:58
pappso::TimsBinDec::m_timsBinFile
QString m_timsBinFile
Definition: timsbindec.h:105
pappso::PappsoException
Definition: pappsoexception.h:62