~ubuntu-branches/ubuntu/maverick/ncbi-tools6/maverick

« back to all changes in this revision

Viewing changes to biostruc/pdbeast/mmdborgcpy.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
/*===========================================================================
 
2
*
 
3
*                            PUBLIC DOMAIN NOTICE
 
4
*               National Center for Biotechnology Information
 
5
*
 
6
*  This software/database is a "United States Government Work" under the
 
7
*  terms of the United States Copyright Act.  It was written as part of
 
8
*  the author's official duties as a United States Government employee and
 
9
*  thus cannot be copyrighted.  This software/database is freely available
 
10
*  to the public for use. The National Library of Medicine and the U.S.
 
11
*  Government have not placed any restriction on its use or reproduction.
 
12
*
 
13
*  Although all reasonable efforts have been taken to ensure the accuracy
 
14
*  and reliability of the software and data, the NLM and the U.S.
 
15
*  Government do not and cannot warrant the performance or results that
 
16
*  may be obtained by using this software or data. The NLM and the U.S.
 
17
*  Government disclaim all warranties, express or implied, including
 
18
*  warranties of performance, merchantability or fitness for any particular
 
19
*  purpose.
 
20
*
 
21
*  Please cite the author in any work or product based on this material.
 
22
*
 
23
* ===========================================================================
 
24
*
 
25
* File Name:  mmdborgcpy.c
 
26
*
 
27
* Author:  Yanli Wang
 
28
*
 
29
* Initial Version Creation Date: 04/19/1997
 
30
*
 
31
* File Description:
 
32
*         Copy taxonomy assignment from structure bioseq to biostruc
 
33
*
 
34
*
 
35
* Modifications:
 
36
* --------------------------------------------------------------------------
 
37
* $Log: mmdborgcpy.c,v $
 
38
* Revision 1.1  2002/12/17 15:13:43  ywang
 
39
* pdbeast related tools updated
 
40
*
 
41
*
 
42
* ==========================================================================
 
43
*/
 
44
 
 
45
/*----------------- get org from Bioseq and put them in Biostruc -------------*/
 
46
#include <ncbi.h>
 
47
#include <ncbistr.h>
 
48
#include <taxinc.h>
 
49
#include <objseq.h>
 
50
#include <objsset.h>
 
51
#include <objfeat.h>
 
52
#include <objblock.h>
 
53
#include <objloc.h>
 
54
#include <objmmdb1.h>
 
55
#include <objmmdb2.h>
 
56
#include <objmmdb3.h>
 
57
#include <mmdbapi1.h>
 
58
 
 
59
Args myargs[9] = {
 
60
    {"Text Input Seq-entry File Directory","/net/keystone/usr/people/ywang/work/taxonomy/RawBioseq/", NULL,NULL,TRUE,'h',ARG_STRING,0.0,0,NULL},
 
61
    {"Binary Input Seq-entry File Directory","/net/clobber/usr/people8/bryant/MMDB.Bioseq/", NULL,NULL,TRUE,'i',ARG_STRING,0.0,0,NULL},
 
62
    {"Text Input Biostruc File Directory","/net/keystone/usr/people/ywang/work/taxonomy/Biostr_text/", NULL,NULL,TRUE,'h',ARG_STRING,0.0,0,NULL},
 
63
    {"Binary Input Biostruc File Directory","/net/clobber/usr/people8/bryant/MMDB/", NULL,NULL,TRUE,'i',ARG_STRING,0.0,0,NULL},
 
64
    {"Text Output Biostruc File Directory","/net/keystone/usr/people/ywang/work/taxonomy/Bioseq_text/", NULL,NULL,TRUE,'n',ARG_STRING,0.0,0,NULL},
 
65
    {"Binary Output Biostruc File Directory","/net/clobber/usr/people10/ywang/work/taxonomy/MMDB/", NULL,NULL,TRUE,'o',ARG_STRING,0.0,0,NULL},
 
66
    {"Entry Code List File Directory","/net/keystone/usr/people/ywang/work/taxonomy/index/", NULL,NULL,TRUE,'b',ARG_STRING,0.0,0,NULL},
 
67
    {"List File Name","all.OCT96", NULL,NULL,TRUE,'c',ARG_FILE_IN,0.0,0,NULL},
 
68
    {"Log errors to file named:","log.pdbeast.April",NULL,NULL,TRUE,'l',ARG_FILE_OUT, 0.0,0,NULL} };
 
