File: AlignmentParameters.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 (498 lines) | stat: -rw-r--r-- 14,749 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
/**
 * Changes:
 * Mark: 18-01-2007. Changed from using QFileDialog to FileDialog.
 *
 *
 */
#include <QPushButton>
#include <QGroupBox>
#include <QRadioButton>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QSizePolicy>
#include <QComboBox>
#include <QtWidgets>
#include <QLabel>
#include <QButtonGroup>
#include <QLineEdit>
#include <QHBoxLayout>
#include <cstring>
#include "AlignmentParameters.h"
#include "clustalW/general/userparams.h"
#include "clustalW/substitutionMatrix/globalmatrix.h"
#include "FileDialog.h"

AlignmentParameters::AlignmentParameters()
{   
    setWindowTitle("Alignment Parameters");
    proteinMatLoaded = false;
    dnaMatLoaded = false;
    
    paramGridBox = new QGroupBox;
    proteinMatGridBox = new QGroupBox(tr("Protein Weight Matrix"));
    dnaMatGridBox = new QGroupBox(tr("DNA Weight Matrix"));
    verticalBox = new QGroupBox(tr("Multiple Parameters"));
    mainLayout = new QVBoxLayout;
     
    okButton = new QPushButton(tr("OK"));
    okButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
    connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
    
    setUpLayout();
    
    mainLayout->addWidget(okButton);
    mainLayout->addWidget(verticalBox);
    setLayout(mainLayout);
}

void AlignmentParameters::showEvent(QShowEvent* event)
{
    setInitialProteinMat();
    setInitialDNAMat();
    setInitialParams();
}

void AlignmentParameters::setUpLayout()
{
    setUpOtherParams();
    grid = new QGridLayout; 
    grid->addWidget(gapOpenLabel, 0, 0);
    grid->addWidget(gapOpen, 0, 1);
    grid->addWidget(gapExtendLabel, 1, 0);
    grid->addWidget(gapExtend, 1, 1);
    grid->addWidget(delayDivergentLabel, 2, 0);
    grid->addWidget(delayDivergent, 2, 1);
    grid->addWidget(dnaTranWeightLabel, 3, 0);
    grid->addWidget(dnaTranWeight, 3, 1);
    grid->addWidget(useNegMatLabel, 4, 0);
    grid->addWidget(useNegMat, 4, 1);   
    paramGridBox->setLayout(grid);
   
    setUpProteinMatRadioButtons();
    protMatLayout = new QGridLayout; 
    protMatLayout->addWidget(blosum, 0, 0);
    protMatLayout->addWidget(pam, 0, 1);
    protMatLayout->addWidget(gonnet, 1, 0);
    protMatLayout->addWidget(identity, 1, 1);
    protMatLayout->addWidget(userProt, 0, 2);
    proteinMatGridBox->setLayout(protMatLayout);
   
    setUpDNAMatRadioButtons();
    dnaMatLayout = new QGridLayout; 
    dnaMatLayout->addWidget(IUB, 0, 0);
    dnaMatLayout->addWidget(clustal, 0, 1);
    dnaMatLayout->addWidget(userDNA, 0, 2);
    dnaMatGridBox->setLayout(dnaMatLayout); 

    setUpLoadButtons();                   
    multipleParamLayout = new QVBoxLayout;
    multipleParamLayout->addWidget(paramGridBox);
    multipleParamLayout->addWidget(proteinMatGridBox);
    multipleParamLayout->addWidget(loadProteinGroup);
    multipleParamLayout->addWidget(dnaMatGridBox);
    multipleParamLayout->addWidget(loadDNAGroup);
    verticalBox->setLayout(multipleParamLayout);     
}

void AlignmentParameters::setUpProteinMatRadioButtons()
{
    proteinMat = new QButtonGroup;
    proteinMat->setExclusive(true);
    blosum = new QRadioButton("BLOSUM series");
    pam = new QRadioButton("PAM series");
    gonnet = new QRadioButton("Gonnet series");
    identity = new QRadioButton("Identity matrix");
    userProt = new QRadioButton("User defined");

    connect(userProt, SIGNAL(clicked()), this, SLOT(userProteinClicked()));        
     
    proteinMat->addButton(blosum);
    proteinMat->addButton(pam);
    proteinMat->addButton(gonnet);
    proteinMat->addButton(identity);
    proteinMat->addButton(userProt);                   
}

