-
Notifications
You must be signed in to change notification settings - Fork 0
/
glosa.cpp
3306 lines (2392 loc) · 82.1 KB
/
glosa.cpp
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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <fstream>
#include <iostream>
#include <list>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <map>
#include <string.h>
#include <algorithm>
#include <assert.h>
#include <ctime>
using namespace std;
// **************************
// **** Global Variables ****
// **************************
string progname;
string s1, s2, s1cf, s2cf, ref_struct, fit_struct;
string surf1 = "n";
string surf1cf = "n";
string s1ss = "n";
string s2ss = "n";
string s2w = "n";
int min_blosum_value = 0;
int num_iter = 3;
int num_iter_cf = 0;
int f_option = 1;
int surf_option = 0;
int ss_option = 0;
int n_option = 1;
int output_option = 1;
float dist_tolerance_init = 1.5;
float dist_tolerance_cf_init = 2.5;
float dist_tolerance = 1.5;
float dist_tolerance_cf = 2.5;
float d0 = 3.0;
double u[3][3], t[3];
double u_best[3][3], t_best[3];
int ref_elements_in_product_graph[3000];
int fit_elements_in_product_graph[3000];
float shortestDist[3000];
double cost[3000][3000];
double score[3000][3000];
int spalte[3000];
int alignedRes[3000];
int alignedResBest[3000];
map<char, int> blosum62_map;
map<char, int> :: iterator blosum62_map_iter;
int aa_size = 22;
const char *tc_aa[] = {
"GLY", "ALA", "SER", "CYS", "VAL",
"THR", "ILE", "PRO", "MET", "ASP",
"ASN", "LEU", "LYS", "GLU", "GLN",
"ARG", "HIS", "PHE", "TYR", "TRP",
"CYX", "MSE" };
char oc_aa[] = {
'G', 'A', 'S', 'C', 'V',
'T', 'I', 'P', 'M', 'D',
'N', 'L', 'K', 'E', 'Q',
'R', 'H', 'F', 'Y', 'W',
'C', 'M' };
float blosum62[20][20] = {
{ 9, -1, -1, -3, 0, -3, -3, -3, -4, -3, -3, -3, -3, -1, -1, -1, -1, -2, -2, -2 },
{ -1, 4, 1, -1, 1, 0, 1, 0, 0, 0, -1, -1, 0, -1, -2, -2, -2, -2, -2, -3 },
{ -1, 1, 5, -1, 0, -2, 0, -1, -1, -1, -2, -1, -1, -1, -1, -1, 0, -2, -2, -2 },
{ -3, -1, -1, 7, -1, -2, -1, -1, -1, -1, -2, -2, -1, -2, -3, -3, -2, -4, -3, -4 },
{ 0, 1, 0, -1, 4, 0, -1, -2, -1, -1, -2, -1, -1, -1, -1, -1, -2, -2, -2, -3 },
{ -3, 0, -2, -2, 0, 6, -2, -1, -2, -2, -2, -2, -2, -3, -4, -4, 0, -3, -3, -2 },
{ -3, 1, 0, -2, -2, 0, 6, 1, 0, 0, -1, 0, 0, -2, -3, -3, -3, -3, -2, -4 },
{ -3, 0, -1, -1, -2, -1, 1, 6, 2, 0, -1, -2, -1, -3, -3, -4, -3, -3, -3, -4 },
{ -4, 0, -1, -1, -1, -2, 0, 2, 5, 2, 0, 0, 1, -2, -3, -3, -3, -3, -2, -3 },
{ -3, 0, -1, -1, -1, -2, 0, 0, 2, 5, 0, 1, 1, 0, -3, -2, -2, -3, -1, -2 },
{ -3, -1, -2, -2, -2, -2, 1, -1, 0, 0, 8, 0, -1, -2, -3, -3, -2, -1, 2, -2 },
{ -3, -1, -1, -2, -1, -2, 0, -2, 0, 1, 0, 5, 2, -1, -3, -2, -3, -3, -2, -3 },
{ -3, 0, -1, -1, -1, -2, 0, -1, 1, 1, -1, 2, 5, -1, -3, -2, -3, -3, -2, -3 },
{ -1, -1, -1, -2, -1, -3, -2, -3, -2, 0, -2, -1, -1, 5, 1, 2, -2, 0, -1, -1 },
{ -1, -2, -1, -3, -1, -4, -3, -3, -3, -3, -3, -3, -3, 1, 4, 2, 1, 0, -1, -3 },
{ -1, -2, -1, -3, -1, -4, -3, -4, -3, -2, -3, -2, -2, 2, 2, 4, 3, 0, -1, -2 },
{ -1, -2, 0, -2, 0, -3, -3, -3, -2, -2, -3, -3, -2, 1, 3, 1, 4, -1, -1, -3 },
{ -2, -2, -2, -4, -2, -3, -3, -3, -3, -3, -1, -3, -3, 0, 0, 0, -1, 6, 3, 1 },
{ -2, -2, -2, -3, -2, -3, -2, -3, -2, -1, 2, -2, -2, -1, -1, -1, -1, 3, 7, 2 },
{ -2, -3, -2, -4, -3, -2, -4, -4, -3, -2, -2, -3, -3, -1, -3, -2, -3, 1, 2, 11 }
};
// ************************
// *****************
// **** Classes ****
// *****************
class Atom{
public:
Atom();
~Atom();
Atom( Atom & );
public:
char res_name;
int res_Seq;
char cf[2];
double R[3];
double SR[3];
double R_sup[3];
double SR_sup[3];
char ss; // A: alpha, B: beta, C: coil
};
Atom :: Atom()
{}
Atom :: ~Atom()
{}
Atom :: Atom( Atom & )
{}
class Pair{
public:
Pair();
~Pair();
Pair( Pair & );
public:
int ref_index;
int fit_index;
};
Pair :: Pair()
{}
Pair :: ~Pair()
{}
Pair :: Pair( Pair & )
{}
class Edge{
public:
Edge();
~Edge();
Edge( Edge & );
public:
int pair_i;
int pair_j;
};
Edge :: Edge()
{}
Edge :: ~Edge()
{}
Edge :: Edge( Edge & )
{}
class Fragment{
public:
Fragment();
~Fragment();
Fragment( Fragment & );
public:
int index[3];
};
Fragment :: Fragment()
{}
Fragment :: ~Fragment()
{}
Fragment :: Fragment( Fragment & )
{}
// *********************************
// ********* Parse Command *********
// *********************************
void help( string msg ){
cout << msg
<< "\n\n"
<< "options [required]: " << "\n"
<< " -s1 structure 1 (PDB format) " << "\n"
<< " -s1cf chemical feature file for structure 1 " << "\n"
<< " -s2 structure 2 (PDB format) " << "\n"
<< " -s2cf chemical feature file for structure 2 " << "\n"
<< "\n"
<< "options [advanced]: " << "\n"
<< " -b BLOSUM62 cutoff value for filtering (default=0) " << "\n"
<< " -iter the number of iteration for CA-based maximum clique search (1-3, default=3) " << "\n"
<< " < 1: don't use CA-based maximum clique search " << "\n"
<< " -itercf the number of iteration for chemical feature-based maximum clique search (1-3, default=0)" << "\n"
<< " < 1: don't use chemical feature-based maximum clique search " << "\n"
<< " -f the number of conserved residue(s) in a fragment pair (1-3, default=1) " << "\n"
<< " >3 : don't use fragment superposition " << "\n"
<< "\n"
<< " -surf use surface structure for alignment " << "\n"
<< " (This option is only used when a whole protein structure is used for s1) " << "\n"
<< " 0: don't use this option (default) " << "\n"
<< " 1: use this option " << "\n"
<< " -surf1 surface residues for structure 1 (n: don't use this option, default=n) " << "\n"
<< " -surf1cf chemical feature for the surface residues structure (n: don't use this option, default=n)" << "\n"
<< "\n"
<< " -s2w additional structure to be transferred (PDB format) (n: don't use this option, default=n)" << "\n"
<< "\n"
<< " -ss check secondary structure conservation " << "\n"
<< " 0: don't use this option (default) " << "\n"
<< " 1: use this option " << "\n"
<< " -s1ss secondary structure file for structure 1 (n: don't use this option, default=n) " << "\n"
<< " -s2ss secondary structure file for structure 2 (n: don't use this option, default=n) " << "\n"
<< "\n"
<< " -n normalization option " << "\n"
<< " 1: normalize using structure with smaller number of chemical feature points (N_min) (default)" << "\n"
<< " 2: normalize using structure with larger number of chemical feature points (N_max) " << "\n"
<< " 3: normalize using the average of N_min and N_max " << "\n"
<< " 4: normalize using s1 structure " << "\n"
<< " 5: normalize using s2 structure " << "\n"
<< "\n"
<< " -o output option " << "\n"
<< " 0: score only " << "\n"
<< " 1: score and superposed s2 structure with matrix (default) " << "\n"
<< " 2: score with matrix " << "\n"
<< "\n"
<< " -help" << "\n"
<< "\n"
<< "outputs: " << "\n"
<< " GA-score : G-LoSA alignment score " << "\n"
<< " ali_struct.pdb : the PDB coordinates of s2 structure aligned onto s1 structure " << "\n"
<< " matrix.txt : translational and rotational matrix to align s2 structure onto s1 structure" << "\n"
<< " ali_struct_with.pdb: the PDB coordinates of s2w structure transferred by the matrix " << "\n";
exit(1);
}
void parseCommandLine( int argc, char *argv[] ){
string a;
progname = *argv;
if( argc == 1 ) help( "" );
for( ++argv ; --argc ; ++argv ){
a = *argv;
if( a == "-s1" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
s1 = *++argv;
}
else if( a == "-s1cf" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
s1cf = *++argv;
}
else if( a == "-s1ss" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
s1ss = *++argv;
}
else if( a == "-s2" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
s2 = *++argv;
}
else if( a == "-s2cf" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
s2cf = *++argv;
}
else if( a == "-surf" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
surf_option = (int)atof( *++argv );
}
else if( a == "-surf1" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
surf1 = *++argv;
}
else if( a == "-surf1cf" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
surf1cf = *++argv;
}
else if( a == "-s2ss" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
s2ss = *++argv;
}
else if( a == "-s2w" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
s2w = *++argv;
}
else if( a == "-b" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
min_blosum_value = (int)atof( *++argv );
}
else if( a == "-iter" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
num_iter = (int)atof( *++argv );
}
else if( a == "-itercf" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
num_iter_cf = (int)atof( *++argv );
}
else if( a == "-f" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
f_option = (int)atof( *++argv );
}
else if( a == "-ss" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
ss_option = (int)atof( *++argv );
}
else if( a == "-n" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
n_option = (int)atof( *++argv );
}
else if( a == "-o" ){
if( --argc == 0 ) help( "ERROR: " + a + " requires value." );
output_option = (int)atof( *++argv );
}
else if (a=="-help") help( "" );
else help( "ERROR: Bad option: " + a );
}
}
// ************************
// ************************************************************************
// *********** Class and Functions for Maximum Clique Detection ***********
// ************************************************************************
// ===============================================================
// There are a class and functions to identify maximum clique based on an improved
// branch and bound algorithm
// Reference:
// Janez Konc and Dusanka Janezic. An improved branch and bound algorithm for the
// maximum clique problem. MATCH Commun. Math. Comput. Chem., 2007, 58, 569-590.
//
// Modified by H. S. Lee
// ==============================================================
class Maxclique {
const bool* const* e;
int pk, level;
const float Tlimit;
class Vertices {
class Vertex {
int i, d;
public:
void set_i( const int ii ) { i = ii; }
int get_i() const { return i; }
void set_degree( int dd ) { d = dd; }
int get_degree() const { return d; }
};
Vertex *v;
int sz;
static bool desc_degree( const Vertex vi, const Vertex vj) { return (vi.get_degree() > vj.get_degree()); }
public:
Vertices( int size ) : sz(0) { v = new Vertex[size]; }
~Vertices () {}
void dispose() { if (v) delete [] v; }
void sort() { std::sort( v, v+sz, desc_degree ); }
void init_colors();
void set_degrees( Maxclique& );
int size() const { return sz; }
void push( const int ii ) { v[sz++].set_i(ii); };
void pop() { sz--; };
Vertex& at( const int ii ) const { return v[ii]; };
Vertex& end() const { return v[sz - 1]; };
};
class ColorClass {
int *i;
int sz;
public:
ColorClass() : sz(0), i(0) {}
ColorClass( const int sz ) : sz(sz), i(0) { init(sz); }
~ColorClass() { if (i) delete [] i; }
void init( const int sz ) { i = new int[sz]; rewind(); }
void push( const int ii ) { i[sz++] = ii; };
void pop() { sz--; };
void rewind() { sz = 0; };
int size() const { return sz; }
int& at(const int ii) const { return i[ii]; }
ColorClass& operator=( const ColorClass& dh ) {
for (int j = 0; j < dh.sz; j++) i[j] = dh.i[j];
sz = dh.sz;
return *this;
}
};
Vertices V;
ColorClass *C, QMAX, Q;
class StepCount {
int i1, i2;
public:
StepCount() : i1(0), i2(0) {}
void set_i1( const int ii ) { i1 = ii; }
int get_i1() const { return i1; }
void set_i2( const int ii ) { i2 = ii; }
int get_i2() const { return i2; }
void inc_i1() { i1++; }
};
StepCount *S;
bool connection(const int i, const int j ) const { return e[i][j]; }
bool cut1( const int, const ColorClass& );
void cut2( const Vertices&, Vertices& );
void color_sort( Vertices& );
void expand( Vertices );
void expand_dyn( Vertices );
void _mcq( int*&, int&, bool );
void degree_sort( Vertices &R ) { R.set_degrees(*this); R.sort(); }
public:
Maxclique( const bool* const*, const int, const float=0.025 );
int steps() const { return pk; }
void mcq( int* &maxclique, int &sz ) { _mcq( maxclique, sz, false ); }
void mcqdyn( int* &maxclique, int &sz ) { _mcq(maxclique, sz, true); }
~Maxclique() {
if( C ) delete [] C;
if( S ) delete [] S;
V.dispose();
};
};
Maxclique::Maxclique ( const bool* const* conn, const int sz, const float tt) : pk(0), level(1), Tlimit(tt), V(sz), Q(sz), QMAX(sz) {
assert(conn!=0 && sz>0);
for (int i=0; i < sz; i++) V.push(i);
e = conn;
C = new ColorClass[sz + 1];
for(int i=0; i < sz + 1; i++) C[i].init(sz + 1);
S = new StepCount[sz + 1];
}
void Maxclique::_mcq( int* &maxclique, int &sz, bool dyn ) {
V.set_degrees(*this);
V.sort();
V.init_colors();
if( dyn ) {
for ( int i=0; i < V.size() + 1; i++ ) {
S[i].set_i1(0);
S[i].set_i2(0);
}
expand_dyn(V);
}
else
expand(V);
maxclique = new int[QMAX.size()];
for( int i=0; i<QMAX.size(); i++ ) {
maxclique[i] = QMAX.at(i);
}
sz = QMAX.size();
}
void Maxclique::Vertices::init_colors() {
const int max_degree = v[0].get_degree();
for( int i = 0; i < max_degree; i++ )
v[i].set_degree(i + 1);
for( int i = max_degree; i < sz; i++ )
v[i].set_degree(max_degree + 1);
}
void Maxclique::Vertices::set_degrees( Maxclique &m ) {
for( int i=0; i < sz; i++ ) {
int d = 0;
for( int j=0; j < sz; j++ )
if( m.connection(v[i].get_i(), v[j].get_i()) ) d++;
v[i].set_degree(d);
}
}
bool Maxclique::cut1( const int pi, const ColorClass &A ) {
for( int i = 0; i < A.size(); i++ )
if( connection(pi, A.at(i)) ) return true;
return false;
}
void Maxclique::cut2( const Vertices &A, Vertices &B ) {
for( int i = 0; i < A.size() - 1; i++ ) {
if( connection(A.end().get_i(), A.at(i).get_i()) )
B.push(A.at(i).get_i());
}
}
void Maxclique::color_sort( Vertices &R ) {
int j = 0;
int maxno = 1;
int min_k = QMAX.size() - Q.size() + 1;
C[1].rewind();
C[2].rewind();
int k = 1;
for( int i=0; i < R.size(); i++ ) {
int pi = R.at(i).get_i();
k = 1;
while( cut1(pi, C[k]) )
k++;
if( k > maxno ) {
maxno = k;
C[maxno + 1].rewind();
}
C[k].push(pi);
if( k < min_k ) {
R.at(j++).set_i(pi);
}
}
if( j > 0 ) R.at(j-1).set_degree(0);
if( min_k <= 0 ) min_k = 1;
for( k = min_k; k <= maxno; k++ ) {
for( int i = 0; i < C[k].size(); i++ ) {
R.at(j).set_i(C[k].at(i));
R.at(j++).set_degree(k);
}
}
}
void Maxclique::expand( Vertices R ) {
while( R.size() ) {
if( Q.size() + R.end().get_degree() > QMAX.size() ) {
Q.push(R.end().get_i());
Vertices Rp(R.size());
cut2(R, Rp);
if( Rp.size() ) {
color_sort(Rp);
pk++;
expand(Rp);
}
else if( Q.size() > QMAX.size() ) {
QMAX = Q;
}
Rp.dispose();
Q.pop();
}
else {
return;
}
R.pop();
}
}
void Maxclique::expand_dyn( Vertices R ) {
S[level].set_i1(S[level].get_i1() + S[level - 1].get_i1() - S[level].get_i2());
S[level].set_i2(S[level - 1].get_i1());
while( R.size() ) {
if( Q.size() + R.end().get_degree() > QMAX.size() ) {
Q.push(R.end().get_i());
Vertices Rp(R.size());
cut2(R, Rp);
if( Rp.size() ) {
if( (float)S[level].get_i1()/++pk < Tlimit ) {
degree_sort(Rp);
}
color_sort(Rp);
S[level].inc_i1();
level++;
expand_dyn(Rp);
level--;
}
else if( Q.size() > QMAX.size() ) {
QMAX = Q;
}
Rp.dispose();
Q.pop();
}
else{
return;
}
R.pop();
}
}
// *************************************************
char getResidueName( const char* res ){
for( int i = 0 ; i < aa_size ; i++ ){
if( strcmp( tc_aa[i], res ) == 0 ){
return oc_aa[i];
}
}
return 'X';
}
void setBLOSUN62Map(){
//C S T P A G N D E Q H R K M I L V F Y W
blosum62_map.insert( pair< char, int > ( 'C', 0 ) );
blosum62_map.insert( pair< char, int > ( 'S', 1 ) );
blosum62_map.insert( pair< char, int > ( 'T', 2 ) );
blosum62_map.insert( pair< char, int > ( 'P', 3 ) );
blosum62_map.insert( pair< char, int > ( 'A', 4 ) );
blosum62_map.insert( pair< char, int > ( 'G', 5 ) );
blosum62_map.insert( pair< char, int > ( 'N', 6 ) );
blosum62_map.insert( pair< char, int > ( 'D', 7 ) );
blosum62_map.insert( pair< char, int > ( 'E', 8 ) );
blosum62_map.insert( pair< char, int > ( 'Q', 9 ) );
blosum62_map.insert( pair< char, int > ( 'H', 10 ) );
blosum62_map.insert( pair< char, int > ( 'R', 11 ) );
blosum62_map.insert( pair< char, int > ( 'K', 12 ) );
blosum62_map.insert( pair< char, int > ( 'M', 13 ) );
blosum62_map.insert( pair< char, int > ( 'I', 14 ) );
blosum62_map.insert( pair< char, int > ( 'L', 15 ) );
blosum62_map.insert( pair< char, int > ( 'V', 16 ) );
blosum62_map.insert( pair< char, int > ( 'F', 17 ) );
blosum62_map.insert( pair< char, int > ( 'Y', 18 ) );
blosum62_map.insert( pair< char, int > ( 'W', 19 ) );
}
int getValueBLOSUN62Map( char res ){
blosum62_map_iter = blosum62_map.find( res );
if( blosum62_map_iter == blosum62_map.end() )
return -1;
return blosum62_map_iter->second;
}
int getNumberOfResidues( string filename ){
char buffer[100];
int num_residue = 0;
FILE *pInputFile = fopen( filename.c_str(), "r" );
while( fgets( buffer, 100, pInputFile ) != NULL ){
if( buffer[0] == 'T' || buffer[0] == 'E' )
break;
if( buffer[0] == 'A' && buffer[1] == 'T' && buffer[13] == 'C' && buffer[14] == 'A' ){
num_residue++;
}
}
fclose( pInputFile );
return num_residue;
}
void readCAAtomWithSideChainCentroidFromPDBFile( string filename, vector< Atom * > &vStruct ){
char buffer[100];
Atom *atom;
char res[4];
char resSeq[5];
char X_char[9], Y_char[9], Z_char[9];
FILE *pInputFile = fopen( filename.c_str(), "r" );
int num_CA_atoms = 0;
int num_sc_atoms = 0;
double sum_sc_X = 0;
double sum_sc_Y = 0;
double sum_sc_Z = 0;
while( fgets( buffer, 100, pInputFile ) != NULL ){
if( buffer[0] == 'T' || buffer[0] == 'E' ){
if( num_sc_atoms == 0 ){
atom->SR[0] = atom->R[0];
atom->SR[1] = atom->R[1];
atom->SR[2] = atom->R[2];
}
else{
atom->SR[0] = sum_sc_X/num_sc_atoms;
atom->SR[1] = sum_sc_Y/num_sc_atoms;
atom->SR[2] = sum_sc_Z/num_sc_atoms;
}
vStruct.push_back( atom );
break;
}
if( buffer[0] == 'A' && buffer[1] == 'T' && buffer[13] == 'C' && buffer[14] == 'A' ){
num_CA_atoms++;
if( num_CA_atoms > 1 ){
if( num_sc_atoms == 0 ){
atom->SR[0] = atom->R[0];
atom->SR[1] = atom->R[1];
atom->SR[2] = atom->R[2];
}
else{
atom->SR[0] = sum_sc_X/num_sc_atoms;
atom->SR[1] = sum_sc_Y/num_sc_atoms;
atom->SR[2] = sum_sc_Z/num_sc_atoms;
}
vStruct.push_back( atom );
num_sc_atoms = 0;
sum_sc_X = 0;
sum_sc_Y = 0;
sum_sc_Z = 0;
}
// Residue name
for( int i = 0 ; i < 3 ; i++ ){
res[i] = buffer[17+i];
}
res[3] = '\0';
// Residue sequence
for( int i = 0 ; i < 4 ; i++ )
resSeq[i] = buffer[22+i];
resSeq[4] = '\0';
// Coordinates
for( int i = 0 ; i < 8 ; i++ ){
X_char[i] = buffer[30+i];
Y_char[i] = buffer[38+i];
Z_char[i] = buffer[46+i];
}
X_char[8] = '\0';
Y_char[8] = '\0';
Z_char[8] = '\0';
atom = new Atom();
atom->res_name = getResidueName( res );
atom->res_Seq = (int)atof( resSeq );
atom->R[0] = (double)atof( X_char );
atom->R[1] = (double)atof( Y_char );
atom->R[2] = (double)atof( Z_char );
}
if( buffer[0] == 'A' && buffer[1] == 'T' && !( buffer[13] == 'N' && buffer[14] == ' ' ) && !( buffer[13] == 'C' && buffer[14] == 'A' )
&& !( buffer[13] == 'C' && buffer[14] == ' ' ) && !( buffer[13] == 'O' && buffer[14] == ' ' ) ){
num_sc_atoms++;
// Coordinates
for( int i = 0 ; i < 8 ; i++ ){
X_char[i] = buffer[30+i];
Y_char[i] = buffer[38+i];
Z_char[i] = buffer[46+i];
}
X_char[8] = '\0';
Y_char[8] = '\0';
Z_char[8] = '\0';
sum_sc_X += (double)atof( X_char );
sum_sc_Y += (double)atof( Y_char );
sum_sc_Z += (double)atof( Z_char );
}
}
fclose( pInputFile );
}
void readChemicalFeatures( string filename, vector< Atom * > &vStruct ){
char buffer[100];
Atom *atom;
char res[4];
char resSeq[5];
char cf[2];
char X_char[9], Y_char[9], Z_char[9];
FILE *pInputFile = fopen( filename.c_str(), "r" );
while( fgets( buffer, 100, pInputFile ) != NULL ){
if( buffer[0] == 'T' || buffer[0] == 'E' )
break;
if( buffer[0] == 'A' && buffer[1] == 'T' ){
// Residue name
for( int i = 0 ; i < 3 ; i++ ){
res[i] = buffer[17+i];
}
res[3] = '\0';
// Residue sequence
for( int i = 0 ; i < 4 ; i++ )
resSeq[i] = buffer[22+i];
resSeq[4] = '\0';
// Chemical feature
cf[0] = buffer[13];
cf[1] = buffer[14];
// Coordinates
for( int i = 0 ; i < 8 ; i++ ){
X_char[i] = buffer[30+i];
Y_char[i] = buffer[38+i];
Z_char[i] = buffer[46+i];
}
X_char[8] = '\0';
Y_char[8] = '\0';
Z_char[8] = '\0';
atom = new Atom();
atom->res_name = getResidueName( res );
atom->res_Seq = (int)atof( resSeq );
atom->cf[0] = cf[0];
atom->cf[1] = cf[1];
atom->R[0] = (double)atof( X_char );
atom->R[1] = (double)atof( Y_char );
atom->R[2] = (double)atof( Z_char );
vStruct.push_back( atom );
}
}
fclose( pInputFile );
}
void setSecondaryStructure( string filename, vector< Atom * > &vStruct ){
char buffer[100];
int i = -1;
FILE *pInputFile = fopen( filename.c_str(), "r" );
while( fgets( buffer, 100, pInputFile ) != NULL ){
i++;
if( buffer[0] == 'T' || buffer[0] == 'E' )
break;
vStruct[i]->ss = buffer[13];
}
fclose( pInputFile );
}
void readCAAtomsFromPDBFile( string filename, vector< Atom * > &vStruct ){
char buffer[100];
Atom *atom;
char res[4];
char resSeq[5];
char X_char[9], Y_char[9], Z_char[9];
FILE *pInputFile = fopen( filename.c_str(), "r" );
while( fgets( buffer, 100, pInputFile ) != NULL ){
if( buffer[0] == 'T' || buffer[0] == 'E' )
break;
if( buffer[0] == 'A' && buffer[1] == 'T' && buffer[13] == 'C' && buffer[14] == 'A' ){
// Residue name
for( int i = 0 ; i < 3 ; i++ ){
res[i] = buffer[17+i];
}
res[3] = '\0';
// Residue sequence
for( int i = 0 ; i < 4 ; i++ )
resSeq[i] = buffer[22+i];
resSeq[4] = '\0';
// Coordinates
for( int i = 0 ; i < 8 ; i++ ){
X_char[i] = buffer[30+i];
Y_char[i] = buffer[38+i];
Z_char[i] = buffer[46+i];
}
X_char[8] = '\0';
Y_char[8] = '\0';
Z_char[8] = '\0';
atom = new Atom();
atom->res_name = getResidueName( res );
atom->res_Seq = (int)atof( resSeq );
atom->R[0] = (double)atof( X_char );
atom->R[1] = (double)atof( Y_char );
atom->R[2] = (double)atof( Z_char );
vStruct.push_back( atom );
}