~ubuntu-branches/ubuntu/precise/ncbi-tools6/precise

« back to all changes in this revision

Viewing changes to biostruc/newvast/vastchkid.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vastchkid.c
 
2
 *
 
3
 * ===========================================================================
 
4
 *
 
5
 *                            PUBLIC DOMAIN NOTICE
 
6
 *            National Center for Biotechnology Information (NCBI)
 
7
 *
 
8
 *  This software/database is a "United States Government Work" under the
 
9
 *  terms of the United States Copyright Act.  It was written as part of
 
10
 *  the author's official duties as a United States Government employee and
 
11
 *  thus cannot be copyrighted.  This software/database is freely available
 
12
 *  to the public for use. The National Library of Medicine and the U.S.
 
13
 *  Government do not place any restriction on its use or reproduction.
 
14
 *  We would, however, appreciate having the NCBI and the author cited in
 
15
 *  any work or product based on this material
 
16
 *
 
17
 *  Although all reasonable efforts have been taken to ensure the accuracy
 
18
 *  and reliability of the software and data, the NLM and the U.S.
 
19
 *  Government do not and cannot warrant the performance or results that
 
20
 *  may be obtained by using this software or data. The NLM and the U.S.
 
21
 *  Government disclaim all warranties, express or implied, including
 
22
 *  warranties of performance, merchantability or fitness for any particular
 
23
 *  purpose.
 
24
 *
 
25
 * ===========================================================================
 
26
 *
 
27
 * File Name: vastchkid.c
 
28
 *
 
29
 * Author: Yanli Wang 
 
30
 *
 
31
 * Version Creation Date: 6/16/98
 
32
 *
 
33
 * $Log: vastchkid.c,v $
 
34
 * Revision 1.1.1.1  2002/12/06 20:17:21  chenj
 
35
 * Imported Scouces
 
36
 *
 
37
 * Revision 6.7  2000/05/26 22:31:40  ywang
 
38
 * assign local for various types of seq features
 
39
 *
 
40
 * Revision 6.6  1999/07/21 22:33:43  ywang
 
41
 * assign local id to seq-annot
 
42
 *
 
43
 * Revision 6.5  1998/12/22 18:01:52  addess
 
44
 * changes relevant to reading new type of annot-set data
 
45
 *
 
46
 * Revision 6.4  1998/11/27  16:54:05  addess
 
47
 * made change to AssignLocaIdToSeqAlignMaster as suggested by Hugues
 
48
 *
 
49
 * Revision 6.3  1998/10/21  15:42:16  ywang
 
50
 * to simplify extraction of vast alignment clique number
 
51
 *
 
52
 * Revision 6.2  1998/10/14  17:21:42  addess
 
53
 * for sending aligned chains from vastsearch
 
54
 *
 
55
 * Revision 6.1  1998/07/17  18:42:33  madej
 
56
 * Handles local sequence IDs.
 
57
 *
 
58
 *
 
59
 */
 
60
#include <stdio.h>
 
61
#include <ncbi.h>
 
62
#include <accentr.h>
 
63
#include <objalign.h>
 
64
#include <objseq.h>
 
65
#include <objmgr.h>
 
66
#include <lsqfetch.h>
 
67
#include <netentr.h>
 
68
#include <www.h>
 
69
#include <sys/resource.h>
 
70
#include <mmdbapi.h>
 
71
#include <mmdbapi1.h>
 
72
#include "vastlocl.h"
 
73
#include "mmdblocl.h"
 
74
#include "mmdbdata.h"
 
75
#include "vast2mage.h"
 
76
#include "vastsrv.h"
 
77
#include <asnmime.h>
 
78
#include <objmime.h>
 
79
#include <strimprt.h>
 
80
 
 
81
#define Local_max 20 
 
82
Char pSegmentMaster[Local_max];
 
83
/*--------------- find PDBSeqId ------------------*/
 
84
PDBSeqIdPtr GetPdbSeqId(SeqIdPtr sip)
 
85
              /* may need to be modified according to how bioseq id is */
 
86
{
 
87
  SeqIdPtr  seq_id = NULL;
 
88
  PDBSeqIdPtr pdb_seq_id = NULL;
 
89
 
 
90
  seq_id = sip;
 
91
 
 
92
  while(seq_id != NULL){
 
93
     if(seq_id->choice == 15){
 
94
        pdb_seq_id = seq_id->data.ptrvalue;
 
95
        break;
 
96
     }
 
97
     seq_id = seq_id->next;
 
98
  }
 
99
 
 
100
  return(pdb_seq_id);
 
101
}
 
