masschroq_gui.cpp 4.05 KB
Newer Older
Edlira Nano's avatar
Edlira Nano committed
1
2
3
4
5
6
7
8
/**
 * \file masschroq_gui.cpp
 * \date November 10, 2011
 * \author Edlira Nano
 */


#include "masschroq_gui.h"
Edlira Nano's avatar
Edlira Nano committed
9
10
#include "xicProfile.h"
#include "xicSelectionWidget.h"
Edlira Nano's avatar
Edlira Nano committed
11
12
13
#include "../lib/mcq_error.h"
#include "../lib/msrun/msrun_classic.h"
#include "../lib/msrun/msrun_sliced.h"
Edlira Nano's avatar
Edlira Nano committed
14
15
16
17
#include "../lib/xicExtractionMethods/xicExtractionMethodBase.h"
#include "../lib/quanti_items/quantiItemMzRt.h"
#include "../lib/xic/xic_base.h"

Edlira Nano's avatar
Edlira Nano committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <math.h>

MasschroqGui::MasschroqGui() {

}

MasschroqGui::~MasschroqGui() {

}

void
MasschroqGui::setMsRun(const QString & filename) {
  QFileInfo filenameInfo(filename);
    
  if (! filenameInfo.exists()) {
    throw mcqError(QObject::tr("The chosen MSrun file %1, does not exist").arg(filename));
  } else if (! filenameInfo.isReadable()) {
    throw mcqError(QObject::tr("The chosen MSrun file %1, is not readable").arg(filename));
  }
  
  QString suffix = filenameInfo.suffix();
  mcq_xml_format format;
  if (suffix == "mzXML") {
    format = MZXML;
  } else if (suffix == "mzML") {
    format = MZML;
  } else {
    throw mcqError(QObject::tr("The chosen MSrun file format %1, is not mzXML or mzML format").arg(suffix));
  }
  
  mcq_double size_in_bytes = filenameInfo.size();
  if (size_in_bytes < MAX_SLICE_SIZE ) { 
    try {
      MsrunClassic * msrun = new MsrunClassic(filename);
      cout << "MS run classic '" 
	   << filename.toStdString()
	   << "' : parsing begin" << endl;
      msrun->set_from_xml(filename, format);
Edlira Nano's avatar
Edlira Nano committed
56
      this->addMsRun(filename, msrun);
Edlira Nano's avatar
Edlira Nano committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    } catch (mcqError error) {
      throw mcqError(QObject::tr("problem creating msrun %1:\n%2").arg(filename, error.what()));
    }
  } else { 
    mcq_double nb_of_slices_double = ceil(size_in_bytes/MAX_SLICE_SIZE); 
    int nb_of_slices = static_cast<int> (nb_of_slices_double);
    try {
      MsrunSliced * msrun = new MsrunSliced(filename, nb_of_slices);
      cout << "MS run sliced '"
	   << filename.toStdString()
	   << "', number of slices " << nb_of_slices 
	   <<", : parsing begin" << endl;
      
      msrun->set_from_xml(filename, format);
Edlira Nano's avatar
Edlira Nano committed
71
      this->addMsRun(filename, msrun);
Edlira Nano's avatar
Edlira Nano committed
72
73
74
75
76
77
    } catch (mcqError error) {
      throw mcqError(QObject::tr("problem creating msrun %1:\n%2").arg(filename, error.what()));
    }
  }
}

Edlira Nano's avatar
Edlira Nano committed
78
void
Edlira Nano's avatar
Edlira Nano committed
79
MasschroqGui::addMsRun(const QString & filename, Msrun * msrun) {
Edlira Nano's avatar
Edlira Nano committed
80
81
82
83
  _msrun_map[filename] = msrun; 
}

Msrun * 
Edlira Nano's avatar
Edlira Nano committed
84
MasschroqGui::getMsRun(const QString & filename) const {
Edlira Nano's avatar
Edlira Nano committed
85
86
  std::map<QString, Msrun *>::const_iterator it;
  it = _msrun_map.find(filename);
Edlira Nano's avatar
Edlira Nano committed
87
  if (it == _msrun_map.end()) {
Edlira Nano's avatar
Edlira Nano committed
88
89
90
91
92
93
94
    return (NULL);
  } else {
    return (it->second);
  }
}

XicProfile *
Edlira Nano's avatar
Edlira Nano committed
95
96
97
98
99
100
101
102
103
MasschroqGui::extractXicProfile(const QString & msrun_filename, XicSelectionWidget * xic) {
  qDebug() << "Yo 1" << endl; 
  Msrun * msrun = getMsRun(msrun_filename); 
  if (msrun == NULL) {
    throw mcqError(QObject::tr("The msrun with filename %1, does not exist").arg(msrun_filename));
  }
  qDebug() << "Yo 2" << endl; 
  if (xic == NULL) 
    qDebug() << "Null" << endl; 
Edlira Nano's avatar
Edlira Nano committed
104
  XicExtractionMethodBase * extraction_method = xic->getXicExtractionMethod();
Edlira Nano's avatar
Edlira Nano committed
105
  qDebug() << "Yo 3" << endl; 
Edlira Nano's avatar
Edlira Nano committed
106
107
108
  mcq_xic_type xic_type = xic->getXicType();
  mcq_double mz_value = xic->getMzToExtract();
  mcq_double rt_value = xic->getRtToExtract();
Edlira Nano's avatar
Edlira Nano committed
109
110
111
112
113
114
115
116
117
  qDebug() << "Yo 3" << endl; 
  extraction_method->setMz(mz_value);
  qDebug() << "Yo 4" << endl; 
  QuantiItemBase * quanti_item;
  if (rt_value != 0) {
    quanti_item = new QuantiItemMzRt(*extraction_method, rt_value);
  } else { 
    quanti_item = new QuantiItemBase(*extraction_method);
  }
Edlira Nano's avatar
Edlira Nano committed
118
  // extract XIC
Edlira Nano's avatar
Edlira Nano committed
119
120
121
122
  qDebug() << "Yo 3" << endl; 
  msrun->prepareSpectraForQuantification(extraction_method);
  xicBase * current_xic = msrun->extractXic(xic_type, quanti_item);
    qDebug() << "Yo 4" << endl; 
Edlira Nano's avatar
Edlira Nano committed
123
124
125
  if (current_xic == 0) {
    qDebug() << "MsrunSelectionXic null xic ";
  }
Edlira Nano's avatar
Edlira Nano committed
126
  qDebug() << "Yo 5" << endl; 
Edlira Nano's avatar
Edlira Nano committed
127
128
129
  XicProfile * xic_profile = new XicProfile();
  xic_profile->setRtVector(*(current_xic->getRetentionTimes()));
  xic_profile->setIntensityVector(*(current_xic->getIntensities()));
Edlira Nano's avatar
Edlira Nano committed
130
  qDebug() << "Yo 6" << endl; 
Edlira Nano's avatar
Edlira Nano committed
131
  delete (current_xic);
Edlira Nano's avatar
Edlira Nano committed
132
  msrun->doneWithSpectra();
Edlira Nano's avatar
Edlira Nano committed
133
134
135
136
  
  return xic_profile;

}