void AlignmentParameters::setInitialProteinMat()
{
    if((clustalw::subMatrix->getMatrixNum() - 1) == clustalw::AABLOSUM)
    {
        blosum->setChecked(true);
    }
    else if((clustalw::subMatrix->getMatrixNum() - 1) == clustalw::AAPAM)
    {
        pam->setChecked(true);
    }
    else if((clustalw::subMatrix->getMatrixNum() - 1) == clustalw::AAGONNET)
    {
        gonnet->setChecked(true);
    }
    else if((clustalw::subMatrix->getMatrixNum() - 1) == clustalw::AAIDENTITY)
    {
        identity->setChecked(true);
    }
    else if((clustalw::subMatrix->getMatrixNum() - 1) == clustalw::AAUSERDEFINED)
    {
        userProt->setChecked(true);
    }
}

void AlignmentParameters::radioSetUsingUserProtein()
{
    userProt->setChecked(true);
    blosum->setChecked(false);
    pam->setChecked(false);
    gonnet->setChecked(false);
    identity->setChecked(false);
}

void AlignmentParameters::userProteinClicked()
{   
    if(!proteinMatLoaded)
    {
        browseProtein();
    }
}

void AlignmentParameters::setUpDNAMatRadioButtons()
{
    DNAMat = new QButtonGroup;
    DNAMat->setExclusive(true);
    IUB = new QRadioButton("IUB");
    clustal = new QRadioButton("CLUSTALW(1.6)");
    userDNA = new QRadioButton("User defined");

    connect(userDNA, SIGNAL(clicked()), this, SLOT(userDNAClicked()));
            
    DNAMat->addButton(IUB);
    DNAMat->addButton(clustal);
    DNAMat->addButton(userDNA);
}

void AlignmentParameters::setInitialDNAMat()
{
    if((clustalw::subMatrix->getDNAMatrixNum() - 1) == clustalw::DNAIUB)
    {
        IUB->setChecked(true);
    }
    else if((clustalw::subMatrix->getDNAMatrixNum() - 1) == clustalw::DNACLUSTALW)
    {
        clustal->setChecked(true);
    }
    else if((clustalw::subMatrix->getDNAMatrixNum() - 1) == clustalw::DNAUSERDEFINED)
    {
        userDNA->setChecked(true);
    }
}

void AlignmentParameters::userDNAClicked()
{
    if(!dnaMatLoaded)
    {
        browseDNA();
    }
}

void AlignmentParameters::setUpOtherParams()
{
    // Need to intialy set the parameters to be either DNA or protein.
    // Could be setting DNA if the alignment we read in is DNA.
    
    gapOpen = new QLineEdit;
    gapOpenLabel = new QLabel(tr("Gap Opening [0-100]: "));
    
    gapExtend = new QLineEdit;
    gapExtendLabel = new QLabel(tr("Gap Extension [0-100]: "));
    
    delayDivergent = new QLineEdit;    
    delayDivergentLabel = new QLabel(tr("Delay Divergent Sequences(%): "));
    
    dnaTranWeight = new QLineEdit;    
    dnaTranWeightLabel = new QLabel(tr("DNA Transition Weight[0-1] "));                 
    
    useNegMat = new QComboBox();
    useNegMat->addItem("Off");    
    useNegMat->addItem("On");
    useNegMatLabel = new QLabel(tr("Use Negative Matrix "));
    
    loadProtMat = new QPushButton(tr("Load protein matrix:"));
    loadProtMat->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    connect(loadProtMat, SIGNAL(clicked()), this, SLOT(browseProtein()));
    
    loadDNAMat = new QPushButton(tr("Load DNA matrix:"));
    loadDNAMat->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);    
    connect(loadDNAMat, SIGNAL(clicked()), this, SLOT(browseDNA()));
}


