~ubuntu-branches/ubuntu/edgy/ncbi-tools6/edgy

« back to all changes in this revision

Viewing changes to demo/asn2gb.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2006-07-19 23:28:07 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060719232807-et3cdmcjgmnyleyx
Tags: 6.1.20060507-3ubuntu1
Re-merge with Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
*
30
30
* Version Creation Date:   10/21/98
31
31
*
32
 
* $Revision: 6.79 $
 
32
* $Revision: 6.88 $
33
33
*
34
34
* File Description:  New GenBank flatfile generator application
35
35
*
50
50
#include <explore.h>
51
51
#include <asn2gnbp.h>
52
52
 
53
 
#define ASN2GB_APP_VER "2.8"
 
53
#define ASN2GB_APP_VER "3.2"
54
54
 
55
55
CharPtr ASN2GB_APPLICATION = ASN2GB_APP_VER;
56
56
 
478
478
  }
479
479
}
480
480
 
 
481
static CharPtr fffmt [] = {
 
482
  "",
 
483
  "genbank",
 
484
  "embl",
 
485
  "genbank",
 
486
  "embl",
 
487
  "ftable",
 
488
  NULL
 
489
};
 
490
 
 
491
static CharPtr ffmod [] = {
 
492
  "",
 
493
  "release",
 
494
  "entrez",
 
495
  "gbench",
 
496
  "dump",
 
497
  NULL
 
498
};
 
499
 
 
500
static CharPtr ffstl [] = {
 
501
  "",
 
502
  "normal",
 
503
  "segment",
 
504
  "master",
 
505
  "contig",
 
506
  NULL
 
507
};
 
508
 
 
509
static CharPtr ffvew [] = {
 
510
  "",
 
511
  "nuc",
 
512
  "nuc",
 
513
  "prot",
 
514
  "prot",
 
515
  "nuc",
 
516
  NULL
 
517
};
 
518
 
481
519
static void CompareFlatFiles (
482
520
  CharPtr path1,
483
521
  CharPtr path2,
493
531
  CstType custom,
494
532
  XtraPtr extra,
495
533
  Int2 batch,
496
 
  CharPtr gbdjoin,
497
 
  Boolean useGbdjoin
 
534
  CharPtr ffdiff,
 
535
  CharPtr asn2flat,
 
536
  Boolean useFfdiff
498
537
)
499
538
 