69
 
 
70
#define chain_choice_num  1
 
71
#define biosource_choice_num 6
 
72
#define molecule_type_num 9
 
73
 
 
74
FILE *afp;
 
75
Boolean IsBioseq, IsBioseqSet, TextInSeq = FALSE, TextInStr = FALSE, TextOutStr = FALSE, SeqOpen;
 
76
Int4 nchain, num_assign;
 
77
Char chain[100], current_chain;
 
78
BioSourcePtr biosource_chain[100];
 
79
SeqEntryPtr  root_sep;
 
80
BiostrucPtr  root_bstrucp;
 
81
AsnIoPtr aip1, aip2, aip3;
 
82
/*----------------   Initialize --------------------------*/
 
83
Init()
 
84
{
 
85
 
 
86
    SeqEntryLoad();
 
87
 
 
88
    objmmdb1AsnLoad();
 
89
    objmmdb2AsnLoad();
 
90
    objmmdb3AsnLoad();
 
91
 
 
92
    SeqLocAsnLoad();
 
93
}
 
94
/*-------------------------------------------------*/
 
95
PrintArg(){
 
96
 
 
97
       printf("\t -aid.seq      Text Input Seq-entry File Directory\n");
 
98
       printf("\t -bid.seq      Binary Input Seq-entry File Directory\n");
 
99
       printf("\t -aid.str      Text Input Biostruc File Directory\n");
 
100
       printf("\t -bid.str      Binary Input Biostruc File Directory\n");
 
101
       printf("\t -aod          Text Output Biostruc File Directory\n");
 
102
       printf("\t -bod          Binary Output Biostruc File Directory\n");
 
103
       printf("\t -ListPath     Entry Code List File Directory\n");
 
104
       printf("\t -ListName     Entry Code List File Name\n");
 
105
       printf("\t -Logfile      File Name For Log Errors\n");
 
106
       printf("\t -im.seq       Input Mode of Seq-entry File: 'a' for text / 'b' for binary\n");
 
107
       printf("\t -im.str       Input Mode of Biostruc File: 'a' for text / 'b' for binary\n");
 
108
       printf("\t -om           Output Mode of Biostruc File: 'a' for text / 'b' for binary\n");
 
109
 
 
110
       return;
 
111
 
 
112
}
 
113
/*---------------    Get Arguments ------------------*/
 
114
InitArg(argc, argv)
 
115
int argc;
 
116
char *argv[];
 
