~ubuntu-branches/ubuntu/saucy/ncbi-tools6/saucy-proposed

« back to all changes in this revision

Viewing changes to tools/suggest.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2009-08-11 22:03:47 UTC
  • mfrom: (1.4.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090811220347-g4b6lzdvphvvbpiu
* New upstream release.
* debian/libncbi6.symbols: update accordingly.
* debian/control: clean up obsolete or redundant relationship declarations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
static char const rcsid[] = "$Id: suggest.c,v 6.12 2007/03/20 18:27:14 bollin Exp $";
 
1
static char const rcsid[] = "$Id: suggest.c,v 6.14 2009/04/10 17:22:14 kans Exp $";
2
2
 
3
3
/*   suggest.c
4
4
* ===========================================================================
31
31
*
32
32
* Version Creation Date:   3/17/94
33
33
*
34
 
* $Revision: 6.12 $
 
34
* $Revision: 6.14 $
35
35
*
36
36
* File Description: 
37
37
*
40
40
* Date     Name        Description of modification
41
41
* -------  ----------  -----------------------------------------------------
42
42
*
43
 
*
44
 
* ==========================================================================
45
 
*/
46
 
 
47
 
/*
48
 
* =======================================================
49
 
* File Name: suggest.c
50
 
*
51
43
* Author: This is actually a good question!
52
44
*     The initial version (called exons.c) was coded by Webb Miller.
53
45
*     Warren Gish then incorporated it into the Markup screen package.
66
58
*     intermediate solutions in a way that the indexers can
67
59
*     use to deal more effectively with strange papers.
68
60
*     
69
 
*     A detailed change log follows:
70
 
*     $Log: suggest.c,v $
71
 
*     Revision 6.12  2007/03/20 18:27:14  bollin
72
 
*     Added sequence ID reporting to Suggest_Intervals messages.
73
 
*
74
 
*     Revision 6.11  2003/05/30 17:25:38  coulouri
75
 
*     add rcsid
76
 
*
77
 
*     Revision 6.10  2003/05/13 16:02:54  coulouri
78
 
*     make ErrPostEx(SEV_FATAL, ...) exit with nonzero status
79
 
*
80
 
*     Revision 6.9  2002/02/06 21:10:38  kans
81
 
*     PlusStrand and MinusStrand prefixed with Suggest to avoid collision with asn2graphic viewer symbols
82
 
*
83
 
*     Revision 6.8  2001/05/25 19:43:53  vakatov
84
 
*     Nested comment typo fixed
85
 
*
86
 
*     Revision 6.7  1998/06/17 21:55:47  kans
87
 
*     fixed 64-bit SGI compiler warnings
88
 
*
89
 
*     Revision 6.6  1998/06/12 20:42:18  kans
90
 
*     fixed most unix compiler warnings
91
 
*
92
 
*     Revision 6.5  1997/12/02 17:43:52  kans
93
 
*     added cast to sprintf, explicit int return values
94
 
*
95
 
*     Revision 6.4  1997/08/27 18:26:19  kans
96
 
*     temporarily convert * to X to avoid bad triptab index
97
 
*
98
 
*     Revision 6.3  1997/08/27 14:50:23  kans
99
 
*     added second protection against table overflow
100
 
*
101
 
*     Revision 6.2  1997/08/26 23:56:02  kans
102
 
*     added protection to bld_table based on purify array bounds violations
103
 
*
104
 
*     Revision 6.1  1997/08/26 19:37:36  kans
105
 
*     added batch functions to process nucleotide once for many proteins
106
 
*
107
 
*     Revision 6.0  1997/08/25 18:54:58  madden
108
 
*     Revision changed to 6.0
109
 
*
110
 
*     Revision 5.4  1997/08/21 20:28:44  kans
111
 
*     fixed correction for alt start codon (Karl)
112
 
*
113
 
*     Revision 5.3  1996/10/16 15:09:05  kans
114
 
*     finished cleaning up linked lists headed by triptab arrays
115
 
*
116
 
 * Revision 5.2  1996/10/15  22:39:24  kans
117
 
 * cleaned up most memory leaks detected by purify (one big one remains)
118
 
 *
119
 
 * Revision 5.1  1996/09/27  19:05:18  kans
120
 
 * adjusts first interval if first protein residue isn't included, under
121
 
 * the assumption that it's using an alternative start codon
122
 
 *
123
 
 * Revision 5.0  1996/05/28  13:43:15  ostell
124
 
 * Set to revision 5.0
125
 
 *
126
 
 * Revision 1.5  1996/03/27  19:40:25  vakatov
127
 
 * Some unused stuff has been eliminated
128
 
 *
129
 
 * Revision 1.4  1996/03/25  22:13:06  vakatov
130
 
 * One more  free() -> MemFree()  correction...
131
 
 *
132
 
 * Revision 1.3  1996/03/25  21:43:06  vakatov
133
 
 * The "reverse" function slightly changed to avoid pointing to the outside
134
 
 * of array "r[]" lower limit (to please the Win-16 segmentation quirks)
135
 
 *
136
 
 * Revision 1.2  1996/03/13  21:07:40  epstein
137
 
 * change printfs to ErrPostEx()
138
 
 *
139
 
 * Revision 1.1  1995/11/28  22:19:10  kans
140
 
 * Initial revision
141
 
 *
142
 
 * Revision 1.4  1995/09/22  21:46:16  kans
143
 
 * split big array into 26 small arrays, other cleanups
144
 
 *
145
 
 * Revision 1.3  1995/08/29  16:29:51  epstein
146
 
 * eliminate troublesome header
147
 
 *
148
 
 * Revision 1.2  1995/08/18  19:52:32  epstein
149
 
 * *** empty log message ***
150
 
 *
151
 
 * Revision 1.1  1995/08/14  18:24:21  epstein
152
 
 * Initial revision
153
 
 *
154
 
 * Revision 1.8  1995/07/07  14:44:05  kans
155
 
 * updated genetic codes
156
 
 *
157
 
 * Revision 1.7  1994/07/26  18:04:55  kans
158
 
 * *** empty log message ***
159
 
 *
160
 
 * Revision 1.6  1994/07/01  14:38:22  kans
161
 
 * *** empty log message ***
162
 
 *
163
 
 * Revision 1.5  1994/06/30  22:36:54  kans
164
 
 * *** empty log message ***
165
 
 *
166
 
 * Revision 1.4  1994/06/24  23:03:46  kans
167
 
 * *** empty log message ***
168
 
 *
169
 
 * Revision 1.3  1994/05/12  18:21:31  kans
170
 
 * *** empty log message ***
171
 
 *
172
 
 * Revision 1.2  1994/04/08  16:24:37  kans
173
 
 * *** empty log message ***
174
 
 *
175
 
 * Revision 1.1  1994/03/17  16:33:30  kans
176
 
 * Initial revision
177
 
 *
178
 
 * Revision 2.90  92/07/22  10:46:21  sirotkin
179
 
 * forgot to put in earlier
180
 
 * 
181
 
 * Revision 2.86  92/04/16  15:37:39  sirotkin
182
 
 * looks for stops activated
183
 
 * 
184
 
 * Revision 2.85  92/02/26  14:57:25  sirotkin
185
 
 * fixed desending checks in Int_INt2Ext
186
 
 * 
187
 
 * Revision 2.83  92/01/13  10:42:47  sirotkin
188
 
 * lonum guarenteed to be <= hunum
189
 
 * 
190
 
 * Revision 2.82  91/11/26  17:22:43  sirotkin
191
 
 * passed saber, adds terminal stop, conditionally
192
 
 * 
193
 
 * Revision 2.81  91/11/18  16:00:34  sirotkin
194
 
 * Fixed problem pub 34736 which caused dramtic sugest failure
195
 
 * 
196
 
 * Revision 2.3  91/10/22  13:14:10  sirotkin
197
 
 * Now picks up and rewrites minimum exon and range to explore
198
 
 * 
199
 
 * Revision 2.2  91/10/11  09:50:00  sirotkin
200
 
 * *** empty log message ***
201
 
 * 
202
 
 * Revision 2.1  91/10/11  09:48:30  sirotkin
203
 
 * getting ready for range limitation
204
 
 * 
205
 
 * Revision 2.0  91/04/25  17:21:02  sirotkin
206
 
 * To set revision of procution version
207
 
 * 
208
 
 * Revision 1.104  91/03/26  15:46:13  sirotkin
209
 
 * fixed Dramatic failure test to use pro_len and not dna_len
210
 
 * 
211
 
 * Revision 1.103  91/03/21  10:36:06  sirotkin
212
 
 * changed field string expected on form from
213
 
 * exception to genetic_code
214
 
 * 
215
 
 * Revision 1.102  91/03/01  10:49:02  sirotkin
216
 
 * ready to install
217
 
 * 
218
 
 * Revision 1.101  91/02/19  09:05:00  sirotkin
219
 
 * Shoulod be ready for next install
220
 
 * 
221
 
 * Revision 1.100  91/02/15  09:07:13  sirotkin
222
 
 * after bug fixes in redundant with mismatches
223
 
 * 
224
 
 * Revision 1.99  91/02/14  16:25:15  sirotkin
225
 
 * removes redunant intervals, coaleses multiple mismatches
226
 
 * removes during consisten set insure one at a time
227
 
 * more stringent during weirdness pass 1
228
 
 * if unkonw genetic code, uses standard
229
 
 * 
230
 
 * Revision 1.91  91/01/30  14:10:25  sirotkin
231
 
 * This version works with ambigous bases.  When an
232
 
 * ambiguous base still allows knowledge of amino acid, that
233
 
 * amino acid is used.  Matches ambiguous DNA with unknown amino
234
 
 * acids.  Suggests last 2 bases of incomplete codon when will
235
 
 * code for correct amino acid.
236
 
 * 
237
 
 * Revision 1.90  91/01/22  16:23:27  sirotkin
238
 
 * markup rev 1.90 mini-load for 23 jan 1991
239
 
 * 
240
 
 * Revision 1.26  91/01/18  16:05:03  sirotkin
241
 
 * changed MAX_DNA to 1000000 from (3*32*1024)
242
 
 * 
243
 
 * Revision 1.25  91/01/16  17:28:31  sirotkin
244
 
 * added checks to genetic code
245
 
 * 
246
 
 * Revision 1.27  91/01/10  15:13:30  sirotkin
247
 
 * back to variable length only
248
 
 * 
249
 
 * Revision 1.25  90/12/28  15:43:54  sirotkin
250
 
 * This version has the variable minimum exon length installed
251
 
 * 
252
 
 * Revision 1.24  90/12/28  09:03:06  sirotkin
253
 
 * Before making TooShort a variable which is set depending upon
254
 
 * the aa length and the combined dna_length
255
 
 * 
256
 
 * Revision 1.23  90/12/21  16:48:41  sirotkin
257
 
 * change to keep compiler happy
258
 
 * 
259
 
 * Revision 1.23  90/12/21  15:28:27  sirotkin
260
 
 * tweaks for compiler
261
 
 * 
262
 
 * Revision 1.22  90/12/20  16:47:43  sirotkin
263
 
 * minor cosmetic stuff
264
 
 * 
265
 
 * Revision 1.22  90/12/19  15:12:27  sirotkin
266
 
 * ready to install
267
 
 * 
268
 
 * Revision 1.21  90/11/26  15:02:12  sirotkin
269
 
 * with changes to interval group and writing frame to form
270
 
 * 
271
 
 * Revision 1.20  90/11/24  16:04:06  sirotkin
272
 
 * frame moved from intervals to form
273
 
 * 
274
 
 * Revision 1.19  90/11/23  12:20:37  sirotkin
275
 
 * before moving frame from intervals to form
276
 
 * 
277
 
 * Revision 1.18  90/11/02  15:34:18  sirotkin
278
 
 * commented out DEBUG
279
 
 * 
280
 
 * Revision 1.17  90/10/31  13:54:11  sirotkin
281
 
 * Segmented sequences now work.
282
 
 * 
283
 
 * Revision 1.14  90/10/22  15:06:38  sirotkin
284
 
 * Now reports revision number in the testname field
285
 
 * 
286
 
 * Revision 1.12  90/10/04  18:00:21  sirotkin
287
 
 * Unexpectedly, this version worked for id_seq 9121, the
288
 
 * last three intervals (shorter gene)
289
 
 * 
290
 
 * Revision 1.11  90/10/02  15:30:30  sirotkin
291
 
 * Only one change, but important enough for a separate version:
292
 
 * changed the constant TooShort from 6 to 4, allowing 5 codon
293
 
 * segments.
294
 
 * 
295
 
 * Revision 1.10  90/09/24  14:41:58  sirotkin
296
 
 * logic of selecting best set, fixing overlaps
297
 
 * by looking at likely splice sites and tehn
298
 
 * insuring consistent set by deleting, fi necessary,
299
 
 * all seems to work in this version
300
 
 * 
301
 
* only important changes left in below
302
 
revision 1.6        
303
 
date: 90/09/19 11:48:09;  author: sirotkin;  state: Exp;  lines added/del: 450/40
304
 
partially retro-fitted function headers
305
 
----------------------------
306
 
revision 1.1        
307
 
date: 90/09/07 09:18:17;  author: sirotkin;  state: Exp;  
308
 
Initial revision
309
 
=============================================================================
310
 
 * 
311
61
==========================================
312
62
* exons.c - map an amino acid sequence to a DNA coding region
313
63
*
415
165
to complement the sequence, if the minus strand was given
416
166
for any particular segment
417
167
 
 
168
=============================================================================
418
169
*/
419
170
 
420
171
/* with the cursor on this line, the following
487
238
static Int4 min_exon_from_form;
488
239
static DBTINYINT last_orient;
489
240
 
 
241
/*
490
242
static char     *module = "APT_suggest";
 
243
#define fatal(m)        {ErrPostEx(SEV_FATAL, 1, 0, "%s:  %s", module, m); goto Error;}
 
244
*/
 
245
 
491
246
static DBSMALLINT       exception;
492
247
static Int4 * nt_id_seq = NULL;
493
248
#ifdef DEBUG_TOO_SHORT  
501
256
 
502
257
Int4 Total_len;
503
258
 
504
 
#define fatal(m)        {ErrPostEx(SEV_FATAL, 1, 0, "%s:  %s", module, m); goto Error;}
505
 
 
506
 
static char * suggest_revision = "$Revision: 6.12 $";
507
259
 
508
260
static Int4     suggest_get_frames_init = 1;
509
261
 
1237
989
static Int4 APT_suggest(SuggestOutputPtr pSuggestOut, Int4 num_nuc)
1238
990
{
1239
991
        Int4            i;
1240
 
        Int4 suggest_revision_len = strlen(suggest_revision);
1241
992
        Int4 nt;
1242
 
        DBTINYINT frame_1 =1;
 
993
    Int4 rsult = 0;
1243
994
        char nt_msg[512];
1244
995
        double combined_length;
1245
996
 
1416
1167
                goto Error;
1417
1168
 
1418
1169
        if ( Total_len < pro_len * .1) {
 
1170
        rsult = 1;
 
1171
#ifdef DEBUG_TOO_SHORT  
1419
1172
                ErrPostEx(SEV_ERROR, 0, 0, "Dramatic Suggest failure: Please check reverse\n on both aa and DNA sequences.\nPlease check that the proper sequences selected.\n");
1420
1173
                if (min_exon_from_form > -1 || Min_val > 0 || Max_val < dna_len){
1421
1174
                        ErrPostEx(SEV_ERROR, 0, 0, "Since Parameters were set, also check them on the verify form.\n");
1422
1175
                }
 
1176
#endif
1423
1177
        }
1424
1178
 
1425
1179
        if (Min_val <=0)
1437
1191
#ifdef CdCycle
1438
1192
ErrPostEx(SEV_INFO, 0, 0, "Ending Suggest");
1439
1193
#endif
1440
 
        return 0;
 
1194
        return rsult;
1441
1195
Error:
1442
1196
        cleanup();
1443
1197
#ifdef CdCycle
1596
1350
*
1597
1351
*****************************************************************************/
1598
1352
 
1599
 
static void Suggest_Intervals (SuggestRecPtr sugrp,
1600
 
                               SuggestOutputPtr pSuggestOut, Int4 num_nuc)
 
1353
static Int2 Suggest_Intervals (SuggestRecPtr sugrp, SuggestOutputPtr pSuggestOut, Int4 num_nuc)
1601
1354
{
1602
1355
  Boolean    goOn;
1603
1356
  Int4       i;
1607
1360
  SeqRecPtr  nucleotide;
1608
1361
  SeqRecPtr  protein;
1609
1362
  Int4       tripdex;
 
1363
  Int2       rsult = 0;
1610
1364
  struct trip_node      *h, *oh;
1611
1365
 
1612
1366
  if (sugrp != NULL) {
1616
1370
    geneticCode = sugrp->geneticCode;
1617
1371
    if (nucleotide != NULL && protein != NULL && geneticCode != NULL) {
1618
1372
      if ((nucleotide->length +1) / 3 < protein->length) {
 
1373
#ifdef DEBUG_TOO_SHORT  
1619
1374
        ReportSuggestIntervalsError (nucleotide, "Nucleotide is too short to encode protein");
 
1375
#endif
 
1376
        rsult = 2;
1620
1377
        goOn = FALSE;
1621
1378
      }
1622
1379
      if (nucleotide->length < 18) {
 
1380
#ifdef DEBUG_TOO_SHORT  
1623
1381
        ReportSuggestIntervalsError (nucleotide, "Nucleotide length is too short");
 
1382
#endif
 
1383
        rsult = 3;
1624
1384
        goOn = FALSE;
1625
1385
      }
1626
1386
      if (protein->length < 6) {
 
1387
#ifdef DEBUG_TOO_SHORT  
1627
1388
        ReportSuggestIntervalsError (protein, "Protein length is too short");
 
1389
#endif
 
1390
        rsult = 4;
1628
1391
        goOn = FALSE;
1629
1392
      }
1630
1393
 
1686
1449
          nt_id_seq[nt] = nt;
1687
1450
        }
1688
1451
 
1689
 
        APT_suggest (pSuggestOut, num_nuc);
 
1452
        if (APT_suggest (pSuggestOut, num_nuc) != 0) {
 
1453
          rsult = 1;
 
1454
        }
1690
1455
 
1691
1456
        m_stk = MemFree (m_stk);
1692
1457
 
1717
1482
 
1718
1483
    }
1719
1484
  }
 
1485
  return rsult;
1720
1486
}
1721
1487
 
1722
1488
/* default code (code 0) means use the standard code (code 1) */
1747
1513
*
1748
1514
*****************************************************************************/
1749
1515
 
1750
 
Int4 Get_Genetic_Code (Int4 code, SuggestRecPtr sugrp)
 
1516
extern Int4 Get_Genetic_Code (Int4 code, SuggestRecPtr sugrp)
1751
1517
 
1752
1518
{
1753
1519
  GeneticCodePtr  codes;
1815
1581
 *      FALSE otherwise
1816
1582
 *
1817
1583
\*----------------------------------------------------------------------------*/
1818
 
Boolean
1819
 
InitSuggest(void)
 
1584
extern Boolean InitSuggest (void)
1820
1585
{
1821
1586
    if (!AllObjLoad ()) {
1822
1587
        Message (MSG_FATAL, "AllObjLoad failed");
1866
1631
 *      FALSE   - otherwise;
1867
1632
 *
1868
1633
\*----------------------------------------------------------------------------*/
1869
 
Boolean
1870
 
ProcessData(SuggestOutputPtr pSuggestOut, Boolean clearNucSeqRec)
 
1634
 
 
1635
Int2 ProcessData (SuggestOutputPtr pSuggestOut, Boolean clearNucSeqRec)
1871
1636
{
1872
1637
    Int4        num_nuc;
1873
1638
    Int4        num_prt;
1874
1639
    Int4        len;
1875
1640
    Int4        i;
 
1641
    Int2    rsult = 0;
1876
1642
    
1877
1643
    suggestRec.protein.sequence = MemFree(suggestRec.protein.sequence);
1878
1644
    suggestRec.protein.length = 0;
1882
1648
    BSSeek(suggestRec.protein.rawSeq, 0L, 0);
1883
1649
    
1884
1650
    for (i = 0; i < num_prt; i++) {
1885
 
        OutProteinID(pSuggestOut, i);
 
1651
        OutProteinID (pSuggestOut, i);
1886
1652
        BSRead(suggestRec.protein.segLens, &len, sizeof(len));
1887
1653
        suggestRec.protein.sequence = MemNew((len + 1) * sizeof(Uint1));
1888
1654
        len = BSRead(suggestRec.protein.rawSeq,
1889
1655
                     suggestRec.protein.sequence, len);
1890
1656
        suggestRec.protein.length = len;
1891
 
        Suggest_Intervals(&suggestRec, pSuggestOut, num_nuc);
 
1657
        rsult = Suggest_Intervals(&suggestRec, pSuggestOut, num_nuc);
1892
1658
        suggestRec.minVal = 0L;
1893
1659
        suggestRec.maxVal = 0L;
1894
1660
        suggestRec.tooShort = 0L;
1904
1670
    suggestRec.geneticCode = (CharPtr)MemFree(suggestRec.geneticCode);
1905
1671
    genetic_code = NULL;
1906
1672
 
1907
 
    return TRUE;
 
1673
    return rsult;
1908
1674
}
1909
1675
 
1910
1676