500
539
{
501
540
#ifdef OS_UNIX
502
541
  AsnIoPtr     aip;
 
542
  Char         arguments [128];
503
543
  BioseqPtr    bsp;
504
544
  Char         buf [256];
505
545
  Char         cmmd [256];
527
567
    SaveAsn2gnbk (sep, path1, format, SEQUIN_MODE, style, flags, locks, custom);
528
568
    SaveAsn2gnbk (sep, path2, format, RELEASE_MODE, style, flags, locks, custom);
529
569
 
530
 
    if (useGbdjoin) {
531
 
      sprintf (cmmd, "%s -o %s -n %s -d reports", gbdjoin, path1, path2);
 
570
    if (useFfdiff) {
 
571
      sprintf (cmmd, "%s -o %s -n %s -d reports", ffdiff, path1, path2);
532
572
      system (cmmd);
533
573
 
534
574
      sprintf (cmmd, "rm %s; rm %s", path1, path2);
559
599
 
560
600
  } else if (batch == 3) {
561
601
 
562
 
    aip = AsnIoOpen (path3, "w");
563
 
    if (aip == NULL) return;
564
 
 
565
 
    SeqEntryAsnWrite (sep, aip, NULL);
566
 
    AsnIoClose (aip);
567
 
 
568
 
    fsep = FindNthBioseq (sep, 1);
569
 
    if (fsep == NULL || fsep->choice != 1) return;
570
 
    bsp = (BioseqPtr) fsep->data.ptrvalue;
571
 
    if (bsp == NULL) return;
572
 
    SeqIdWrite (bsp->id, buf, PRINTID_FASTA_LONG, sizeof (buf));
 
602
    SaveAsn2gnbk (sep, path1, format, mode, style, flags, locks, custom);
 
603
 
 
604
    aip = AsnIoOpen (path3, "w");
 
605
    if (aip == NULL) return;
 
606
 
 
607
    SeqEntryAsnWrite (sep, aip, NULL);
 
608
    AsnIoClose (aip);
 
609
 
 
610
    fsep = FindNthBioseq (sep, 1);
 
611
    if (fsep == NULL || fsep->choice != 1) return;
 
612
    bsp = (BioseqPtr) fsep->data.ptrvalue;
 
613
    if (bsp == NULL) return;
 
614
    SeqIdWrite (bsp->id, buf, PRINTID_FASTA_LONG, sizeof (buf));
 
615
 
 
616
    arguments [0] = '\0';
 
617
    sprintf (arguments, "-format %s -mode %s -style %s -view %s",
 
618
             fffmt [(int) format], ffmod [(int) mode], ffstl [(int) style], ffvew [(int) format]);
 
619
 
 
620
    sprintf (cmmd, "%s %s -i %s -o %s", asn2flat, arguments, path3, path2);
 
621
    system (cmmd);
 
622
 
 
623
    if (useFfdiff) {
 
624
      sprintf (cmmd, "%s -o %s -n %s -d reports", ffdiff, path1, path2);
 
625
      system (cmmd);
 
626
 
 
627
      sprintf (cmmd, "rm %s; rm %s", path1, path2);
 
628
      system (cmmd);
 
629
    } else {
 
630
      sprintf (cmmd, "sort %s | uniq -c > %s.suc; rm %s", path1, path1, path1);
 
631
      system (cmmd);
 
632
 
 
633
      sprintf (cmmd, "sort %s | uniq -c > %s.suc; rm %s", path2, path2, path2);
 
634
      system (cmmd);
 
635
 
 
636
      sprintf (cmmd, "diff %s.suc %s.suc > %s", path1, path2, path3);
 
637
      system (cmmd);
 
638
 
 
639
      sprintf (cmmd, "cat %s", path3);
 
640
      fpo = popen (cmmd, "r");
 
641
      if (fpo != NULL) {
 
642
        while ((ct = fread (buf, 1, sizeof (buf), fpo)) > 0) {
 
643
          fwrite (buf, 1, ct, fp);
 
644
          fflush (fp);
 
645
        }
 
646
        pclose (fpo);
 
647
      }
 
648
 
 
649
      sprintf (cmmd, "rm %s.suc; rm %s.suc", path1, path2);
 
650
      system (cmmd);
 
651
    }
 
652
 
 
653
  } else if (batch == 4) {
 
654
 
 
655
    aip = AsnIoOpen (path3, "w");
 
656
    if (aip == NULL) return;
 
657
 
 
658
    SeqEntryAsnWrite (sep, aip, NULL);
 
659
    AsnIoClose (aip);
 
660
 
 
661
    fsep = FindNthBioseq (sep, 1);
 
662
    if (fsep == NULL || fsep->choice != 1) return;
 
663
    bsp = (BioseqPtr) fsep->data.ptrvalue;
 
664
    if (bsp == NULL) return;
 
665
    SeqIdWrite (bsp->id, buf, PRINTID_FASTA_LONG, sizeof (buf));
 
666
 
 
667
    arguments [0] = '\0';
 
668
    sprintf (arguments, "-format %s -mode %s -style %s -view %s -nocleanup",
 
669
             fffmt [(int) format], ffmod [(int) mode], ffstl [(int) style], ffvew [(int) format]);
 
670
 
 
671
    sprintf (cmmd, "%s %s -i %s -o %s", asn2flat, arguments, path3, path1);
 
672
    system (cmmd);
 
673
 
 
674
    arguments [0] = '\0';
 
675
    sprintf (arguments, "-format %s -mode %s -style %s -view %s",
 
676
             fffmt [(int) format], ffmod [(int) mode], ffstl [(int) style], ffvew [(int) format]);
 
677
 
 
678
    sprintf (cmmd, "%s %s -i %s -o %s", asn2flat, arguments, path3, path2);
 
679
    system (cmmd);
 
680
 
 
681
    if (useFfdiff) {
 
682
      sprintf (cmmd, "%s -o %s -n %s -d reports", ffdiff, path1, path2);
 
683
      system (cmmd);
 
684
 
 
685
      sprintf (cmmd, "rm %s; rm %s", path1, path2);
 
686
      system (cmmd);
 
687
    } else {
 
688
      sprintf (cmmd, "sort %s | uniq -c > %s.suc; rm %s", path1, path1, path1);
 
689
      system (cmmd);
 
690
 
 
691
      sprintf (cmmd, "sort %s | uniq -c > %s.suc; rm %s", path2, path2, path2);
 
692
      system (cmmd);
 
693
 
 
694
      sprintf (cmmd, "diff %s.suc %s.suc > %s", path1, path2, path3);
 
695
      system (cmmd);
 
696
 
 
697
      sprintf (cmmd, "cat %s", path3);
 
698
      fpo = popen (cmmd, "r");
 
699
      if (fpo != NULL) {
 
700
        while ((ct = fread (buf, 1, sizeof (buf), fpo)) > 0) {
 
701
          fwrite (buf, 1, ct, fp);
 
702
          fflush (fp);
 
703
        }
 
704
        pclose (fpo);
 
705
      }
 
706
 
 
707
      sprintf (cmmd, "rm %s.suc; rm %s.suc", path1, path2);
 
708
      system (cmmd);
 
709
    }
 
710
 
 
711
  } else if (batch == 5) {
 
712
 
 
713
    aip = AsnIoOpen (path3, "w");
 
714
    if (aip == NULL) return;
 
715
 
 
716
    SeqEntryAsnWrite (sep, aip, NULL);
 
717
    AsnIoClose (aip);
573
718
 
574
719
    if (FindNucBioseq (sep) != NULL) {
575
720
 
605
750
        pclose (fpo);
606
751
      }
607
752
    }
608
 
 
609
753
  }
610
754
 
611
755
#else
683
827
  Boolean binary,
684
828
  Boolean compressed,
685
829
  Boolean propOK,
686
 
  CharPtr gbdjoin,
 
830
  CharPtr ffdiff,
 
831
  CharPtr asn2flat,
687
832
  CharPtr accn,
688
833
  FILE *logfp
689
834
)
718
863
  time_t          starttime, stoptime, worsttime;