117
{
 
118
 
 
119
    Char listname[120], Command[120], str[120];
 
120
    Char my_argu[120];
 
121
 
 
122
    if(argc == 1){
 
123
        PrintArg();
 
124
        exit (1);
 
125
    }
 
126
    else{
 
127
        while(--argc > 0){
 
128
            *++argv;
 
129
            if(StringCmp(*argv, "-aid.seq") == 0) {
 
130
                sscanf(*++argv, "%s", my_argu);    
 
131
                myargs[0].strvalue = StringSave(my_argu);
 
132
            }
 
133
            else if (StringCmp(*argv, "-bid.seq") == 0) {
 
134
                sscanf(*++argv, "%s", my_argu);
 
135
                myargs[1].strvalue = StringSave(my_argu);
 
136
            }
 
137
            if(StringCmp(*argv, "-aid.str") == 0) {
 
138
                sscanf(*++argv, "%s", my_argu);
 
139
                myargs[2].strvalue = StringSave(my_argu);
 
140
            }
 
141
            else if (StringCmp(*argv, "-bid.str") == 0) {
 
142
                sscanf(*++argv, "%s", my_argu);
 
143
                myargs[3].strvalue = StringSave(my_argu);
 
144
            }
 
145
            else if (StringCmp(*argv, "-aod") == 0) {
 
146
                sscanf(*++argv, "%s", my_argu);
 
147
                myargs[4].strvalue = StringSave(my_argu);
 
148
            }
 
149
            else if (StringCmp(*argv, "-bod") == 0) {
 
150
                sscanf(*++argv, "%s", my_argu);
 
151
                myargs[5].strvalue = StringSave(my_argu);
 
152
            }
 
153
            else if (StringCmp(*argv, "-Listpath") == 0) {
 
154
                sscanf(*++argv, "%s", my_argu);
 
155
                myargs[6].strvalue = StringSave(my_argu);
 
156
            }
 
157
            else if (StringCmp(*argv, "-ListName") == 0) {
 
158
                sscanf(*++argv, "%s", my_argu);
 
159
                myargs[7].strvalue = StringSave(my_argu);
 
160
            }
 
161
            else if (StringCmp(*argv, "-Logfile") == 0) {
 
162
                sscanf(*++argv, "%s", my_argu);
 
163
                myargs[8].strvalue = StringSave(my_argu);
 
164
            }
 
165
            else if (StringCmp(*argv, "-im.seq") == 0) {
 
166
                sscanf(*++argv, "%s", str);
 
167
                if(StringCmp(str, "a") == 0) TextInSeq = TRUE;
 
168
                else if(StringCmp(str, "b") == 0) TextInSeq = FALSE;
 
169
            }
 
170
            else if (StringCmp(*argv, "-im.str") == 0) {
 
171
                sscanf(*++argv, "%s", str);
 
172
                if(StringCmp(str, "a") == 0) TextInStr = TRUE;
 
173
                else if(StringCmp(str, "b") == 0) TextInStr = FALSE;
 
174
            }
 
175
            else if (StringCmp(*argv, "-om") == 0) {
 
176
                sscanf(*++argv, "%s", str);
 
177
                if(StringCmp(str, "a") == 0) TextOutStr = TRUE;
 
178
                else if(StringCmp(str, "b") == 0)TextOutStr = FALSE;
 
179
            }
 
180
       }
 
181
    }
 
182
 
 
183
 
 
184
}
 
185
/*------------------------------------------------------*/
 
186
InitBoolean()
 
187
{
 
188
 
 
189
    SeqOpen = FALSE; 
 
190
    IsBioseq = FALSE;
 
191
    IsBioseqSet = FALSE;
 
192
 
 
193
}
 
194
/*---------------  Get PDB Seq-id ----------------------------*/
 
195
PDBSeqIdPtr GetPdbSeqId(BioseqPtr my_bsp)
 
196
{
 
197
 
 
198
    SeqIdPtr  my_seq_id;
 
199
    PDBSeqIdPtr my_pdb_seq_id;
 
200
 
 
201
    my_seq_id = my_bsp->id;
 
202
 
 
203
    while(my_seq_id != NULL){
 
204
        if(my_seq_id->choice == 15){
 
205
            my_pdb_seq_id = my_seq_id->data.ptrvalue;
 
206
            break;
 
207
        }
 
208
        my_seq_id = my_seq_id->next;
 
209
    }
 
210
 
 
211
    return(my_pdb_seq_id);
 
212
 
 
213
}
 
214
/*------------------------------------------------------*/
 
215
AccessBioseq(BioseqPtr my_bsp)
 
216
{
 
217
    BioSourcePtr my_bio_sourcep;
 
218
    PDBSeqIdPtr my_pdb_seq_id;
 
219
    ValNodePtr descr;
 
220
 
 
221
 
 
222
 
 
223
    my_pdb_seq_id = GetPdbSeqId(my_bsp);
 
224
 
 
225
    if(my_pdb_seq_id !=NULL) {
 
226
        if(my_pdb_seq_id->chain !=NULL) chain[nchain] = (Char) my_pdb_seq_id->chain;
 
227
        else printf("No Identifier for This Chain!!!\n");
 
228
    }
 
229
 
 
230
    descr = my_bsp->descr;
 
231
 
 
232
    biosource_chain[nchain] = NULL;
 
233
 
 
234
    while(descr != NULL){
 
235
        if(descr->choice == 23) {
 
236
            biosource_chain[nchain] = descr->data.ptrvalue;
 
237
            break;
 
238
        }
 
239
          
 
240
        descr = descr->next;
 
241
    }
 
242
 
 
243
    return;
 
244
 
 
245
}
 
