~ubuntu-branches/ubuntu/karmic/kboincspy/karmic

« back to all changes in this revision

Viewing changes to src/monitors/predictor/predictordata.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Frank S. Thomas
  • Date: 2005-03-31 12:33:43 UTC
  • Revision ID: james.westby@ubuntu.com-20050331123343-37fm35635duf506y
Tags: upstream-0.9.0
ImportĀ upstreamĀ versionĀ 0.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2005 by Roberto Virga                                   *
 
3
 *   rvirga@users.sf.net                                                   *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 *   This program is distributed in the hope that it will be useful,       *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
 *   GNU General Public License for more details.                          *
 
14
 *                                                                         *
 
15
 *   You should have received a copy of the GNU General Public License     *
 
16
 *   along with this program; if not, write to the                         *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
19
 ***************************************************************************/
 
20
 
 
21
#include <qregexp.h>
 
22
 
 
23
#include "predictordata.h"
 
24
 
 
25
const QString PredictorAminoAcidName[] =
 
26
  {"GLY", "ALA", "SER", "CYS", "VAL", "THR", "ILE", "PRO", "MET", "ASP",
 
27
   "ASN", "LEU", "LYS", "GLU", "GLN", "ARG", "HIS", "PHE", "TYR", "TRP",
 
28
   "???"};
 
29
 
 
30
const char PredictorAminoAcidAbbrev[] =
 
31
  {'G', 'A', 'S', 'C', 'V', 'T', 'I', 'P', 'M', 'D',
 
32
   'N', 'L', 'K', 'E', 'Q', 'R', 'H', 'F', 'Y', 'W',
 
33
   '?'};
 
34
 
 
35
const unsigned PredictorAminoAcidAtoms[] =
 
36
  {4, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 9, 9, 9, 11, 10, 11, 12, 14, 0};
 
37
 
 
38
/*
 
39
const double PredictorAminoAcidMass[] =
 
40
  { 75.07, 89.09, 105.09, 121.16, 117.15, 119.12, 131.17, 115.13, 149.21, 133.10,
 
41
    132.12, 131.17, 146.19, 147.13, 146.15, 174.20, 155.16, 165.19, 181.19, 204.23,
 
42
    0.0};
 
43
*/
 
44
 
 
45
bool parseAminoAcid(const QString &name, PredictorAminoAcid &aa)
 
