This file is indexed.

/usr/include/ncbi/sqnutils.h is in libncbi6-dev 6.1.20110713-3ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
/*   sqnutils.h
* ===========================================================================
*
*                            PUBLIC DOMAIN NOTICE
*            National Center for Biotechnology Information (NCBI)
*
*  This software/database is a "United States Government Work" under the
*  terms of the United States Copyright Act.  It was written as part of
*  the author's official duties as a United States Government employee and
*  thus cannot be copyrighted.  This software/database is freely available
*  to the public for use. The National Library of Medicine and the U.S.
*  Government do not place any restriction on its use or reproduction.
*  We would, however, appreciate having the NCBI and the author cited in
*  any work or product based on this material
*
*  Although all reasonable efforts have been taken to ensure the accuracy
*  and reliability of the software and data, the NLM and the U.S.
*  Government do not and cannot warrant the performance or results that
*  may be obtained by using this software or data. The NLM and the U.S.
*  Government disclaim all warranties, express or implied, including
*  warranties of performance, merchantability or fitness for any particular
*  purpose.
*
* ===========================================================================
*
* File Name:  sqnutils.h
*
* Author:  Jonathan Kans
*
* Version Creation Date:   9/2/97
*
* $Revision: 6.559 $
*
* File Description: 
*
* Modifications:  
* --------------------------------------------------------------------------
* Date     Name        Description of modification
* -------  ----------  -----------------------------------------------------
*
*
* ==========================================================================
*/

#ifndef _SQNUTILS_
#define _SQNUTILS_

#include <ncbi.h>
#include <sequtil.h>
#include <objpubme.h>
#include <objentgene.h>
#include <util/creaders/alnread.h>
#include <subutil.h>

#undef NLM_EXTERN
#ifdef NLM_IMPORT
#define NLM_EXTERN NLM_IMPORT
#else
#define NLM_EXTERN extern
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef  void  (*Nlm_ChangeNotifyProc) PROTO ((Pointer));

NLM_EXTERN SeqEntryPtr LIBCALL GetTopSeqEntryForEntityID (Uint2 entityID);
NLM_EXTERN SeqEntryPtr LIBCALL GetBestTopParentForData (Uint2 entityID, BioseqPtr bsp);
NLM_EXTERN SeqEntryPtr LIBCALL GetBestTopParentForItemID (Uint2 entityID, Uint4 itemID, Uint2 itemtype);

NLM_EXTERN SeqEntryPtr LIBCALL GetBestTopParentForDataEx (Uint2 entityID, BioseqPtr bsp, Boolean skipGenProdSet);
NLM_EXTERN SeqEntryPtr LIBCALL GetBestTopParentForItemIDEx (Uint2 entityID, Uint4 itemID, Uint2 itemtype, Boolean skipGenProdSet);

NLM_EXTERN SeqIdPtr SeqIdFindWorst (SeqIdPtr sip);
NLM_EXTERN void ChangeSeqIdToWorstID (SeqIdPtr sip);
NLM_EXTERN void ChangeSeqLocToWorstID (SeqLocPtr slp);

NLM_EXTERN SeqIdPtr MakeSeqID (CharPtr str);
NLM_EXTERN SeqIdPtr MakeUniqueSeqID (CharPtr prefix);

NLM_EXTERN DatePtr DateAdvance (DatePtr dp, Uint1 monthsToAdd);

NLM_EXTERN SeqEntryPtr LIBCALL FindNthSeqEntry (SeqEntryPtr sep, Int2 seq);
NLM_EXTERN SeqEntryPtr LIBCALL FindNthBioseq (SeqEntryPtr sep, Int2 seq);
NLM_EXTERN SeqEntryPtr LIBCALL FindNthSequinEntry (SeqEntryPtr sep, Int2 seq);
NLM_EXTERN SeqEntryPtr LIBCALL FindNucSeqEntry (SeqEntryPtr sep);
NLM_EXTERN BioseqPtr LIBCALL FindNucBioseq (SeqEntryPtr sep);
NLM_EXTERN SeqEntryPtr LIBCALL FindBioseqSetByClass (SeqEntryPtr sep, Uint1 _class);

NLM_EXTERN Boolean LIBCALL SeqEntryHasNucs (SeqEntryPtr sep);
NLM_EXTERN Boolean LIBCALL SeqEntryHasProts (SeqEntryPtr sep);
NLM_EXTERN Boolean LIBCALL SeqEntryHasAligns (Uint2 entityID, SeqEntryPtr sep);
NLM_EXTERN Boolean LIBCALL PowerBLASTASN1Detected (SeqEntryPtr sep);

NLM_EXTERN Int2 EntityIDToGeneticCode (Uint2 entityID, BoolPtr mito, CharPtr taxname, size_t maxsize);
NLM_EXTERN Int2 SeqEntryToGeneticCode (SeqEntryPtr sep, BoolPtr mito, CharPtr taxname, size_t maxsize);
NLM_EXTERN Int2 SeqEntryToBioSource (SeqEntryPtr sep, BoolPtr mito, CharPtr taxname, size_t maxsize, BioSourcePtr PNTR biopp);

NLM_EXTERN Boolean BioseqToGeneticCode (
  BioseqPtr bsp,
  Int2Ptr gencodep,
  BoolPtr mitop,
  BoolPtr plastidp,
  CharPtr taxnamep,
  size_t maxsize,
  BioSourcePtr PNTR biopp
);

NLM_EXTERN SeqLocPtr   CreateWholeInterval (SeqEntryPtr sep);
NLM_EXTERN SeqFeatPtr  CreateNewFeature (SeqEntryPtr sep, SeqEntryPtr placeHere, Uint1 choice, SeqFeatPtr useThis);
NLM_EXTERN ValNodePtr  CreateNewDescriptor (SeqEntryPtr sep, Uint1 choice);

NLM_EXTERN Boolean IsPopPhyEtcSet (Uint1 _class);

/* Variants that call SeqMgrGetSeqEntryForData. The feature version allows a location
to be specified, overriding the default full-length seq-int location.  (If location is
not NULL, it copies it after deleting the existing sfp->location.)  For both functions
you still need to set the sfp->data.value.ptrvalue of the sdp->data.ptrvalue. */
NLM_EXTERN SeqFeatPtr CreateNewFeatureOnBioseq (BioseqPtr bsp, Uint1 choice, SeqLocPtr slp);
NLM_EXTERN ValNodePtr CreateNewDescriptorOnBioseq (BioseqPtr bsp, Uint1 choice);

NLM_EXTERN void        UpdateLocalId (BioseqPtr bsp, CharPtr localId);
NLM_EXTERN void        UpdateTitle (BioseqPtr bsp, CharPtr title);

NLM_EXTERN GeneRefPtr  CreateNewGeneRef (CharPtr locus, CharPtr allele,
                                     CharPtr desc, Boolean pseudo);
NLM_EXTERN ProtRefPtr  CreateNewProtRef (CharPtr name, CharPtr desc,
                                     CharPtr ec, CharPtr activity);
NLM_EXTERN CdRegionPtr CreateNewCdRgn (Uint1 frame, Boolean orf, Int2 genCode);

NLM_EXTERN void        SetSeqFeatData (SeqFeatPtr sfp, Pointer data);
NLM_EXTERN void        SetSeqFeatProduct (SeqFeatPtr sfp, BioseqPtr bsp);
NLM_EXTERN void        ResetSeqFeatInterval (SeqFeatPtr sfp);

NLM_EXTERN void        AddSeqFeatInterval (SeqFeatPtr sfp, BioseqPtr bsp, Int4 from, Int4 to,
                                       Boolean partial5, Boolean partial3);

NLM_EXTERN void        AddSeqLocPoint (SeqLocPtr PNTR old_slp, SeqIdPtr sip, Int4 location,
                                       Boolean fuzz_before, Boolean fuzz_after, Int2 strand);
NLM_EXTERN void        AddSeqFeatPoint (SeqFeatPtr sfp, BioseqPtr bsp, Int4 location, Boolean fuzz_before, Boolean fuzz_after, Int2 strand);

/* AddSeqEntryToSeqEntry and ReplaceSeqEntryWithSeqEntry leave
   the original target sep pointing to the new structure. */

NLM_EXTERN void        AddSeqEntryToSeqEntry (SeqEntryPtr target, SeqEntryPtr insert, Boolean relink);
NLM_EXTERN void        ReplaceSeqEntryWithSeqEntry (SeqEntryPtr target, SeqEntryPtr replaceWith, Boolean relink);

NLM_EXTERN void        RemoveSeqEntryFromSeqEntry (SeqEntryPtr top, SeqEntryPtr del, Boolean relink);
NLM_EXTERN void        RenormalizeNucProtSets (SeqEntryPtr sep, Boolean relink);

/* The following functions are called by the above when relink is TRUE.  Examine the
   code of ReplaceSeqEntryWithSeqEntry (in dlgutil2.c) to see how relink is treated. */

NLM_EXTERN void        GetSeqEntryParent (SeqEntryPtr target, Pointer PNTR parentptr, Uint2Ptr parenttype);

NLM_EXTERN void        SaveSeqEntryObjMgrData (SeqEntryPtr target, ObjMgrDataPtr PNTR omdptopptr, ObjMgrData PNTR omdataptr);
NLM_EXTERN void        RestoreSeqEntryObjMgrData (SeqEntryPtr target, ObjMgrDataPtr omdptop, ObjMgrData PNTR omdataptr);

/* If relink FALSE, call SeqMgrLinkSeqEntry (target, parenttype, parentptr)
   with original parent after all sequences have been added to the target. */

/* If relink FALSE, call SaveSeqEntryObjMgrData with the address of temporary
   ObjMgrDataPtr and ObjMgrData variables, and after calling SeqMgrLinkSeqEntry to
   update the link table, call RestoreSeqEntryObjMgrData with the value of the
   temporary ObjMgrDataPtr and the address of the ObjMgrData variable. */

/* ExtractBioSourceAndPubs and ReplaceBioSourceAndPubs can be called before and
   after AddSeqEntryToSeqEntry to propagate source and pub descriptors to top level. */

NLM_EXTERN ValNodePtr  ExtractBioSourceAndPubs (SeqEntryPtr sep);
NLM_EXTERN void        ReplaceBioSourceAndPubs (SeqEntryPtr sep, ValNodePtr descr);

/* SeqLocMerge combines feature intervals.  It can be used to extend the gene feature
   intervals, and (eventually) to fuse mutliple features into one. */

NLM_EXTERN SeqLocPtr SeqLocMerge (BioseqPtr target,
                                  SeqLocPtr to, SeqLocPtr from,
                                  Boolean single_interval, Boolean fuse_joints,
                                  Boolean add_null);

NLM_EXTERN SeqLocPtr SeqLocMergeEx (BioseqPtr target, SeqLocPtr to, SeqLocPtr from,
                                    Boolean single_interval, Boolean fuse_joints,
                                    Boolean merge_overlaps, Boolean add_null);

NLM_EXTERN SeqLocPtr SeqLocMergeExEx (BioseqPtr target, SeqLocPtr to, SeqLocPtr from,
                                      Boolean single_interval, Boolean fuse_joints,
                                      Boolean merge_overlaps, Boolean add_null,
                                      Boolean ignore_mixed, Boolean ignore_out_of_order);

NLM_EXTERN Boolean CheckSeqLocForPartial (SeqLocPtr location, BoolPtr p5ptr, BoolPtr p3ptr);
NLM_EXTERN void SetSeqLocPartial (SeqLocPtr location, Boolean partial5, Boolean partial3);
NLM_EXTERN void FreeAllFuzz (SeqLocPtr location);
NLM_EXTERN Boolean LocationHasNullsBetween (SeqLocPtr location);
NLM_EXTERN void NormalizeNullsBetween (SeqLocPtr location);
NLM_EXTERN ValNodePtr GetSeqLocPartialSet (SeqLocPtr location);
NLM_EXTERN void SetSeqLocPartialSet (SeqLocPtr location, ValNodePtr vnp);
NLM_EXTERN Boolean SeqLocBadSortOrder (BioseqPtr bsp, SeqLocPtr slp);
NLM_EXTERN Boolean SeqLocMixedStrands (BioseqPtr bsp, SeqLocPtr slp);
/* Check/SetSeqLocPartialEx take lim argument - 3 is tr, 4 is tl */
NLM_EXTERN Boolean CheckSeqLocForPartialEx (SeqLocPtr location, BoolPtr p5ptr, BoolPtr p3ptr, Int4Ptr limptr);
NLM_EXTERN void SetSeqLocPartialEx (SeqLocPtr location, Boolean partial5, Boolean partial3, Int4 lim);

/* GetBioseqGivenSeqLoc returns a segmented bioseq if the SeqLoc is to the parts */

NLM_EXTERN BioseqPtr GetBioseqGivenSeqLoc (SeqLocPtr slp, Uint2 entityID);

NLM_EXTERN BioseqPtr GetBioseqGivenIDs (Uint2 entityID, Uint4 itemID, Uint2 itemtype);
NLM_EXTERN Uint4 GetItemIDGivenPointer (Uint2 entityID, Uint2 itemtype, Pointer lookfor);

NLM_EXTERN Uint1 FindFeatFromFeatDefType (Uint2 subtype);
NLM_EXTERN Uint1 FindFeatDefTypeFromKey (CharPtr key);
NLM_EXTERN CharPtr FindKeyFromFeatDefType (Uint1 type, Boolean forGBFF);

NLM_EXTERN Uint1 CodonToGcIndex (CharPtr codon);
NLM_EXTERN CharPtr GcIndextoCodon (Uint1 index);

/* finds bioseq from (cds) product, gets largest protein feature packaged on it */

NLM_EXTERN SeqFeatPtr LIBCALL GetBestProteinFeatureUnindexed (SeqLocPtr product);

/* resynchronizes coding regions with product protein bioseq and protein feature */

NLM_EXTERN void ResynchCodingRegionPartials (SeqEntryPtr sep);
NLM_EXTERN Boolean ResynchCodingRegionPartialsEx (SeqEntryPtr sep, FILE *log_fp);

/* resynchronizes mRNAs with product cDNA bioseq */

NLM_EXTERN void ResynchMessengerRNAPartials (SeqEntryPtr sep);

/* resynchronizes protein feature with product peptide bioseq */

NLM_EXTERN void ResynchProteinPartials (SeqEntryPtr sep);

/* individual feature callbacks for above functions */

NLM_EXTERN void ResynchMRNAPartials (SeqFeatPtr sfp, Pointer userdata);
NLM_EXTERN void ResynchCDSPartials (SeqFeatPtr sfp, Pointer userdata);
NLM_EXTERN void ResynchPeptidePartials (SeqFeatPtr sfp, Pointer userdata);

/* functions for associating CDS and parent mRNA using featureIDs */

NLM_EXTERN void ClearFeatIDs (SeqFeatPtr sfp);
NLM_EXTERN void ClearFeatIDXrefs (SeqFeatPtr sfp);

NLM_EXTERN void ClearFeatureIDs (SeqEntryPtr sep);
NLM_EXTERN Int4 FindHighestFeatureID (SeqEntryPtr sep);

NLM_EXTERN void AssignFeatureIDs (SeqEntryPtr sep);

NLM_EXTERN void OffsetFeatureIDs (SeqEntryPtr sep, Int4 offset);
NLM_EXTERN void OffsetFeatureIDXrefs (SeqEntryPtr sep, Int4 offset);

NLM_EXTERN void ReassignFeatureIDs (SeqEntryPtr sep);

NLM_EXTERN void LinkCDSmRNAbyOverlap (SeqEntryPtr sep);
NLM_EXTERN void LinkCDSmRNAbyProduct (SeqEntryPtr sep);
NLM_EXTERN void LinkCDSmRNAbyLabel (SeqEntryPtr sep);
NLM_EXTERN void LinkCDSmRNAbyLabelAndLocation (SeqEntryPtr sep);