246
/*------------------------------------------------------*/
 
247
AccessSeqEntry(SeqEntryPtr my_sep)
 
248
{
 
249
 
 
250
    BioseqPtr  my_bsp;
 
251
    BioseqSetPtr my_bssp;
 
252
    Int2 choice;
 
253
 
 
254
    nchain = 0;
 
255
    choice = my_sep->choice;
 
256
    if(choice == 1 ) {
 
257
        IsBioseq = TRUE;
 
258
        my_bsp = my_sep->data.ptrvalue;
 
259
        AccessBioseq(my_bsp);
 
260
        nchain++;
 
261
    }
 
262
    else if(choice == 2){
 
263
        IsBioseqSet = TRUE;
 
264
        my_bssp = my_sep->data.ptrvalue;
 
265
        my_sep = my_bssp->seq_set;
 
266
 
 
267
        while(my_sep != NULL){
 
268
            my_bsp = my_sep->data.ptrvalue;
 
269
            AccessBioseq(my_bsp);
 
270
            nchain++;
 
271
            my_sep = my_sep->next;
 
272
        }
 
273
    }
 
274
 
 
275
}
 
276
/*------------------------------------------------------*/
 
277
GoToSeqEntry(Char code[120])
 
278
{
 
279
    Char fname[120];
 
280
    CharPtr option;
 
281
 
 
282
    InitBoolean();
 
283
 
 
284
    if(TextInStr){
 
285
        StringCpy(fname, myargs[0].strvalue);
 
286
        StringCat(fname, "a");
 
287
    }
 
288
    else{
 
289
        StringCpy(fname, myargs[1].strvalue);
 
290
        StringCat(fname, "b");
 
291
    }
 
292
 
 
293
    StringCat(fname, code);
 
294
    StringCat(fname, ".ASN1");
 
295
 
 
296
    if(TextInSeq){
 
297
        if(!(aip1 = AsnIoOpen(fname, "r"))) {
 
298
            printf("Seq-Entry File %s can not be opened!", fname);
 
299
            return;
 
300
        }
 
301
        else SeqOpen = TRUE;
 
302
    }
 
303
    else{
 
304
        if(!(aip1 = AsnIoOpen(fname, "rb"))) {
 
305
            printf("Seq-Entry File %s can not be opened!", fname);
 
306
            return;
 
307
        }
 
308
        else SeqOpen = TRUE;
 
309
    }
 
310
 
 
311
    
 
312
    root_sep = SeqEntryAsnRead(aip1, NULL);
 
313
 
 
314
    aip1 = AsnIoClose(aip1);
 
315
 
 
316
    AccessSeqEntry(root_sep);
 
317
 
 
318
}
 
319
/*-------------- Delete existed Org -------------------*/
 
320
DeleteOrg(MoleculeGraphPtr mgp)
 
321
{
 
322
    BioSourcePtr my_biosource;
 
323
    ValNodePtr descr, last_descr = NULL;
 
324
 
 
325
    descr = mgp->descr;
 
326
 
 
327
    while(descr != NULL){
 
328
        if(descr->choice == biosource_choice_num){
 
329
            my_biosource = descr->data.ptrvalue;
 
330
            my_biosource = BioSourceFree(my_biosource);
 
331
            if(last_descr != NULL) {
 
332
                last_descr->next = descr->next;
 
333
                MemFree(descr);
 
334
 
 
335
                return;
 
336
            }
 
337
            else {
 
338
                mgp->descr = descr->next; 
 
339
                MemFree(mgp->descr);
 
340
                return;
 
341
            }
 
342
        }
 
343
 
 
344
        last_descr = descr;
 
345
        descr = descr->next; 
 
346
 
 
347
    }
 
348
 
 
349
    return;
 
350
 
 
351
}
 
