Newer
Older
/**
* \filed core/msrun.cpp
* \date 5/4/2017
* \author Olivier Langella
* \brief describes an MS run (chemical sample injected in a mass spectrometer)
*/
/*******************************************************************************
* Copyright (c) 2017 Olivier Langella <Olivier.Langella@u-psud.fr>.
*
* This file is part of XTPcpp.
*
* XTPcpp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* XTPcpp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XTPcpp. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and implementation
******************************************************************************/
#include "msrun.h"
#include <QFileInfo>
#include <QSettings>
#include <QDebug>
#include <QDir>
#include <pappsomspp/msrun/msrunreaderfactory.h>
#include <pappsomspp/exception/exceptionnotfound.h>
MsRun::MsRun(const QString & location):pappso::MsRunId(location) {
QFileInfo fileinfo(location);
}
MsRun::MsRun(const MsRun& other):pappso::MsRunId(other) {
_param_stats = other._param_stats;
}
MsRun::~MsRun() {
}
pappso::MsRunReaderSp & MsRun::getMsRunReaderSp() {
return _msrun_reader_sp;
}
void MsRun::setMsRunStatistics(MsRunStatistics param, const QVariant& value) {
_param_stats.insert(std::pair<MsRunStatistics, QVariant>(param, value));
}
const std::map<MsRunStatistics, QVariant> & MsRun::getMsRunStatisticsMap() const {
return _param_stats;
}
const QVariant MsRun::getMsRunStatistics(MsRunStatistics param) const {
try {
return _param_stats.at(param);
}
catch (std::out_of_range) {
return QVariant();
}
}
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
bool MsRun::findMsRunFile() {
QFileInfo file(this->getFilename());
bool file_ok = false;
if (file.exists()) {
file_ok = true;
}
QString basename = file.baseName();
QString onlyfilename = file.fileName();
QSettings settings;
QString path = settings.value("path/mzdatadir", "").toString();
QDir dir_search(path);
QFileInfoList files = dir_search.entryInfoList();
foreach (QFileInfo file, files) {
if (file.isDir()) {
qDebug() << "DIR: " << file.fileName();
} else {
qDebug() << "FILE: " << file.fileName();
if (onlyfilename == file.fileName()) {
this->setFilename(file.absoluteFilePath());
file_ok = true;
}
if (file.fileName().contains(onlyfilename)) {
this->setFilename(file.absoluteFilePath());
file_ok = true;
}
}
}
if (file_ok) {
if (_msrun_reader_sp == nullptr) {
_msrun_reader_sp = pappso::MsRunReaderFactory::getInstance().buildPwizMsRunReaderSp(*this);
}
}
return file_ok;
}
void MsRun::checkMsRunStatistics() {
QVariant msrun_var = getMsRunStatistics(MsRunStatistics::total_spectra);
if (msrun_var.isNull()) {
try {
pappso::MsRunSimpleStatistics stats;
_msrun_reader_sp.get()->readSpectrumCollection(stats);
setMsRunStatistics(MsRunStatistics::total_spectra, (unsigned int) stats.getTotalCount());
setMsRunStatistics(MsRunStatistics::total_spectra_ms1, (unsigned int) stats.getMsLevelCount(1));
setMsRunStatistics(MsRunStatistics::total_spectra_ms2, (unsigned int) stats.getMsLevelCount(2));
setMsRunStatistics(MsRunStatistics::total_spectra_ms3, (unsigned int) stats.getMsLevelCount(3));
}
catch (pappso::ExceptionNotFound& error) {
//no file found, no statistics
}
}
}