void AlignmentParameters::setInitialParams()
{
    if(clustalw::userParameters->getDNAFlag())
    {
        clustalw::userParameters->setDNAParams();
    }
    else
    {
        clustalw::userParameters->setProtParams();
    }
    
    QString num;
    num = num.setNum(clustalw::userParameters->getGapOpen());
    gapOpen->setText(num);
    
    num = num.setNum(clustalw::userParameters->getGapExtend());    
    gapExtend->setText(num);
    
    num = num.setNum(clustalw::userParameters->getDivergenceCutoff());    
    delayDivergent->setText(num);
    
    num = num.setNum(clustalw::userParameters->getTransitionWeight());    
    dnaTranWeight->setText(num);
    
    if(clustalw::userParameters->getUseNegMatrix())
    {
        useNegMat->setCurrentIndex(1);
    }
    else
    {
        useNegMat->setCurrentIndex(0);
    }
}

void AlignmentParameters::setUpLoadButtons()
{
    loadProteinGroup = new QGroupBox;
    horizLayoutAA = new QHBoxLayout; 
    userProteinMatrix = new QLabel("");
    horizLayoutAA->addWidget(loadProtMat);
    horizLayoutAA->addWidget(userProteinMatrix);
    loadProteinGroup->setLayout(horizLayoutAA); 

    loadDNAGroup = new QGroupBox;
    horizLayoutDNA = new QHBoxLayout;
    userDNAMatrix = new QLabel("");
    horizLayoutDNA->addWidget(loadDNAMat);
    horizLayoutDNA->addWidget(userDNAMatrix);
    loadDNAGroup->setLayout(horizLayoutDNA);
}

void AlignmentParameters::browseProtein()
{   
    // Mark Jan 18th 2007: changes to remember working Dir
    FileDialog fd;
    aaMatrixPath = fd.getOpenFileName(this, tr("Find Protein Matrix"));
                    
    string path = aaMatrixPath.toStdString();
                                   
    if(path != "")
    {
        int lenOfString = path.length();
        
        char* userFile = new char[lenOfString + 1];
        strcpy(userFile, path.c_str());
        
        if (clustalw::subMatrix->getUserMatFromFile(userFile, clustalw::Protein,
                                                    clustalw::MultipleAlign))
        {
            aaMatrixFile = string(userFile);
            proteinMatLoaded = true;
            userProteinMatrix->setText(aaMatrixFile.c_str());
            radioSetUsingUserProtein();           
        }
        else
        {
            aaMatrixFile = "";
            proteinMatLoaded = false;
            userProteinMatrix->setText(aaMatrixFile.c_str());
            setInitialProteinMat();                         
        }
        delete []userFile;
    }
    else // we pressed cancel
    {
        if(!proteinMatLoaded)
        {
            setInitialProteinMat();
        }
    }                                  
}

void AlignmentParameters::browseDNA()
{
    // Mark Jan 18th 2007: changes to remember working Dir
    FileDialog fd;
    dnaMatrixPath = fd.getOpenFileName(this, tr("Find DNA Matrix"));
               
    string path = dnaMatrixPath.toStdString();
                                   
    if(path != "")
    {
        int lenOfString = path.length();
        
        char* userFile = new char[lenOfString + 1];
        strcpy(userFile, path.c_str());
        
        if (clustalw::subMatrix->getUserMatFromFile(userFile, clustalw::DNA,
                                                    clustalw::MultipleAlign))
        {
            dnaMatrixFile = string(userFile);
            dnaMatLoaded = true;
            userDNAMatrix->setText(dnaMatrixFile.c_str());
            userDNA->setChecked(true);
        }
        else
        {
            dnaMatrixFile = "";
            dnaMatLoaded = false; 
            setInitialDNAMat();
            userDNAMatrix->setText(dnaMatrixFile.c_str());                        
        }
        delete []userFile;
    }
    else // we pressed cancel
    {
        if(!dnaMatLoaded)
        {
            setInitialDNAMat();
        }
    }                                       
}