352
/*------------------------------------------------------*/
 
353
GetBioSource(MoleculeGraphPtr mgp)
 
354
{
 
355
 
 
356
    Int2 n;
 
357
    Boolean OrgExist = FALSE;
 
358
 
 
359
    BioSourcePtr dummy_bsourcep;
 
360
    BioSourcePtr ThisBiosource;
 
361
    ValNodePtr descr;
 
362
 
 
363
    descr = mgp->descr;
 
364
 
 
365
    while(descr != NULL){
 
366
        if(descr->choice == biosource_choice_num){
 
367
            ThisBiosource = descr->data.ptrvalue;
 
368
            if(ThisBiosource != NULL) {
 
369
                DeleteOrg(mgp);
 
370
            }
 
371
        }
 
372
       descr = descr->next;
 
373
    }
 
374
 
 
375
    for(n = 0 ; n < nchain; n++){
 
376
        if(current_chain == chain[n]){
 
377
            num_assign++;
 
378
            if(biosource_chain[n] != NULL){
 
379
                dummy_bsourcep = AsnIoMemCopy(biosource_chain[n], (AsnReadFunc)BioSourceAsnRead, (AsnWriteFunc) BioSourceAsnWrite);     
 
380
       
 
381
                ValNodeAddPointer(&mgp->descr, biosource_choice_num, dummy_bsourcep);
 
382
                break;
 
383
            }
 
384
            else {
 
385
                printf("BioSourcePtr biosource_chain is NULL\n");
 
386
                return;
 
387
            }
 
388
        }
 
389
   }
 
390
 
 
391
 
 
392
    return;
 
393
 
 
394
}    
 
395
/*------------------------------------------------------*/
 
396
AccessBiostruc(BiostrucPtr my_bstrucp)
 
397
{
 
398
 
 
399
    BiostrucGraphPtr bgp;
 
400
    MoleculeGraphPtr mgp;
 
401
    ValNodePtr descr;
 
402
    CharPtr chainp;
 
403
    Int4 molecule_type;
 
404
 
 
405
    num_assign = 0;
 
406
 
 
407
    bgp = my_bstrucp->chemical_graph;
 
408
    mgp = bgp->molecule_graphs;
 
409
 
 
410
    while(mgp != NULL){
 
411
        if(mgp->descr != NULL){
 
412
            descr = mgp->descr;
 
413
            while(descr != NULL){
 
414
                if(descr->choice == chain_choice_num){
 
415
                    chainp = descr->data.ptrvalue;
 
416
                    current_chain = *chainp;
 
417
                }
 
418
                if(descr->choice == molecule_type_num) molecule_type = descr->data.intvalue;     
 
419
 
 
420
                descr = descr->next;
 
421
 
 
422
            }
 
423
 
 
424
            if( molecule_type  == Molecule_type_protein || molecule_type  == Molecule_type_dna || molecule_type  == Molecule_type_rna || molecule_type  == Molecule_type_other_biopolymer || molecule_type  == Molecule_type_other_nonpolymer) GetBioSource(mgp);    
 
425
        }
 
426
/*      else {
 
427
            descr = ValNodeNew(NULL);
 
428
            current_chain = ' ';
 
429
            GetBioSource(descr);      
 
430
            mgp->descr = descr->next;
 
431
        }      */
 
432
      
 
433
        if(num_assign == nchain ) break;
 
434
        else mgp = mgp->next;
 
435
 
 
436
    }
 
437
 
 
438
 
 
439
    return;
 
440
 
 
441
}
 
442
/*------------------------------------------------------*/
 
443
GoToBiostruc(Char code[120])
 
