libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
ionmobilitygrid.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/msrun/xiccoord/ionmobilitygrid.cpp
3 * \date 26/01/2023
4 * \author Olivier Langella
5 * \brief store observed ion mobility coordinates differences between MS runs
6 */
7
8
9/*******************************************************************************
10 * Copyright (c) 2023 Olivier Langella
11 *<Olivier.Langella@universite-paris-saclay.fr>.
12 *
13 * This file is part of the PAPPSOms++ library.
14 *
15 * PAPPSOms++ is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * PAPPSOms++ is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
27 *
28 ******************************************************************************/
29
30#include "ionmobilitygrid.h"
31#include <QVariant>
32#include "xiccoordtims.h"
34
35using namespace pappso;
36
40
44
45void
47 const pappso::XicCoord *xic_coorda,
48 const pappso::MsRunId &msrun_idb,
49 const pappso::XicCoord *xic_coordb)
50{
51 if(msrun_ida == msrun_idb)
52 return;
53 QString msrun_key(QString("%1-%2").arg(msrun_ida.getXmlId()).arg(msrun_idb.getXmlId()));
54
55
56 if(msrun_ida.getXmlId() > msrun_idb.getXmlId())
57 {
58 msrun_key = QString("%1-%2").arg(msrun_idb.getXmlId()).arg(msrun_ida.getXmlId());
59 std::swap(xic_coorda, xic_coordb);
60 }
61
62 auto it_start = m_mapDiferrencesStart.insert({msrun_key, std::vector<qint64>()});
63 const QVariant &ref_variantb =
65 if(ref_variantb.isNull())
66 {
67 throw pappso::ExceptionNotPossible(QObject::tr(
68 "XicCoordParam::TimsTofIonMobilityScanNumberStart QVariant is null for xic_coordb"));
69 }
70 const QVariant &ref_varianta =
72
73 if(ref_varianta.isNull())
74 {
75 throw pappso::ExceptionNotPossible(QObject::tr(
76 "XicCoordParam::TimsTofIonMobilityScanNumberStart QVariant is null for xic_coorda"));
77 }
78 it_start.first->second.push_back(ref_variantb.toLongLong() - ref_varianta.toLongLong());
79
80
81 auto it_stop = m_mapDiferrencesStop.insert({msrun_key, std::vector<qint64>()});
82 it_stop.first->second.push_back(
85}
86
87void
89{
90 for(auto pair_key_start_vector : m_mapDiferrencesStart)
91 {
92
93 if(pair_key_start_vector.second.size() > 5)
94 {
95 // median
96 const auto middleItr =
97 pair_key_start_vector.second.begin() + (pair_key_start_vector.second.size() / 2);
98 std::nth_element(
99 pair_key_start_vector.second.begin(), middleItr, pair_key_start_vector.second.end());
100 m_mapCorrectionsStart[pair_key_start_vector.first] = *middleItr;
101 }
102 else
103 {
104 m_mapCorrectionsStart[pair_key_start_vector.first] = 0;
105 }
106 }
107 m_mapDiferrencesStart.clear();
108 for(auto pair_key_stop_vector : m_mapDiferrencesStop)
109 {
110
111 if(pair_key_stop_vector.second.size() > 5)
112 {
113 // median
114 const auto middleItr =
115 pair_key_stop_vector.second.begin() + (pair_key_stop_vector.second.size() / 2);
116 std::nth_element(
117 pair_key_stop_vector.second.begin(), middleItr, pair_key_stop_vector.second.end());
118 m_mapCorrectionsStop[pair_key_stop_vector.first] = *middleItr;
119 }
120 else
121 {
122 m_mapCorrectionsStop[pair_key_stop_vector.first] = 0;
123 }
124 }
125 m_mapDiferrencesStop.clear();
126}
127
130 const pappso::MsRunId &source_msrunid,
131 const pappso::MsRunId &target_msrunid) const
132{
133 if(m_mapCorrectionsStop.size() == 0)
134 {
135 return source_xic_coord.initializeAndClone();
136 }
137
138 bool opposed = false;
139 QString msrun_key(QString("%1-%2").arg(source_msrunid.getXmlId()).arg(target_msrunid.getXmlId()));
140
141
142 if(source_msrunid.getXmlId() > target_msrunid.getXmlId())
143 {
144 msrun_key = QString("%1-%2").arg(target_msrunid.getXmlId()).arg(source_msrunid.getXmlId());
145 opposed = true;
146 }
147 auto itstart = m_mapCorrectionsStart.find(msrun_key);
148 long start_dev = 0;
149 if(itstart != m_mapCorrectionsStart.end())
150 {
151 start_dev = itstart->second;
152 if(opposed)
153 {
154 start_dev *= -1;
155 }
156 }
157
158 auto itstop = m_mapCorrectionsStop.find(msrun_key);
159 long stop_dev = 0;
160 if(itstop != m_mapCorrectionsStop.end())
161 {
162 stop_dev = itstop->second;
163 if(opposed)
164 {
165 stop_dev *= -1;
166 }
167 }
168
169 pappso::XicCoordSPtr result_xic_coord_sp = source_xic_coord.initializeAndClone();
170 XicCoordTims *tims_coord = static_cast<XicCoordTims *>(result_xic_coord_sp.get());
171
172 tims_coord->scanNumBeginRangeCorrection(start_dev, stop_dev);
173
174 return result_xic_coord_sp;
175}
176
177const std::map<QString, std::vector<qint64>> &
182
183const std::map<QString, long> &
std::map< QString, long > m_mapCorrectionsStop
scan num correction on start position stored for each msrun pair
const std::map< QString, long > & getMapCorrectionsStart() const
pappso::XicCoordSPtr translateXicCoordFromTo(const pappso::XicCoord &source_xic_coord, const MsRunId &source_msrunid, const MsRunId &target_msrunid) const
std::map< QString, std::vector< qint64 > > m_mapDiferrencesStart
std::map< QString, long > m_mapCorrectionsStart
scan num correction on start position stored for each msrun pair
void storeObservedIdentityBetween(const MsRunId &msrun_ida, const XicCoord *xic_coorda, const MsRunId &msrun_idb, const XicCoord *xic_coordb)
const std::map< QString, std::vector< qint64 > > & getMapDiferrencesStart() const
std::map< QString, std::vector< qint64 > > m_mapDiferrencesStop
MS run identity MsRunId identifies an MS run with a unique ID (XmlId) and contains eventually informa...
Definition msrunid.h:54
const QString & getXmlId() const
Definition msrunid.cpp:144
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
@ TimsTofIonMobilityScanNumberStart
Definition xiccoord.h:52
std::shared_ptr< XicCoord > XicCoordSPtr
Definition xiccoord.h:44
coordinates of the XIC to extract and the resulting XIC after extraction
void scanNumBeginRangeCorrection(long start_dev, long stop_dev)
apply scan num correction on xic coordinate
coordinates of the XIC to extract and the resulting XIC after extraction
Definition xiccoord.h:68
virtual XicCoordSPtr initializeAndClone() const
intialize the XIC and make a deep copy of object
Definition xiccoord.cpp:52
virtual const QVariant getParam(XicCoordParam param) const
get a specific XIC coordinate parameter
Definition xiccoord.cpp:121