719
864
  SeqDescrPtr     subcit = NULL;
720
865
  FILE            *tfp;
721
 
  Boolean         useGbdjoin;
 
866
  Boolean         useFfdiff;
722
867
  ValNode         vn;
723
868
#ifdef OS_UNIX
724
869
  CharPtr         gzcatprog;
815
960
    return 1;
816
961
  }
817
962
 
818
 
  if ((batch == 1 || batch == 3 || format != GENBANK_FMT) && extra == NULL) {
 
963
  if ((batch == 1 || batch == 3 || batch == 4 || batch == 5 || format != GENBANK_FMT) && extra == NULL) {
819
964
    ofp = FileOpen (outputFile, "w");
820
965
    if (ofp == NULL) {
821
966
      AsnIoClose (aip);
901
1046
          if (batch != 1) {
902
1047
            printf ("%s\n", buf);
903
1048
            fflush (stdout);
904
 
            if (batch != 3) {
 
1049
            if (batch != 3 && batch != 4 && batch != 5) {
905
1050
              if (ofp != NULL) {
906
1051
                fprintf (ofp, "%s\n", buf);
907
1052
                fflush (ofp);
951
1096
          }
952
1097
 
953
1098
          starttime = GetSecs ();
954
 
          useGbdjoin = (Boolean) (format == GENBANK_FMT && (! hasRefSeq));
 
1099
          useFfdiff = (Boolean) (format == GENBANK_FMT && (! hasRefSeq));
955
1100
          CompareFlatFiles (path1, path2, path3, sep, ofp,
956
1101
                            format, altformat, mode, style, flags, locks,
957
 
                            custom, extra, batch, gbdjoin, useGbdjoin);
 
1102
                            custom, extra, batch, ffdiff, asn2flat, useFfdiff);
958
1103
          stoptime = GetSecs ();
959
1104
          if (stoptime - starttime > worsttime) {
960
1105
            worsttime = stoptime - starttime;
1158
1303
#define r_argRemote      14
1159
1304
#define A_argAccession   15
1160
1305
#ifdef OS_UNIX
1161
 
#define q_argGbdJoin     16
1162
 
#define j_argFrom        17
1163
 
#define k_argTo          18
1164
 
#define d_argStrand      19
1165
 
#define y_argItemID      20
 
1306
#define q_argFfDiff      16
 
1307
#define n_argAsn2Flat    17
 
1308
#define j_argFrom        18
 
1309
#define k_argTo          19
 
1310
#define d_argStrand      20
 
1311
#define y_argItemID      21
1166
1312
#ifdef ENABLE_ARG_X
1167
 
#define x_argAccnToSave  21
 
1313
#define x_argAccnToSave  22
1168
1314
#endif
1169
1315
#endif
1170
1316
 
1185
1331
    FALSE, 'h', ARG_INT, 0.0, 0, NULL},
1186
1332
  {"Custom Flags (2 HideMostImpFeats, 4 HideSnpFeats)", "0", NULL, NULL,
1187
1333
    FALSE, 'u', ARG_INT, 0.0, 0, NULL},
1188
 
  {"ASN.1 Type (a Any, e Seq-entry, b Bioseq, s Bioseq-set, m Seq-submit, t Batch Report)", "a", NULL, NULL,
 
1334
  {"ASN.1 Type (a Any, e Seq-entry, b Bioseq, s Bioseq-set, m Seq-submit, t Batch Bioseq-set, u Batch Seq-submit)", "a", NULL, NULL,
1189
1335
    TRUE, 'a', ARG_STRING, 0.0, 0, NULL},
1190
 
  {"Batch (1 Report, 2 Sequin/Release)", "0", NULL, NULL,
 
1336
  {"Batch (1 Report, 2 Sequin/Release, 3 asn2gb/asn2flat, 4 asn2flat BSEC/nocleanup, 5 oldasn2gb/newasn2gb)", "0", "0", "5",
1191
1337
    FALSE, 't', ARG_INT, 0.0, 0, NULL},
1192
 
  {"Bioseq-set is Binary", "F", NULL, NULL,
 
1338
  {"Input File is Binary", "F", NULL, NULL,
1193
1339
    TRUE, 'b', ARG_BOOLEAN, 0.0, 0, NULL},
1194
 
  {"Bioseq-set is Compressed", "F", NULL, NULL,
 
1340
  {"Batch File is Compressed", "F", NULL, NULL,
1195
1341
    TRUE, 'c', ARG_BOOLEAN, 0.0, 0, NULL},
1196
1342
  {"Propagate Top Descriptors", "F", NULL, NULL,
1197
1343
    TRUE, 'p', ARG_BOOLEAN, 0.0, 0, NULL},
1203
1349
    TRUE, 'A', ARG_STRING, 0.0, 0, NULL},
1204
1350
#ifdef OS_UNIX
1205
1351
#ifdef PROC_I80X86
1206
 
  {"Gbdjoin Executable", "gbdjoin", NULL, NULL,
 
1352
  {"Ffdiff Executable", "ffdiff", NULL, NULL,
1207
1353
    TRUE, 'q', ARG_FILE_IN, 0.0, 0, NULL},
 
1354
  {"Asn2Flat Executable", "asn2flat", NULL, NULL,
 
1355
    TRUE, 'n', ARG_FILE_IN, 0.0, 0, NULL},
1208
1356
#else
1209
 
  {"Gbdjoin Executable", "/netopt/genbank/subtool/bin/gbdjoin", NULL, NULL,
 
1357
  {"Ffdiff Executable", "/netopt/genbank/subtool/bin/ffdiff", NULL, NULL,
1210
1358
    TRUE, 'q', ARG_FILE_IN, 0.0, 0, NULL},
 
1359
  {"Asn2Flat Executable", "asn2flat", NULL, NULL,
 
1360
    TRUE, 'n', ARG_FILE_IN, 0.0, 0, NULL},
1211
1361
#endif
1212
1362
  {"SeqLoc From", "0", NULL, NULL,
1213
1363
    TRUE, 'j', ARG_INT, 0.0, 0, NULL},
1237
1387
  AsnIoPtr     aip = NULL;
1238
1388
  FmtType      altformat = (FmtType) 0;
1239
1389
  Char         app [64];
 
1390
  CharPtr      asn2flat = NULL;
1240
1391
  AsnTypePtr   atp = NULL;
1241
1392
  Int2         batch = 0;
1242
1393
  Boolean      binary = FALSE;
1247
1398
  Boolean      do_tiny_seq = FALSE;
1248
1399
  Boolean      do_fasta_stream = FALSE;
1249
1400
  XtraPtr      extra = NULL;
 
1401
  CharPtr      ffdiff = NULL;
1250
1402
  FlgType      flags;
1251
1403
  FmtType      format = GENBANK_FMT;
1252
1404
  Int4         from = 0;
1253
 
  CharPtr      gbdjoin = NULL;
1254
1405
  GBSeq        gbsq;
1255
1406
  GBSet        gbst;
1256
1407
  Int4         itemID = 0;
1259
1410
  FILE         *logfp = NULL;
1260
1411
  ModType      mode = SEQUIN_MODE;
1261
1412
  Boolean      propOK = FALSE;
 
1413
  Boolean      remote = FALSE;
1262
1414
  Int2         rsult = 0;
1263
1415
  time_t       runtime, starttime, stoptime;
1264
1416
  SeqEntryPtr  sep;
1306
1458
    return 0;
1307
1459
  }
1308
1460
 
1309
 
  batch = (Int2) myargs [t_argBatch].intvalue;
1310
 
 
1311
1461
  if (myargs [b_argBinary].intvalue) {
1312
1462
    binary = TRUE;
1313
1463
  } else {
1418
1568
    type = 1;
1419
1569
  }
1420
1570
 
 
1571
  if (myargs [t_argBatch].intvalue > 0) {
 
1572
    batch = (Int2) myargs [t_argBatch].intvalue;
 
1573
  }
 
1574
 
1421
1575
  if ((binary || compressed) && batch == 0) {
1422
1576
    if (type == 1) {
1423
1577
      Message (MSG_FATAL, "-b or -c cannot be used without -t or -a");
1425
1579
    }
1426
1580
  }
1427
1581
 
1428
 
  if (myargs [r_argRemote].intvalue) {
 
1582
  remote = (Boolean) myargs [r_argRemote].intvalue;
 
1583
 
 
1584
  accntofetch = (CharPtr) myargs [A_argAccession].strvalue;
 
1585
  if (StringDoesHaveText (accntofetch)) {
 
1586
    remote = TRUE;
 
1587
  }
 
1588
 
 
1589
  if (remote) {
1429
1590
#ifdef INTERNAL_NCBI_ASN2GB
1430
1591
    if (! PUBSEQBioseqFetchEnable ("asn2gb", FALSE)) {
1431
1592
      Message (MSG_POSTERR, "PUBSEQBioseqFetchEnable failed");
1443
1604
    logfp = FileOpen (logfile, "w");
1444
1605
  }
1445
1606
 
1446
 
  accntofetch = (CharPtr) myargs [A_argAccession].strvalue;
1447
 
 
1448
1607
#ifdef OS_UNIX
1449
 
  gbdjoin = myargs [q_argGbdJoin].strvalue;
 
1608
  ffdiff = myargs [q_argFfDiff].strvalue;
 
1609
  asn2flat = myargs [n_argAsn2Flat].strvalue;
1450
1610
 
1451
1611
  from = myargs [j_argFrom].intvalue;
1452
1612
  to = myargs [k_argTo].intvalue;
1514
1674
 
1515
1675
  if (StringDoesHaveText (accntofetch)) {
1516
1676
 
1517
 
    if (myargs [r_argRemote].intvalue) {
 
1677
    if (remote) {
1518
1678
      sep = SeqEntryFromAccnOrGi (accntofetch);
1519
1679
      if (sep != NULL) {
1520
1680
        ProcessOneSeqEntry (sep, myargs [o_argOutputFile].strvalue,
1530
1690
                                   myargs [o_argOutputFile].strvalue,
1531
1691
                                   format, altformat, mode, style, flags, locks,
1532
1692
                                   custom, extra, type, batch, binary, compressed,
1533
 
                                   propOK, gbdjoin, accn, logfp);
 
1693
                                   propOK, ffdiff, asn2flat, accn, logfp);
1534
1694
  } else {
1535
1695
 
1536
1696
    rsult = HandleSingleRecord (myargs [i_argInputFile].strvalue,
1553
1713
    FileClose (logfp);
1554
1714
  }
1555
1715
 
1556
 
  if (myargs [r_argRemote].intvalue) {
 
1716
  if (remote) {
1557
1717
    LocalSeqFetchDisable ();
1558
1718
    PubMedFetchDisable ();
1559
1719
#ifdef INTERNAL_NCBI_ASN2GB