102
/***************************************************************************/                                                                       
 
103
/*            GetLocalId() Ken                                            */
 
104
/***************************************************************************/
 
105
ObjectIdPtr GetLocalId(SeqIdPtr sip)
 
106
{
 
107
  ObjectIdPtr oip = NULL;
 
108
  SeqIdPtr seq_id = NULL;
 
109
 
 
110
  seq_id = sip;
 
111
 
 
112
  while(seq_id != NULL)
 
113
  {
 
114
     if (seq_id->choice == 1)
 
115
     {
 
116
        oip = seq_id->data.ptrvalue;
 
117
        break;
 
118
     }
 
119
     seq_id = seq_id->next;
 
120
  }
 
121
  
 
122
  return oip;
 
123
}
 
124
/*---------------- remove redundancy sequences ---------------*/ 
 
125
SeqEntryPtr ExtractThisSep(SeqEntryPtr sepThis, Char Chain)
 
126
{
 
127
  SeqEntryPtr sepThisNew = NULL;
 
128
  BioseqPtr bsp = NULL;
 
129
  BioseqSetPtr bssp = NULL;
 
130
  PDBSeqIdPtr pdb_seq_id;
 
131
  ObjectIdPtr object_id;
 
132
 
 
133
  Int2 choice;
 
134
  Char ThisChain;
 
135
 
 
136
  sepThisNew = SeqEntryNew();
 
137
  sepThisNew->choice = 1;
 
138
 
 
139
  choice = sepThis->choice;
 
140
  if(choice == 1) {
 
141
     sepThisNew->data.ptrvalue = sepThis->data.ptrvalue;
 
142
     return (sepThisNew);
 
143
  }
 
144
  else if(choice == 2){
 
145
     bssp = sepThis->data.ptrvalue;
 
146
     sepThis = bssp->seq_set;
 
147
 
 
148
     while(sepThis != NULL){
 
149
        bsp = sepThis->data.ptrvalue;
 
150
        if (bsp->id->choice == 15)
 
151
        {
 
152
          pdb_seq_id = GetPdbSeqId(bsp->id);
 
153
          if(pdb_seq_id->chain !=NULL) ThisChain = (Char) pdb_seq_id->chain;
 
154
          else ThisChain = ' ';
 
155
        }
 
156
        if (bsp->id->choice == 1)
 
157
        {
 
158
          object_id = GetLocalId(bsp->id);
 
159
          if (object_id->str) ThisChain = object_id->str[5];
 
160
        }
 
161
 
 
162
        if(ThisChain == Chain) {
 
163
           sepThisNew->data.ptrvalue = bsp;
 
164
           return (sepThisNew);
 
165
        }
 
166
 
 
167
        sepThis = sepThis->next;
 
168
     }
 
169
  }
 
170
 
 
171
}
 
172
/*---------------- make a new SeqEntry ------------------------*/
 
173
NcbiMimeAsn1Ptr ScreenSequence( NcbiMimeAsn1Ptr pvnNcbi, CharPtr JobID)
 
