Skip to content

Commit

Permalink
Merge pull request #117 from samo38/master
Browse files Browse the repository at this point in the history
new pseudo-absorbance program
  • Loading branch information
demeler authored Jul 16, 2024
2 parents 93c4ea8 + 12d6860 commit 4400d2b
Show file tree
Hide file tree
Showing 6 changed files with 1,599 additions and 1,784 deletions.
16 changes: 9 additions & 7 deletions programs/us_legacy_converter/us_legacy_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ void US_LegacyConverter::reload() {
}
QFileInfo tar_finfo = QFileInfo(tar_fpath);
if (! tar_finfo.exists()) {
QMessageBox::warning(this, "Error!", tr("File Not Found!\n\n(%1)!").arg(tar_finfo.absoluteFilePath()));
QMessageBox::warning(this, "Error!", tr("TAR File Not Found!\n\n(%1)!").arg(tar_finfo.absoluteFilePath()));
tar_fpath.clear();
qApp->restoreOverrideCursor();
return;
Expand All @@ -327,13 +327,13 @@ void US_LegacyConverter::reload() {
QStringList filelist;
list_files(tmp_dir.path(), filelist);
if (filelist.size() == 0) {
QMessageBox::warning(this, "Warning!", tr("Empty File!\n(%1)").arg(tar_finfo.absoluteFilePath()));
QMessageBox::warning(this, "Warning!", tr("File is empty!\n(%1)").arg(tar_finfo.absoluteFilePath()));
tar_fpath.clear();
qApp->restoreOverrideCursor();
return;
}
if (! sort_files( filelist, tmp_dir_sorted.path() ) ) {
QMessageBox::warning(this, "Warning!", tr("No right files found in the TAR file!\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();
qApp->restoreOverrideCursor();
return;
Expand Down Expand Up @@ -384,18 +384,20 @@ bool US_LegacyConverter::sort_files(const QStringList& flist, const QString& tmp
QRegularExpression re;
re.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
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$";
re.setPattern(pattern);

QString runid;
QString runtype;
QMap<QString, QString> file_map;
QMap<QString, QVector<int>> tcws_map;

foreach (QString fpath, flist) {
QFileInfo finfo = QFileInfo(fpath);
QFile file(fpath);
QString fname = finfo.fileName();

// RunId1991-s0001-c2-s0009-w260-r_-n1.ri2
re.setPattern("^(.+)-s(\\d{4,6})-c(\\d)-s(\\d{4,6})-w(\\d{3})-(.+?)[.](?:RA|RI|IP|FI|WA|WI)\\d$");
match = re.match(fname);
if (match.hasMatch()) {
if (runid.size() == 0) {
Expand All @@ -419,7 +421,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!", "Scan number redundancy!");
QMessageBox::warning(this, "Error!", "Some of scans are redundant!");
return false;
} else {
file_map.insert(tcws, fpath);
Expand Down
209 changes: 130 additions & 79 deletions programs/us_pseudo_absorbance/us_add_refScan.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "us_add_refScan.h"
#include <QTextStream>

US_AddRefScan::US_AddRefScan() : US_Widgets()
{
Expand Down Expand Up @@ -64,16 +65,17 @@ US_AddRefScan::US_AddRefScan() : US_Widgets()
ckb_align->setCheckState(Qt::Unchecked);
pb_clscltr = us_pushbutton("Clustering Control", false, 0 );
pb_clscltr->setDisabled(true);
// pb_clscltr->setFixedWidth(150);

QHBoxLayout* cls_aln_lyt = new QHBoxLayout();
cls_aln_lyt->addLayout(ckb_cls_lyt);
cls_aln_lyt->addLayout(ckb_aln_lyt);
// QHBoxLayout* cls_aln_lyt = new QHBoxLayout();
// cls_aln_lyt->addLayout(ckb_cls_lyt);
// cls_aln_lyt->addLayout(ckb_aln_lyt);

// Chromatic Aberration Correction
QLabel* lb_CA = us_banner(tr("Chromatic Aberration Correction"));
ckb_CA_state = new QCheckBox();
QGridLayout* ckb_CA_state_lyt = us_checkbox("Do Not Correct", ckb_CA_state);
ckb_CA_state->setCheckState(Qt::Unchecked);
ckb_CA_state->setCheckState(Qt::Checked);
ckb_CA_local = new QCheckBox();
QGridLayout* ckb_CA_source_lyt = us_checkbox("Local Disk", ckb_CA_local);
ckb_CA_local->setCheckState(Qt::Unchecked);
Expand All @@ -82,37 +84,55 @@ US_AddRefScan::US_AddRefScan() : US_Widgets()
ckb_CA_state->setDisabled(true);
ckb_CA_local->setDisabled(true);
pb_loadCA->setDisabled(true);
QHBoxLayout *CA_lyt = new QHBoxLayout();
CA_lyt->addLayout(ckb_CA_state_lyt);
CA_lyt->addLayout(ckb_CA_source_lyt);
CA_lyt->addWidget(pb_loadCA);
// QHBoxLayout *CA_lyt = new QHBoxLayout();
// CA_lyt->addLayout(ckb_CA_state_lyt);
// CA_lyt->addLayout(ckb_CA_source_lyt);
// CA_lyt->addWidget(pb_loadCA);

lb_CA->hide();
ckb_CA_state->hide();
for (int ii = 0; ii < ckb_CA_state_lyt->count(); ii++) {
ckb_CA_state_lyt->itemAt(ii)->widget()->hide();
}
for (int ii = 0; ii < ckb_CA_source_lyt->count(); ii++) {
ckb_CA_source_lyt->itemAt(ii)->widget()->hide();
}
pb_loadCA->hide();


// save refScan control
QLabel* lb_save = us_banner(tr("Saving Control"));
dkdb_ctrl = new US_Disk_DB_Controls();
dkdb_ctrl->set_disk();

lb_dir = us_label( tr( "Directory:" ), -1 );
le_dir = us_lineedit( US_Settings::importDir(), -1, true );
lb_dbName = us_label( tr( "Database:" ), -1 );
le_dbName = us_lineedit( "", -1, true );
// QLabel* lb_save = us_banner(tr("Saving Control"));
// dkdb_ctrl = new US_Disk_DB_Controls();
// dkdb_ctrl->set_disk();

// lb_dir = us_label( tr( "Directory:" ), -1 );
// le_dir = us_lineedit( US_Settings::workBaseDir(), -1, true );
// lb_dbName = us_label( tr( "Database:" ), -1 );
// le_dbName = us_lineedit( "", -1, true );
pb_save = us_pushbutton("Save", false, 0 );
pb_save->setDisabled(true);

if (dkdb_ctrl->db()){
lb_dir->hide();
le_dir->hide();
}else{
lb_dbName->hide();
le_dbName->hide();
}
QHBoxLayout* dir_lyt = new QHBoxLayout();
dir_lyt->addWidget(lb_dir);
dir_lyt->addWidget(le_dir);
QHBoxLayout* db_lyt = new QHBoxLayout();
db_lyt->addWidget(lb_dbName);
db_lyt->addWidget(le_dbName);

// pb_save->setFixedWidth(150);

// if (dkdb_ctrl->db()){
// lb_dir->hide();
// le_dir->hide();
// }else{
// lb_dbName->hide();
// le_dbName->hide();
// }
// QHBoxLayout* dir_lyt = new QHBoxLayout();
// dir_lyt->addWidget(lb_dir);
// dir_lyt->addWidget(le_dir);
// QHBoxLayout* db_lyt = new QHBoxLayout();
// db_lyt->addWidget(lb_dbName);
// db_lyt->addWidget(le_dbName);


QGridLayout* procctrl_lyt = new QGridLayout();
procctrl_lyt->addLayout(ckb_cls_lyt, 0, 0, 1, 1);
procctrl_lyt->addLayout(ckb_aln_lyt, 0, 1, 1, 1);
procctrl_lyt->addWidget(pb_clscltr, 1, 0, 1, 1);
procctrl_lyt->addWidget(pb_save, 1, 1, 1, 1);
// status
QLabel* lb_status = us_label(tr("Status:"));
le_status = us_lineedit(tr(""), -1, true);
Expand All @@ -134,7 +154,7 @@ US_AddRefScan::US_AddRefScan() : US_Widgets()
// layout
QVBoxLayout* left_lyt = new QVBoxLayout();
left_lyt->addStretch(0);
left_lyt->setSpacing(5);
left_lyt->setSpacing(1);
left_lyt->addWidget(lb_run);
left_lyt->addLayout(import_lyt);
left_lyt->addLayout(rid_lyt);
Expand All @@ -143,15 +163,15 @@ US_AddRefScan::US_AddRefScan() : US_Widgets()
left_lyt->addLayout(wavl_rng_lyt);
left_lyt->addLayout(wavl_plt_lyt);
left_lyt->addWidget(lb_cluster);
left_lyt->addLayout(cls_aln_lyt);
left_lyt->addWidget(pb_clscltr);
left_lyt->addWidget(lb_CA);
left_lyt->addLayout(CA_lyt);
left_lyt->addWidget(lb_save);
left_lyt->addLayout(dkdb_ctrl);
left_lyt->addLayout(dir_lyt);
left_lyt->addLayout(db_lyt);
left_lyt->addWidget(pb_save);
left_lyt->addLayout(procctrl_lyt);
left_lyt->addWidget(pb_clscltr, 0, Qt::AlignCenter);
// left_lyt->addWidget(lb_CA);
// left_lyt->addLayout(CA_lyt);
// left_lyt->addWidget(lb_save);
// left_lyt->addLayout(dkdb_ctrl);
// left_lyt->addLayout(dir_lyt);
// left_lyt->addLayout(db_lyt);
left_lyt->addWidget(pb_save, 0, Qt::AlignCenter);
// left_lyt->setStretch(0);
// left_lyt->addSpacing(20);
left_lyt->addStretch(1);
Expand Down Expand Up @@ -294,6 +314,7 @@ US_AddRefScan::US_AddRefScan() : US_Widgets()
tab1_lyt->addLayout(tab1_plt_lyt3, 1);
tab1_lyt->addLayout(tab1_plt_lyt4);
tab1_lyt->setMargin(0);
tab1_lyt->setSpacing(1);

//**//
tabs = new QTabWidget();
Expand Down Expand Up @@ -325,7 +346,7 @@ US_AddRefScan::US_AddRefScan() : US_Widgets()
connect(pb_save, SIGNAL(clicked()), this, SLOT(slt_save()));
connect(pb_loadCA, SIGNAL(clicked()), this, SLOT(slt_load_CA()));
connect(ckb_CA_state, SIGNAL(stateChanged(int)), this, SLOT(slt_CA_state(int)));
connect(dkdb_ctrl, SIGNAL(changed(bool)), this, SLOT(slt_db_local(bool)));
// connect(dkdb_ctrl, SIGNAL(changed(bool)), this, SLOT(slt_db_local(bool)));
connect(this, SIGNAL(sig_plot_l(bool)), this, SLOT(slt_plot_l(bool)));
connect(this, SIGNAL(sig_plot_r(bool)), this, SLOT(slt_plot_r(bool)));
connect(this, SIGNAL(sig_plot_dist(bool)), this, SLOT(slt_plot_dist(bool)));
Expand Down Expand Up @@ -700,29 +721,31 @@ void US_AddRefScan::slt_save(void){
}
this->setCursor(QCursor(Qt::ArrowCursor));

if (dkdb_ctrl->db())
save_db(referenceScans);
else
save_local(referenceScans);
// if (dkdb_ctrl->db())
// save_db(referenceScans);
// else
// save_local(referenceScans);

save_local(referenceScans);
return;
}

void US_AddRefScan::slt_db_local(bool status){
if (status){
lb_dir->hide();
le_dir->hide();
lb_dbName->show();
le_dbName->show();
check_connection();
}else{
lb_dir->show();
le_dir->show();
lb_dbName->hide();
le_dbName->hide();
}
// void US_AddRefScan::slt_db_local(bool status){
// if (status){
// lb_dir->hide();
// le_dir->hide();
// lb_dbName->show();
// le_dbName->show();
// check_connection();
// }else{
// lb_dir->show();
// le_dir->show();
// lb_dbName->hide();
// le_dbName->hide();
// }

return;
}
// return;
// }

void US_AddRefScan::slt_plot_l(bool state){
tab0_plotLU->detachItems(QwtPlotItem::Rtti_PlotItem, false);
Expand Down Expand Up @@ -2354,20 +2377,48 @@ bool US_AddRefScan::check_runIDs(US_DB2* db, QVector<int>& experimentIDs,
}

void US_AddRefScan::save_local(US_RefScanDataIO::RefData &refScans){
QString outFileName;
FileNameWidget FileName(outFileName);
FileName.show();
int s = FileName.exec();
if (s == QDialog::Accepted){
qDebug() << outFileName;
int error = US_RefScanDataIO::writeRefData(outFileName, refScans);
if (error != US_RefScanDataIO::OK)
le_status->setText(US_RefScanDataIO::errorString(error));
else{
le_status->setText("Written on the local disk");
US_RefScanDataIO::RefData refScans2;
US_RefScanDataIO::readRefData(outFileName, refScans2);
qDebug() << "";
// QString outFileName;
// FileNameWidget FileName(outFileName);
// FileName.show();
// int s = FileName.exec();
// if (s == QDialog::Accepted){
// qDebug() << outFileName;
// int error = US_RefScanDataIO::writeRefData(outFileName, refScans);
// if (error != US_RefScanDataIO::OK)
// le_status->setText(US_RefScanDataIO::errorString(error));
// else{
// le_status->setText("Written on the local disk");
// US_RefScanDataIO::RefData refScans2;
// US_RefScanDataIO::readRefData(outFileName, refScans2);
// qDebug() << "";
// }
// }

QString fpath = QFileDialog::getSaveFileName(this, "Save Reference Scan File",
US_Settings::dataDir(), tr("dat (*.dat)"));
if (fpath.isEmpty()) {
return;
}
if (!fpath.endsWith(".dat", Qt::CaseInsensitive)) {
fpath.append(".dat");
}
QFile file(fpath);

if (file.open(QIODevice::WriteOnly)) {
QTextStream textout{&file};
// textout << "Points(cm)";
textout << "cm";
for (int ii = 0; ii < refScans.nWavelength; ii++) {
// textout << tr(";Lambda(%1)").arg(refScans.wavelength.at(ii));
textout << tr(";%1nm").arg(refScans.wavelength.at(ii));
}
textout << "\n";
for (int ii = 0; ii < refScans.nPoints; ii++) {
textout << QString::number(refScans.xValues.at(ii));
for (int jj = 0; jj < refScans.nWavelength; jj++) {
textout << ";" << QString::number(refScans.rValues.at(jj).at(ii));
}
textout << "\n";
}
}
return;
Expand Down Expand Up @@ -2492,10 +2543,10 @@ void US_AddRefScan::check_connection(){
// First row
if (dbCon->isConnected()){
QStringList DB = US_Settings::defaultDB();
if (DB.isEmpty())
le_dbName->setText("Undefined");
else
le_dbName->setText(DB.at(3));
// if (DB.isEmpty())
// le_dbName->setText("Undefined");
// else
// le_dbName->setText(DB.at(3));
}
return;
}
Expand Down
12 changes: 6 additions & 6 deletions programs/us_pseudo_absorbance/us_add_refScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class US_AddRefScan : public US_Widgets
void slt_plot_ovlp(bool);
void slt_plot_inty(bool);
void slt_save(void);
void slt_db_local(bool);
// void slt_db_local(bool);
void slt_reset(void);
void slt_CA_state(int);
void slt_load_CA(void);
Expand Down Expand Up @@ -175,11 +175,11 @@ class US_AddRefScan : public US_Widgets
QLineEdit* le_lambstrt; ///< Line edit for start wavelength
QLineEdit* le_lambstop; ///< Line edit for stop wavelength
QLineEdit* le_status; ///< Line edit for status
QLineEdit* le_dir; ///< Line edit for directory
QLineEdit* le_dbName; ///< Line edit for database name
// QLineEdit* le_dir; ///< Line edit for directory
// QLineEdit* le_dbName; ///< Line edit for database name

QLabel* lb_dbName; ///< Label for database name
QLabel* lb_dir; ///< Label for directory
// QLabel* lb_dbName; ///< Label for database name
// QLabel* lb_dir; ///< Label for directory
QLabel* lb_wavlBw; ///< Label for wavelength bandwidth
QLabel* lb_runIDs; ///< Label for run IDs
QLabel* lb_wavl; ///< Label for wavelength
Expand Down Expand Up @@ -207,7 +207,7 @@ class US_AddRefScan : public US_Widgets

QRadioButton *rb_db; ///< Radio button for database
QTabWidget* tabs; ///< Tab widget
US_Disk_DB_Controls* dkdb_ctrl; ///< Disk/DB controls
// US_Disk_DB_Controls* dkdb_ctrl; ///< Disk/DB controls
US_Passwd pw; ///< Password object
US_DB2* dbCon; ///< Database connection

Expand Down
Loading

0 comments on commit 4400d2b

Please sign in to comment.