Loading...
Searching...
No Matches
timsdatafastmap.cpp
Go to the documentation of this file.
/**
* \file pappsomspp/vendors/tims/timsdatafastmap.h
* \date 16/12/2023
* \author Olivier Langella
* \brief replacement fot std::map dedicated to tims data for fast computations
*/
/*******************************************************************************
* Copyright (c) 2023 Olivier Langella
*<Olivier.Langella@universite-paris-saclay.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 "timsdatafastmap.h"
#include <QDebug>
#include "../../exception/exceptionoutofrange.h"
namespace pappso
{
std::map<QThread *, TimsDataFastMap>
TimsDataFastMap::m_preAllocatedFastMapPerThread = {};
pappso::TimsDataFastMap &
TimsDataFastMap::getTimsDataFastMapInstance()
{
auto it = TimsDataFastMap::m_preAllocatedFastMapPerThread.insert(
{QThread::currentThread(), TimsDataFastMap()});
if(it.second)
{
it.first->second.mapTofIndexIntensity.resize(500000);
}
return it.first->second;
}
TimsDataFastMap::TimsDataFastMap()
{
// map.resize(500000);
}
std::size_t
TimsDataFastMap::accumulateIntensity(quint32 key, std::size_t intensity)
{
qDebug();
try
{
TimsDataFastMapElement &map_element = mapTofIndexIntensity.at(key);
if(map_element.first_access)
{
map_element.first_access = false;
map_element.count = intensity;
tofIndexList.push_back(key);
}
else
{
map_element.count += intensity;
}
qDebug();
return map_element.count;
}
catch(std::out_of_range &error)
{
throw pappso::ExceptionOutOfRange(
QObject::tr("out of range exception for tof index %1 ").arg(key));
}
}
std::size_t
TimsDataFastMap::readIntensity(quint32 key)
{
TimsDataFastMapElement &map_element = mapTofIndexIntensity.at(key);
// FIXME: why set first_access to true below?
map_element.first_access = true;
return map_element.count;
}
void
TimsDataFastMap::downsizeMzRawMap(std::size_t mzindex_merge_window)
{
std::vector<std::pair<quint32, std::size_t>> temp_vector;
for(quint32 tof_index : tofIndexList)
{
temp_vector.push_back({tof_index, readIntensity(tof_index)});
}
tofIndexList.clear();
for(auto &pair_tof_intensity : temp_vector)
{
quint32 mzkey = (pair_tof_intensity.first / mzindex_merge_window);
mzkey = (mzkey * mzindex_merge_window) + (mzindex_merge_window / 2);
accumulateIntensity(mzkey, pair_tof_intensity.second);
}
}
void
TimsDataFastMap::builtInCentroid()
{
qDebug() << "tofIndexList.size()=" << tofIndexList.size();
if(tofIndexList.size() > 2)
{
std::vector<quint32> tof_index_list_tmp = tofIndexList;
std::sort(tof_index_list_tmp.begin(), tof_index_list_tmp.end());
tofIndexList.clear();
quint32 previous_tof_index = tof_index_list_tmp[0];
std::size_t previous_intensity = readIntensity(previous_tof_index);
for(std::size_t i = 1; i < tof_index_list_tmp.size(); i++)
{
quint32 tof_index = tof_index_list_tmp[i];
if(previous_tof_index == tof_index - 1)
{
std::size_t intensity = readIntensity(tof_index);
if(previous_intensity > intensity)
{
// flush writing current accumulated intensity
accumulateIntensity(previous_tof_index,
previous_intensity + intensity);
previous_intensity = 0;
previous_tof_index = tof_index;
}
else
{
// accumulate while intensity increases
previous_intensity += intensity;
previous_tof_index = tof_index;
}
}
else
{
// write accumulated intensity :
if(previous_intensity > 0)
{
// flush
accumulateIntensity(previous_tof_index, previous_intensity);
}
previous_tof_index = tof_index;
previous_intensity = readIntensity(tof_index);
}
}
// write remaining intensity :
if(previous_intensity > 0)
{
// flush
accumulateIntensity(previous_tof_index, previous_intensity);
}
}
qDebug() << "tofIndexList.size()=" << tofIndexList.size();
}
void
TimsDataFastMap::removeArtefactualSpike()
{
std::vector<quint32> tof_index_list_tmp = tofIndexList;
tofIndexList.clear();
for(quint32 tof_index : tof_index_list_tmp)
{
if((tof_index > 0) && mapTofIndexIntensity[tof_index - 1].first_access &&
mapTofIndexIntensity[tof_index + 1].first_access &&
(mapTofIndexIntensity[tof_index].count == 10))
{
// this measure is too small and alone : remove it
mapTofIndexIntensity[tof_index].first_access = true;
}
else
{
tofIndexList.push_back(tof_index);
}
}
}
const std::vector<quint32> &
TimsDataFastMap::getTofIndexList() const
{
return tofIndexList;
}
void
TimsDataFastMap::clear()
{
tofIndexList.clear();
}
} // namespace pappso
pappso::ExceptionOutOfRange
Definition exceptionoutofrange.h:32
pappso::TimsDataFastMap
replacement for std::map
Definition timsdatafastmap.h:46
pappso::TimsDataFastMap::accumulateIntensity
std::size_t accumulateIntensity(quint32 tofIndex, std::size_t intensity)
accumulates intesity for the given tof index
Definition timsdatafastmap.cpp:60
pappso::TimsDataFastMap::removeArtefactualSpike
void removeArtefactualSpike()
Definition timsdatafastmap.cpp:176
pappso::TimsDataFastMap::getTofIndexList
const std::vector< quint32 > & getTofIndexList() const
Definition timsdatafastmap.cpp:198
pappso::TimsDataFastMap::builtInCentroid
void builtInCentroid()
simple filter to agregate counts on neigbhor mobility slots (+1)
Definition timsdatafastmap.cpp:118
pappso::TimsDataFastMap::TimsDataFastMap
TimsDataFastMap()
Definition timsdatafastmap.cpp:54
pappso::TimsDataFastMap::readIntensity
std::size_t readIntensity(quint32)
reads intensity for a tof_index
Definition timsdatafastmap.cpp:88
pappso::TimsDataFastMap::tofIndexList
std::vector< quint32 > tofIndexList
Definition timsdatafastmap.h:104
pappso::TimsDataFastMap::downsizeMzRawMap
void downsizeMzRawMap(std::size_t mzindex_merge_window)
downsize mz resolution to lower the number of real mz computations
Definition timsdatafastmap.cpp:97
pappso::TimsDataFastMap::getTimsDataFastMapInstance
static TimsDataFastMap & getTimsDataFastMapInstance()
Definition timsdatafastmap.cpp:41
pappso::TimsDataFastMap::m_preAllocatedFastMapPerThread
static std::map< QThread *, TimsDataFastMap > m_preAllocatedFastMapPerThread
Definition timsdatafastmap.h:48
pappso::TimsDataFastMap::mapTofIndexIntensity
std::vector< TimsDataFastMapElement > mapTofIndexIntensity
Definition timsdatafastmap.h:106
pappso::TimsDataFastMap::clear
void clear()
Definition timsdatafastmap.cpp:204
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
pappso::TimsDataFastMap::TimsDataFastMapElement
Definition timsdatafastmap.h:55
pappso::TimsDataFastMap::TimsDataFastMapElement::count
std::size_t count
Definition timsdatafastmap.h:57
pappso::TimsDataFastMap::TimsDataFastMapElement::first_access
bool first_access
Definition timsdatafastmap.h:56
timsdatafastmap.h
replacement fot std::map dedicated to tims data for fast computations