174
{
 
175
  BiostrucAlignPtr pbsaStruct = NULL;
 
176
  BiostrucAnnotSetPtr pbsaThis = NULL, pbsaHead = NULL;
 
177
  BiostrucFeatureSetPtr pbsfsThis = NULL;
 
178
  BiostrucFeaturePtr pbsfThis = NULL;
 
179
  SeqEntryPtr sepHead = NULL, sepHeadNew = NULL, sepThis = NULL;
 
180
 
 
181
  /*Char PDBName[Local_max], */
 
182
  Char Chain, Domain;
 
183
  CharPtr pSegmentSlave;
 
184
 
 
185
  pbsaStruct = pvnNcbi->data.ptrvalue;
 
186
 
 
187
  pbsaThis = pbsaStruct->alignments;
 
188
  pbsfsThis = pbsaThis->features;
 
189
  pbsfThis = pbsfsThis->features;
 
190
 
 
191
  StringNCpy(pSegmentMaster, pbsfThis->name, 6);
 
192
 /* StringNCpy(PDBName, pSegmentMaster, 4); */
 
193
  Chain = pSegmentMaster[4];
 
194
  
 
195
  sepHead = pbsaStruct->sequences;
 
196
  /*if(JobID){
 
197
     sepThis = SeqEntryNew();
 
198
     sepThis->choice = 1;
 
199
     sepThis->data.ptrvalue = sepHead->data.ptrvalue;
 
200
   }
 
201
  else */
 
202
  sepThis = ExtractThisSep(sepHead, Chain); 
 
203
  ValNodeLink(&sepHeadNew, sepThis);
 
204
 
 
205
  sepHead = sepHead->next;
 
206
  while(pbsfThis){
 
207
     pSegmentSlave = StringSave(&pbsfThis->name[7]);
 
208
     pSegmentSlave[6]='\0';
 
209
 
 
210
     /*StringNCpy(PDBName, pSegmentSlave, 4);*/
 
211
     Chain = pSegmentSlave[4];
 
212
 
 
213
     sepThis = ExtractThisSep(sepHead, Chain);
 
214
     ValNodeLink(&sepHeadNew, sepThis);
 
215
 
 
216
     pbsfThis = pbsfThis->next;
 
217
     sepHead = sepHead->next; 
 
218
  }
 
219
 
 
220
  pbsaStruct->sequences = sepHeadNew;
 
221
  MemFree(pSegmentSlave); 
 
222
 
 
223
  return(pvnNcbi);
 
224
}
 
225
/*---------------- replace original seq_id by local_id  --------------*/
 
226
void AssignLocaIdToBiostruc(SeqIdPtr sip, Char *PDBName, Char Chain,BiostrucPtr bsp)
 
227
{
 
228
  BiostrucDescrPtr pbsdrThis = NULL;
 
229
  MoleculeGraphPtr pmgThis = NULL;
 
230
  BiomolDescrPtr pbmdrThis = NULL;
 
231
 
 
232
  Char ThisPDBName[Local_max], *ThisChain;
 
233
 
 
234
  StringCpy(ThisPDBName, PDBNAME_DEFAULT);
 
235
  pbsdrThis = ValNodeFindNext(bsp->descr, NULL, BiostrucDescr_name);
 
236
  if(pbsdrThis) StringNCpy(ThisPDBName, pbsdrThis ->data.ptrvalue, 4);
 
237
 
 
238
/*if(StringCmp(PDBName, ThisPDBName) != 0) {
 
239
     printf("Something is wrong!\n");
 
240
     return;
 
241
  }  */
 
242
 
 
243
  pmgThis = bsp->chemical_graph->molecule_graphs;
 
244
 
 
245
  while(pmgThis) {
 
246
                     /* loop over molecule_graphs to match chain */ 
 
247
     pbmdrThis = ValNodeFindNext(pmgThis->descr, NULL, BiomolDescr_name);
 
248
     if(pbmdrThis){
 
249
        ThisChain = StringSave((CharPtr)pbmdrThis->data.ptrvalue); 
 
250
     }
 
251
     else ThisChain = StringSave(STRING_UNK_MOL);
 
252
     if(Chain == *ThisChain) {
 
253
        pmgThis->seq_id = sip; 
 
254
        return;
 
255
      }
 
256
 
 
257
     pmgThis = pmgThis->next;
 
258
  }
 
259
 
 
260
}
 
261
/***************************************************************************/                                                                       
 
262
/*            GetObjectId() Ken                                            */
 
263
/***************************************************************************/
 
264
ObjectIdPtr GetObjectId(BiostrucPtr bsp, CharPtr pSegmentThis)
 
265
{
 
266
  ObjectIdPtr oip;
 
267
  SeqIdPtr sip;
 
268
  MoleculeGraphPtr mgp;
 
269
  
 
270
  for (mgp = bsp->chemical_graph->molecule_graphs; mgp; mgp = mgp->next)
 
271
  {
 
272
    sip = mgp->seq_id;
 
273
    oip = (ObjectIdPtr)sip->data.ptrvalue;
 
274
    if (oip->str[5] == pSegmentThis[4]) break;
 
275
  }
 
276
  
 
277
  return oip;
 
278
}
 
279
/*--------------- check SeqId for each Bioseq -----------------*/
 