void AlignmentParameters::accept()
{
    bool ok;
    // check _gapExtention
    QString gExtend = gapExtend->text();
    float extend;
    extend = gExtend.toFloat(&ok);   

    if(ok && extend >= 0.0 && extend <= 100.0)
    {
        if(clustalw::userParameters->getDNAFlag())
        {
            clustalw::userParameters->setDNAGapExtend(extend);
        }
        else
        {
            clustalw::userParameters->setAAGapExtend(extend);
        }
    }  
      
    // check _gapOpen
    QString gOpen = gapOpen->text();
    float open;
    open = gOpen.toFloat(&ok);   

    if(ok && open >= 0.0 && open <= 100.0)
    {
        if(clustalw::userParameters->getDNAFlag())
        {
            clustalw::userParameters->setDNAGapOpen(open);
        }
        else
        {
            clustalw::userParameters->setAAGapOpen(open);
        }
    }
        
    // check _delayDivSeq
    QString divPc = delayDivergent->text();
    int delay;
    delay = divPc.toInt(&ok);   

    if(ok && delay >= 0 && delay <= 100)
    {
        clustalw::userParameters->setDivergenceCutoff(delay);
    }
        
    // check _DNATranWeight
    QString tWeight = dnaTranWeight->text();
    float tranWeight;
    tranWeight = tWeight.toFloat(&ok);
    
    if(ok && tranWeight >= 0.0 && tranWeight <= 1.0)
    {
        clustalw::userParameters->setTransitionWeight(tranWeight);
    }

    // Protein Weight Matrix
    if(blosum->isChecked())
    {
        clustalw::subMatrix->setCurrentNameAndNum("blosum", 1, 
                                            clustalw::Protein, clustalw::MultipleAlign); 
    }
    else if(pam->isChecked())
    {
        clustalw::subMatrix->setCurrentNameAndNum("pam", 2, 
                                            clustalw::Protein, clustalw::MultipleAlign); 
    }
    else if(gonnet->isChecked())
    {
        clustalw::subMatrix->setCurrentNameAndNum("gonnet", 3, 
                                            clustalw::Protein, clustalw::MultipleAlign); 
    }
    else if(identity->isChecked())
    {
        clustalw::subMatrix->setCurrentNameAndNum("id", 4, 
                                            clustalw::Protein, clustalw::MultipleAlign); 
    }
    else if(userProt->isChecked())
    {
        if(aaMatrixFile != "")
        {
            clustalw::subMatrix->setCurrentNameAndNum(aaMatrixFile, 5, 
                                            clustalw::Protein, clustalw::MultipleAlign);
        }
        else // Set to a default if a problem with the 
        {
            clustalw::subMatrix->setCurrentNameAndNum("gonnet", 3, 
                                            clustalw::Protein, clustalw::MultipleAlign);   
        }    
    }

    // DNA matrix
    if(IUB->isChecked())
    {
        clustalw::subMatrix->setCurrentNameAndNum("iub", 1, clustalw::DNA,
                                                  clustalw::MultipleAlign);
    }
    else if(clustal->isChecked())
    {
        clustalw::subMatrix->setCurrentNameAndNum("clustalw", 2, clustalw::DNA,
                                                  clustalw::MultipleAlign);
    }
    else if(userDNA->isChecked())
    {
        if(dnaMatrixFile != "")
        {
            clustalw::subMatrix->setCurrentNameAndNum(dnaMatrixFile, 3, 
                                                    clustalw::DNA, clustalw::MultipleAlign);
        }
        else // Set it to the default
        {
            clustalw::subMatrix->setCurrentNameAndNum("iub", 1, clustalw::DNA,
                                                  clustalw::MultipleAlign);
        }
    }
    if(useNegMat->currentIndex() == 1)
    {
        clustalw::userParameters->setUseNegMatrix(true);   
    }
    else
    {
        clustalw::userParameters->setUseNegMatrix(false);    
    }
    
    // NOTE it is important to set the parameters here.
    if(clustalw::userParameters->getDNAFlag())
    {
        clustalw::userParameters->setDNAParams();
    }
    else
    {
        clustalw::userParameters->setProtParams();
    }                    
    setResult(QDialog::Accepted);
    hide();
}