Vespucci  1.0.0
matrixanalyzer.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 *******************************************************************************/
21 
22 MatrixAnalyzer::MatrixAnalyzer(QSharedPointer<VespucciWorkspace> ws, const QStringList &data_keys, bool transpose)
23  :MetaAnalyzer(ws), data_keys_(data_keys)
24 {
25  transpose_ = transpose;
26  GetData();
27 }
28 
30 
31 void MatrixAnalyzer::GetData()
32 {
33  if (transpose_){
34  data_ = workspace_->GetMatrix(data_keys_).t();
35  abscissa_ = linspace(0, data_.n_rows - 1, data_.n_rows);
36  }
37  else{
38  data_ = workspace_->GetMatrix(data_keys_);
39  abscissa_ = linspace(0, data_.n_cols - 1, data_.n_cols);
40  }
41 }
42 
43 QString MatrixAnalyzer::FindUniqueName(QString name)
44 {
45  if (data_keys_.size() > 2){
46  QSharedPointer<AnalysisResults> results = workspace_->GetAnalysisResults(data_keys_[0], data_keys_[1]);
47  QMap<QString, uvec> parent_rows = results->parent_rows();
48  QString new_name = name;
49  QStringList results_names;
50  int i = 0;
51  for (auto dataset_key: parent_rows.keys())
52  results_names = results_names + workspace_->GetDataset(dataset_key)->AnalysisResultsKeys();
53  while (results_names.contains(new_name))
54  new_name = name + " (" + QString::number(++i) + ")";
55  return new_name;
56  }
57  else return name; //unique name resolved by VespucciDataset::AddAnalysisResult
58 }
59 
60 void MatrixAnalyzer::AddAnalysisResults(QSharedPointer<AnalysisResults> results, QStringList matrices)
61 {
62  QString first_dataset_key = data_keys_.first();
63  QSharedPointer<VespucciDataset> first_dataset = workspace_->GetDataset(first_dataset_key);
64  if (data_keys_.size() < 3) first_dataset->AddAnalysisResult(results);
65  else{
66  QSharedPointer<AnalysisResults> parent_results = workspace_->GetAnalysisResults(data_keys_[0], data_keys_[1]);
67  QMap<QString, uvec> parent_rows = parent_results->parent_rows();
68  if (parent_rows.size() < 2){
69  first_dataset->AddAnalysisResult(results);
70  return;
71  }
72  else{
73  for (auto key: parent_rows.keys()){
74  QSharedPointer<VespucciDataset> current_dataset = workspace_->GetDataset(key);
75  current_dataset->AddAnalysisResult(results);
76  if (!matrices.isEmpty())
77  current_dataset->AddAnalysisResult(results->Subset(matrices, parent_rows[key](0), parent_rows[key](1)));
78  }
79  }
80  }
81 }
QSharedPointer< VespucciWorkspace > workspace_
workspace_ The global workspace, used to obtain access to matrices
Definition: metaanalyzer.h:100
MatrixAnalyzer(QSharedPointer< VespucciWorkspace > ws, const QStringList &data_keys, bool transpose)
The MetaAnalyzer class This class is used to perform analysis on "pseudo-datasets". This allows us perform analysis on a concatentated spectra matrix from multiple datasets (the MultiAnalyzer derived class) or on a single matrix in a single dataset (the MatrixAnalyzer derived class). This class is not concerned with how the data_ and abscissa_ members are initialized (this is handled by GetData in derived classes).
Definition: metaanalyzer.h:33