Loading...
Searching...
No Matches
timsframe.cpp
Go to the documentation of this file.
/**
* \file pappsomspp/vendors/tims/timsframe.cpp
* \date 23/08/2019
* \author Olivier Langella
* \brief handle a single Bruker's TimsTof frame
*/
/*******************************************************************************
* Copyright (c) 2019 Olivier Langella <Olivier.Langella@u-psud.fr>.
*
* This file is part of the PAPPSOms++ library.
*
* PAPPSOms++ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAPPSOms++ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#include "timsframe.h"
#include "../../../pappsomspp/pappsoexception.h"
#include <QDebug>
#include <QObject>
#include <QtEndian>
#include <memory>
namespace pappso
{
TimsFrame::XicComputeStructure::XicComputeStructure(
const TimsFrame *fram_p, const XicCoordTims &xic_struct)
{
xic_ptr = xic_struct.xicSptr.get();
mobilityIndexBegin = xic_struct.scanNumBegin;
mobilityIndexEnd = xic_struct.scanNumEnd;
mzIndexLowerBound =
fram_p->getMzCalibrationInterfaceSPtr().get()->getTofIndexFromMz(
xic_struct.mzRange.lower()); // convert mz to raw digitizer value
mzIndexUpperBound =
fram_p->getMzCalibrationInterfaceSPtr().get()->getTofIndexFromMz(
xic_struct.mzRange.upper());
tmpIntensity = 0;
}
TimsFrame::TimsFrame(std::size_t timsId, quint32 scanNum)
: TimsFrameBase(timsId, scanNum)
{
// m_timsDataFrame.resize(10);
}
TimsFrame::TimsFrame(std::size_t timsId,
quint32 scanNum,
char *p_bytes,
std::size_t len)
: TimsFrameBase(timsId, scanNum)
{
// langella@themis:~/developpement/git/bruker/cbuild$
// ./src/sample/timsdataSamplePappso
// /gorgone/pappso/fichiers_fabricants/Bruker/Demo_TimsTOF_juin2019/Samples/1922001/1922001-1_S-415_Pep_Pur-1ul_Slot1-10_1_2088.d/
qDebug() << timsId;
m_timsDataFrame.resize(len);
if(p_bytes != nullptr)
{
unshufflePacket(p_bytes);
}
else
{
if(m_scanNumber == 0)
{
throw pappso::PappsoException(
QObject::tr("TimsFrame::TimsFrame(%1,%2,nullptr,%3) FAILED")
.arg(m_timsId)
.arg(m_scanNumber)
.arg(len));
}
}
}
TimsFrame::TimsFrame(const TimsFrame &other) : TimsFrameBase(other)
{
}
TimsFrame::~TimsFrame()
{
}
void
TimsFrame::unshufflePacket(const char *src)
{
qDebug();
quint64 len = m_timsDataFrame.size();
if(len % 4 != 0)
{
throw pappso::PappsoException(
QObject::tr("TimsFrame::unshufflePacket error: len % 4 != 0"));
}
quint64 nb_uint4 = len / 4;
char *dest = m_timsDataFrame.data();
quint64 src_offset = 0;
for(quint64 j = 0; j < 4; j++)
{
for(quint64 i = 0; i < nb_uint4; i++)
{
dest[(i * 4) + j] = src[src_offset];
src_offset++;
}
}
qDebug();
}
std::size_t
TimsFrame::getNbrPeaks(std::size_t scanNum) const
{
if(m_timsDataFrame.size() == 0)
return 0;
/*
if(scanNum == 0)
{
quint32 res = (*(quint32 *)(m_timsDataFrame.constData() + 4)) -
(*(quint32 *)(m_timsDataFrame.constData()-4));
return res / 2;
}*/
if(scanNum == (m_scanNumber - 1))
{
auto nb_uint4 = m_timsDataFrame.size() / 4;
std::size_t cumul = 0;
for(quint32 i = 0; i < m_scanNumber; i++)
{
cumul += (*(quint32 *)(m_timsDataFrame.constData() + (i * 4)));
}
return (nb_uint4 - cumul) / 2;
}
checkScanNum(scanNum);
// quint32 *res = (quint32 *)(m_timsDataFrame.constData() + (scanNum * 4));
// qDebug() << " res=" << *res;
return (*(quint32 *)(m_timsDataFrame.constData() + ((scanNum + 1) * 4))) / 2;
}
std::size_t
TimsFrame::getScanOffset(std::size_t scanNum) const
{
std::size_t offset = 0;
for(std::size_t i = 0; i < (scanNum + 1); i++)
{
offset += (*(quint32 *)(m_timsDataFrame.constData() + (i * 4)));
}
return offset;
}
std::vector<quint32>
TimsFrame::getScanIndexList(std::size_t scanNum) const
{
qDebug();
checkScanNum(scanNum);
std::vector<quint32> scan_tof;
if(m_timsDataFrame.size() == 0)
return scan_tof;
scan_tof.resize(getNbrPeaks(scanNum));
std::size_t offset = getScanOffset(scanNum);
qint32 previous = -1;
for(std::size_t i = 0; i < scan_tof.size(); i++)
{
scan_tof[i] =
(*(quint32 *)(m_timsDataFrame.constData() + (offset * 4) + (i * 8))) +
previous;
previous = scan_tof[i];
}
qDebug();
return scan_tof;
}
std::vector<quint32>
TimsFrame::getScanIntensities(std::size_t scanNum) const
{
qDebug();
checkScanNum(scanNum);
std::vector<quint32> scan_intensities;
if(m_timsDataFrame.size() == 0)
return scan_intensities;
scan_intensities.resize(getNbrPeaks(scanNum));
std::size_t offset = getScanOffset(scanNum);
for(std::size_t i = 0; i < scan_intensities.size(); i++)
{
scan_intensities[i] = (*(quint32 *)(m_timsDataFrame.constData() +
(offset * 4) + (i * 8) + 4));
}
qDebug();
return scan_intensities;
}
quint64
TimsFrame::cumulateSingleScanIntensities(std::size_t scanNum) const
{
qDebug();
quint64 summed_intensities = 0;
if(m_timsDataFrame.size() == 0)
return summed_intensities;
// checkScanNum(scanNum);
std::size_t size = getNbrPeaks(scanNum);
std::size_t offset = getScanOffset(scanNum);
qint32 previous = -1;
for(std::size_t i = 0; i < size; i++)
{
quint32 x =
(*(quint32 *)((m_timsDataFrame.constData() + (offset * 4) + (i * 8))) +
previous);
quint32 y = (*(quint32 *)(m_timsDataFrame.constData() + (offset * 4) +
(i * 8) + 4));
previous = x;
summed_intensities += y;
}
// Normalization over the accumulation time for this frame.
summed_intensities *= ((double)100.0 / m_accumulationTime);
qDebug();
return summed_intensities;
}
/**
* @brief ...
*
* @param mobility_scan_begin p_mobility_scan_begin:...
* @param mobility_scan_end p_mobility_scan_end:...
* @return quint64
*/
quint64
TimsFrame::cumulateScansIntensities(std::size_t mobility_scan_begin,
std::size_t mobility_scan_end) const
{
quint64 summed_intensities = 0;
// qDebug() << "begin mobility_scan_begin =" << mobility_scan_begin
//<< "mobility_scan_end =" << mobility_scan_end;
if(m_timsDataFrame.size() == 0)
return summed_intensities;
try
{
std::size_t mobility_scan_max = mobility_scan_end + 1;
for(std::size_t i = mobility_scan_begin; i < mobility_scan_max; i++)
{
qDebug() << i;
summed_intensities += cumulateSingleScanIntensities(i);
qDebug() << i;
}
}
catch(std::exception &error)
{
qDebug() << QString("Failure in %1 %2 to %3 :\n %4")
.arg(__FUNCTION__)
.arg(mobility_scan_begin)
.arg(mobility_scan_end)
.arg(error.what());
}
// qDebug() << "end";
return summed_intensities;
}
void
TimsFrame::cumulateScan(std::size_t scanNum,
std::map<quint32, quint32> &accumulate_into) const
{
// qDebug();
if(m_timsDataFrame.size() == 0)
return;
// checkScanNum(scanNum);
std::size_t scan_size = getNbrPeaks(scanNum);
std::size_t scan_offset = getScanOffset(scanNum);
qint32 previous = -1;
for(std::size_t i = 0; i < scan_size; i++)
{
quint32 x = (*(quint32 *)((m_timsDataFrame.constData() +
(scan_offset * 4) + (i * 8))) +
previous);
quint32 y = (*(quint32 *)(m_timsDataFrame.constData() +
(scan_offset * 4) + (i * 8) + 4));
previous = x;
auto ret = accumulate_into.insert(std::pair<quint32, quint32>(x, y));
if(ret.second == false)
{
// already existed : cumulate
ret.first->second += y;
}
}
// qDebug();
}
// Proof of concept m/z range-conditions for accumulations
void
TimsFrame::cumulateScan2(std::size_t scanNum,
std::map<quint32, quint32> &accumulate_into,
double mz_range_begin,
double mz_range_end,
quint32 accepted_tof_index_range_begin,
quint32 accepted_tof_index_range_end) const
{
// qDebug();
if(m_timsDataFrame.size() == 0)
return;
// checkScanNum(scanNum);
std::size_t scan_size = getNbrPeaks(scanNum);
std::size_t scan_offset = getScanOffset(scanNum);
qint32 previous = -1;
for(std::size_t i = 0; i < scan_size; i++)
{
quint32 x = (*(quint32 *)((m_timsDataFrame.constData() +
(scan_offset * 4) + (i * 8))) +
previous);
if(x < accepted_tof_index_range_begin)
{
// qDebug() << "TOF index still not in range, x:" << x;
continue;
}
if(x > accepted_tof_index_range_end)
{
// qDebug() << "TOF index already out of range, x:" << x;
break;
}
// qDebug() << "TOF index in range, x:" << x;
quint32 y = (*(quint32 *)(m_timsDataFrame.constData() +
(scan_offset * 4) + (i * 8) + 4));
previous = x;
auto ret = accumulate_into.insert(std::pair<quint32, quint32>(x, y));
if(ret.second == false)
{
// already existed : cumulate
ret.first->second += y;
}
}
// qDebug();
}
Trace
TimsFrame::cumulateScansToTrace(std::size_t mobility_scan_begin,
std::size_t mobility_scan_end) const
{
// qDebug();
Trace new_trace;
try
{
if(m_timsDataFrame.size() == 0)
return new_trace;
std::map<quint32, quint32> raw_spectrum;
// double local_accumulationTime = 0;
std::size_t mobility_scan_max = mobility_scan_end + 1;
qDebug();
for(std::size_t i = mobility_scan_begin; i < mobility_scan_max; i++)
{
// qDebug() << i;
cumulateScan(i, raw_spectrum);
// qDebug() << i;
// local_accumulationTime += m_accumulationTime;
}
// qDebug();
pappso::DataPoint data_point_cumul;
MzCalibrationInterface *mz_calibration_p =
getMzCalibrationInterfaceSPtr().get();
for(std::pair<quint32, quint32> pair_tof_intensity : raw_spectrum)
{
data_point_cumul.x =
mz_calibration_p->getMzFromTofIndex(pair_tof_intensity.first);
// normalization
data_point_cumul.y =
pair_tof_intensity.second * ((double)100.0 / m_accumulationTime);
new_trace.push_back(data_point_cumul);
}
new_trace.sortX();
// qDebug();
}
catch(std::exception &error)
{
qDebug() << QString(
"Failure in TimsFrame::cumulateScanToTrace %1 to %2 :\n %3")
.arg(mobility_scan_begin, mobility_scan_end)
.arg(error.what());
}
return new_trace;
}
Trace
TimsFrame::cumulateScansToTraceMzDownResolution(
std::size_t mz_index_merge_window,
std::size_t mobility_scan_begin,
std::size_t mobility_scan_end,
quint32 &mz_minimum_index_out,
quint32 &mz_maximum_index_out) const
{
// qDebug();
Trace new_trace;
try
{
if(m_timsDataFrame.size() == 0)
{
qDebug() << "The frame is empty, returning empty trace.";
return new_trace;
}
// Allocate a map for (TOF,intensity) pairs to
// accumulate ion mobility scans.
std::map<quint32, quint32> raw_spectrum;
// double local_accumulationTime = 0;
std::size_t mobility_scan_max = mobility_scan_end + 1;
for(std::size_t i = mobility_scan_begin; i < mobility_scan_max; i++)
{
// qDebug() << "Going to cumulate currently iterated mobility scan:"
// << i;
cumulateScan(i, raw_spectrum);
// qDebug() << "Done cumulating currently iterated mobility scan:" <<
// i;
// local_accumulationTime += m_accumulationTime;
}
// qDebug();
pappso::DataPoint data_point_cumul;
MzCalibrationInterface *mz_calibration_p =
getMzCalibrationInterfaceSPtr().get();
// If the caller asks that m/z values be binned larger than they are,
// ask that the m/z raw map be reduced in resolution.
if(mz_index_merge_window > 0)
raw_spectrum = downsizeMzRawMap(mz_index_merge_window, raw_spectrum);
// Store the first mz index and the last mz index of the current spectrum.
// The values are set to the out parameters.
mz_minimum_index_out = std::numeric_limits<quint32>::max();
mz_maximum_index_out = 0;
for(std::pair<quint32, quint32> pair_tof_intensity : raw_spectrum)
{
if(pair_tof_intensity.first > mz_maximum_index_out)
mz_maximum_index_out = pair_tof_intensity.first;
if(pair_tof_intensity.first < mz_minimum_index_out)
mz_minimum_index_out = pair_tof_intensity.first;
// Convert the TOF index to m/z
data_point_cumul.x =
mz_calibration_p->getMzFromTofIndex(pair_tof_intensity.first);
// Normalization
data_point_cumul.y =
pair_tof_intensity.second * ((double)100.0 / m_accumulationTime);
// Finally make the data point a new Trace point.
new_trace.push_back(data_point_cumul);
}
// qDebug() << "At this point we have mz_minimum_index_out:"
// << mz_minimum_index_out
// << "and mz_maximum_index_out:" << mz_maximum_index_out;
// FIXME: this does not seem to be necessary since raw_spectrum is a map
// with auto-sorting on the keys which are quint32.
// new_trace.sortX();
// qDebug();
}
catch(std::exception &error)
{
qDebug() << QString(
"Failure in TimsFrame::cumulateScanToTrace %1 to %2 :\n %3")
.arg(mobility_scan_begin, mobility_scan_end)
.arg(error.what());
}
// qDebug() << "Returning new trace of size:" << new_trace.size();
return new_trace;
}
Trace
TimsFrame::cumulateScansToTraceMzDownResolution2(
std::size_t mz_index_merge_window,
double mz_range_begin,
double mz_range_end,
std::size_t mobility_scan_begin,
std::size_t mobility_scan_end,
quint32 &mz_minimum_index_out,
quint32 &mz_maximum_index_out) const
{
// qDebug();
Trace new_trace;
try
{
if(m_timsDataFrame.size() == 0)
{
qDebug() << "The frame is empty, returning empty trace.";
return new_trace;
}
// Allocate a map for (TOF index,intensity) pairs to
// accumulate ion mobility scans.
std::map<quint32, quint32> raw_spectrum;
// double local_accumulationTime = 0;
std::size_t mobility_scan_max = mobility_scan_end + 1;
quint32 only_in_mz_begin_tof_index_range =
getMzCalibrationInterfaceSPtr().get()->getTofIndexFromMz(
mz_range_begin);
quint32 only_in_mz_end_tof_index_range =
getMzCalibrationInterfaceSPtr().get()->getTofIndexFromMz(mz_range_end);
// qDebug() << "20231129 TOF index range begin:"
// << only_in_mz_begin_tof_index_range;
// qDebug() << "20231129 TOF index range end:"
// << only_in_mz_end_tof_index_range;
for(std::size_t i = mobility_scan_begin; i < mobility_scan_max; i++)
{
// qDebug() << "Going to cumulate currently iterated mobility scan:"
// << i;
cumulateScan2(i,
raw_spectrum,
mz_range_begin,
mz_range_end,
only_in_mz_begin_tof_index_range,
only_in_mz_end_tof_index_range);
// qDebug() << "Done cumulating currently iterated mobility scan:" <<
// i;
// local_accumulationTime += m_accumulationTime;
}
// qDebug();
pappso::DataPoint data_point_cumul;
MzCalibrationInterface *mz_calibration_p =
getMzCalibrationInterfaceSPtr().get();
// If the caller asks that m/z values be binned larger than they are,
// ask that the m/z raw map be reduced in resolution.
if(mz_index_merge_window > 0)
raw_spectrum = downsizeMzRawMap(mz_index_merge_window, raw_spectrum);
// Store the first mz index and the last mz index of the current spectrum.
// The values are set to the out parameters.
mz_minimum_index_out = std::numeric_limits<quint32>::max();
mz_maximum_index_out = 0;
for(std::pair<quint32, quint32> pair_tof_intensity : raw_spectrum)
{
if(pair_tof_intensity.first > mz_maximum_index_out)
mz_maximum_index_out = pair_tof_intensity.first;
if(pair_tof_intensity.first < mz_minimum_index_out)
mz_minimum_index_out = pair_tof_intensity.first;
// Convert the TOF index to m/z
data_point_cumul.x =
mz_calibration_p->getMzFromTofIndex(pair_tof_intensity.first);
// Normalization
data_point_cumul.y =
pair_tof_intensity.second * ((double)100.0 / m_accumulationTime);
// Finally make the data point a new Trace point.
new_trace.push_back(data_point_cumul);
}
// qDebug() << "At this point we have mz_minimum_index_out:"
// << mz_minimum_index_out
// << "and mz_maximum_index_out:" << mz_maximum_index_out;
// FIXME: this does not seem to be necessary since raw_spectrum is a map
// with auto-sorting on the keys which are quint32.
// new_trace.sortX();
// qDebug();
}
catch(std::exception &error)
{
qDebug() << QString(
"Failure in TimsFrame::cumulateScanToTrace %1 to %2 :\n %3")
.arg(mobility_scan_begin, mobility_scan_end)
.arg(error.what());
}
// qDebug() << "Returning new trace of size:" << new_trace.size();
return new_trace;
}
void
TimsFrame::cumulateScansInRawMap(std::map<quint32, quint32> &rawSpectrum,
std::size_t mobility_scan_begin,
std::size_t mobility_scan_end) const
{
// qDebug() << "begin mobility_scan_begin=" << mobility_scan_begin
//<< " mobility_scan_end=" << mobility_scan_end;
if(m_timsDataFrame.size() == 0)
return;
try
{
std::size_t mobility_scan_max = mobility_scan_end + 1;
qDebug();
for(std::size_t i = mobility_scan_begin; i < mobility_scan_max; i++)
{
qDebug() << i;
cumulateScan(i, rawSpectrum);
qDebug() << i;
// local_accumulationTime += m_accumulationTime;
}
}
catch(std::exception &error)
{
qDebug() << QString("Failure in %1 %2 to %3 :\n %4")
.arg(__FUNCTION__)
.arg(mobility_scan_begin)
.arg(mobility_scan_end)
.arg(error.what());
}
// qDebug() << "end";
}
pappso::MassSpectrumCstSPtr
TimsFrame::getMassSpectrumCstSPtr(std::size_t scanNum) const
{
// qDebug();
return getMassSpectrumSPtr(scanNum);
}
pappso::MassSpectrumSPtr
TimsFrame::getMassSpectrumSPtr(std::size_t scanNum) const
{
// qDebug() << " scanNum=" << scanNum;
checkScanNum(scanNum);
// qDebug();
pappso::MassSpectrumSPtr mass_spectrum_sptr =
std::make_shared<pappso::MassSpectrum>();
// std::vector<DataPoint>
if(m_timsDataFrame.size() == 0)
return mass_spectrum_sptr;
// qDebug();
std::size_t size = getNbrPeaks(scanNum);
std::size_t offset = getScanOffset(scanNum);
MzCalibrationInterface *mz_calibration_p =
getMzCalibrationInterfaceSPtr().get();
qint32 previous = -1;
qint32 tof_index;
// std::vector<quint32> index_list;
DataPoint data_point;
for(std::size_t i = 0; i < size; i++)
{
tof_index =
(*(quint32 *)((m_timsDataFrame.constData() + (offset * 4) + (i * 8))) +
previous);
data_point.y = (*(quint32 *)(m_timsDataFrame.constData() + (offset * 4) +
(i * 8) + 4));
// intensity normalization
data_point.y *= 100.0 / m_accumulationTime;
previous = tof_index;
// mz calibration
data_point.x = mz_calibration_p->getMzFromTofIndex(tof_index);
mass_spectrum_sptr.get()->push_back(data_point);
}
// qDebug();
return mass_spectrum_sptr;
}
void
TimsFrame::extractTimsXicListInRtRange(
std::vector<XicCoordTims *>::iterator &itXicListbegin,
std::vector<XicCoordTims *>::iterator &itXicListend,
XicExtractMethod method) const
{
qDebug() << std::distance(itXicListbegin, itXicListend);
std::vector<TimsFrame::XicComputeStructure> tmp_xic_list;
for(auto it = itXicListbegin; it != itXicListend; it++)
{
tmp_xic_list.push_back(TimsFrame::XicComputeStructure(this, **it));
qDebug() << " tmp_xic_struct.mobilityIndexBegin="
<< tmp_xic_list.back().mobilityIndexBegin
<< " tmp_xic_struct.mobilityIndexEnd="
<< tmp_xic_list.back().mobilityIndexEnd;
qDebug() << " tmp_xic_struct.mzIndexLowerBound="
<< tmp_xic_list.back().mzIndexLowerBound
<< " tmp_xic_struct.mzIndexUpperBound="
<< tmp_xic_list.back().mzIndexUpperBound;
}
if(tmp_xic_list.size() == 0)
return;
/*
std::sort(tmp_xic_list.begin(), tmp_xic_list.end(), [](const
TimsXicStructure &a, const TimsXicStructure &b) { return
a.mobilityIndexBegin < b.mobilityIndexBegin;
});
*/
std::vector<std::size_t> unique_scan_num_list;
for(auto &&struct_xic : tmp_xic_list)
{
for(std::size_t scan = struct_xic.mobilityIndexBegin;
(scan <= struct_xic.mobilityIndexEnd) && (scan < m_scanNumber);
scan++)
{
unique_scan_num_list.push_back(scan);
}
}
std::sort(unique_scan_num_list.begin(), unique_scan_num_list.end());
auto it_scan_num_end =
std::unique(unique_scan_num_list.begin(), unique_scan_num_list.end());
auto it_scan_num = unique_scan_num_list.begin();
while(it_scan_num != it_scan_num_end)
{
TraceSPtr ms_spectrum = getRawTraceSPtr(*it_scan_num);
// qDebug() << ms_spectrum.get()->toString();
for(auto &&tmp_xic_struct : tmp_xic_list)
{
if(((*it_scan_num) >= tmp_xic_struct.mobilityIndexBegin) &&
((*it_scan_num) <= tmp_xic_struct.mobilityIndexEnd))
{
if(method == XicExtractMethod::max)
{
tmp_xic_struct.tmpIntensity +=
ms_spectrum.get()->maxY(tmp_xic_struct.mzIndexLowerBound,
tmp_xic_struct.mzIndexUpperBound);
qDebug() << "tmp_xic_struct.tmpIntensity="
<< tmp_xic_struct.tmpIntensity;
}
else
{
// sum
tmp_xic_struct.tmpIntensity +=
ms_spectrum.get()->sumY(tmp_xic_struct.mzIndexLowerBound,
tmp_xic_struct.mzIndexUpperBound);
qDebug() << "tmp_xic_struct.tmpIntensity="
<< tmp_xic_struct.tmpIntensity;
}
}
}
it_scan_num++;
}
for(auto &&tmp_xic_struct : tmp_xic_list)
{
if(tmp_xic_struct.tmpIntensity != 0)
{
qDebug() << tmp_xic_struct.xic_ptr;
tmp_xic_struct.xic_ptr->push_back(
{m_time, tmp_xic_struct.tmpIntensity});
}
}
qDebug();
}
pappso::TraceSPtr
TimsFrame::getRawTraceSPtr(std::size_t scanNum) const
{
// qDebug();
pappso::TraceSPtr trace_sptr = std::make_shared<pappso::Trace>();
// std::vector<DataPoint>
if(m_timsDataFrame.size() == 0)
return trace_sptr;
// qDebug();
std::size_t size = getNbrPeaks(scanNum);
std::size_t offset = getScanOffset(scanNum);
qint32 previous = -1;
std::vector<quint32> index_list;
for(std::size_t i = 0; i < size; i++)
{
DataPoint data_point(
(*(quint32 *)((m_timsDataFrame.constData() + (offset * 4) + (i * 8))) +
previous),
(*(quint32 *)(m_timsDataFrame.constData() + (offset * 4) + (i * 8) +
4)));
// intensity normalization
data_point.y *= 100.0 / m_accumulationTime;
previous = data_point.x;
trace_sptr.get()->push_back(data_point);
}
// qDebug();
return trace_sptr;
}
} // namespace pappso
pappso::MzCalibrationInterface
Definition mzcalibrationinterface.h:43
pappso::MzCalibrationInterface::getMzFromTofIndex
virtual double getMzFromTofIndex(quint32 tof_index)=0
get m/z from time of flight raw index
pappso::MzRange::lower
pappso_double lower() const
Definition mzrange.h:71
pappso::MzRange::upper
pappso_double upper() const
Definition mzrange.h:77
pappso::PappsoException
Definition pappsoexception.h:42
pappso::TimsFrameBase
Definition timsframebase.h:48
pappso::TimsFrameBase::m_accumulationTime
double m_accumulationTime
accumulation time in milliseconds
Definition timsframebase.h:283
pappso::TimsFrameBase::downsizeMzRawMap
std::map< quint32, quint32 > & downsizeMzRawMap(std::size_t mzindex_merge_window, std::map< quint32, quint32 > &rawSpectrum) const
downsize mz resolution to lower the number of real mz computations
Definition timsframebase.cpp:606
pappso::TimsFrameBase::m_time
double m_time
retention time
Definition timsframebase.h:289
pappso::TimsFrameBase::m_scanNumber
quint32 m_scanNumber
total number of scans contained in this frame
Definition timsframebase.h:273
pappso::TimsFrameBase::m_timsId
std::size_t m_timsId
Tims frame database id (the SQL identifier of this frame)
Definition timsframebase.h:279
pappso::TimsFrameBase::getMzCalibrationInterfaceSPtr
virtual const MzCalibrationInterfaceSPtr & getMzCalibrationInterfaceSPtr() const final
get the MzCalibration model to compute mz and TOF for this frame
Definition timsframebase.cpp:473
pappso::TimsFrameBase::checkScanNum
bool checkScanNum(std::size_t scanNum) const
check that this scan number exists
Definition timsframebase.cpp:103
pappso::TimsFrame
Definition timsframe.h:52
pappso::TimsFrame::m_timsDataFrame
QByteArray m_timsDataFrame
Definition timsframe.h:225
pappso::TimsFrame::getScanIndexList
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
Definition timsframe.cpp:171
pappso::TimsFrame::getNbrPeaks
virtual std::size_t getNbrPeaks(std::size_t scanNum) const override
get the number of peaks in this spectrum need the binary file
Definition timsframe.cpp:129
pappso::TimsFrame::cumulateScansToTraceMzDownResolution
virtual Trace cumulateScansToTraceMzDownResolution(std::size_t mzindex_merge_window, std::size_t scanNumBegin, std::size_t scanNumEnd, quint32 &minimum_index, quint32 &maximum_index) const override
cumulate spectrum given a scan number range need the binary file The intensities are normalized with ...
Definition timsframe.cpp:459
pappso::TimsFrame::~TimsFrame
virtual ~TimsFrame()
Definition timsframe.cpp:96
pappso::TimsFrame::cumulateScansIntensities
virtual quint64 cumulateScansIntensities(std::size_t scanNumBegin, std::size_t scanNumEnd) const override
...
Definition timsframe.cpp:267
pappso::TimsFrame::cumulateScansToTrace
virtual Trace cumulateScansToTrace(std::size_t scanNumBegin, std::size_t scanNumEnd) const override
cumulate scan list into a trace
Definition timsframe.cpp:400
pappso::TimsFrame::cumulateScan
virtual void cumulateScan(std::size_t scanNum, std::map< quint32, quint32 > &accumulate_into) const
cumulate a scan into a map
Definition timsframe.cpp:305
pappso::TimsFrame::TimsFrame
TimsFrame(std::size_t timsId, quint32 scanNum, char *p_bytes, std::size_t len)
Definition timsframe.cpp:61
pappso::TimsFrame::getMassSpectrumSPtr
virtual pappso::MassSpectrumSPtr getMassSpectrumSPtr(std::size_t scanNum) const override
get Mass spectrum with peaks for this scan number need the binary file
Definition timsframe.cpp:720
pappso::TimsFrame::cumulateSingleScanIntensities
virtual quint64 cumulateSingleScanIntensities(std::size_t scanNum) const override
Definition timsframe.cpp:220
pappso::TimsFrame::cumulateScan2
virtual void cumulateScan2(std::size_t scanNum, std::map< quint32, quint32 > &accumulate_into, double mz_range_begin, double mz_range_end, quint32 accepted_tof_index_range_begin, quint32 accepted_tof_index_range_end) const
Definition timsframe.cpp:344
pappso::TimsFrame::getScanIntensities
virtual std::vector< quint32 > getScanIntensities(std::size_t scanNum) const override
get raw intensities without transformation from one scan it needs intensity normalization
Definition timsframe.cpp:196
pappso::TimsFrame::unshufflePacket
void unshufflePacket(const char *src)
unshuffle data packet of tims compression type 2
Definition timsframe.cpp:102
pappso::TimsFrame::cumulateScansToTraceMzDownResolution2
Trace cumulateScansToTraceMzDownResolution2(std::size_t mz_index_merge_window, double mz_range_begin, double mz_range_end, std::size_t mobility_scan_begin, std::size_t mobility_scan_end, quint32 &mz_minimum_index_out, quint32 &mz_maximum_index_out) const
Definition timsframe.cpp:558
pappso::TimsFrame::getScanOffset
std::size_t getScanOffset(std::size_t scanNum) const
get offset for this spectrum in the binary file
Definition timsframe.cpp:159
pappso::TimsFrame::cumulateScansInRawMap
virtual void cumulateScansInRawMap(std::map< quint32, quint32 > &rawSpectrum, std::size_t scanNumBegin, std::size_t scanNumEnd) const override
cumulate scan list into a trace into a raw spectrum map
Definition timsframe.cpp:675
pappso::TimsFrame::extractTimsXicListInRtRange
void extractTimsXicListInRtRange(std::vector< XicCoordTims * >::iterator &itXicListbegin, std::vector< XicCoordTims * >::iterator &itXicListend, XicExtractMethod method) const
Definition timsframe.cpp:776
pappso::TimsFrame::getMassSpectrumCstSPtr
virtual pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtr(std::size_t scanNum) const
get the mass spectrum corresponding to a scan number
Definition timsframe.cpp:712
pappso::TimsFrame::getRawTraceSPtr
virtual pappso::TraceSPtr getRawTraceSPtr(std::size_t scanNum) const
get the raw index tof_index and intensities (normalized)
Definition timsframe.cpp:869
pappso::Trace
A simple container of DataPoint instances.
Definition trace.h:148
pappso::Trace::sortX
void sortX(SortOrder sort_order=SortOrder::ascending)
Definition trace.cpp:1086
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
pappso::PeptideIonCter::y
@ y
pappso::PeptideIonCter::x
@ x
pappso::TraceSPtr
std::shared_ptr< Trace > TraceSPtr
Definition trace.h:135
pappso::MassSpectrumCstSPtr
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
Definition massspectrum.h:57
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition massspectrum.h:56
pappso::XicExtractMethod
XicExtractMethod
Definition types.h:240
pappso::XicExtractMethod::max
@ max
maximum of intensities
pappso::DataPoint
Definition datapoint.h:22
pappso::DataPoint::x
pappso_double x
Definition datapoint.h:23
pappso::DataPoint::y
pappso_double y
Definition datapoint.h:24
pappso::TimsFrame::XicComputeStructure
Definition timsframe.h:211
pappso::TimsFrame::XicComputeStructure::tmpIntensity
double tmpIntensity
Definition timsframe.h:221
pappso::TimsFrame::XicComputeStructure::XicComputeStructure
XicComputeStructure(const TimsFrame *fram_p, const XicCoordTims &xic_struct)
Definition timsframe.cpp:39
pappso::TimsFrame::XicComputeStructure::xic_ptr
Xic * xic_ptr
Definition timsframe.h:216
pappso::TimsFrame::XicComputeStructure::mobilityIndexBegin
std::size_t mobilityIndexBegin
Definition timsframe.h:217
pappso::TimsFrame::XicComputeStructure::mzIndexUpperBound
std::size_t mzIndexUpperBound
Definition timsframe.h:220
pappso::TimsFrame::XicComputeStructure::mzIndexLowerBound
std::size_t mzIndexLowerBound
Definition timsframe.h:219
pappso::TimsFrame::XicComputeStructure::mobilityIndexEnd
std::size_t mobilityIndexEnd
Definition timsframe.h:218
pappso::XicCoordTims
coordinates of the XIC to extract and the resulting XIC after extraction
Definition xiccoordtims.h:51
pappso::XicCoordTims::scanNumEnd
std::size_t scanNumEnd
mobility index end
Definition xiccoordtims.h:98
pappso::XicCoordTims::scanNumBegin
std::size_t scanNumBegin
mobility index begin
Definition xiccoordtims.h:94
pappso::XicCoord::xicSptr
XicSPtr xicSptr
extracted xic
Definition xiccoord.h:130
pappso::XicCoord::mzRange
MzRange mzRange
the mass to extract
Definition xiccoord.h:120
timsframe.h
handle a single Bruker's TimsTof frame