488 lines
15 KiB
C++
488 lines
15 KiB
C++
#include "createdialogs.h"
|
||
#include "limits.h"
|
||
#include <QPushButton>
|
||
#include <QLabel>
|
||
#include <QGridLayout>
|
||
#include <qmath.h>
|
||
#include <QGroupBox>
|
||
#include <QVBoxLayout>
|
||
#include "DEC-0.0/processor/Settings.h"
|
||
#include "DEC-0.0/DerevyankoReport2014.h"
|
||
#include "DEC-0.0/DerevyankoReport.h"
|
||
#include <string>
|
||
#include <vector>
|
||
|
||
|
||
CreateDialogs::CreateDialogs(QWidget *parent, int flag, QString winLabel) :
|
||
QDialog(parent)
|
||
{
|
||
locisNum = 0;
|
||
winFlag = 0;
|
||
if (flag == 1)
|
||
{
|
||
createChooseModelDialog();
|
||
}
|
||
if (flag == 2)
|
||
{
|
||
winFlag = 2;
|
||
createDerReport2014SettingDialog(winLabel);
|
||
}
|
||
if (flag == 3)
|
||
{
|
||
winFlag = 3;
|
||
createDerReport2014SettingDialog(winLabel);
|
||
}
|
||
if (flag == 4)
|
||
{
|
||
winFlag = 4;
|
||
createDerReport2014SettingDialog(winLabel);
|
||
}
|
||
if (flag == 5)
|
||
{
|
||
winFlag = 5;
|
||
createDerReport2014SettingDialog(winLabel);
|
||
}
|
||
if (flag == 6)
|
||
{
|
||
createDerReportSettingDialog();
|
||
}
|
||
if (flag == 7)
|
||
{
|
||
createBreedSettingsDialog();
|
||
}
|
||
|
||
}
|
||
|
||
void CreateDialogs::createChooseModelDialog()
|
||
{
|
||
QGridLayout *layout = new QGridLayout(this);
|
||
QGroupBox *modelGBox = new QGroupBox("Models");
|
||
layout->addWidget(modelGBox, 0, 0);
|
||
|
||
derevyankoReport2014_button = new QRadioButton("DerevyankoReport2014_01");
|
||
derevyankoReportRFBR2013_01_button = new QRadioButton("DerevyankoReportRFBR2013_01");
|
||
KolchShindyalov_button = new QRadioButton("KolchShindyalov");
|
||
inOutBreeding01_button = new QRadioButton("InOutBreeding01");
|
||
agressor_button = new QRadioButton("Agressor-Protector");
|
||
|
||
QVBoxLayout *groupLayout = new QVBoxLayout;
|
||
modelGBox->setLayout(groupLayout);
|
||
groupLayout->addWidget(derevyankoReport2014_button, 0, 0);
|
||
groupLayout->addWidget(derevyankoReportRFBR2013_01_button, 1, 0);
|
||
groupLayout->addWidget(KolchShindyalov_button, 2, 0);
|
||
groupLayout->addWidget(inOutBreeding01_button, 3, 0);
|
||
groupLayout->addWidget(agressor_button, 4, 0);
|
||
|
||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||
layout->addLayout(buttonLayout, 1, 0, 1, 1);
|
||
buttonLayout->addStretch();
|
||
|
||
QPushButton *cancelButton = new QPushButton(tr("Cancel"));
|
||
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
|
||
buttonLayout->addWidget(cancelButton);
|
||
QPushButton *okButton = new QPushButton(tr("OK"));
|
||
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
|
||
buttonLayout->addWidget(okButton);
|
||
|
||
okButton->setDefault(true);
|
||
|
||
}
|
||
|
||
void CreateDialogs::createBreedSettingsDialog()
|
||
{
|
||
QGridLayout *layout = new QGridLayout(this);
|
||
layout->addWidget(new QLabel(tr("Max Generations:")), 0, 0);
|
||
maxGen_Spin = new QSpinBox();
|
||
maxGen_Spin->setRange(0, 1000000);
|
||
maxGen_Spin->setSingleStep(100);
|
||
maxGen_Spin->setValue(10);
|
||
layout->addWidget(maxGen_Spin, 0, 1);
|
||
layout->addWidget(new QLabel(tr("Init Pop Size:")), 1, 0);
|
||
initPopSize_Spin = new QSpinBox();
|
||
initPopSize_Spin->setRange(0, 1000000);
|
||
initPopSize_Spin->setSingleStep(100);
|
||
initPopSize_Spin->setValue(10);
|
||
layout->addWidget(initPopSize_Spin, 1, 1);
|
||
layout->addWidget(new QLabel(tr("RatioBetweenPops:")), 2, 0);
|
||
ratioBetweenPops_doubleSpin = new QDoubleSpinBox();
|
||
ratioBetweenPops_doubleSpin->setRange(0, 100);
|
||
ratioBetweenPops_doubleSpin->setSingleStep(1.0);
|
||
ratioBetweenPops_doubleSpin->setValue(1.0);
|
||
layout->addWidget(ratioBetweenPops_doubleSpin, 2, 1);
|
||
layout->addWidget(new QLabel(tr("MaxIndivids:")), 3, 0);
|
||
maxIndivid_Spin = new QSpinBox();
|
||
maxIndivid_Spin->setRange(0, 10000000);
|
||
maxIndivid_Spin->setSingleStep(1000);
|
||
maxIndivid_Spin->setValue(10000);
|
||
layout->addWidget(maxIndivid_Spin, 3, 1);
|
||
layout->addWidget(new QLabel(tr("Range:")), 4, 0);
|
||
range_Spin = new QSpinBox();
|
||
range_Spin->setRange(0, 10000000);
|
||
range_Spin->setSingleStep(100);
|
||
range_Spin->setValue(1000);
|
||
layout->addWidget(range_Spin, 4, 1);
|
||
layout->addWidget(new QLabel(tr("Precision:")), 5, 0);
|
||
precision_Spin = new QSpinBox();
|
||
precision_Spin->setRange(0, 10000000);
|
||
precision_Spin->setSingleStep(10);
|
||
precision_Spin->setValue(10);
|
||
layout->addWidget(precision_Spin, 5, 1);
|
||
|
||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||
layout->addLayout(buttonLayout, 6, 1, 1, 1);
|
||
buttonLayout->addStretch();
|
||
|
||
QPushButton *cancelButton = new QPushButton(tr("Cancel"));
|
||
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
|
||
buttonLayout->addWidget(cancelButton);
|
||
QPushButton *okButton = new QPushButton(tr("OK"));
|
||
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
|
||
buttonLayout->addWidget(okButton);
|
||
|
||
okButton->setDefault(true);
|
||
|
||
|
||
|
||
}
|
||
|
||
void CreateDialogs::createDerReportSettingDialog()
|
||
{
|
||
QGridLayout *layout = new QGridLayout(this);
|
||
layout->addWidget(new QLabel(tr("Pop_name:")), 1, 0);
|
||
popNameEditLine = new QLineEdit();
|
||
layout->addWidget(popNameEditLine, 1, 1);
|
||
layout->addWidget(new QLabel(tr("Pop_founder:")), 2, 0);
|
||
founderSpinBox = new QDoubleSpinBox();
|
||
founderSpinBox->setRange(0, 100);
|
||
founderSpinBox->setSingleStep(0.1);
|
||
founderSpinBox->setValue(0.1);
|
||
layout->addWidget(founderSpinBox, 2, 1);
|
||
layout->addWidget(new QLabel(tr("Separate from:")), 3, 0);
|
||
popNames = new QComboBox();
|
||
for (int i = 0; i < DerevyankoReport::populNames.size(); i++)
|
||
{
|
||
popNames->addItem(DerevyankoReport::populNames.at(i), QVariant(i));
|
||
}
|
||
layout->addWidget(popNames, 3, 1);
|
||
// layout->addWidget(new QLabel(tr("Evolution_time:")), 4, 0);
|
||
// evol_time = new QSpinBox();
|
||
// evol_time->setRange(0, 1000000);
|
||
// evol_time->setSingleStep(100);
|
||
// evol_time->setValue(1000);
|
||
// layout->addWidget(evol_time, 4, 1);
|
||
|
||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||
layout->addLayout(buttonLayout, 4, 1, 1, 1);
|
||
buttonLayout->addStretch();
|
||
|
||
QPushButton *cancelButton = new QPushButton(tr("Cancel"));
|
||
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
|
||
buttonLayout->addWidget(cancelButton);
|
||
QPushButton *okButton = new QPushButton(tr("OK"));
|
||
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
|
||
buttonLayout->addWidget(okButton);
|
||
|
||
okButton->setDefault(true);
|
||
|
||
|
||
}
|
||
|
||
void CreateDialogs::createDerReport2014SettingDialog(QString winLabel)
|
||
{
|
||
QGridLayout *layout = new QGridLayout(this);
|
||
QLabel *winLb = new QLabel();
|
||
winLb->setText(winLabel);
|
||
layout->addWidget(new QLabel(tr("Initial parameters for - ")), 0, 0);
|
||
layout->addWidget(winLb, 0, 1);
|
||
layout->addWidget(new QLabel(tr("Num Loci:")), 1, 0);
|
||
numLociSpin = new QSpinBox();
|
||
numLociSpin->setRange(1, 100);
|
||
numLociSpin->setSingleStep(1);
|
||
numLociSpin->setValue(1);
|
||
layout->addWidget(numLociSpin, 1, 1);
|
||
layout->addWidget(new QLabel(tr("Male/Female pop size:")), 2, 0);
|
||
sexNumSpin = new QSpinBox();
|
||
sexNumSpin->setRange(0, 1000000);
|
||
sexNumSpin->setSingleStep(1000);
|
||
sexNumSpin->setValue(5000);
|
||
layout->addWidget(sexNumSpin, 2, 1);
|
||
layout->addWidget(new QLabel(tr("Use default init sequence:")), 3, 0);
|
||
QPushButton *defaultButton = new QPushButton(tr("Default"));
|
||
connect(defaultButton, SIGNAL(clicked()), this, SLOT(preprocessScript()));
|
||
layout->addWidget(defaultButton, 3, 1);
|
||
layout->addWidget(new QLabel(tr("percentDiffLoci:")), 4, 0);
|
||
perDiffLociSpin = new QDoubleSpinBox();
|
||
layout->addWidget(perDiffLociSpin, 4, 1);
|
||
perDiffLociSpin->setRange(0, 100);
|
||
perDiffLociSpin->setSingleStep(0.1);
|
||
perDiffLociSpin->setValue(0.1);
|
||
|
||
layout->addWidget(new QLabel(tr("Locis:")), 5, 0);
|
||
locisLinesArea = new QScrollArea();
|
||
gBoxLayout = new QVBoxLayout();
|
||
layout->addWidget(locisLinesArea, 5, 1);
|
||
|
||
geneSeqEditLine = new QLineEdit();
|
||
gBoxLayout->addWidget(geneSeqEditLine, 0, 0);
|
||
geneSeqEditLine->setMinimumWidth(450);
|
||
|
||
QWidget *containerWidget=new QWidget;
|
||
containerWidget->setLayout(gBoxLayout);
|
||
locisLinesArea->setWidgetResizable(true);
|
||
locisLinesArea->setWidget(containerWidget);
|
||
|
||
connect(numLociSpin, SIGNAL(valueChanged(int)), this, SLOT(addLociLine()));
|
||
|
||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||
layout->addLayout(buttonLayout, 6, 1, 1, 1);
|
||
buttonLayout->addStretch();
|
||
|
||
QPushButton *cancelButton = new QPushButton(tr("Cancel"));
|
||
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
|
||
buttonLayout->addWidget(cancelButton);
|
||
QPushButton *okButton = new QPushButton(tr("OK"));
|
||
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
|
||
buttonLayout->addWidget(okButton);
|
||
|
||
okButton->setDefault(true);
|
||
|
||
|
||
}
|
||
|
||
void CreateDialogs::addLociLine()
|
||
{
|
||
locisNum = numLociSpin->text().toInt();
|
||
locisEditLines.clear();
|
||
clearLayout(gBoxLayout);
|
||
for (int i = 0; i < locisNum; i++)
|
||
{
|
||
locisEditLines.push_back(new QLineEdit());
|
||
gBoxLayout->addWidget(locisEditLines[i], 0, 0);
|
||
|
||
}
|
||
}
|
||
|
||
void CreateDialogs::preprocessScript()
|
||
{
|
||
|
||
if (winFlag == 2)
|
||
{
|
||
Settings::calcScript = DerevyankoReport2014::parseScript("script.txt");
|
||
|
||
int numLoci = Settings::numLoci;
|
||
Settings::initMtDNA.resize(numLoci);
|
||
Settings::initMtDNA_ancient.resize(numLoci);
|
||
for(unsigned int i = 0; i < Settings::initMtDNA.size(); i++){
|
||
Settings::initMtDNA.at(i) = DerevyankoReport2014::getInitGene(0,i);
|
||
|
||
if(i<= numLoci*Settings::percentDiffLoci){
|
||
std::string seq = Settings::initMtDNA.at(i);
|
||
for(int j = 0; j < 5; j++){
|
||
int pos = (int)(j/5.*Settings::locusLength);
|
||
if(seq.at(pos)=='T')
|
||
seq.replace(pos,1,"G");
|
||
else
|
||
seq.replace(pos,1,"T");
|
||
}
|
||
Settings::initMtDNA_ancient.at(i) = seq;
|
||
}
|
||
else{
|
||
Settings::initMtDNA_ancient.at(i) = Settings::initMtDNA.at(i);
|
||
}
|
||
}
|
||
numLociSpin->setValue(Settings::numLoci);
|
||
sexNumSpin->setValue(Settings::PopulationHomoInitSize);
|
||
perDiffLociSpin->setValue(Settings::percentDiffLoci);
|
||
for (int i = 0; i < Settings::numLoci; i++)
|
||
{
|
||
locisEditLines[i]->setText(QString::fromStdString(Settings::initMtDNA.at(i)));
|
||
}
|
||
}
|
||
else if (winFlag == 3)
|
||
{
|
||
numLociSpin->setValue(Settings::numLoci);
|
||
sexNumSpin->setValue(Settings::PopulationAncientInitSize);
|
||
perDiffLociSpin->setValue(Settings::percentDiffLoci);
|
||
for (int i = 0; i < Settings::numLoci; i++)
|
||
{
|
||
locisEditLines[i]->setText(QString::fromStdString(Settings::initMtDNA_ancient.at(i)));
|
||
}
|
||
}
|
||
else if (winFlag == 4)
|
||
{
|
||
DerevyankoReport::initMtDNA = "TTCTTTCATGGGGAAGCAGATTTGGGTACCACCCAAGTATTGACTCACCCATCAACAACC";
|
||
DerevyankoReport::initMtDNA += "GCTATGTATTTCGTACATTACTGCCAGCCACCATGAATATTGTACGGTACCATAAATACT";
|
||
DerevyankoReport::initMtDNA += "TGACCACCTGTAGTACATAAAAACCCAATCCACATCAAAACCCCCCCCTCATGCTTACAA";
|
||
DerevyankoReport::initMtDNA += "GCAAGTACAGCAATCAACCTTCAACTATCACACATCAACTGCAACTCCAAAGCCACCCCT";
|
||
DerevyankoReport::initMtDNA += "CACCCACTAGGATATCAACAAACCTACCCATCCTTAACAGTACATGGTACATAAAGCCAT";
|
||
DerevyankoReport::initMtDNA += "TTACCGTACATAGCACATTACAGTCAAATCCCTTCTCGTCCCCATGGATGACCCCCCTCA";
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> G)
|
||
DerevyankoReport::initMtDNA_G = DerevyankoReport::initMtDNA;
|
||
DerevyankoReport::initMtDNA_G.replace(60,1,"T");
|
||
DerevyankoReport::initMtDNA_G.replace(120,1,"A");
|
||
DerevyankoReport::initMtDNA_G.replace(180,1,"C");
|
||
DerevyankoReport::initMtDNA_G.replace(240,1,"G");
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
//
|
||
DerevyankoReport::basePopSize = 5000;
|
||
DerevyankoReport::initBirthRate = 0.25f;
|
||
DerevyankoReport::deltaBirthRate = 0.0002f;
|
||
numLociSpin->setValue(6);
|
||
sexNumSpin->setValue(DerevyankoReport::basePopSize);
|
||
for (int i = 0; i < 6; i++)
|
||
{
|
||
locisEditLines[i]->setText(QString::fromStdString(DerevyankoReport::initMtDNA.substr(60 * i, 60)));
|
||
}
|
||
}
|
||
else if (winFlag == 5)
|
||
{
|
||
DerevyankoReport::basePopSize = 5000;
|
||
DerevyankoReport::initBirthRate = 0.25f;
|
||
DerevyankoReport::deltaBirthRate = 0.0002f;
|
||
numLociSpin->setValue(6);
|
||
sexNumSpin->setValue(DerevyankoReport::basePopSize);
|
||
for (int i = 0; i < 6; i++)
|
||
{
|
||
locisEditLines[i]->setText(QString::fromStdString(DerevyankoReport::initMtDNA_G.substr(60 * i, 60)));
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
void CreateDialogs::clearLayout(QLayout *layout)
|
||
{
|
||
if (layout != NULL)
|
||
{
|
||
QLayoutItem* item;
|
||
while ((item = layout->takeAt(0)) != NULL)
|
||
{
|
||
delete item->widget();
|
||
delete item;
|
||
}
|
||
}
|
||
}
|
||
|
||
int CreateDialogs::getMaxGen()
|
||
{
|
||
return maxGen_Spin->value();
|
||
}
|
||
|
||
int CreateDialogs::getInitPopSize()
|
||
{
|
||
return initPopSize_Spin->value();
|
||
}
|
||
|
||
double CreateDialogs::getBetweenRatio()
|
||
{
|
||
return ratioBetweenPops_doubleSpin->value();
|
||
}
|
||
|
||
int CreateDialogs::getMaxIndivids()
|
||
{
|
||
return maxIndivid_Spin->value();
|
||
}
|
||
|
||
int CreateDialogs::getRange()
|
||
{
|
||
return range_Spin->value();
|
||
}
|
||
|
||
int CreateDialogs::getPrecision()
|
||
{
|
||
return precision_Spin->value();
|
||
}
|
||
|
||
QString CreateDialogs::getPopName()
|
||
{
|
||
return popNameEditLine->text();
|
||
}
|
||
|
||
double CreateDialogs::getFounderVal()
|
||
{
|
||
return founderSpinBox->value();
|
||
}
|
||
|
||
int CreateDialogs::getSepPopInd()
|
||
{
|
||
return popNames->itemData(popNames->currentIndex()).toInt();
|
||
}
|
||
|
||
int CreateDialogs::getEvolTime()
|
||
{
|
||
return evol_time->value();
|
||
}
|
||
|
||
bool CreateDialogs::checkPopName()
|
||
{
|
||
return popNameEditLine->text().isEmpty();
|
||
}
|
||
|
||
bool CreateDialogs::checkLoci() //ToDo: add more conditions
|
||
{
|
||
return (locisEditLines.size() == 0);
|
||
}
|
||
|
||
int CreateDialogs::getNumLociVal()
|
||
{
|
||
return numLociSpin->value();
|
||
}
|
||
|
||
int CreateDialogs::getSizeNum()
|
||
{
|
||
return sexNumSpin->value();
|
||
}
|
||
|
||
double CreateDialogs::getPerDiffLoci()
|
||
{
|
||
return perDiffLociSpin->value();
|
||
}
|
||
|
||
std::vector<std::string> CreateDialogs::getInitHomoGen()
|
||
{
|
||
std::vector<std::string> genVect;
|
||
for (int i = 0; i < Settings::numLoci; i++)
|
||
{
|
||
genVect.push_back(locisEditLines[i]->text().toLocal8Bit().constData());
|
||
}
|
||
return genVect;
|
||
}
|
||
|
||
std::vector<std::string> CreateDialogs::getInitAncientGen()
|
||
{
|
||
std::vector<std::string> genVect;
|
||
for (int i = 0; i < Settings::numLoci; i++)
|
||
{
|
||
genVect.push_back(locisEditLines[i]->text().toLocal8Bit().constData());
|
||
}
|
||
return genVect;
|
||
}
|
||
|
||
bool CreateDialogs::checkDerRep2014_button()
|
||
{
|
||
return derevyankoReport2014_button->isChecked();
|
||
}
|
||
|
||
bool CreateDialogs::checkDerRepRFBR_button()
|
||
{
|
||
return derevyankoReportRFBR2013_01_button->isChecked();
|
||
}
|
||
|
||
bool CreateDialogs::checkKolch_button()
|
||
{
|
||
return KolchShindyalov_button->isChecked();
|
||
}
|
||
|
||
bool CreateDialogs::checkInOutBreed_bitton()
|
||
{
|
||
return inOutBreeding01_button->isChecked();
|
||
}
|
||
|
||
bool CreateDialogs::checkAgressor_button()
|
||
{
|
||
return agressor_button->isChecked();
|
||
}
|