280
Boolean ReplaceBioseqId(SeqIdPtr sip, Char *PDBName, Char Chain, BioseqPtr bsp)
 
281
{
 
282
  PDBSeqIdPtr pdb_seq_id;
 
283
  Char ThisChain;
 
284
 
 
285
  SeqAnnotPtr sap = NULL;
 
286
  SeqFeatPtr sfp = NULL;
 
287
  SeqLocPtr slp = NULL;
 
288
  SeqIntPtr  sintp = NULL;
 
289
  SeqIdPtr  sip_temp = NULL;
 
290
 
 
291
  SeqLocPtr slp_mix = NULL;
 
292
  SeqPntPtr spp = NULL;
 
293
  SeqBondPtr sbp = NULL;
 
294
 
 
295
  pdb_seq_id = GetPdbSeqId(bsp->id);
 
296
          /* may need to be modified according to how bioseq id is */
 
297
          /* in bioseq fetched from Entrez, PDBSeqId exists, but not sure */
 
298
          /* how struc2seq works */
 
299
  if(pdb_seq_id->chain !=NULL) ThisChain = (Char) pdb_seq_id->chain;
 
300
  else ThisChain = ' ';
 
301
  
 
302
  if(ThisChain == Chain) {
 
303
     bsp->id = sip;
 
304
 
 
305
     sap = bsp->annot;
 
306
     if(sap == NULL) return TRUE;
 
307
     else if(sap->type == 1){
 
308
        sfp = sap->data;
 
309
        while(sfp){
 
310
           slp = sfp->location;
 
311
           if(slp != NULL ) {
 
312
              if(slp->choice == SEQLOC_INT) {
 
313
                 sintp = slp->data.ptrvalue;
 
314
                 if(sintp) {
 
315
                    sip_temp = sintp->id;
 
316
                    sintp->id = sip;
 
317
          /*        sip_temp = SeqIdFree(sip_temp); */
 
318
                 /* cause problem when slave is a duplication of master */
 
319
                 /* might be related to the way how the sequence is made */
 
320
                 /* or fetched */
 
321
                }
 
322
              }
 
323
              else if(slp->choice == SEQLOC_BOND){
 
324
                 sbp = slp->data.ptrvalue;
 
325
                 spp = sbp->a;
 
326
                 if(spp) spp->id = sip;
 
327
                 spp = sbp->b;
 
328
                 if(spp) spp->id = sip;
 
329
              }
 
330
              else if(slp->choice == SEQLOC_MIX){
 
331
                 slp_mix = slp->data.ptrvalue;
 
332
                 while(slp_mix){
 
333
                    if(slp_mix->choice == SEQLOC_INT){
 
334
                       sintp = slp_mix->data.ptrvalue;
 
335
                       if(sintp) sintp->id = sip;
 
336
                    }
 
337
                    else if(slp_mix->choice == SEQLOC_BOND){
 
338
                       sbp = slp_mix->data.ptrvalue;
 
339
                       spp = sbp->a;
 
340
                       if(spp) spp->id = sip;
 
341
                       spp = sbp->b;
 
342
                       if(spp) spp->id = sip;
 
343
                    }
 
344
                    slp_mix = slp_mix->next;
 
345
                 }
 
346
              }         
 
347
           }
 
348
           else return TRUE;
 
349
 
 
350
           sfp = sfp->next;
 
351
        }
 
352
     }     
 
353
 
 
354
     return TRUE;
 
355
  }
 
356
 
 
357
  else return FALSE;
 
358
 
 
359
}
 
360
/*---------------- replace original seq_id by local_id  --------------*/
 
361
void AssignLocaIdToBioseq(SeqIdPtr sip, Char *PDBName, Char Chain, SeqEntryPtr sep)
 
362
{
 
363
  BioseqPtr bsp;
 
364
  BioseqSetPtr bssp;
 
365
  Int2 choice;
 
366
 
 
367
  Boolean IdReplaced = FALSE;
 
368
 
 
369
  choice = sep->choice;
 
370
  if(choice == 1) {
 
371
     bsp = sep->data.ptrvalue;
 
372
     ReplaceBioseqId(sip, PDBName, Chain, bsp);
 
373
   }
 
374
   else if(choice == 2){
 
375
      bssp = sep->data.ptrvalue;
 
376
      sep = bssp->seq_set;
 
377
 
 
378
      while(sep != NULL){
 
379
         bsp = sep->data.ptrvalue;
 
380
         IdReplaced = ReplaceBioseqId(sip, PDBName, Chain, bsp); 
 
381
         if(IdReplaced) return;
 
382
         sep = sep->next;
 
383
      }
 
384
   }
 
385
   
 
386
}
 
