/** * \file /gui/tandem_run_dialog/tandem_run_dialog.cpp * \date 31/8/2017 * \author Olivier Langella * \brief dialog window to launch tandem process */ /******************************************************************************* * 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 "tandemrundialog.h" #include "ui_tandem_run_dialog.h" #include <QDebug> #include <QSettings> #include <QFileDialog> #include <QMessageBox> #include <pappsomspp/pappsoexception.h> #include "../../files/tandemparametersfile.h" //Q_DECLARE_METATYPE(QFileInfo) TandemRunDialog::TandemRunDialog(QWidget * parent): QDialog(parent), ui(new Ui::TandemRunDialog) { qDebug() << "TandemRunDialog::TandemRunDialog begin"; ui->setupUi(this); this->setModal(true); _p_fasta_file_list = new QStringListModel(); _p_mz_file_list = new QStringListModel(); ui->fasta_file_listview->setModel(_p_fasta_file_list); ui->mz_file_listview->setModel(_p_mz_file_list); #if QT_VERSION >= 0x050000 // Qt5 code #else // Qt4 code #endif reset(); fillPresetComboBox(); qDebug() << "TandemRunDialog::TandemRunDialog end"; } TandemRunDialog::~TandemRunDialog() { delete ui; delete _p_fasta_file_list; delete _p_mz_file_list; } void TandemRunDialog::setPresetName(QString preset_name) { QSettings settings; settings.setValue("tandem/preset_name", preset_name); //get presets : TandemParametersFile param_file(ui->preset_combobox->itemData(ui->preset_combobox->currentIndex()).value<QString>()); ui->thread_spin_box->setValue(param_file.getTandemParameters().getValue("spectrum, threads").toInt()); } void TandemRunDialog::fillPresetComboBox() { ui->preset_combobox->clear(); QSettings settings; QString default_preset_location = settings.value("path/tandemrun_preset_directory", "").toString(); QString default_preset_name = settings.value("tandem/preset_name", "").toString(); QDir preset_dir(default_preset_location); QStringList filters; filters << "*.xml"; preset_dir.setNameFilters(filters); for (QFileInfo file_info: preset_dir.entryInfoList() ) { ui->preset_combobox->addItem(file_info.baseName(), QVariant(file_info.absoluteFilePath())); } int index = ui->preset_combobox->findText(default_preset_name); if ( index != -1 ) { // -1 for not found ui->preset_combobox->setCurrentIndex(index); } } void TandemRunDialog::reset() { QSettings settings; QString default_output_location = settings.value("path/identificationfiles", "").toString(); QString tandem_bin_path = settings.value("path/tandem_bin", "/usr/bin/tandem").toString(); ui->output_directory_label->setText(default_output_location); ui->tandem_bin_label->setText(tandem_bin_path); _p_fasta_file_list->stringList().clear(); _p_mz_file_list->stringList().clear(); /* if (filenames.size() > 0) { settings.setValue("path/identificationfiles", QFileInfo(filenames[0]).absolutePath()); }*/ } void TandemRunDialog::selectPresetDirectory() { try { QSettings settings; QString default_preset_location = settings.value("path/tandemrun_preset_directory", "").toString(); QString directory = QFileDialog::getExistingDirectory(this,tr("Choose preset directory"),default_preset_location ); if (!directory.isEmpty()) { settings.setValue("path/tandemrun_preset_directory", directory); fillPresetComboBox(); } } catch (pappso::PappsoException & error) { //QMessageBox::warning(this, // tr("Error choosing identification result files : %1").arg(error.qwhat()), error); } } void TandemRunDialog::selectOutputDirectory() { try { QSettings settings; QString default_output_location = settings.value("path/identificationfiles", "").toString(); QString directory = QFileDialog::getExistingDirectory(this,tr("Choose output directory"),default_output_location ); if (!directory.isEmpty()) { settings.setValue("path/identificationfiles", directory); ui->output_directory_label->setText(directory); } } catch (pappso::PappsoException & error) { //QMessageBox::warning(this, // tr("Error choosing identification result files : %1").arg(error.qwhat()), error); } } void TandemRunDialog::selectFastaFiles() { try { QSettings settings; QString default_fasta_location = settings.value("path/tandemrun_fastafiles_directory", "").toString(); QStringList filenames = QFileDialog::getOpenFileNames(this,tr("FASTA files"),default_fasta_location, tr("FASTA files (*.fasta);;all files (*)") ); if (filenames.size() > 0) { settings.setValue("path/tandemrun_fastafiles_directory", QFileInfo(filenames[0]).absolutePath()); } QStringList file_list = _p_fasta_file_list->stringList(); file_list.append(filenames); _p_fasta_file_list->setStringList(file_list); } catch (pappso::PappsoException & error) { //QMessageBox::warning(this, // tr("Error choosing identification result files : %1").arg(error.qwhat()), error); } } void TandemRunDialog::selectMzFiles() { try { QSettings settings; QString default_mz_location = settings.value("path/tandemrun_mzfiles_directory", "").toString(); QStringList filenames = QFileDialog::getOpenFileNames(this,tr("select peak list files"),default_mz_location, tr("mz files (*.mzXML *.mzML *.mgf);;all files (*)") ); if (filenames.size() > 0) { settings.setValue("path/tandemrun_mzfiles_directory", QFileInfo(filenames[0]).absolutePath()); } QStringList file_list = _p_mz_file_list->stringList(); file_list.append(filenames); _p_mz_file_list->setStringList(file_list); } catch (pappso::PappsoException & error) { //QMessageBox::warning(this, // tr("Error choosing identification result files : %1").arg(error.qwhat()), error); } } TandemRunBatch TandemRunDialog::getTandemRunBatch() const { TandemRunBatch tandem_run_batch; tandem_run_batch._tandem_bin_path = ui->tandem_bin_label->text(); tandem_run_batch._mz_file_list = _p_mz_file_list->stringList(); tandem_run_batch._fasta_file_list = _p_fasta_file_list->stringList(); //tandem_run_batch._preset_file = ui->preset_combobox->itemData(ui->preset_combobox->currentIndex()).value<QFileInfo>().absoluteFilePath(); tandem_run_batch._preset_file = ui->preset_combobox->itemData(ui->preset_combobox->currentIndex()).value<QString>(); tandem_run_batch._output_directory = ui->output_directory_label->text(); tandem_run_batch._number_of_threads = ui->thread_spin_box->value(); return tandem_run_batch; }