Skip to content

Commit

Permalink
[ref] Made changes after review 3
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshikukreja14 committed Dec 22, 2020
1 parent be0b0b4 commit 8a7fa58
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ script:
# export encoded update repository URL
export UPDATE_REPO_URL_BASE64=`echo $UPDATE_REPO_URL | base64`
qmake CONFIG+=release CONFIG+=force_debug_info CONFIG+=separate_debug_info NOTESTS=yes
make -j4;
fi
Expand Down
21 changes: 0 additions & 21 deletions src/core/libmaven/PeakGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,18 +1071,7 @@ void PeakGroup::setUserLabel(char label)
// ignore invalid labels
return;
}
_predictionProbability = 0.0f;
_predictionInference.clear();
_userLabel = label;

if (parent != nullptr && parent->tagString == C12_PARENT_LABEL) {
parent->setUserLabel(label);
return;
}

for (auto& child : _childIsotopes) {
child->setUserLabel(label);
}
}

void PeakGroup::setPredictedLabel(const ClassifiedLabel label,
Expand All @@ -1099,16 +1088,6 @@ void PeakGroup::setPredictedLabel(const ClassifiedLabel label,
this->_userLabel = 'g';
}
_predictionProbability = probability;

if (parent != nullptr && parent->tagString == C12_PARENT_LABEL) {
parent->setPredictedLabel(label, probability);
return;
}
for (auto& child : _childIsotopes) {
if (child->_predictedLabel != label
&& child->_predictionProbability != probability)
child->setPredictedLabel(label, probability);
}
}

void PeakGroup::setPredictionInference(const multimap<float, string>& inference)
Expand Down
1 change: 1 addition & 0 deletions src/core/libmaven/mavenparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ void MavenParameters::copyFrom(const MavenParameters& mp)
// which will not be created by a copy operation like this.
samples = mp.samples;

classifyUsingPeakMl = mp.classifyUsingPeakMl;
peakMlModelType = mp.peakMlModelType;
badGroupUpperLimit = mp.badGroupUpperLimit;
goodGroupLowerLimit = mp.goodGroupLowerLimit;
Expand Down
75 changes: 39 additions & 36 deletions src/gui/mzroll/backgroundopsthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,6 @@ void BackgroundOpsThread::qtSignalSlot(const string& progressText,
total_slices);
}

void BackgroundOpsThread::writeCSVRep(string setName)
{
// int lastUniqueId = 0;
// for (auto&group : mavenParameters->allgroups)
// group.setUniqueId(++lastUniqueId);

// for(auto&group : mavenParameters->allgroups)
// for (auto& child : group.childIsotopes())
// child->setUniqueId(++lastUniqueId);

if (mainwindow->mavenParameters->classifyUsingPeakMl)
classifyGroups(mavenParameters->allgroups);

emitGroups();

Q_EMIT(updateProgressBar("Done", 1, 1));
}

void BackgroundOpsThread::align()
{
// these if-else statements will take care of all corner cases of
Expand Down Expand Up @@ -298,7 +280,12 @@ void BackgroundOpsThread::computePeaks()
peakDetector->mavenParameters()->searchAdducts = hadSearchAdducts;
}

writeCSVRep("slices");
if (mainwindow->mavenParameters->classifyUsingPeakMl)
classifyGroups(mavenParameters->allgroups);

emitGroups();

Q_EMIT(updateProgressBar("Done", 1, 1));

emit updateProgressBar("Status", 0, 100);
}
Expand All @@ -322,7 +309,12 @@ void BackgroundOpsThread::findFeatures()
peakDetector->mavenParameters()->searchAdducts = hadSearchAdducts;
}

writeCSVRep("allSlices");
if (mainwindow->mavenParameters->classifyUsingPeakMl)
classifyGroups(mavenParameters->allgroups);

emitGroups();

Q_EMIT(updateProgressBar("Done", 1, 1));