NLM_EXTERN void StripFeatIDXrefAsnFilter (AsnIoPtr aip, AsnIoPtr aop);
NLM_EXTERN void StripSeqDataGapAsnFilter (AsnIoPtr aip, AsnIoPtr aop);
NLM_EXTERN void StripNewFeatMolInfoFieldsAsnFilter (AsnIoPtr aip, AsnIoPtr aop);
NLM_EXTERN void StripPCRPrimerAsnFilter (AsnIoPtr aip, AsnIoPtr aop);
NLM_EXTERN void StripOrgNamePgcodeAsnFilter (AsnIoPtr aip, AsnIoPtr aop);
NLM_EXTERN void StripGeneRnaPcrAsnFilter (AsnIoPtr aip, AsnIoPtr aop);
NLM_EXTERN void StripSeqFeatSupportAsnFilter (AsnIoPtr aip, AsnIoPtr aop);

/* functions to parse [org=Drosophila melanogaster] and [gene=lacZ] from titles */
/* for example, passing "gene" to SqnTagFind returns "lacZ" */

#define MAX_SQN_TAGS  32

typedef struct sqntag {
  CharPtr  query;
  Int2     num_tags;
  CharPtr  tag [MAX_SQN_TAGS];
  CharPtr  val [MAX_SQN_TAGS];
  Boolean  used [MAX_SQN_TAGS];
} SqnTag, PNTR SqnTagPtr;

NLM_EXTERN SqnTagPtr SqnTagParse (CharPtr ttl);
NLM_EXTERN SqnTagPtr SqnTagFree (SqnTagPtr stp);

NLM_EXTERN CharPtr SqnTagFind (SqnTagPtr stp, CharPtr tag);
NLM_EXTERN ValNodePtr SqnTagFindMultiple (SqnTagPtr stp, CharPtr tag);
NLM_EXTERN CharPtr SqnTagFindUnused (SqnTagPtr stp, CharPtr tag);

NLM_EXTERN void ReadTechFromString (CharPtr str, MolInfoPtr mip);
NLM_EXTERN void ReadCompletenessFromString (CharPtr str, MolInfoPtr mip);

extern Boolean StringsAreEquivalent (CharPtr str1, CharPtr str2);
NLM_EXTERN Uint1 EquivalentSubSource (CharPtr str);
NLM_EXTERN Uint1 EquivalentOrgMod (CharPtr str);
NLM_EXTERN Uint1 EquivalentSubSourceEx (CharPtr str, Boolean allow_discouraged_and_discontinued);
NLM_EXTERN Uint1 EquivalentOrgModEx (CharPtr str, Boolean allow_discouraged_and_discontinued);


/* functions to extract BioSource, MolInfo, and Bioseq information from parsed titles */

NLM_EXTERN BioSourcePtr ParseTitleIntoBioSource (
  SqnTagPtr stp,
  CharPtr organism,
  BioSourcePtr biop
);

NLM_EXTERN MolInfoPtr ParseTitleIntoMolInfo (
  SqnTagPtr stp,
  MolInfoPtr mip
);

NLM_EXTERN BioseqPtr ParseTitleIntoBioseq (
  SqnTagPtr stp,
  BioseqPtr bsp
);

NLM_EXTERN GeneRefPtr ParseTitleIntoGeneRef (
  SqnTagPtr stp,
  GeneRefPtr grp
);

NLM_EXTERN ProtRefPtr ParseTitleIntoProtRef (
  SqnTagPtr stp,
  ProtRefPtr prp
);

NLM_EXTERN GBBlockPtr ParseTitleIntoGenBank (
  SqnTagPtr stp,
  GBBlockPtr gbp
);

NLM_EXTERN SeqHistPtr ParseTitleIntoSeqHist (
  SqnTagPtr stp,
  SeqHistPtr shp
);

NLM_EXTERN SeqHistPtr ParseStringIntoSeqHist (
  SeqHistPtr shp,
  CharPtr str
);

NLM_EXTERN void ParseTitleIntoSubmitBlock (
  SqnTagPtr stp,
  SubmitBlockPtr sbp
);

NLM_EXTERN UserObjectPtr ParseTitleIntoTpaAssembly (
  SqnTagPtr stp,
  UserObjectPtr uop
);

NLM_EXTERN UserObjectPtr ParseTitleIntoGenomeProjectsDB (
  SqnTagPtr stp,
  UserObjectPtr uop
);

NLM_EXTERN Boolean IsGenomeProjectIDDescriptor (SeqDescrPtr sdp); 
NLM_EXTERN SeqDescrPtr GetGenomeProjectIDDescriptor (BioseqPtr bsp);
NLM_EXTERN Int4 GetGenomeProjectID (BioseqPtr bsp);


NLM_EXTERN void AddPubsFromTitle (
  SqnTagPtr stp,
  SeqDescrPtr PNTR desc_list
);

/* structured comment user object for flatfile presentation */

NLM_EXTERN UserObjectPtr ParseStringIntoStructuredComment (
  UserObjectPtr uop,
  CharPtr str,
  CharPtr prefix,
  CharPtr suffix
);


/* UseLocalAsnloadDataAndErrMsg transiently sets paths to asnload, data, and errmsg
  if they are packaged in the same directory as the executing program. */

NLM_EXTERN Boolean UseLocalAsnloadDataAndErrMsg (void);

/* GetRidOfLocusInSeqIds strips locus from all feature location and product seqIds */

NLM_EXTERN void GetRidOfLocusInSeqIds (Uint2 entityID, SeqEntryPtr sep);

NLM_EXTERN SeqLocPtr StripLocusFromSeqLoc (SeqLocPtr location);
NLM_EXTERN SeqIdPtr SeqIdStripLocus (SeqIdPtr sip);

/* LeaveBestCDD removes all but best CDD region in an area of overlapping features */

NLM_EXTERN void LeaveBestCDD (SeqEntryPtr sep);

/* ConvertPubSrcComDescsToFeats is useful when merging records */

NLM_EXTERN Boolean ConvertPubSrcComDescsToFeats (SeqEntryPtr sep, Boolean pub, Boolean src, Boolean com, Boolean toProts, Boolean PNTR asked_about_prop, Boolean PNTR propagate_descriptions, CharPtr findstring);

NLM_EXTERN void DeleteMultipleTitles (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent);

NLM_EXTERN Uint1 FindTrnaAA (CharPtr str);
NLM_EXTERN Uint1 FindTrnaAA3 (CharPtr str);
NLM_EXTERN Uint1 ParseTRnaString (CharPtr strx, BoolPtr justTrnaText, Uint1Ptr codon, Boolean noSingleLetter);
NLM_EXTERN CharPtr FindTrnaAAIndex (CharPtr str);
NLM_EXTERN Char FindResidueByName (CharPtr res_name, SeqCodeTablePtr sctp);
NLM_EXTERN ValNodePtr TokenizeTRnaString (CharPtr strx);
NLM_EXTERN Boolean ParseDegenerateCodon (tRNAPtr trp, Uint1Ptr codon);
NLM_EXTERN Boolean SerialNumberInString (CharPtr str);

/* ModernizeRNAFields uses new RNAGenPtr choice of RnaRef.ext for misc_RNA, ncRNA, tmRNA */

NLM_EXTERN void ModernizeRNAFields (
  SeqFeatPtr sfp
);

/* ModernizeGeneFields populates new GeneNomenclaturePtr field from OfficialNomenclature user object */

NLM_EXTERN void ModernizeGeneFields (
  SeqFeatPtr sfp
);

/* for sorting and uniquing valnode list by (charptr) data.ptrvalue (with case sensitive/insensitive variants) */

