libpappsomspp
Library for mass spectrometry
timsdirectxicextractor.cpp
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/vendors/tims/xicextractor/timsdirectxicextractor.cpp
3  * \date 21/09/2019
4  * \author Olivier Langella
5  * \brief minimum functions to extract XICs from Tims Data
6  */
7 
8 /*******************************************************************************
9  * Copyright (c) 2019 Olivier Langella <Olivier.Langella@u-psud.fr>.
10  *
11  * This file is part of the PAPPSOms++ library.
12  *
13  * PAPPSOms++ is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * PAPPSOms++ is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
25  *
26  ******************************************************************************/
27 
28 #include "timsdirectxicextractor.h"
29 #include "../../../msrun/xiccoord/xiccoordtims.h"
30 #include "../../../exception/exceptioninterrupted.h"
31 #include <QDebug>
32 
33 using namespace pappso;
34 
36  : pappso::TimsXicExtractorInterface(msrun_reader)
37 {
38 }
39 
41 {
42 }
43 
44 
45 void
47  UiMonitorInterface &monitor,
48  std::vector<XicCoordSPtr>::iterator it_xic_coord_list_begin,
49  std::vector<XicCoordSPtr>::iterator it_xic_coord_list_end)
50 {
51  qDebug();
52  std::size_t xic_total_number =
53  std::distance(it_xic_coord_list_begin, it_xic_coord_list_end);
54  if(xic_total_number == 0)
55  return;
56 
57  std::vector<XicCoordTims *> xic_coord_tims_list;
58  xic_coord_tims_list.reserve(xic_total_number);
59 
60  for(auto it = it_xic_coord_list_begin; it != it_xic_coord_list_end; it++)
61  {
62  XicCoordTims *p_xic_coord_tims = dynamic_cast<XicCoordTims *>(it->get());
63  if(p_xic_coord_tims == nullptr)
64  {
65  }
66  else
67  {
68  xic_coord_tims_list.push_back(p_xic_coord_tims);
69  }
70  }
71 
72  std::sort(xic_coord_tims_list.begin(),
73  xic_coord_tims_list.end(),
74  [](const XicCoordTims *pa, const XicCoordTims *pb) {
75  return pa->rtTarget < pb->rtTarget;
76  });
77 
78 
79  std::vector<std::size_t> tims_frameid_list =
80  mp_timsData->getTimsMS1FrameIdRange(
81  xic_coord_tims_list[0]->rtTarget - m_retentionTimeAroundTarget,
82  xic_coord_tims_list.back()->rtTarget + m_retentionTimeAroundTarget);
83 
84  monitor.setStatus(QObject::tr("extracting %1 XICs on %2 Tims frames")
85  .arg(xic_total_number)
86  .arg(tims_frameid_list.size()));
87  monitor.setTotalSteps(tims_frameid_list.size());
88 
89  qDebug() << " tims_frameid_list.size()=" << tims_frameid_list.size();
90  qDebug() << " rt begin=" << xic_coord_tims_list[0]->rtTarget;
91  qDebug() << " rt end=" << xic_coord_tims_list.back()->rtTarget;
92  for(std::size_t frame_id : tims_frameid_list)
93  {
94  std::vector<XicCoordTims *>::iterator itXicListbegin =
95  xic_coord_tims_list.begin();
96  std::vector<XicCoordTims *>::iterator itXicListend =
97  xic_coord_tims_list.end();
98  qDebug();
99  TimsFrameCstSPtr frame_sptr =
100  mp_timsData->getTimsFrameCstSPtrCached(frame_id);
101  qDebug();
102  double rtframe = frame_sptr.get()->getTime();
103  qDebug();
104 
105  double rtbeginframe = rtframe - m_retentionTimeAroundTarget;
106  double rtendframe = rtframe + m_retentionTimeAroundTarget;
107 
108  if(rtbeginframe < 0)
109  rtbeginframe = 0;
110 
111  qDebug() << rtbeginframe;
112  while((itXicListbegin != itXicListend) &&
113  ((*itXicListbegin)->rtTarget < rtbeginframe))
114  {
115  itXicListbegin++;
116  }
117  qDebug();
118  itXicListend = itXicListbegin;
119  while((itXicListend != xic_coord_tims_list.end()) &&
120  ((*itXicListend)->rtTarget < rtendframe))
121  {
122  itXicListend++;
123  }
124  frame_sptr.get()->extractTimsXicListInRtRange(
125  itXicListbegin, itXicListend, m_xicExtractMethod);
126 
127  qDebug() << "" << frame_sptr.get()->getId();
128  monitor.count();
129  if(monitor.shouldIstop())
130  {
132  QObject::tr("Xic extraction process interrupted"));
133  }
134  }
135  qDebug();
136 }
TimsDirectXicExtractor(MsRunReaderSPtr &msrun_reader)
void protectedExtractXicCoordSPtrList(UiMonitorInterface &monitor, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_begin, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_end) override
virtual void setStatus(const QString &status)=0
current status of the process
virtual void setTotalSteps(std::size_t total_number_of_steps)
use it if the number of steps is known in an algorithm the total number of steps is usefull to report...
virtual bool shouldIstop()=0
should the procces be stopped ? If true, then cancel process Use this function at strategic point of ...
virtual void count()=0
count steps report when a step is computed in an algorithm
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
std::shared_ptr< MsRunReader > MsRunReaderSPtr
Definition: msrunreader.h:185
std::shared_ptr< const TimsFrame > TimsFrameCstSPtr
Definition: timsframe.h:42
coordinates of the XIC to extract and the resulting XIC after extraction
Definition: xiccoordtims.h:51
minimum functions to extract XICs from Tims Data