source: branches/ali/RNA3D/RNA3D_StructureData.cxx

Last change on this file was 19206, checked in by westram, 3 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 45.3 KB
Line 
1#include "RNA3D_GlobalHeader.hxx"
2#include "RNA3D_Global.hxx"
3#include "RNA3D_OpenGLGraphics.hxx"
4#include "RNA3D_Graphics.hxx"
5#include "RNA3D_StructureData.hxx"
6
7#include <cerrno>
8#include <string>
9#include <iostream>
10#include <fstream>
11
12#include <arbdbt.h>
13#include <aw_msg.hxx>
14#include <aw_awars.hxx>
15#include <aw_root.hxx>
16#include <ed4_extern.hxx>
17#include <ed4_plugins.hxx>
18#include <BI_basepos.hxx>
19#include <arb_global_defs.h>
20
21
22#define COLORLINK (ED4_G_SBACK_0 - RNA3D_GC_SBACK_0)  // to link to the colors defined in primary editor ed4_defs.hxx
23#define SAICOLORS (ED4_G_CBACK_0 - RNA3D_GC_CBACK_0)
24
25using namespace std;
26
27static Struct3Dinfo   *start3D                 = NULp;
28static Struct2Dinfo   *start2D                 = NULp;
29static Struct2Dplus3D *start2D3D               = NULp;
30static HelixNrInfo    *start                   = NULp;
31static CurrSpecies    *startSp                 = NULp;
32static bool            bOldSpeciesDataExists   = false;
33static Insertions     *startIns                = NULp;
34static bool            bOldInsertionDataExists = false;
35static bool            bStartPosStored         = false;
36static bool            bEndPosStored           = false;
37
38inline bool is_Gap(char c) {
39    return GAP::is_std_gap(c); // @@@ use AWAR defined gaps?
40}
41
42static char *find_data_file(const char *name) {
43    char *fname = GB_lib_file(false, "rna3d/", name);
44    if (!fname) throw string("file not found: ")+name;
45    return fname;
46}
47
48static void throw_IO_error(const char *filename) __ATTR__NORETURN;
49static void throw_IO_error(const char *filename) {
50    string error = string("IO-Error: ")+strerror(errno)+" ('"+filename+"')";
51    throw error;
52}
53
54GBDATA *Structure3D::gb_main = NULp;
55
56Structure3D::Structure3D(ED4_plugin_host& host_)
57    : strCen(new Vector3(0.0, 0.0, 0.0)),
58      iInterval(25),
59      iMapSAI(0),
60      iMapSearch(0),
61      iMapEnable(0),
62      iStartPos(0),
63      iEndPos(0),
64      iEColiStartPos(0),
65      iEColiEndPos(0),
66      iTotalSubs(0),
67      iTotalDels(0),
68      iTotalIns(0),
69      LSU_molID(3), // default molecule to load in case of 23S rRNA : 1C2W
70      HelixBase(500),
71      EColiRef(NULp),
72      Host(host_),
73      GRAPHICS(new OpenGLGraphics)
74{}
75
76Structure3D::~Structure3D() {
77    delete GRAPHICS;
78    delete strCen;
79}
80
81
82void Structure3D::StoreCoordinates(float x, float y, float z, char base, unsigned int pos) {
83    Struct3Dinfo *data, *temp;
84    data = new Struct3Dinfo;
85    data->x    = x;
86    data->y    = y;
87    data->z    = z;
88    data->base = base;
89    data->pos  = pos;
90    data->next = NULp;
91
92    if (!start3D)
93        start3D = data;
94    else {
95        temp = start3D;
96        // We know this is not NULp - list not empty!
97        while (temp->next) {
98            temp = temp->next;  // Move to next link in chain
99        }
100        temp->next = data;
101    }
102}
103
104// ------------------Selecting rRNA type--------------------------//
105
106int Structure3D::FindTypeOfRNA() { // @@@ should better return an enum type
107    int       rnaType    = 0;
108    GB_ERROR  error      = GB_push_transaction(gb_main);
109    GBDATA   *gbTemplate = GBT_find_SAI(gb_main, "ECOLI");
110
111    if (!gbTemplate) {
112        error = "SAI:ECOLI not found";
113    }
114    else {
115        char *ali_name = GBT_get_default_alignment(gb_main);
116        if (!ali_name) {
117            error = GB_await_error();
118        }
119        else {
120            GBDATA *gbAlignment       = GB_entry(gbTemplate, ali_name);
121            GBDATA *gbTemplateSeqData = gbAlignment ? GB_entry(gbAlignment, "data") : NULp;
122
123            if (!gbTemplateSeqData) {
124                error = "Could not find ECOLI sequence data in the database!";
125            }
126            else {
127                const char *pTemplateSeqData  = GB_read_char_pntr(gbTemplateSeqData);
128                int iSeqLen = strlen(pTemplateSeqData);
129                int iBaseCount = 0;
130                for (int i = 0; i<iSeqLen; i++) {
131                    if (!is_Gap(pTemplateSeqData[i])) {
132                        iBaseCount++;
133                    }
134                }
135
136                if (iBaseCount > 2000)      rnaType = LSU_23S;
137                else if (iBaseCount > 300)  rnaType = SSU_16S;
138                else                        rnaType = LSU_5S;
139            }
140            free(ali_name);
141        }
142    }
143
144    error = GB_end_transaction(gb_main, error);
145    aw_message_if(error);
146
147    return rnaType;
148}
149
150// ----------Delete old molecule data-------------------------------//
151// Struct2Dinfo, Struct2Dplus3D, Struct3Dinfo, HelixNrInfo, Insertions
152
153void Structure3D::DeleteOldMoleculeData() {
154    // Struct2Dinfo -> start2D
155    {
156        Struct2Dinfo *tmp, *data;
157        for (data = start2D; data; data = tmp) {
158            tmp = data->next;
159            delete data;
160        }
161        start2D = NULp;
162    }
163
164    // Struct2Dplus3D ->start2D3D
165    {
166        Struct2Dplus3D *tmp, *data;
167        for (data = start2D3D; data; data = tmp) {
168            tmp = data->next;
169            delete data;
170        }
171        start2D3D = NULp;
172    }
173
174    // Struct3Dinfo ->start3D
175    {
176        Struct3Dinfo *tmp, *data;
177        for (data = start3D; data; data = tmp) {
178            tmp = data->next;
179            delete data;
180        }
181        start3D = NULp;
182    }
183
184    // HelixNrInfo -> start
185    {
186        HelixNrInfo *tmp, *data;
187        for (data = start; data; data = tmp) {
188            tmp = data->next;
189            delete data;
190        }
191        start = NULp;
192    }
193
194    // Delete insertions data
195    DeleteOldInsertionData();
196
197    // Delete mapped species data
198    DeleteOldSpeciesData ();
199}
200
201// =========== Reading 3D Coordinates from PDB file ====================//
202
203static char globalComment[1000];
204
205void Structure3D::ReadCoOrdinateFile() {
206    static char *DataFile = NULp;
207    int          rnaType  = FindTypeOfRNA();
208
209    RNA3D->bDisplayComments = true; // displaying comments in main window
210
211    switch (rnaType) {
212    case LSU_23S:
213        switch (LSU_molID) {
214        case _1PNU:
215            DataFile = find_data_file("Ecoli_1PNU_23S_rRNA.pdb");
216            sprintf(globalComment, "The 3D molecule rendered from PDB entry : 1PNU at 8.7 Angstrom.");
217            break;
218        case _1VOR:
219            DataFile = find_data_file("Ecoli_1VOR_23S_rRNA.pdb");
220            sprintf(globalComment, "The 3D molecule is rendered from PDB entry [1VOR] with 11.5 Angstrom resolution.");
221            break;
222        case _1C2W:
223            DataFile = find_data_file("Ecoli_1C2W_23S_rRNA.pdb");
224            sprintf(globalComment, "The 3D molecule is rendered from PDB entry [1C2W] with 7.5 Angstrom resolution.");
225            break;
226        }
227        break;
228    case LSU_5S:
229        DataFile = find_data_file("Ecoli_1C2X_5S_rRNA.pdb");
230        sprintf(globalComment, "The 3D molecule is rendered from PDB entry [1C2X] with 7.5 Angstrom resolution.");
231        break;
232    case SSU_16S:
233        DataFile = find_data_file("Ecoli_1M5G_16S_rRNA.pdb");
234        sprintf(globalComment, "The 3D molecule is rendered from PDB entry [1M5G] with 11.5 Angstrom resolution.");
235        break;
236    }
237
238    ifstream readData;
239    readData.open(DataFile, ios::in);
240    if (!readData.is_open()) {
241        throw_IO_error(DataFile);
242    }
243
244    int          cntr                 = 0;
245    unsigned int last3Dpos            = 0;
246    static bool  bEColiStartPosStored = false;
247
248    while (!readData.eof()) {
249        char buf[256];
250        readData.getline(buf, 100);
251
252        string line(buf);
253        if ((line.find("ATOM") != string::npos) || (line.find("HETATM") != string::npos)) {
254            string atom = line.substr(77, 2);
255            if (atom.find("P") != string::npos) {
256                char     base = line[19];
257                unsigned pos  = atoi(line.substr(22, 4).c_str());
258
259                // special filter for 23S rRNA structure (IVOR/IPNU)
260                // IVOR/IPNU contains artifacts and are not mentioned in any of the
261                // remarks of PDB file
262                if (last3Dpos != pos && !(pos >= 3093)) {
263                    float X = atof(line.substr(31, 8).c_str());
264                    float Y = atof(line.substr(39, 8).c_str());
265                    float Z = atof(line.substr(47, 8).c_str());
266
267                    StoreCoordinates(X, Y, Z, base, pos);
268                    last3Dpos  = pos;
269                    strCen->x += X; strCen->y += Y; strCen->z += Z;
270                    cntr++;
271                }
272                if (!bEColiStartPosStored) {
273                    iEColiStartPos = pos;
274                    bEColiStartPosStored = true;
275                }
276                iEColiEndPos = pos;
277            }
278        }
279    }
280
281    cout<<"--------------------------------------------------"<<endl
282        <<globalComment<<endl
283        <<"Structure contains "<<iEColiEndPos-iEColiStartPos<<"( "<<iEColiStartPos<<" - "
284        <<iEColiEndPos<<" ) positions."<<endl
285        <<"---------------------------------------------------"<<endl;
286
287    strCen->x = strCen->x/cntr;
288    strCen->y = strCen->y/cntr;
289    strCen->z = strCen->z/cntr;
290
291    readData.close();
292    free(DataFile);
293}
294
295
296void Structure3D::Store2Dinfo(char *info, int pos, int helixNr) {
297    Struct2Dinfo *data = new Struct2Dinfo;
298
299    data->base    = info[0];
300    data->mask    = info[1];
301    data->code    = info[2];
302    data->pos     = pos;
303    data->helixNr = helixNr;
304
305    data->next = NULp;
306
307    if (!start2D) {
308        start2D = data;
309    }
310    else {
311        Struct2Dinfo *temp = start2D;
312        // We know this is not NULp - list not empty!
313        while (temp->next) {
314            temp = temp->next;  // Move to next link in chain
315        }
316        temp->next = data;
317    }
318}
319
320// =========== Reading Secondary Structure Data from Ecoli Secondary Structure Mask file ====================//
321
322void Structure3D::GetSecondaryStructureInfo() {
323    static char *DataFile = NULp;
324    int          rnaType  = FindTypeOfRNA();
325
326    switch (rnaType) {
327        case LSU_23S:
328            DataFile = find_data_file("SecondaryStructureModel_23SrRNA.data");
329            break;
330        case LSU_5S:
331            DataFile = find_data_file("SecondaryStructureModel_5SrRNA.data");
332            break;
333        case SSU_16S:
334            DataFile = find_data_file("SecondaryStructureModel_16SrRNA.data");
335            break;
336    }
337
338    char  buf[256];
339
340    int  pos         = 0;
341    int  helixNr     = 0;
342    int  lastHelixNr = 0;
343    char info[4];
344    info[3]          = '\0';
345    bool insideHelix = false;
346    bool skip        = false;
347
348    ifstream readData;
349    readData.open(DataFile, ios::in);
350    if (!readData.is_open()) {
351        throw_IO_error(DataFile);
352    }
353
354    while (!readData.eof()) {
355        readData.getline(buf, 100);
356        char *tmp;
357        tmp = strtok(buf, " ");
358        for (int i = 0; tmp; tmp = strtok(NULp, " "), i++) {
359            switch (i) {
360                case 0: pos = atoi(tmp);      break;
361                case 1: info[0] = tmp[0];     break;
362                case 2: info[1] = tmp[0];     break;
363                case 3: info[2] = tmp[0];     break;
364                case 4: helixNr = atoi(tmp); break;
365            }
366        }
367
368        bool is_SE = (info[2] == 'S') || (info[2] == 'E'); // 'S' = helix start 'E' = helix end
369        if (is_SE) {
370            if (helixNr>0) lastHelixNr = helixNr;
371
372            if (!insideHelix) insideHelix = true;
373            else {
374                Store2Dinfo(info, pos, lastHelixNr);
375                skip        = true;
376                insideHelix = false;
377            }
378        }
379        if (insideHelix) Store2Dinfo(info, pos, lastHelixNr);
380        else {
381            if (skip) skip = false;
382            else Store2Dinfo(info, pos, 0);
383        }
384    }
385    readData.close();
386    free(DataFile);
387}
388
389void Structure3D::Store2D3Dinfo(Struct2Dinfo *s2D, Struct3Dinfo *s3D) {
390    Struct2Dplus3D *data, *temp;
391    data = new Struct2Dplus3D;
392    data->base    = s2D->base;
393    data->mask    = s2D->mask;
394    data->code    = s2D->code;
395    data->pos     = s2D->pos;
396    data->helixNr = s2D->helixNr;
397    data->x       = s3D->x;
398    data->y       = s3D->y;
399    data->z       = s3D->z;
400    data->next    = NULp;
401
402    if (!start2D3D)
403        start2D3D = data;
404    else {
405        temp = start2D3D;
406        while (temp->next) {
407            temp = temp->next;
408        }
409        temp->next = data;
410    }
411}
412
413// =========== Combining Secondary Structure Data with 3D Coordinates =======================//
414
415void Structure3D::Combine2Dand3DstructureInfo() {
416    Struct3Dinfo *temp3D;
417    Struct2Dinfo *temp2D;
418    int cntr = 0;
419
420    cout<<"Missing Base Positions : "<<endl;
421
422    temp3D = start3D;
423    temp2D = start2D;
424    while (temp3D && temp2D) {
425        if (temp2D->pos == temp3D->pos) {
426            Store2D3Dinfo(temp2D, temp3D);
427        }
428        else {
429            while (temp2D->pos != temp3D->pos) {
430                cout<<temp2D->pos<<", "; // missing base positions
431                cntr++;
432                temp2D = temp2D->next;
433            }
434            Store2D3Dinfo(temp2D, temp3D);
435        }
436
437        temp3D = temp3D->next;
438        temp2D = temp2D->next;
439    }
440    cout<<endl<<"Total No. of bases missing = "<<cntr<<endl;
441
442    // printing comments in the main window
443    {
444        RNA3D->bDisplayComments = true;
445        char buf[256];
446        sprintf(buf, "Total No. of bases missing = %d. See the console messages for the actual missing base positions.", cntr);
447        strcat(globalComment, buf);
448    }
449}
450
451void Structure3D::PointsToQuads(float x, float y, float z) {
452
453    if (RNA3D->bPointSpritesSupported) {
454        glVertex3f(x, y, z);
455    }
456    else {
457        glBegin(GL_QUADS);
458        // Front Face
459        glTexCoord2f(0, 0); glVertex3f(x - 1, y + 1, z + 1);
460        glTexCoord2f(1, 0); glVertex3f(x + 1, y + 1, z + 1);
461        glTexCoord2f(1, 1); glVertex3f(x + 1, y - 1, z + 1);
462        glTexCoord2f(0, 1); glVertex3f(x - 1, y - 1, z + 1);
463
464        // Back Face
465        glTexCoord2f(0, 0); glVertex3f(x + 1, y + 1, z - 1);
466        glTexCoord2f(1, 0); glVertex3f(x - 1, y + 1, z - 1);
467        glTexCoord2f(1, 1); glVertex3f(x - 1, y - 1, z - 1);
468        glTexCoord2f(0, 1); glVertex3f(x + 1, y - 1, z - 1);
469
470        // Top Face
471        glTexCoord2f(0, 0); glVertex3f(x + 1, y + 1, z + 1);
472        glTexCoord2f(1, 0); glVertex3f(x - 1, y + 1, z + 1);
473        glTexCoord2f(1, 1); glVertex3f(x - 1, y + 1, z - 1);
474        glTexCoord2f(0, 1); glVertex3f(x + 1, y + 1, z - 1);
475
476        // Bottom Face
477        glTexCoord2f(0, 0); glVertex3f(x + 1, y - 1, z - 1);
478        glTexCoord2f(1, 0); glVertex3f(x - 1, y - 1, z - 1);
479        glTexCoord2f(1, 1); glVertex3f(x - 1, y - 1, z + 1);
480        glTexCoord2f(0, 1); glVertex3f(x + 1, y - 1, z + 1);
481
482        // Left Face
483        glTexCoord2f(0, 0); glVertex3f(x + 1, y + 1, z + 1);
484        glTexCoord2f(1, 0); glVertex3f(x + 1, y + 1, z - 1);
485        glTexCoord2f(1, 1); glVertex3f(x + 1, y - 1, z - 1);
486        glTexCoord2f(0, 1); glVertex3f(x + 1, y - 1, z + 1);
487
488        // Right Face
489        glTexCoord2f(0, 0); glVertex3f(x - 1, y + 1, z - 1);
490        glTexCoord2f(1, 0); glVertex3f(x - 1, y + 1, z + 1);
491        glTexCoord2f(1, 1); glVertex3f(x - 1, y - 1, z + 1);
492        glTexCoord2f(0, 1); glVertex3f(x - 1, y - 1, z - 1);
493
494        glEnd();
495    }
496}
497
498void Structure3D::PositionsToCoordinatesDispList(int listID, int *pos, int len) {
499    Struct2Dplus3D *t;
500    int tmpPos = 0;
501
502    glNewList(listID, GL_COMPILE);
503    {
504        if (RNA3D->bPointSpritesSupported) {
505            glBegin(GL_POINTS);
506        }
507        for (int i = 0; i < len; i++) {
508            tmpPos = pos[i];
509            t = start2D3D;
510            while (t) {
511                if (t->pos == tmpPos) {
512                    PointsToQuads(t->x, t->y, t->z);
513                    break;
514                }
515                t = t->next;
516            }
517        }
518        if (RNA3D->bPointSpritesSupported) {
519            glEnd();
520        }
521    }
522    glEndList();
523}
524
525void Structure3D::GenerateSecStructureNonHelixRegions() {
526    Struct2Dplus3D *t;
527    const int MAX_BASE = 1000;
528    int baseA[MAX_BASE], baseG[MAX_BASE], baseC[MAX_BASE], baseU[MAX_BASE];
529    int a, g, c, u; a=g=c=u=0;
530
531    {
532        t = start2D3D;
533        while (t) {
534            if (t->helixNr == 0) {
535                switch (t->base) {
536                    case 'A': baseA[a++] = t->pos; break;
537                    case 'G': baseG[g++] = t->pos; break;
538                    case 'C': baseC[c++] = t->pos; break;
539                    case 'U': baseU[u++] = t->pos; break;
540                }
541            }
542            t = t->next;
543        }
544    }
545
546    PositionsToCoordinatesDispList(NON_HELIX_A, baseA, a);
547    PositionsToCoordinatesDispList(NON_HELIX_G, baseG, g);
548    PositionsToCoordinatesDispList(NON_HELIX_C, baseC, c);
549    PositionsToCoordinatesDispList(NON_HELIX_U, baseU, u);
550}
551
552void Structure3D::GenerateSecStructureHelixRegions() {
553    Struct2Dplus3D *t;
554    const int MAX_BASE = 1000;
555    int baseA[MAX_BASE], baseG[MAX_BASE], baseC[MAX_BASE], baseU[MAX_BASE];
556    int a, g, c, u; a=g=c=u=0;
557
558    {
559        t = start2D3D;
560        while (t) {
561            if (t->helixNr > 0) {
562                if ((t->mask == '[') || (t->mask == ']') || (t->mask == '<') || (t->mask == '>')) {
563                    switch (t->base) {
564                        case 'A': baseA[a++] = t->pos; break;
565                        case 'G': baseG[g++] = t->pos; break;
566                        case 'C': baseC[c++] = t->pos; break;
567                        case 'U': baseU[u++] = t->pos; break;
568                    }
569                }
570            }
571            t = t->next;
572        }
573    }
574
575    PositionsToCoordinatesDispList(HELIX_A, baseA, a);
576    PositionsToCoordinatesDispList(HELIX_G, baseG, g);
577    PositionsToCoordinatesDispList(HELIX_C, baseC, c);
578    PositionsToCoordinatesDispList(HELIX_U, baseU, u);
579}
580
581void Structure3D::GenerateSecStructureUnpairedHelixRegions() {
582    Struct2Dplus3D *t;
583    const int MAX_BASE = 500;
584    int baseA[MAX_BASE], baseG[MAX_BASE], baseC[MAX_BASE], baseU[MAX_BASE];
585    int a, g, c, u; a=g=c=u=0;
586
587    {
588        t = start2D3D;
589        while (t) {
590            if (t->helixNr > 0) {
591                if (t->mask == '.') {
592                    switch (t->base) {
593                        case 'A': baseA[a++] = t->pos; break;
594                        case 'G': baseG[g++] = t->pos; break;
595                        case 'C': baseC[c++] = t->pos; break;
596                        case 'U': baseU[u++] = t->pos; break;
597                    }
598                }
599            }
600            t = t->next;
601        }
602    }
603
604    PositionsToCoordinatesDispList(UNPAIRED_HELIX_A, baseA, a);
605    PositionsToCoordinatesDispList(UNPAIRED_HELIX_G, baseG, g);
606    PositionsToCoordinatesDispList(UNPAIRED_HELIX_C, baseC, c);
607    PositionsToCoordinatesDispList(UNPAIRED_HELIX_U, baseU, u);
608}
609
610// ==============================================================================
611// Tertiary Interactions of 16S ribosomal RNA model of E.coli.
612// Reference : http://www.rna.icmb.utexas.edu/
613// Year of Last Update : 2001.
614// Pseudoknots and Triple Base pairs are extracted and displayed in
615// the 3D model.
616// ==============================================================================
617
618void Structure3D::GenerateTertiaryInteractionsDispLists() {
619    Struct2Dplus3D *t;
620    static char    *DataFile = NULp;
621    int             rnaType  = FindTypeOfRNA();
622
623    switch (rnaType) {
624        case LSU_23S:
625            DataFile = find_data_file("TertiaryInteractions_23SrRNA.data");
626            break;
627        case LSU_5S:
628            cout<<"There are no tertiary interactions observed in 5S rRNA model!"<<endl;
629            return;
630        case SSU_16S:
631            DataFile = find_data_file("TertiaryInteractions_16SrRNA.data");
632            break;
633    }
634
635    cout<<"Tertiary Interactions are fetched from comparative RNA website [http://www.rna.icmb.utexas.edu]."<<endl
636        <<"The same are located in the file \""<<DataFile<<"\"."<<endl;
637
638    char  buf[256];
639
640    ifstream readData;
641    readData.open(DataFile, ios::in);
642    if (!readData.is_open()) {
643        throw_IO_error(DataFile);
644    }
645
646    int K[100];
647    int R[100];
648    int k, r; k = r = 0;
649
650    while (!readData.eof()) {
651        readData.getline(buf, 100);
652        char *tmp;
653        tmp = strtok(buf, " ");
654        if (tmp) {
655            if (strcmp(tmp, "KNOT") == 0) {
656                tmp = strtok(NULp, ":");
657                while (tmp) {
658                    K[k++] = atoi(tmp);
659                    tmp = strtok(NULp, ":");
660                }
661            }
662            else if (strcmp(tmp, "TRIPLE") == 0) {
663                tmp = strtok(NULp, ":");
664                while (tmp) {
665                    R[r++] = atoi(tmp);
666                    tmp = strtok(NULp, ":");
667                }
668            }
669        }
670    }
671    readData.close();
672
673    glNewList(ECOLI_TERTIARY_INTRACTION_PSEUDOKNOTS, GL_COMPILE);
674    {
675        for (int i = 0; i < k;) {
676            glBegin(GL_LINES);
677            for (int j = 0; j < 2; j++) {
678                t = start2D3D;
679                while (t) {
680                    if (t->pos == K[i]) {
681                        glVertex3f(t->x, t->y, t->z);
682                        i++;
683                        break;
684                    }
685                    t = t->next;
686                }
687            }
688            glEnd();
689        }
690    }
691    glEndList();
692
693    glNewList(ECOLI_TERTIARY_INTRACTION_TRIPLE_BASES, GL_COMPILE);
694    {
695        for (int i = 0; i < r;) {
696            glBegin(GL_LINE_STRIP);
697            for (int j = 0; j < 3; j++) {
698                t = start2D3D;
699                while (t) {
700                    if (t->pos == R[i]) {
701                        glVertex3f(t->x, t->y, t->z);
702                        i++;
703                        break;
704                    }
705                    t = t->next;
706                }
707            }
708            glEnd();
709        }
710    }
711    glEndList();
712    free(DataFile);
713}
714
715// ==============================================================================
716
717void Structure3D::StoreHelixNrInfo(float x, float y, float z, int helixNr) {
718    HelixNrInfo *data, *temp;
719    data = new HelixNrInfo;
720    data->helixNr = helixNr;
721    data->x       = x;
722    data->y       = y;
723    data->z       = z;
724    data->next    = NULp;
725
726    if (!start)
727        start = data;
728    else {
729        temp = start;
730        while (temp->next) {
731            temp = temp->next;
732        }
733        temp->next = data;
734    }
735}
736
737void Structure3D::GenerateHelixDispLists(int HELIX_NR_ID, int HELIX_NR) {
738    Struct2Dinfo *temp2D;
739    Struct2Dplus3D *temp2D3D;
740
741    const int MAX = 500;
742
743    int thisStrandPos[MAX], otherStrandPos[MAX];
744    int i, j; i = j = 0;
745    {
746        temp2D = start2D;
747        while (temp2D) {
748            if (temp2D->helixNr == HELIX_NR) {
749                if ((temp2D->mask == '[') || (temp2D->mask == '<'))
750                    thisStrandPos[i++]  = temp2D->pos;
751                if ((temp2D->mask == ']') || (temp2D->mask == '>'))
752                    otherStrandPos[j++] = temp2D->pos;
753            }
754            temp2D = temp2D->next;
755        }
756    }
757
758    int tempPos = 0;
759    float x1, x2, y1, y2, z1, z2; x1=x2=y1=y2=z1=z2=0.0;
760
761    bool bThisStrand, bOtherStrand;
762    bThisStrand = bOtherStrand = false;
763
764    bool bMissingBasePair = false;
765
766    glNewList(HELIX_NR_ID, GL_COMPILE);
767    {
768        for (int k = 0, l = j-1; k < i && l >= 0; k++, l--) {
769            tempPos = thisStrandPos[k];
770            {
771                temp2D3D = start2D3D;
772                while (temp2D3D) {
773                    if (temp2D3D->pos == tempPos) {
774                        bThisStrand = true;
775                        x1=temp2D3D->x; y1=temp2D3D->y; z1=temp2D3D->z;
776                        break;
777                    }
778                    temp2D3D = temp2D3D->next;
779                }
780            }
781            tempPos = otherStrandPos[l];
782            {
783                temp2D3D = start2D3D;
784                while (temp2D3D) {
785                    if (temp2D3D->pos == tempPos) {
786                        bOtherStrand = true;
787                        x2=temp2D3D->x; y2=temp2D3D->y; z2=temp2D3D->z;
788                        break;
789                    }
790                    temp2D3D = temp2D3D->next;
791                }
792            }
793            // if bases present in both the strands then draw a bond
794            // and store the helix number information
795            if (bThisStrand && bOtherStrand) {
796                glVertex3f(x1, y1, z1);
797                glVertex3f(x2, y2, z2);
798
799                x1 = (x1+x2)/2; y1 = (y1+y2)/2; z1 = (z1+z2)/2;
800                StoreHelixNrInfo(x1, y1, z1, HELIX_NR);
801
802                bThisStrand = bOtherStrand = false;
803            }
804            else {
805                bMissingBasePair = true;
806                cout<<thisStrandPos[k]<<"-"<<tempPos<<"("<<HELIX_NR_ID<<"), ";
807            }
808        }
809        if (bMissingBasePair) cout<<endl;
810    }
811    glEndList();
812}
813
814void Structure3D::GenerateHelixNrDispList(int startHx, int endHx) {
815    HelixNrInfo *t;
816
817    glNewList(HELIX_NUMBERS, GL_COMPILE);
818    {
819        char POS[50];
820        for (int i = startHx; i <= endHx; i++) {
821            t = start;
822            while (t) {
823                if (t->helixNr == i) {
824                    sprintf(POS, "%d", t->helixNr);
825                    GRAPHICS->PrintString(t->x, t->y, t->z, POS, GLUT_BITMAP_8_BY_13);
826                }
827                t = t->next;
828            }
829        }
830    }
831    glEndList();
832
833    glNewList(HELIX_NUMBERS_POINTS, GL_COMPILE);
834    {
835        if (RNA3D->bPointSpritesSupported) {
836            glBegin(GL_POINTS);
837        }
838        for (int i = startHx; i <= endHx; i++) {
839            t = start;
840            while (t) {
841                if (t->helixNr == i) {
842                    PointsToQuads(t->x, t->y, t->z);
843                }
844                t = t->next;
845            }
846        }
847        if (RNA3D->bPointSpritesSupported) {
848            glEnd();
849        }
850    }
851    glEndList();
852}
853
854void Structure3D::GenerateDisplayLists() {
855
856    GenerateMoleculeSkeleton();
857    ComputeBasePositions();
858
859    int rnaType = FindTypeOfRNA();
860    switch (rnaType) {
861    case SSU_16S:
862        if (glIsList(HelixBase) != GL_TRUE) {
863            for (int i = 1; i <= 50; i++) {
864                GenerateHelixDispLists(HelixBase+i, i);
865            }
866        }
867        break;
868    case LSU_23S:
869        cout<<"=========================================================="<<endl
870            <<"Missing base pairs (bracket number indicates helix number) "<<endl;
871        if (glIsList(HelixBase) != GL_TRUE) {
872            for (int i = 1; i <= 101; i++) {
873                GenerateHelixDispLists(HelixBase+i, i);
874            }
875        }
876        cout<<"=========================================================="<<endl;
877        break;
878    case LSU_5S:
879        if (glIsList(HelixBase) != GL_TRUE) {
880            for (int i = 1; i <= 5; i++) {
881                GenerateHelixDispLists(HelixBase+i, i);
882            }
883        }
884        break;
885    }
886
887    GenerateSecStructureHelixRegions();
888    GenerateSecStructureNonHelixRegions();
889    GenerateSecStructureUnpairedHelixRegions();
890
891    GenerateTertiaryInteractionsDispLists();
892}
893
894void Structure3D::GenerateMoleculeSkeleton() {
895    Struct2Dplus3D *t;
896
897    glNewList(STRUCTURE_BACKBONE, GL_COMPILE);
898    {
899        glBegin(GL_LINE_STRIP);
900        t = start2D3D;
901        while (t) {
902            glVertex3f(t->x, t->y, t->z);
903            t = t->next;
904        }
905        glEnd();
906    }
907    glEndList();
908
909    glNewList(STRUCTURE_BACKBONE_CLR, GL_COMPILE);
910    {
911        glBegin(GL_LINE_STRIP);
912        t = start2D3D;
913        while (t) {
914            if (t->helixNr > 0) {
915                if ((t->mask == '[') || (t->mask == ']') || (t->mask == '<') || (t->mask == '>')) {
916                    GRAPHICS->SetColor(RNA3D_GC_BASES_HELIX);
917                    glVertex3f(t->x, t->y, t->z);
918                }
919                if (t->mask == '.') {
920                    GRAPHICS->SetColor(RNA3D_GC_BASES_UNPAIRED_HELIX);
921                    glVertex3f(t->x, t->y, t->z);
922                }
923            }
924            if (t->helixNr == 0) {
925                GRAPHICS->SetColor(RNA3D_GC_BASES_NON_HELIX);
926                glVertex3f(t->x, t->y, t->z);
927            }
928            t = t->next;
929        }
930        glEnd();
931    }
932    glEndList();
933}
934
935void Structure3D::GenerateCursorPositionDispList(long pos) {
936    Struct3Dinfo *temp;
937
938    glNewList(ECOLI_CURSOR_POSITION, GL_COMPILE);
939    {
940        glBegin(GL_POINTS);
941        temp = start3D;
942        while (temp) {
943            if (temp->pos == pos) {
944#ifdef DEBUG
945                cout<<"Cursor Position : "<<pos<<endl;
946#endif
947                glVertex3f(temp->x, temp->y, temp->z);
948                break;
949            }
950            temp = temp->next;
951        }
952        glEnd();
953    }
954    glEndList();
955}
956
957void Structure3D::ComputeBasePositions() {
958    Struct3Dinfo *temp;
959
960    char POS[50];
961    float spacer = 1.5;
962    int posSkip = iInterval;
963    if (posSkip <= 0) posSkip = 25; // default interval value
964
965    glNewList(STRUCTURE_POS, GL_COMPILE);
966    {
967        temp = start3D;
968        while (temp) {
969            if (temp->pos%posSkip == 0) {
970                sprintf(POS, "%d", temp->pos);
971                GRAPHICS->PrintString(temp->x-spacer, temp->y, temp->z-spacer, POS, GLUT_BITMAP_HELVETICA_10);
972            }
973            temp = temp->next;
974        }
975    }
976    glEndList();
977
978    glNewList(STRUCTURE_POS_ANCHOR, GL_COMPILE);
979    {
980        glLineWidth(0.5);
981        glBegin(GL_LINES);
982        temp = start3D;
983        while (temp) {
984            if (temp->pos%posSkip == 0) {
985                glVertex3f(temp->x, temp->y, temp->z);
986                glVertex3f(temp->x-spacer, temp->y, temp->z-spacer);
987            }
988            temp = temp->next;
989        }
990        glEnd();
991    }
992    glEndList();
993}
994
995// [
996// removed function Structure3D::PrepareSecondaryStructureData()
997// - did read data from files in Yadhus account
998// - was unused
999// (stored in VC.. :)
1000// ]
1001
1002void Structure3D::StoreCurrSpeciesDifference(char base, int pos) {
1003    Struct2Dplus3D *st;
1004    st = start2D3D;
1005    while (st) {
1006        if (st->pos == pos) {
1007            CurrSpecies *data, *temp;
1008            data = new CurrSpecies;
1009            data->base = base;
1010            data->pos  = pos;
1011            data->x = st->x;
1012            data->y = st->y;
1013            data->z = st->z;
1014            data->next = NULp;
1015
1016            if (!startSp) {
1017                startSp = data;
1018                bOldSpeciesDataExists = true;
1019            }
1020            else {
1021                temp = startSp;
1022                while (temp->next) {
1023                    temp = temp->next;
1024                }
1025                temp->next = data;
1026            }
1027            break;
1028        }
1029        st = st->next;
1030    }
1031}
1032
1033void Structure3D::DeleteOldSpeciesData() {
1034    CurrSpecies *tmp, *data;
1035
1036    for (data = startSp; data; data = tmp) {
1037        tmp = data->next;
1038        delete data;
1039    }
1040    startSp = NULp;
1041
1042    bOldSpeciesDataExists = false;
1043}
1044
1045void Structure3D::GenerateBaseDifferencePositionDisplayList() {
1046    CurrSpecies *t;
1047    Struct3Dinfo *temp;
1048
1049    char POS[50];
1050    float spacer = 1.5;
1051
1052    glNewList(MAP_SPECIES_BASE_DIFFERENCE_POS, GL_COMPILE);
1053    {
1054        for (t = startSp; t; t = t->next) {
1055            for (temp = start3D; temp; temp = temp->next) {
1056                if (temp->pos == t->pos) {
1057                    sprintf(POS, "%d", temp->pos);
1058                    GRAPHICS->PrintString(temp->x-spacer, temp->y, temp->z-spacer, POS, GLUT_BITMAP_8_BY_13);
1059                }
1060            }
1061        }
1062    }
1063    glEndList();
1064
1065    glNewList(MAP_SPECIES_BASE_DIFFERENCE_POS_ANCHOR, GL_COMPILE);
1066    {
1067        glLineWidth(1.0);
1068        glBegin(GL_LINES);
1069
1070        for (t = startSp; t; t = t->next) {
1071            for (temp = start3D; temp; temp = temp->next) {
1072                if (temp->pos == t->pos) {
1073                    glVertex3f(temp->x, temp->y, temp->z);
1074                    glVertex3f(temp->x-spacer, temp->y, temp->z-spacer);
1075                }
1076            }
1077        }
1078        glEnd();
1079    }
1080    glEndList();
1081}
1082
1083void Structure3D::BuildDisplayList(int listID, int *pos, int len) {
1084    CurrSpecies *t;
1085    int tmpPos = 0;
1086
1087    glNewList(listID, GL_COMPILE);
1088    {
1089        if (RNA3D->bPointSpritesSupported) {
1090            glBegin(GL_POINTS);
1091        }
1092        for (int i = 0; i < len; i++) {
1093            tmpPos = pos[i];
1094            t = startSp;
1095            while (t) {
1096                if (t->pos == tmpPos) {
1097                    PointsToQuads(t->x, t->y, t->z);
1098                    break;
1099                }
1100                t = t->next;
1101            }
1102        }
1103        if (RNA3D->bPointSpritesSupported) {
1104            glEnd();
1105        }
1106    }
1107    glEndList();
1108}
1109
1110void Structure3D::GenerateBaseDifferenceDisplayList() {
1111    CurrSpecies *t;
1112
1113    glNewList(MAP_SPECIES_BASE_DIFFERENCE, GL_COMPILE);
1114    {
1115        if (RNA3D->bPointSpritesSupported) {
1116            glBegin(GL_POINTS);
1117        }
1118        t = startSp;
1119        while (t) {
1120            PointsToQuads(t->x, t->y, t->z);
1121            t = t->next;
1122        }
1123        if (RNA3D->bPointSpritesSupported) {
1124            glEnd();
1125        }
1126    }
1127    glEndList();
1128
1129    const int MAX_BASE = 400;
1130    int baseA[MAX_BASE], baseG[MAX_BASE], baseC[MAX_BASE],
1131        baseU[MAX_BASE], deletion[MAX_BASE], miss[MAX_BASE];
1132    int a, g, c, u, d, m; a=g=c=u=d=m=0;
1133
1134    {
1135        t = startSp;
1136        while (t) {
1137            switch (t->base) {
1138                case 'A': baseA[a++]     = t->pos; break;
1139                case 'G': baseG[g++]     = t->pos; break;
1140                case 'C': baseC[c++]     = t->pos; break;
1141                case 'U': baseU[u++]     = t->pos; break;
1142                case '-': deletion[d++] = t->pos; break;
1143                case '.': miss[m++] = t->pos; break;
1144            }
1145            t = t->next;
1146        }
1147        BuildDisplayList(MAP_SPECIES_BASE_A, baseA, a);
1148        BuildDisplayList(MAP_SPECIES_BASE_U, baseU, u);
1149        BuildDisplayList(MAP_SPECIES_BASE_G, baseG, g);
1150        BuildDisplayList(MAP_SPECIES_BASE_C, baseC, c);
1151        BuildDisplayList(MAP_SPECIES_DELETION, deletion, d);
1152        BuildDisplayList(MAP_SPECIES_MISSING, miss, m);
1153        GenerateBaseDifferencePositionDisplayList();
1154
1155        iTotalSubs = a+g+c+u;  // Summing up the substitutions/mutations
1156        iTotalDels = d;        // Storing total number of deletions
1157#ifdef DEBUG
1158        cout<<"Substitutions = "<<iTotalSubs<<endl;
1159        cout<<"Deletions     = "<<iTotalDels<<endl;
1160#endif
1161    }
1162}
1163
1164void Structure3D::StoreInsertions(char base, int pos) {
1165    Insertions *data, *temp;
1166    data = new Insertions;
1167    data->base = base;
1168    data->pos  = pos;
1169    data->next = NULp;
1170
1171    if (!startIns) {
1172        startIns = data;
1173        bOldInsertionDataExists = true;
1174    }
1175    else {
1176        temp = startIns;
1177        while (temp->next) {
1178            temp = temp->next;
1179        }
1180        temp->next = data;
1181    }
1182}
1183
1184void Structure3D::DeleteOldInsertionData() {
1185    Insertions *tmp, *data;
1186
1187    for (data = startIns; data; data = tmp) {
1188        tmp = data->next;
1189        delete data;
1190    }
1191    startIns = NULp;
1192
1193    bOldInsertionDataExists = false;
1194}
1195
1196void Structure3D::GenerateInsertionDisplayList() {
1197    Insertions   *ins;
1198    Struct3Dinfo *str;
1199    char inserts[500];
1200    int i, cntr;
1201    float spacer = 2.0;
1202    iTotalIns = 0;
1203
1204    glNewList(MAP_SPECIES_INSERTION_BASES, GL_COMPILE);
1205    {
1206        for (str = start3D; str; str = str->next) {
1207            i = cntr = 0;
1208            for (ins = startIns; ins; ins = ins->next) {
1209                if (str->pos == ins->pos) {
1210                    inserts[i++] = ins->base;
1211                    cntr++;
1212                }
1213            }
1214            if (cntr>0) {
1215                inserts[i] = '\0';
1216                char buffer[strlen(inserts) + 10];
1217                sprintf(buffer, "%d:%s", cntr, inserts);
1218                GRAPHICS->PrintString(str->x, str->y+spacer, str->z,
1219                                      buffer, GLUT_BITMAP_8_BY_13);
1220
1221                iTotalIns += cntr; // Summing up the insertions
1222            }
1223        }
1224    }
1225    glEndList();
1226
1227#ifdef DEBUG
1228    cout<<"Insertions = "<<iTotalIns<<endl;
1229#endif
1230
1231    glNewList(MAP_SPECIES_INSERTION_BASES_ANCHOR, GL_COMPILE);
1232    {
1233        glLineWidth(1.0);
1234        glBegin(GL_LINES);
1235
1236        for (str = start3D; str; str = str->next) {
1237            for (ins = startIns; ins; ins = ins->next) {
1238                if (str->pos == ins->pos) {
1239                    glVertex3f(str->x, str->y, str->z);
1240                    glVertex3f(str->x, str->y+spacer, str->z);
1241                }
1242            }
1243        }
1244        glEnd();
1245    }
1246    glEndList();
1247
1248    glNewList(MAP_SPECIES_INSERTION_POINTS, GL_COMPILE);
1249    {
1250        if (RNA3D->bPointSpritesSupported) {
1251            glBegin(GL_POINTS);
1252        }
1253        for (str = start3D; str; str = str->next) {
1254            for (ins = startIns; ins; ins = ins->next) {
1255                if (str->pos == ins->pos) {
1256                    PointsToQuads(str->x, str->y, str->z);
1257                    break;
1258                }
1259            }
1260        }
1261        if (RNA3D->bPointSpritesSupported) {
1262            glEnd();
1263        }
1264    }
1265    glEndList();
1266}
1267
1268void Structure3D::MapCurrentSpeciesToEcoliTemplate(AW_root *awr) {
1269    GB_ERROR error = GB_push_transaction(gb_main);
1270
1271    if (!error) {
1272        GBDATA *gbTemplate = GBT_find_SAI(gb_main, "ECOLI");
1273
1274        if (!gbTemplate) {
1275            error = "SAI:ECOLI not found";
1276        }
1277        else {
1278            char *pSpeciesName = awr->awar(AWAR_SPECIES_NAME)->read_string();
1279            if (pSpeciesName) {
1280                Host.announce_current_species(pSpeciesName);
1281                GBDATA *gbSpecies = GBT_find_species(gb_main, pSpeciesName);
1282                if (gbSpecies) {
1283                    char *ali_name = GBT_get_default_alignment(gb_main);
1284                    if (!ali_name) {
1285                        error = GB_await_error();
1286                    }
1287                    else {
1288                        GBDATA *gbAlignment       = GB_entry(gbTemplate, ali_name);
1289                        GBDATA *gbTemplateSeqData = gbAlignment ? GB_entry(gbAlignment, "data") : NULp;
1290
1291                        if (!gbTemplateSeqData) {
1292                            error = GBS_global_string("Mapping impossible, since SAI:ECOLI has no data in alignment '%s'", ali_name);
1293                        }
1294                        else {
1295                            const char *pTemplateSeqData  = GB_read_char_pntr(gbTemplateSeqData);
1296
1297                            if (!RNA3D->bEColiRefInitialized) {
1298                                EColiRef = new BI_ecoli_ref;
1299                                EColiRef->init(gb_main);
1300                                RNA3D->bEColiRefInitialized = true;
1301                            }
1302
1303                            char buf[100];
1304                            char *pSpFullName = GB_read_string(GB_entry(gbSpecies, "full_name"));
1305                            sprintf(buf, "%s : %s", pSpeciesName, pSpFullName);
1306                            awr->awar(AWAR_3D_SELECTED_SPECIES)->write_string(buf);
1307
1308                            GBDATA *gbSeqData    = GBT_find_sequence(gbSpecies, ali_name);
1309                            const char *pSeqData = GB_read_char_pntr(gbSeqData);
1310
1311                            if (pSeqData && pTemplateSeqData) {
1312                                int iSeqLen = strlen(pTemplateSeqData);
1313
1314                                if (bOldSpeciesDataExists) {
1315                                    DeleteOldSpeciesData();
1316                                }
1317
1318                                for (int i = 0, iSeqCount = 0; i<iSeqLen; i++) {
1319                                    if (!is_Gap(pTemplateSeqData[i])) {
1320                                        if (!bStartPosStored) {
1321                                            iStartPos = i;
1322                                            bStartPosStored = true;
1323                                        }
1324                                        if (pTemplateSeqData[i] != pSeqData[i]) {
1325                                            StoreCurrSpeciesDifference(pSeqData[i], iSeqCount);
1326                                        }
1327                                        iSeqCount++;
1328                                    }
1329                                }
1330
1331                                for (int i = iSeqLen; i>0; i--) {
1332                                    if (!is_Gap(pTemplateSeqData[i])) {
1333                                        if (!bEndPosStored) {
1334                                            iEndPos = i;
1335                                            bEndPosStored = true;
1336                                            break;
1337                                        }
1338                                    }
1339                                }
1340
1341                                if (bOldInsertionDataExists) {
1342                                    DeleteOldInsertionData();
1343                                }
1344
1345                                for (int i = iStartPos, iSeqCount = 0; i < iEndPos; i++) {
1346                                    if (!is_Gap(pTemplateSeqData[i])) {
1347                                        // Store EColi base positions : Insertion point!
1348                                        iSeqCount++;
1349                                    }
1350
1351                                    if ((pTemplateSeqData[i] == '-') && !is_Gap(pSeqData[i])) {
1352                                        StoreInsertions(pSeqData[i], iSeqCount);
1353                                    }
1354                                }
1355                            }
1356                            free(pSpFullName);
1357                        }
1358                        free(ali_name);
1359                    }
1360                }
1361                GenerateBaseDifferenceDisplayList();
1362                GenerateInsertionDisplayList();
1363            }
1364            free(pSpeciesName);
1365        }
1366    }
1367
1368    error = GB_end_transaction(gb_main, error);
1369    aw_message_if(error);
1370}
1371
1372static bool ValidSearchColor(int iColor, int mode) {
1373    bool isValid = false;
1374
1375    switch (mode) {
1376        case SAI:    isValid = (iColor >= RNA3D_GC_CBACK_0) && (iColor < RNA3D_GC_MAX); break;
1377        case SEARCH: isValid = (iColor >= RNA3D_GC_SBACK_0) && (iColor < RNA3D_GC_MAX); break;
1378    }
1379    return isValid;
1380}
1381
1382void Structure3D::MapSearchStringsToEcoliTemplate(AW_root * /* awr */) {
1383    const char *pSearchColResults = NULp;
1384
1385    if (iMapSearch) pSearchColResults = Host.get_search_background(iStartPos, iEndPos);
1386
1387    if (pSearchColResults) {
1388        int iColor = 0;
1389
1390        glNewList(MAP_SEARCH_STRINGS_TO_STRUCTURE, GL_COMPILE);
1391        {
1392            if (RNA3D->bPointSpritesSupported) glBegin(GL_POINTS);
1393            for (int i = iStartPos; i < iEndPos; i++) {
1394                if (RNA3D->bEColiRefInitialized) {
1395                    long absPos   = (long) i;
1396                    long EColiPos = EColiRef->abs_2_rel(absPos);
1397
1398                    for (Struct3Dinfo *t = start3D; t; t = t->next) {
1399                        if ((t->pos == EColiPos) && (pSearchColResults[i] >= 0)) {
1400                            iColor = pSearchColResults[i] - COLORLINK;
1401
1402                            if (ValidSearchColor(iColor, SEARCH)) {
1403                                RNA3D->cGraphics->SetColor(iColor);
1404                                PointsToQuads(t->x, t->y, t->z);
1405                            }
1406                            break;
1407                        }
1408                    }
1409                }
1410            }
1411            if (RNA3D->bPointSpritesSupported) glEnd();
1412        }
1413        glEndList();
1414
1415        glNewList(MAP_SEARCH_STRINGS_BACKBONE, GL_COMPILE);
1416        {
1417            int iLastClr = 0; int iLastPos = 0; Vector3 vLastPt;
1418            glBegin(GL_LINES);
1419            for (int i = iStartPos; i < iEndPos; i++) {
1420                if (RNA3D->bEColiRefInitialized) {
1421                    long absPos   = (long) i;
1422                    long EColiPos = EColiRef->abs_2_rel(absPos);
1423
1424                    for (Struct3Dinfo *t = start3D; t; t = t->next) {
1425                        if ((t->pos == EColiPos) && (pSearchColResults[i] >= 0)) {
1426                            iColor = pSearchColResults[i] - COLORLINK;
1427
1428                            if (ValidSearchColor(iColor, SEARCH)) {
1429                                if ((iLastClr == iColor) && (iLastPos == EColiPos-1)) {
1430                                    RNA3D->cGraphics->SetColor(iColor);
1431                                    glVertex3f(vLastPt.x, vLastPt.y, vLastPt.z);
1432                                    glVertex3f(t->x, t->y, t->z);
1433                                }
1434                                iLastPos = EColiPos;
1435                                iLastClr = iColor;
1436                                vLastPt.x = t->x; vLastPt.y = t->y; vLastPt.z = t->z;
1437                            }
1438                            break;
1439                        }
1440                    }
1441                }
1442            }
1443            glEnd();
1444        }
1445        glEndList();
1446
1447        RNA3D->bMapSearchStringsDispListCreated = true;
1448    }
1449    else cout<<"BuildColorString did not get the colors : SAI cannot be Visualized!"<<endl;
1450}
1451
1452void Structure3D::MapSaiToEcoliTemplate() {
1453    const char *pSearchColResults = NULp;
1454
1455    if (iMapSAI && Host.SAIs_visualized()) {
1456        pSearchColResults = Host.get_SAI_background(iStartPos, iEndPos); // returns 0 if sth went wrong
1457    }
1458
1459    if (pSearchColResults) {
1460        int iColor = 0;
1461
1462        glNewList(MAP_SAI_TO_STRUCTURE, GL_COMPILE);
1463        {
1464            if (RNA3D->bPointSpritesSupported) glBegin(GL_POINTS);
1465
1466            for (int i = iStartPos; i < iEndPos; i++) {
1467                if (RNA3D->bEColiRefInitialized) {
1468                    long absPos   = (long) i;
1469                    long EColiPos = EColiRef->abs_2_rel(absPos);
1470
1471                    for (Struct3Dinfo *t = start3D; t; t = t->next) {
1472                        if ((t->pos == EColiPos) && (pSearchColResults[i] >= 0)) {
1473                            iColor = pSearchColResults[i-1] - SAICOLORS;
1474
1475                            if (ValidSearchColor(iColor, SAI)) {
1476                                RNA3D->cGraphics->SetColor(iColor);
1477                                PointsToQuads(t->x, t->y, t->z);
1478                            }
1479                            break;
1480                        }
1481                    }
1482                }
1483            }
1484
1485            if (RNA3D->bPointSpritesSupported) glEnd();
1486        }
1487        glEndList();
1488
1489        RNA3D->bMapSaiDispListCreated = true;
1490    }
1491    else cout<<"ED4_getSaiColorString did not get the colors : SAI cannot be Visualized!"<<endl;
1492}
Note: See TracBrowser for help on using the repository browser.