NLM_EXTERN int LIBCALLBACK SortVnpByStringCS (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN int LIBCALLBACK SortVnpByStringCI (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN int LIBCALLBACK SortVnpByStringCIUCFirst (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN int LIBCALLBACK SortVnpByStringCILCFirst (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN ValNodePtr UniqueStringValNodeCS (ValNodePtr list);
NLM_EXTERN ValNodePtr UniqueStringValNodeCI (ValNodePtr list);

NLM_EXTERN int LIBCALLBACK SortVnpByString (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN ValNodePtr UniqueValNode (ValNodePtr list);

/* for sorting and uniquing valnode list by data.intvalue */

NLM_EXTERN int LIBCALLBACK SortByIntvalue (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN ValNodePtr UniqueIntValNode (ValNodePtr list);

/* keytag sorts/uniques and then owns valnode character list */

typedef struct keytag {
  Int2               num;
  ValNodePtr         list;
  CharPtr PNTR       index; /* elements point into above valnode list */
} KeyTag;                   /* used as substructure, not allocated separately */

NLM_EXTERN void KeyTagInit (KeyTag PNTR ktp, ValNodePtr list);
NLM_EXTERN void KeyTagClear (KeyTag PNTR ktp);

NLM_EXTERN Int2 KeyFromTag (KeyTag PNTR ktp, CharPtr tag);
NLM_EXTERN CharPtr TagFromKey (KeyTag PNTR ktp, Int2 key);

/* inference qualifier utility */

#define VALID_INFERENCE            0
#define EMPTY_INFERENCE_STRING     1
#define BAD_INFERENCE_PREFIX       2
#define BAD_INFERENCE_BODY         3
#define SINGLE_INFERENCE_FIELD     4
#define SPACES_IN_INFERENCE        5
#define SAME_SPECIES_MISUSED       6
#define BAD_INFERENCE_ACCESSION    7
#define BAD_INFERENCE_ACC_VERSION  8
#define ACC_VERSION_NOT_PUBLIC     9
#define BAD_ACCESSION_TYPE        10

NLM_EXTERN Int2 ValidateInferenceQualifier (CharPtr val, Boolean fetchAccn);


/* from Colombe */
NLM_EXTERN SeqLocPtr StringSearchInBioseq (SeqIdPtr sip, CharPtr sub);

/*****************************************************************************
*
*   SequinEntryList (sep, mydata, mycallback, index, indent)
*       traverses all Seq-entry nodes beginning with sep
*       calls mycallback () at each node
*       Does enter BioseqSets of _class "parts", but ignores the
*       parts set itself
*
*****************************************************************************/

NLM_EXTERN Int4 SequinEntryList (SeqEntryPtr sep, Pointer mydata, SeqEntryFunc mycallback, Int4 index, Int2 indent);

#define SequinEntryCount( a )  SequinEntryList( a ,NULL,NULL,0,0)
#define SequinEntryExplore(a,b,c) SequinEntryList(a, b, c, 0L, 0)

/* Phrap reading function, based on sample code supplied by C. Magness, returns a SeqEntry list
of Bioseqs containing SeqGraphs, with individual reads removed and only contigs remaining */

NLM_EXTERN SeqEntryPtr ReadPhrapFile (FILE *fp);

/* Internal function to read quality scores, made available to parse separate DNA and quality score files */

NLM_EXTERN SeqGraphPtr ReadPhrapQuality (FILE *fp, BioseqPtr bsp);
NLM_EXTERN SeqGraphPtr ReadPhrapQualityFC (FileCachePtr fcp, BioseqPtr bsp);

/* SetPhrapContigOrder takes the results of ReadPhrapFile and a string indicating the order
of contigs, and returns a SeqEntryList in the desired order, with all other contigs removed */

NLM_EXTERN SeqEntryPtr SetPhrapContigOrder (SeqEntryPtr head, CharPtr contigs);

NLM_EXTERN void PrintQualityScores (BioseqPtr bsp, FILE *fp);

NLM_EXTERN void TrimSeqGraph (SeqGraphPtr sgp, Int4 num_to_trim, Boolean from_left);
NLM_EXTERN void TrimQualityScores (BioseqPtr bsp, Int4 num_to_trim, Boolean from_left);

NLM_EXTERN void ReverseSeqGraph (SeqGraphPtr sgp);
NLM_EXTERN void ReverseQualityScores (BioseqPtr bsp);


typedef void (*QualityWriteFunc) (CharPtr buf, Uint4 buflen, Pointer userdata);

NLM_EXTERN void PrintQualityScoresToBuffer (BioseqPtr bsp, Boolean gapIsZero, Pointer userdata, QualityWriteFunc callback);

/* special function for genome contig delta sequences with far pointers */

NLM_EXTERN void PrintQualityScoresForContig (BioseqPtr bsp, Boolean gapIsZero, FILE* fp);

/* more efficient function for far genomic contig, makes separate graphs */

NLM_EXTERN SeqAnnotPtr PhrapGraphForContig (BioseqPtr bsp);

/* ReadContigList builds a far segmented bioseq from a table of accessions, starts, stops,
lengths, and (optional) strands.  Gaps of a given length (with 0 start and stop) are also
allowed. */

NLM_EXTERN SeqEntryPtr ReadContigList (FILE *fp, Boolean coordinatesOnMaster);
NLM_EXTERN SeqEntryPtr ReadContigListEx (FILE *fp, Boolean coordinatesOnMaster, CharPtr seqid, CharPtr title);

/* ReadAsnFastaOrFlatFile reads object manager-registered ASN.1, FASTA, GenBank, EMBL, GenPept,
Feature table, Restriction table, Contig table, Message response, or saved UID list, with the
option of saving FASTA results as OBJ_FASTA (SimpleSeq) to avoid ID collisions */

NLM_EXTERN Pointer ReadAsnFastaOrFlatFileEx (FILE *fp, Uint2Ptr datatypeptr, Uint2Ptr entityIDptr,
                                           Boolean forceNuc, Boolean forceProt,
                                           Boolean parseFastaSeqId, Boolean fastaAsSimpleSeq,
                                           BoolPtr chars_stripped);
NLM_EXTERN Pointer ReadAsnFastaOrFlatFile (FILE *fp, Uint2Ptr datatypeptr, Uint2Ptr entityIDptr,
                                           Boolean forceNuc, Boolean forceProt,
                                           Boolean parseFastaSeqId, Boolean fastaAsSimpleSeq);

/* ReadFeatureTableFile only handles >Feature tables */

NLM_EXTERN Pointer ReadFeatureTableFile (
  FILE *fp,
  Uint2Ptr datatypeptr,
  Uint2Ptr entityIDptr,
  Int4Ptr lineP,
  BoolPtr failP
);

/* ReadDeltaFasta reads a FASTA file, combining raw sequence and >?unk100 lines into
a delta Bioseq.  The file pointer stops at the next FASTA with a real SeqID. */

NLM_EXTERN BioseqPtr ReadDeltaFasta (FILE *fp, Uint2Ptr entityIDptr);

/* This function is identical to ReadDeltaFasta, except that the contents of 
 * chars_stripped will be set to TRUE if characters other than digits were stripped from
 * the sequence, or FALSE if not.
 */
NLM_EXTERN BioseqPtr ReadDeltaFastaEx (FILE *fp, Uint2Ptr entityIDptr, BoolPtr chars_stripped);

/* ReadDeltaFastaWithEmptyDefline reads just one delta sequence with an empty
 * definition line.
 * Calling function should make sure that fp is set to the start of the line 
 * with the empty definition line and that there is a "gap sequence ID"
 * present as the next definition line in the file.
 */
NLM_EXTERN BioseqPtr ReadDeltaFastaWithEmptyDefline (FILE *fp, Uint2Ptr entityIDptr, BoolPtr chars_stripped);

/* PromoteXrefs expands generef or protref feature cross-references (made by reading a
feature table with ReadAsnFastaOrFlatFile) to stand-alone gene features or protein features
and protein bioseqs.  It processes ALL features in the list - you give it the FIRST sfp. */

NLM_EXTERN void PromoteXrefs (
  SeqFeatPtr sfp,
  BioseqPtr bsp,
  Uint2 entityID
);
NLM_EXTERN void PromoteXrefsEx (
  SeqFeatPtr sfp,
  BioseqPtr bsp,
  Uint2 entityID,
  Boolean include_stop,
  Boolean remove_trailingX,
  Boolean gen_prod_set
);
NLM_EXTERN void PromoteXrefsExEx (
  SeqFeatPtr sfp,
  BioseqPtr bsp,
  Uint2 entityID,
  Boolean include_stop,
  Boolean remove_trailingX,
  Boolean gen_prod_set,
  Boolean force_local_id,
  BoolPtr seq_fetch_failP
);

/* SetEmptyGeneticCodes imposes genetic code on all coding regions within a feature table */

NLM_EXTERN void SetEmptyGeneticCodes (SeqAnnotPtr sap, Int2 genCode);

/* AddIntervalToLocation is a convenience function to add a single interval, and is called by
ReadAsnFastaOrFlatFile internally. */

NLM_EXTERN SeqLocPtr AddIntervalToLocation (SeqLocPtr loc, SeqIdPtr sip, Int4 start,
                                            Int4 stop, Boolean partial5, Boolean partial3);

/* AddQualifierToFeature applies cds product and gene qualifiers as protref or generef stored
as feature xrefs.  Most others (e.g., protein_id) are stored as gbquals.  PromoteXrefs can then
turn these special cases into the appropriate structures in fully expanded records. */

NLM_EXTERN void AddQualifierToFeature (SeqFeatPtr sfp, CharPtr qual, CharPtr val);

/* specialized string trimming functions */

NLM_EXTERN CharPtr TrimSpacesAndSemicolons (CharPtr str);
NLM_EXTERN CharPtr TrimSpacesAndJunkFromEnds (CharPtr str, Boolean allowEllipsis);

/* specialized cleanup for subsource and orgmod lists */
NLM_EXTERN void CleanSubSourceList (SubSourcePtr PNTR sspp, Uint1 location);
NLM_EXTERN void CleanOrgModList (OrgModPtr PNTR ompp);

/* used by original BankIt to merge multiple primer subsources */
NLM_EXTERN void CleanSubSourcePrimers (SubSourcePtr PNTR sspp);

NLM_EXTERN Boolean PubIsEffectivelyEmpty (PubdescPtr pdp);

/* extracts and reinserts descriptors in a standard order */
NLM_EXTERN void NormalizeDescriptorOrder (SeqEntryPtr sep);

/* BasicSeqEntryCleanup cleans up strings, moves gbquals to the appropriate field, and
does several other conversions, all without changing the itemID structure (which would
require reindexing) */

NLM_EXTERN void BasicSeqEntryCleanup (SeqEntryPtr sep);

/* cleanup for a single descriptor, after editing */
NLM_EXTERN void CleanupStringsForOneDescriptor (SeqDescPtr sdp, SeqEntryPtr sep);

/* Selective components of BasicSeqEntryCleanup can be called for QA filtering */

NLM_EXTERN void CleanUpSeqFeat (SeqFeatPtr sfp, Boolean isEmblOrDdbj, Boolean isJscan, Boolean stripSerial, Boolean modernizeFeats, ValNodePtr PNTR publist);

NLM_EXTERN void CleanUpSeqLoc (SeqLocPtr slp);

NLM_EXTERN void CleanupSubSourceOrgModOtherFeat (SeqFeatPtr sfp, Pointer userdata);
NLM_EXTERN void CleanupSubSourceOrgModOtherDesc (SeqDescrPtr sdp, Pointer userdata);

NLM_EXTERN void CleanUpPubdescAuthors (PubdescPtr pdp);
NLM_EXTERN void CleanUpPubdescBody (PubdescPtr pdp, Boolean stripSerial);

NLM_EXTERN void CleanStructuredComment (UserObjectPtr uop);

NLM_EXTERN void SortSeqEntryQualifiers (SeqEntryPtr sep);

/* BasicSeqAnnotCleanup is for cleaning up contents of separate named Seq-annot objects */

NLM_EXTERN void BasicSeqAnnotCleanup (SeqAnnotPtr sap);

NLM_EXTERN void RemoveUnnecessaryGeneXrefs (SeqFeatPtr sfp, Pointer userdata);

/* CautiousSeqEntryCleanup is a gradual consolidation and replacement of functions in SeriousSeqEntryCleanup,
which does change the itemID structure, and is intended to be safe for a retrofit of the ID database */

NLM_EXTERN void CautiousSeqEntryCleanup (SeqEntryPtr sep, SeqEntryFunc taxfun, SeqEntryFunc taxmerge);

/* Convert a segmented or delta Bioseq to a raw Bioseq */

NLM_EXTERN void SegOrDeltaBioseqToRaw (BioseqPtr bsp);

NLM_EXTERN void ConvertSegSetsToDeltaSequences (SeqEntryPtr sep);

/* general purpose text finite state machine */
/* based on Practical Algorithms for Programmers by Binstock and Rex */

struct TextFsa;
typedef struct TextFsa* TextFsaPtr;

NLM_EXTERN TextFsaPtr TextFsaNew (void);
NLM_EXTERN void TextFsaAdd (TextFsaPtr tbl, CharPtr word);
NLM_EXTERN Int4 TextFsaNext (TextFsaPtr tbl, Int4 currState, Char ch, ValNodePtr PNTR matches);
NLM_EXTERN TextFsaPtr TextFsaFree (TextFsaPtr tbl);
NLM_EXTERN Boolean TextFsaGetStats (TextFsaPtr tbl, Int4Ptr highStateP, Int4Ptr numWordsP, Int4Ptr longestWordP);

/* PCR_primer manipulation functions */

typedef struct pcrset {
  CharPtr  fwd_seq;
  CharPtr  rev_seq;
  CharPtr  fwd_name;
  CharPtr  rev_name;
  Int2     orig_order;
} PcrSet, PNTR PcrSetPtr;

NLM_EXTERN ValNodePtr ParsePCRSet (BioSourcePtr biop);
NLM_EXTERN ValNodePtr ParsePCRStrings (
  CharPtr fwd_primer_seq,
  CharPtr rev_primer_seq,
  CharPtr fwd_primer_name,
  CharPtr rev_primer_name
);
NLM_EXTERN SubSourcePtr WritePCRSet (ValNodePtr pset);
NLM_EXTERN ValNodePtr FreePCRSet (ValNodePtr pset);

NLM_EXTERN int LIBCALLBACK SortVnpByPCRSetSeq (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN int LIBCALLBACK SortVnpByPCRSetOrder (VoidPtr ptr1, VoidPtr ptr2);

NLM_EXTERN ValNodePtr UniqueVnpByPCRSetSeq (ValNodePtr pset);

NLM_EXTERN void ModernizePCRPrimers (
  BioSourcePtr biop
);

/*
   very simple explore functions - VisitOn only does one chain, VisitIn goes into set components,
   they now return a count of the number of nodes visited, and the callback can be NULL if the purpose
   is simply to count nodes
*/

typedef void (*VisitDescriptorsFunc) (SeqDescrPtr sdp, Pointer userdata);
NLM_EXTERN Int4 VisitDescriptorsOnBsp (BioseqPtr bsp, Pointer userdata, VisitDescriptorsFunc callback);
NLM_EXTERN Int4 VisitDescriptorsOnSet (BioseqSetPtr bssp, Pointer userdata, VisitDescriptorsFunc callback);
NLM_EXTERN Int4 VisitDescriptorsInSet (BioseqSetPtr bssp, Pointer userdata, VisitDescriptorsFunc callback);
NLM_EXTERN Int4 VisitDescriptorsOnSep (SeqEntryPtr sep, Pointer userdata, VisitDescriptorsFunc callback);
NLM_EXTERN Int4 VisitDescriptorsInSep (SeqEntryPtr sep, Pointer userdata, VisitDescriptorsFunc callback);

typedef void (*VisitFeaturesFunc) (SeqFeatPtr sfp, Pointer userdata);
NLM_EXTERN Int4 VisitFeaturesOnSap (SeqAnnotPtr sap, Pointer userdata, VisitFeaturesFunc callback);
NLM_EXTERN Int4 VisitFeaturesOnBsp (BioseqPtr bsp, Pointer userdata, VisitFeaturesFunc callback);
NLM_EXTERN Int4 VisitFeaturesOnSet (BioseqSetPtr bssp, Pointer userdata, VisitFeaturesFunc callback);
NLM_EXTERN Int4 VisitFeaturesInSet (BioseqSetPtr bssp, Pointer userdata, VisitFeaturesFunc callback);
NLM_EXTERN Int4 VisitFeaturesOnSep (SeqEntryPtr sep, Pointer userdata, VisitFeaturesFunc callback);
NLM_EXTERN Int4 VisitFeaturesInSep (SeqEntryPtr sep, Pointer userdata, VisitFeaturesFunc callback);

typedef void (*VisitAlignmentsFunc) (SeqAlignPtr sap, Pointer userdata);
NLM_EXTERN Int4 VisitAlignmentsOnSap (SeqAnnotPtr sap, Pointer userdata, VisitAlignmentsFunc callback);
NLM_EXTERN Int4 VisitAlignmentsOnBsp (BioseqPtr bsp, Pointer userdata, VisitAlignmentsFunc callback);
NLM_EXTERN Int4 VisitAlignmentsOnSet (BioseqSetPtr bssp, Pointer userdata, VisitAlignmentsFunc callback);
NLM_EXTERN Int4 VisitAlignmentsInSet (BioseqSetPtr bssp, Pointer userdata, VisitAlignmentsFunc callback);
NLM_EXTERN Int4 VisitAlignmentsOnSep (SeqEntryPtr sep, Pointer userdata, VisitAlignmentsFunc callback);
NLM_EXTERN Int4 VisitAlignmentsInSep (SeqEntryPtr sep, Pointer userdata, VisitAlignmentsFunc callback);

typedef void (*VisitGraphsFunc) (SeqGraphPtr sgp, Pointer userdata);
NLM_EXTERN Int4 VisitGraphsOnSap (SeqAnnotPtr sap, Pointer userdata, VisitGraphsFunc callback);
NLM_EXTERN Int4 VisitGraphsOnBsp (BioseqPtr bsp, Pointer userdata, VisitGraphsFunc callback);
NLM_EXTERN Int4 VisitGraphsOnSet (BioseqSetPtr bssp, Pointer userdata, VisitGraphsFunc callback);
NLM_EXTERN Int4 VisitGraphsInSet (BioseqSetPtr bssp, Pointer userdata, VisitGraphsFunc callback);
NLM_EXTERN Int4 VisitGraphsOnSep (SeqEntryPtr sep, Pointer userdata, VisitGraphsFunc callback);
NLM_EXTERN Int4 VisitGraphsInSep (SeqEntryPtr sep, Pointer userdata, VisitGraphsFunc callback);

typedef void (*VisitAnnotsFunc) (SeqAnnotPtr sap, Pointer userdata);
NLM_EXTERN Int4 VisitAnnotsOnBsp (BioseqPtr bsp, Pointer userdata, VisitAnnotsFunc callback);
NLM_EXTERN Int4 VisitAnnotsOnSet (BioseqSetPtr bssp, Pointer userdata, VisitAnnotsFunc callback);
NLM_EXTERN Int4 VisitAnnotsInSet (BioseqSetPtr bssp, Pointer userdata, VisitAnnotsFunc callback);
NLM_EXTERN Int4 VisitAnnotsOnSep (SeqEntryPtr sep, Pointer userdata, VisitAnnotsFunc callback);
NLM_EXTERN Int4 VisitAnnotsInSep (SeqEntryPtr sep, Pointer userdata, VisitAnnotsFunc callback);

typedef void (*VisitBioseqsFunc) (BioseqPtr bsp, Pointer userdata);
NLM_EXTERN Int4 VisitBioseqsInSet (BioseqSetPtr bssp, Pointer userdata, VisitBioseqsFunc callback);
NLM_EXTERN Int4 VisitBioseqsInSep (SeqEntryPtr sep, Pointer userdata, VisitBioseqsFunc callback);

/* VisitSequences allows you to limit visitation to nucs or prots that aren't parts, or just to parts */

#define VISIT_MAINS 1
#define VISIT_NUCS  2
#define VISIT_PROTS 3
#define VISIT_PARTS 4

typedef void (*VisitSequencesFunc) (BioseqPtr bsp, Pointer userdata);
NLM_EXTERN Int4 VisitSequencesInSet (BioseqSetPtr bssp, Pointer userdata, Int2 filter, VisitSequencesFunc callback);
NLM_EXTERN Int4 VisitSequencesInSep (SeqEntryPtr sep, Pointer userdata, Int2 filter, VisitSequencesFunc callback);

typedef void (*VisitSetsFunc) (BioseqSetPtr bssp, Pointer userdata);
NLM_EXTERN Int4 VisitSetsInSep (SeqEntryPtr sep, Pointer userdata, VisitSetsFunc callback);
NLM_EXTERN Int4 VisitSetsInSet (BioseqSetPtr bssp, Pointer userdata, VisitSetsFunc callback);

/* visits components of pop/phy/mut/genbank sets, callback is at most nuc-prot set, can then call above functions */

typedef void (*VisitElementsFunc) (SeqEntryPtr sep, Pointer userdata);
NLM_EXTERN Int4 VisitElementsInSep (SeqEntryPtr sep, Pointer userdata, VisitElementsFunc callback);

/* visits all SeqIds within a SeqLoc, or within features, alignments, graphs, or annots */

typedef void (*VisitSeqIdFunc) (SeqIdPtr sip, Pointer userdata);
NLM_EXTERN Int4 VisitSeqIdsInSeqLoc (SeqLocPtr slp, Pointer userdata, VisitSeqIdFunc callback);

NLM_EXTERN Int4 VisitSeqIdsInBioseq (BioseqPtr bsp, Pointer userdata, VisitSeqIdFunc callback);
NLM_EXTERN Int4 VisitSeqIdsInSeqFeat (SeqFeatPtr sfp, Pointer userdata, VisitSeqIdFunc callback);
NLM_EXTERN Int4 VisitSeqIdsInSeqAlign (SeqAlignPtr sap, Pointer userdata, VisitSeqIdFunc callback);
NLM_EXTERN Int4 VisitSeqIdsInSeqGraph (SeqGraphPtr sgp, Pointer userdata, VisitSeqIdFunc callback);
NLM_EXTERN Int4 VisitSeqIdsInSeqAnnot (SeqAnnotPtr annot, Pointer userdata, VisitSeqIdFunc callback);

/* visits all sub UserFields - if the data type is 11, VisitUserFieldsInUfp recurses */

typedef void (*VisitUserFieldsFunc) (UserFieldPtr ufp, Pointer userdata);
NLM_EXTERN Int4 VisitUserFieldsInUfp (UserFieldPtr ufp, Pointer userdata, VisitUserFieldsFunc callback);
NLM_EXTERN Int4 VisitUserFieldsInUop (UserObjectPtr uop, Pointer userdata, VisitUserFieldsFunc callback);

/* visits all sub UserObjects if the data type is 12 - needed to pack multiple user objects on a single feature.  Does not visit user objects which contain other user objects. */

typedef void (*VisitUserObjectFunc) (UserObjectPtr uop, Pointer userdata);
NLM_EXTERN Int4 VisitUserObjectsInUop (UserObjectPtr uop, Pointer userdata, VisitUserObjectFunc callback);
/* Visits all user objects, even if they contain other user objects */
NLM_EXTERN Int4 VisitAllUserObjectsInUop (UserObjectPtr uop, Pointer userdata, VisitUserObjectFunc callback);

/* explores sub UserObjects including "CombinedFeatureUserObjects" and finds by label  */

NLM_EXTERN UserObjectPtr FindUopByTag (UserObjectPtr top, CharPtr tag);

/* creates "CombinedFeatureUserObjects" sfp->ext to combine two user objects */

NLM_EXTERN UserObjectPtr CombineUserObjects (UserObjectPtr origuop, UserObjectPtr newuop);

/* visits all publication descriptors or features */

typedef void (*VisitPubdescsFunc) (PubdescPtr pdp, Pointer userdata);
NLM_EXTERN Int4 VisitPubdescsOnBsp (BioseqPtr bsp, Pointer userdata, VisitPubdescsFunc callback);
NLM_EXTERN Int4 VisitPubdescsOnSet (BioseqSetPtr bssp, Pointer userdata, VisitPubdescsFunc callback);
NLM_EXTERN Int4 VisitPubdescsInSet (BioseqSetPtr bssp, Pointer userdata, VisitPubdescsFunc callback);
NLM_EXTERN Int4 VisitPubdescsOnSep (SeqEntryPtr sep, Pointer userdata, VisitPubdescsFunc callback);
NLM_EXTERN Int4 VisitPubdescsInSep (SeqEntryPtr sep, Pointer userdata, VisitPubdescsFunc callback);

/* visits all authors in a publication */

typedef void (*VisitAuthorFunc) (NameStdPtr nsp, Pointer userdata);
NLM_EXTERN Int4 VisitAuthorsInPub (PubdescPtr pdp, Pointer userdata, VisitAuthorFunc callback);

/* visits all biosource descriptors or features */

typedef void (*VisitBioSourcesFunc) (BioSourcePtr biop, Pointer userdata);
NLM_EXTERN Int4 VisitBioSourcesOnBsp (BioseqPtr bsp, Pointer userdata, VisitBioSourcesFunc callback);
NLM_EXTERN Int4 VisitBioSourcesOnSet (BioseqSetPtr bssp, Pointer userdata, VisitBioSourcesFunc callback);
NLM_EXTERN Int4 VisitBioSourcesInSet (BioseqSetPtr bssp, Pointer userdata, VisitBioSourcesFunc callback);
NLM_EXTERN Int4 VisitBioSourcesOnSep (SeqEntryPtr sep, Pointer userdata, VisitBioSourcesFunc callback);
NLM_EXTERN Int4 VisitBioSourcesInSep (SeqEntryPtr sep, Pointer userdata, VisitBioSourcesFunc callback);

/* function to scan binary ASN.1 file of entire release as Bioseq-set, simple explore from successive top seps */
/* compressed can be TRUE only on UNIX, where it does a popen on zcat to decompress on-the-fly */
/* although it now returns a count of components visited, the callback cannot be NULL for this function */

typedef void (*ScanBioseqSetFunc) (SeqEntryPtr sep, Pointer userdata);
NLM_EXTERN Int4 ScanBioseqSetRelease (
  CharPtr inputFile,
  Boolean binary,
  Boolean compressed,
  Pointer userdata,
  ScanBioseqSetFunc callback
);

/* multi-thread safe version does not free SeqEntryPtr after calling callback, use FreeScanSeqEntryMT */
NLM_EXTERN Int4 ScanBioseqSetReleaseMT (
  CharPtr inputFile,
  Boolean binary,
  Boolean compressed,
  Pointer userdata,
  ScanBioseqSetFunc callback
);
NLM_EXTERN SeqEntryPtr LIBCALL FreeScanSeqEntryMT (
  SeqEntryPtr sep
);

/* More automatic version of ReadAsnFastaOrFlatFile, can read BioseqSet release file */

NLM_EXTERN Int4 ReadSequenceAsnFile (
  CharPtr inputFile,
  Boolean binary,
  Boolean compressed,
  Pointer userdata,
  ScanBioseqSetFunc callback
);

/* function to scan binary ASN.1 file of entrezgene release as Entrezgene-Set */

typedef void (*ScanEntrezgeneSetFunc) (EntrezgenePtr egp, Pointer userdata);
NLM_EXTERN Int4 ScanEntrezgeneSetRelease (
  CharPtr inputFile,
  Boolean binary,
  Boolean compressed,
  Pointer userdata,
  ScanEntrezgeneSetFunc callback
);

/* PubMed registered fetch functionality */

NLM_EXTERN PubmedEntryPtr LIBCALL GetPubMedForUid (Int4 uid);

/* internal support type, registration function */

typedef PubmedEntryPtr (LIBCALLBACK * PubMedFetchFunc) (Int4 uid);

NLM_EXTERN void LIBCALL PubMedSetFetchFunc (PubMedFetchFunc func);

NLM_EXTERN void FirstNameToInitials (CharPtr first, CharPtr inits, size_t maxsize);

extern CharPtr MyFGetLine (FILE *fp, ValNodePtr PNTR current_data);

#if defined (WIN32)
extern char * __stdcall AbstractReadFunction (Pointer userdata);
extern void __stdcall AbstractReportError (TErrorInfoPtr err_ptr, Pointer userdata);
#else
extern char * AbstractReadFunction (Pointer userdata);
extern void AbstractReportError (TErrorInfoPtr err_ptr, Pointer userdata);
#endif

typedef struct readbuffer {
  FILE *fp;
  ValNodePtr current_data;
} ReadBufferData, PNTR ReadBufferPtr;

extern void FreeBufferedReadList (ValNodePtr vnp);

extern CharPtr AlignmentStringToSequenceString (CharPtr aln_str, Uint1 moltype);
extern SeqEntryPtr MakeSequinDataFromAlignment (TAlignmentFilePtr afp, Uint1 moltype);
extern SeqEntryPtr MakeSequinDataFromAlignmentEx (TAlignmentFilePtr afp, Uint1 moltype, Boolean check_ids);
extern SeqEntryPtr make_seqentry_for_seqentry (SeqEntryPtr sep);
extern void ProcessPseudoMiscFeatsForEntityID (Uint2 entityID);
extern Boolean ConvertOnePseudoCDSToMiscFeat (SeqFeatPtr sfp);
NLM_EXTERN Boolean ConvertOnePseudoCDSToMiscFeatEx (SeqFeatPtr sfp, Boolean remove_product);
extern void ConvertPseudoCDSToMiscFeatsForEntityID (Uint2 entityID);

extern SeqAlignPtr FindAlignmentsForBioseq (BioseqPtr bsp);
extern ValNodePtr FindAlignSeqAnnotsForBioseq (BioseqPtr bsp);
extern Boolean IsSequenceFirstInPairwise (SeqEntryPtr sep, SeqIdPtr sip);
extern Boolean RemoveSequenceFromAlignments (SeqEntryPtr sep, SeqIdPtr sip);
extern BioseqPtr ReadFastaOnly (FILE *fp,
                              Boolean forceNuc, Boolean forceProt,
                              BoolPtr chars_stripped,
                              CharPtr lastchar);
extern void MergeFeatureIntervalsToParts (SeqFeatPtr sfp, Boolean ordered);

extern void ExtendSingleGeneOnMRNA (BioseqPtr bsp, Pointer userdata);

typedef struct loginfo 
{
  FILE *fp;
  Boolean data_in_log;
  CharPtr display_title;
  Char path[PATH_MAX];  
} LogInfoData, PNTR LogInfoPtr;

extern LogInfoPtr OpenLog (CharPtr display_title);
extern LogInfoPtr FreeLog (LogInfoPtr lip);

NLM_EXTERN void FixNonWGSSets (ValNodePtr item_list, Pointer data, LogInfoPtr lip);

/* structures and functions for the Discrepancy Report */
typedef void (*ClickableCallback) (ValNodePtr item_list, Pointer userdata);
typedef void (*ClickableCallbackDataFree) (Pointer userdata);
typedef void (*AutofixCallback) (ValNodePtr item_list, Pointer userdata, LogInfoPtr lip);

typedef struct clickableitem 
{
  Uint4                     clickable_item_type;
  CharPtr                   description;
  ValNodePtr                item_list;
  ClickableCallback         callback_func; 
  ClickableCallbackDataFree datafree_func; 
  Pointer                   callback_data;
  Boolean                   chosen;
  ValNodePtr                subcategories;
  Boolean                   expanded;
  Int4                      level;
  AutofixCallback           autofix_func;  /* note - autofix functions can be set for an 
                                            * entire category or for an individual clickable
                                            * item.  Don't set autofix functions in both
                                            * places or they will both be called.
                                            */
  Pointer                   autofix_data;  /* data for item-specific autofixes */
} ClickableItemData, PNTR ClickableItemPtr;

extern ClickableItemPtr 
NewClickableItem 
(Uint4           clickable_item_type,
 CharPtr         description_fmt,
 ValNodePtr      item_list);

extern ClickableItemPtr 
NewClickableItemNoList 
(Uint4           clickable_item_type,
 CharPtr         description);

extern ValNodePtr ClickableItemObjectListFree (ValNodePtr vnp);
extern ValNodePtr ClickableItemObjectListCopy (ValNodePtr orig);
extern ClickableItemPtr ClickableItemFree (ClickableItemPtr cip);
extern ValNodePtr FreeClickableList (ValNodePtr list);
extern Boolean AnyDiscrepanciesChosen (ValNodePtr cip_list);
NLM_EXTERN void ChooseAllDiscrepancies (ValNodePtr cip_list);

extern int LIBCALLBACK SortVnpByClickableItemDescription (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN int LIBCALLBACK SortVnpByClickableItemChosen (VoidPtr ptr1, VoidPtr ptr2);

extern void ExpandClickableItemList (ValNodePtr vnp);
extern void ContractClickableItemList (ValNodePtr vnp);

NLM_EXTERN void RemoveDuplicateItems (ValNodePtr PNTR item_list);

/* To add a new type of test, do ALL Of the following:
 * 1. add an item to the DiscrepancyType enum (this will fill the clickable_item_type value)
 * 2. add a collection function and declare it with the others
 * 3. add an item to discrepancy_info_list that corresponds with the position of the
 *    new enum value.  If you are combining multiple types in one collection function,
 *    be sure to list them together.
 */

typedef enum {
  DISC_GENE_MISSING = 0,
  DISC_SUPERFLUOUS_GENE,
  DISC_GENE_MISSING_LOCUS_TAG,
  DISC_GENE_DUPLICATE_LOCUS_TAG,
  DISC_GENE_LOCUS_TAG_BAD_FORMAT,
  DISC_GENE_LOCUS_TAG_INCONSISTENT_PREFIX,
  DISC_NON_GENE_LOCUS_TAG,
  DISC_COUNT_NUCLEOTIDES,
  DISC_MISSING_PROTEIN_ID,
  DISC_INCONSISTENT_PROTEIN_ID_PREFIX,
  DISC_GENE_CDS_mRNA_LOCATION_CONFLICT,
  DISC_GENE_PRODUCT_CONFLICT,
  DISC_GENE_DUPLICATE_LOCUS,
  DISC_EC_NUMBER_NOTE,
  DISC_PSEUDO_MISMATCH,
  DISC_JOINED_FEATURES,
  DISC_OVERLAPPING_GENES,
  DISC_OVERLAPPING_CDS,
  DISC_CONTAINED_CDS,
  DISC_RNA_CDS_OVERLAP,
  DISC_SHORT_CONTIG,
  DISC_INCONSISTENT_BIOSRC,
  DISC_SUSPECT_PRODUCT_NAME,
  DISC_PRODUCT_NAME_TYPO,
  DISC_PRODUCT_NAME_QUICKFIX,
  DISC_INCONSISTENT_BIOSRC_DEFLINE,
  DISC_PARTIAL_CDS_IN_COMPLETE_SEQUENCE,
  DISC_EC_NUMBER_ON_HYPOTHETICAL_PROTEIN,
  DISC_NO_TAXLOOKUP,
  DISC_BAD_TAXLOOKUP,
  DISC_SHORT_SEQUENCE,
  DISC_SUSPECT_PHRASES,
  DISC_SUSPICIOUS_NOTE_TEXT,
  DISC_COUNT_TRNA,
  DISC_DUP_TRNA,
  DISC_BADLEN_TRNA,
  DISC_STRAND_TRNA,
  DISC_COUNT_RRNA,
  DISC_DUP_RRNA,
  DISC_RNA_NO_PRODUCT,
  DISC_TRANSL_NO_NOTE,
  DISC_NOTE_NO_TRANSL,
  DISC_TRANSL_TOO_LONG,
  DISC_CDS_OVERLAP_TRNA,
  DISC_COUNT_PROTEINS,
  DISC_FEAT_OVERLAP_SRCFEAT,
  DISC_MISSING_GENPRODSET_PROTEIN,
  DISC_DUP_GENPRODSET_PROTEIN,
  DISC_MISSING_GENPRODSET_TRANSCRIPT_ID,
  DISC_DUP_GENPRODSET_TRANSCRIPT_ID,
  DISC_PERCENTN,
  DISC_N_RUNS,
  DISC_ZERO_BASECOUNT,
  DISC_ADJACENT_PSEUDOGENE,
  DISC_NO_ANNOTATION,
  DISC_INFLUENZA_DATE_MISMATCH,
  DISC_SHORT_INTRON,
  DISC_MISSING_VIRAL_QUALS,
  DISC_SRC_QUAL_PROBLEM,
  DISC_MISSING_SRC_QUAL,
  DISC_DUP_SRC_QUAL,
  DISC_DUP_SRC_QUAL_DATA,
  DISC_HAPLOTYPE_MISMATCH,
  DISC_FEATURE_MOLTYPE_MISMATCH,
  DISC_CDS_WITHOUT_MRNA,
  DISC_EXON_INTRON_CONFLICT,
  DISC_FEATURE_COUNT,
  DISC_SPECVOUCHER_TAXNAME_MISMATCH,
  DISC_GENE_PARTIAL_CONFLICT,
  DISC_FLATFILE_FIND_ONCALLER,
  DISC_CDS_PRODUCT_FIND,
  DISC_DUP_DEFLINE,
  DUP_DISC_ATCC_CULTURE_CONFLICT,
  DISC_USA_STATE,
  DISC_INCONSISTENT_MOLTYPES,
  DISC_SUBMITBLOCK_CONFLICT,
  DISC_POSSIBLE_LINKER,
  DISC_TITLE_AUTHOR_CONFLICT,
  DISC_BAD_GENE_STRAND,
  DISC_MAP_CHROMOSOME_CONFLICT,
  DISC_RBS_WITHOUT_GENE,
  DISC_CITSUBAFFIL_CONFLICT,
  DISC_REQUIRED_CLONE,
  DISC_SOURCE_QUALS_ASNDISC,
  DISC_mRNA_ON_WRONG_SEQUENCE_TYPE,
  DISC_RETROVIRIDAE_DNA,
  DISC_CHECK_AUTH_CAPS,
  DISC_CHECK_RNA_PRODUCTS_AND_COMMENTS,
  DISC_MICROSATELLITE_REPEAT_TYPE,
  DISC_MITOCHONDRION_REQUIRED,
  DISC_UNPUB_PUB_WITHOUT_TITLE,
  DISC_QUALITY_SCORES,
  DISC_INTERNAL_TRANSCRIBED_SPACER_RRNA,
  DISC_PARTIAL_PROBLEMS,
  DISC_BACTERIAL_PARTIAL_NONEXTENDABLE_PROBLEMS,
  DISC_BACTERIAL_PARTIAL_NONEXTENDABLE_EXCEPTION,
  DISC_SUSPECT_RRNA_PRODUCTS,
  DISC_SUSPECT_MISC_FEATURES,
  DISC_BACTERIA_MISSING_STRAIN,
  DISC_MISSING_DEFLINES,
  DISC_MISSING_AFFIL,
  DISC_BACTERIA_SHOULD_NOT_HAVE_ISOLATE,
  DISC_BACTERIA_SHOULD_NOT_HAVE_MRNA,
  DISC_CDS_HAS_NEW_EXCEPTION,
  DISC_TRINOMIAL_SHOULD_HAVE_QUALIFIER,
  DISC_METAGENOMIC,
  DISC_METAGENOME_SOURCE,
  ONCALLER_GENE_MISSING,
  ONCALLER_SUPERFLUOUS_GENE,
  DISC_SHORT_RRNA,
  ONCALLER_CHECK_AUTHORITY,
  ONCALLER_CONSORTIUM,
  ONCALLER_STRAIN_CULTURE_COLLECTION_MISMATCH,
  ONCALLER_MULTISRC,
  ONCALLER_MULTIPLE_CULTURE_COLLECTION,
  DISC_SEGSETS_PRESENT,
  DISC_NONWGS_SETS_PRESENT,
  DISC_FEATURE_LIST,
  DISC_CATEGORY_HEADER,
  DISC_MISMATCHED_COMMENTS,
  DISC_STRAIN_TAXNAME_MISMATCH,
  DISC_HUMAN_HOST,
  DISC_BAD_BACTERIAL_GENE_NAME,
  TEST_BAD_GENE_NAME,
  ONCALLER_ORDERED_LOCATION,
  ONCALLER_COMMENT_PRESENT,
  ONCALLER_DEFLINE_ON_SET,
  ONCALLER_HIV_RNA_INCONSISTENT,
  SHORT_PROT_SEQUENCES,
  TEST_EXON_ON_MRNA,
  TEST_HAS_PROJECT_ID,
  ONCALLER_HAS_STANDARD_NAME,
  ONCALLER_MISSING_STRUCTURED_COMMENTS,
  DISC_REQUIRED_STRAIN,
  MISSING_GENOMEASSEMBLY_COMMENTS,
  DISC_BACTERIAL_TAX_STRAIN_MISMATCH,
  TEST_CDS_HAS_CDD_XREF,
  TEST_UNUSUAL_NT,
  TEST_LOW_QUALITY_REGION,
  TEST_ORGANELLE_NOT_GENOMIC,
  TEST_UNWANTED_SPACER,
  TEST_ORGANELLE_PRODUCTS,
  TEST_SP_NOT_UNCULTURED,
  TEST_BAD_MRNA_QUAL,
  TEST_UNNECESSARY_ENVIRONMENTAL,
  TEST_UNNECESSARY_VIRUS_GENE,
  TEST_UNWANTED_SET_WRAPPER,
  TEST_MISSING_PRIMER,
  TEST_UNUSUAL_MISC_RNA,
  TEST_AMPLIFIED_PRIMERS_NO_ENVIRONMENTAL_SAMPLE,
  TEST_DUP_GENES_OPPOSITE_STRANDS,
  TEST_SMALL_GENOME_SET_PROBLEM,
  TEST_OVERLAPPING_RRNAS,
  TEST_MRNA_SEQUENCE_MINUS_STRAND_FEATURES,
  TEST_TAXNAME_NOT_IN_DEFLINE,
  MAX_DISC_TYPE
} DiscrepancyType;


typedef enum {
  eReportTypeDiscrepancy = 1,
  eReportTypeOnCaller,
  eReportTypeMegaReport
} EDiscrepancyReportType;

extern Boolean IsTestTypeAppropriateForReportType (Int4 test_type, EDiscrepancyReportType report_type);

extern void PrintDiscrepancyTestList (FILE *fp);

extern void SetDiscrepancyLevels (ValNodePtr discrepancy_list, Int4 level);

extern CharPtr GetDiscrepancyTestConfName (DiscrepancyType dtype);
extern CharPtr GetDiscrepancyTestSettingName (DiscrepancyType dtype);
extern DiscrepancyType GetDiscrepancyTypeFromSettingName (CharPtr setting_name);

typedef struct discrepancyconfig
{
  Boolean conf_list[MAX_DISC_TYPE];
  Boolean use_feature_table_format;
} DiscrepancyConfigData, PNTR DiscrepancyConfigPtr;

extern DiscrepancyConfigPtr DiscrepancyConfigFree (DiscrepancyConfigPtr dcp);
extern DiscrepancyConfigPtr DiscrepancyConfigNew (void);
extern DiscrepancyConfigPtr DiscrepancyConfigCopy (DiscrepancyConfigPtr dcp);
extern DiscrepancyConfigPtr ReadDiscrepancyConfig (void);
extern DiscrepancyConfigPtr ReadDiscrepancyConfigEx (CharPtr report_config_name);
extern void SaveDiscrepancyConfig (DiscrepancyConfigPtr dcp);
extern void SaveDiscrepancyConfigEx (DiscrepancyConfigPtr dcp, CharPtr report_name);
extern void DisableTRNATests (DiscrepancyConfigPtr dcp);
extern CharPtr SetDiscrepancyReportTestsFromString (CharPtr list, Boolean enable, DiscrepancyConfigPtr dcp);
extern void ConfigureForBigSequence (DiscrepancyConfigPtr dcp);
extern void ConfigureForGenomes (DiscrepancyConfigPtr dcp);
extern void ConfigureForReportType (DiscrepancyConfigPtr dcp, EDiscrepancyReportType report_type);

typedef void (*PerformDiscrepancyTest) PROTO ((ValNodePtr PNTR, ValNodePtr));

extern ValNodePtr CollectDiscrepancies (DiscrepancyConfigPtr dcp, ValNodePtr sep_list, PerformDiscrepancyTest taxlookup);
extern void AutofixDiscrepancies (ValNodePtr vnp, Boolean fix_all, LogInfoPtr lip);
extern void ChooseFixableDiscrepancies (ValNodePtr vnp);
extern CharPtr GetDiscrepancyItemText (ValNodePtr vnp);
extern CharPtr GetDiscrepancyItemTextEx (ValNodePtr vnp, CharPtr filename);
extern void VisitGenProdSetFeatures (SeqEntryPtr sep, Pointer userdata, VisitFeaturesFunc callback);
extern ValNodePtr ReplaceDiscrepancyItemWithFeatureTableStrings (ValNodePtr feat_list);
extern CharPtr GetParentLabelForDiscrepancyItem (ValNodePtr vnp);
extern void WriteDiscrepancy (FILE *fp, ClickableItemPtr dip, Boolean use_feature_table_fmt);
extern void WriteDiscrepancyEx (FILE *fp, ClickableItemPtr dip, Boolean use_feature_table_fmt, Boolean cmd_line, CharPtr descr_prefix, Boolean list_features_if_subcat);
extern int LIBCALLBACK SortVnpByDiscrepancyDescription (VoidPtr ptr1, VoidPtr ptr2);
extern int LIBCALLBACK SortVnpByDiscrepancyItemText (VoidPtr ptr1, VoidPtr ptr2);
extern void ValNodeReverse (ValNodePtr PNTR list);

/* Individual discrepancy test function declarations */
extern const CharPtr kOverlappingCDSNoteText;
extern const CharPtr kOverlappingCDSNeedsNoteFmt;
extern void AddOverlappingCodingRegionDiscrepancies (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list);
extern void AddDiscrepanciesForMissingOrNonUniqueGeneLocusTagsEx (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list, Boolean exclude_dirsub);
extern void AddDiscrepanciesForMissingOrNonUniqueGeneLocusTags (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list);
extern void FindShortIntrons (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list);
extern void CheckBioSourceQuals (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list);
extern void FindExtendablePartials (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list);
extern void FindBacterialNonExtendablePartials (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list);
NLM_EXTERN void FindMismatchedComments (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list);

/* autofix functions */
NLM_EXTERN void MarkOverlappingCDSs (ValNodePtr item_list, Pointer data, LogInfoPtr lip);
NLM_EXTERN void FixBacterialNonExtendablePartials (ValNodePtr item_list, Pointer data, LogInfoPtr lip);
NLM_EXTERN void FixExtendablePartials (ValNodePtr item_list, Pointer data, LogInfoPtr lip);
NLM_EXTERN void FixMismatchedComments (ValNodePtr item_list, Pointer data, LogInfoPtr lip);
NLM_EXTERN void FixHumanHosts (ValNodePtr item_list, Pointer data, LogInfoPtr lip);
NLM_EXTERN void FixOrderedLocations (ValNodePtr item_list, Pointer data, LogInfoPtr lip);
NLM_EXTERN void OncallerToolPseudoDiscrepanciesFix (ValNodePtr item_list, Pointer data, LogInfoPtr lip);
NLM_EXTERN void OncallerToolFindEcoNoEnvFix (ValNodePtr item_list, Pointer data, LogInfoPtr lip);
NLM_EXTERN void AddExceptionsToShortIntrons (ValNodePtr item_list, Pointer data, LogInfoPtr lip);

/* structure shared by tbl2asn and discrepancy report functions */
typedef struct genprodsetdiscrepancylists {
  ValNodePtr cds_product_list;
  ValNodePtr mrna_product_list;
  ValNodePtr missing_mrna_product;
  ValNodePtr missing_protein_id;
} GenProdSetDiscrepancyListsData, PNTR GenProdSetDiscrepancyListsPtr;

extern void CheckGenProdSetsInSeqEntry (SeqEntryPtr sep, GenProdSetDiscrepancyListsPtr lists);  


typedef struct protidlists {
  ValNodePtr missing_gnl_list;
  ValNodePtr gnl_list;
} ProtIdListsData, PNTR ProtIdListsPtr;

/* structure shared by tbl2asn and discrepancy report functions */
typedef struct globaldiscrepancy {
  CharPtr str;
  Uint1   data_choice;
  Pointer data;
} GlobalDiscrepancyData, PNTR GlobalDiscrepancyPtr;

extern GlobalDiscrepancyPtr GlobalDiscrepancyNew (CharPtr str, Uint1 data_choice, Pointer data);
extern GlobalDiscrepancyPtr GlobalDiscrepancyFree (GlobalDiscrepancyPtr g);
extern ValNodePtr FreeGlobalDiscrepancyList (ValNodePtr vnp);
extern void ConvertGlobalDiscrepancyToText (GlobalDiscrepancyPtr g, Boolean use_feature_fmt, CharPtr filename);
extern void ConvertGlobalDiscrepancyListToText (ValNodePtr vnp, Boolean use_feature_fmt, CharPtr filename);
extern ValNodePtr GetGlobalDiscrepancyItem (GlobalDiscrepancyPtr g);
extern CharPtr GetGlobalDiscrepancyStr (GlobalDiscrepancyPtr g);
NLM_EXTERN int LIBCALLBACK SortVnpByGlobalDiscrepancyString (VoidPtr ptr1, VoidPtr ptr2);
extern ClickableItemPtr
ReportNonUniqueGlobalDiscrepancy 
(ValNodePtr vnp, 
 CharPtr    label_fmt,
 CharPtr    ind_cat_fmt,
 Uint4      clickable_item_type,
 Boolean    keep_top_category);
extern ValNodePtr ReportInconsistentGlobalDiscrepancyPrefixes
(ValNodePtr vnp, 
 CharPtr    label_fmt,
 Uint4      clickable_item_type);
extern ValNodePtr ReportInconsistentGlobalDiscrepancyStrings
(ValNodePtr vnp, 
 CharPtr    label_fmt,
 Uint4      clickable_item_type);
extern ClickableItemPtr ReportMissingFields (ValNodePtr list, CharPtr label_fmt, Uint4 clickable_item_type);
extern ClickableItemPtr ReportBadLocusTagFormat (ValNodePtr list);
extern ClickableItemPtr FindAdjacentDuplicateLocusTagGenes (ValNodePtr locus_tag_list);
extern void FindProteinIDCallback (BioseqPtr bsp, Pointer userdata);


/* formats for global discrepancies also used by tbl2asn */
extern CharPtr discReportDuplicateLocusTagFmt;
extern CharPtr discReportOneDuplicateLocusTagFmt;
extern CharPtr discReportDuplicateProteinIDFmt;
extern CharPtr discReportOneDuplicateProteinIDFmt;
extern CharPtr discReportDuplicateTranscriptIdFmt;
extern CharPtr discReportOneDuplicateTranscriptIdFmt;
extern CharPtr discReportInconsistentLocusTagPrefixFmt;
extern CharPtr discReportMissingLocusTags;
extern CharPtr discReportInconsistentProteinIDPrefixFmt;
extern CharPtr discReportBadProteinIdFmt;
extern CharPtr discReportMissingTranscriptIDFmt;

extern CharPtr GetBioseqLabel (BioseqPtr bsp);
extern CharPtr GetBioseqSetLabel (BioseqSetPtr bssp);

NLM_EXTERN ValNodePtr ValNodeDupStringList (ValNodePtr vnp);
NLM_EXTERN ValNodePtr ValNodeDupIntList (ValNodePtr vnp);

typedef enum {
  eLocusTagErrorBadFormat,
  eLocusTagErrorDuplicate,
  eLocusTagErrorInconsistentPrefix
} ELocusTagError;

NLM_EXTERN ValNodePtr FindBadLocusTagsInList (ValNodePtr list);


typedef struct discreportoutputconfig {
  Boolean use_feature_table_format;
  Boolean expand_report_categories[MAX_DISC_TYPE];
  Boolean summary_report;
} DiscReportOutputConfigData, PNTR DiscReportOutputConfigPtr;


typedef struct globaldiscrepreport {
  ValNodePtr  locus_tag_list;
  ValNodePtr  missing_locus_tag;
  ValNodePtr  cds_product_list;
  ValNodePtr  missing_cds_product;
  ValNodePtr  mrna_product_list;
  ValNodePtr  missing_mrna_product;
  ValNodePtr  adjacent_locus_tag_disc_list;
  ValNodePtr  missing_gnl_list;
  ValNodePtr  gnl_list;
  ValNodePtr  global_src_qual_vals;
  ValNodePtr  global_srcs;

  ValNodePtr  src_qual_repeated_list;
  ValNodePtr  src_qual_multi_list;
  ValNodePtr  feature_count_list;
  ValNodePtr  discrepancy_list;

  PerformDiscrepancyTest    taxlookup;
  DiscrepancyConfigPtr      test_config;
  DiscReportOutputConfigPtr output_config;
} GlobalDiscrepReportData, PNTR GlobalDiscrepReportPtr;

NLM_EXTERN GlobalDiscrepReportPtr GlobalDiscrepReportNew ();
NLM_EXTERN GlobalDiscrepReportPtr GlobalDiscrepReportFree (GlobalDiscrepReportPtr g);
NLM_EXTERN void AddSeqEntryToGlobalDiscrepReport (SeqEntryPtr sep, GlobalDiscrepReportPtr g, CharPtr filename);
NLM_EXTERN void WriteGlobalDiscrepancyReport (GlobalDiscrepReportPtr g, FILE *fp);

NLM_EXTERN Boolean CollectionDateIsInTheFuture (CharPtr name);
NLM_EXTERN Boolean CollectionDateIsValid (CharPtr name);

/* for the Barcode Discrepancy Test */
typedef enum {
  eBarcodeTest_Length = 0,
  eBarcodeTest_Primers,
  eBarcodeTest_Country,
  eBarcodeTest_SpecimenVoucher,
  eBarcodeTest_PercentN,
  eBarcodeTest_CollectionDate,
  eBarcodeTest_OrderAssignment,
  eBarcodeTest_LowTrace,
  eBarcodeTest_FrameShift,
  eBarcodeTest_LAST
} EBarcodeTest;

typedef struct barcodetestconfig
{
  Boolean conf_list[eBarcodeTest_LAST];
  Int4    min_length;
  FloatLo min_n_percent;
  Boolean require_keyword;
} BarcodeTestConfigData, PNTR BarcodeTestConfigPtr;

extern BarcodeTestConfigPtr BarcodeTestConfigNew();
extern BarcodeTestConfigPtr BarcodeTestConfigFree (BarcodeTestConfigPtr cfg);

extern CharPtr GetBarcodeTestName (Int4 i);

extern Int4 GetBarcodeTestNumFromBarcodeTestName (CharPtr test_name);

typedef struct barcodetestresults
{
  Boolean failed_tests[eBarcodeTest_LAST];
  BioseqPtr bsp;
  FloatLo   n_percent;
  Int4      num_trace;
} BarcodeTestResultsData, PNTR BarcodeTestResultsPtr;

extern BarcodeTestResultsPtr BarcodeTestResultsNew ();
extern BarcodeTestResultsPtr BarcodeTestResultsFree (BarcodeTestResultsPtr res);
extern BarcodeTestResultsPtr BarcodeTestResultsCopy (BarcodeTestResultsPtr res);
extern ValNodePtr            BarcodeTestResultsListFree (ValNodePtr res_list);
extern ValNodePtr            BarcodeTestResultsExtractPass (ValNodePtr PNTR res_list);

extern Boolean IsBarcodeID (SeqIdPtr sip);

extern CharPtr BarcodeTestBarcodeIdString (BioseqPtr bsp);
extern CharPtr BarcodeTestGenbankIdString (BioseqPtr bsp);

/* This one gets discrepancies by category */
extern ValNodePtr GetBarcodeDiscrepancies (ValNodePtr sep_list, BarcodeTestConfigPtr cfg);
extern ValNodePtr GetBarcodePassFail (SeqEntryPtr sep, BarcodeTestConfigPtr cfg);
NLM_EXTERN CharPtr GetBarcodeTestFailureReasons (BarcodeTestResultsPtr res);
/* This one lists passes and failures, with reasons for failures */
extern void WriteBarcodeTestComprehensive (FILE *fp, ValNodePtr results_list);
extern void WriteBarcodeDiscrepancies (FILE *fp, ValNodePtr results_list);
extern void WriteBarcodeFailureReport (FILE *fp, ValNodePtr results_list);
extern void WriteBarcodeTestCompliance (FILE *fp, ValNodePtr results_list);
extern void WriteBarcodeTestComplianceEx (FILE *fp, ValNodePtr results_list, Boolean low_trace_fail);
extern void WriteBarcodeTagTable (FILE *fp, ValNodePtr results_list);
NLM_EXTERN Boolean IsIBOL (BioseqPtr bsp);

NLM_EXTERN Boolean 
BarcodeValidateOneSeqEntry 
(FILE *ofp,
 SeqEntryPtr sep,
 Boolean show_all,
 Boolean use_xml,
 Boolean show_header,
 CharPtr xml_header_text);
extern void RemoveBarcodeTech (FILE *fp, ValNodePtr results_list);
extern void RemoveBarcodeKeywords (FILE *fp, ValNodePtr results_list);
extern void ApplyBarcodeKeywords (FILE *fp, ValNodePtr results_list);
extern void ApplyBarcodeTech (FILE *fp, ValNodePtr results_list);
extern Boolean PassBarcodeTests (BarcodeTestResultsPtr res);
extern Boolean HasBARCODETech (BioseqPtr bsp);
NLM_EXTERN void ApplyBarcodeKeywordToBioseq (BioseqPtr bsp);
NLM_EXTERN Boolean BioseqHasBarcodeKeyword (BioseqPtr bsp);
NLM_EXTERN Boolean BioseqHasKeyword (BioseqPtr bsp, CharPtr keyword);
NLM_EXTERN void RemoveBarcodeKeywordsFromObjectList (FILE *fp, ValNodePtr object_list);
NLM_EXTERN Boolean RemoveBarcodeTechFromBioseq (BioseqPtr bsp);
extern Int4 CountPolymorphismsInBioseq (BioseqPtr bsp);
NLM_EXTERN Boolean RemoveBarcodeKeywordFromBioseq (BioseqPtr bsp);


extern CharPtr ExpandDiscrepancyReportTestsFromString (CharPtr list, Boolean expand, DiscReportOutputConfigPtr dcp);
extern void CollateDiscrepancyReports (ValNodePtr PNTR discrepancy_reports);
extern void WriteAsnDiscReport (ValNodePtr discrepancy_list, FILE *ofp, DiscReportOutputConfigPtr oc, Boolean use_flag);


/* extern to allow access to subsource_subtype_alist */
typedef struct Nlm_qual_name_assoc {
   Nlm_CharPtr name; 
   Uint1       value;
} Nlm_QualNameAssoc, PNTR Nlm_QualNameAssocPtr, Nlm_QualNameAlist[];

typedef struct Nlm_name_name_assoc {
   Nlm_CharPtr name; 
   Nlm_CharPtr alias; 
   Uint1       value;
} Nlm_NameNameAssoc, PNTR Nlm_NameNameAssocPtr, Nlm_NameNameAlist[];

extern Nlm_QualNameAssoc current_orgmod_subtype_alist[];
extern Nlm_QualNameAssoc discouraged_orgmod_subtype_alist[];
extern Nlm_QualNameAssoc discontinued_orgmod_subtype_alist[];
extern Nlm_NameNameAssoc orgmod_aliases[];
extern CharPtr GetOrgModQualName (Uint1 subtype);
extern void BioSourceHasOldOrgModQualifiers (BioSourcePtr biop, BoolPtr has_discouraged, BoolPtr has_discontinued);

extern Nlm_QualNameAssoc  current_subsource_subtype_alist [];
extern Nlm_QualNameAssoc  discouraged_subsource_subtype_alist[];
extern Nlm_QualNameAssoc  discontinued_subsource_subtype_alist[];
extern Nlm_NameNameAssoc  subsource_aliases [];
extern CharPtr GetSubsourceQualName (Uint1 subtype);
extern void BioSourceHasOldSubSourceQualifiers (BioSourcePtr biop, BoolPtr has_discouraged, BoolPtr has_discontinued);
extern Boolean GeneRefMatch (GeneRefPtr grp1, GeneRefPtr grp2);
extern Boolean DbxrefsMatch (ValNodePtr vnp1, ValNodePtr vnp2, Boolean case_sensitive);
extern Boolean XrefsMatch (SeqFeatXrefPtr x1, SeqFeatXrefPtr x2);
extern Boolean ProtRefMatch (ProtRefPtr prp1, ProtRefPtr prp2);
NLM_EXTERN Boolean DoFeaturesMatch (SeqFeatPtr sfp1, SeqFeatPtr sfp2, Boolean allow_different_sequences, Boolean case_sensitive, Boolean ignore_partial);

extern void IsCorrectLatLonFormat (CharPtr lat_lon, BoolPtr format_correct, BoolPtr lat_in_range, BoolPtr lon_in_range);
extern CharPtr FixLatLonFormat (CharPtr orig_lat_lon);
extern Boolean ParseLatLon (CharPtr lat_lon, FloatHi PNTR latP, FloatHi PNTR lonP);
extern void ApplyBarcodeDbxrefsToBioseq (BioseqPtr bsp, Pointer data);

extern CharPtr GetCountryFix (CharPtr country, CharPtr PNTR country_list);

extern CharPtr ncrnaClassList[];
extern Int4 NcrnaOTHER;
extern Boolean IsStringInNcRNAClassList (CharPtr str);
extern ValNodePtr ListFeaturesInLocation (BioseqPtr bsp, SeqLocPtr slp, Uint1 seqfeatChoice, Uint1 featdefChoice);
extern ValNodePtr ListCodingRegionsContainedInSourceFeatures (SeqEntryPtr sep);
extern ValNodePtr ListFeaturesOverlappingLocationEx (BioseqPtr bsp, SeqLocPtr slp, Uint1 seqfeatChoice, Uint1 featdefChoice, ValNodePtr constraint);
extern ValNodePtr ListFeaturesOverlappingLocation (BioseqPtr bsp, SeqLocPtr slp, Uint1 seqfeatChoice, Uint1 featdefChoice);

extern void ConvertSourceFeatDescProc (SeqFeatPtr sfp, Pointer userdata);

/* for correcting capitalization */
NLM_EXTERN void 
FixCapitalizationInElement 
(CharPtr PNTR pEl,
 Boolean      bAbbrev, 
 Boolean      bShortWords,
 Boolean      bApostrophes);

NLM_EXTERN void FixCapitalizationInAuthor (AuthorPtr pAuthor);
NLM_EXTERN void FixCapsInPubAffil (AffilPtr affil);
NLM_EXTERN void FixCapsInPubAffilEx (AffilPtr affil, Boolean punct_only);
NLM_EXTERN void FixCapitalizationInCountryString (CharPtr PNTR pCountry);
NLM_EXTERN void FixCapitalizationInCountryStringEx (CharPtr PNTR pCountry, Boolean punct_only);
NLM_EXTERN void FixStateAbbreviationsInAffil (AffilPtr affil, LogInfoPtr lip);

NLM_EXTERN void FixAffiliationShortWordsInElement (CharPtr PNTR pEl);
NLM_EXTERN void FixKnownAbbreviationsInElement (CharPtr PNTR pEl);

NLM_EXTERN void FixAbbreviationsInElement (CharPtr PNTR pEl);
NLM_EXTERN void FixOrgNamesInString (CharPtr str, ValNodePtr org_names);
NLM_EXTERN void ResetCapitalization (Boolean first_is_upper, CharPtr pString);

NLM_EXTERN SeqIdPtr CreateSeqIdFromText (CharPtr id_str, SeqEntryPtr sep);
NLM_EXTERN SeqLocPtr SeqLocWholeNew (BioseqPtr bsp);
NLM_EXTERN Int4 GetDeltaSeqLen (DeltaSeqPtr dsp);

typedef SeqAlignPtr (*GlobalAlignFunc) PROTO ((BioseqPtr, BioseqPtr, BoolPtr));

typedef enum {
  eAdjustFeatForGap_unknown_gaps = 0x01,
  eAdjustFeatForGap_known_gaps = 0x02,
  eAdjustFeatForGap_make_partial = 0x04,
  eAdjustFeatForGap_partial_for_pseudo = 0x08,
  eAdjustFeatForGap_trim_ends = 0x10,
  eAdjustFeatForGap_split_internal = 0x20,
  eAdjustFeatForGap_split_in_intron = 0x40
} EAdjustFeatForGap;

typedef struct adjustfeatforgap {
  ValNodePtr feature_list;
  Uint4      options;
  GlobalAlignFunc align_func;
  ValNodePtr features_in_gap;
} AdjustFeatForGapData, PNTR AdjustFeatForGapPtr;

NLM_EXTERN AdjustFeatForGapPtr AdjustFeatForGapFree (AdjustFeatForGapPtr agp);
NLM_EXTERN Boolean FeatureOkForFeatureList (SeqFeatPtr sfp, ValNodePtr feature_list);
NLM_EXTERN void
LocationContainsGaps
(SeqLocPtr slp,
 BioseqPtr bsp,
 Uint4     options,
 BoolPtr   terminal_gaps,
 BoolPtr   internal_gaps,
 BoolPtr   entirely_in_gap);

NLM_EXTERN void AdjustFeatureForGapsCallback (SeqFeatPtr sfp, Pointer data);
NLM_EXTERN void MarkFeaturesInGapsForDeletion (AdjustFeatForGapPtr afgp);
NLM_EXTERN void AdjustCDSLocationsForUnknownGapsCallback (SeqFeatPtr sfp, Pointer data);
NLM_EXTERN Boolean GapInLocation (Int4 seq_offset, Int4 length, SeqLocPtr loc);
NLM_EXTERN BioseqPtr 
AddProteinSequenceCopy 
(BioseqPtr  protbsp, 
 BioseqPtr  featbsp,
 SeqFeatPtr new_sfp,
 Uint2      entityID);
NLM_EXTERN void AdjustFrame (SeqFeatPtr sfp, BioseqPtr oldprot);
NLM_EXTERN void SetProductSequencePartials (BioseqPtr protbsp, Boolean partial5, Boolean partial3);
NLM_EXTERN void AddCDSGapComment (SeqFeatPtr sfp);


NLM_EXTERN Boolean SeqEdFixProteinFeatures (BioseqPtr oldbsp, BioseqPtr newbsp, Boolean force_fix, GlobalAlignFunc align_func);
NLM_EXTERN void SeqEdTranslateOneCDS (SeqFeatPtr sfp, BioseqPtr featbsp, Uint2 entityID, GlobalAlignFunc align_func);
NLM_EXTERN void SeqEdRemapLocation (SeqAlignPtr salp, SeqLocPtr slp, Int4 seq_len);

NLM_EXTERN CharPtr GetStateAbbreviation (CharPtr state);

typedef SeqAlignPtr (*LocalAlignFunc) PROTO ((BioseqPtr, BioseqPtr));

typedef struct transcriptomeids {
  BioseqPtr consensus_bsp;
  ValNodePtr token_list;
} TranscriptomeIdsData, PNTR TranscriptomeIdsPtr;

NLM_EXTERN TranscriptomeIdsPtr TranscriptomeIdsNew (BioseqPtr bsp, ValNodePtr token_list);
NLM_EXTERN TranscriptomeIdsPtr TranscriptomeIdsFree (TranscriptomeIdsPtr t);

NLM_EXTERN ValNodePtr TranscriptomeIdsListFree (ValNodePtr list);
NLM_EXTERN ValNodePtr GetTranscriptomeIdsList (FILE *fp, SeqEntryPtr sep, ValNodePtr PNTR err_list);
NLM_EXTERN ValNodePtr GetExistingTSATableIds (SeqEntryPtr sep);

NLM_EXTERN ValNodePtr 
ApplyTranscriptomeIdsListToSeqEntrySeqHist 
(ValNodePtr           list,
 LocalAlignFunc      aln_func,
 Nlm_ChangeNotifyProc change_notify,
 Pointer              change_userdata);
NLM_EXTERN ValNodePtr 
MakeTranscriptomeAssemblySeqHist 
(TranscriptomeIdsPtr t,
 LocalAlignFunc aln_func,
 Nlm_ChangeNotifyProc     change_notify,
 Pointer                  change_userdata);

extern void ReverseAlignmentStrand (SeqAlignPtr salp, Int4 nth);

NLM_EXTERN Boolean HasExistingSeqHistAssembly (ValNodePtr list);
NLM_EXTERN void DeleteSeqHistAssembliesForList (ValNodePtr list);
NLM_EXTERN ValNodePtr ReportCoverageForTranscriptomeIdsListSeqHist (ValNodePtr list);

NLM_EXTERN SeqAlignPtr SortPairwiseAlignmentsByFirstSeqRange (SeqAlignPtr salp);
NLM_EXTERN ValNodePtr ReportCoverageForBioseqSeqHist (BioseqPtr bsp);
NLM_EXTERN ValNodePtr ReportConsensusMatchForBioseqSeqHist (BioseqPtr bsp);

NLM_EXTERN ValNodePtr ReportGapsInSeqHistAlignmentForBioseq (BioseqPtr bsp);
NLM_EXTERN ValNodePtr ReportGapsInSeqHistAlignmentsForIdsList (ValNodePtr list);

NLM_EXTERN void ConvertLocalIdsToTSAIds (SeqEntryPtr sep, CharPtr suffix);
NLM_EXTERN void ConvertLocalIdsToBarcodeIds (SeqEntryPtr sep);

NLM_EXTERN ValNodePtr MakeTokensFromLine (CharPtr line);

NLM_EXTERN SeqFeatPtr GetGeneForFeature (SeqFeatPtr sfp);
NLM_EXTERN SeqFeatPtr GetmRNAforCDS (SeqFeatPtr cds);
NLM_EXTERN SeqFeatPtr GetCDSformRNA (SeqFeatPtr mrna);

NLM_EXTERN Boolean IsStringInSpanInList (CharPtr str, CharPtr list);

NLM_EXTERN void ParseGoTermsFromFields (SeqEntryPtr sep);

/* for autodef */
typedef enum {
  RemovableExon = 0,
  RemovableIntron,
  Removable5UTR,
  Removable3UTR,
  RemovableuORF,
  RemovableCDS,
  RemovablePromoter,
  RemovableLTR,
  RemovableNoncodingProductFeat,
  RemovableMobileElement,
  RemovablePrecursorRNA,
  RemovablencRNA,
  NumRemovableItems
} RemovableList;
NLM_EXTERN CharPtr GetRemovableItemName (Int4 i);

typedef enum {
  DEFLINE_USE_FEATURES = 1,
  DEFLINE_COMPLETE_SEQUENCE,
  DEFLINE_PARTIAL_SEQUENCE,
  DEFLINE_COMPLETE_GENOME,
  DEFLINE_PARTIAL_GENOME,
  DEFLINE_SEQUENCE
} DefLineType;

typedef struct deflinefeaturerequestlist {
  Boolean      keep_items[NumRemovableItems];
  Boolean      add_fake_promoters;
  Boolean      suppress_alt_splice_phrase;
  Boolean      remove_subfeatures;
  DefLineType  feature_list_type;
  Int4         misc_feat_parse_rule;
  Boolean      suppress_locus_tags;
  ValNodePtr   suppressed_feature_list;
  Boolean      use_ncrna_note;
  Boolean      suppress_allele;
} DeflineFeatureRequestList, PNTR DeflineFeatureRequestListPtr;

NLM_EXTERN void InitFeatureRequests (DeflineFeatureRequestListPtr feature_requests);


/* ModifierItemLocalData is used to store information about the results of
 * a search of the set of organisms in a record and the results of user
 * input to a dialog for deciding which modifiers should be used in the
 * organism description.
 */
typedef struct modifieritemlocal {
/*  ButtoN        button; */
  Boolean       any_present;
  Boolean       all_present;
  Boolean       is_unique;
  CharPtr       first_value_seen;
  ValNodePtr    values_seen;
  Boolean       all_unique;
  CharPtr       status;
  Boolean       required;
} ModifierItemLocalData, PNTR ModifierItemLocalPtr;

typedef enum {
  DEFLINE_POS_Acronym = 0,
  DEFLINE_POS_Anamorph,
  DEFLINE_POS_Authority,
  DEFLINE_POS_Bio_material,
  DEFLINE_POS_Biotype,
  DEFLINE_POS_Biovar,
  DEFLINE_POS_Breed,
  DEFLINE_POS_Cell_line,
  DEFLINE_POS_Cell_type,
  DEFLINE_POS_Chemovar,
  DEFLINE_POS_Chromosome,
  DEFLINE_POS_Clone,
  DEFLINE_POS_Clone_lib,
  DEFLINE_POS_Collected_by,
  DEFLINE_POS_Collection_date,
  DEFLINE_POS_Common,
  DEFLINE_POS_Country,
  DEFLINE_POS_Cultivar,
  DEFLINE_POS_Culture_collection,
  DEFLINE_POS_Dev_stage,
  DEFLINE_POS_Ecotype,
  DEFLINE_POS_Endogenous_virus_name,
  DEFLINE_POS_Environmental_sample,
  DEFLINE_POS_Forma,
  DEFLINE_POS_Forma_specialis,
  DEFLINE_POS_Frequency,
  DEFLINE_POS_Genotype,
  DEFLINE_POS_Germline,
  DEFLINE_POS_Group,
  DEFLINE_POS_Haplogroup,
  DEFLINE_POS_Haplotype,
  DEFLINE_POS_Specific_host,
  DEFLINE_POS_Identified_by,
  DEFLINE_POS_Isolate,
  DEFLINE_POS_Isolation_source,
  DEFLINE_POS_Lab_host,
  DEFLINE_POS_Lat_lon,
  DEFLINE_POS_Linkage_group,
  DEFLINE_POS_Map,
  DEFLINE_POS_Mating_type,
  DEFLINE_POS_Metagenomic,
  DEFLINE_POS_Note_orgmod,
  DEFLINE_POS_Note_subsrc,
  DEFLINE_POS_Pathovar,
  DEFLINE_POS_Plasmid_name,
  DEFLINE_POS_Plastid_name,
  DEFLINE_POS_Pop_variant,
  DEFLINE_POS_Rearranged,
  DEFLINE_POS_Segment,
  DEFLINE_POS_Serogroup,
  DEFLINE_POS_Serotype,
  DEFLINE_POS_Serovar,
  DEFLINE_POS_Sex,
  DEFLINE_POS_Specimen_voucher,
  DEFLINE_POS_Strain,
  DEFLINE_POS_Subclone,
  DEFLINE_POS_Subgroup,
  DEFLINE_POS_Sub_species,
  DEFLINE_POS_Substrain,
  DEFLINE_POS_Subtype,
  DEFLINE_POS_Synonym,
  DEFLINE_POS_Teleomorph,
  DEFLINE_POS_Tissue_lib,
  DEFLINE_POS_Tissue_type,
  DEFLINE_POS_Transgenic,
  DEFLINE_POS_Type,
  DEFLINE_POS_Variety
} DefLinePos;

NLM_EXTERN Int4 GetDeflinePosForFieldType (ValNodePtr field);

/* ModifierItemGlobalData is used to store information about the available
 * modifiers - the name to use when displaying a list of checkboxes, whether
 * the modifier is an Organism modifier or a Source modifier, the subtype
 * to use when looking for the modifier in the organism qualifier list,
 * and whether this modifier is required by default.
 */
typedef struct modifieritemglobal {
  CharPtr       name;
  Boolean       isOrgMod;
  Uint1         subtype;
} ModifierItemGlobalData, PNTR ModifierItemGlobalPtr;

extern ModifierItemGlobalData DefLineModifiers[];
NLM_EXTERN size_t NumDefLineModifiers (void);

/* OrganismDescriptionModifiers is used to apply specific user preferences
 * for how to construct the organism descriptions - whether or not to use
 * labels for the modifiers, whether and how to limit the number of modifiers
 * used in any one organism description, whether to keep or remove modifier
 * information in parentheses in the organism taxonomy name, and whether or
 * not to apply modifiers to organisms with "sp." in the middle of the
 * taxonomy name.
 */
typedef struct organismdescriptionmodifiers {
  Boolean  use_labels;
  Int2     max_mods;
  Boolean  keep_paren;
  Boolean  exclude_sp;
  Boolean  exclude_cf;
  Boolean  exclude_aff;
  Boolean  exclude_nr;
  Boolean  include_country_extra;
  Int4     clone_isolate_HIV_rule_num;
  Boolean  use_modifiers;
  Boolean  allow_semicolon_in_modifier;
  Boolean  allow_mod_at_end_of_taxname;
} OrganismDescriptionModifiers, PNTR OrganismDescriptionModifiersPtr;

NLM_EXTERN Boolean ShouldExcludeSp (SeqEntryPtr sep);
NLM_EXTERN void InitOrganismDescriptionModifiers(OrganismDescriptionModifiersPtr odmp, SeqEntryPtr sep);

/* These values are used for the clone_isolate_HIV_rule_num value in OrganismDescriptionModifiers */
typedef enum {
  clone_isolate_HIV_rule_prefer_clone = 1,
  clone_isolate_HIV_rule_prefer_isolate,
  clone_isolate_HIV_rule_want_both
} clone_isolate_HIV_rule_values;
  

typedef struct sourcequaldesc
{
  CharPtr       name;
  Boolean       isOrgMod;
  Uint1         subtype;
  Uint1         subfield;
} SourceQualDescData, PNTR SourceQualDescPtr;

NLM_EXTERN int LIBCALLBACK SortVnpBySourceQualDesc (VoidPtr ptr1, VoidPtr ptr2);

NLM_EXTERN void SetRequiredModifiers (ModifierItemLocalPtr modList);
NLM_EXTERN void CountModifiers (ModifierItemLocalPtr ItemList, SeqEntryPtr sep);
NLM_EXTERN ValNodePtr FindBestModifiersEx(SeqEntryPtr sep, ModifierItemLocalPtr ItemList, Boolean use_new);
NLM_EXTERN ValNodePtr FindBestModifiers(SeqEntryPtr sep, ModifierItemLocalPtr ItemList);
NLM_EXTERN ValNodePtr FindBestModifiersForDeflineClauseList (ValNodePtr defline_clauses, ModifierItemLocalPtr ItemList);

NLM_EXTERN ValNodePtr GetModifierIndicesFromModList (ModifierItemLocalPtr modList);
extern void TestFindBestQualCombo (FILE *fp);


NLM_EXTERN CharPtr MergeValNodeStrings (ValNodePtr list, Boolean useReturn);

NLM_EXTERN ValNodePtr FindExactStringListMatch (ValNodePtr list, CharPtr value);

NLM_EXTERN void BuildDefLineFeatClauseList 
( SeqEntryPtr sep,
  Uint2 entityID,
  DeflineFeatureRequestList PNTR feature_requests,
  Int2 product_flag,
  Boolean alternate_splice_flag,
  Boolean gene_cluster_opp_strand,
  ValNodePtr PNTR list);

NLM_EXTERN Boolean AreFeatureClausesUnique (ValNodePtr list);
NLM_EXTERN void DefLineFeatClauseListFree (ValNodePtr vnp);

NLM_EXTERN void 
BuildDefinitionLinesFromFeatureClauseLists 
(ValNodePtr list,
 ModifierItemLocalPtr modList,
 ValNodePtr modifier_indices,
 OrganismDescriptionModifiersPtr odmp);

NLM_EXTERN void 
BuildDefLinesFromFeatClauseListsForOneBsp 
(ValNodePtr list,
 ModifierItemLocalPtr modList,
 ValNodePtr modifier_indices,
 OrganismDescriptionModifiersPtr odmp,
 BioseqPtr bsp);

NLM_EXTERN void 
AutoDefForSeqEntry 
(SeqEntryPtr sep,
 Uint2 entityID,
 OrganismDescriptionModifiersPtr odmp,
 ModifierItemLocalPtr modList,
 ValNodePtr modifier_indices,
 DeflineFeatureRequestListPtr feature_requests,
 Int2 product_flag,
 Boolean alternate_splice_flag,
 Boolean gene_cluster_opp_strand);

NLM_EXTERN void AddPopsetTitles 
(SeqEntryPtr sep,
 DeflineFeatureRequestListPtr feature_requests,
 Int2 product_flag,
 Boolean alternate_splice_flag,
 Boolean gene_cluster_opp_strand);

NLM_EXTERN void RemovePopsetTitles(SeqEntryPtr sep); 

typedef struct popsetretrostat {
  Int4 feature_clause;
  Int4 common_title;
  Int4 uncalculatable; 
  Boolean title_added;
} PopSetRetroStatData, PNTR PopSetRetroStatPtr;

NLM_EXTERN void PopSetAutoDefRetro (SeqEntryPtr sep, PopSetRetroStatPtr stat);

NLM_EXTERN Boolean IsSpName (CharPtr taxName);

#define DEFAULT_ORGANELLE_CLAUSE 10
NLM_EXTERN BioSourcePtr GetBiopForBsp (BioseqPtr bsp);
NLM_EXTERN Boolean IsLocAInBonSameStrand (SeqLocPtr slp1, SeqLocPtr slp2);
NLM_EXTERN void CleanUpTaxName (CharPtr taxName, Boolean keep_in_paren);
NLM_EXTERN Boolean UseOrgModifier (OrgModPtr mod, CharPtr taxName, Boolean allow_at_end);
NLM_EXTERN void AddModifierLabel 
( Boolean use_labels,
  Boolean is_orgmod,
  Uint1   subtype,
  CharPtr modifier_text);
NLM_EXTERN Boolean LIBCALLBACK IsMobileElement (SeqFeatPtr sfp);
NLM_EXTERN void RemoveNucProtSetTitles (SeqEntryPtr sep);
NLM_EXTERN void RemoveMRnaTitles (SeqEntryPtr sep);
NLM_EXTERN void RemoveProteinTitles (SeqEntryPtr sep);
NLM_EXTERN void SetAutoDefIDModifiers (ModifierItemLocalPtr modList);


NLM_EXTERN ValNodePtr ReadTabTableFromFile (FILE *fp);
NLM_EXTERN ValNodePtr FlipTabTableAxes (ValNodePtr row_list);
NLM_EXTERN ValNodePtr FreeTabTable (ValNodePtr row_list);
NLM_EXTERN ValNodePtr CopyTabTable (ValNodePtr row_list);
NLM_EXTERN void WriteTabTableToFile (ValNodePtr table, FILE *fp);
NLM_EXTERN ValNodePtr CountTabTableBlanks (ValNodePtr row_list);
NLM_EXTERN ValNodePtr ScanTabTableForSpecialCharacters (ValNodePtr row_list);
NLM_EXTERN ValNodePtr AutoReplaceSpecialCharactersInText (CharPtr PNTR text);
NLM_EXTERN void AutoReplaceSpecialCharactersWithMessage (CharPtr PNTR text);
NLM_EXTERN ValNodePtr AutoReplaceSpecialCharactersInTabTable (ValNodePtr row_list);
NLM_EXTERN void AutoFixSpecialCharactersInEntity (Uint2 entityID);

NLM_EXTERN void RemoveQuotesFromTabTable (ValNodePtr row_list);
NLM_EXTERN void ReparseTabTableConvertFirstSpaceToTab (ValNodePtr row_list);
NLM_EXTERN void ReparseTabTableConvertMultiSpaceToTab (ValNodePtr row_list);
NLM_EXTERN void CombineTabTableColumns (ValNodePtr row_list, ValNodePtr column_pos, CharPtr delimiter);
NLM_EXTERN void ReparseTabTableSeparateColumnAtDelimiter (ValNodePtr row_list, Char delimiter, Int4 col, Boolean stop_after_first);
NLM_EXTERN void AddTextToTabTableColumn (ValNodePtr row_list, Int4 col, CharPtr text, Uint2 existing_text);
NLM_EXTERN ValNodePtr ReadOneColumnList (CharPtr line);
NLM_EXTERN ValNodePtr SortTableRowByAnyColumn (ValNodePtr table, Int4 column);

NLM_EXTERN void SpecialCharFindWithContext (CharPtr PNTR strp, Pointer userdata, BoolPtr did_find, BoolPtr did_change);
NLM_EXTERN ValNodePtr FreeContextList (ValNodePtr context_list);

typedef struct twostringhash {
  CharPtr PNTR table;
  Int4 num_lines;
} TwoStringHashData, PNTR TwoStringHashPtr;

NLM_EXTERN TwoStringHashPtr TwoStringHashFree (TwoStringHashPtr tsh);
NLM_EXTERN TwoStringHashPtr MakeTwoStringHashFromTabTable (ValNodePtr line_list, Int4 column1, Int4 column2);
NLM_EXTERN CharPtr GetValueFromTwoStringHash (CharPtr key, TwoStringHashPtr tsh);

NLM_EXTERN Int4 ExtendSeqLocToEnd (SeqLocPtr slp, BioseqPtr bsp, Boolean end5);

/* functions for converting features */
NLM_EXTERN Boolean IsBioseqSetInGPS (BioseqSetPtr bssp);
NLM_EXTERN Boolean IsBioseqInGPS (BioseqPtr bsp);
NLM_EXTERN Boolean IsFeatInGPS (SeqFeatPtr sfp);
NLM_EXTERN void 
ApplyCDSOptionsToFeature
(SeqFeatPtr sfp,
 Boolean remove_mRNA,
 Boolean remove_gene,
 Boolean remove_transcript_id,
 Boolean keep_original);

NLM_EXTERN Boolean 
ConvertCDSToRNA 
(SeqFeatPtr  sfp,
 Uint2       rna_type);

NLM_EXTERN Boolean ConvertGeneToRNA (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertBioSrcToRepeatRegion (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN CharPtr SubSourceText (BioSourcePtr biop, Uint1 subtype, BoolPtr found);
NLM_EXTERN CharPtr OrgModText (BioSourcePtr biop, Uint1 subtype, BoolPtr found);
NLM_EXTERN CharPtr NoteText (BioSourcePtr biop, CharPtr comment);
NLM_EXTERN Boolean ConvertNonPseudoCDSToMiscFeat (SeqFeatPtr sfp, Boolean viral);

NLM_EXTERN CharPtr GetImportFeatureName (Uint2 featdef_key);
NLM_EXTERN RnaRefPtr RnaRefFromLabel (Uint2 featdef_to, CharPtr label, BoolPtr add_label_to_comment);

NLM_EXTERN SeqLocPtr GetProteinLocationForNucleotideFeatureConversion (SeqLocPtr nuc_slp, BoolPtr no_cds);
NLM_EXTERN SeqLocPtr FindNucleotideLocationForProteinFeatureConversion (SeqLocPtr slp);
NLM_EXTERN SeqLocPtr BuildProtLoc (SeqFeatPtr overlapping_cds, SeqLocPtr slp, Int4Ptr frame);
NLM_EXTERN Boolean ConvertImpToProtFunc (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertProtToImpFunc (SeqFeatPtr  sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertRegionToProtFunc (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertRegionToImpFunc (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertImpToImpFunc (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertRegionToRNAFunc (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertGeneToMiscFeatFunc (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertProtToProtFunc (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertMiscFeatToGene (SeqFeatPtr sfp);
NLM_EXTERN Boolean ConvertMiscFeatToCodingRegion (SeqFeatPtr sfp);
NLM_EXTERN void ExtraCDSCreationActions (SeqFeatPtr cds, SeqEntryPtr parent_sep);
NLM_EXTERN SeqFeatPtr GetProtFeature (BioseqPtr protbsp);

NLM_EXTERN void InstantiateMatPeptideProducts (SeqEntryPtr sep);

NLM_EXTERN Boolean CodingRegionHasTranslExcept (SeqFeatPtr sfp);

NLM_EXTERN SeqEntryPtr SequenceStringToSeqEntry (CharPtr str, SeqIdPtr sip, Uint1 mol_type);

NLM_EXTERN void RevCompOneFeatForBioseq (SeqFeatPtr sfp, BioseqPtr bsp);
NLM_EXTERN void RevCompFeats (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent);

NLM_EXTERN ValNodePtr SplitPubListFree (ValNodePtr list);
NLM_EXTERN ValNodePtr MakeSplitPubListFromTabList (ValNodePtr PNTR tab_table, SeqEntryPtr sep, ValNodePtr PNTR err_list);
NLM_EXTERN void SplitPubsByList (ValNodePtr split_list);
/* for parsing collection dates */
NLM_EXTERN CharPtr ReformatDateStringEx (CharPtr orig_date, Boolean month_first, BoolPtr month_ambiguous);
NLM_EXTERN CharPtr ReformatDateWithMonthNames (CharPtr orig_date);
NLM_EXTERN Int4 GetYearFromToken (CharPtr token, Int4 token_len);
NLM_EXTERN Int4 ReadNumberFromToken (CharPtr token, Int4 token_len);
NLM_EXTERN CharPtr GetMonthFromToken (CharPtr token, Int4 token_len);
NLM_EXTERN Int4 GetMonthNumFromAbbrev (CharPtr month_abbrev);
NLM_EXTERN CharPtr GetMonthAbbrev (Int4 n);
NLM_EXTERN Int4 GetDaysInMonth (Int4 n);

NLM_EXTERN void CreateStructuredCommentsForAllFromTable (SeqEntryPtr sep, ValNodePtr header, ValNodePtr line, ValNodePtr PNTR err_list);
NLM_EXTERN ValNodePtr CreateStructuredCommentsFromFile (FILE *fp, SeqEntryPtr sep, Boolean apply_to_all);
NLM_EXTERN void AddDatabaseNameToStructuredComment (UserObjectPtr uop, CharPtr dbname);
NLM_EXTERN ValNodePtr CreateStructuredCommentTableFromSeqEntry (SeqEntryPtr sep);

#define ALNMGR_GAP           -2
#define ALNMGR_ROW_UNDEFINED -1

NLM_EXTERN void 
AlignmentIntervalToString 
(SeqAlignPtr salp,
 Int4        row,
 Int4        start,
 Int4        stop,
 Int4        target_row,
 Boolean     view_whole_entity,
 Uint1Ptr    seqbuf,
 Uint1Ptr    alnbuf,
 Int4 PNTR   alnbuffer_len,
 Boolean     show_substitutions);

/* Compare Functions */
NLM_EXTERN int LIBCALL ObjectIdCompare (ObjectIdPtr a, ObjectIdPtr b);
NLM_EXTERN int LIBCALL DbtagCompare (DbtagPtr a, DbtagPtr b);
NLM_EXTERN int LIBCALL OrgModSetCompare (OrgModPtr mod1, OrgModPtr mod2);
NLM_EXTERN int LIBCALL OrgNameCompare (OrgNamePtr onp1, OrgNamePtr onp2);
NLM_EXTERN int LIBCALL OrgRefCompare (OrgRefPtr orp1, OrgRefPtr orp2);

extern void CountNsInSequence (BioseqPtr bsp, Int4Ptr p_total, Int4Ptr p_max_stretch, Boolean expand_gaps);
NLM_EXTERN Boolean IsTSA (BioseqPtr bsp);

NLM_EXTERN Boolean IsPseudo (SeqFeatPtr sfp);

NLM_EXTERN Boolean ExtendPartialsToEndOrGap (SeqFeatPtr sfp);
NLM_EXTERN Boolean RetranslateOneCDS 
( SeqFeatPtr sfp,
  Uint2 entityID,
  Boolean include_stop,
  Boolean no_stop_at_end_of_complete_cds);
NLM_EXTERN SeqFeatPtr FindBestProtein (Uint2 entityID, SeqLocPtr product);
NLM_EXTERN void AddNonExtendableException (SeqFeatPtr sfp);
NLM_EXTERN SeqLocPtr GetmRNALocationFromCDSLocation (SeqLocPtr slp, Uint2 entityID);
NLM_EXTERN void AddmRNAForCDS (SeqFeatPtr sfp);
NLM_EXTERN Boolean ProductsMatchForRefSeq (CharPtr cds_str, CharPtr mrna_str);
NLM_EXTERN SeqSubmitPtr FindSeqSubmitForSeqEntry (SeqEntryPtr sep);
NLM_EXTERN Boolean CreateMatPeptideFromCDS (SeqFeatPtr sfp);
NLM_EXTERN Boolean ConvertCDSToMatPeptideForOverlappingCDS (SeqFeatPtr sfp, SeqFeatPtr top_cds, Boolean remove_original);
NLM_EXTERN Boolean AutoConvertCDSToMiscFeat (SeqFeatPtr cds, Boolean remove_original);

NLM_EXTERN AuthListPtr PNTR GetAuthListForPub (PubPtr the_pub);
NLM_EXTERN void RemoveConsortiumFromPub (PubPtr pub);

NLM_EXTERN Int4 Extend5PartialSeqIntToEndOrGap (SeqIntPtr sint, BioseqPtr bsp, Boolean short_only);
NLM_EXTERN Int4 Extend3PartialSeqIntToEndOrGap (SeqIntPtr sint, BioseqPtr bsp, Boolean short_only);
NLM_EXTERN Int4 ExtendSeqLocToEndOrGap (SeqLocPtr slp, BioseqPtr bsp, Boolean end5);
NLM_EXTERN FloatLo PercentNInBioseq (BioseqPtr bsp, Boolean include_gaps);

NLM_EXTERN SeqEntryPtr GetBestSeqEntryForItem (ValNodePtr vnp);
NLM_EXTERN void AddNewUniqueDescriptors (SeqDescrPtr PNTR new_set, SeqDescrPtr parent_set);
NLM_EXTERN void AddNewUniqueAnnotations (SeqAnnotPtr PNTR new_set, SeqAnnotPtr parent_set);
NLM_EXTERN BioseqSetPtr MakeGroupsForUniqueValues (BioseqSetPtr bssp, ValNodePtr value_lists);
NLM_EXTERN ValNodePtr PrepareSequenceListForSegregateByNumberOfSets (Int4 num_sets, SeqEntryPtr sep);
NLM_EXTERN void SegregateSetsByNumber (SeqEntryPtr sep, Int4 num_sets);
NLM_EXTERN ValNodePtr PrepareSequenceListForSegregateByNumberPerSet (Int4 num_per_set, SeqEntryPtr sep);
NLM_EXTERN void SegregateSetsByNumberPerSet (SeqEntryPtr sep, Int4 num_per_set);

NLM_EXTERN void MoveSequencesFromSetToWrapper (ValNodePtr list, Uint2 entityID);

NLM_EXTERN ValNodePtr CreateStructuredCommentsFromRow (ValNodePtr header, ValNodePtr values, CharPtr id_str, ValNodePtr PNTR err_list);

NLM_EXTERN void MergeAdjacentAnnotsInList (SeqAnnotPtr sap);

NLM_EXTERN Boolean GetsDocsumTitle(Uint1 set_class);
NLM_EXTERN void PromoteCommonTitlesToSet (SeqEntryPtr sep);

NLM_EXTERN void SetDescriptorPropagate (BioseqSetPtr bssp);
NLM_EXTERN Boolean RemoveDuplicateNestedSetsForEntityID (Uint2 entityID);

NLM_EXTERN void AddStructuredCommentKeywords (Uint2 entityID);
NLM_EXTERN CharPtr KeywordForStructuredCommentName (UserObjectPtr uop);
NLM_EXTERN Boolean HasKeywordForStructuredCommentName (BioseqPtr bsp, UserObjectPtr uop);
NLM_EXTERN void RemoveStructuredCommentKeywords (Uint2 entityID);

NLM_EXTERN void ParseTaxNameToQuals (OrgRefPtr org, TextFsaPtr tags);

NLM_EXTERN ValNodePtr GetLocusTagPrefixList (SeqEntryPtr sep);

NLM_EXTERN Boolean IsProductNameOk (CharPtr product_name);
NLM_EXTERN Boolean ReportProductNameProblems (CharPtr product_name, FILE *output_file, CharPtr prefix);

NLM_EXTERN SeqEntryPtr ReadFilteredAsn (FILE *fp, Boolean is_binary, CharPtr accn_list, Uint2Ptr entityIDptr);
NLM_EXTERN void ReintegrateFilteredAsn (SeqEntryPtr sep, FILE *orig_file, FILE *output, Boolean is_binary);

typedef struct descstream {
  SeqDescPtr orig;
  SeqDescPtr replace;
  SeqIdPtr   owners;
  SeqIdPtr   last_owner;
  Boolean    on_all;
  CharPtr    text;
  Int4       num_dependent;
} DescStreamData, PNTR DescStreamPtr;

NLM_EXTERN DescStreamPtr DescStreamNew (SeqDescPtr sdp, BioseqPtr parent);
NLM_EXTERN DescStreamPtr DescStreamFree (DescStreamPtr ds);
NLM_EXTERN ValNodePtr DescStreamListFree (ValNodePtr vnp);

NLM_EXTERN ValNodePtr StreamAsnForDescriptors (FILE *fp, Boolean is_binary, Boolean is_batch, Boolean is_submit, SeqIdPtr PNTR sip_list);
NLM_EXTERN void WriteAsnWithReplacedDescriptors (ValNodePtr desc_stream_list, FILE *orig_file, FILE *output, Boolean is_binary, Boolean is_batch, Boolean is_submit);
NLM_EXTERN Boolean IdListsMatch (SeqIdPtr sip_list, ValNodePtr all_sip);
NLM_EXTERN void SetOnAllValsForDescStreamList (ValNodePtr desc_list, ValNodePtr all_sip);

extern Boolean ParseCodeBreak (SeqFeatPtr sfp, CharPtr val, Int4 offset);

NLM_EXTERN void CleanupOneSeqFeat (SeqFeatPtr sfp);

NLM_EXTERN Uint1 GetSpecialPlastidGenCode (
  CharPtr taxname,
  CharPtr lineage
);


NLM_EXTERN Boolean TrimPrimerSeqJunkInSeqEntry (SeqEntryPtr sep, FILE *log_fp);
NLM_EXTERN Boolean FixUsaAndStateAbbreviations (Uint2 entityID, FILE *log_fp);
NLM_EXTERN Boolean TrimStopsFromCompleteCodingRegions (SeqEntryPtr sep, FILE *log_fp);
NLM_EXTERN void AdjustSeqEntryForConsensusSplice (SeqEntryPtr sep);
NLM_EXTERN Boolean AdjustSeqEntryForConsensusSpliceEx (SeqEntryPtr sep, FILE *log_fp);

NLM_EXTERN void 
FixCapitalizationInTitle 
(CharPtr PNTR pTitle,
 Boolean      first_is_upper,
 ValNodePtr   org_names);

NLM_EXTERN Int4 ConvertCommentsWithSpacesToStructuredCommentsForSeqEntry (SeqEntryPtr sep);

NLM_EXTERN void ParseExtractorResultsTableToFeatures (FILE *fp, SeqEntryPtr sep);

#ifdef OS_MSWIN
NLM_EXTERN Int4 RunSilent(const char *cmdline);
#endif


NLM_EXTERN CharPtr ValNodeSeqIdName (ValNodePtr vnp);
NLM_EXTERN void ValNodeSeqIdFree (ValNodePtr vnp);
NLM_EXTERN ValNodePtr ValNodeSeqIdCopy (ValNodePtr vnp);
NLM_EXTERN Boolean ValNodeSeqIdMatch (ValNodePtr vnp1, ValNodePtr vnp2);
NLM_EXTERN ValNodePtr ValNodeSeqIdListFree (ValNodePtr list);
NLM_EXTERN ValNodePtr ValNodeSeqIdListCopy (ValNodePtr list);
NLM_EXTERN ValNodePtr SeqIdListToValNodeSeqIdList (SeqIdPtr sip_list);
NLM_EXTERN SeqIdPtr ValNodeSeqIdListToSeqIdList (ValNodePtr vnp_list);

NLM_EXTERN void StringToLower (CharPtr str);

NLM_EXTERN ValNodePtr FixupCountryQuals (SeqEntryPtr sep, Boolean fix_after_colon);
NLM_EXTERN Boolean FixupCountryQualsWithLog (SeqEntryPtr sep, Boolean fix_after_colon, FILE *log_fp);
NLM_EXTERN Boolean FixupMouseStrains (SeqEntryPtr sep, FILE *log_fp);

NLM_EXTERN CharPtr StructuredCommentDbnameFromString (CharPtr string);
NLM_EXTERN ValNodePtr GetStructuredCommentPrefixList (void);
extern ValNodePtr GetSourceQualDescListEx (Boolean get_subsrc, Boolean get_orgmod, Boolean get_discouraged, Boolean get_discontinued, Boolean get_subfields);

NLM_EXTERN Boolean RemoveCultureNotes (SeqEntryPtr sep);

NLM_EXTERN AuthListPtr GetAuthorListForPub (PubPtr the_pub);

NLM_EXTERN void FixProductWordCapitalization (CharPtr PNTR pProduct);
NLM_EXTERN Boolean FixSrcQualCaps (SeqEntryPtr sep, Int4 src_qual, FILE *log_fp);
NLM_EXTERN Boolean IsNCBIFileID (SeqIdPtr sip);

NLM_EXTERN Boolean IsLocationOrganelle (Uint1 genome);

NLM_EXTERN void RemoveFeatureLink (SeqFeatPtr sfp1, SeqFeatPtr sfp2);
NLM_EXTERN void LinkTwoFeatures (SeqFeatPtr dst, SeqFeatPtr sfp);
NLM_EXTERN void MakeFeatureXrefsFromProteinIdQuals (SeqEntryPtr sep);
NLM_EXTERN void MakeFeatureXrefsFromTranscriptIdQuals (SeqEntryPtr sep);
NLM_EXTERN void FinishHalfXrefs (SeqEntryPtr sep);
NLM_EXTERN void FlipCodonRecognizedInSeqEntry (SeqEntryPtr sep, LogInfoPtr lip);
NLM_EXTERN void RemoveBadCodonRecognizedInSeqEntry (SeqEntryPtr sep, LogInfoPtr lip);
NLM_EXTERN Uint1 GetAaFromtRNA (tRNAPtr trp);
NLM_EXTERN CharPtr GetCodesFortRNA (SeqFeatPtr sfp, Int2 *pCode);


#ifdef __cplusplus
}
#endif

#undef NLM_EXTERN
#ifdef NLM_EXPORT
#define NLM_EXTERN NLM_EXPORT
#else
#define NLM_EXTERN
#endif

#endif /* ndef _SQNUTILS_ */