File: BootstrapTreeDialog.cpp

package info (click to toggle)
clustalx 2.1%2Blgpl-8
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,320 kB
  • sloc: cpp: 40,050; sh: 163; xml: 102; makefile: 16
file content (266 lines) | stat: -rw-r--r-- 7,678 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/**
 * Changes:
 * Mark: 18-01-2007. Changed from using QFileDialog to FileDialog.
 *
 * 12-4-07, Mark Larkin, Removed destructor. No need to delete QObjects. Also removed
 * setAllPtrsToNull function. 
 */
#include <QPushButton>
#include <QGroupBox>
#include <QCheckBox>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QSizePolicy>
#include <QComboBox>
#include <QtWidgets>
#include <QLabel>
#include <iostream>
#include "BootstrapTreeDialog.h"
#include "clustalW/general/userparams.h"
#include "clustalW/general/utils.h"
#include "ClustalQtParams.h"
#include "FileDialog.h"

BootstrapTreeDialog::BootstrapTreeDialog(QString seqFileName)
{    
    setAllPtrsToNull();
    
    title = "Draw Tree";
        
    setWindowTitle(title);
    
    filePath = getPathFromFileName(seqFileName);
    
    mainLayout = new QVBoxLayout;
     
    okButton = new QPushButton(tr("OK"));
    okButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
    connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
    bootstrapCancelButton = new QPushButton(tr("Cancel"));
    bootstrapCancelButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
    connect(bootstrapCancelButton, SIGNAL(clicked()), this, SLOT(cancel()));        
    
    fileBox = new QGroupBox();
    
    setUpLayout();
    mainLayout->addWidget(fileBox);
    setLayout(mainLayout);
        
}

QString BootstrapTreeDialog::getPathFromFileName(QString fileName)
{
    QString filePath;
    if(fileName.size() > 0)
    {
        std::string path = "";
        clustalw::utilityObject->getPath(fileName.toStdString(), &path);
        
        if(path.size() > 0)
        {
            filePath = QString(path.c_str());
        }
        else
        {
           filePath = QDir::currentPath() + QString(QDir::separator()) + "temp";
        }
    }
    return filePath;
}

void BootstrapTreeDialog::setUpLayout()
{
    int row = 0;
    fileLayout = new QGridLayout;
    QString numStr;
    int num;
    
    randomNumberGenSeedLabel = new QLabel(tr("Random number generator seed[1-1000]: "));
    randomNumberGenSeed = new QLineEdit();
    num = clustalw::userParameters->getBootRanSeed();
    numStr.setNum(num);
    randomNumberGenSeed->setText(numStr);
    fileLayout->addWidget(randomNumberGenSeedLabel, row, 0);
    fileLayout->addWidget(randomNumberGenSeed, row, 1);    
    row++;
    
    numBootstrapTrialsLabel = new QLabel(tr("Number of bootstrap trials[1-10000]: "));
    numBootstrapTrials = new QLineEdit();
    num = clustalw::userParameters->getBootNumTrials();
    numStr.setNum(num);
    numBootstrapTrials->setText(numStr);
    fileLayout->addWidget(numBootstrapTrialsLabel, row, 0);
    fileLayout->addWidget(numBootstrapTrials, row, 1);    
    row++;
       
    if(clustalw::userParameters->getOutputTreeClustal())
    {
        clustalTreeNameLabel = new QLabel(tr("Save Clustal tree as: "));
        clustalTreeName = new QLineEdit();
        clustalTreeName->setText(filePath + "njb");
        clustalTreeName->setMinimumWidth(MinLineEditWidth);
        clustalTreeBrowseButton = new QPushButton("Browse");
        connect(clustalTreeBrowseButton, SIGNAL(clicked()), this, SLOT(browseClustal()));
        fileLayout->addWidget(clustalTreeNameLabel, row, 0);
        fileLayout->addWidget(clustalTreeName, row, 1);
        fileLayout->addWidget(clustalTreeBrowseButton, row, 2);
        row++;
    }
    if(clustalw::userParameters->getOutputTreePhylip())
    {
        phylipTreeNameLabel = new QLabel(tr("Save Phylip tree as: "));
        phylipTreeName = new QLineEdit();
        phylipTreeName->setText(filePath + "phb");
        phylipTreeName->setMinimumWidth(MinLineEditWidth);
        phylipTreeBrowseButton = new QPushButton("Browse");
        connect(phylipTreeBrowseButton, SIGNAL(clicked()), this, SLOT(browsePhylip()));
        fileLayout->addWidget(phylipTreeNameLabel, row, 0);
        fileLayout->addWidget(phylipTreeName, row, 1);
        fileLayout->addWidget(phylipTreeBrowseButton, row, 2);
        row++;    
    }
    if(clustalw::userParameters->getOutputTreeNexus())
    {
        nexusTreeNameLabel = new QLabel(tr("Save Nexus tree as: "));
        nexusTreeName = new QLineEdit();
        nexusTreeName->setText(filePath + "treb");
        nexusTreeName->setMinimumWidth(MinLineEditWidth);
        nexusTreeBrowseButton = new QPushButton("Browse");
        connect(nexusTreeBrowseButton, SIGNAL(clicked()), this, SLOT(browseNexus()));
        fileLayout->addWidget(nexusTreeNameLabel, row, 0);
        fileLayout->addWidget(nexusTreeName, row, 1);
        fileLayout->addWidget(nexusTreeBrowseButton, row, 2);
        row++;     
    }
    fileLayout->addWidget(okButton, row, 0);
    fileLayout->addWidget(bootstrapCancelButton, row, 1);
    fileBox->setLayout(fileLayout);
}