46
{
 
47
  for(unsigned i = 0; i < AminoAcids; ++i)
 
48
    if(PredictorAminoAcidName[i] == name) {
 
49
      aa = PredictorAminoAcid(i);
 
50
      return true;
 
51
    }
 
52
 
 
53
  return false;
 
54
 
55
 
 
56
QValueList<uint> parseUIntList(const QString &text)
 
57
{
 
58
  QStringList list = QStringList::split(" ", text);
 
59
  QValueList<uint> out;
 
60
  
 
61
  for(QStringList::const_iterator it = list.constBegin(); list.constEnd() != it; ++it)
 
62
    out << (*it).toUInt(0, 10);
 
63
    
 
64
  return out;
 
65
}
 
66
 
 
67
QValueList<double> parseDoubleList(const QString &text)
 
68
{
 
69
  QStringList list = QStringList::split(" ", text);
 
70
  QValueList<double> out;
 
71
  
 
72
  for(QStringList::const_iterator it = list.constBegin(); list.constEnd() != it; ++it)
 
73
    out << (*it).toDouble();
 
74
    
 
75
  return out;
 
76
}
 
77
 
 
78
bool PredictorBurials::parse(const QStringList &lines)
 
79
{
 
80
  QStringList::const_iterator line = lines.constBegin();
 
81
  
 
82
  if(lines.constEnd() == line
 
83
  || !(*line).contains("Average percentage of burial")) return false;
 
84
  ++line;
 
85
  
 
86
  // skip header
 
87
  if(lines.constEnd() == line) return false;
 
88
  ++line;
 
89
  
 
90
  // parse table
 
91
  for(unsigned row = 0; row <= AminoAcids; ++row)
 
92
  {
 
93
    if(lines.constEnd() == line) return false;
 
94
    
 
95
    QValueList<double> values = parseDoubleList((*line).mid(4));
 
96
    if(values.count() != AminoAcids+1)  return false;
 
97
     
 
98
    for(unsigned column = 0; column <= AminoAcids; ++column)
 
99
      avg[row][column] = values[column];
 
100
                
 
101
    ++line;
 
102
  }
 
103
  
 
104
  if(lines.constEnd() == line 
 
105
  || !(*line).contains("Average standard deviation of burial")) return false;
 
106
  ++line;
 
107
  
 
108
  // skip header
 
109
  if(lines.constEnd() == line) return false;
 
110
  ++line;
 
111
  
 
112
  // parse table
 
113
  for(unsigned row = 0; row <= AminoAcids; ++row)
 
114
  {
 
115
    if(lines.constEnd() == line) return false;
 
116
    
 
117
    QValueList<double> values = parseDoubleList((*line).mid(4));
 
118
    if(values.count() != AminoAcids+1)  return false;
 
119
        
 
120
    for(unsigned column = 0; column <= AminoAcids; ++column)
 
121
      sdev[row][column] = values[column];
 
122
                
 
123
    ++line;
 
124
  }
 
125
    
 
126
  if(lines.constEnd() == line 
 
127
  || !(*line).contains("Number of pairs used")) return false;
 
128
  ++line; if(lines.constEnd() == line) return false;
 
129
  
 
130
  // skip header
 
131
  ++line; if(lines.constEnd() == line) return false;
 
132
  
 
133
  // parse table
 
134
  for(unsigned row = 0; row <= AminoAcids; ++row)
 
135
  {
 
136
    QValueList<unsigned> values = parseUIntList((*line).mid(4));
 
137
    if(values.count() != AminoAcids+1)  return false;
 
138
        
 
139
    for(unsigned column = 0; column <= AminoAcids; ++column)
 
140
      pairs[row][column] = values[column];
 
141
                
 
142
    ++line; if(lines.constEnd() == line) return false;
 
143
  }
 
144
  
 
145
  return true;
 
146
}
 
147
 
 
148
bool PredictorECovers24::parse(const QStringList &lines)
 
149
{
 
150
  QStringList::const_iterator line = lines.constBegin();
 
151
  
 
152
  // skip header
 
153
  if(lines.constEnd() == line) return false;
 
154
  ++line;
 
155
  
 
156
  // parse table
 
157
  for(unsigned row = 0; row < AminoAcids; ++row)
 
158
  {
 
159
    if(lines.constEnd() == line) return false;
 
160
    
 
161
    QValueList<double> values = parseDoubleList((*line).mid(4));
 
162
    if(values.count() != 25)  return false;
 
163
     
 
164
    for(unsigned column = 0; column < 25; ++column)
 
165
      value[row][column] = values[column];
 
166
                
 
167
    ++line;
 
168
  }
 
169
  
 
170
  return true;
 
171
}
 
172
  
 
173
bool PredictorProfile3::parse(const QStringList &lines)
 
174
{
 
175
  QStringList::const_iterator line = lines.constBegin();
 
176
  
 
177
  for(unsigned aa = 0; aa < AminoAcids; ++aa)
 
178
  {
 
179
    // skip header
 
180
    if(lines.constEnd() == line) return false;
 
181
    ++line;
 
182
 
 
183
    for(unsigned set = 0; set < 5; ++set)
 
184
      for(unsigned row = 0; row < 5; ++row)
 
185
      {
 
186
        if(lines.constEnd() == line) return false;
 
187
        sscanf(*line, "%lf %lf %lf %lf %lf",
 
188
               &value[aa][set][row][0],
 
189
               &value[aa][set][row][1],
 
190
               &value[aa][set][row][2],
 
191
               &value[aa][set][row][3],
 
192
               &value[aa][set][row][4]);
 
193
        ++line;
 
194
      }
 
195
  }
 
196
  
 
197
  return true;
 
198
}
 
199
 
 
200
bool PredictorQuasi3::parse(const QStringList &lines)
 
201
{
 
202
  unsigned npar = 0, nmid = 0, nant = 0;
 
203
  QStringList::const_iterator line = lines.constBegin();
 
204
  
 
205
  while(lines.constEnd() != line)
 
206
  {
 
207
    if((*line).startsWith("PAR")) {
 
208
      line++;
 
209
      
 
210
      for(unsigned row = 0; row < AminoAcids; ++row)
 
211
      {
 
212
        if(lines.constEnd() == line) return false;
 
213
    
 
214
        QValueList<double> values = parseDoubleList((*line).mid(4));
 
215
        if(values.count() != AminoAcids)  return false;
 
216
     
 
217
        for(unsigned column = 0; column < AminoAcids; ++column)
 
218
          par[npar][row][column] = values[column];
 
219
                
 
220
        ++line; 
 
221
      }
 
222
      
 
223
      npar++;
 
224
    }
 
225
    else if((*line).startsWith("MID"))
 
226
    {
 
227
      line++;
 
228
      
 
229
      for(unsigned row = 0; row < AminoAcids; ++row)
 
230
      {
 
231
        if(lines.constEnd() == line) return false;
 
232
    
 
233
        QValueList<double> values = parseDoubleList((*line).mid(4));
 
234
        if(values.count() != AminoAcids)  return false;
 
235
     
 
236
        for(unsigned column = 0; column < AminoAcids; ++column)
 
237
          mid[nmid][row][column] = values[column];
 
238
                
 
239
        ++line; 
 
240
      }
 
241
      
 
242
      nmid++;
 
243
    }
 
244
    else if((*line).startsWith("ANT"))
 
245
    {
 
246
      line++;
 
247
      
 
248
      for(unsigned row = 0; row < AminoAcids; ++row)
 
249
      {
 
250
        if(lines.constEnd() == line) return false;
 
251
    
 
252
        QValueList<double> values = parseDoubleList((*line).mid(4));
 
253
        if(values.count() != AminoAcids)  return false;
 
254
     
 
255
        for(unsigned column = 0; column < AminoAcids; ++column)
 
256
          ant[nant][row][column] = values[column];
 
257
                
 
258
        ++line; 
 
259
      }
 
260
      
 
261
      nant++;
 
262
    }
 
263
    else
 
264
      return false;
 
265
  }
 
266
  
 
267
  return true;
 
268
}
 
269
 
 
270
bool PredictorScale3B::parse(const QString &line)
 
271
{
 
272
  if(!parseAminoAcid(line.mid(0, 3), aa[0])) return false;
 
273
  if(!parseAminoAcid(line.mid(4, 3), aa[1])) return false;
 
274
  if(!parseAminoAcid(line.mid(8, 3), aa[2])) return false;
 
275
  sscanf(line.mid(12), "%u %u %u %lf",
 
276
         &count[0], &count[1], &count[2],
 
277
         &value);
 
278
  
 
279
  return true;
 
280
}
 
281
 
 
282
bool PredictorS1234::parse(const QStringList &lines)
 
283
{
 
284
  QStringList::const_iterator line = lines.constBegin();
 
285
  
 
286
  while(lines.constEnd() != line)
 
287
  {
 
288
    if((*line).startsWith("##### R1.2")) {
 
289
      line++;
 
290
      
 
291
      for(unsigned row = 0; row < AminoAcids; ++row)
 
292
        for(unsigned column = 0; column < AminoAcids; ++column)
 
293
        {
 
294
          // skip header
 
295
          if(lines.constEnd() == line) return false;
 
296
          line++;
 
297
          
 
298
          if(lines.constEnd() == line) return false;
 
299
          sscanf(*line, "%lf %lf %lf",
 
300
                 &r1_2[row][column][0],
 
301
                 &r1_2[row][column][1],
 
302
                 &r1_2[row][column][2]);
 
303
 
 
304
          line++;
 
305
        }
 
306
    } else if((*line).startsWith("##### R1.3")) {
 
307
      line++;
 
308
      
 
309
      for(unsigned row = 0; row < AminoAcids; ++row)
 
310
        for(unsigned column = 0; column < AminoAcids; ++column)
 
311
        {
 
312
          // skip header
 
313
          if(lines.constEnd() == line) return false;
 
314
          line++;
 
315
          
 
316
          if(lines.constEnd() == line) return false;
 
317
          sscanf(*line, "%lf %lf %lf %lf",
 
318
                 &r1_3[row][column][0],
 
319
                 &r1_3[row][column][1],
 
320
                 &r1_3[row][column][2],
 
321
                 &r1_3[row][column][3]);
 
322
 
 
323
          line++;
 
324
        }
 
325
    } else if((*line).startsWith("##### R1.4")) {
 
326
      line++;
 
327
      
 
328
      for(unsigned row = 0; row < AminoAcids; ++row)
 
329
        for(unsigned column = 0; column < AminoAcids; ++column)
 
330
        {
 
331
          // skip header
 
332
          if(lines.constEnd() == line) return false;
 
333
          line++;
 
334
          
 
335
          if(lines.constEnd() == line) return false;
 
336
          sscanf(*line, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
 
337
                 &r1_4[row][column][0],
 
338
                 &r1_4[row][column][1],
 
339
                 &r1_4[row][column][2],
 
340
                 &r1_4[row][column][3],
 
341
                 &r1_4[row][column][4],
 
342
                 &r1_4[row][column][5],
 
343
                 &r1_4[row][column][6],
 
344
                 &r1_4[row][column][7],
 
345
                 &r1_4[row][column][8],
 
346
                 &r1_4[row][column][9],
 
347
                 &r1_4[row][column][10],
 
348
                 &r1_4[row][column][11],
 
349
                 &r1_4[row][column][12],
 
350
                 &r1_4[row][column][13]);
 
351
 
 
352
          line++;
 
353
        }
 
354
    } else if((*line).startsWith("##### R1.5")) {
 
355
      line++;
 
356
      
 
357
      for(unsigned row = 0; row < AminoAcids; ++row)
 
358
        for(unsigned column = 0; column < AminoAcids; ++column)
 
359
        {
 
360
          // skip header
 
361
          if(lines.constEnd() == line) return false;
 
362
          line++;
 
363
          
 
364
          if(lines.constEnd() == line) return false;
 
365
          sscanf(*line, "%lf %lf %lf %lf %lf %lf %lf",
 
366
                 &r1_5[row][column][0],
 
367
                 &r1_5[row][column][1],
 
368
                 &r1_5[row][column][2],
 
369
                 &r1_5[row][column][3],
 
370
                 &r1_5[row][column][4],
 
371
                 &r1_5[row][column][5],
 
372
                 &r1_5[row][column][6]);
 
373
 
 
374
          line++;
 
375
        }
 
376
    } else
 
377
      return false;
 
378
  }
 
379
  
 
380
  return true;
 
381
}
 
382
 
 
383
bool PredictorMonssterAtom::parse(const QString &line)
 
384
{
 
385
  sscanf(line, "%u %u %u", &x, &y, &z);
 
386
  
 
387
  return true;
 
388
}
 
389
 
 
390
bool PredictorMonssterInput::parse(const QStringList &lines)
 
391
{
 
392
  QStringList::const_iterator line = lines.constBegin();
 
393
 
 
394
  if(lines.constEnd() == line) return false;
 
395
  sscanf(*line, "%u %u %u %u", &random, &ncycle, &icycle, &tsteps);
 
396
  ++line;
 
397
         
 
398
  if(lines.constEnd() == line) return false;
 
399
  sscanf(*line, "%u %u", &resmin, &resmax);
 
400
  ++line;
 
401
  
 
402
  if(lines.constEnd() == line) return false;
 
403
  ++line;
 
404
  
 
405
  if(lines.constEnd() == line) return false;
 
406
  sscanf(*line, "%lf %lf %lf %lf", &temp[0], &temp[1], &softcore, &central);
 
407
  ++line;
 
408
  
 
409
  if(lines.constEnd() == line) return false;
 
410
  sscanf(*line, "%lf %lf %lf %lf %lf", &stiff, &pair, &kdcore, &hbond, &shrt);
 
411
  ++line;
 
412
    
 
413
  if(lines.constEnd() == line) return false;
 
414
  sscanf(*line, "%lf %lf %lf", &burial, &multibody, &threebody);
 
415
  ++line;
 
416
  
 
417
  return true;
 
418
}
 
419
 
 
420
bool PredictorMonssterResidue::parse(const QString &line)
 
421
{
 
422
  resSeq = line.left(5).toUInt(0, 10);
 
423
  if(!parseAminoAcid(line.mid(8, 3), resName)) return false;
 
424
  sscanf(line.mid(12), "%u %u", &count[0], &count[1]);
 
425
  
 
426
  return true;
 
427
}
 
428
 
 
429
bool PredictorMonssterSeq::parse(const QStringList &lines)
 
430
{
 
431
  atoms = 0;
 
432
  groups.clear();
 
433
  QStringList::const_iterator line = lines.constBegin();
 
434
 
 
435
  while(lines.constEnd() != line)
 
436
  {
 
437
    PredictorMonssterResidue item;
 
438
    if(!item.parse(*line)) return false;
 
439
    
 
440
    atoms += PredictorAminoAcidAtoms[item.resName];
 
441
    groups << item;
 
442
    ++line;
 
443
  }
 
444
 
 
445
  return true;
 
446
}
 
447
 
 
448
QString PredictorMonssterSeq::toString() const
 
449
{
 
450
  QString out;
 
451
 
 
452
  unsigned column = 0;
 
453
  for(QValueList<PredictorMonssterResidue>::const_iterator group = groups.begin();
 
454
      group != groups.end(); ++group)
 
455
  {
 
456
    if(column > 0 && (column % 60) == 0) out.append('\n');
 
457
    out.append(PredictorAminoAcidAbbrev[(*group).resName]);
 
458
    ++column;
 
459
  }
 
460
 
 
461
  return out;
 
462
}
 
463
 
 
464
bool PredictorMonssterRestraint::parse(const QString &line)
 
465
{
 
466
  sscanf(line, "%u %lf", &num, &value);
 
467
  
 
468
  return true;
 
469
}
 
470
 
 
471
bool PredictorAtomPDB::parse(const QString &line)
 
472
{
 
473
  const unsigned len = line.length();
 
474
  
 
475
  if(len < 6 || line.left(6) != "ATOM  ") return false;
 
476
  
 
477
  serial = (len > 6) ? line.mid(6, 5).toUInt(0, 10) : 0;
 
478
  
 
479
  if(len > 12)
 
480
  {
 
481
    element = line.mid(12, 2).stripWhiteSpace();
 
482
    if(element.startsWith("H")) element = "H";
 
483
    
 
484
    name.remoteness = 0;
 
485
    const QString greek = " ABGDEZHT";
 
486
    while(line.at(14) != greek.at(name.remoteness))
 
487
      if(++name.remoteness >= greek.length())
 
488
        break;
 
489
    
 
490
    name.branch = (line.at(15) == ' ') ? 0 : (line.at(15) - '1');
 
491
    name.iupac = line.mid(12, 4).stripWhiteSpace();
 
492
  }
 
493
  else
 
494
  {
 
495
    element = name.iupac = QString::null;
 
496
    name.remoteness = name.branch = 0;
 
497
  }
 
498
  
 
499
  altLoc = (len > 16) ? line.at(16) : QChar(' ');
 
500
  
 
501
  if(len > 17) {
 
502
    if(!parseAminoAcid(line.mid(17, 3), resName)) return false;
 
503
  } else
 
504
    resName = AminoAcids;
 
505
  
 
506
  chainID = (len > 21) ? line.at(21) : QChar(' ');
 
507
  
 
508
  resSeq = (len > 22) ? line.mid(22, 4).toUInt(0, 10) : 0;
 
509
  
 
510
  iCode = (len > 26) ? line.at(26) : QChar(' ');
 
511
  
 
512
  x = (len > 30) ? line.mid(30, 8).toDouble() : 0.0;
 
513
  
 
514
  y = (len > 38) ? line.mid(38, 8).toDouble() : 0.0;
 
515
  
 
516
  z = (len > 46) ? line.mid(46, 8).toDouble() : 0.0;
 
517
  
 
518
  occupancy = (len > 54) ? line.mid(54, 6).toDouble() : 0.0;
 
519
  
 
520
  tempFactor = (len > 60) ? line.mid(60, 6).toDouble() : 0.0;
 
521
  
 
522
  segID = (len > 72) ? line.mid(72, 4).stripWhiteSpace() : QString::null;
 
523
  
 
524
  if(len > 76) element = line.mid(76, 2).stripWhiteSpace();
 
525
  
 
526
  charge = (len > 78) ? line.mid(78, 2).stripWhiteSpace() : QString::null;
 
527
  
 
528
  return true;
 
529
}
 
530
 
 
531
bool operator<(const PredictorAtomPDB &a1, const PredictorAtomPDB &a2)
 
532
{
 
533
  return(a1.serial < a2.serial);
 
534
}
 
535
 
 
536
bool PredictorHelixPDB::parse(const QString &line)
 
537
{
 
538
  const unsigned len = line.length();
 
539
  
 
540
  if(len < 6 || line.left(6) != "HELIX ") return false;
 
541
  
 
542
  serNum = (len > 7) ? line.mid(7, 3).toUInt(0, 10) : 0;
 
543
  
 
544
  helixID = (len > 11) ? line.mid(11, 3).stripWhiteSpace() : QString::null;
 
545
  
 
546
  if(len > 15) {
 
547
    if(!parseAminoAcid(line.mid(15, 3), init.resName)) return false;
 
548
  } else
 
549
    init.resName = AminoAcids;
 
550
  
 
551
  init.chainID = (len > 19) ? line.at(19) : QChar(' ');
 
552
  
 
553
  init.seqNum = (len > 21) ? line.mid(21, 4).toUInt(0, 10) : 0;
 
554
  
 
555
  init.iCode = (len > 25) ? line.at(25) : QChar(' ');
 
556
  
 
557
  if(len > 27) {
 
558
    if(!parseAminoAcid(line.mid(27, 3), end.resName)) return false;
 
559
  } else
 
560
    end.resName = AminoAcids;
 
561
  
 
562
  end.chainID = (len > 31) ? line.at(31) : QChar(' ');
 
563
  
 
564
  end.seqNum = (len > 33) ? line.mid(33, 4).toUInt(0, 10) : 0;
 
565
  
 
566
  end.iCode = (len > 37) ? line.at(37) : QChar(' ');
 
567
  
 
568
  helixClass = (len > 38) ? PredictorHelixClass(line.mid(38, 2).toUInt(0, 10)) : RightHandedApha;
 
569
  
 
570
  comment = (len > 40) ? line.mid(40, 30).stripWhiteSpace() : QString::null;
 
571
  
 
572
  length = (len > 71) ? line.mid(71, 5).toUInt(0, 10) : 0;
 
573
  
 
574
  return true;
 
575
}
 
576
 
 
577
bool operator<(const PredictorHelixPDB &h1, const PredictorHelixPDB &h2)
 
578
{
 
579
  return(h1.init.seqNum < h2.init.seqNum);
 
580
}
 
581
 
 
582
bool PredictorSheetPDB::parse(const QString &line)
 
583
{
 
584
  const unsigned len = line.length();
 
585
  
 
586
  if(len < 6 || line.left(6) != "SHEET ") return false;
 
587
  
 
588
  strand = (len > 7) ? line.mid(7, 3).toUInt(0, 10) : 0;
 
589
  
 
590
  sheetID = (len > 11) ? line.mid(11, 3).stripWhiteSpace() : QString::null;
 
591
  
 
592
  numStrands = (len > 14) ? line.mid(14, 2).toUInt(0, 10) : 0;
 
593
  
 
594
  if(len > 17) {
 
595
    if(!parseAminoAcid(line.mid(17, 3), init.resName)) return false;
 
596
  } else
 
597
    init.resName = AminoAcids;
 
598
  
 
599
  init.chainID = (len > 21) ? line.at(21) : QChar(' ');
 
600
  
 
601
  init.seqNum = (len > 22) ? line.mid(22, 4).toUInt(0, 10) : 0;
 
602
  
 
603
  init.iCode = (len > 26) ? line.at(26) : QChar(' ');
 
604
  
 
605
  if(len > 28) {
 
606
    if(!parseAminoAcid(line.mid(28, 3), end.resName)) return false;
 
607
  } else
 
608
    end.resName = AminoAcids;
 
609
  
 
610
  end.chainID = (len > 32) ? line.at(32) : QChar(' ');
 
611
  
 
612
  end.seqNum = (len > 33) ? line.mid(33, 4).toUInt(0, 10) : 0;
 
613
  
 
614
  end.iCode = (len > 37) ? line.at(37) : QChar(' ');
 
615
  
 
616
  sense = (len > 38) ? line.mid(38, 2).toInt(0, 10) : 0;
 
617
  
 
618
  curr.atom = (len > 41) ? line.mid(41, 4).stripWhiteSpace() : QString::null;
 
619
  
 
620
  if(len > 45) {
 
621
    if(!parseAminoAcid(line.mid(45, 3), curr.resName)) return false;
 
622
  } else
 
623
    curr.resName = AminoAcids;
 
624
  
 
625
  curr.chainId = (len > 49) ? line.at(49) : QChar(' ');
 
626
  
 
627
  curr.resSeq = (len > 50) ? line.mid(50, 4).toUInt(0, 10) : 0;
 
628
  
 
629
  curr.iCode = (len > 54) ? line.at(54) : QChar(' ');
 
630
  
 
631
  prev.atom = (len > 56) ? line.mid(56, 4).stripWhiteSpace() : QString::null;
 
632
  
 
633
  if(len > 60) {
 
634
    if(!parseAminoAcid(line.mid(60, 3), prev.resName)) return false;
 
635
  } else
 
636
    prev.resName = AminoAcids;
 
637
  
 
638
  prev.chainId = (len > 64) ? line.at(64) : QChar(' ');
 
639
  
 
640
  prev.resSeq = (len > 65) ? line.mid(65, 4).toUInt(0, 10) : 0;
 
641
  
 
642
  prev.iCode = (len > 69) ? line.at(69) : QChar(' ');
 
643
  
 
644
  return true;
 
645
}
 
646
 
 
647
bool operator<(const PredictorSheetPDB &s1, const PredictorSheetPDB &s2)
 
648
{
 
649
  return(s1.init.seqNum < s2.init.seqNum);
 
650
}
 
651
 
 
652
bool PredictorTurnPDB::parse(const QString &line)
 
653
{
 
654
  const unsigned len = line.length();
 
655
  
 
656
  if(len < 6 || line.left(6) != "TURN  ") return false;
 
657
  
 
658
  seq = (len > 7) ? line.mid(7, 3).toUInt(0, 10) : 0;
 
659
  
 
660
  turnID = (len > 11) ? line.mid(11, 3).stripWhiteSpace() : QString::null;
 
661
  
 
662
  if(len > 15) {
 
663
    if(!parseAminoAcid(line.mid(15, 3), init.resName)) return false;
 
664
  } else
 
665
    init.resName = AminoAcids;
 
666
  
 
667
  init.chainID = (len > 19) ? line.at(19) : QChar(' ');
 
668
  
 
669
  init.seqNum = (len > 20) ? line.mid(20, 4).toUInt(0, 10) : 0;
 
670
  
 
671
  init.iCode = (len > 24) ? line.at(24) : QChar(' ');
 
672
  
 
673
  if(len > 26) {
 
674
    if(!parseAminoAcid(line.mid(26, 3), end.resName)) return false;
 
675
  } else
 
676
    end.resName = AminoAcids;
 
677
  
 
678
  end.chainID = (len > 30) ? line.at(30) : QChar(' ');
 
679
  
 
680
  end.seqNum = (len > 31) ? line.mid(31, 4).toUInt(0, 10) : 0;
 
681
  
 
682
  end.iCode = (len > 35) ? line.at(35) : QChar(' ');
 
683
  
 
684
  comment = (len > 40) ? line.mid(40, 30) : QString::null;
 
685
  
 
686
  return true;
 
687
}
 
688
 
 
689
bool operator<(const PredictorTurnPDB &t1, const PredictorTurnPDB &t2)
 
690
{
 
691
  return(t1.init.seqNum < t2.init.seqNum);
 
692
}
 
693
 
 
694
bool PredictorProteinPDB::parse(const QStringList &lines)
 
695
{
 
696
  groups = 0;
 
697
  atoms.clear();
 
698
  helix.clear();
 
699
  sheet.clear();
 
700
  turn.clear();
 
701
 
 
702
  bool hasSecondary = false;
 
703
  for(QStringList::const_iterator line = lines.constBegin();
 
704
      line != lines.constEnd(); ++line)
 
705
    if((*line).startsWith("ATOM"))
 
706
    {
 
707
      PredictorAtomPDB item;
 
708
      if(!item.parse(*line)) return false;
 
709
      
 
710
      atoms << item;
 
711
      if(item.name.iupac == "CA") groups++;
 
712
    }
 
713
    else if((*line).startsWith("HELIX"))
 
714
    {
 
715
      PredictorHelixPDB item;
 
716
      if(!item.parse(*line)) return false;
 
717
      
 
718
      helix << item;
 
719
      hasSecondary = true;
 
720
    }
 
721
    else if((*line).startsWith("SHEET"))
 
722
    {
 
723
      PredictorSheetPDB item;
 
724
      if(!item.parse(*line)) return false;
 
725
      
 
726
      sheet << item;
 
727
      hasSecondary = true;
 
728
    }
 
729
    else if((*line).startsWith("TURN"))
 
730
    {
 
731
      PredictorTurnPDB item;
 
732
      if(!item.parse(*line)) return false;
 
733
      
 
734
      turn << item;
 
735
      hasSecondary = true;
 
736
    }
 
737
    else if((*line).startsWith("END"))
 
738
      break;
 
739
  
 
740
  qHeapSort(atoms);
 
741
  if(hasSecondary) {
 
742
    qHeapSort(helix);
 
743
    qHeapSort(sheet);
 
744
    qHeapSort(turn);
 
745
  }
 
746
  
 
747
  return true;
 
748
}
 
749
 
 
750
QString PredictorProteinPDB::toString() const
 
751
{
 
752
  QString out;
 
753
 
 
754
  unsigned column = 0;
 
755
  for(QValueList<PredictorAtomPDB>::const_iterator atom = atoms.begin();
 
756
      atom != atoms.end(); ++atom)
 
757
  {
 
758
    if((*atom).name.iupac != "CA") continue;
 
759
    if(column > 0 && (column % 60) == 0) out.append('\n');
 
760
    out.append(PredictorAminoAcidAbbrev[(*atom).resName]);
 
761
    ++column;
 
762
  }
 
763
 
 
764
  return out;
 
765
}
 
766
 
 
767
bool PredictorProteinNOE::parse(const QString &line)
 
768
{
 
769
  QStringList values = QStringList::split(" ", line);
 
770
  if(values.count() != 21) return false;
 
771
  
 
772
  select[0].index = values[4].toUInt(0, 10);
 
773
  select[0].name = values[5];
 
774
  
 
775
  select[1].index = values[10].toUInt(0, 10);
 
776
  select[1].name = values[11];
 
777
  
 
778
  kmin = values[14].toDouble();
 
779
  rmin = values[16].toDouble();
 
780
  kmax = values[18].toDouble();
 
781
  rmax = values[20].toDouble();
 
782
  
 
783
  return true;
 
784
}
 
785
 
 
786
bool PredictorCharmmInp::parse(const QStringList &lines)
 
787
{
 
788
  ntemps = nsteps = t.low = t.high = 0;
 
789
  
 
790
  for(QStringList::const_iterator line = lines.begin(); lines.constEnd() != line; ++line)
 
791
  {
 
792
    if((*line).stripWhiteSpace().startsWith("!")) continue;
 
793
    
 
794
    int start = (*line).find(QRegExp("set \\w+ = "));
 
795
    if(start < 0) continue;
 
796
    start += 4;
 
797
    
 
798
    int end = (*line).find('=', start);
 
799
    if(end < 0) continue;
 
800
    
 
801
    const QString key = (*line).mid(start, end - start).stripWhiteSpace(),
 
802
                  value = (*line).mid(end+1).stripWhiteSpace();
 
803
    
 
804
    if(key == "ntemps")
 
805
      ntemps = value.toUInt(0, 10);
 
806
    else if(key == "nsteps")
 
807
      nsteps = value.toUInt(0, 10);
 
808
    else if(key == "thigh")
 
809
      t.high = value.toUInt(0, 10);
 
810
    else if(key == "tlow")
 
811
      t.low = value.toUInt(0, 10);
 
812
  }
 
813
  
 
814
  return true;
 
815
}
 
816
 
 
817
bool PredictorMonssterRestart::parse(const QStringList &lines)
 
818
{
 
819
  QStringList::const_iterator line = lines.constBegin();
 
820
 
 
821
  if(lines.constEnd() == line) return false;
 
822
  sscanf(*line, "%u %u %lf %lf %lf %lf %lf",
 
823
         &line1a[0], &line1a[1],
 
824
         &line1b[0], &line1b[1], &line1b[2], &line1b[3], &line1b[4]);
 
825
  ++line;
 
826
  
 
827
  if(lines.constEnd() == line) return false;
 
828
  sscanf(*line, "%u %u %u", &line2[0], &line2[1], &line2[2]);
 
829
  ++line;
 
830
  
 
831
  if(lines.constEnd() == line) return false;
 
832
  sscanf(*line, "%lf %lf", &line3[0], &line3[1]);
 
833
  ++line;
 
834
  
 
835
  unsigned count = 0;
 
836
  
 
837
  if(lines.constEnd() == line) return false;
 
838
  sscanf(*line, "%u", &count);
 
839
  ++line;
 
840
  
 
841
  chain.clear();
 
842
  for(unsigned i = 0; i < count; ++i)
 
843
  {
 
844
    PredictorMonssterAtom item;
 
845
    
 
846
    if(lines.constEnd() == line || !item.parse(*line)) return false;
 
847
    ++line;
 
848
    
 
849
    chain << item;
 
850
  }
 
851
  
 
852
  qDebug("...parse OK");
 
853
  
 
854
  return true;
 
855
}