emit updateProgressBar("Status", 0, 100);
}
Expand Down Expand Up @@ -405,11 +397,11 @@ void BackgroundOpsThread::classifyGroups(vector<PeakGroup>& groups)
#ifdef Q_OS_WIN
auto mlBinary = tempDir + QDir::separator() + "moi.exe";
#endif
QString mlModel;
QString ml_model;
// Following code is commented out because for now we have only one model in
// aws bucket. Once, we have more comments would be removed.
// if(mainwindow->mavenParameters->peakMlModelType == "Global Model Elucidata"){
mlModel = tempDir + QDir::separator() + "model.pickle.dat";
// if(mainwindow->mavenParameters->peakml_modelType == "Global Model Elucidata"){
ml_model = tempDir + QDir::separator() + "model.pickle.dat";
// }
// else{
// return;
Expand All @@ -424,30 +416,41 @@ void BackgroundOpsThread::classifyGroups(vector<PeakGroup>& groups)
return;
}
}
if (!QFile::exists(mlModel)) {
if (!QFile::exists(ml_model)) {
bool downloadSuccess = downloadPeakMlFilesFromURL("model.pickle.dat");
if(!downloadSuccess) {
cerr << "Error: ML model not found at path: "
<< mlModel.toStdString()
<< ml_model.toStdString()
<< endl;
return;
}
}

Q_EMIT(updateProgressBar("Preparing inputs for classification…", 0, 0));

QString peakAttributesFile = tempDir
QString peak_attributes_file = tempDir
+ QDir::separator()
+ "peak_ml_input.csv";
QString classificationOutputFile = tempDir
QString classification_output_file = tempDir
+ QDir::separator()
+ "peak_ml_output.csv";

CSVReports::writeDataForPeakMl(peakAttributesFile.toStdString(),
int startId = 1;
for (auto& group : groups) {
group.setGroupId(startId++);
for (auto& child : group.childIsotopes()) {
child->setGroupId(startId++);
}
for (auto& child : group.childAdducts()) {
child->setGroupId(startId++);
}
}

CSVReports::writeDataForPeakMl(peak_attributes_file.toStdString(),
groups);
if (!QFile::exists(peakAttributesFile)) {
if (!QFile::exists(peak_attributes_file)) {
cerr << "Error: peak attributes input file not found at path: "
<< peakAttributesFile.toStdString()
<< peak_attributes_file.toStdString()
<< endl;
return;
}
Expand All @@ -456,25 +459,25 @@ void BackgroundOpsThread::classifyGroups(vector<PeakGroup>& groups)
QString maybeGood_group_limit = QString::fromStdString(
mzUtils::float2string(mavenParameters->goodGroupLowerLimit, 1));
QStringList mlArguments;
mlArguments << "--input_attributes_file" << peakAttributesFile
<< "--output_moi_file" << classificationOutputFile
<< "--model_path" << mlModel
mlArguments << "--input_attributes_file" << peak_attributes_file
<< "--output_moi_file" << classification_output_file
<< "--model_path" << ml_model
<< "--bad_group_limit" << bad_group_limit
<< "--maybeGood_group_limit" << maybeGood_group_limit;
QProcess subProcess;
subProcess.setWorkingDirectory(QFileInfo(mlBinary).path());
subProcess.start(mlBinary, mlArguments);
subProcess.waitForFinished(-1);
if (!QFile::exists(classificationOutputFile)) {
if (!QFile::exists(classification_output_file)) {
qDebug() << "MOI stdout:" << subProcess.readAllStandardOutput();
qDebug() << "MOI stderr:" << subProcess.readAllStandardError();
cerr << "Error: peak classification output file not found at path: "
<< peakAttributesFile.toStdString()
<< peak_attributes_file.toStdString()
<< endl;
return;
}

QFile file(classificationOutputFile);
QFile file(classification_output_file);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
cerr << "Error: failed to open classification output file" << endl;
return;
Expand Down
6 changes: 0 additions & 6 deletions src/gui/mzroll/backgroundopsthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,6 @@ class BackgroundOpsThread : public QThread
// perform PolyFit alignment just after peak detection (if true)
bool _performPolyFitAlignment;

/**
* [write CSV Report]
* @param setName [name of the set]
*/
void writeCSVRep(string setName);

/**
* @brief Downloads binary and model from S3 bucket
* if the two files does not exist on user's pc.
Expand Down
11 changes: 9 additions & 2 deletions src/gui/mzroll/loginform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "mainwindow.h"
#include "pollyelmaveninterface.h"
#include "pollyintegration.h"
#include "peakdetectiondialog.h"
#include "ui_loginform.h"


Expand Down Expand Up @@ -45,8 +46,14 @@ LoginForm::LoginForm(PollyElmavenInterfaceDialog* pollyelmaveninterfacedialog, b
ui->login_label->clear();
ui->pushButton->setEnabled(true);
});
connect(this, SIGNAL(loginSuccessful()), _pollyelmaveninterfacedialog, SLOT(emitLoginReady()));
connect(this, SIGNAL(widgetClosed()), _pollyelmaveninterfacedialog, SLOT(loginFormClosed()));
connect(this,
&LoginForm::loginSuccessful,
_pollyelmaveninterfacedialog->getMainWindow()->peakDetectionDialog,
&PeakDetectionDialog::loginSuccessful);
connect(this,
&LoginForm::widgetClosed,
_pollyelmaveninterfacedialog->getMainWindow()->peakDetectionDialog,
&PeakDetectionDialog::unsuccessfulLogin);
}

LoginForm::~LoginForm()
Expand Down
23 changes: 5 additions & 18 deletions src/gui/mzroll/pollyelmaveninterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ PollyElmavenInterfaceDialog::PollyElmavenInterfaceDialog(MainWindow* mw)
qRegisterMetaType<PollyApp>("PollyApp");
qRegisterMetaType<QMap<PollyApp, bool>>();

showPollyApps = true;

auto configLocation = QStandardPaths::QStandardPaths::GenericConfigLocation;
_writeableTempDir = QStandardPaths::writableLocation(configLocation)
+ QDir::separator()
Expand Down Expand Up @@ -198,8 +196,6 @@ PollyElmavenInterfaceDialog::PollyElmavenInterfaceDialog(MainWindow* mw)
&QTabWidget::currentChanged,
this,
&PollyElmavenInterfaceDialog::_changeMode);
connect(this, SIGNAL(loginResponse()), _mainwindow->peakDetectionDialog, SLOT(loginSuccessful()));
connect(this, SIGNAL(loginUnsuccessful()), _mainwindow->peakDetectionDialog, SLOT(unsuccessfulLogin()));
}
PollyElmavenInterfaceDialog::~PollyElmavenInterfaceDialog()
{
Expand Down Expand Up @@ -435,15 +431,6 @@ void PollyElmavenInterfaceDialog::loginForPeakMl()
}
}

void PollyElmavenInterfaceDialog::emitLoginReady()
{
emit loginResponse();
}
void PollyElmavenInterfaceDialog::loginFormClosed()
{
emit loginUnsuccessful();
}

void PollyElmavenInterfaceDialog::initialSetup()
{
int nodeStatus = _pollyIntegration->checkNodeExecutable();
Expand All @@ -457,7 +444,7 @@ void PollyElmavenInterfaceDialog::initialSetup()
int askForLogin = _pollyIntegration->askForLogin();
if (askForLogin == 1) {
try {
_callLoginForm(showPollyApps);
_callLoginForm();
} catch (...) {
QMessageBox msgBox(this);
msgBox.setWindowModality(Qt::NonModal);
Expand Down Expand Up @@ -489,9 +476,9 @@ void PollyElmavenInterfaceDialog::showEPIError(QString errorMessage)
QCoreApplication::processEvents();
}

void PollyElmavenInterfaceDialog::_callLoginForm(bool showPollyApp)
void PollyElmavenInterfaceDialog::_callLoginForm(bool showPollyApps)
{
_loginform = new LoginForm(this, showPollyApp);
_loginform = new LoginForm(this, showPollyApps);
_loginform->setModal(true);
_loginform->show();
}
Expand Down Expand Up @@ -787,7 +774,7 @@ void PollyElmavenInterfaceDialog::_uploadDataToPolly()
// redirect to login form if user credentials have not been saved
int askForLogin = _pollyIntegration->askForLogin();
if (askForLogin == 1) {
_callLoginForm(showPollyApps);
_callLoginForm();
emit uploadFinished(false);
return;
}
Expand Down Expand Up @@ -1113,9 +1100,9 @@ QStringList PollyElmavenInterfaceDialog::_prepareFilesToUpload(QDir qdir,
+ QDir::separator()
+ datetimestamp
+ "_Peaks_information_json_Elmaven_Polly.json";
peakTable->exportJsonToPolly(_writeableTempDir, jsonFilename, true);

if (_selectedApp == PollyApp::PollyPhi) {
peakTable->exportJsonToPolly(_writeableTempDir, jsonFilename, true);
QCoreApplication::processEvents();
//Preparing the sample cohort file
QString sampleCohortFileName = _writeableTempDir + QDir::separator() + datetimestamp +
Expand Down
7 changes: 1 addition & 6 deletions src/gui/mzroll/pollyelmaveninterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,6 @@ public Q_SLOTS:

void showEPIError(QString errorMessage);

void emitLoginReady();

void loginFormClosed();


Q_SIGNALS:

/**
Expand Down Expand Up @@ -318,7 +313,7 @@ public Q_SLOTS:
/**
* @brief This function calls login form UI to take credentials from user.
*/
void _callLoginForm(bool showPollyApps);
void _callLoginForm(bool showPollyApps = true);

/**
* @brief This function calls initial login UI to connect to Polly and fetch
Expand Down
1 change: 0 additions & 1 deletion src/gui/mzroll/rangeSlider.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#ifndef RANGESLIDER_H
#define RANGESLIDER_H
#pragma once

#include <QWidget>
#include <QPainter>
Expand Down
Loading

0 comments on commit 8a7fa58

Please sign in to comment.