From f6d27ed0310cc31c65e9edd836b69d5b469fb109 Mon Sep 17 00:00:00 2001 From: Saeed Date: Sun, 15 Dec 2024 15:33:52 -0700 Subject: [PATCH 1/7] us_legacy_converter: update regex expression --- .../us_legacy_converter.cpp | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/programs/us_legacy_converter/us_legacy_converter.cpp b/programs/us_legacy_converter/us_legacy_converter.cpp index 4d72eb056..c7c83b101 100644 --- a/programs/us_legacy_converter/us_legacy_converter.cpp +++ b/programs/us_legacy_converter/us_legacy_converter.cpp @@ -261,12 +261,14 @@ void US_LegacyConverter::reload() { if (filelist.size() == 0) { QMessageBox::warning(this, "Warning!", tr("File is empty!\n(%1)").arg(tar_finfo.absoluteFilePath())); tar_fpath.clear(); + te_info->clear(); qApp->restoreOverrideCursor(); return; } if (! sort_files( filelist, tmp_dir_sorted.path() ) ) { QMessageBox::warning(this, "Warning!", tr("Incorrect filename pattern!\n\n(%1)").arg(tar_finfo.absoluteFilePath())); tar_fpath.clear(); + te_info->clear(); qApp->restoreOverrideCursor(); return; } @@ -314,11 +316,17 @@ bool US_LegacyConverter::sort_files(const QStringList& flist, const QString& tmp QRegularExpressionMatch match; // RunId1991-s0001-c2-s0009-w260-r_-n1.ri2 // RunId1991-s0002-c1-s0001-n1.ip1 - QString pattern = "^(.+)-s(\\d{4,6})-c(\\d)-s(\\d{4,6})-(?:w(\\d{3})-)?(.+?)[.](?:RA|RI|IP|FI|WA|WI)\\d$"; + // QString pattern = "^(.+)-s(\\d{4,6})-c(\\d)-s(\\d{4,6})-(?:w(\\d{3})-)?(.+?)[.](?:RA|RI|IP|FI|WA|WI)\\d$"; + //group1 (.+) = runID + //group2 -s(\\d{4,6}) = ? maybe sample + //group3 -c(\\d) = cell number + //group4 -s(\\d{4,6}) = scan number + //group5 (?:-w(\\d{3})-r_)? = wavelength (optional: some files include it) + //group6 (ra|ri|ip|fi|wa|wi)\\d = run type + QString pattern = "^(.+)-s(\\d{4,6})-c(\\d)-s(\\d{4,6})(?:-w(\\d{3})-r_)?-n\\d[.](ra|ri|ip|fi|wa|wi)\\d$"; re.setPattern(pattern); QString runid; - QString runtype; QMap file_map; QMap> tcws_map; @@ -326,9 +334,9 @@ bool US_LegacyConverter::sort_files(const QStringList& flist, const QString& tmp QFileInfo finfo = QFileInfo(fpath); QFile file(fpath); QString fname = finfo.fileName(); - match = re.match(fname); + match = re.match(fname.toLower()); if (match.hasMatch()) { - if (runid.size() == 0) { + if (runid.isEmpty()) { runid = match.captured(1); } else { if (QString::compare(runid, match.captured(1)) != 0) { @@ -336,10 +344,13 @@ bool US_LegacyConverter::sort_files(const QStringList& flist, const QString& tmp return false; } } - runtype = fname.right(3).left(2).toUpper(); QString cell = match.captured(3); int scan = match.captured(4).toInt(); QString wavl = match.captured(5); + if (wavl.isEmpty()) { + wavl = "000"; + } + QString runtype = match.captured(6); QString tcw = runtype + "-" + cell + "-" + wavl; if (tcws_map.contains(tcw)) { tcws_map[tcw] << scan; @@ -349,7 +360,7 @@ bool US_LegacyConverter::sort_files(const QStringList& flist, const QString& tmp } QString tcws = tcw + "-" + QString::number(scan); if (file_map.contains(tcws)) { - QMessageBox::warning(this, "Error!", "Some of scans are redundant!"); + QMessageBox::warning(this, "Error!", tr("Redundancy in scans!\%1").arg(fname)); return false; } else { file_map.insert(tcws, fpath); From 6d5e4dc7d8fcdc063818fd612ba7a317f321d427 Mon Sep 17 00:00:00 2001 From: Saeed Date: Mon, 16 Dec 2024 10:17:16 -0700 Subject: [PATCH 2/7] us_legacy_converter: removed run type combo, tolerance counter, and reload button --- .../us_legacy_converter.cpp | 54 ++++++------------- .../us_legacy_converter/us_legacy_converter.h | 3 -- 2 files changed, 17 insertions(+), 40 deletions(-) diff --git a/programs/us_legacy_converter/us_legacy_converter.cpp b/programs/us_legacy_converter/us_legacy_converter.cpp index c7c83b101..ed0458010 100644 --- a/programs/us_legacy_converter/us_legacy_converter.cpp +++ b/programs/us_legacy_converter/us_legacy_converter.cpp @@ -48,25 +48,11 @@ US_LegacyConverter::US_LegacyConverter() : US_Widgets() lb_runid->setAlignment(Qt::AlignRight); le_runid = new US_LineEdit_RE("", 0); - QLabel *lb_runtype = us_label("Run Type:"); - lb_runtype->setAlignment(Qt::AlignRight); - cb_runtype = us_comboBox(); pb_save = us_pushbutton("Save", true, 0); - QLabel* lb_tolerance = us_label("Separation Tolerance:"); - lb_tolerance->hide(); - lb_tolerance->setAlignment(Qt::AlignRight); - ct_tolerance = us_counter ( 2, 0.0, 100.0, 5.0 ); - ct_tolerance->setSingleStep( 1 ); - ct_tolerance->hide(); - pb_reload = us_pushbutton("Reload"); - pb_reload->hide(); - te_info = us_textedit(); te_info->setReadOnly(true); - pb_save->setMinimumWidth(lb_tolerance->sizeHint().width()); - QGridLayout *layout = new QGridLayout(); layout->addWidget(pb_load, 0, 0, 1, 1); layout->addWidget(le_load, 0, 1, 1, 2); @@ -74,12 +60,7 @@ US_LegacyConverter::US_LegacyConverter() : US_Widgets() layout->addWidget(le_dir, 1, 1, 1, 2); layout->addWidget(lb_runid, 2, 0, 1, 1); layout->addWidget(le_runid, 2, 1, 1, 2); - layout->addWidget(lb_runtype, 3, 0, 1, 1); - layout->addWidget(cb_runtype, 3, 1, 1, 1); - layout->addWidget(pb_save, 3, 2, 1, 1); - layout->addWidget(lb_tolerance, 4, 0, 1, 1); - layout->addWidget(ct_tolerance, 4, 1, 1, 1); - layout->addWidget(pb_reload, 4, 2, 1, 1); + layout->addWidget(pb_save, 3, 1, 1, 1); layout->addWidget(te_info, 5, 0, 4, 3); layout->setMargin(2); layout->setSpacing(2); @@ -89,11 +70,9 @@ US_LegacyConverter::US_LegacyConverter() : US_Widgets() counter = 0; connect(pb_load, &QPushButton::clicked, this, &US_LegacyConverter::load); - connect(pb_reload, &QPushButton::clicked, this, &US_LegacyConverter::reload); connect(le_runid, &US_LineEdit_RE::textUpdated, this, &US_LegacyConverter::runid_updated); connect(le_dir, &QLineEdit::textChanged, this, &US_LegacyConverter::runid_updated); connect(pb_save, &QPushButton::clicked, this, &US_LegacyConverter::save_auc); - connect(ct_tolerance, &QwtCounter::valueChanged, this, &US_LegacyConverter::new_tolerance); connect(archive, &US_Archive::itemExtracted, this, &US_LegacyConverter::itemExtracted); } @@ -143,18 +122,19 @@ void US_LegacyConverter::save_auc() { dir.mkdir(dir.absolutePath()); QMapIterator it(data_types); QString rtype; - while (it.hasNext()) { - it.next(); - if (QString::compare(it.value(), cb_runtype->currentText(), Qt::CaseInsensitive) == 0) { - rtype = it.key(); - break; - } - } + // while (it.hasNext()) { + // it.next(); + // if (QString::compare(it.value(), cb_runtype->currentText(), Qt::CaseInsensitive) == 0) { + // rtype = it.key(); + // break; + // } + // } QVector< US_DataIO::RawData* > data; QList< US_Convert::TripleInfo > triples; QVector< US_Convert::Excludes > excludes; QMapIterator< QString, US_Convert::TripleInfo > it_triple(all_triples); - QString msg = tr("Saving the %1 OpenAuc files:\n").arg(cb_runtype->currentText()); + // QString msg = tr("Saving the %1 OpenAuc files:\n").arg(cb_runtype->currentText()); + QString msg; msg += dir.absolutePath() + "\n"; while (it_triple.hasNext()) { it_triple.next(); @@ -174,8 +154,8 @@ void US_LegacyConverter::save_auc() { if (state == US_Convert::OK) { te_info->insertPlainText(msg); te_info->moveCursor(QTextCursor::End); - QMessageBox::information(this, "Data Saved!", cb_runtype->currentText() + - " data saved in \n\n" + dir.absolutePath()); + // QMessageBox::information(this, "Data Saved!", cb_runtype->currentText() + + // " data saved in \n\n" + dir.absolutePath()); } else { QMessageBox::warning(this, "Error!", "Data cannot be saved! Check the output directory!"); } @@ -187,7 +167,6 @@ void US_LegacyConverter::reset(void) { lb_runid->setText("Run ID:"); le_runid->setStyleSheet("color: black;"); te_info->clear(); - cb_runtype->clear(); all_data.clear(); all_triples.clear(); } @@ -288,9 +267,9 @@ void US_LegacyConverter::reload() { loaded_types << dtype; } } - foreach (QString key, loaded_types) { - cb_runtype->addItem(data_types.value(key)); - } + // foreach (QString key, loaded_types) { + // cb_runtype->addItem(data_types.value(key)); + // } te_info->setText(status); te_info->moveCursor(QTextCursor::End); runid_updated(); @@ -393,7 +372,8 @@ bool US_LegacyConverter::read_beckman_files(const QString& path, QString& status QDir tmpdir(path); QStringList subdirs = tmpdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks); int counter = 1; - double tolerance = static_cast(ct_tolerance->value()); + // double tolerance = static_cast(ct_tolerance->value()); + double tolerance = 0.5; foreach (QString path, subdirs) { QList rawscan; QString runtype; diff --git a/programs/us_legacy_converter/us_legacy_converter.h b/programs/us_legacy_converter/us_legacy_converter.h index e48f668e4..bc802022e 100644 --- a/programs/us_legacy_converter/us_legacy_converter.h +++ b/programs/us_legacy_converter/us_legacy_converter.h @@ -29,10 +29,7 @@ class US_LegacyConverter : public US_Widgets QString tar_fpath; //!< File path for the TAR archive QLineEdit *le_load; //!< Line edit for load path QTextEdit *te_info; //!< Text edit for information display - QComboBox *cb_runtype; //!< Combo box for run type - QwtCounter *ct_tolerance; //!< Counter for tolerance QPushButton *pb_load; //!< Button to load data - QPushButton *pb_reload; //!< Button to reload data QPushButton *pb_save; //!< Button to save data US_LineEdit_RE *le_runid; //!< Line edit for run ID with regular expression validation QLineEdit *le_dir; //!< Line edit for directory From 94d9d67c4b92450eecc37a59d7e60c8635a27f9a Mon Sep 17 00:00:00 2001 From: Saeed Date: Mon, 16 Dec 2024 12:59:00 -0700 Subject: [PATCH 3/7] us_legacy_converter: delete the tolerance function --- .../us_legacy_converter.cpp | 34 ++++--------------- .../us_legacy_converter/us_legacy_converter.h | 8 ----- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/programs/us_legacy_converter/us_legacy_converter.cpp b/programs/us_legacy_converter/us_legacy_converter.cpp index ed0458010..211aa75cf 100644 --- a/programs/us_legacy_converter/us_legacy_converter.cpp +++ b/programs/us_legacy_converter/us_legacy_converter.cpp @@ -76,13 +76,6 @@ US_LegacyConverter::US_LegacyConverter() : US_Widgets() connect(archive, &US_Archive::itemExtracted, this, &US_LegacyConverter::itemExtracted); } -void US_LegacyConverter::new_tolerance(double){ - reset(); - if (! tar_fpath.isEmpty()){ - te_info->setText("Reload the current file or load another file!"); - } -} - void US_LegacyConverter::runid_updated() { QDir dir = QDir(le_dir->text()); dir.setPath(dir.absoluteFilePath(le_runid->text())); @@ -173,15 +166,11 @@ void US_LegacyConverter::reset(void) { void US_LegacyConverter::load() { QString ext_str = "tar.gz Files ( *.tar.gz )"; - QString fpath = QFileDialog::getOpenFileName(this, tr("Beckman Optima tar.gz File"), QDir::homePath(), ext_str); - if (fpath.size() == 0){ + QString tar_fpath = QFileDialog::getOpenFileName(this, tr("Beckman Optima tar.gz File"), QDir::homePath(), ext_str); + if (tar_fpath.isEmpty()){ return; } - tar_fpath = fpath; - reload(); -} -void US_LegacyConverter::reload() { reset(); le_load->clear(); QRegularExpression re; @@ -193,18 +182,8 @@ void US_LegacyConverter::reload() { te_info->moveCursor(QTextCursor::End); qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); qApp->processEvents(); - if (tar_fpath.size() == 0) { - QMessageBox::warning(this, "Warning!", tr("No File Loaded!")); - qApp->restoreOverrideCursor(); - return; - } + QFileInfo tar_finfo = QFileInfo(tar_fpath); - if (! tar_finfo.exists()) { - QMessageBox::warning(this, "Error!", tr("TAR File Not Found!\n\n(%1)!").arg(tar_finfo.absoluteFilePath())); - tar_fpath.clear(); - qApp->restoreOverrideCursor(); - return; - } qDebug() << "file path: " << tar_fpath; QTemporaryDir tmp_dir; @@ -237,7 +216,7 @@ void US_LegacyConverter::reload() { } QStringList filelist; list_files(tmp_dir.path(), filelist); - if (filelist.size() == 0) { + if (filelist.isEmpty()) { QMessageBox::warning(this, "Warning!", tr("File is empty!\n(%1)").arg(tar_finfo.absoluteFilePath())); tar_fpath.clear(); te_info->clear(); @@ -295,9 +274,8 @@ bool US_LegacyConverter::sort_files(const QStringList& flist, const QString& tmp QRegularExpressionMatch match; // RunId1991-s0001-c2-s0009-w260-r_-n1.ri2 // RunId1991-s0002-c1-s0001-n1.ip1 - // QString pattern = "^(.+)-s(\\d{4,6})-c(\\d)-s(\\d{4,6})-(?:w(\\d{3})-)?(.+?)[.](?:RA|RI|IP|FI|WA|WI)\\d$"; //group1 (.+) = runID - //group2 -s(\\d{4,6}) = ? maybe sample + //group2 -s(\\d{4,6}) = speed //group3 -c(\\d) = cell number //group4 -s(\\d{4,6}) = scan number //group5 (?:-w(\\d{3})-r_)? = wavelength (optional: some files include it) @@ -308,6 +286,7 @@ bool US_LegacyConverter::sort_files(const QStringList& flist, const QString& tmp QString runid; QMap file_map; QMap> tcws_map; + QStringList stcws; // speed-type-cell-wavelength-scan foreach (QString fpath, flist) { QFileInfo finfo = QFileInfo(fpath); @@ -323,6 +302,7 @@ bool US_LegacyConverter::sort_files(const QStringList& flist, const QString& tmp return false; } } + QString speed = match.captured(2); QString cell = match.captured(3); int scan = match.captured(4).toInt(); QString wavl = match.captured(5); diff --git a/programs/us_legacy_converter/us_legacy_converter.h b/programs/us_legacy_converter/us_legacy_converter.h index bc802022e..3c6fc8b9f 100644 --- a/programs/us_legacy_converter/us_legacy_converter.h +++ b/programs/us_legacy_converter/us_legacy_converter.h @@ -26,7 +26,6 @@ class US_LegacyConverter : public US_Widgets QMap< QString, US_Convert::TripleInfo > all_triples; //!< Map of all triples QLabel *lb_runid; //!< Label for run ID - QString tar_fpath; //!< File path for the TAR archive QLineEdit *le_load; //!< Line edit for load path QTextEdit *te_info; //!< Text edit for information display QPushButton *pb_load; //!< Button to load data @@ -64,19 +63,12 @@ class US_LegacyConverter : public US_Widgets //! \brief Slot to load data void load(void); - //! \brief Slot to reload data - void reload(void); - //! \brief Slot to update the run ID void runid_updated(void); //! \brief Slot to save AUC data void save_auc(void); - //! \brief Slot to update tolerance - //! \param tolerance New tolerance value - void new_tolerance(double tolerance); - //! \brief Slot to update text edit when a file extracted from the archive file //! \param relative path //! \param absolute path From d8344ac415cb1473af74e1706aebfc50d6cab501 Mon Sep 17 00:00:00 2001 From: Saeed Date: Mon, 16 Dec 2024 16:29:04 -0700 Subject: [PATCH 4/7] us_legacy_converter: sort data by speed and run type --- .../us_legacy_converter.cpp | 120 +++++++++--------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/programs/us_legacy_converter/us_legacy_converter.cpp b/programs/us_legacy_converter/us_legacy_converter.cpp index 211aa75cf..0dd8d9d83 100644 --- a/programs/us_legacy_converter/us_legacy_converter.cpp +++ b/programs/us_legacy_converter/us_legacy_converter.cpp @@ -89,6 +89,12 @@ void US_LegacyConverter::runid_updated() { } void US_LegacyConverter::save_auc() { + // RI -> Intensity + // RA -> Absorbance + // WI -> Intensity + // WA -> Absorbance + // IP -> Interference + // FI -> Fluorensce te_info->moveCursor(QTextCursor::End); if (all_data.isEmpty()) { QMessageBox::warning(this, "Warning!", "No Data Loaded!"); @@ -96,7 +102,7 @@ void US_LegacyConverter::save_auc() { } QString runid = le_runid->text(); if (runid.isEmpty()) { - QMessageBox::warning(this, "Error!", "No Run ID Set!"); + QMessageBox::warning(this, "Error!", "No RunID Set!"); return; } QDir dir = QDir(le_dir->text()); @@ -165,6 +171,7 @@ void US_LegacyConverter::reset(void) { } void US_LegacyConverter::load() { + QString ext_str = "tar.gz Files ( *.tar.gz )"; QString tar_fpath = QFileDialog::getOpenFileName(this, tr("Beckman Optima tar.gz File"), QDir::homePath(), ext_str); if (tar_fpath.isEmpty()){ @@ -178,7 +185,7 @@ void US_LegacyConverter::load() { QRegularExpressionMatch match; te_info->clear(); - te_info->append("Extracting archive file. Please Wait!"); + te_info->append("Extracting the Archive File. Please Wait!"); te_info->moveCursor(QTextCursor::End); qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); qApp->processEvents(); @@ -193,11 +200,11 @@ void US_LegacyConverter::load() { QString fpath = tar_finfo.absoluteFilePath(); QString opath = tmp_dir.path(); bool ok = archive->extract(fpath, opath); - te_info->append("Process: Extracting file ..."); + te_info->append("Process: Extracting File ..."); qApp->processEvents(); if (! ok) { te_info->clear(); - te_info->append( tr("Failed to exctract the file: %1 \n").arg(tar_finfo.absoluteFilePath()) ); + te_info->append( tr("Failed to Exctract the File: %1 \n").arg(tar_finfo.absoluteFilePath()) ); te_info->append(archive->getError()); tar_fpath.clear(); qApp->restoreOverrideCursor(); @@ -209,7 +216,7 @@ void US_LegacyConverter::load() { qApp->processEvents(); runid = tar_finfo.fileName().chopped(7); } else { - QMessageBox::warning(this, "Error!", tr("FAILED to create a /tmp directory!")); + QMessageBox::warning(this, "Error!", tr("FAILED to Create a Temporary Directory!")); tar_fpath.clear(); qApp->restoreOverrideCursor(); return; @@ -217,14 +224,14 @@ void US_LegacyConverter::load() { QStringList filelist; list_files(tmp_dir.path(), filelist); if (filelist.isEmpty()) { - QMessageBox::warning(this, "Warning!", tr("File is empty!\n(%1)").arg(tar_finfo.absoluteFilePath())); + QMessageBox::warning(this, "Warning!", tr("Empty TGZ File!\n(%1)").arg(tar_finfo.absoluteFilePath())); tar_fpath.clear(); te_info->clear(); qApp->restoreOverrideCursor(); return; } if (! sort_files( filelist, tmp_dir_sorted.path() ) ) { - QMessageBox::warning(this, "Warning!", tr("Incorrect filename pattern!\n\n(%1)").arg(tar_finfo.absoluteFilePath())); + QMessageBox::warning(this, "Warning!", tr("Incorrect Filename Pattern!\n\n(%1)").arg(tar_finfo.absoluteFilePath())); tar_fpath.clear(); te_info->clear(); qApp->restoreOverrideCursor(); @@ -237,18 +244,6 @@ void US_LegacyConverter::load() { } le_load->setText(tar_finfo.absoluteFilePath()); le_runid->setText(runid); - QStringList loaded_types; - QMapIterator< QString, US_Convert::TripleInfo > it(all_triples); - while (it.hasNext()) { - it.next(); - QString dtype = it.key().split(':').at(0).trimmed(); - if (! loaded_types.contains(dtype)){ - loaded_types << dtype; - } - } - // foreach (QString key, loaded_types) { - // cb_runtype->addItem(data_types.value(key)); - // } te_info->setText(status); te_info->moveCursor(QTextCursor::End); runid_updated(); @@ -284,9 +279,9 @@ bool US_LegacyConverter::sort_files(const QStringList& flist, const QString& tmp re.setPattern(pattern); QString runid; - QMap file_map; - QMap> tcws_map; - QStringList stcws; // speed-type-cell-wavelength-scan + QMap> stcw_scans; // speed-type-cell-wavelength -> scans + QMap file_map; // speed-type-cell-wavelength-scan -> filepath + QVector speed_list; foreach (QString fpath, flist) { QFileInfo finfo = QFileInfo(fpath); @@ -298,11 +293,14 @@ bool US_LegacyConverter::sort_files(const QStringList& flist, const QString& tmp runid = match.captured(1); } else { if (QString::compare(runid, match.captured(1)) != 0) { - QMessageBox::warning(this, "Error!", "Multiple run IDs found!"); + QMessageBox::warning(this, "Error!", "Multiple Run IDs Found!"); return false; } } - QString speed = match.captured(2); + int speed = match.captured(2).toInt(); + if (! speed_list.contains(speed)) { + speed_list << speed; + } QString cell = match.captured(3); int scan = match.captured(4).toInt(); QString wavl = match.captured(5); @@ -310,39 +308,42 @@ bool US_LegacyConverter::sort_files(const QStringList& flist, const QString& tmp wavl = "000"; } QString runtype = match.captured(6); - QString tcw = runtype + "-" + cell + "-" + wavl; - if (tcws_map.contains(tcw)) { - tcws_map[tcw] << scan; + QString key1 = tr("%1-%2-%3-%4").arg(speed_list.indexOf(speed) + 1).arg(runtype, cell, wavl); + if (stcw_scans.contains(key1)) { + stcw_scans[key1] << scan; } else { QVector ss(1, scan); - tcws_map.insert(tcw, ss); + stcw_scans.insert(key1, ss); } - QString tcws = tcw + "-" + QString::number(scan); - if (file_map.contains(tcws)) { - QMessageBox::warning(this, "Error!", tr("Redundancy in scans!\%1").arg(fname)); + QString key2 = tr("%1-%2").arg(key1).arg(scan); + if (file_map.contains(key2)) { + QMessageBox::warning(this, "Error!", tr("Redundancy In Scans!\%1").arg(fname)); return false; } else { - file_map.insert(tcws, fpath); + file_map.insert(key2, fpath); } } } QDir dir = QDir(tmpDir); - QMapIterator> it(tcws_map); - bool state = false; + QDir subdir = QDir(); + QMapIterator> it(stcw_scans); + bool state = true; while (it.hasNext()) { it.next(); - QString tcw = it.key(); - dir.mkdir(tcw); - QDir subdir = QDir(dir.absoluteFilePath(tcw)); + QString key1 = it.key(); + dir.mkdir(key1); + subdir.setPath(dir.absoluteFilePath(key1)); QVector scans = it.value(); std::sort(scans.begin(), scans.end()); - QFileInfo finfo = QFileInfo(); + // QFileInfo finfo = QFileInfo(); for (int ii = 0; ii < scans.size(); ii++) { - QString ss = QString::number(scans.at(ii)); - QString fpath1 = file_map.value(tcw + "-" + ss); - QString fname2 = ss.rightJustified(5, '0') + fpath1.right(4); - finfo.setFile(subdir, fname2); - if (QFile::copy(fpath1, finfo.absoluteFilePath())) state = true; + QString key2 = tr("%1-%2").arg(key1).arg(scans.at(ii)); + QString fpath1 = file_map.value(key2); + QString fname2 = tr("%1.%2").arg(ii + 1).arg(fpath1.right(3)); + // finfo.setFile(subdir, fname2.rightJustified(9, '0')); + if (! QFile::copy(fpath1, subdir.absoluteFilePath(fname2.rightJustified(9, '0'))) ) { + state = false; + } } } return state; @@ -351,9 +352,6 @@ bool US_LegacyConverter::sort_files(const QStringList& flist, const QString& tmp bool US_LegacyConverter::read_beckman_files(const QString& path, QString& status){ QDir tmpdir(path); QStringList subdirs = tmpdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks); - int counter = 1; - // double tolerance = static_cast(ct_tolerance->value()); - double tolerance = 0.5; foreach (QString path, subdirs) { QList rawscan; QString runtype; @@ -361,34 +359,36 @@ bool US_LegacyConverter::read_beckman_files(const QString& path, QString& status if (rawscan.size() == 0) { continue; } - + QString speed = path.split('-').at(0); QVector< US_DataIO::RawData > rawdata; QList< US_Convert::TripleInfo > triples; - US_Convert::convertLegacyData(rawscan, rawdata, triples, runtype, tolerance); + US_Convert::convertLegacyData(rawscan, rawdata, triples, runtype, 0.5); QDir subd = QDir(tmpdir.absoluteFilePath(path), "*", QDir::Name, QDir::Files); - status += QString::number(counter) + ":\n"; - counter ++; - status += tr("Run type: %1 (%2)\n").arg(data_types.value(runtype), runtype); - status += tr("Number of the parsed files: %1\n").arg(subd.count()); - status += tr("Number of the beckman data objects: %1\n").arg(rawscan.count()); - - QString msg("Run type: %1 (%2), Number of the processed files: %3"); - te_info->append(msg.arg(data_types.value(runtype), runtype).arg(subd.count())); + status += tr("RPM : %1\n").arg(speed); + status += tr("Run Type : %1 (%2)\n").arg(data_types.value(runtype), runtype); + status += tr("Number of Parsed Files : %1\n").arg(subd.count()); + status += tr("Number of Beckman Data Objects : %1\n").arg(rawscan.count()); + + QString msg("RPM:%1, Run type: %2 (%3), Number of the processed files: %4"); + te_info->append(msg.arg(speed, data_types.value(runtype), runtype).arg(subd.count())); te_info->moveCursor(QTextCursor::End); qApp->processEvents(); for (int ii = 0; ii < triples.size(); ii ++) { - QString tdesc = triples.at(ii).tripleDesc.trimmed(); - QString key = tr("%1:%2").arg(runtype, tdesc); + QStringList ccw = triples.at(ii).tripleDesc.split('/'); + // speed-runtype-cell-channel-lambda + QString key = tr("%1-%2-%3-%4-%5").arg(speed, runtype, ccw.at(0).trimmed(), + ccw.at(1).trimmed(), ccw.at(2).trimmed()); if (all_triples.contains(key)){ - QMessageBox::warning(this, "Error!", "Triple redundancy!"); + QMessageBox::warning(this, "Error!", "Triple Redundancy!"); qDebug().noquote() << status; return false; } all_triples.insert(key, triples.at(ii)); all_data.insert(key, rawdata.at(ii)); - status += tr("Triple: %1 # Scans: %2\n").arg(tdesc).arg(rawdata.at(ii).scanData.count()); + status += tr( "Triple: %1 # Scans: %2\n").arg(triples.at(ii).tripleDesc) + .arg(rawdata.at(ii).scanData.count() ); } status += "------------------------------\n"; // qApp->processEvents(); From 508069163bc3457dbbbe56fd7028770cdf8fda38 Mon Sep 17 00:00:00 2001 From: Saeed Date: Mon, 16 Dec 2024 21:10:57 -0700 Subject: [PATCH 5/7] us_legacy_converter: replaced QMap with QVector for all_data and all_triples. Stored indexes of triples, rawdata, and output runIDs in output_index and output_types --- .../us_legacy_converter.cpp | 126 +++++++++++------- .../us_legacy_converter/us_legacy_converter.h | 6 +- 2 files changed, 84 insertions(+), 48 deletions(-) diff --git a/programs/us_legacy_converter/us_legacy_converter.cpp b/programs/us_legacy_converter/us_legacy_converter.cpp index 0dd8d9d83..3da0eb5e7 100644 --- a/programs/us_legacy_converter/us_legacy_converter.cpp +++ b/programs/us_legacy_converter/us_legacy_converter.cpp @@ -25,8 +25,8 @@ US_LegacyConverter::US_LegacyConverter() : US_Widgets() data_types.insert("RI", "Intensity"); data_types.insert("RA", "Absorbance"); - data_types.insert("WI", "Intensity"); - data_types.insert("WA", "Absorbance"); + data_types.insert("WI", "WI"); + data_types.insert("WA", "WA"); data_types.insert("IP", "Interference"); data_types.insert("FI", "Fluorensce"); @@ -80,7 +80,7 @@ void US_LegacyConverter::runid_updated() { QDir dir = QDir(le_dir->text()); dir.setPath(dir.absoluteFilePath(le_runid->text())); if (dir.exists()) { - lb_runid->setText("( existing ) Run ID:"); + lb_runid->setText("Already Exists! Run ID:"); le_runid->setStyleSheet("color: red;"); } else { lb_runid->setText("Run ID:"); @@ -89,12 +89,6 @@ void US_LegacyConverter::runid_updated() { } void US_LegacyConverter::save_auc() { - // RI -> Intensity - // RA -> Absorbance - // WI -> Intensity - // WA -> Absorbance - // IP -> Interference - // FI -> Fluorensce te_info->moveCursor(QTextCursor::End); if (all_data.isEmpty()) { QMessageBox::warning(this, "Warning!", "No Data Loaded!"); @@ -128,36 +122,38 @@ void US_LegacyConverter::save_auc() { // break; // } // } - QVector< US_DataIO::RawData* > data; - QList< US_Convert::TripleInfo > triples; - QVector< US_Convert::Excludes > excludes; - QMapIterator< QString, US_Convert::TripleInfo > it_triple(all_triples); - // QString msg = tr("Saving the %1 OpenAuc files:\n").arg(cb_runtype->currentText()); - QString msg; - msg += dir.absolutePath() + "\n"; - while (it_triple.hasNext()) { - it_triple.next(); - if (QString::compare(it_triple.key().split(':').at(0), rtype) == 0){ - triples << it_triple.value(); - US_DataIO::RawData *rdp; - US_DataIO::RawData rd = all_data[it_triple.key()]; - rdp = &all_data[it_triple.key()]; - data << rdp; - US_Convert::Excludes excl; - excludes << excl; - msg += it_triple.key().split(':').at(1).trimmed() + "\n"; - } - } - msg += "------------------------------\n"; - int state = US_Convert::saveToDisk(data, triples, excludes, rtype, runid, dir.absolutePath(), false); - if (state == US_Convert::OK) { - te_info->insertPlainText(msg); - te_info->moveCursor(QTextCursor::End); - // QMessageBox::information(this, "Data Saved!", cb_runtype->currentText() + - // " data saved in \n\n" + dir.absolutePath()); - } else { - QMessageBox::warning(this, "Error!", "Data cannot be saved! Check the output directory!"); - } + + + // QVector< US_DataIO::RawData* > data; + // QList< US_Convert::TripleInfo > triples; + // QVector< US_Convert::Excludes > excludes; + // QMapIterator< QString, US_Convert::TripleInfo > it_triple(all_triples); + // // QString msg = tr("Saving the %1 OpenAuc files:\n").arg(cb_runtype->currentText()); + // QString msg; + // msg += dir.absolutePath() + "\n"; + // while (it_triple.hasNext()) { + // it_triple.next(); + // if (QString::compare(it_triple.key().split(':').at(0), rtype) == 0){ + // triples << it_triple.value(); + // US_DataIO::RawData *rdp; + // US_DataIO::RawData rd = all_data[it_triple.key()]; + // rdp = &all_data[it_triple.key()]; + // data << rdp; + // US_Convert::Excludes excl; + // excludes << excl; + // msg += it_triple.key().split(':').at(1).trimmed() + "\n"; + // } + // } + // msg += "------------------------------\n"; + // int state = US_Convert::saveToDisk(data, triples, excludes, rtype, runid, dir.absolutePath(), false); + // if (state == US_Convert::OK) { + // te_info->insertPlainText(msg); + // te_info->moveCursor(QTextCursor::End); + // // QMessageBox::information(this, "Data Saved!", cb_runtype->currentText() + + // // " data saved in \n\n" + dir.absolutePath()); + // } else { + // QMessageBox::warning(this, "Error!", "Data cannot be saved! Check the output directory!"); + // } runid_updated(); } @@ -168,6 +164,9 @@ void US_LegacyConverter::reset(void) { te_info->clear(); all_data.clear(); all_triples.clear(); + output_index.clear(); + output_types.clear(); + counter = 0; } void US_LegacyConverter::load() { @@ -212,7 +211,6 @@ void US_LegacyConverter::load() { } te_info->clear(); te_info->append("Parsing Data. Please Wait!"); - counter = 0; qApp->processEvents(); runid = tar_finfo.fileName().chopped(7); } else { @@ -242,6 +240,18 @@ void US_LegacyConverter::load() { qApp->restoreOverrideCursor(); return; } + // multi speed run: rename output directories + QList speed_list = output_types.keys(); + if (speed_list.size() > 1) { + foreach (int speed, speed_list) { + foreach (QString rtype, output_types.value(speed).keys()) { + QString cval = output_types.value(speed).value(rtype); + QString nval = tr("%1-RPM%2").arg(cval).arg(speed); + output_types[speed][rtype] = nval; + } + } + } + le_load->setText(tar_finfo.absoluteFilePath()); le_runid->setText(runid); te_info->setText(status); @@ -352,6 +362,8 @@ bool US_LegacyConverter::sort_files(const QStringList& flist, const QString& tmp bool US_LegacyConverter::read_beckman_files(const QString& path, QString& status){ QDir tmpdir(path); QStringList subdirs = tmpdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks); + int NN = 0; + QStringList stccw; foreach (QString path, subdirs) { QList rawscan; QString runtype; @@ -359,7 +371,7 @@ bool US_LegacyConverter::read_beckman_files(const QString& path, QString& status if (rawscan.size() == 0) { continue; } - QString speed = path.split('-').at(0); + int speed = path.split('-').at(0).toInt(); QVector< US_DataIO::RawData > rawdata; QList< US_Convert::TripleInfo > triples; US_Convert::convertLegacyData(rawscan, rawdata, triples, runtype, 0.5); @@ -371,22 +383,44 @@ bool US_LegacyConverter::read_beckman_files(const QString& path, QString& status status += tr("Number of Beckman Data Objects : %1\n").arg(rawscan.count()); QString msg("RPM:%1, Run type: %2 (%3), Number of the processed files: %4"); - te_info->append(msg.arg(speed, data_types.value(runtype), runtype).arg(subd.count())); + te_info->append(msg.arg(speed).arg(data_types.value(runtype), runtype).arg(subd.count())); te_info->moveCursor(QTextCursor::End); qApp->processEvents(); for (int ii = 0; ii < triples.size(); ii ++) { QStringList ccw = triples.at(ii).tripleDesc.split('/'); // speed-runtype-cell-channel-lambda - QString key = tr("%1-%2-%3-%4-%5").arg(speed, runtype, ccw.at(0).trimmed(), + QString key = tr("%1-%2-%3-%4-%5").arg(speed).arg(runtype, ccw.at(0).trimmed(), ccw.at(1).trimmed(), ccw.at(2).trimmed()); - if (all_triples.contains(key)){ + if (stccw.contains(key)){ QMessageBox::warning(this, "Error!", "Triple Redundancy!"); qDebug().noquote() << status; return false; } - all_triples.insert(key, triples.at(ii)); - all_data.insert(key, rawdata.at(ii)); + all_triples << triples.at(ii); + all_data << rawdata.at(ii); + if (output_index.contains(speed)) { + if(output_index.value(speed).contains(runtype)) { + output_index[speed][runtype] << NN; + } else { + QVector vec; + vec << NN; + output_index[speed].insert(runtype, vec); + output_types[speed].insert(runtype, data_types.value(runtype)); + } + + } else { + QVector vec; + vec << NN; + QHash> rt_ndx; + rt_ndx.insert(runtype, vec); + output_index.insert(speed, rt_ndx); + + QHash rt; + rt.insert(runtype, data_types.value(runtype)); + output_types.insert(speed, rt); + } + NN++; status += tr( "Triple: %1 # Scans: %2\n").arg(triples.at(ii).tripleDesc) .arg(rawdata.at(ii).scanData.count() ); } diff --git a/programs/us_legacy_converter/us_legacy_converter.h b/programs/us_legacy_converter/us_legacy_converter.h index 3c6fc8b9f..5f2fdb92b 100644 --- a/programs/us_legacy_converter/us_legacy_converter.h +++ b/programs/us_legacy_converter/us_legacy_converter.h @@ -22,8 +22,10 @@ class US_LegacyConverter : public US_Widgets private: QMap< QString, QString > data_types; //!< Map of data types - QMap< QString, US_DataIO::RawData > all_data; //!< Map of all raw data - QMap< QString, US_Convert::TripleInfo > all_triples; //!< Map of all triples + QVector< US_DataIO::RawData > all_data; //!< Map of all raw data + QVector< US_Convert::TripleInfo > all_triples; //!< Map of all triples + QHash< int, QHash< QString, QVector< int > > > output_index; // speed -> runType -> QVector(data index) + QHash< int, QHash< QString, QString > > output_types; // speed -> runType -> runType out QLabel *lb_runid; //!< Label for run ID QLineEdit *le_load; //!< Line edit for load path From add15e1334fd2bb1d8fdbec7d624ab8c8971ad67 Mon Sep 17 00:00:00 2001 From: Saeed Date: Mon, 16 Dec 2024 21:27:18 -0700 Subject: [PATCH 6/7] us_legacy_converter: update runid_updated method whether output runIDs already exist or not --- .../us_legacy_converter.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/programs/us_legacy_converter/us_legacy_converter.cpp b/programs/us_legacy_converter/us_legacy_converter.cpp index 3da0eb5e7..a73bd784d 100644 --- a/programs/us_legacy_converter/us_legacy_converter.cpp +++ b/programs/us_legacy_converter/us_legacy_converter.cpp @@ -78,8 +78,23 @@ US_LegacyConverter::US_LegacyConverter() : US_Widgets() void US_LegacyConverter::runid_updated() { QDir dir = QDir(le_dir->text()); - dir.setPath(dir.absoluteFilePath(le_runid->text())); - if (dir.exists()) { + QHashIterator> it(output_types); + QString runid = le_runid->text(); + bool exists = false; + while (it.hasNext()) { + it.next(); + bool br = false; + foreach (QString rt, it.value().values()) { + QString out_runid = runid + "-" + rt; + if (dir.exists(out_runid)) { + exists = true; + br = true; + break; + } + } + if (br) break; + } + if (exists) { lb_runid->setText("Already Exists! Run ID:"); le_runid->setStyleSheet("color: red;"); } else { From 2683b126a007e311cff3b98ffe3f4ed98581c3a3 Mon Sep 17 00:00:00 2001 From: Saeed Date: Mon, 16 Dec 2024 22:56:32 -0700 Subject: [PATCH 7/7] us_legacy_converter: finished writing function --- .../us_legacy_converter.cpp | 119 ++++++++++-------- .../us_legacy_converter/us_legacy_converter.h | 1 + 2 files changed, 65 insertions(+), 55 deletions(-) diff --git a/programs/us_legacy_converter/us_legacy_converter.cpp b/programs/us_legacy_converter/us_legacy_converter.cpp index a73bd784d..f8f950a85 100644 --- a/programs/us_legacy_converter/us_legacy_converter.cpp +++ b/programs/us_legacy_converter/us_legacy_converter.cpp @@ -67,7 +67,7 @@ US_LegacyConverter::US_LegacyConverter() : US_Widgets() this->setLayout(layout); archive = new US_Archive(); - counter = 0; + reset(); connect(pb_load, &QPushButton::clicked, this, &US_LegacyConverter::load); connect(le_runid, &US_LineEdit_RE::textUpdated, this, &US_LegacyConverter::runid_updated); @@ -80,7 +80,7 @@ void US_LegacyConverter::runid_updated() { QDir dir = QDir(le_dir->text()); QHashIterator> it(output_types); QString runid = le_runid->text(); - bool exists = false; + exists = false; while (it.hasNext()) { it.next(); bool br = false; @@ -95,7 +95,7 @@ void US_LegacyConverter::runid_updated() { if (br) break; } if (exists) { - lb_runid->setText("Already Exists! Run ID:"); + lb_runid->setText("( Already Exists! ) Run ID:"); le_runid->setStyleSheet("color: red;"); } else { lb_runid->setText("Run ID:"); @@ -114,62 +114,61 @@ void US_LegacyConverter::save_auc() { QMessageBox::warning(this, "Error!", "No RunID Set!"); return; } + + if (exists) { + // QMessageBox::StandardButton state; + int state = QMessageBox::question(this, "Warning!", "RunID already exists!\n" + "Do you want to overwrite it?"); + if (state == QMessageBox::No) return; + } + qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); + pb_save->setDisabled(true); QDir dir = QDir(le_dir->text()); - dir.setPath(dir.absoluteFilePath(runid)); - if (dir.exists()) { - QMessageBox::StandardButton state; - state = QMessageBox::question(this, "Warning!", "The output directory exists!\n\n" - + dir.absolutePath() + "\n\nBy clicking on 'YES', all data will be overwritten! " - + "Do you want to proceed?"); - if (state == QMessageBox::No) { - return; - } else { - dir.removeRecursively(); + QDir subdir = QDir(); + QString basename = le_runid->text(); + + QString msg; + QList speedL = output_index.keys(); + std::sort(speedL.begin(), speedL.end()); + foreach (int speed, speedL) { + QStringList rtypeL = output_index.value(speed).keys(); + rtypeL.sort(); + + foreach (QString rtype, rtypeL) { + QString runid = basename + "-" + output_types.value(speed).value(rtype); + QString path = dir.absoluteFilePath(runid); + subdir.setPath(path); + if (subdir.exists()) { + subdir.removeRecursively(); + } + subdir.mkpath(subdir.absolutePath()); + + QVector< US_DataIO::RawData* > data; + QList< US_Convert::TripleInfo > triples; + QVector< US_Convert::Excludes > excludes; + QVector indexL = output_index.value(speed).value(rtype); + foreach (int index, indexL) { + triples << all_triples.at(index); + data << &all_data[index]; + US_Convert::Excludes excl; + excludes << excl; + } + + int state = US_Convert::saveToDisk(data, triples, excludes, rtype, runid, path, false); + if (state == US_Convert::OK) { + msg += runid + "\n"; + } else { + QMessageBox::warning(this, "Error!", "Failed to Save this RunID!\n\n" + runid); + subdir.removeRecursively(); + } } } - dir.mkdir(dir.absolutePath()); - QMapIterator it(data_types); - QString rtype; - // while (it.hasNext()) { - // it.next(); - // if (QString::compare(it.value(), cb_runtype->currentText(), Qt::CaseInsensitive) == 0) { - // rtype = it.key(); - // break; - // } - // } - - - // QVector< US_DataIO::RawData* > data; - // QList< US_Convert::TripleInfo > triples; - // QVector< US_Convert::Excludes > excludes; - // QMapIterator< QString, US_Convert::TripleInfo > it_triple(all_triples); - // // QString msg = tr("Saving the %1 OpenAuc files:\n").arg(cb_runtype->currentText()); - // QString msg; - // msg += dir.absolutePath() + "\n"; - // while (it_triple.hasNext()) { - // it_triple.next(); - // if (QString::compare(it_triple.key().split(':').at(0), rtype) == 0){ - // triples << it_triple.value(); - // US_DataIO::RawData *rdp; - // US_DataIO::RawData rd = all_data[it_triple.key()]; - // rdp = &all_data[it_triple.key()]; - // data << rdp; - // US_Convert::Excludes excl; - // excludes << excl; - // msg += it_triple.key().split(':').at(1).trimmed() + "\n"; - // } - // } - // msg += "------------------------------\n"; - // int state = US_Convert::saveToDisk(data, triples, excludes, rtype, runid, dir.absolutePath(), false); - // if (state == US_Convert::OK) { - // te_info->insertPlainText(msg); - // te_info->moveCursor(QTextCursor::End); - // // QMessageBox::information(this, "Data Saved!", cb_runtype->currentText() + - // // " data saved in \n\n" + dir.absolutePath()); - // } else { - // QMessageBox::warning(this, "Error!", "Data cannot be saved! Check the output directory!"); - // } runid_updated(); + qApp->restoreOverrideCursor(); + if (! msg.isEmpty()) { + QMessageBox::information(this, "Data Stored!", "Run(s) Successfully Saved!\n\n" + msg); + } + pb_save->setEnabled(true); } void US_LegacyConverter::reset(void) { @@ -182,6 +181,8 @@ void US_LegacyConverter::reset(void) { output_index.clear(); output_types.clear(); counter = 0; + exists = false; + pb_save->setDisabled(true); } void US_LegacyConverter::load() { @@ -193,6 +194,7 @@ void US_LegacyConverter::load() { } reset(); + pb_load->setDisabled(true); le_load->clear(); QRegularExpression re; re.setPatternOptions(QRegularExpression::CaseInsensitiveOption); @@ -222,6 +224,7 @@ void US_LegacyConverter::load() { te_info->append(archive->getError()); tar_fpath.clear(); qApp->restoreOverrideCursor(); + pb_load->setEnabled(true); return; } te_info->clear(); @@ -232,6 +235,7 @@ void US_LegacyConverter::load() { QMessageBox::warning(this, "Error!", tr("FAILED to Create a Temporary Directory!")); tar_fpath.clear(); qApp->restoreOverrideCursor(); + pb_load->setEnabled(true); return; } QStringList filelist; @@ -241,6 +245,7 @@ void US_LegacyConverter::load() { tar_fpath.clear(); te_info->clear(); qApp->restoreOverrideCursor(); + pb_load->setEnabled(true); return; } if (! sort_files( filelist, tmp_dir_sorted.path() ) ) { @@ -248,11 +253,13 @@ void US_LegacyConverter::load() { tar_fpath.clear(); te_info->clear(); qApp->restoreOverrideCursor(); + pb_load->setEnabled(true); return; } QString status; if(! read_beckman_files(tmp_dir_sorted.path(), status)) { qApp->restoreOverrideCursor(); + pb_load->setEnabled(true); return; } // multi speed run: rename output directories @@ -272,6 +279,8 @@ void US_LegacyConverter::load() { te_info->setText(status); te_info->moveCursor(QTextCursor::End); runid_updated(); + pb_save->setEnabled(true); + pb_load->setEnabled(true); qApp->restoreOverrideCursor(); } diff --git a/programs/us_legacy_converter/us_legacy_converter.h b/programs/us_legacy_converter/us_legacy_converter.h index 5f2fdb92b..2c8cfe37f 100644 --- a/programs/us_legacy_converter/us_legacy_converter.h +++ b/programs/us_legacy_converter/us_legacy_converter.h @@ -36,6 +36,7 @@ class US_LegacyConverter : public US_Widgets QLineEdit *le_dir; //!< Line edit for directory US_Archive* archive; //!< Archive object int counter; //!< counter to update test edit + bool exists; //!< if it's true, runIDs are overwritten on disk //! \brief Resets the converter to its initial state void reset(void);