387
/*---------------- replace original seq_id by local_id  --------------*/
 
388
void AssignLocaIdToSeqAlign(SeqIdPtr sip, Char *PDBName, Char Chain, SeqAlignPtr salpHead)
 
389
{
 
390
 
 
391
  DenseDiagPtr ddp = NULL;
 
392
  SeqIdPtr  sipThis = NULL;
 
393
  PDBSeqIdPtr pdb_seq_id;
 
394
  Char ThisChain;
 
395
 
 
396
  ddp = salpHead->segs;
 
397
 
 
398
  while(ddp){
 
399
     sipThis = ddp->id;
 
400
     sipThis = sipThis->next;
 
401
              /* get to the slave SeqId */
 
402
 
 
403
     pdb_seq_id = GetPdbSeqId(sipThis);
 
404
     if(pdb_seq_id != NULL){
 
405
        if(pdb_seq_id->chain !=NULL) ThisChain = (Char) pdb_seq_id->chain;
 
406
        else ThisChain = ' ';
 
407
        if(ThisChain == Chain) ddp->id->next = sip;
 
408
                       /* actually match chain here may not be neccessary */
 
409
     }
 
410
 
 
411
     ddp = ddp->next; 
 
412
 
 
413
  }
 
414
 
 
415
}
 
416
/*---------------- To put Local_id in segs for Vastsearch - Ken -----------*/
 
417
void AssignLocaIdToSeqAlignMaster(SeqIdPtr sip, SeqAlignPtr salpHead)
 
418
{
 
419
 
 
420
  DenseDiagPtr ddp;
 
421
  SeqIdPtr  sipTemp = NULL;
 
422
 
 
423
  ddp = salpHead->segs;
 
424
 
 
425
  while(ddp)
 
426
  {
 
427
     if(ddp->id!=NULL) {
 
428
        sipTemp = ddp->id->next;
 
429
        SeqIdFree(ddp->id);
 
430
        ddp->id = AsnIoMemCopy(sip, (AsnReadFunc) SeqIdAsnRead, (AsnWriteFunc) SeqIdAsnWrite);
 
431
        ddp->id->next = sipTemp;
 
432
     } else
 
433
        ErrPostEx(SEV_ERROR,0,0,"AssignLocalIdToSeqAlignMaster: No SeqId on SeqALign\n");
 
434
     ddp = ddp->next; 
 
435
  }
 
436
 
 
437
}
 
438
/*---------------- to check if an identical chain exist ----------------*/
 
439
Boolean FindIdSlave(Char *pSegmentThis, BiostrucFeaturePtr pbsfHead, Int4 iCount1)
 
