masschroq_gui.cpp 3.68 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
    return (NULL);
  } else {
    return (it->second);
  }
}

Edlira Nano's avatar
Edlira Nano committed
94
95
96
97
98
void
MasschroqGui::extractXicProfile(XicProfile * xic_profile, 
				const QString & msrun_filename, 
				XicSelectionWidget * xic) {

Edlira Nano's avatar
Edlira Nano committed
99
  Msrun * msrun = getMsRun(msrun_filename); 
Edlira Nano's avatar
Edlira Nano committed
100

Edlira Nano's avatar
Edlira Nano committed
101
102
103
  if (msrun == NULL) {
    throw mcqError(QObject::tr("The msrun with filename %1, does not exist").arg(msrun_filename));
  }
Edlira Nano's avatar
Edlira Nano committed
104
  
Edlira Nano's avatar
Edlira Nano committed
105
106
107
108
  XicExtractionMethodBase * extraction_method = xic->getXicExtractionMethod();
  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
  extraction_method->setMz(mz_value);
  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
116

Edlira Nano's avatar
Edlira Nano committed
117
  // extract XIC
Edlira Nano's avatar
Edlira Nano committed
118
119
  msrun->prepareSpectraForQuantification(extraction_method);
  xicBase * current_xic = msrun->extractXic(xic_type, quanti_item);
Edlira Nano's avatar
Edlira Nano committed
120
121
122
123
  if (current_xic == 0) {
    qDebug() << "MsrunSelectionXic null xic ";
  }
  
Edlira Nano's avatar
Edlira Nano committed
124
125
126
127
128
  xic_profile->setOriginalXic( *(current_xic->getRetentionTimes()), 
			       *(current_xic->getIntensities()) );
  
  delete (current_xic);
  msrun->doneWithSpectra();  
Edlira Nano's avatar
Edlira Nano committed
129
}