void BootstrapTreeDialog::browseClustal()
{
    browse(clustalTreeName);
}

void BootstrapTreeDialog::browseNexus()
{
    browse(nexusTreeName);
}

void BootstrapTreeDialog::browsePhylip()
{
    browse(phylipTreeName);
}

void BootstrapTreeDialog::accept()
{
    bool ok;
    int num;
    QString randomNumSeed = randomNumberGenSeed->text();
    num = randomNumSeed.toInt(&ok);
    if(ok)
    {
        if(num >= 1 && num <= 1000)
        {
            clustalw::userParameters->setBootRanSeed(num);
        }
    }
    
    QString numTrials = numBootstrapTrials->text();
    num = numTrials.toInt(&ok);
    if(ok)
    {
        if(num >= 1 && num <= 10000)
        {
            clustalw::userParameters->setBootNumTrials(num);
        }
    }
        
    treeFileNames.reset(new clustalw::TreeNames);
    if(clustalTreeName != 0)
    {
        if(clustalTreeName->text() == "")
        {
            treeFileNames->clustalName = filePath.toStdString() + "njb";
        }
        else
        {
            QString file = clustalTreeName->text(); 
            treeFileNames->clustalName = file.toStdString();
        }    
    }
    if(phylipTreeName != 0)
    {
        if(phylipTreeName->text() == "")
        {
            treeFileNames->phylipName = filePath.toStdString() + "phb";
        }
        else
        {
            QString file = phylipTreeName->text(); 
            treeFileNames->phylipName = file.toStdString();
        }    
    }    

    if(nexusTreeName != 0)
    {
        if(nexusTreeName->text() == "")
        {
            treeFileNames->nexusName = filePath.toStdString() + "treb";
        }
        else
        {
            QString file = nexusTreeName->text(); 
            treeFileNames->nexusName = file.toStdString();
        }    
    }  
                       
    setResult(QDialog::Accepted);
    hide();
}

void BootstrapTreeDialog::cancel()
{
    setResult(QDialog::Rejected);
    hide();
}

void BootstrapTreeDialog::browse(QLineEdit* lineEditName)
{
    QString myFile;
    // Mark Jan 18th 2007: changes to remember working Dir    
    FileDialog fd;
    myFile = fd.getSaveFileName(this, tr("Save as"));
    
    if(myFile != "")
    {
        lineEditName->setText(myFile);
    }
}

clustalw::TreeNames BootstrapTreeDialog::getNames()
{
    return *(treeFileNames.get());
}

void BootstrapTreeDialog::setAllPtrsToNull()
{
    nexusTreeBrowseButton = 0;
    nexusTreeName = 0;
    nexusTreeNameLabel = 0;
    phylipTreeBrowseButton = 0;
    phylipTreeName = 0;
    phylipTreeNameLabel = 0;
    clustalTreeBrowseButton = 0;
    clustalTreeName = 0;
    clustalTreeNameLabel = 0;
    numBootstrapTrials = 0;
    numBootstrapTrialsLabel = 0;
    randomNumberGenSeed = 0;
    randomNumberGenSeedLabel = 0;
    bootstrapCancelButton = 0;
    okButton = 0;
    fileLayout = 0;
    fileBox = 0;
    mainLayout = 0;
}