440
{
 
441
  Int4 iCount2 = 0;
 
442
 
 
443
  if(StringNCmp(pSegmentThis, pSegmentMaster, 5) == 0){
 
444
                         /* only compare PDB code and Chain Id */
 
445
     return TRUE;
 
446
  }
 
447
  else if(iCount1 == 0) {
 
448
     return FALSE;
 
449
  }
 
450
 
 
451
  iCount2 = 0;
 
452
  while(pbsfHead){
 
453
     if(iCount2 >= iCount1) return FALSE;
 
454
     if(StringNCmp(pSegmentThis, pbsfHead->name + 7, 5) == 0) {
 
455
                          /* only compare PDB code and Chain Id */
 
456
        return TRUE;
 
457
     }
 
458
 
 
459
     iCount2++;
 
460
     pbsfHead = pbsfHead->next;
 
461
  }
 
462
 
 
463
  return FALSE;
 
464
 
 
465
 
466
/*---------------- make new LocalId ------------------------*/
 
467
SeqIdPtr MakeLocalId(Char *str)
 
468
{
 
469
  SeqIdPtr sip;
 
470
  ObjectIdPtr oip;
 
471
 
 
472
  oip = ObjectIdNew();
 
473
  oip->str = str;
 
474
 
 
475
  sip = ValNodeNew(NULL);
 
476
  sip->choice = SEQID_LOCAL;
 
477
  sip->data.ptrvalue = oip;     
 
478
 
 
479
  return(sip);
 
480
}
 
481
/*---------------- to assign local id to identical chain ---------------*/
 
482
NcbiMimeAsn1Ptr CheckId(NcbiMimeAsn1Ptr pvnNcbi, CharPtr JobID)
 
483
{
 
484
            /* to assign local id to identical chain so that to work around */
 
485
            /* object manager for messaging */  /* yanli */
 
486
 
 
487
  BiostrucAlignPtr pbsaStruct = NULL;
 
488
  BiostrucPtr pbsMaster = NULL, pbsSlaveHead = NULL;
 
489
  BiostrucAnnotSetPtr pbsaThis = NULL, pbsaHead = NULL;
 
490
  SeqAnnotPtr psaAlignHead = NULL; 
 
491
  SeqEntryPtr sepHead;
 
492
 
 
493
  BiostrucFeatureSetPtr pbsfsThis = NULL, pbsfsHead = NULL;
 
494
  BiostrucFeaturePtr pbsfThis = NULL, pbsfHead = NULL;
 
495
  SeqAlignPtr salpHead;
 
496
 
 
497
  SeqIdPtr sip, sip_cpy, sipMaster, sip_temp;
 
498
  ObjectIdPtr oipMaster, oip;
 
499
 
 
500
  Int4 iCount1 = 0, iCount_ID = 0;
 
501
  Boolean IdChainFound = FALSE;
 
502
 
 
503
  CharPtr pSegmentSlave;
 
504
  Char PDBName[Local_max], Chain, Domain; 
 
505
 
 
506
  Char AlignIdStr[Local_max];
 
507
  Int4 AlignId;    
 
508
 
 
509
  typedef struct local_string{
 
510
  Char str[Local_max];
 
511
  }Local_String, PNTR Local_StringPtr;
 
512
 
 
513
  Local_String **str; 
 
514
 
 
515
  pvnNcbi = ScreenSequence(pvnNcbi, JobID);
 
516
 
 
517
  pbsaStruct = pvnNcbi->data.ptrvalue;
 
518
  
 
519
  pbsaThis = pbsaStruct->alignments; 
 
520
  pbsSlaveHead = pbsaStruct->slaves;
 
521
  sepHead = pbsaStruct->sequences;
 
522
  psaAlignHead = pbsaStruct->seqalign;
 
523
 
 
524
  pbsfsThis = pbsaThis->features;
 
525
  pbsfThis = pbsfsThis->features;
 
526
                     /* from vastsrv page, we are always considering one */
 
527
                     /* domain of the master, so no loop for pbsfsThis */
 
528
 
 
529
  StringNCpy(pSegmentMaster, pbsfThis->name, 6);
 
530
  pSegmentMaster[6]='\0';
 
531
/*pSegmentMaster[0]=pbsfThis->name[0];
 
532
  pSegmentMaster[1]=pbsfThis->name[1];
 
533
  pSegmentMaster[2]=pbsfThis->name[2];
 
534
  pSegmentMaster[3]=pbsfThis->name[3];
 
535
  pSegmentMaster[4]=pbsfThis->name[4];
 
536
  pSegmentMaster[5]=pbsfThis->name[5];  
 
537
  pSegmentMaster[6]='\0';  */
 
538
 
 
539
  /* see if Master Sequence was generated by VastSearch - Ken*/ 
 
540
  if (JobID)
 
541
  {
 
542
    for (salpHead = psaAlignHead->data; salpHead; salpHead = salpHead->next)
 
543
    {
 
544
      oipMaster = ObjectIdNew();
 
545
      oipMaster = GetObjectId(pbsaStruct->master, pSegmentMaster);
 
546
    
 
547
      sipMaster = ValNodeNew(NULL);
 
548
      sipMaster->choice = SEQID_LOCAL;
 
549
      sipMaster->data.ptrvalue = oipMaster;
 
550
      AssignLocaIdToSeqAlignMaster(sipMaster, salpHead);
 
551
    }
 
552
  }
 
553
    
 
554
  salpHead = psaAlignHead->data;
 
555
             /* from SeqAnnot to SeqAlign */ 
 
556
  sepHead = sepHead->next;
 
557
              /* go to the slave sequences */ 
 
558
 
 
559
  iCount1 = 0;
 
560
  while(pbsfThis){
 
561
     pSegmentSlave = StringSave(&pbsfThis->name[7]);
 
562
     pSegmentSlave[6]='\0';
 
563
 
 
564
     IdChainFound = FindIdSlave(pSegmentSlave, pbsaThis->features->features, iCount1);
 
565
     if(IdChainFound) iCount_ID++;
 
566
     iCount1++;
 
567
     MemFree(pSegmentSlave);
 
568
     pbsfThis = pbsfThis->next;
 
569
  }
 
570
 
 
571
  str = (Pointer) MemNew((size_t) ((iCount_ID + 1) * sizeof(Pointer)));
 
572
  for(iCount1 = 0; iCount1 < iCount_ID; iCount1++){
 
573
     str[iCount1] = (Local_StringPtr) MemNew(sizeof(Local_String));
 
574
  }
 
575
 
 
576
  pbsfThis = pbsfsThis->features;
 
577
  iCount_ID = 0;
 
578
  iCount1 = 0;
 
579
  while(pbsfThis){
 
580
 
 
581
     pSegmentSlave = StringSave(&pbsfThis->name[7]);
 
582
     pSegmentSlave[6]='\0';
 
583
 
 
584
/*   pSegmentSlave[0]=pbsfThis->name[7];
 
585
     pSegmentSlave[1]=pbsfThis->name[8];
 
586
     pSegmentSlave[2]=pbsfThis->name[9];
 
587
     pSegmentSlave[3]=pbsfThis->name[10];
 
588
     pSegmentSlave[4]=pbsfThis->name[11];
 
589
     pSegmentSlave[5]=pbsfThis->name[12];     
 
590
     pSegmentSlave[6]='\0';   */
 
591
 
 
592
     IdChainFound = FindIdSlave(pSegmentSlave, pbsaThis->features->features, iCount1);
 
593
     if(IdChainFound){
 
594
        StringNCpy(str[iCount_ID]->str, pSegmentSlave, 4);
 
595
        str[iCount_ID]->str[4] = ' '; str[iCount_ID]->str[5] = pSegmentSlave[4];
 
596
        str[iCount_ID]->str[6] = ' '; str[iCount_ID]->str[7] = pSegmentSlave[5];
 
597
        str[iCount_ID]->str[8] = '\0';
 
598
        
 
599
        AlignId = (Int2) (pbsfThis->id % 10) ;  /* clique number */
 
600
        sprintf(AlignIdStr, "%d", AlignId);
 
601
        str[iCount_ID]->str[8] = ' '; str[iCount_ID]->str[9] = '\0';
 
602
        StringCat(str[iCount_ID]->str, AlignIdStr);
 
603
 
 
604
        sip_cpy = MakeLocalId(str[iCount_ID]->str);
 
605
        iCount_ID++;
 
606
 
 
607
/*      oip = ObjectIdNew();
 
608
        oip->str = str; 
 
609
 
 
610
        sip = ValNodeNew(NULL);
 
611
        sip->choice = SEQID_LOCAL;
 
612
        sip->data.ptrvalue = oip; 
 
613
 
 
614
        sip_cpy = AsnIoMemCopy(sip, (AsnReadFunc) SeqIdAsnRead, (AsnWriteFunc) SeqIdAsnWrite);   */
 
615
       
 
616
        StringNCpy(PDBName, pSegmentSlave, 4);
 
617
        Chain = pSegmentSlave[4];
 
618
 
 
619
        AssignLocaIdToBiostruc(sip_cpy, PDBName, Chain, pbsSlaveHead); 
 
620
        AssignLocaIdToBioseq(sip_cpy, PDBName, Chain, sepHead);
 
621
        AssignLocaIdToSeqAlign(sip_cpy, PDBName, Chain, salpHead);     
 
622
     }   
 
623
     MemFree(pSegmentSlave);
 
624
     pbsfThis = pbsfThis->next;
 
625
     iCount1++;
 
626
     if(pbsSlaveHead) pbsSlaveHead = pbsSlaveHead->next;
 
627
     if(sepHead) sepHead = sepHead->next;
 
628
     if(salpHead) salpHead = salpHead->next;
 
629
  }
 
630
 
 
631
  return (pvnNcbi);
 
632
 
 
633
}