Vespucci  1.0.0
transformdialog.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (C) 2014-2016 Wright State University - All Rights Reserved
3  Daniel P. Foose - Maintainer/Lead Developer
4 
5  This file is part of Vespucci.
6 
7  Vespucci is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  Vespucci is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Vespucci. If not, see <http://www.gnu.org/licenses/>.
19 *******************************************************************************/
20 #include "transformdialog.h"
21 #include "ui_transformdialog.h"
24 
25 TransformDialog::TransformDialog(QWidget *parent, QSharedPointer<VespucciWorkspace> ws, const QStringList keys) :
26  QDialog(parent),
27  ui(new Ui::TransformDialog)
28 {
29  ui->setupUi(this);
30  workspace_ = ws;
31  data_keys_ = keys;
32  ui->constantLineEdit->setValidator(new QDoubleValidator(-DBL_MAX, DBL_MAX, 5));
33  matrix_selection_dialog_ = new MatrixSelectionDialog(this, workspace_->dataset_tree_model());
34  connect(matrix_selection_dialog_, &MatrixSelectionDialog::MatrixSelected,
36 }
37 
39 {
40  delete ui;
41  delete matrix_selection_dialog_;
42 }
43 
44 void TransformDialog::MatrixSelected(QStringList keys)
45 {
46  operand_keys_ = keys;
47  ui->matrixNameLabel->setText(keys.last());
48  raise();
49 }
50 
51 void TransformDialog::on_selectPushButton_clicked()
52 {
53  matrix_selection_dialog_->show();
54 }
55 
56 void TransformDialog::on_buttonBox_accepted()
57 {
58  QString operation = ui->operationComboBox->currentText();
59  bool ok;
60  double constant = ui->constantLineEdit->text().toDouble(&ok);
61  if (!ok) constant = 0;
62  mat matrix = workspace_->GetMatrix(data_keys_);
63  mat operand = workspace_->GetMatrix(operand_keys_);
64  mat new_matrix;
65  QString name = ui->nameLineEdit->text();
66  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(data_keys_.first());
67 
68  try{
69  if (operation == "Constant addition")
70  new_matrix = matrix + constant * ones(matrix.n_rows, matrix.n_cols);
71  else if (operation == "Constant subtraction")
72  new_matrix = matrix + -1*constant*ones(matrix.n_rows, matrix.n_cols);
73  else if (operation == "Constant division")
74  new_matrix = (1.0/constant) * matrix;
75  else if (operation == "Constant multiplication")
76  new_matrix = constant * matrix;
77  else if (operation == "Matrix addition")
78  new_matrix = matrix + operand;
79  else if (operation == "Matrix subtraction")
80  new_matrix = matrix - operand;
81  else if (operation == "Matrix multiplication (dot product)")
82  new_matrix = matrix * operand;
83  else if (operation == "Element-wise multiplication")
84  new_matrix = matrix % operand;
85  else if (operation == "Element-wise division")
86  new_matrix = matrix / operand;
87  else if (operation == "Minimum subtraction")
88  new_matrix = matrix - matrix.min() * ones(matrix.n_rows, matrix.n_cols);
89  else if (operation == "Maximum division")
90  new_matrix = (1.0/matrix.max()) * matrix;
91  else if (operation == "Min/Max normalization"){
92  new_matrix = matrix;
93  for (uword i = 0; i < new_matrix.n_cols; ++i){
94  vec column = new_matrix.col(i);
95  column = column - column.min() * ones(column.n_rows);
96  column = column / column.max();
97  new_matrix.col(i) = column;
98  }
99  }
100  else if (operation == "SNV normalization")
101  new_matrix = Vespucci::Math::Normalization::SNVNorm(matrix, 0, true);
102  else if (operation == "Z-Score normalization")
104  else if (operation == "Normalize to 1-norm")
105  new_matrix = normalise(matrix, 1);
106  else if (operation == "Normalize to 2-norm")
107  new_matrix = normalise(matrix, 2);
108  else if (operation == "Calibration")
109  ;//do nothing for now
110  else
111  return;
112  }catch(...){
113  QMessageBox::warning(this, "Cannot perform operation", "The operation could not be performed");
114  close();
115  return;
116  }
117  dataset->AddAuxiliaryMatrix(name, new_matrix);
118  close();
119 }
VESPUCCI_EXPORT arma::mat StandardScoreMat(const arma::mat &X)
Vespucci::Math::Normalization::StandardScore.
TransformDialog(QWidget *parent, QSharedPointer< VespucciWorkspace > ws, const QStringList keys)
Definition: ahcadialog.h:26
void MatrixSelected(QStringList keys)
VESPUCCI_EXPORT arma::mat SNVNorm(const arma::mat &X, const double offset, bool center)
Vespucci::Math::Normalization::SNVNorm.
void MatrixSelected(QStringList keys)