File: sw_wrap.c

package info (click to toggle)
wise 2.4.1-28
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 39,348 kB
  • sloc: ansic: 276,376; makefile: 1,021; perl: 886; lex: 93; yacc: 81; sh: 25
file content (544 lines) | stat: -rw-r--r-- 16,596 bytes parent folder | download | duplicates (2)
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
#ifdef _cplusplus
extern "C" {
#endif
#include "sw_wrap.h"

/* Function:  Align_strings_ProteinSmithWaterman(one,two,comp,gap,ext,dpenv,dpri)
 *
 * Descrip:    This is the most *stupidly* abstracted view of two sequences
 *             getting aligned, being two strings.
 *
 *             It would be much better if you used Sequence objects or Protein
 *             objects to carry the proteins.
 *
 *
 * Arg:          one [UNKN ] string of the first sequence [char *]
 * Arg:          two [UNKN ] string of the second sequence [char *]
 * Arg:         comp [UNKN ] Comparison Matrix [CompMat *]
 * Arg:          gap [UNKN ] gap penalty [int]
 * Arg:          ext [UNKN ] extension penalty [int]
 * Arg:        dpenv [UNKN ] Undocumented argument [DPEnvelope *]
 * Arg:         dpri [UNKN ] Undocumented argument [DPRunImpl *]
 *
 * Return [UNKN ]  Undocumented return value [AlnBlock *]
 *
 */
# line 37 "sw_wrap.dy"
AlnBlock * Align_strings_ProteinSmithWaterman(char * one,char * two,CompMat * comp,int gap,int ext,DPEnvelope * dpenv,DPRunImpl * dpri)
{
  Sequence * one_s;
  Sequence * two_s;
  AlnBlock * out;

  /* error check the strings? */

  one_s = new_Sequence_from_strings(NULL,one);
  if( one_s == NULL ) {
    warn("Cannot make new sequence...\n");
    return NULL;
  }

  two_s = new_Sequence_from_strings(NULL,two);
  if( two_s == NULL ) {
    warn("Cannot make new sequence...\n");
    return NULL;
  }

  out = Align_Sequences_ProteinSmithWaterman(one_s,two_s,comp,gap,ext,dpenv,dpri);

  free_Sequence(one_s);
  free_Sequence(two_s);

  return out;
}
  

/* Function:  Align_Sequences_ProteinSmithWaterman(one,two,comp,gap,ext,dpenv,dpri)
 *
 * Descrip:    This function is a mid-level abstraction of
 *             comparing two sequences, which could be
 *             generic types (eg DNA!). This is tested
 *             for and warnings are given but the alignment
 *             is still calculated. To prevent this test
 *             warning either make sure the Sequence types
 *             are set to PROTEIN or, better still, use the
 *             high level abstraction Align_Proteins_SmithWaterman
 *
 *             Otherwise this performs a standard smith waterman
 *             protein alignment...
 *
 *             To display the alignment use  write_pretty_seq_align
 *
 *
 * Arg:          one [READ ] First sequence to compare [Sequence *]
 * Arg:          two [READ ] Second sequecne to compare [Sequence *]
 * Arg:         comp [READ ] Comparison matrix to use [CompMat *]
 * Arg:          gap [UNKN ] gap penalty. Must be negative or 0 [int]
 * Arg:          ext [UNKN ] ext penalty. Must be negative or 0 [int]
 * Arg:        dpenv [UNKN ] Undocumented argument [DPEnvelope *]
 * Arg:         dpri [UNKN ] Undocumented argument [DPRunImpl *]
 *
 * Return [OWNER]  new AlnBlock structure representing the alignment [AlnBlock *]
 *
 */
# line 88 "sw_wrap.dy"
AlnBlock * Align_Sequences_ProteinSmithWaterman(Sequence * one,Sequence * two,CompMat * comp,int gap,int ext,DPEnvelope * dpenv,DPRunImpl * dpri)
{
  AlnBlock * out = NULL;
  ComplexSequenceEvalSet * evalfunc = NULL;
  ComplexSequence * query_cs = NULL;
  ComplexSequence * target_cs = NULL;
  PackAln * pal = NULL;

  if( one == NULL || two == NULL || comp == NULL ) {
    warn("Passed in NULL objects into Align_Sequences_ProteinSmithWaterman!");
    return NULL;
  }

  if( one->type != SEQUENCE_PROTEIN ) {
    warn("Sequence %s is not typed as protein... ignoring!\n",one->name);
  }

  if( two->type != SEQUENCE_PROTEIN ) {
    warn("Sequence %s is not typed as protein... ignoring!\n",two->name);
  }


  if( gap > 0 || ext > 0 ) {
    warn("Gap penalties %d,%d only make sense if they are negative",gap,ext);
    return NULL;
  }

  evalfunc = default_aminoacid_ComplexSequenceEvalSet();
  
  query_cs = new_ComplexSequence(one,evalfunc);
  if( query_cs == NULL )
    goto cleanup;
  target_cs = new_ComplexSequence(two,evalfunc);
  if( target_cs == NULL )
    goto cleanup;

  pal = PackAln_bestmemory_ProteinSW(query_cs,target_cs,comp,gap,ext,dpenv,dpri);
  if( pal == NULL ) 
    goto cleanup;

  out = convert_PackAln_to_AlnBlock_ProteinSW(pal);
  
  goto cleanup;

  cleanup :

    if( query_cs != NULL )
      free_ComplexSequence(query_cs);

  if( target_cs != NULL )
    free_ComplexSequence(target_cs);

  if( pal != NULL )
    free_PackAln(pal);

  if( evalfunc != NULL )
    free_ComplexSequenceEvalSet(evalfunc);

  return out;

}

/* Function:  Align_Sequences_ProteinBlockAligner(one,two,comp,bentry,bexit,b1exit,b_self,b_on,dpenv,dpri)
 *
 * Descrip:    This is a way of aligning two sequences using
 *             the ProteinBlockAligner algorithm
 *
 *
 *
 * Arg:           one [UNKN ] Sequence to align [Sequence *]
 * Arg:           two [UNKN ] Sequence to align [Sequence *]
 * Arg:          comp [UNKN ] Comparison Matrix [CompMat *]
 * Arg:        bentry [UNKN ] entry into a block [int]
 * Arg:         bexit [UNKN ] exit for a block [int]
 * Arg:        b1exit [UNKN ] exit for a block of length one [int]
 * Arg:        b_self [UNKN ] self transition [int]
 * Arg:          b_on [UNKN ] onwards transition [int]
 * Arg:         dpenv [UNKN ] Undocumented argument [DPEnvelope *]
 * Arg:          dpri [UNKN ] Undocumented argument [DPRunImpl *]
 *
 * Return [UNKN ]  Undocumented return value [AlnBlock *]
 *
 */
# line 164 "sw_wrap.dy"
AlnBlock * Align_Sequences_ProteinBlockAligner(Sequence * one,Sequence * two,CompMat * comp,int bentry,int bexit,int b1exit,int b_self,int b_on,DPEnvelope * dpenv,DPRunImpl * dpri)
{
  ComplexSequence * cone=NULL;
  ComplexSequence * ctwo=NULL;
  AlnBlock * alb= NULL;
  PackAln * pal=NULL;
  ComplexSequenceEvalSet * evalfunc = NULL;

  if( one == NULL || two == NULL || comp == NULL ) {
    warn("Passed in NULL objects into Align_Sequences_ProteinSmithWaterman!");
    return NULL;
  }

  if( one->type != SEQUENCE_PROTEIN ) {
    warn("Sequence %s is not typed as protein... ignoring!\n",one->name);
  }

  if( two->type != SEQUENCE_PROTEIN ) {
    warn("Sequence %s is not typed as protein... ignoring!\n",two->name);
  }


  evalfunc = default_aminoacid_ComplexSequenceEvalSet();
  
  cone = new_ComplexSequence(one,evalfunc);
  if( cone == NULL )
    goto cleanup;
  ctwo = new_ComplexSequence(two,evalfunc);
  if( ctwo == NULL )
    goto cleanup;

  pal = PackAln_bestmemory_ProteinBlockAligner(cone,ctwo,comp,bentry,b1exit,b_on,b_self,bexit,dpenv,dpri);

  if( pal == NULL ) 
    goto cleanup;

  alb = convert_PackAln_to_AlnBlock_ProteinSW(pal);
  
  goto cleanup;

  cleanup :

  if( cone != NULL )
      free_ComplexSequence(cone);

  if( ctwo != NULL )
    free_ComplexSequence(ctwo);

  if( pal != NULL )
    free_PackAln(pal);

  if( evalfunc != NULL )
    free_ComplexSequenceEvalSet(evalfunc);

  return alb;

}

/* Function:  Align_Sequences_ProteinABC(one,two,comp,a,b,c,dpenv,dpri)
 *
 * Descrip:    Align_Sequences_ProteinABC
 *             this function is analogous to Align_Sequences_ProteinSmithWaterman
 *             but using the abc model
 *
 *
 * Arg:          one [UNKN ] Sequence to align [Sequence *]
 * Arg:          two [UNKN ] Sequence to align [Sequence *]
 * Arg:         comp [UNKN ] Comparison Matrix [CompMat *]
 * Arg:            a [UNKN ] genearlized affine gap cost  [int]
 * Arg:            b [UNKN ] genearlized affine gap cost  [int]
 * Arg:            c [UNKN ] genearlized affine gap cost  [int]
 * Arg:        dpenv [UNKN ] Undocumented argument [DPEnvelope *]
 * Arg:         dpri [UNKN ] Undocumented argument [DPRunImpl *]
 *
 * Return [UNKN ]  Undocumented return value [AlnBlock *]
 *
 */
# line 234 "sw_wrap.dy"
AlnBlock * Align_Sequences_ProteinABC(Sequence * one,Sequence * two,CompMat * comp,int a, int b, int c,DPEnvelope * dpenv,DPRunImpl * dpri)
{
   ComplexSequence * cone=NULL;
   ComplexSequence * ctwo=NULL;
   AlnBlock * alb= NULL;
   PackAln * pal=NULL;
   ComplexSequenceEvalSet * evalfunc = NULL;

   if( one == NULL || two == NULL || comp == NULL ) {
     warn("Passed in NULL objects into Align_Sequences_ProteinSmithWaterman!");
     return NULL;
   }

   if( one->type != SEQUENCE_PROTEIN ) {
     warn("Sequence %s is not typed as protein... ignoring!\n",one->name);
   }

   if( two->type != SEQUENCE_PROTEIN ) {
     warn("Sequence %s is not typed as protein... ignoring!\n",two->name);
   }

   evalfunc = default_aminoacid_ComplexSequenceEvalSet();

   cone = new_ComplexSequence(one,evalfunc);
   if( cone == NULL )
      goto cleanup;
    ctwo = new_ComplexSequence(two,evalfunc);
   if( ctwo == NULL )
     goto cleanup;

   pal = PackAln_bestmemory_abc(cone,ctwo,comp,a,b,c,NULL,dpri);

   if( pal == NULL )
     goto cleanup;

   alb = convert_PackAln_to_AlnBlock_abc(pal);

   goto cleanup;

   cleanup :

   if( cone != NULL )
       free_ComplexSequence(cone);

   if( ctwo != NULL )
     free_ComplexSequence(ctwo);

   if( pal != NULL )
     free_PackAln(pal);

   if( evalfunc != NULL )
     free_ComplexSequenceEvalSet(evalfunc);

   return alb;

}
  
/* Function:  Align_Proteins_ABC(one,two,comp,a,b,c,dpenv,dpri)
 *
 * Descrip:    Analogous to Align_Proteins_SmithWaterman for ABC model
 *
 *
 * Arg:          one [UNKN ] protein to align [Protein *]
 * Arg:          two [UNKN ] protein to align [Protein *]
 * Arg:         comp [UNKN ] comparison matrix [CompMat *]
 * Arg:            a [UNKN ] generalized affine gap cost a [int]
 * Arg:            b [UNKN ] generalized affine gap cost b [int]
 * Arg:            c [UNKN ] generalized affine gap cost c [int]
 * Arg:        dpenv [UNKN ] Undocumented argument [DPEnvelope *]
 * Arg:         dpri [UNKN ] Undocumented argument [DPRunImpl *]
 *
 * Return [UNKN ]  Undocumented return value [AlnBlock *]
 *
 */
# line 301 "sw_wrap.dy"
AlnBlock * Align_Proteins_ABC(Protein * one,Protein * two,CompMat * comp,int a,int b,int c,DPEnvelope * dpenv,DPRunImpl * dpri) 
{

  if( one == NULL || two == NULL || comp == NULL ) {
    warn("Passed in NULL objects into Align_Proteins_ABC!");
    return NULL;
  }

  return Align_Sequences_ProteinABC(one->baseseq,two->baseseq,comp,a,b,c,dpenv,dpri);
}

/* Function:  Align_Proteins_SmithWaterman(one,two,comp,gap,ext,dpenv,dpri)
 *
 * Descrip:    This is the most correct way of aligning two Proteins,
 *             using Protein objects, which can be assumed to be
 *             proteins with no objections
 *
 *             To display the alignment use write_pretty_Protein_align
 *
 *
 *
 * Arg:          one [UNKN ] Protein to align [Protein *]
 * Arg:          two [UNKN ] Protein to align [Protein *]
 * Arg:         comp [UNKN ] Comparison Matrix [CompMat *]
 * Arg:          gap [UNKN ] gap penalty [int]
 * Arg:          ext [UNKN ] extension penalty [int]
 * Arg:        dpenv [UNKN ] Undocumented argument [DPEnvelope *]
 * Arg:         dpri [UNKN ] Undocumented argument [DPRunImpl *]
 *
 * Return [UNKN ]  Undocumented return value [AlnBlock *]
 *
 */
# line 326 "sw_wrap.dy"
AlnBlock * Align_Proteins_SmithWaterman(Protein * one,Protein * two,CompMat * comp,int gap,int ext,DPEnvelope * dpenv,DPRunImpl * dpri)
{
  if( one == NULL || two == NULL || comp == NULL ) {
    warn("Passed in NULL objects into Align_Proteins_SmithWaterman!");
    return NULL;
  }
    
  
  return Align_Sequences_ProteinSmithWaterman(one->baseseq,two->baseseq,comp,gap,ext,dpenv,dpri);
}

/* Function:  Hscore_from_ProteinSW(querydb,targetdb,comp,gap,ext,bits_cutoff,report_level,die_on_error,dbsi)
 *
 * Descrip:    Runs a database psw search 
 *
 *
 * Arg:             querydb [UNKN ] query database  [ProteinDB*]
 * Arg:            targetdb [UNKN ] target database [ProteinDB*]
 * Arg:                comp [UNKN ] comparison matrix [CompMat*]
 * Arg:                 gap [UNKN ] gap penalty [int]
 * Arg:                 ext [UNKN ] extension penalty [int]
 * Arg:         bits_cutoff [UNKN ]  [double]
 * Arg:        report_level [UNKN ]  [int]
 * Arg:        die_on_error [UNKN ]  [boolean]
 * Arg:                dbsi [UNKN ]  [DBSearchImpl*]
 *
 * Return [UNKN ]  Undocumented return value [Hscore *]
 *
 */
# line 350 "sw_wrap.dy"
Hscore * Hscore_from_ProteinSW(ProteinDB* querydb,ProteinDB* targetdb,CompMat* comp,int gap,int ext,double bits_cutoff,int report_level,boolean die_on_error,DBSearchImpl* dbsi)
{

   Hscore * out = NULL;
 
   Search_Return_Type ret;

   ret = SEARCH_ERROR;

   out = std_score_Hscore(bits_cutoff,report_level);

   if( dbsi == NULL ) {
      warn("Passed a NULL dbsi search implementation object. Exiting without searching");
      goto exit;
   }

   if( querydb == NULL ) {
      warn("Passed a NULL querydb. Exiting without searching");
      goto exit;
   }

   if( targetdb == NULL ) {
      warn("Passed a NULL targetdb. Exiting without searching");
      goto exit;
   }

   if( comp == NULL ) {
      warn("Passed a NULL comparison matrix. Exiting without searching");
      goto exit;
   }

   ret = search_ProteinSW(dbsi,out,querydb,targetdb,comp,gap,ext);

   exit:

   return out;
}

/* Function:  Hscore_from_ProteinABC(querydb,targetdb,comp,a,b,c,bits_cutoff,report_level,die_on_error,dbsi)
 *
 * Descrip:    Runs a database abc search 
 *
 *
 * Arg:             querydb [UNKN ] query database  [ProteinDB*]
 * Arg:            targetdb [UNKN ] target database [ProteinDB*]
 * Arg:                comp [UNKN ] comparison matrix [CompMat*]
 * Arg:                   a [UNKN ] generalized affine gap cost a [int]
 * Arg:                   b [UNKN ] generalized affine gap cost b [int]
 * Arg:                   c [UNKN ] generalized affine gap cost c [int]
 * Arg:         bits_cutoff [UNKN ]  [double]
 * Arg:        report_level [UNKN ]  [int]
 * Arg:        die_on_error [UNKN ]  [boolean]
 * Arg:                dbsi [UNKN ]  [DBSearchImpl*]
 *
 * Return [UNKN ]  Undocumented return value [Hscore *]
 *
 */
# line 402 "sw_wrap.dy"
Hscore * Hscore_from_ProteinABC(ProteinDB* querydb,ProteinDB* targetdb,CompMat* comp,int a,int b,int c,double bits_cutoff,int report_level,boolean die_on_error,DBSearchImpl* dbsi)
{

   Hscore * out = NULL;
 
   Search_Return_Type ret;

   ret = SEARCH_ERROR;

   out = std_score_Hscore(bits_cutoff,report_level);

   if( dbsi == NULL ) {
      warn("Passed a NULL dbsi search implementation object. Exiting without searching");
      goto exit;
   }

   if( querydb == NULL ) {
      warn("Passed a NULL querydb. Exiting without searching");
      goto exit;
   }

   if( targetdb == NULL ) {
      warn("Passed a NULL targetdb. Exiting without searching");
      goto exit;
   }

   if( comp == NULL ) {
      warn("Passed a NULL comparison matrix. Exiting without searching");
      goto exit;
   }

   ret = search_abc(dbsi,out,querydb,targetdb,comp,a,b,c);

   exit:

   return out;
}

/* Function:  Hscore_from_ProteinBA(querydb,targetdb,comp,bentry,bexit,bfor_trans,b_self_trans,b3exit,bits_cutoff,report_level,dbsi)
 *
 * Descrip:    Runs a database pba search
 *
 *
 * Arg:             querydb [UNKN ] query database [ProteinDB*]
 * Arg:            targetdb [UNKN ] target database [ProteinDB*]
 * Arg:                comp [UNKN ] comparison matrix [CompMat*]
 * Arg:              bentry [UNKN ]  [Score]
 * Arg:               bexit [UNKN ]  [Score]
 * Arg:          bfor_trans [UNKN ]  [Score]
 * Arg:        b_self_trans [UNKN ]  [Score]
 * Arg:              b3exit [UNKN ]  [Score]
 * Arg:         bits_cutoff [UNKN ]  [double]
 * Arg:        report_level [UNKN ]  [int]
 * Arg:                dbsi [UNKN ]  [DBSearchImpl*]
 *
 * Return [UNKN ]  Undocumented return value [Hscore *]
 *
 */
# line 455 "sw_wrap.dy"
Hscore * Hscore_from_ProteinBA(ProteinDB* querydb,ProteinDB* targetdb,CompMat* comp,Score bentry,Score bexit,Score bfor_trans,Score b_self_trans,Score b3exit,double bits_cutoff,int report_level,DBSearchImpl* dbsi)
{

   Hscore * out = NULL;

   Search_Return_Type ret;

   ret = SEARCH_ERROR;

   out = std_score_Hscore(bits_cutoff,report_level);

   if( dbsi == NULL ) {
      warn("Passed a NULL dbsi search implementation object. Exiting without searching");
      goto exit;
   }

   if( querydb == NULL ) {
      warn("Passed a NULL querydb. Exiting without searching");
      goto exit;
   }

   if( targetdb == NULL ) {
      warn("Passed a NULL targetdb. Exiting without searching");
      goto exit;
   }

   if( comp == NULL ) {
      warn("Passed a NULL comparison matrix. Exiting without searching");
      goto exit;
   }

   ret = search_ProteinBlockAligner(dbsi,out,querydb,targetdb,comp,bentry,bexit,bfor_trans,b_self_trans,b3exit);

   exit:

   return out;
}

# line 521 "sw_wrap.c"

#ifdef _cplusplus
}
#endif