444
{
 
445
 
 
446
    Char fname[120];
 
447
    CharPtr option;
 
448
 
 
449
 
 
450
    if(TextInStr){
 
451
        StringCpy(fname, myargs[2].strvalue);
 
452
        StringCat(fname, "a");
 
453
    }
 
454
    else{
 
455
        StringCpy(fname, myargs[3].strvalue);
 
456
        StringCat(fname, "b");
 
457
    }
 
458
 
 
459
    StringCat(fname, code);
 
460
/*  StringCat(fname, ".ASN1");  */
 
461
 
 
462
    if(TextInStr){
 
463
        if(!(aip2 = AsnIoOpen(fname, "r"))) {
 
464
            printf("Can not open Input Biostruc File %s\n", fname);
 
465
            fprintf(afp, "Org has NOT been copied in!\n\n");
 
466
            return;   
 
467
        }
 
468
    }
 
469
    else {
 
470
        if(!(aip2 = AsnIoOpen(fname, "rb"))) {
 
471
            printf("Can not open Input Biostruc File %s\n", fname);
 
472
            fprintf(afp, "Org has NOT been copied in!\n\n");
 
473
            return;   
 
474
        }
 
475
    }
 
476
 
 
477
    root_bstrucp = BiostrucAsnRead(aip2, NULL);
 
478
    aip2 = AsnIoClose(aip2);
 
479
 
 
480
 
 
481
    if(TextOutStr){
 
482
        StringCpy(fname, myargs[4].strvalue);
 
483
        StringCat(fname, "a");
 
484
    }
 
485
    else{
 
486
        StringCpy(fname, myargs[5].strvalue);
 
487
        StringCat(fname, "b");
 
488
    }
 
489
 
 
490
    StringCat(fname, code);
 
491
/*  StringCat(fname, ".ASN1");  */
 
492
  
 
493
    if(TextOutStr){
 
494
        if(!(aip3 = AsnIoOpen(fname, "w"))) {
 
495
            printf("File %s  can not be opened!\n");
 
496
            fprintf(afp, "Org has NOT been copied in!\n\n");
 
497
            return; 
 
498
        }
 
499
    }
 
500
    else {
 
501
        if(!(aip3 = AsnIoOpen(fname, "wb"))) {
 
502
            printf("File %s  can not be opened!\n");
 
503
            fprintf(afp, "Org has NOT been copied in!\n\n");
 
504
            return;
 
505
        }
 
506
    }
 
507
 
 
508
/*  root_bstrucp = BiostrucAsnRead(aip2, NULL);
 
509
    aip2 = AsnIoClose(aip2);   */
 
510
 
 
511
    AccessBiostruc(root_bstrucp);
 
512
 
 
513
    BiostrucAsnWrite(root_bstrucp, aip3, NULL);
 
514
    aip3 = AsnIoClose(aip3);
 
515
    fprintf(afp, "Org has been copied in!\n\n");
 
516
    
 
517
    root_bstrucp = BiostrucFree(root_bstrucp);
 
518
    root_sep = SeqEntryFree(root_sep);
 
519
 
 
520
    return;
 
521
 
 
522
}
 
523
/*----------------   Main Starts Here ------------------*/
 
524
Int2 Main()
 
525
{
 
526
    Char fname[120], code[120];
 
527
    FILE *CodeList;
 
528
 
 
529
    Init();
 
530
    InitArg(GetArgc(), GetArgv());
 
531
 
 
532
    afp = FileOpen(myargs[8].strvalue, "w");
 
533
 
 
534
    StringCpy(fname, myargs[6].strvalue);
 
535
    StringCat(fname, myargs[7].strvalue);
 
536
 
 
537
    CodeList = FileOpen(fname, "r");
 
538
    if(CodeList == NULL){
 
539
        printf("Problem reading file: %s \n", fname);
 
540
        return;
 
541
    }
 
542
 
 
543
    while(fscanf(CodeList, "%s", code) != EOF){
 
544
        fprintf(afp, "\tEntry: %s\n", code);
 
545
 
 
546
printf("%s\n", code);
 
547
 
 
548
        GoToSeqEntry(code);
 
549
        if(SeqOpen) GoToBiostruc(code); 
 
550
 
 
551
 
 
552
    }
 
553
 
 
554
    FileClose(afp);
 
555
 
 
556
}
 
557