libpappsomspp
Library for mass spectrometry
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"
33
34using namespace pappso;
35
36IonMobilityGrid::IonMobilityGrid()
37{
38}
39
41{
42}
43
44void
46 const pappso::MsRunId &msrun_ida,
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(
54 QString("%1-%2").arg(msrun_ida.getXmlId()).arg(msrun_idb.getXmlId()));
55
56
57 if(msrun_ida.getXmlId() > msrun_idb.getXmlId())
58 {
59 msrun_key =
60 QString("%1-%2").arg(msrun_idb.getXmlId()).arg(msrun_ida.getXmlId());
61 std::swap(xic_coorda, xic_coordb);
62 }
63
64 auto it_start =
65 m_mapDiferrencesStart.insert({msrun_key, std::vector<qint64>()});
66 it_start.first->second.push_back(
68 .toLongLong() -
70 .toLongLong());
71
72
73 auto it_stop =
74 m_mapDiferrencesStop.insert({msrun_key, std::vector<qint64>()});
75 it_stop.first->second.push_back(
77 .toLongLong() -
79 .toLongLong());
80}
81
82void
84{
85 for(auto pair_key_start_vector : m_mapDiferrencesStart)
86 {
87
88 if(pair_key_start_vector.second.size() > 5)
89 {
90 // median
91 const auto middleItr = pair_key_start_vector.second.begin() +
92 (pair_key_start_vector.second.size() / 2);
93 std::nth_element(pair_key_start_vector.second.begin(),
94 middleItr,
95 pair_key_start_vector.second.end());
96 m_mapCorrectionsStart[pair_key_start_vector.first] = *middleItr;
97 }
98 else
99 {
100 m_mapCorrectionsStart[pair_key_start_vector.first] = 0;
101 }
102 }
103 m_mapDiferrencesStart.clear();
104 for(auto pair_key_stop_vector : m_mapDiferrencesStop)
105 {
106
107 if(pair_key_stop_vector.second.size() > 5)
108 {
109 // median
110 const auto middleItr = pair_key_stop_vector.second.begin() +
111 (pair_key_stop_vector.second.size() / 2);
112 std::nth_element(pair_key_stop_vector.second.begin(),
113 middleItr,
114 pair_key_stop_vector.second.end());
115 m_mapCorrectionsStop[pair_key_stop_vector.first] = *middleItr;
116 }
117 else
118 {
119 m_mapCorrectionsStop[pair_key_stop_vector.first] = 0;
120 }
121 }
122 m_mapDiferrencesStop.clear();
123}
124
127 const pappso::XicCoord &source_xic_coord,
128 const pappso::MsRunId &source_msrunid,
129 const pappso::MsRunId &target_msrunid) const
130{
131 if(m_mapCorrectionsStop.size() == 0)
132 {
133 return source_xic_coord.initializeAndClone();
134 }
135
136 bool opposed = false;
137 QString msrun_key(QString("%1-%2")
138 .arg(source_msrunid.getXmlId())
139 .arg(target_msrunid.getXmlId()));
140
141
142 if(source_msrunid.getXmlId() > target_msrunid.getXmlId())
143 {
144 msrun_key = QString("%1-%2")
145 .arg(target_msrunid.getXmlId())
146 .arg(source_msrunid.getXmlId());
147 opposed = true;
148 }
149 auto itstart = m_mapCorrectionsStart.find(msrun_key);
150 long start_dev = 0;
151 if(itstart != m_mapCorrectionsStart.end())
152 {
153 start_dev = itstart->second;
154 if(opposed)
155 {
156 start_dev *= -1;
157 }
158 }
159
160 auto itstop = m_mapCorrectionsStop.find(msrun_key);
161 long stop_dev = 0;
162 if(itstop != m_mapCorrectionsStop.end())
163 {
164 stop_dev = itstop->second;
165 if(opposed)
166 {
167 stop_dev *= -1;
168 }
169 }
170
171 pappso::XicCoordSPtr result_xic_coord_sp =
172 source_xic_coord.initializeAndClone();
173 XicCoordTims *tims_coord =
174 static_cast<XicCoordTims *>(result_xic_coord_sp.get());
175
176 tims_coord->scanNumBeginRangeCorrection(start_dev, stop_dev);
177
178 return result_xic_coord_sp;
179}
180
181const std::map<QString, std::vector<qint64>> &
183{
184 return m_mapDiferrencesStart;
185}
186
187const std::map<QString, long> &
189{
190 return m_mapCorrectionsStart;
191}
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
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
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
store observed ion mobility coordinates differences between MS runs
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
std::shared_ptr< XicCoord > XicCoordSPtr
Definition: xiccoord.h:43
coordinates of the XIC to extract and the resulting XIC after extraction
Definition: xiccoordtims.h:51
void scanNumBeginRangeCorrection(long start_dev, long stop_dev)
coordinates of the XIC to extract and the resulting XIC after extraction
Definition: xiccoord.h:67
virtual XicCoordSPtr initializeAndClone() const
intialize the XIC and make a deep copy of object
Definition: xiccoord.cpp:54
virtual const QVariant getParam(XicCoordParam param) const
get a specific XIC coordinate parameter
Definition: xiccoord.cpp:123
XIC coordinate in a Tims MSrun.